diff --git a/armlib/Makefile b/armlib/Makefile index fa76b6a57..d989b7656 100644 --- a/armlib/Makefile +++ b/armlib/Makefile @@ -94,4 +94,4 @@ $(ARMLIB): $(ARMLIB_OBJ) | $(OBJDIR) $(call ARMLIB_REGISTER_RULES) -include $(ARMLIB_DEP) -endif \ No newline at end of file +endif diff --git a/armlib/at32_i2c/at32f435_437_i2c_app.c b/armlib/at32_i2c/at32f435_437_i2c_app.c index 432304c22..26eaf5dc7 100644 --- a/armlib/at32_i2c/at32f435_437_i2c_app.c +++ b/armlib/at32_i2c/at32f435_437_i2c_app.c @@ -102,8 +102,7 @@ * @param none * @retval none */ -__WEAK void i2c_lowlevel_init(i2c_handle_type* hi2c) -{ +__WEAK void i2c_lowlevel_init(i2c_handle_type *hi2c) { } @@ -112,16 +111,15 @@ __WEAK void i2c_lowlevel_init(i2c_handle_type* hi2c) * @param hi2c: the handle points to the operation information. * @retval none. */ -void i2c_config(i2c_handle_type* hi2c) -{ - /* reset i2c peripheral */ - i2c_reset(hi2c->i2cx); +void i2c_config(i2c_handle_type *hi2c) { + /* reset i2c peripheral */ + i2c_reset(hi2c->i2cx); - /* i2c peripheral initialization */ - i2c_lowlevel_init(hi2c); + /* i2c peripheral initialization */ + i2c_lowlevel_init(hi2c); - /* i2c peripheral enable */ - i2c_enable(hi2c->i2cx, TRUE); + /* i2c peripheral enable */ + i2c_enable(hi2c->i2cx, TRUE); } /** @@ -129,19 +127,16 @@ void i2c_config(i2c_handle_type* hi2c) * @param hi2c: the handle points to the operation information. * @retval none. */ -void i2c_refresh_txdt_register(i2c_handle_type* hi2c) -{ - /* clear tdis flag */ - if (i2c_flag_get(hi2c->i2cx, I2C_TDIS_FLAG) != RESET) - { - hi2c->i2cx->txdt = 0x00; - } +void i2c_refresh_txdt_register(i2c_handle_type *hi2c) { + /* clear tdis flag */ + if (i2c_flag_get(hi2c->i2cx, I2C_TDIS_FLAG) != RESET) { + hi2c->i2cx->txdt = 0x00; + } - /* refresh txdt register*/ - if (i2c_flag_get(hi2c->i2cx, I2C_TDBE_FLAG) == RESET) - { - hi2c->i2cx->sts_bit.tdbe = 1; - } + /* refresh txdt register*/ + if (i2c_flag_get(hi2c->i2cx, I2C_TDBE_FLAG) == RESET) { + hi2c->i2cx->sts_bit.tdbe = 1; + } } /** @@ -149,13 +144,12 @@ void i2c_refresh_txdt_register(i2c_handle_type* hi2c) * @param hi2c: the handle points to the operation information. * @retval none. */ -void i2c_reset_ctrl2_register(i2c_handle_type* hi2c) -{ - hi2c->i2cx->ctrl2_bit.saddr = 0; - hi2c->i2cx->ctrl2_bit.readh10 = 0; - hi2c->i2cx->ctrl2_bit.cnt = 0; - hi2c->i2cx->ctrl2_bit.rlden = 0; - hi2c->i2cx->ctrl2_bit.dir = 0; +void i2c_reset_ctrl2_register(i2c_handle_type *hi2c) { + hi2c->i2cx->ctrl2_bit.saddr = 0; + hi2c->i2cx->ctrl2_bit.readh10 = 0; + hi2c->i2cx->ctrl2_bit.cnt = 0; + hi2c->i2cx->ctrl2_bit.rlden = 0; + hi2c->i2cx->ctrl2_bit.dir = 0; } /** @@ -164,23 +158,19 @@ void i2c_reset_ctrl2_register(i2c_handle_type* hi2c) * @param timeout: maximum waiting time. * @retval i2c status. */ -i2c_status_type i2c_wait_end(i2c_handle_type* hi2c, uint32_t timeout) -{ - while(hi2c->status != I2C_END) - { - /* check timeout */ - if((timeout--) == 0) - { - return I2C_ERR_TIMEOUT; +i2c_status_type i2c_wait_end(i2c_handle_type *hi2c, uint32_t timeout) { + while (hi2c->status != I2C_END) { + /* check timeout */ + if ((timeout--) == 0) { + return I2C_ERR_TIMEOUT; + } } - } - if(hi2c->error_code != I2C_OK) - { - return hi2c->error_code; - } + if (hi2c->error_code != I2C_OK) { + return hi2c->error_code; + } - return I2C_OK; + return I2C_OK; } /** @@ -213,66 +203,54 @@ i2c_status_type i2c_wait_end(i2c_handle_type* hi2c, uint32_t timeout) * @param timeout: maximum waiting time. * @retval i2c status. */ -i2c_status_type i2c_wait_flag(i2c_handle_type* hi2c, uint32_t flag, uint32_t event_check, uint32_t timeout) -{ - if(flag == I2C_BUSYF_FLAG) - { - while(i2c_flag_get(hi2c->i2cx, flag) != RESET) - { - /* check timeout */ - if((timeout--) == 0) - { - hi2c->error_code = I2C_ERR_TIMEOUT; +i2c_status_type i2c_wait_flag(i2c_handle_type *hi2c, uint32_t flag, uint32_t event_check, uint32_t timeout) { + if (flag == I2C_BUSYF_FLAG) { + while (i2c_flag_get(hi2c->i2cx, flag) != RESET) { + /* check timeout */ + if ((timeout--) == 0) { + hi2c->error_code = I2C_ERR_TIMEOUT; - return I2C_ERR_TIMEOUT; - } - } - } - else - { - while(i2c_flag_get(hi2c->i2cx, flag) == RESET) - { - /* check the ack fail flag */ - if(event_check & I2C_EVENT_CHECK_ACKFAIL) - { - if(i2c_flag_get(hi2c->i2cx, I2C_ACKFAIL_FLAG) != RESET) - { - /* clear ack fail flag */ - i2c_flag_clear(hi2c->i2cx, I2C_ACKFAIL_FLAG); - - hi2c->error_code = I2C_ERR_ACKFAIL; - - return I2C_ERR_ACKFAIL; + return I2C_ERR_TIMEOUT; + } } - } + } else { + while (i2c_flag_get(hi2c->i2cx, flag) == RESET) { + /* check the ack fail flag */ + if (event_check & I2C_EVENT_CHECK_ACKFAIL) { + if (i2c_flag_get(hi2c->i2cx, I2C_ACKFAIL_FLAG) != RESET) { + /* clear ack fail flag */ + i2c_flag_clear(hi2c->i2cx, I2C_ACKFAIL_FLAG); - /* check the stop flag */ - if(event_check & I2C_EVENT_CHECK_STOP) - { - if(i2c_flag_get(hi2c->i2cx, I2C_STOPF_FLAG) != RESET) - { - /* clear stop flag */ - i2c_flag_clear(hi2c->i2cx, I2C_STOPF_FLAG); + hi2c->error_code = I2C_ERR_ACKFAIL; - i2c_reset_ctrl2_register(hi2c); + return I2C_ERR_ACKFAIL; + } + } - hi2c->error_code = I2C_ERR_STOP; + /* check the stop flag */ + if (event_check & I2C_EVENT_CHECK_STOP) { + if (i2c_flag_get(hi2c->i2cx, I2C_STOPF_FLAG) != RESET) { + /* clear stop flag */ + i2c_flag_clear(hi2c->i2cx, I2C_STOPF_FLAG); - return I2C_ERR_STOP; + i2c_reset_ctrl2_register(hi2c); + + hi2c->error_code = I2C_ERR_STOP; + + return I2C_ERR_STOP; + } + } + + /* check timeout */ + if ((timeout--) == 0) { + hi2c->error_code = I2C_ERR_TIMEOUT; + + return I2C_ERR_TIMEOUT; + } } - } - - /* check timeout */ - if((timeout--) == 0) - { - hi2c->error_code = I2C_ERR_TIMEOUT; - - return I2C_ERR_TIMEOUT; - } } - } - return I2C_OK; + return I2C_OK; } /** @@ -283,26 +261,25 @@ i2c_status_type i2c_wait_flag(i2c_handle_type* hi2c, uint32_t flag, uint32_t eve * @param size: data size. * @retval none. */ -void i2c_dma_config(i2c_handle_type* hi2c, dma_channel_type* dma_channel, uint8_t* pdata, uint16_t size) -{ - /* disable the dma channel */ - dma_channel_enable(dma_channel, FALSE); +void i2c_dma_config(i2c_handle_type *hi2c, dma_channel_type *dma_channel, uint8_t *pdata, uint16_t size) { + /* disable the dma channel */ + dma_channel_enable(dma_channel, FALSE); - /* disable the transfer complete interrupt */ - dma_interrupt_enable(dma_channel, DMA_FDT_INT, FALSE); + /* disable the transfer complete interrupt */ + dma_interrupt_enable(dma_channel, DMA_FDT_INT, FALSE); - /* configure the dma channel with the buffer address and the buffer size */ - hi2c->dma_init_struct.memory_base_addr = (uint32_t)pdata; - hi2c->dma_init_struct.direction = (dma_channel == hi2c->dma_tx_channel) ? DMA_DIR_MEMORY_TO_PERIPHERAL : DMA_DIR_PERIPHERAL_TO_MEMORY; - hi2c->dma_init_struct.peripheral_base_addr = (dma_channel == hi2c->dma_tx_channel) ? (uint32_t)&hi2c->i2cx->txdt : (uint32_t)&hi2c->i2cx->rxdt; - hi2c->dma_init_struct.buffer_size = (uint32_t)size; - dma_init(dma_channel, &hi2c->dma_init_struct); + /* configure the dma channel with the buffer address and the buffer size */ + hi2c->dma_init_struct.memory_base_addr = (uint32_t)pdata; + hi2c->dma_init_struct.direction = (dma_channel == hi2c->dma_tx_channel) ? DMA_DIR_MEMORY_TO_PERIPHERAL : DMA_DIR_PERIPHERAL_TO_MEMORY; + hi2c->dma_init_struct.peripheral_base_addr = (dma_channel == hi2c->dma_tx_channel) ? (uint32_t)&hi2c->i2cx->txdt : (uint32_t)&hi2c->i2cx->rxdt; + hi2c->dma_init_struct.buffer_size = (uint32_t)size; + dma_init(dma_channel, &hi2c->dma_init_struct); - /* enable the transfer complete interrupt */ - dma_interrupt_enable(dma_channel, DMA_FDT_INT, TRUE); + /* enable the transfer complete interrupt */ + dma_interrupt_enable(dma_channel, DMA_FDT_INT, TRUE); - /* enable the dma channel */ - dma_channel_enable(dma_channel, TRUE); + /* enable the dma channel */ + dma_channel_enable(dma_channel, TRUE); } /** @@ -316,20 +293,16 @@ void i2c_dma_config(i2c_handle_type* hi2c, dma_channel_type* dma_channel, uint8_ * - I2C_GEN_START_WRITE: send data and generate start. * @retval i2c status. */ -void i2c_start_transfer(i2c_handle_type* hi2c, uint16_t address, i2c_start_mode_type start) -{ - if (hi2c->pcount > MAX_TRANSFER_CNT) - { - hi2c->psize = MAX_TRANSFER_CNT; +void i2c_start_transfer(i2c_handle_type *hi2c, uint16_t address, i2c_start_mode_type start) { + if (hi2c->pcount > MAX_TRANSFER_CNT) { + hi2c->psize = MAX_TRANSFER_CNT; - i2c_transmit_set(hi2c->i2cx, address, hi2c->psize, I2C_RELOAD_MODE, start); - } - else - { - hi2c->psize = hi2c->pcount; + i2c_transmit_set(hi2c->i2cx, address, hi2c->psize, I2C_RELOAD_MODE, start); + } else { + hi2c->psize = hi2c->pcount; - i2c_transmit_set(hi2c->i2cx, address, hi2c->psize, I2C_AUTO_STOP_MODE, start); - } + i2c_transmit_set(hi2c->i2cx, address, hi2c->psize, I2C_AUTO_STOP_MODE, start); + } } /** @@ -343,26 +316,22 @@ void i2c_start_transfer(i2c_handle_type* hi2c, uint16_t address, i2c_start_mode_ * - I2C_GEN_START_WRITE: send data and generate start. * @retval i2c status. */ -void i2c_start_transfer_dma(i2c_handle_type* hi2c, dma_channel_type* dma_channelx, uint16_t address, i2c_start_mode_type start) -{ - if (hi2c->pcount > MAX_TRANSFER_CNT) - { - hi2c->psize = MAX_TRANSFER_CNT; +void i2c_start_transfer_dma(i2c_handle_type *hi2c, dma_channel_type *dma_channelx, uint16_t address, i2c_start_mode_type start) { + if (hi2c->pcount > MAX_TRANSFER_CNT) { + hi2c->psize = MAX_TRANSFER_CNT; - /* config dma */ - i2c_dma_config(hi2c, dma_channelx, hi2c->pbuff, hi2c->psize); + /* config dma */ + i2c_dma_config(hi2c, dma_channelx, hi2c->pbuff, hi2c->psize); - i2c_transmit_set(hi2c->i2cx, address, hi2c->psize, I2C_RELOAD_MODE, start); - } - else - { - hi2c->psize = hi2c->pcount; + i2c_transmit_set(hi2c->i2cx, address, hi2c->psize, I2C_RELOAD_MODE, start); + } else { + hi2c->psize = hi2c->pcount; - /* config dma */ - i2c_dma_config(hi2c, dma_channelx, hi2c->pbuff, hi2c->psize); + /* config dma */ + i2c_dma_config(hi2c, dma_channelx, hi2c->pbuff, hi2c->psize); - i2c_transmit_set(hi2c->i2cx, address, hi2c->psize, I2C_AUTO_STOP_MODE, start); - } + i2c_transmit_set(hi2c->i2cx, address, hi2c->psize, I2C_AUTO_STOP_MODE, start); + } } /** @@ -374,62 +343,55 @@ void i2c_start_transfer_dma(i2c_handle_type* hi2c, dma_channel_type* dma_channel * @param timeout: maximum waiting time. * @retval i2c status. */ -i2c_status_type i2c_master_transmit(i2c_handle_type* hi2c, uint16_t address, uint8_t* pdata, uint16_t size, uint32_t timeout) -{ - /* initialization parameters */ - hi2c->pbuff = pdata; - hi2c->pcount = size; +i2c_status_type i2c_master_transmit(i2c_handle_type *hi2c, uint16_t address, uint8_t *pdata, uint16_t size, uint32_t timeout) { + /* initialization parameters */ + hi2c->pbuff = pdata; + hi2c->pcount = size; - hi2c->error_code = I2C_OK; + hi2c->error_code = I2C_OK; - /* wait for the busy flag to be reset */ - if (i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) - { - return I2C_ERR_STEP_1; - } - - /* start transfer */ - i2c_start_transfer(hi2c, address, I2C_GEN_START_WRITE); - - while (hi2c->pcount > 0) - { - /* wait for the tdis flag to be set */ - if(i2c_wait_flag(hi2c, I2C_TDIS_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK) - { - return I2C_ERR_STEP_2; + /* wait for the busy flag to be reset */ + if (i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) { + return I2C_ERR_STEP_1; } - /* send data */ - i2c_data_send(hi2c->i2cx, *hi2c->pbuff++); - hi2c->psize--; - hi2c->pcount--; + /* start transfer */ + i2c_start_transfer(hi2c, address, I2C_GEN_START_WRITE); - if ((hi2c->psize == 0) && (hi2c->pcount != 0)) - { - /* wait for the tcrld flag to be set */ - if (i2c_wait_flag(hi2c, I2C_TCRLD_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK) - { - return I2C_ERR_STEP_3; - } + while (hi2c->pcount > 0) { + /* wait for the tdis flag to be set */ + if (i2c_wait_flag(hi2c, I2C_TDIS_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK) { + return I2C_ERR_STEP_2; + } - /* continue transfer */ - i2c_start_transfer(hi2c, address, I2C_WITHOUT_START); + /* send data */ + i2c_data_send(hi2c->i2cx, *hi2c->pbuff++); + hi2c->psize--; + hi2c->pcount--; + + if ((hi2c->psize == 0) && (hi2c->pcount != 0)) { + /* wait for the tcrld flag to be set */ + if (i2c_wait_flag(hi2c, I2C_TCRLD_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK) { + return I2C_ERR_STEP_3; + } + + /* continue transfer */ + i2c_start_transfer(hi2c, address, I2C_WITHOUT_START); + } } - } - /* wait for the stop flag to be set */ - if(i2c_wait_flag(hi2c, I2C_STOPF_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK) - { - return I2C_ERR_STEP_4; - } + /* wait for the stop flag to be set */ + if (i2c_wait_flag(hi2c, I2C_STOPF_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK) { + return I2C_ERR_STEP_4; + } - /* clear stop flag */ - i2c_flag_clear(hi2c->i2cx, I2C_STOPF_FLAG); + /* clear stop flag */ + i2c_flag_clear(hi2c->i2cx, I2C_STOPF_FLAG); - /* reset ctrl2 register */ - i2c_reset_ctrl2_register(hi2c); + /* reset ctrl2 register */ + i2c_reset_ctrl2_register(hi2c); - return I2C_OK; + return I2C_OK; } /** @@ -440,78 +402,70 @@ i2c_status_type i2c_master_transmit(i2c_handle_type* hi2c, uint16_t address, uin * @param timeout: maximum waiting time. * @retval i2c status. */ -i2c_status_type i2c_slave_receive(i2c_handle_type* hi2c, uint8_t* pdata, uint16_t size, uint32_t timeout) -{ - /* initialization parameters */ - hi2c->pbuff = pdata; - hi2c->pcount = size; +i2c_status_type i2c_slave_receive(i2c_handle_type *hi2c, uint8_t *pdata, uint16_t size, uint32_t timeout) { + /* initialization parameters */ + hi2c->pbuff = pdata; + hi2c->pcount = size; - hi2c->error_code = I2C_OK; + hi2c->error_code = I2C_OK; - /* wait for the busy flag to be reset */ - if(i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) - { - return I2C_ERR_STEP_1; - } + /* wait for the busy flag to be reset */ + if (i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) { + return I2C_ERR_STEP_1; + } - /* enable acknowledge */ - i2c_ack_enable(hi2c->i2cx, TRUE); + /* enable acknowledge */ + i2c_ack_enable(hi2c->i2cx, TRUE); - /* wait for the addr flag to be set */ - if (i2c_wait_flag(hi2c, I2C_ADDRF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) - { - return I2C_ERR_STEP_2; - } + /* wait for the addr flag to be set */ + if (i2c_wait_flag(hi2c, I2C_ADDRF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) { + return I2C_ERR_STEP_2; + } - /* clear addr flag */ - i2c_flag_clear(hi2c->i2cx, I2C_ADDRF_FLAG); + /* clear addr flag */ + i2c_flag_clear(hi2c->i2cx, I2C_ADDRF_FLAG); - while (hi2c->pcount > 0) - { - /* wait for the rdbf flag to be set */ - if(i2c_wait_flag(hi2c, I2C_RDBF_FLAG, I2C_EVENT_CHECK_STOP, timeout) != I2C_OK) - { - /* disable acknowledge */ - i2c_ack_enable(hi2c->i2cx, FALSE); + while (hi2c->pcount > 0) { + /* wait for the rdbf flag to be set */ + if (i2c_wait_flag(hi2c, I2C_RDBF_FLAG, I2C_EVENT_CHECK_STOP, timeout) != I2C_OK) { + /* disable acknowledge */ + i2c_ack_enable(hi2c->i2cx, FALSE); + + /* if data is received, read data */ + if (i2c_flag_get(hi2c->i2cx, I2C_RDBF_FLAG) == SET) { + /* read data */ + (*hi2c->pbuff++) = i2c_data_receive(hi2c->i2cx); + hi2c->pcount--; + } + + return I2C_ERR_STEP_4; + } - /* if data is received, read data */ - if (i2c_flag_get(hi2c->i2cx, I2C_RDBF_FLAG) == SET) - { /* read data */ (*hi2c->pbuff++) = i2c_data_receive(hi2c->i2cx); hi2c->pcount--; - } - - return I2C_ERR_STEP_4; } - /* read data */ - (*hi2c->pbuff++) = i2c_data_receive(hi2c->i2cx); - hi2c->pcount--; - } + /* wait for the stop flag to be set */ + if (i2c_wait_flag(hi2c, I2C_STOPF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) { + /* disable acknowledge */ + i2c_ack_enable(hi2c->i2cx, FALSE); - /* wait for the stop flag to be set */ - if(i2c_wait_flag(hi2c, I2C_STOPF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) - { - /* disable acknowledge */ - i2c_ack_enable(hi2c->i2cx, FALSE); + return I2C_ERR_STEP_5; + } - return I2C_ERR_STEP_5; - } + /* clear stop flag */ + i2c_flag_clear(hi2c->i2cx, I2C_STOPF_FLAG); - /* clear stop flag */ - i2c_flag_clear(hi2c->i2cx, I2C_STOPF_FLAG); + /* wait for the busy flag to be reset */ + if (i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) { + /* disable acknowledge */ + i2c_ack_enable(hi2c->i2cx, FALSE); - /* wait for the busy flag to be reset */ - if (i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) - { - /* disable acknowledge */ - i2c_ack_enable(hi2c->i2cx, FALSE); + return I2C_ERR_STEP_6; + } - return I2C_ERR_STEP_6; - } - - return I2C_OK; + return I2C_OK; } /** @@ -523,62 +477,55 @@ i2c_status_type i2c_slave_receive(i2c_handle_type* hi2c, uint8_t* pdata, uint16_ * @param timeout: maximum waiting time. * @retval i2c status. */ -i2c_status_type i2c_master_receive(i2c_handle_type* hi2c, uint16_t address, uint8_t* pdata, uint16_t size, uint32_t timeout) -{ - /* initialization parameters */ - hi2c->pbuff = pdata; - hi2c->pcount = size; +i2c_status_type i2c_master_receive(i2c_handle_type *hi2c, uint16_t address, uint8_t *pdata, uint16_t size, uint32_t timeout) { + /* initialization parameters */ + hi2c->pbuff = pdata; + hi2c->pcount = size; - hi2c->error_code = I2C_OK; + hi2c->error_code = I2C_OK; - /* wait for the busy flag to be reset */ - if (i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) - { - return I2C_ERR_STEP_1; - } - - /* start transfer */ - i2c_start_transfer(hi2c, address, I2C_GEN_START_READ); - - while (hi2c->pcount > 0) - { - /* wait for the rdbf flag to be set */ - if(i2c_wait_flag(hi2c, I2C_RDBF_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK) - { - return I2C_ERR_STEP_2; + /* wait for the busy flag to be reset */ + if (i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) { + return I2C_ERR_STEP_1; } - /* read data */ - (*hi2c->pbuff++) = i2c_data_receive(hi2c->i2cx); - hi2c->pcount--; - hi2c->psize--; + /* start transfer */ + i2c_start_transfer(hi2c, address, I2C_GEN_START_READ); - if ((hi2c->psize == 0) && (hi2c->pcount != 0)) - { - /* wait for the tcrld flag to be set */ - if (i2c_wait_flag(hi2c, I2C_TCRLD_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) - { - return I2C_ERR_STEP_3; - } + while (hi2c->pcount > 0) { + /* wait for the rdbf flag to be set */ + if (i2c_wait_flag(hi2c, I2C_RDBF_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK) { + return I2C_ERR_STEP_2; + } - /* continue transfer */ - i2c_start_transfer(hi2c, address, I2C_WITHOUT_START); + /* read data */ + (*hi2c->pbuff++) = i2c_data_receive(hi2c->i2cx); + hi2c->pcount--; + hi2c->psize--; + + if ((hi2c->psize == 0) && (hi2c->pcount != 0)) { + /* wait for the tcrld flag to be set */ + if (i2c_wait_flag(hi2c, I2C_TCRLD_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) { + return I2C_ERR_STEP_3; + } + + /* continue transfer */ + i2c_start_transfer(hi2c, address, I2C_WITHOUT_START); + } } - } - /* wait for the stop flag to be set */ - if(i2c_wait_flag(hi2c, I2C_STOPF_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK) - { - return I2C_ERR_STEP_4; - } + /* wait for the stop flag to be set */ + if (i2c_wait_flag(hi2c, I2C_STOPF_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK) { + return I2C_ERR_STEP_4; + } - /* clear stop flag */ - i2c_flag_clear(hi2c->i2cx, I2C_STOPF_FLAG); + /* clear stop flag */ + i2c_flag_clear(hi2c->i2cx, I2C_STOPF_FLAG); - /* reset ctrl2 register */ - i2c_reset_ctrl2_register(hi2c); + /* reset ctrl2 register */ + i2c_reset_ctrl2_register(hi2c); - return I2C_OK; + return I2C_OK; } /** @@ -589,100 +536,90 @@ i2c_status_type i2c_master_receive(i2c_handle_type* hi2c, uint16_t address, uint * @param timeout: maximum waiting time. * @retval i2c status. */ -i2c_status_type i2c_slave_transmit(i2c_handle_type* hi2c, uint8_t* pdata, uint16_t size, uint32_t timeout) -{ - /* initialization parameters */ - hi2c->pbuff = pdata; - hi2c->pcount = size; +i2c_status_type i2c_slave_transmit(i2c_handle_type *hi2c, uint8_t *pdata, uint16_t size, uint32_t timeout) { + /* initialization parameters */ + hi2c->pbuff = pdata; + hi2c->pcount = size; - hi2c->error_code = I2C_OK; + hi2c->error_code = I2C_OK; - /* wait for the busy flag to be reset */ - if(i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) - { - return I2C_ERR_STEP_1; - } + /* wait for the busy flag to be reset */ + if (i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) { + return I2C_ERR_STEP_1; + } - /* enable acknowledge */ - i2c_ack_enable(hi2c->i2cx, TRUE); + /* enable acknowledge */ + i2c_ack_enable(hi2c->i2cx, TRUE); - /* wait for the addr flag to be set */ - if (i2c_wait_flag(hi2c, I2C_ADDRF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) - { - /* disable acknowledge */ - i2c_ack_enable(hi2c->i2cx, FALSE); - return I2C_ERR_STEP_2; - } - - /* clear addr flag */ - i2c_flag_clear(hi2c->i2cx, I2C_ADDRF_FLAG); - - /* if 10-bit address mode is used */ - if (hi2c->i2cx->ctrl2_bit.addr10 != RESET) - { /* wait for the addr flag to be set */ - if (i2c_wait_flag(hi2c, I2C_ADDRF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) - { - /* disable acknowledge */ - i2c_ack_enable(hi2c->i2cx, FALSE); - - return I2C_ERR_STEP_3; + if (i2c_wait_flag(hi2c, I2C_ADDRF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) { + /* disable acknowledge */ + i2c_ack_enable(hi2c->i2cx, FALSE); + return I2C_ERR_STEP_2; } /* clear addr flag */ i2c_flag_clear(hi2c->i2cx, I2C_ADDRF_FLAG); - } - while (hi2c->pcount > 0) - { - /* wait for the tdis flag to be set */ - if(i2c_wait_flag(hi2c, I2C_TDIS_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK) - { - /* disable acknowledge */ - i2c_ack_enable(hi2c->i2cx, FALSE); + /* if 10-bit address mode is used */ + if (hi2c->i2cx->ctrl2_bit.addr10 != RESET) { + /* wait for the addr flag to be set */ + if (i2c_wait_flag(hi2c, I2C_ADDRF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) { + /* disable acknowledge */ + i2c_ack_enable(hi2c->i2cx, FALSE); - return I2C_ERR_STEP_5; + return I2C_ERR_STEP_3; + } + + /* clear addr flag */ + i2c_flag_clear(hi2c->i2cx, I2C_ADDRF_FLAG); } - /* send data */ - i2c_data_send(hi2c->i2cx, *hi2c->pbuff++); - hi2c->pcount--; - } + while (hi2c->pcount > 0) { + /* wait for the tdis flag to be set */ + if (i2c_wait_flag(hi2c, I2C_TDIS_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK) { + /* disable acknowledge */ + i2c_ack_enable(hi2c->i2cx, FALSE); - /* wait for the ackfail flag to be set */ - if(i2c_wait_flag(hi2c, I2C_ACKFAIL_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) - { - return I2C_ERR_STEP_6; - } + return I2C_ERR_STEP_5; + } - /* clear ack fail flag */ - i2c_flag_clear(hi2c->i2cx, I2C_ACKFAIL_FLAG); + /* send data */ + i2c_data_send(hi2c->i2cx, *hi2c->pbuff++); + hi2c->pcount--; + } - /* wait for the stop flag to be set */ - if(i2c_wait_flag(hi2c, I2C_STOPF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) - { - /* disable acknowledge */ - i2c_ack_enable(hi2c->i2cx, FALSE); + /* wait for the ackfail flag to be set */ + if (i2c_wait_flag(hi2c, I2C_ACKFAIL_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) { + return I2C_ERR_STEP_6; + } - return I2C_ERR_STEP_7; - } + /* clear ack fail flag */ + i2c_flag_clear(hi2c->i2cx, I2C_ACKFAIL_FLAG); - /* clear stop flag */ - i2c_flag_clear(hi2c->i2cx, I2C_STOPF_FLAG); + /* wait for the stop flag to be set */ + if (i2c_wait_flag(hi2c, I2C_STOPF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) { + /* disable acknowledge */ + i2c_ack_enable(hi2c->i2cx, FALSE); - /* wait for the busy flag to be reset */ - if (i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) - { - /* disable acknowledge */ - i2c_ack_enable(hi2c->i2cx, FALSE); + return I2C_ERR_STEP_7; + } - return I2C_ERR_STEP_8; - } + /* clear stop flag */ + i2c_flag_clear(hi2c->i2cx, I2C_STOPF_FLAG); - /* refresh tx dt register */ - i2c_refresh_txdt_register(hi2c); + /* wait for the busy flag to be reset */ + if (i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) { + /* disable acknowledge */ + i2c_ack_enable(hi2c->i2cx, FALSE); - return I2C_OK; + return I2C_ERR_STEP_8; + } + + /* refresh tx dt register */ + i2c_refresh_txdt_register(hi2c); + + return I2C_OK; } /** @@ -694,30 +631,28 @@ i2c_status_type i2c_slave_transmit(i2c_handle_type* hi2c, uint8_t* pdata, uint16 * @param timeout: maximum waiting time. * @retval i2c status. */ -i2c_status_type i2c_master_transmit_int(i2c_handle_type* hi2c, uint16_t address, uint8_t* pdata, uint16_t size, uint32_t timeout) -{ - /* initialization parameters */ - hi2c->mode = I2C_INT_MA_TX; - hi2c->status = I2C_START; +i2c_status_type i2c_master_transmit_int(i2c_handle_type *hi2c, uint16_t address, uint8_t *pdata, uint16_t size, uint32_t timeout) { + /* initialization parameters */ + hi2c->mode = I2C_INT_MA_TX; + hi2c->status = I2C_START; - hi2c->pbuff = pdata; - hi2c->pcount = size; + hi2c->pbuff = pdata; + hi2c->pcount = size; - hi2c->error_code = I2C_OK; + hi2c->error_code = I2C_OK; - /* wait for the busy flag to be reset */ - if (i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) - { - return I2C_ERR_STEP_1; - } + /* wait for the busy flag to be reset */ + if (i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) { + return I2C_ERR_STEP_1; + } - /* start transfer */ - i2c_start_transfer(hi2c, address, I2C_GEN_START_WRITE); + /* start transfer */ + i2c_start_transfer(hi2c, address, I2C_GEN_START_WRITE); - /* enable interrupt */ - i2c_interrupt_enable(hi2c->i2cx, I2C_ERR_INT | I2C_TDC_INT | I2C_STOP_INT | I2C_ACKFIAL_INT | I2C_TD_INT, TRUE); + /* enable interrupt */ + i2c_interrupt_enable(hi2c->i2cx, I2C_ERR_INT | I2C_TDC_INT | I2C_STOP_INT | I2C_ACKFIAL_INT | I2C_TD_INT, TRUE); - return I2C_OK; + return I2C_OK; } /** @@ -728,30 +663,28 @@ i2c_status_type i2c_master_transmit_int(i2c_handle_type* hi2c, uint16_t address, * @param timeout: maximum waiting time. * @retval i2c status. */ -i2c_status_type i2c_slave_receive_int(i2c_handle_type* hi2c, uint8_t* pdata, uint16_t size, uint32_t timeout) -{ - /* initialization parameters */ - hi2c->mode = I2C_INT_SLA_RX; - hi2c->status = I2C_START; +i2c_status_type i2c_slave_receive_int(i2c_handle_type *hi2c, uint8_t *pdata, uint16_t size, uint32_t timeout) { + /* initialization parameters */ + hi2c->mode = I2C_INT_SLA_RX; + hi2c->status = I2C_START; - hi2c->pbuff = pdata; - hi2c->pcount = size; + hi2c->pbuff = pdata; + hi2c->pcount = size; - hi2c->error_code = I2C_OK; + hi2c->error_code = I2C_OK; - /* wait for the busy flag to be reset */ - if (i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) - { - return I2C_ERR_STEP_1; - } + /* wait for the busy flag to be reset */ + if (i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) { + return I2C_ERR_STEP_1; + } - /* enable acknowledge */ - i2c_ack_enable(hi2c->i2cx, TRUE); + /* enable acknowledge */ + i2c_ack_enable(hi2c->i2cx, TRUE); - /* enable interrupt */ - i2c_interrupt_enable(hi2c->i2cx, I2C_ERR_INT | I2C_TDC_INT | I2C_STOP_INT | I2C_ACKFIAL_INT | I2C_ADDR_INT | I2C_RD_INT, TRUE); + /* enable interrupt */ + i2c_interrupt_enable(hi2c->i2cx, I2C_ERR_INT | I2C_TDC_INT | I2C_STOP_INT | I2C_ACKFIAL_INT | I2C_ADDR_INT | I2C_RD_INT, TRUE); - return I2C_OK; + return I2C_OK; } /** @@ -763,30 +696,28 @@ i2c_status_type i2c_slave_receive_int(i2c_handle_type* hi2c, uint8_t* pdata, uin * @param timeout: maximum waiting time. * @retval i2c status. */ -i2c_status_type i2c_master_receive_int(i2c_handle_type* hi2c, uint16_t address, uint8_t* pdata, uint16_t size, uint32_t timeout) -{ - /* initialization parameters */ - hi2c->mode = I2C_INT_MA_RX; - hi2c->status = I2C_START; +i2c_status_type i2c_master_receive_int(i2c_handle_type *hi2c, uint16_t address, uint8_t *pdata, uint16_t size, uint32_t timeout) { + /* initialization parameters */ + hi2c->mode = I2C_INT_MA_RX; + hi2c->status = I2C_START; - hi2c->pbuff = pdata; - hi2c->pcount = size; + hi2c->pbuff = pdata; + hi2c->pcount = size; - hi2c->error_code = I2C_OK; + hi2c->error_code = I2C_OK; - /* wait for the busy flag to be reset */ - if (i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) - { - return I2C_ERR_STEP_1; - } + /* wait for the busy flag to be reset */ + if (i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) { + return I2C_ERR_STEP_1; + } - /* start transfer */ - i2c_start_transfer(hi2c, address, I2C_GEN_START_READ); + /* start transfer */ + i2c_start_transfer(hi2c, address, I2C_GEN_START_READ); - /* enable interrupt */ - i2c_interrupt_enable(hi2c->i2cx, I2C_ERR_INT | I2C_TDC_INT | I2C_STOP_INT | I2C_ACKFIAL_INT | I2C_RD_INT, TRUE); + /* enable interrupt */ + i2c_interrupt_enable(hi2c->i2cx, I2C_ERR_INT | I2C_TDC_INT | I2C_STOP_INT | I2C_ACKFIAL_INT | I2C_RD_INT, TRUE); - return I2C_OK; + return I2C_OK; } /** @@ -797,32 +728,30 @@ i2c_status_type i2c_master_receive_int(i2c_handle_type* hi2c, uint16_t address, * @param timeout: maximum waiting time. * @retval i2c status. */ -i2c_status_type i2c_slave_transmit_int(i2c_handle_type* hi2c, uint8_t* pdata, uint16_t size, uint32_t timeout) -{ - /* initialization parameters */ - hi2c->mode = I2C_INT_SLA_TX; - hi2c->status = I2C_START; +i2c_status_type i2c_slave_transmit_int(i2c_handle_type *hi2c, uint8_t *pdata, uint16_t size, uint32_t timeout) { + /* initialization parameters */ + hi2c->mode = I2C_INT_SLA_TX; + hi2c->status = I2C_START; - hi2c->pbuff = pdata; - hi2c->pcount = size; + hi2c->pbuff = pdata; + hi2c->pcount = size; - hi2c->error_code = I2C_OK; + hi2c->error_code = I2C_OK; - /* wait for the busy flag to be reset */ - if (i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) - { - return I2C_ERR_STEP_1; - } + /* wait for the busy flag to be reset */ + if (i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) { + return I2C_ERR_STEP_1; + } - /* enable acknowledge */ - i2c_ack_enable(hi2c->i2cx, TRUE); + /* enable acknowledge */ + i2c_ack_enable(hi2c->i2cx, TRUE); - /* enable interrupt */ - i2c_interrupt_enable(hi2c->i2cx, I2C_ERR_INT | I2C_TDC_INT | I2C_STOP_INT | I2C_ACKFIAL_INT | I2C_ADDR_INT | I2C_TD_INT, TRUE); + /* enable interrupt */ + i2c_interrupt_enable(hi2c->i2cx, I2C_ERR_INT | I2C_TDC_INT | I2C_STOP_INT | I2C_ACKFIAL_INT | I2C_ADDR_INT | I2C_TD_INT, TRUE); - i2c_refresh_txdt_register(hi2c); + i2c_refresh_txdt_register(hi2c); - return I2C_OK; + return I2C_OK; } /** @@ -834,36 +763,34 @@ i2c_status_type i2c_slave_transmit_int(i2c_handle_type* hi2c, uint8_t* pdata, ui * @param timeout: maximum waiting time. * @retval i2c status. */ -i2c_status_type i2c_master_transmit_dma(i2c_handle_type* hi2c, uint16_t address, uint8_t* pdata, uint16_t size, uint32_t timeout) -{ - /* initialization parameters */ - hi2c->mode = I2C_DMA_MA_TX; - hi2c->status = I2C_START; +i2c_status_type i2c_master_transmit_dma(i2c_handle_type *hi2c, uint16_t address, uint8_t *pdata, uint16_t size, uint32_t timeout) { + /* initialization parameters */ + hi2c->mode = I2C_DMA_MA_TX; + hi2c->status = I2C_START; - hi2c->pbuff = pdata; - hi2c->pcount = size; + hi2c->pbuff = pdata; + hi2c->pcount = size; - hi2c->error_code = I2C_OK; + hi2c->error_code = I2C_OK; - /* wait for the busy flag to be reset */ - if(i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) - { - return I2C_ERR_STEP_1; - } + /* wait for the busy flag to be reset */ + if (i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) { + return I2C_ERR_STEP_1; + } - /* disable dma request */ - i2c_dma_enable(hi2c->i2cx, I2C_DMA_REQUEST_TX, FALSE); + /* disable dma request */ + i2c_dma_enable(hi2c->i2cx, I2C_DMA_REQUEST_TX, FALSE); - /* start transfer */ - i2c_start_transfer_dma(hi2c, hi2c->dma_tx_channel, address, I2C_GEN_START_WRITE); + /* start transfer */ + i2c_start_transfer_dma(hi2c, hi2c->dma_tx_channel, address, I2C_GEN_START_WRITE); - /* enable i2c interrupt */ - i2c_interrupt_enable(hi2c->i2cx, I2C_ERR_INT | I2C_ACKFIAL_INT, TRUE); + /* enable i2c interrupt */ + i2c_interrupt_enable(hi2c->i2cx, I2C_ERR_INT | I2C_ACKFIAL_INT, TRUE); - /* enable dma request */ - i2c_dma_enable(hi2c->i2cx, I2C_DMA_REQUEST_TX, TRUE); + /* enable dma request */ + i2c_dma_enable(hi2c->i2cx, I2C_DMA_REQUEST_TX, TRUE); - return I2C_OK; + return I2C_OK; } /** @@ -874,39 +801,37 @@ i2c_status_type i2c_master_transmit_dma(i2c_handle_type* hi2c, uint16_t address, * @param timeout: maximum waiting time. * @retval i2c status. */ -i2c_status_type i2c_slave_receive_dma(i2c_handle_type* hi2c, uint8_t* pdata, uint16_t size, uint32_t timeout) -{ - /* initialization parameters */ - hi2c->mode = I2C_DMA_SLA_RX; - hi2c->status = I2C_START; +i2c_status_type i2c_slave_receive_dma(i2c_handle_type *hi2c, uint8_t *pdata, uint16_t size, uint32_t timeout) { + /* initialization parameters */ + hi2c->mode = I2C_DMA_SLA_RX; + hi2c->status = I2C_START; - hi2c->pbuff = pdata; - hi2c->pcount = size; + hi2c->pbuff = pdata; + hi2c->pcount = size; - hi2c->error_code = I2C_OK; + hi2c->error_code = I2C_OK; - /* wait for the busy flag to be reset */ - if(i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) - { - return I2C_ERR_STEP_1; - } + /* wait for the busy flag to be reset */ + if (i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) { + return I2C_ERR_STEP_1; + } - /* disable dma request */ - i2c_dma_enable(hi2c->i2cx, I2C_DMA_REQUEST_RX, FALSE); + /* disable dma request */ + i2c_dma_enable(hi2c->i2cx, I2C_DMA_REQUEST_RX, FALSE); - /* config dma */ - i2c_dma_config(hi2c, hi2c->dma_rx_channel, hi2c->pbuff, size); + /* config dma */ + i2c_dma_config(hi2c, hi2c->dma_rx_channel, hi2c->pbuff, size); - /* enable acknowledge */ - i2c_ack_enable(hi2c->i2cx, TRUE); + /* enable acknowledge */ + i2c_ack_enable(hi2c->i2cx, TRUE); - /* enable i2c interrupt */ - i2c_interrupt_enable(hi2c->i2cx, I2C_ADDR_INT | I2C_STOP_INT | I2C_ACKFIAL_INT | I2C_ERR_INT, TRUE); + /* enable i2c interrupt */ + i2c_interrupt_enable(hi2c->i2cx, I2C_ADDR_INT | I2C_STOP_INT | I2C_ACKFIAL_INT | I2C_ERR_INT, TRUE); - /* enable dma request */ - i2c_dma_enable(hi2c->i2cx, I2C_DMA_REQUEST_RX, TRUE); + /* enable dma request */ + i2c_dma_enable(hi2c->i2cx, I2C_DMA_REQUEST_RX, TRUE); - return I2C_OK; + return I2C_OK; } /** @@ -918,36 +843,34 @@ i2c_status_type i2c_slave_receive_dma(i2c_handle_type* hi2c, uint8_t* pdata, uin * @param timeout: maximum waiting time. * @retval i2c status. */ -i2c_status_type i2c_master_receive_dma(i2c_handle_type* hi2c, uint16_t address, uint8_t* pdata, uint16_t size, uint32_t timeout) -{ - /* initialization parameters */ - hi2c->mode = I2C_DMA_MA_RX; - hi2c->status = I2C_START; +i2c_status_type i2c_master_receive_dma(i2c_handle_type *hi2c, uint16_t address, uint8_t *pdata, uint16_t size, uint32_t timeout) { + /* initialization parameters */ + hi2c->mode = I2C_DMA_MA_RX; + hi2c->status = I2C_START; - hi2c->pbuff = pdata; - hi2c->pcount = size; + hi2c->pbuff = pdata; + hi2c->pcount = size; - hi2c->error_code = I2C_OK; + hi2c->error_code = I2C_OK; - /* wait for the busy flag to be reset */ - if(i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) - { - return I2C_ERR_STEP_1; - } + /* wait for the busy flag to be reset */ + if (i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) { + return I2C_ERR_STEP_1; + } - /* disable dma request */ - i2c_dma_enable(hi2c->i2cx, I2C_DMA_REQUEST_RX, FALSE); + /* disable dma request */ + i2c_dma_enable(hi2c->i2cx, I2C_DMA_REQUEST_RX, FALSE); - /* start transfer */ - i2c_start_transfer_dma(hi2c, hi2c->dma_rx_channel, address, I2C_GEN_START_READ); + /* start transfer */ + i2c_start_transfer_dma(hi2c, hi2c->dma_rx_channel, address, I2C_GEN_START_READ); - /* enable i2c interrupt */ - i2c_interrupt_enable(hi2c->i2cx, I2C_ERR_INT | I2C_ACKFIAL_INT, TRUE); + /* enable i2c interrupt */ + i2c_interrupt_enable(hi2c->i2cx, I2C_ERR_INT | I2C_ACKFIAL_INT, TRUE); - /* enable dma request */ - i2c_dma_enable(hi2c->i2cx, I2C_DMA_REQUEST_RX, TRUE); + /* enable dma request */ + i2c_dma_enable(hi2c->i2cx, I2C_DMA_REQUEST_RX, TRUE); - return I2C_OK; + return I2C_OK; } /** @@ -958,39 +881,37 @@ i2c_status_type i2c_master_receive_dma(i2c_handle_type* hi2c, uint16_t address, * @param timeout: maximum waiting time. * @retval i2c status. */ -i2c_status_type i2c_slave_transmit_dma(i2c_handle_type* hi2c, uint8_t* pdata, uint16_t size, uint32_t timeout) -{ - /* initialization parameters */ - hi2c->mode = I2C_DMA_SLA_TX; - hi2c->status = I2C_START; +i2c_status_type i2c_slave_transmit_dma(i2c_handle_type *hi2c, uint8_t *pdata, uint16_t size, uint32_t timeout) { + /* initialization parameters */ + hi2c->mode = I2C_DMA_SLA_TX; + hi2c->status = I2C_START; - hi2c->pbuff = pdata; - hi2c->pcount = size; + hi2c->pbuff = pdata; + hi2c->pcount = size; - hi2c->error_code = I2C_OK; + hi2c->error_code = I2C_OK; - /* wait for the busy flag to be reset */ - if(i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) - { - return I2C_ERR_STEP_1; - } + /* wait for the busy flag to be reset */ + if (i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) { + return I2C_ERR_STEP_1; + } - /* disable dma request */ - i2c_dma_enable(hi2c->i2cx, I2C_DMA_REQUEST_TX, FALSE); + /* disable dma request */ + i2c_dma_enable(hi2c->i2cx, I2C_DMA_REQUEST_TX, FALSE); - /* config dma */ - i2c_dma_config(hi2c, hi2c->dma_tx_channel, hi2c->pbuff, size); + /* config dma */ + i2c_dma_config(hi2c, hi2c->dma_tx_channel, hi2c->pbuff, size); - /* enable acknowledge */ - i2c_ack_enable(hi2c->i2cx, TRUE); + /* enable acknowledge */ + i2c_ack_enable(hi2c->i2cx, TRUE); - /* enable i2c interrupt */ - i2c_interrupt_enable(hi2c->i2cx, I2C_ADDR_INT | I2C_STOP_INT | I2C_ACKFIAL_INT | I2C_ERR_INT, TRUE); + /* enable i2c interrupt */ + i2c_interrupt_enable(hi2c->i2cx, I2C_ADDR_INT | I2C_STOP_INT | I2C_ACKFIAL_INT | I2C_ERR_INT, TRUE); - /* enable dma request */ - i2c_dma_enable(hi2c->i2cx, I2C_DMA_REQUEST_TX, TRUE); + /* enable dma request */ + i2c_dma_enable(hi2c->i2cx, I2C_DMA_REQUEST_TX, TRUE); - return I2C_OK; + return I2C_OK; } /** @@ -998,40 +919,35 @@ i2c_status_type i2c_slave_transmit_dma(i2c_handle_type* hi2c, uint8_t* pdata, ui * @param hi2c: the handle points to the operation information. * @param mem_address_width: memory address width. * this parameter can be one of the following values: - * - I2C_MEM_ADDR_WIDIH_8: memory address is 8 bit - * - I2C_MEM_ADDR_WIDIH_16: memory address is 16 bit + * - I2C_MEM_ADDR_WIDIH_8: memory address is 8 bit + * - I2C_MEM_ADDR_WIDIH_16: memory address is 16 bit * @param address: memory device address. * @param mem_address: memory address. * @param timeout: maximum waiting time. * @retval i2c status. */ -i2c_status_type i2c_memory_address_send(i2c_handle_type* hi2c, i2c_mem_address_width_type mem_address_width, uint16_t mem_address, int32_t timeout) -{ - i2c_status_type err_code; - - if(mem_address_width == I2C_MEM_ADDR_WIDIH_8) - { - /* send memory address */ - i2c_data_send(hi2c->i2cx, mem_address & 0xFF); - } - else - { - /* send memory address */ - i2c_data_send(hi2c->i2cx, (mem_address >> 8) & 0xFF); - - /* wait for the tdis flag to be set */ - err_code = i2c_wait_flag(hi2c, I2C_TDIS_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout); - - if(err_code != I2C_OK) - { - return err_code; +i2c_status_type i2c_memory_address_send(i2c_handle_type *hi2c, i2c_mem_address_width_type mem_address_width, uint16_t mem_address, int32_t timeout) { + i2c_status_type err_code; + + if (mem_address_width == I2C_MEM_ADDR_WIDIH_8) { + /* send memory address */ + i2c_data_send(hi2c->i2cx, mem_address & 0xFF); + } else { + /* send memory address */ + i2c_data_send(hi2c->i2cx, (mem_address >> 8) & 0xFF); + + /* wait for the tdis flag to be set */ + err_code = i2c_wait_flag(hi2c, I2C_TDIS_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout); + + if (err_code != I2C_OK) { + return err_code; + } + + /* send memory address */ + i2c_data_send(hi2c->i2cx, mem_address & 0xFF); } - - /* send memory address */ - i2c_data_send(hi2c->i2cx, mem_address & 0xFF); - } - - return I2C_OK; + + return I2C_OK; } /** @@ -1039,8 +955,8 @@ i2c_status_type i2c_memory_address_send(i2c_handle_type* hi2c, i2c_mem_address_w * @param hi2c: the handle points to the operation information. * @param mem_address_width: memory address width. * this parameter can be one of the following values: - * - I2C_MEM_ADDR_WIDIH_8: memory address is 8 bit - * - I2C_MEM_ADDR_WIDIH_16: memory address is 16 bit + * - I2C_MEM_ADDR_WIDIH_8: memory address is 8 bit + * - I2C_MEM_ADDR_WIDIH_16: memory address is 16 bit * @param address: memory device address. * @param mem_address: memory address. * @param pdata: data buffer. @@ -1048,77 +964,68 @@ i2c_status_type i2c_memory_address_send(i2c_handle_type* hi2c, i2c_mem_address_w * @param timeout: maximum waiting time. * @retval i2c status. */ -i2c_status_type i2c_memory_write(i2c_handle_type* hi2c, i2c_mem_address_width_type mem_address_width, uint16_t address, uint16_t mem_address, uint8_t* pdata, uint16_t size, uint32_t timeout) -{ - /* initialization parameters */ - hi2c->pbuff = pdata; - hi2c->pcount = size + mem_address_width; +i2c_status_type i2c_memory_write(i2c_handle_type *hi2c, i2c_mem_address_width_type mem_address_width, uint16_t address, uint16_t mem_address, uint8_t *pdata, uint16_t size, uint32_t timeout) { + /* initialization parameters */ + hi2c->pbuff = pdata; + hi2c->pcount = size + mem_address_width; - hi2c->error_code = I2C_OK; + hi2c->error_code = I2C_OK; - /* wait for the busy flag to be reset */ - if (i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) - { - return I2C_ERR_STEP_1; - } + /* wait for the busy flag to be reset */ + if (i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) { + return I2C_ERR_STEP_1; + } - /* start transfer */ - i2c_start_transfer(hi2c, address, I2C_GEN_START_WRITE); + /* start transfer */ + i2c_start_transfer(hi2c, address, I2C_GEN_START_WRITE); - /* wait for the tdis flag to be set */ - if(i2c_wait_flag(hi2c, I2C_TDIS_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK) - { - return I2C_ERR_STEP_2; - } - - /* send memory address */ - if(i2c_memory_address_send(hi2c, mem_address_width, mem_address, timeout) != I2C_OK) - { - return I2C_ERR_STEP_3; - } - - hi2c->psize -= mem_address_width; - hi2c->pcount -= mem_address_width; - - while (hi2c->pcount > 0) - { /* wait for the tdis flag to be set */ - if(i2c_wait_flag(hi2c, I2C_TDIS_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK) - { - return I2C_ERR_STEP_4; + if (i2c_wait_flag(hi2c, I2C_TDIS_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK) { + return I2C_ERR_STEP_2; } - /* send data */ - i2c_data_send(hi2c->i2cx, *hi2c->pbuff++); - hi2c->psize--; - hi2c->pcount--; - - if ((hi2c->psize == 0) && (hi2c->pcount != 0)) - { - /* wait for the tcrld flag to be set */ - if (i2c_wait_flag(hi2c, I2C_TCRLD_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK) - { - return I2C_ERR_STEP_5; - } - - /* continue transfer */ - i2c_start_transfer(hi2c, address, I2C_WITHOUT_START); + /* send memory address */ + if (i2c_memory_address_send(hi2c, mem_address_width, mem_address, timeout) != I2C_OK) { + return I2C_ERR_STEP_3; } - } - /* wait for the stop flag to be set */ - if(i2c_wait_flag(hi2c, I2C_STOPF_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK) - { - return I2C_ERR_STEP_6; - } + hi2c->psize -= mem_address_width; + hi2c->pcount -= mem_address_width; - /* clear stop flag */ - i2c_flag_clear(hi2c->i2cx, I2C_STOPF_FLAG); + while (hi2c->pcount > 0) { + /* wait for the tdis flag to be set */ + if (i2c_wait_flag(hi2c, I2C_TDIS_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK) { + return I2C_ERR_STEP_4; + } - /* reset ctrl2 register */ - i2c_reset_ctrl2_register(hi2c); + /* send data */ + i2c_data_send(hi2c->i2cx, *hi2c->pbuff++); + hi2c->psize--; + hi2c->pcount--; - return I2C_OK; + if ((hi2c->psize == 0) && (hi2c->pcount != 0)) { + /* wait for the tcrld flag to be set */ + if (i2c_wait_flag(hi2c, I2C_TCRLD_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK) { + return I2C_ERR_STEP_5; + } + + /* continue transfer */ + i2c_start_transfer(hi2c, address, I2C_WITHOUT_START); + } + } + + /* wait for the stop flag to be set */ + if (i2c_wait_flag(hi2c, I2C_STOPF_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK) { + return I2C_ERR_STEP_6; + } + + /* clear stop flag */ + i2c_flag_clear(hi2c->i2cx, I2C_STOPF_FLAG); + + /* reset ctrl2 register */ + i2c_reset_ctrl2_register(hi2c); + + return I2C_OK; } /** @@ -1126,8 +1033,8 @@ i2c_status_type i2c_memory_write(i2c_handle_type* hi2c, i2c_mem_address_width_ty * @param hi2c: the handle points to the operation information. * @param mem_address_width: memory address width. * this parameter can be one of the following values: - * - I2C_MEM_ADDR_WIDIH_8: memory address is 8 bit - * - I2C_MEM_ADDR_WIDIH_16: memory address is 16 bit + * - I2C_MEM_ADDR_WIDIH_8: memory address is 8 bit + * - I2C_MEM_ADDR_WIDIH_16: memory address is 16 bit * @param address: memory device address. * @param mem_address: memory address. * @param pdata: data buffer. @@ -1135,83 +1042,73 @@ i2c_status_type i2c_memory_write(i2c_handle_type* hi2c, i2c_mem_address_width_ty * @param timeout: maximum waiting time. * @retval i2c status. */ -i2c_status_type i2c_memory_read(i2c_handle_type* hi2c, i2c_mem_address_width_type mem_address_width, uint16_t address, uint16_t mem_address, uint8_t* pdata, uint16_t size, uint32_t timeout) -{ - /* initialization parameters */ - hi2c->pbuff = pdata; - hi2c->pcount = size; +i2c_status_type i2c_memory_read(i2c_handle_type *hi2c, i2c_mem_address_width_type mem_address_width, uint16_t address, uint16_t mem_address, uint8_t *pdata, uint16_t size, uint32_t timeout) { + /* initialization parameters */ + hi2c->pbuff = pdata; + hi2c->pcount = size; - hi2c->error_code = I2C_OK; + hi2c->error_code = I2C_OK; - /* wait for the busy flag to be reset */ - if(i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) - { - return I2C_ERR_STEP_1; - } - - /* start transfer */ - i2c_transmit_set(hi2c->i2cx, address, mem_address_width, I2C_SOFT_STOP_MODE, I2C_GEN_START_WRITE); - - /* wait for the tdis flag to be set */ - if(i2c_wait_flag(hi2c, I2C_TDIS_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK) - { - return I2C_ERR_STEP_2; - } - - /* send memory address */ - if(i2c_memory_address_send(hi2c, mem_address_width, mem_address, timeout) != I2C_OK) - { - return I2C_ERR_STEP_3; - } - - /* wait for the tdc flag to be set */ - if (i2c_wait_flag(hi2c, I2C_TDC_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) - { - return I2C_ERR_STEP_4; - } - - /* start transfer */ - i2c_start_transfer(hi2c, address, I2C_GEN_START_READ); - - while (hi2c->pcount > 0) - { - /* wait for the rdbf flag to be set */ - if (i2c_wait_flag(hi2c, I2C_RDBF_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK) - { - return I2C_ERR_STEP_5; + /* wait for the busy flag to be reset */ + if (i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) { + return I2C_ERR_STEP_1; } - /* read data */ - (*hi2c->pbuff++) = i2c_data_receive(hi2c->i2cx); - hi2c->pcount--; - hi2c->psize--; + /* start transfer */ + i2c_transmit_set(hi2c->i2cx, address, mem_address_width, I2C_SOFT_STOP_MODE, I2C_GEN_START_WRITE); - if ((hi2c->psize == 0) && (hi2c->pcount != 0)) - { - /* wait for the tcrld flag to be set */ - if (i2c_wait_flag(hi2c, I2C_TCRLD_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) - { - return I2C_ERR_STEP_6; - } - - /* continue transfer */ - i2c_start_transfer(hi2c, address, I2C_WITHOUT_START); + /* wait for the tdis flag to be set */ + if (i2c_wait_flag(hi2c, I2C_TDIS_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK) { + return I2C_ERR_STEP_2; } - } - /* wait for the stop flag to be set */ - if (i2c_wait_flag(hi2c, I2C_STOPF_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK) - { - return I2C_ERR_STEP_7; - } + /* send memory address */ + if (i2c_memory_address_send(hi2c, mem_address_width, mem_address, timeout) != I2C_OK) { + return I2C_ERR_STEP_3; + } - /* clear stop flag */ - i2c_flag_clear(hi2c->i2cx, I2C_STOPF_FLAG); + /* wait for the tdc flag to be set */ + if (i2c_wait_flag(hi2c, I2C_TDC_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) { + return I2C_ERR_STEP_4; + } - /* reset ctrl2 register */ - i2c_reset_ctrl2_register(hi2c); + /* start transfer */ + i2c_start_transfer(hi2c, address, I2C_GEN_START_READ); - return I2C_OK; + while (hi2c->pcount > 0) { + /* wait for the rdbf flag to be set */ + if (i2c_wait_flag(hi2c, I2C_RDBF_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK) { + return I2C_ERR_STEP_5; + } + + /* read data */ + (*hi2c->pbuff++) = i2c_data_receive(hi2c->i2cx); + hi2c->pcount--; + hi2c->psize--; + + if ((hi2c->psize == 0) && (hi2c->pcount != 0)) { + /* wait for the tcrld flag to be set */ + if (i2c_wait_flag(hi2c, I2C_TCRLD_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) { + return I2C_ERR_STEP_6; + } + + /* continue transfer */ + i2c_start_transfer(hi2c, address, I2C_WITHOUT_START); + } + } + + /* wait for the stop flag to be set */ + if (i2c_wait_flag(hi2c, I2C_STOPF_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK) { + return I2C_ERR_STEP_7; + } + + /* clear stop flag */ + i2c_flag_clear(hi2c->i2cx, I2C_STOPF_FLAG); + + /* reset ctrl2 register */ + i2c_reset_ctrl2_register(hi2c); + + return I2C_OK; } /** @@ -1219,8 +1116,8 @@ i2c_status_type i2c_memory_read(i2c_handle_type* hi2c, i2c_mem_address_width_typ * @param hi2c: the handle points to the operation information. * @param mem_address_width: memory address width. * this parameter can be one of the following values: - * - I2C_MEM_ADDR_WIDIH_8: memory address is 8 bit - * - I2C_MEM_ADDR_WIDIH_16: memory address is 16 bit + * - I2C_MEM_ADDR_WIDIH_8: memory address is 8 bit + * - I2C_MEM_ADDR_WIDIH_16: memory address is 16 bit * @param address: memory device address. * @param mem_address: memory address. * @param pdata: data buffer. @@ -1228,45 +1125,41 @@ i2c_status_type i2c_memory_read(i2c_handle_type* hi2c, i2c_mem_address_width_typ * @param timeout: maximum waiting time. * @retval i2c status. */ -i2c_status_type i2c_memory_write_int(i2c_handle_type* hi2c, i2c_mem_address_width_type mem_address_width, uint16_t address, uint16_t mem_address, uint8_t* pdata, uint16_t size, uint32_t timeout) -{ - /* initialization parameters */ - hi2c->mode = I2C_INT_MA_TX; - hi2c->status = I2C_START; +i2c_status_type i2c_memory_write_int(i2c_handle_type *hi2c, i2c_mem_address_width_type mem_address_width, uint16_t address, uint16_t mem_address, uint8_t *pdata, uint16_t size, uint32_t timeout) { + /* initialization parameters */ + hi2c->mode = I2C_INT_MA_TX; + hi2c->status = I2C_START; - hi2c->pbuff = pdata; - hi2c->pcount = size + mem_address_width; + hi2c->pbuff = pdata; + hi2c->pcount = size + mem_address_width; - hi2c->error_code = I2C_OK; + hi2c->error_code = I2C_OK; - /* wait for the busy flag to be reset */ - if (i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) - { - return I2C_ERR_STEP_1; - } + /* wait for the busy flag to be reset */ + if (i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) { + return I2C_ERR_STEP_1; + } - /* start transfer */ - i2c_start_transfer(hi2c, address, I2C_GEN_START_WRITE); + /* start transfer */ + i2c_start_transfer(hi2c, address, I2C_GEN_START_WRITE); - /* wait for the tdis flag to be set */ - if(i2c_wait_flag(hi2c, I2C_TDIS_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK) - { - return I2C_ERR_STEP_2; - } + /* wait for the tdis flag to be set */ + if (i2c_wait_flag(hi2c, I2C_TDIS_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK) { + return I2C_ERR_STEP_2; + } - /* send memory address */ - if(i2c_memory_address_send(hi2c, mem_address_width, mem_address, timeout) != I2C_OK) - { - return I2C_ERR_STEP_3; - } - - hi2c->psize--; - hi2c->pcount--; + /* send memory address */ + if (i2c_memory_address_send(hi2c, mem_address_width, mem_address, timeout) != I2C_OK) { + return I2C_ERR_STEP_3; + } - /* enable interrupt */ - i2c_interrupt_enable(hi2c->i2cx, I2C_ERR_INT | I2C_TDC_INT | I2C_STOP_INT | I2C_ACKFIAL_INT | I2C_TD_INT, TRUE); + hi2c->psize--; + hi2c->pcount--; - return I2C_OK; + /* enable interrupt */ + i2c_interrupt_enable(hi2c->i2cx, I2C_ERR_INT | I2C_TDC_INT | I2C_STOP_INT | I2C_ACKFIAL_INT | I2C_TD_INT, TRUE); + + return I2C_OK; } /** @@ -1274,8 +1167,8 @@ i2c_status_type i2c_memory_write_int(i2c_handle_type* hi2c, i2c_mem_address_widt * @param hi2c: the handle points to the operation information. * @param mem_address_width: memory address width. * this parameter can be one of the following values: - * - I2C_MEM_ADDR_WIDIH_8: memory address is 8 bit - * - I2C_MEM_ADDR_WIDIH_16: memory address is 16 bit + * - I2C_MEM_ADDR_WIDIH_8: memory address is 8 bit + * - I2C_MEM_ADDR_WIDIH_16: memory address is 16 bit * @param address: memory device address. * @param mem_address: memory address. * @param pdata: data buffer. @@ -1283,51 +1176,46 @@ i2c_status_type i2c_memory_write_int(i2c_handle_type* hi2c, i2c_mem_address_widt * @param timeout: maximum waiting time. * @retval i2c status. */ -i2c_status_type i2c_memory_read_int(i2c_handle_type* hi2c, i2c_mem_address_width_type mem_address_width, uint16_t address, uint16_t mem_address, uint8_t* pdata, uint16_t size, uint32_t timeout) -{ - /* initialization parameters */ - hi2c->mode = I2C_INT_MA_RX; - hi2c->status = I2C_START; +i2c_status_type i2c_memory_read_int(i2c_handle_type *hi2c, i2c_mem_address_width_type mem_address_width, uint16_t address, uint16_t mem_address, uint8_t *pdata, uint16_t size, uint32_t timeout) { + /* initialization parameters */ + hi2c->mode = I2C_INT_MA_RX; + hi2c->status = I2C_START; - hi2c->pbuff = pdata; - hi2c->pcount = size; + hi2c->pbuff = pdata; + hi2c->pcount = size; - hi2c->error_code = I2C_OK; + hi2c->error_code = I2C_OK; - /* wait for the busy flag to be reset */ - if(i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) - { - return I2C_ERR_STEP_1; - } + /* wait for the busy flag to be reset */ + if (i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) { + return I2C_ERR_STEP_1; + } - /* start transfer */ - i2c_transmit_set(hi2c->i2cx, address, mem_address_width, I2C_SOFT_STOP_MODE, I2C_GEN_START_WRITE); + /* start transfer */ + i2c_transmit_set(hi2c->i2cx, address, mem_address_width, I2C_SOFT_STOP_MODE, I2C_GEN_START_WRITE); - /* wait for the tdis flag to be set */ - if(i2c_wait_flag(hi2c, I2C_TDIS_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK) - { - return I2C_ERR_STEP_2; - } + /* wait for the tdis flag to be set */ + if (i2c_wait_flag(hi2c, I2C_TDIS_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK) { + return I2C_ERR_STEP_2; + } - /* send memory address */ - if(i2c_memory_address_send(hi2c, mem_address_width, mem_address, timeout) != I2C_OK) - { - return I2C_ERR_STEP_3; - } + /* send memory address */ + if (i2c_memory_address_send(hi2c, mem_address_width, mem_address, timeout) != I2C_OK) { + return I2C_ERR_STEP_3; + } - /* wait for the tdc flag to be set */ - if (i2c_wait_flag(hi2c, I2C_TDC_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) - { - return I2C_ERR_STEP_4; - } + /* wait for the tdc flag to be set */ + if (i2c_wait_flag(hi2c, I2C_TDC_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) { + return I2C_ERR_STEP_4; + } - /* start transfer */ - i2c_start_transfer(hi2c, address, I2C_GEN_START_READ); + /* start transfer */ + i2c_start_transfer(hi2c, address, I2C_GEN_START_READ); - /* enable i2c interrupt */ - i2c_interrupt_enable(hi2c->i2cx, I2C_ERR_INT | I2C_TDC_INT | I2C_STOP_INT | I2C_ACKFIAL_INT | I2C_RD_INT, TRUE); + /* enable i2c interrupt */ + i2c_interrupt_enable(hi2c->i2cx, I2C_ERR_INT | I2C_TDC_INT | I2C_STOP_INT | I2C_ACKFIAL_INT | I2C_RD_INT, TRUE); - return I2C_OK; + return I2C_OK; } /** @@ -1335,8 +1223,8 @@ i2c_status_type i2c_memory_read_int(i2c_handle_type* hi2c, i2c_mem_address_width * @param hi2c: the handle points to the operation information. * @param mem_address_width: memory address width. * this parameter can be one of the following values: - * - I2C_MEM_ADDR_WIDIH_8: memory address is 8 bit - * - I2C_MEM_ADDR_WIDIH_16: memory address is 16 bit + * - I2C_MEM_ADDR_WIDIH_8: memory address is 8 bit + * - I2C_MEM_ADDR_WIDIH_16: memory address is 16 bit * @param address: memory device address. * @param mem_address: memory address. * @param pdata: data buffer. @@ -1344,57 +1232,52 @@ i2c_status_type i2c_memory_read_int(i2c_handle_type* hi2c, i2c_mem_address_width * @param timeout: maximum waiting time. * @retval i2c status. */ -i2c_status_type i2c_memory_write_dma(i2c_handle_type* hi2c, i2c_mem_address_width_type mem_address_width, uint16_t address, uint16_t mem_address, uint8_t* pdata, uint16_t size, uint32_t timeout) -{ - /* initialization parameters */ - hi2c->mode = I2C_DMA_MA_TX; - hi2c->status = I2C_START; +i2c_status_type i2c_memory_write_dma(i2c_handle_type *hi2c, i2c_mem_address_width_type mem_address_width, uint16_t address, uint16_t mem_address, uint8_t *pdata, uint16_t size, uint32_t timeout) { + /* initialization parameters */ + hi2c->mode = I2C_DMA_MA_TX; + hi2c->status = I2C_START; - hi2c->pbuff = pdata; - hi2c->pcount = size; + hi2c->pbuff = pdata; + hi2c->pcount = size; - hi2c->error_code = I2C_OK; + hi2c->error_code = I2C_OK; - /* disable dma request */ - i2c_dma_enable(hi2c->i2cx, I2C_DMA_REQUEST_TX, FALSE); + /* disable dma request */ + i2c_dma_enable(hi2c->i2cx, I2C_DMA_REQUEST_TX, FALSE); - /* wait for the busy flag to be reset */ - if(i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) - { - return I2C_ERR_STEP_1; - } + /* wait for the busy flag to be reset */ + if (i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) { + return I2C_ERR_STEP_1; + } - /* transfer config */ - i2c_transmit_set(hi2c->i2cx, address, mem_address_width, I2C_RELOAD_MODE, I2C_GEN_START_WRITE); + /* transfer config */ + i2c_transmit_set(hi2c->i2cx, address, mem_address_width, I2C_RELOAD_MODE, I2C_GEN_START_WRITE); - /* wait for the tdis flag to be set */ - if(i2c_wait_flag(hi2c, I2C_TDIS_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK) - { - return I2C_ERR_STEP_2; - } + /* wait for the tdis flag to be set */ + if (i2c_wait_flag(hi2c, I2C_TDIS_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK) { + return I2C_ERR_STEP_2; + } - /* send memory address */ - if(i2c_memory_address_send(hi2c, mem_address_width, mem_address, timeout) != I2C_OK) - { - return I2C_ERR_STEP_3; - } + /* send memory address */ + if (i2c_memory_address_send(hi2c, mem_address_width, mem_address, timeout) != I2C_OK) { + return I2C_ERR_STEP_3; + } - /* wait for the tcrld flag to be set */ - if (i2c_wait_flag(hi2c, I2C_TCRLD_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) - { - return I2C_ERR_STEP_4; - } + /* wait for the tcrld flag to be set */ + if (i2c_wait_flag(hi2c, I2C_TCRLD_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) { + return I2C_ERR_STEP_4; + } - /* start transfer */ - i2c_start_transfer_dma(hi2c, hi2c->dma_tx_channel, address, I2C_WITHOUT_START); + /* start transfer */ + i2c_start_transfer_dma(hi2c, hi2c->dma_tx_channel, address, I2C_WITHOUT_START); - /* enable i2c interrupt */ - i2c_interrupt_enable(hi2c->i2cx, I2C_ERR_INT | I2C_ACKFIAL_INT, TRUE); + /* enable i2c interrupt */ + i2c_interrupt_enable(hi2c->i2cx, I2C_ERR_INT | I2C_ACKFIAL_INT, TRUE); - /* enable dma request */ - i2c_dma_enable(hi2c->i2cx, I2C_DMA_REQUEST_TX, TRUE); + /* enable dma request */ + i2c_dma_enable(hi2c->i2cx, I2C_DMA_REQUEST_TX, TRUE); - return I2C_OK; + return I2C_OK; } /** @@ -1402,8 +1285,8 @@ i2c_status_type i2c_memory_write_dma(i2c_handle_type* hi2c, i2c_mem_address_widt * @param hi2c: the handle points to the operation information. * @param mem_address_width: memory address width. * this parameter can be one of the following values: - * - I2C_MEM_ADDR_WIDIH_8: memory address is 8 bit - * - I2C_MEM_ADDR_WIDIH_16: memory address is 16 bit + * - I2C_MEM_ADDR_WIDIH_8: memory address is 8 bit + * - I2C_MEM_ADDR_WIDIH_16: memory address is 16 bit * @param address: memory device address. * @param mem_address: memory address. * @param pdata: data buffer. @@ -1411,57 +1294,52 @@ i2c_status_type i2c_memory_write_dma(i2c_handle_type* hi2c, i2c_mem_address_widt * @param timeout: maximum waiting time. * @retval i2c status. */ -i2c_status_type i2c_memory_read_dma(i2c_handle_type* hi2c, i2c_mem_address_width_type mem_address_width, uint16_t address, uint16_t mem_address, uint8_t* pdata, uint16_t size, uint32_t timeout) -{ - /* initialization parameters */ - hi2c->mode = I2C_DMA_MA_RX; - hi2c->status = I2C_START; +i2c_status_type i2c_memory_read_dma(i2c_handle_type *hi2c, i2c_mem_address_width_type mem_address_width, uint16_t address, uint16_t mem_address, uint8_t *pdata, uint16_t size, uint32_t timeout) { + /* initialization parameters */ + hi2c->mode = I2C_DMA_MA_RX; + hi2c->status = I2C_START; - hi2c->pbuff = pdata; - hi2c->pcount = size; + hi2c->pbuff = pdata; + hi2c->pcount = size; - hi2c->error_code = I2C_OK; + hi2c->error_code = I2C_OK; - /* wait for the busy flag to be reset */ - if(i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) - { - return I2C_ERR_STEP_1; - } + /* wait for the busy flag to be reset */ + if (i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) { + return I2C_ERR_STEP_1; + } - /* start transfer */ - i2c_transmit_set(hi2c->i2cx, address, mem_address_width, I2C_SOFT_STOP_MODE, I2C_GEN_START_WRITE); + /* start transfer */ + i2c_transmit_set(hi2c->i2cx, address, mem_address_width, I2C_SOFT_STOP_MODE, I2C_GEN_START_WRITE); - /* wait for the tdis flag to be set */ - if(i2c_wait_flag(hi2c, I2C_TDIS_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK) - { - return I2C_ERR_STEP_2; - } + /* wait for the tdis flag to be set */ + if (i2c_wait_flag(hi2c, I2C_TDIS_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK) { + return I2C_ERR_STEP_2; + } - /* send memory address */ - if(i2c_memory_address_send(hi2c, mem_address_width, mem_address, timeout) != I2C_OK) - { - return I2C_ERR_STEP_3; - } + /* send memory address */ + if (i2c_memory_address_send(hi2c, mem_address_width, mem_address, timeout) != I2C_OK) { + return I2C_ERR_STEP_3; + } - /* wait for the tdc flag to be set */ - if (i2c_wait_flag(hi2c, I2C_TDC_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) - { - return I2C_ERR_STEP_4; - } + /* wait for the tdc flag to be set */ + if (i2c_wait_flag(hi2c, I2C_TDC_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) { + return I2C_ERR_STEP_4; + } - /* disable dma request */ - i2c_dma_enable(hi2c->i2cx, I2C_DMA_REQUEST_RX, FALSE); + /* disable dma request */ + i2c_dma_enable(hi2c->i2cx, I2C_DMA_REQUEST_RX, FALSE); - /* start transfer */ - i2c_start_transfer_dma(hi2c, hi2c->dma_rx_channel, address, I2C_GEN_START_READ); + /* start transfer */ + i2c_start_transfer_dma(hi2c, hi2c->dma_rx_channel, address, I2C_GEN_START_READ); - /* enable i2c interrupt */ - i2c_interrupt_enable(hi2c->i2cx, I2C_ERR_INT | I2C_ACKFIAL_INT, TRUE); + /* enable i2c interrupt */ + i2c_interrupt_enable(hi2c->i2cx, I2C_ERR_INT | I2C_ACKFIAL_INT, TRUE); - /* enable dma request */ - i2c_dma_enable(hi2c->i2cx, I2C_DMA_REQUEST_RX, TRUE); + /* enable dma request */ + i2c_dma_enable(hi2c->i2cx, I2C_DMA_REQUEST_RX, TRUE); - return I2C_OK; + return I2C_OK; } /** @@ -1473,70 +1351,63 @@ i2c_status_type i2c_memory_read_dma(i2c_handle_type* hi2c, i2c_mem_address_width * @param timeout: maximum waiting time. * @retval i2c status. */ -i2c_status_type i2c_smbus_master_transmit(i2c_handle_type* hi2c, uint16_t address, uint8_t* pdata, uint16_t size, uint32_t timeout) -{ - /* initialization parameters */ - hi2c->pbuff = pdata; - hi2c->pcount = size; +i2c_status_type i2c_smbus_master_transmit(i2c_handle_type *hi2c, uint16_t address, uint8_t *pdata, uint16_t size, uint32_t timeout) { + /* initialization parameters */ + hi2c->pbuff = pdata; + hi2c->pcount = size; - hi2c->error_code = I2C_OK; + hi2c->error_code = I2C_OK; - /* wait for the busy flag to be reset */ - if (i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) - { - return I2C_ERR_STEP_1; - } - - /* enable pec calculation */ - i2c_pec_calculate_enable(hi2c->i2cx, TRUE); - - /* enable pec transmit request */ - i2c_pec_transmit_enable(hi2c->i2cx, TRUE); - - /* start transfer */ - i2c_start_transfer(hi2c, address, I2C_GEN_START_WRITE); - - hi2c->pcount--; - - while (hi2c->pcount > 0) - { - /* wait for the tdis flag to be set */ - if(i2c_wait_flag(hi2c, I2C_TDIS_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK) - { - return I2C_ERR_STEP_2; + /* wait for the busy flag to be reset */ + if (i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) { + return I2C_ERR_STEP_1; } - /* send data */ - i2c_data_send(hi2c->i2cx, *hi2c->pbuff++); - hi2c->psize--; + /* enable pec calculation */ + i2c_pec_calculate_enable(hi2c->i2cx, TRUE); + + /* enable pec transmit request */ + i2c_pec_transmit_enable(hi2c->i2cx, TRUE); + + /* start transfer */ + i2c_start_transfer(hi2c, address, I2C_GEN_START_WRITE); + hi2c->pcount--; - if ((hi2c->psize == 0) && (hi2c->pcount != 0)) - { - /* wait for the tcrld flag to be set */ - if (i2c_wait_flag(hi2c, I2C_TCRLD_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK) - { - return I2C_ERR_STEP_3; - } + while (hi2c->pcount > 0) { + /* wait for the tdis flag to be set */ + if (i2c_wait_flag(hi2c, I2C_TDIS_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK) { + return I2C_ERR_STEP_2; + } - /* continue transfer */ - i2c_start_transfer(hi2c, address, I2C_WITHOUT_START); + /* send data */ + i2c_data_send(hi2c->i2cx, *hi2c->pbuff++); + hi2c->psize--; + hi2c->pcount--; + + if ((hi2c->psize == 0) && (hi2c->pcount != 0)) { + /* wait for the tcrld flag to be set */ + if (i2c_wait_flag(hi2c, I2C_TCRLD_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK) { + return I2C_ERR_STEP_3; + } + + /* continue transfer */ + i2c_start_transfer(hi2c, address, I2C_WITHOUT_START); + } } - } - /* wait for the stop flag to be set */ - if(i2c_wait_flag(hi2c, I2C_STOPF_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK) - { - return I2C_ERR_STEP_4; - } + /* wait for the stop flag to be set */ + if (i2c_wait_flag(hi2c, I2C_STOPF_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK) { + return I2C_ERR_STEP_4; + } - /* clear stop flag */ - i2c_flag_clear(hi2c->i2cx, I2C_STOPF_FLAG); + /* clear stop flag */ + i2c_flag_clear(hi2c->i2cx, I2C_STOPF_FLAG); - /* reset ctrl2 register */ - i2c_reset_ctrl2_register(hi2c); + /* reset ctrl2 register */ + i2c_reset_ctrl2_register(hi2c); - return I2C_OK; + return I2C_OK; } /** @@ -1547,87 +1418,80 @@ i2c_status_type i2c_smbus_master_transmit(i2c_handle_type* hi2c, uint16_t addres * @param timeout: maximum waiting time. * @retval i2c status. */ -i2c_status_type i2c_smbus_slave_receive(i2c_handle_type* hi2c, uint8_t* pdata, uint16_t size, uint32_t timeout) -{ - /* initialization parameters */ - hi2c->pbuff = pdata; - hi2c->pcount = size; +i2c_status_type i2c_smbus_slave_receive(i2c_handle_type *hi2c, uint8_t *pdata, uint16_t size, uint32_t timeout) { + /* initialization parameters */ + hi2c->pbuff = pdata; + hi2c->pcount = size; - hi2c->error_code = I2C_OK; + hi2c->error_code = I2C_OK; - /* enable pec calculation */ - i2c_pec_calculate_enable(hi2c->i2cx, TRUE); + /* enable pec calculation */ + i2c_pec_calculate_enable(hi2c->i2cx, TRUE); - /* enable slave data control mode */ - i2c_slave_data_ctrl_enable(hi2c->i2cx, TRUE); + /* enable slave data control mode */ + i2c_slave_data_ctrl_enable(hi2c->i2cx, TRUE); - /* enable acknowledge */ - i2c_ack_enable(hi2c->i2cx, TRUE); + /* enable acknowledge */ + i2c_ack_enable(hi2c->i2cx, TRUE); - /* wait for the addr flag to be set */ - if (i2c_wait_flag(hi2c, I2C_ADDRF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) - { - return I2C_ERR_STEP_1; - } + /* wait for the addr flag to be set */ + if (i2c_wait_flag(hi2c, I2C_ADDRF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) { + return I2C_ERR_STEP_1; + } - /* enable pec transmit request */ - i2c_pec_transmit_enable(hi2c->i2cx, TRUE); + /* enable pec transmit request */ + i2c_pec_transmit_enable(hi2c->i2cx, TRUE); - /* configure the number of bytes to be transmitted */ - i2c_cnt_set(hi2c->i2cx, hi2c->pcount); + /* configure the number of bytes to be transmitted */ + i2c_cnt_set(hi2c->i2cx, hi2c->pcount); - /* clear addr flag */ - i2c_flag_clear(hi2c->i2cx, I2C_ADDRF_FLAG); + /* clear addr flag */ + i2c_flag_clear(hi2c->i2cx, I2C_ADDRF_FLAG); - while (hi2c->pcount > 0) - { - /* wait for the rdbf flag to be set */ - if(i2c_wait_flag(hi2c, I2C_RDBF_FLAG, I2C_EVENT_CHECK_STOP, timeout) != I2C_OK) - { - /* disable acknowledge */ - i2c_ack_enable(hi2c->i2cx, FALSE); + while (hi2c->pcount > 0) { + /* wait for the rdbf flag to be set */ + if (i2c_wait_flag(hi2c, I2C_RDBF_FLAG, I2C_EVENT_CHECK_STOP, timeout) != I2C_OK) { + /* disable acknowledge */ + i2c_ack_enable(hi2c->i2cx, FALSE); + + /* if data is received, read data */ + if (i2c_flag_get(hi2c->i2cx, I2C_RDBF_FLAG) == SET) { + /* read data */ + (*hi2c->pbuff++) = i2c_data_receive(hi2c->i2cx); + hi2c->pcount--; + } + + return I2C_ERR_STEP_3; + } - /* if data is received, read data */ - if (i2c_flag_get(hi2c->i2cx, I2C_RDBF_FLAG) == SET) - { /* read data */ (*hi2c->pbuff++) = i2c_data_receive(hi2c->i2cx); hi2c->pcount--; - } - - return I2C_ERR_STEP_3; } - /* read data */ - (*hi2c->pbuff++) = i2c_data_receive(hi2c->i2cx); - hi2c->pcount--; - } + /* wait for the stop flag to be set */ + if (i2c_wait_flag(hi2c, I2C_STOPF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) { + /* disable acknowledge */ + i2c_ack_enable(hi2c->i2cx, FALSE); - /* wait for the stop flag to be set */ - if(i2c_wait_flag(hi2c, I2C_STOPF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) - { - /* disable acknowledge */ - i2c_ack_enable(hi2c->i2cx, FALSE); + return I2C_ERR_STEP_4; + } - return I2C_ERR_STEP_4; - } + /* clear stop flag */ + i2c_flag_clear(hi2c->i2cx, I2C_STOPF_FLAG); - /* clear stop flag */ - i2c_flag_clear(hi2c->i2cx, I2C_STOPF_FLAG); + /* wait for the busy flag to be reset */ + if (i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) { + /* disable acknowledge */ + i2c_ack_enable(hi2c->i2cx, FALSE); - /* wait for the busy flag to be reset */ - if (i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) - { - /* disable acknowledge */ - i2c_ack_enable(hi2c->i2cx, FALSE); + return I2C_ERR_STEP_5; + } - return I2C_ERR_STEP_5; - } + /* disable slave data control mode */ + i2c_slave_data_ctrl_enable(hi2c->i2cx, FALSE); - /* disable slave data control mode */ - i2c_slave_data_ctrl_enable(hi2c->i2cx, FALSE); - - return I2C_OK; + return I2C_OK; } /** @@ -1639,68 +1503,61 @@ i2c_status_type i2c_smbus_slave_receive(i2c_handle_type* hi2c, uint8_t* pdata, u * @param timeout: maximum waiting time. * @retval i2c status. */ -i2c_status_type i2c_smbus_master_receive(i2c_handle_type* hi2c, uint16_t address, uint8_t* pdata, uint16_t size, uint32_t timeout) -{ - /* initialization parameters */ - hi2c->pbuff = pdata; - hi2c->pcount = size; +i2c_status_type i2c_smbus_master_receive(i2c_handle_type *hi2c, uint16_t address, uint8_t *pdata, uint16_t size, uint32_t timeout) { + /* initialization parameters */ + hi2c->pbuff = pdata; + hi2c->pcount = size; - hi2c->error_code = I2C_OK; + hi2c->error_code = I2C_OK; - /* wait for the busy flag to be reset */ - if (i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) - { - return I2C_ERR_STEP_1; - } - - /* enable pec calculation */ - i2c_pec_calculate_enable(hi2c->i2cx, TRUE); - - /* enable pec transmit request */ - i2c_pec_transmit_enable(hi2c->i2cx, TRUE); - - /* start transfer */ - i2c_start_transfer(hi2c, address, I2C_GEN_START_READ); - - while (hi2c->pcount > 0) - { - /* wait for the rdbf flag to be set */ - if(i2c_wait_flag(hi2c, I2C_RDBF_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK) - { - return I2C_ERR_STEP_2; + /* wait for the busy flag to be reset */ + if (i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) { + return I2C_ERR_STEP_1; } - /* read data */ - (*hi2c->pbuff++) = i2c_data_receive(hi2c->i2cx); - hi2c->pcount--; - hi2c->psize--; + /* enable pec calculation */ + i2c_pec_calculate_enable(hi2c->i2cx, TRUE); - if ((hi2c->psize == 0) && (hi2c->pcount != 0)) - { - /* wait for the tcrld flag to be set */ - if (i2c_wait_flag(hi2c, I2C_TCRLD_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) - { - return I2C_ERR_STEP_3; - } + /* enable pec transmit request */ + i2c_pec_transmit_enable(hi2c->i2cx, TRUE); - /* continue transfer */ - i2c_start_transfer(hi2c, address, I2C_WITHOUT_START); + /* start transfer */ + i2c_start_transfer(hi2c, address, I2C_GEN_START_READ); + + while (hi2c->pcount > 0) { + /* wait for the rdbf flag to be set */ + if (i2c_wait_flag(hi2c, I2C_RDBF_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK) { + return I2C_ERR_STEP_2; + } + + /* read data */ + (*hi2c->pbuff++) = i2c_data_receive(hi2c->i2cx); + hi2c->pcount--; + hi2c->psize--; + + if ((hi2c->psize == 0) && (hi2c->pcount != 0)) { + /* wait for the tcrld flag to be set */ + if (i2c_wait_flag(hi2c, I2C_TCRLD_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) { + return I2C_ERR_STEP_3; + } + + /* continue transfer */ + i2c_start_transfer(hi2c, address, I2C_WITHOUT_START); + } } - } - /* wait for the stop flag to be set */ - if(i2c_wait_flag(hi2c, I2C_STOPF_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK) - { - return I2C_ERR_STEP_4; - } + /* wait for the stop flag to be set */ + if (i2c_wait_flag(hi2c, I2C_STOPF_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK) { + return I2C_ERR_STEP_4; + } - /* clear stop flag */ - i2c_flag_clear(hi2c->i2cx, I2C_STOPF_FLAG); + /* clear stop flag */ + i2c_flag_clear(hi2c->i2cx, I2C_STOPF_FLAG); - /* reset ctrl2 register */ - i2c_reset_ctrl2_register(hi2c); + /* reset ctrl2 register */ + i2c_reset_ctrl2_register(hi2c); - return I2C_OK; + return I2C_OK; } /** @@ -1711,124 +1568,114 @@ i2c_status_type i2c_smbus_master_receive(i2c_handle_type* hi2c, uint16_t address * @param timeout: maximum waiting time. * @retval i2c status. */ -i2c_status_type i2c_smbus_slave_transmit(i2c_handle_type* hi2c, uint8_t* pdata, uint16_t size, uint32_t timeout) -{ - /* initialization parameters */ - hi2c->pbuff = pdata; - hi2c->pcount = size; +i2c_status_type i2c_smbus_slave_transmit(i2c_handle_type *hi2c, uint8_t *pdata, uint16_t size, uint32_t timeout) { + /* initialization parameters */ + hi2c->pbuff = pdata; + hi2c->pcount = size; - hi2c->error_code = I2C_OK; + hi2c->error_code = I2C_OK; - /* enable pec calculation */ - i2c_pec_calculate_enable(hi2c->i2cx, TRUE); + /* enable pec calculation */ + i2c_pec_calculate_enable(hi2c->i2cx, TRUE); - /* enable slave data control mode */ - i2c_slave_data_ctrl_enable(hi2c->i2cx, TRUE); + /* enable slave data control mode */ + i2c_slave_data_ctrl_enable(hi2c->i2cx, TRUE); - /* enable acknowledge */ - i2c_ack_enable(hi2c->i2cx, TRUE); + /* enable acknowledge */ + i2c_ack_enable(hi2c->i2cx, TRUE); - /* wait for the addr flag to be set */ - if (i2c_wait_flag(hi2c, I2C_ADDRF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) - { - /* disable acknowledge */ - i2c_ack_enable(hi2c->i2cx, FALSE); - return I2C_ERR_STEP_1; - } - - /* if 7-bit address mode is selected */ - if (hi2c->i2cx->ctrl2_bit.addr10 == 0) - { - /* enable pec transmit request */ - i2c_pec_transmit_enable(hi2c->i2cx, TRUE); - - /* configure the number of bytes to be transmitted */ - i2c_cnt_set(hi2c->i2cx, hi2c->pcount); - } - - /* clear addr flag */ - i2c_flag_clear(hi2c->i2cx, I2C_ADDRF_FLAG); - - /* if 10-bit address mode is used */ - if (hi2c->i2cx->ctrl2_bit.addr10 != RESET) - { /* wait for the addr flag to be set */ - if (i2c_wait_flag(hi2c, I2C_ADDRF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) - { - /* disable acknowledge */ - i2c_ack_enable(hi2c->i2cx, FALSE); - - return I2C_ERR_STEP_2; + if (i2c_wait_flag(hi2c, I2C_ADDRF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) { + /* disable acknowledge */ + i2c_ack_enable(hi2c->i2cx, FALSE); + return I2C_ERR_STEP_1; } - /* enable pec transmit request */ - i2c_pec_transmit_enable(hi2c->i2cx, TRUE); + /* if 7-bit address mode is selected */ + if (hi2c->i2cx->ctrl2_bit.addr10 == 0) { + /* enable pec transmit request */ + i2c_pec_transmit_enable(hi2c->i2cx, TRUE); - /* configure the number of bytes to be transmitted */ - i2c_cnt_set(hi2c->i2cx, hi2c->pcount); + /* configure the number of bytes to be transmitted */ + i2c_cnt_set(hi2c->i2cx, hi2c->pcount); + } /* clear addr flag */ i2c_flag_clear(hi2c->i2cx, I2C_ADDRF_FLAG); - } - hi2c->pcount--; + /* if 10-bit address mode is used */ + if (hi2c->i2cx->ctrl2_bit.addr10 != RESET) { + /* wait for the addr flag to be set */ + if (i2c_wait_flag(hi2c, I2C_ADDRF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) { + /* disable acknowledge */ + i2c_ack_enable(hi2c->i2cx, FALSE); - while (hi2c->pcount > 0) - { - /* wait for the tdis flag to be set */ - if(i2c_wait_flag(hi2c, I2C_TDIS_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK) - { - /* disable acknowledge */ - i2c_ack_enable(hi2c->i2cx, FALSE); + return I2C_ERR_STEP_2; + } - return I2C_ERR_STEP_4; + /* enable pec transmit request */ + i2c_pec_transmit_enable(hi2c->i2cx, TRUE); + + /* configure the number of bytes to be transmitted */ + i2c_cnt_set(hi2c->i2cx, hi2c->pcount); + + /* clear addr flag */ + i2c_flag_clear(hi2c->i2cx, I2C_ADDRF_FLAG); } - /* send data */ - i2c_data_send(hi2c->i2cx, *hi2c->pbuff++); hi2c->pcount--; - } - /* wait for the ackfail flag to be set */ - if(i2c_wait_flag(hi2c, I2C_ACKFAIL_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) - { - return I2C_ERR_STEP_5; - } + while (hi2c->pcount > 0) { + /* wait for the tdis flag to be set */ + if (i2c_wait_flag(hi2c, I2C_TDIS_FLAG, I2C_EVENT_CHECK_ACKFAIL, timeout) != I2C_OK) { + /* disable acknowledge */ + i2c_ack_enable(hi2c->i2cx, FALSE); - /* clear ack fail flag */ - i2c_flag_clear(hi2c->i2cx, I2C_ACKFAIL_FLAG); + return I2C_ERR_STEP_4; + } - /* wait for the stop flag to be set */ - if(i2c_wait_flag(hi2c, I2C_STOPF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) - { - /* disable acknowledge */ - i2c_ack_enable(hi2c->i2cx, FALSE); + /* send data */ + i2c_data_send(hi2c->i2cx, *hi2c->pbuff++); + hi2c->pcount--; + } - return I2C_ERR_STEP_6; - } + /* wait for the ackfail flag to be set */ + if (i2c_wait_flag(hi2c, I2C_ACKFAIL_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) { + return I2C_ERR_STEP_5; + } - /* clear stop flag */ - i2c_flag_clear(hi2c->i2cx, I2C_STOPF_FLAG); + /* clear ack fail flag */ + i2c_flag_clear(hi2c->i2cx, I2C_ACKFAIL_FLAG); - /* wait for the busy flag to be reset */ - if (i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) - { - /* disable acknowledge */ - i2c_ack_enable(hi2c->i2cx, FALSE); + /* wait for the stop flag to be set */ + if (i2c_wait_flag(hi2c, I2C_STOPF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) { + /* disable acknowledge */ + i2c_ack_enable(hi2c->i2cx, FALSE); - return I2C_ERR_STEP_7; - } + return I2C_ERR_STEP_6; + } - /* reset ctrl2 register */ - i2c_reset_ctrl2_register(hi2c); + /* clear stop flag */ + i2c_flag_clear(hi2c->i2cx, I2C_STOPF_FLAG); - /* refresh tx dt register */ - i2c_refresh_txdt_register(hi2c); + /* wait for the busy flag to be reset */ + if (i2c_wait_flag(hi2c, I2C_BUSYF_FLAG, I2C_EVENT_CHECK_NONE, timeout) != I2C_OK) { + /* disable acknowledge */ + i2c_ack_enable(hi2c->i2cx, FALSE); - /* disable slave data control mode */ - i2c_slave_data_ctrl_enable(hi2c->i2cx, FALSE); + return I2C_ERR_STEP_7; + } - return I2C_OK; + /* reset ctrl2 register */ + i2c_reset_ctrl2_register(hi2c); + + /* refresh tx dt register */ + i2c_refresh_txdt_register(hi2c); + + /* disable slave data control mode */ + i2c_slave_data_ctrl_enable(hi2c->i2cx, FALSE); + + return I2C_OK; } /** @@ -1836,87 +1683,66 @@ i2c_status_type i2c_smbus_slave_transmit(i2c_handle_type* hi2c, uint8_t* pdata, * @param hi2c: the handle points to the operation information. * @retval i2c status. */ -i2c_status_type i2c_master_irq_handler_int(i2c_handle_type* hi2c) -{ - if (i2c_flag_get(hi2c->i2cx, I2C_ACKFAIL_FLAG) != RESET) - { - /* clear ackfail flag */ - i2c_flag_clear(hi2c->i2cx, I2C_ACKFAIL_FLAG); +i2c_status_type i2c_master_irq_handler_int(i2c_handle_type *hi2c) { + if (i2c_flag_get(hi2c->i2cx, I2C_ACKFAIL_FLAG) != RESET) { + /* clear ackfail flag */ + i2c_flag_clear(hi2c->i2cx, I2C_ACKFAIL_FLAG); - /* refresh tx register */ - i2c_refresh_txdt_register(hi2c); + /* refresh tx register */ + i2c_refresh_txdt_register(hi2c); - if(hi2c->pcount != 0) - { - hi2c->error_code = I2C_ERR_ACKFAIL; - } - } - else if (i2c_flag_get(hi2c->i2cx, I2C_TDIS_FLAG) != RESET) - { - /* send data */ - i2c_data_send(hi2c->i2cx, *hi2c->pbuff++); - hi2c->pcount--; - hi2c->psize--; - } - else if (i2c_flag_get(hi2c->i2cx, I2C_TCRLD_FLAG) != RESET) - { - if ((hi2c->psize == 0) && (hi2c->pcount != 0)) - { - /* continue transfer */ - i2c_start_transfer(hi2c, i2c_transfer_addr_get(hi2c->i2cx), I2C_WITHOUT_START); - } - else - { - return I2C_ERR_TCRLD; - } - } - else if (i2c_flag_get(hi2c->i2cx, I2C_RDBF_FLAG) != RESET) - { - /* read data */ - (*hi2c->pbuff++) = i2c_data_receive(hi2c->i2cx); - hi2c->pcount--; - hi2c->psize--; - } - else if (i2c_flag_get(hi2c->i2cx, I2C_TDC_FLAG) != RESET) - { - if (hi2c->pcount == 0) - { - if (hi2c->i2cx->ctrl2_bit.astopen == 0) - { - /* generate stop condtion */ - i2c_stop_generate(hi2c->i2cx); - } - } - else - { - return I2C_ERR_TDC; - } - } - else if (i2c_flag_get(hi2c->i2cx, I2C_STOPF_FLAG) != RESET) - { - /* clear stop flag */ - i2c_flag_clear(hi2c->i2cx, I2C_STOPF_FLAG); + if (hi2c->pcount != 0) { + hi2c->error_code = I2C_ERR_ACKFAIL; + } + } else if (i2c_flag_get(hi2c->i2cx, I2C_TDIS_FLAG) != RESET) { + /* send data */ + i2c_data_send(hi2c->i2cx, *hi2c->pbuff++); + hi2c->pcount--; + hi2c->psize--; + } else if (i2c_flag_get(hi2c->i2cx, I2C_TCRLD_FLAG) != RESET) { + if ((hi2c->psize == 0) && (hi2c->pcount != 0)) { + /* continue transfer */ + i2c_start_transfer(hi2c, i2c_transfer_addr_get(hi2c->i2cx), I2C_WITHOUT_START); + } else { + return I2C_ERR_TCRLD; + } + } else if (i2c_flag_get(hi2c->i2cx, I2C_RDBF_FLAG) != RESET) { + /* read data */ + (*hi2c->pbuff++) = i2c_data_receive(hi2c->i2cx); + hi2c->pcount--; + hi2c->psize--; + } else if (i2c_flag_get(hi2c->i2cx, I2C_TDC_FLAG) != RESET) { + if (hi2c->pcount == 0) { + if (hi2c->i2cx->ctrl2_bit.astopen == 0) { + /* generate stop condtion */ + i2c_stop_generate(hi2c->i2cx); + } + } else { + return I2C_ERR_TDC; + } + } else if (i2c_flag_get(hi2c->i2cx, I2C_STOPF_FLAG) != RESET) { + /* clear stop flag */ + i2c_flag_clear(hi2c->i2cx, I2C_STOPF_FLAG); - /* reset ctrl2 register */ - i2c_reset_ctrl2_register(hi2c); + /* reset ctrl2 register */ + i2c_reset_ctrl2_register(hi2c); - if (i2c_flag_get(hi2c->i2cx, I2C_ACKFAIL_FLAG) != RESET) - { - /* clear ackfail flag */ - i2c_flag_clear(hi2c->i2cx, I2C_ACKFAIL_FLAG); + if (i2c_flag_get(hi2c->i2cx, I2C_ACKFAIL_FLAG) != RESET) { + /* clear ackfail flag */ + i2c_flag_clear(hi2c->i2cx, I2C_ACKFAIL_FLAG); + } + + /* refresh tx dt register */ + i2c_refresh_txdt_register(hi2c); + + /* disable interrupts */ + i2c_interrupt_enable(hi2c->i2cx, I2C_ERR_INT | I2C_TDC_INT | I2C_STOP_INT | I2C_ACKFIAL_INT | I2C_TD_INT | I2C_RD_INT, FALSE); + + /* transfer complete */ + hi2c->status = I2C_END; } - /* refresh tx dt register */ - i2c_refresh_txdt_register(hi2c); - - /* disable interrupts */ - i2c_interrupt_enable(hi2c->i2cx, I2C_ERR_INT | I2C_TDC_INT | I2C_STOP_INT | I2C_ACKFIAL_INT | I2C_TD_INT | I2C_RD_INT, FALSE); - - /* transfer complete */ - hi2c->status = I2C_END; - } - - return I2C_OK; + return I2C_OK; } /** @@ -1924,82 +1750,66 @@ i2c_status_type i2c_master_irq_handler_int(i2c_handle_type* hi2c) * @param hi2c: the handle points to the operation information. * @retval i2c status. */ -i2c_status_type i2c_slave_irq_handler_int(i2c_handle_type* hi2c) -{ - if (i2c_flag_get(hi2c->i2cx, I2C_ACKFAIL_FLAG) != RESET) - { - /* transfer complete */ - if (hi2c->pcount == 0) - { - i2c_refresh_txdt_register(hi2c); +i2c_status_type i2c_slave_irq_handler_int(i2c_handle_type *hi2c) { + if (i2c_flag_get(hi2c->i2cx, I2C_ACKFAIL_FLAG) != RESET) { + /* transfer complete */ + if (hi2c->pcount == 0) { + i2c_refresh_txdt_register(hi2c); - /* clear ackfail flag */ - i2c_flag_clear(hi2c->i2cx, I2C_ACKFAIL_FLAG); - } - /* the transfer has not been completed */ - else - { - /* clear ackfail flag */ - i2c_flag_clear(hi2c->i2cx, I2C_ACKFAIL_FLAG); - } - } - else if (i2c_flag_get(hi2c->i2cx, I2C_ADDRF_FLAG) != RESET) - { - /* clear addr flag */ - i2c_flag_clear(hi2c->i2cx, I2C_ADDRF_FLAG); - } - else if (i2c_flag_get(hi2c->i2cx, I2C_TDIS_FLAG) != RESET) - { - if (hi2c->pcount > 0) - { - /* send data */ - hi2c->i2cx->txdt = (*(hi2c->pbuff++)); - hi2c->psize--; - hi2c->pcount--; - } - } - else if (i2c_flag_get(hi2c->i2cx, I2C_RDBF_FLAG) != RESET) - { - if (hi2c->pcount > 0) - { - /* read data */ - (*hi2c->pbuff++) = i2c_data_receive(hi2c->i2cx); - hi2c->pcount--; - hi2c->psize--; - } - } - else if (i2c_flag_get(hi2c->i2cx, I2C_STOPF_FLAG) != RESET) - { - /* clear stop flag */ - i2c_flag_clear(hi2c->i2cx, I2C_STOPF_FLAG); + /* clear ackfail flag */ + i2c_flag_clear(hi2c->i2cx, I2C_ACKFAIL_FLAG); + } + /* the transfer has not been completed */ + else { + /* clear ackfail flag */ + i2c_flag_clear(hi2c->i2cx, I2C_ACKFAIL_FLAG); + } + } else if (i2c_flag_get(hi2c->i2cx, I2C_ADDRF_FLAG) != RESET) { + /* clear addr flag */ + i2c_flag_clear(hi2c->i2cx, I2C_ADDRF_FLAG); + } else if (i2c_flag_get(hi2c->i2cx, I2C_TDIS_FLAG) != RESET) { + if (hi2c->pcount > 0) { + /* send data */ + hi2c->i2cx->txdt = (*(hi2c->pbuff++)); + hi2c->psize--; + hi2c->pcount--; + } + } else if (i2c_flag_get(hi2c->i2cx, I2C_RDBF_FLAG) != RESET) { + if (hi2c->pcount > 0) { + /* read data */ + (*hi2c->pbuff++) = i2c_data_receive(hi2c->i2cx); + hi2c->pcount--; + hi2c->psize--; + } + } else if (i2c_flag_get(hi2c->i2cx, I2C_STOPF_FLAG) != RESET) { + /* clear stop flag */ + i2c_flag_clear(hi2c->i2cx, I2C_STOPF_FLAG); - /* disable interrupts */ - i2c_interrupt_enable(hi2c->i2cx, I2C_ADDR_INT | I2C_STOP_INT | I2C_ACKFIAL_INT | I2C_ERR_INT | I2C_TDC_INT | I2C_TD_INT | I2C_RD_INT, FALSE); + /* disable interrupts */ + i2c_interrupt_enable(hi2c->i2cx, I2C_ADDR_INT | I2C_STOP_INT | I2C_ACKFIAL_INT | I2C_ERR_INT | I2C_TDC_INT | I2C_TD_INT | I2C_RD_INT, FALSE); - /* reset ctrl2 register */ - i2c_reset_ctrl2_register(hi2c); + /* reset ctrl2 register */ + i2c_reset_ctrl2_register(hi2c); - /* refresh tx dt register */ - i2c_refresh_txdt_register(hi2c); + /* refresh tx dt register */ + i2c_refresh_txdt_register(hi2c); - /* if data is received, read data */ - if (i2c_flag_get(hi2c->i2cx, I2C_RDBF_FLAG) != RESET) - { - /* read data */ - (*hi2c->pbuff++) = i2c_data_receive(hi2c->i2cx); + /* if data is received, read data */ + if (i2c_flag_get(hi2c->i2cx, I2C_RDBF_FLAG) != RESET) { + /* read data */ + (*hi2c->pbuff++) = i2c_data_receive(hi2c->i2cx); - if ((hi2c->psize > 0)) - { - hi2c->pcount--; - hi2c->psize--; - } + if ((hi2c->psize > 0)) { + hi2c->pcount--; + hi2c->psize--; + } + } + + /* transfer complete */ + hi2c->status = I2C_END; } - /* transfer complete */ - hi2c->status = I2C_END; - } - - return I2C_OK; + return I2C_OK; } /** @@ -2007,74 +1817,60 @@ i2c_status_type i2c_slave_irq_handler_int(i2c_handle_type* hi2c) * @param hi2c: the handle points to the operation information. * @retval i2c status. */ -i2c_status_type i2c_master_irq_handler_dma(i2c_handle_type* hi2c) -{ - if (i2c_flag_get(hi2c->i2cx, I2C_ACKFAIL_FLAG) != RESET) - { - /* clear ackfail flag */ - i2c_flag_clear(hi2c->i2cx, I2C_ACKFAIL_FLAG); +i2c_status_type i2c_master_irq_handler_dma(i2c_handle_type *hi2c) { + if (i2c_flag_get(hi2c->i2cx, I2C_ACKFAIL_FLAG) != RESET) { + /* clear ackfail flag */ + i2c_flag_clear(hi2c->i2cx, I2C_ACKFAIL_FLAG); - /* enable stop interrupt to wait for stop generate stop */ - i2c_interrupt_enable(hi2c->i2cx, I2C_STOP_INT, TRUE); + /* enable stop interrupt to wait for stop generate stop */ + i2c_interrupt_enable(hi2c->i2cx, I2C_STOP_INT, TRUE); - /* refresh tx dt register */ - i2c_refresh_txdt_register(hi2c); + /* refresh tx dt register */ + i2c_refresh_txdt_register(hi2c); - if(hi2c->pcount != 0) - { - hi2c->error_code = I2C_ERR_ACKFAIL; - } - } - else if (i2c_flag_get(hi2c->i2cx, I2C_TCRLD_FLAG) != RESET) - { - /* disable tdc interrupt */ - i2c_interrupt_enable(hi2c->i2cx, I2C_TDC_INT, FALSE); + if (hi2c->pcount != 0) { + hi2c->error_code = I2C_ERR_ACKFAIL; + } + } else if (i2c_flag_get(hi2c->i2cx, I2C_TCRLD_FLAG) != RESET) { + /* disable tdc interrupt */ + i2c_interrupt_enable(hi2c->i2cx, I2C_TDC_INT, FALSE); - if (hi2c->pcount != 0) - { - /* continue transfer */ - i2c_start_transfer(hi2c, i2c_transfer_addr_get(hi2c->i2cx), I2C_WITHOUT_START); + if (hi2c->pcount != 0) { + /* continue transfer */ + i2c_start_transfer(hi2c, i2c_transfer_addr_get(hi2c->i2cx), I2C_WITHOUT_START); - /* enable dma request */ - if (hi2c->dma_init_struct.direction == DMA_DIR_MEMORY_TO_PERIPHERAL) - { - i2c_dma_enable(hi2c->i2cx, I2C_DMA_REQUEST_TX, TRUE); - } - else - { - i2c_dma_enable(hi2c->i2cx, I2C_DMA_REQUEST_RX, TRUE); - } - } - else - { - return I2C_ERR_TCRLD; - } - } - else if (i2c_flag_get(hi2c->i2cx, I2C_STOPF_FLAG) != RESET) - { - /* clear stop flag */ - i2c_flag_clear(hi2c->i2cx, I2C_STOPF_FLAG); + /* enable dma request */ + if (hi2c->dma_init_struct.direction == DMA_DIR_MEMORY_TO_PERIPHERAL) { + i2c_dma_enable(hi2c->i2cx, I2C_DMA_REQUEST_TX, TRUE); + } else { + i2c_dma_enable(hi2c->i2cx, I2C_DMA_REQUEST_RX, TRUE); + } + } else { + return I2C_ERR_TCRLD; + } + } else if (i2c_flag_get(hi2c->i2cx, I2C_STOPF_FLAG) != RESET) { + /* clear stop flag */ + i2c_flag_clear(hi2c->i2cx, I2C_STOPF_FLAG); - /* reset ctrl2 register */ - i2c_reset_ctrl2_register(hi2c); + /* reset ctrl2 register */ + i2c_reset_ctrl2_register(hi2c); - if (i2c_flag_get(hi2c->i2cx, I2C_ACKFAIL_FLAG) != RESET) - { - /* clear ackfail flag */ - i2c_flag_clear(hi2c->i2cx, I2C_ACKFAIL_FLAG); + if (i2c_flag_get(hi2c->i2cx, I2C_ACKFAIL_FLAG) != RESET) { + /* clear ackfail flag */ + i2c_flag_clear(hi2c->i2cx, I2C_ACKFAIL_FLAG); + } + + /* refresh tx dt register */ + i2c_refresh_txdt_register(hi2c); + + /* disable interrupts */ + i2c_interrupt_enable(hi2c->i2cx, I2C_ERR_INT | I2C_TDC_INT | I2C_STOP_INT | I2C_ACKFIAL_INT | I2C_TD_INT | I2C_RD_INT, FALSE); + + /* transfer complete */ + hi2c->status = I2C_END; } - /* refresh tx dt register */ - i2c_refresh_txdt_register(hi2c); - - /* disable interrupts */ - i2c_interrupt_enable(hi2c->i2cx, I2C_ERR_INT | I2C_TDC_INT | I2C_STOP_INT | I2C_ACKFIAL_INT | I2C_TD_INT | I2C_RD_INT, FALSE); - - /* transfer complete */ - hi2c->status = I2C_END; - } - - return I2C_OK; + return I2C_OK; } /** @@ -2082,50 +1878,42 @@ i2c_status_type i2c_master_irq_handler_dma(i2c_handle_type* hi2c) * @param hi2c: the handle points to the operation information. * @retval i2c status. */ -i2c_status_type i2c_slave_irq_handler_dma(i2c_handle_type* hi2c) -{ - if (i2c_flag_get(hi2c->i2cx, I2C_ACKFAIL_FLAG) != RESET) - { - /* clear ackfail flag */ - i2c_flag_clear(hi2c->i2cx, I2C_ACKFAIL_FLAG); - } - else if (i2c_flag_get(hi2c->i2cx, I2C_ADDRF_FLAG) != RESET) - { - /* clear addr flag */ - i2c_flag_clear(hi2c->i2cx, I2C_ADDRF_FLAG); - } - else if (i2c_flag_get(hi2c->i2cx, I2C_STOPF_FLAG) != RESET) - { - /* clear stop flag */ - i2c_flag_clear(hi2c->i2cx, I2C_STOPF_FLAG); +i2c_status_type i2c_slave_irq_handler_dma(i2c_handle_type *hi2c) { + if (i2c_flag_get(hi2c->i2cx, I2C_ACKFAIL_FLAG) != RESET) { + /* clear ackfail flag */ + i2c_flag_clear(hi2c->i2cx, I2C_ACKFAIL_FLAG); + } else if (i2c_flag_get(hi2c->i2cx, I2C_ADDRF_FLAG) != RESET) { + /* clear addr flag */ + i2c_flag_clear(hi2c->i2cx, I2C_ADDRF_FLAG); + } else if (i2c_flag_get(hi2c->i2cx, I2C_STOPF_FLAG) != RESET) { + /* clear stop flag */ + i2c_flag_clear(hi2c->i2cx, I2C_STOPF_FLAG); - /* disable interrupts */ - i2c_interrupt_enable(hi2c->i2cx, I2C_ADDR_INT | I2C_STOP_INT | I2C_ACKFIAL_INT | I2C_ERR_INT | I2C_TDC_INT | I2C_TD_INT | I2C_RD_INT, FALSE); + /* disable interrupts */ + i2c_interrupt_enable(hi2c->i2cx, I2C_ADDR_INT | I2C_STOP_INT | I2C_ACKFIAL_INT | I2C_ERR_INT | I2C_TDC_INT | I2C_TD_INT | I2C_RD_INT, FALSE); - /* reset ctrl2 register */ - i2c_reset_ctrl2_register(hi2c); + /* reset ctrl2 register */ + i2c_reset_ctrl2_register(hi2c); - /* refresh tx dt register */ - i2c_refresh_txdt_register(hi2c); + /* refresh tx dt register */ + i2c_refresh_txdt_register(hi2c); - /* if data is received, read data */ - if (i2c_flag_get(hi2c->i2cx, I2C_RDBF_FLAG) != RESET) - { - /* read data */ - (*hi2c->pbuff++) = i2c_data_receive(hi2c->i2cx); + /* if data is received, read data */ + if (i2c_flag_get(hi2c->i2cx, I2C_RDBF_FLAG) != RESET) { + /* read data */ + (*hi2c->pbuff++) = i2c_data_receive(hi2c->i2cx); - if ((hi2c->psize > 0)) - { - hi2c->pcount--; - hi2c->psize--; - } + if ((hi2c->psize > 0)) { + hi2c->pcount--; + hi2c->psize--; + } + } + + /* transfer complete */ + hi2c->status = I2C_END; } - /* transfer complete */ - hi2c->status = I2C_END; - } - - return I2C_OK; + return I2C_OK; } /** @@ -2133,69 +1921,61 @@ i2c_status_type i2c_slave_irq_handler_dma(i2c_handle_type* hi2c) * @param hi2c: the handle points to the operation information. * @retval none. */ -void i2c_dma_tx_rx_irq_handler(i2c_handle_type* hi2c, dma_channel_type* dma_channel) -{ - /* transfer complete */ - if (dma_flag_get(DMA_GET_TC_FLAG(dma_channel)) != RESET) - { - /* disable the transfer complete interrupt */ - dma_interrupt_enable(dma_channel, DMA_FDT_INT, FALSE); +void i2c_dma_tx_rx_irq_handler(i2c_handle_type *hi2c, dma_channel_type *dma_channel) { + /* transfer complete */ + if (dma_flag_get(DMA_GET_TC_FLAG(dma_channel)) != RESET) { + /* disable the transfer complete interrupt */ + dma_interrupt_enable(dma_channel, DMA_FDT_INT, FALSE); - /* clear the transfer complete flag */ - dma_flag_clear(DMA_GET_TC_FLAG(dma_channel)); + /* clear the transfer complete flag */ + dma_flag_clear(DMA_GET_TC_FLAG(dma_channel)); - /* disable dma request */ - i2c_dma_enable(hi2c->i2cx, DMA_GET_REQUEST(dma_channel), FALSE); + /* disable dma request */ + i2c_dma_enable(hi2c->i2cx, DMA_GET_REQUEST(dma_channel), FALSE); - /* disable dma channel */ - dma_channel_enable(dma_channel, FALSE); + /* disable dma channel */ + dma_channel_enable(dma_channel, FALSE); - switch(hi2c->mode) - { - case I2C_DMA_MA_TX: - case I2C_DMA_MA_RX: - { - /* update the number of transfers */ - hi2c->pcount -= hi2c->psize; + switch (hi2c->mode) { + case I2C_DMA_MA_TX: + case I2C_DMA_MA_RX: { + /* update the number of transfers */ + hi2c->pcount -= hi2c->psize; - /* transfer complete */ - if (hi2c->pcount == 0) - { - /* enable stop interrupt */ - i2c_interrupt_enable(hi2c->i2cx, I2C_STOP_INT, TRUE); + /* transfer complete */ + if (hi2c->pcount == 0) { + /* enable stop interrupt */ + i2c_interrupt_enable(hi2c->i2cx, I2C_STOP_INT, TRUE); + } + /* the transfer has not been completed */ + else { + /* update the buffer pointer of transfers */ + hi2c->pbuff += hi2c->psize; + + /* set the number to be transferred */ + if (hi2c->pcount > MAX_TRANSFER_CNT) { + hi2c->psize = MAX_TRANSFER_CNT; + } else { + hi2c->psize = hi2c->pcount; + } + + /* config dma channel, continue to transfer data */ + i2c_dma_config(hi2c, dma_channel, hi2c->pbuff, hi2c->psize); + + /* enable tdc interrupt */ + i2c_interrupt_enable(hi2c->i2cx, I2C_TDC_INT, TRUE); + } + } + break; + case I2C_DMA_SLA_TX: + case I2C_DMA_SLA_RX: { + + } break; + + default: + break; } - /* the transfer has not been completed */ - else - { - /* update the buffer pointer of transfers */ - hi2c->pbuff += hi2c->psize; - - /* set the number to be transferred */ - if (hi2c->pcount > MAX_TRANSFER_CNT) - { - hi2c->psize = MAX_TRANSFER_CNT; - } - else - { - hi2c->psize = hi2c->pcount; - } - - /* config dma channel, continue to transfer data */ - i2c_dma_config(hi2c, dma_channel, hi2c->pbuff, hi2c->psize); - - /* enable tdc interrupt */ - i2c_interrupt_enable(hi2c->i2cx, I2C_TDC_INT, TRUE); - } - }break; - case I2C_DMA_SLA_TX: - case I2C_DMA_SLA_RX: - { - - }break; - - default:break; } - } } /** @@ -2203,9 +1983,8 @@ void i2c_dma_tx_rx_irq_handler(i2c_handle_type* hi2c, dma_channel_type* dma_chan * @param hi2c: the handle points to the operation information. * @retval none. */ -void i2c_dma_tx_irq_handler(i2c_handle_type* hi2c) -{ - i2c_dma_tx_rx_irq_handler(hi2c, hi2c->dma_tx_channel); +void i2c_dma_tx_irq_handler(i2c_handle_type *hi2c) { + i2c_dma_tx_rx_irq_handler(hi2c, hi2c->dma_tx_channel); } /** @@ -2213,9 +1992,8 @@ void i2c_dma_tx_irq_handler(i2c_handle_type* hi2c) * @param hi2c: the handle points to the operation information. * @retval none. */ -void i2c_dma_rx_irq_handler(i2c_handle_type* hi2c) -{ - i2c_dma_tx_rx_irq_handler(hi2c, hi2c->dma_rx_channel); +void i2c_dma_rx_irq_handler(i2c_handle_type *hi2c) { + i2c_dma_tx_rx_irq_handler(hi2c, hi2c->dma_rx_channel); } /** @@ -2223,33 +2001,32 @@ void i2c_dma_rx_irq_handler(i2c_handle_type* hi2c) * @param hi2c: the handle points to the operation information. * @retval none. */ -void i2c_evt_irq_handler(i2c_handle_type* hi2c) -{ - switch(hi2c->mode) - { - case I2C_INT_MA_TX: - case I2C_INT_MA_RX: - { - i2c_master_irq_handler_int(hi2c); - }break; - case I2C_INT_SLA_TX: - case I2C_INT_SLA_RX: - { - i2c_slave_irq_handler_int(hi2c); - }break; - case I2C_DMA_MA_TX: - case I2C_DMA_MA_RX: - { - i2c_master_irq_handler_dma(hi2c); - }break; - case I2C_DMA_SLA_TX: - case I2C_DMA_SLA_RX: - { - i2c_slave_irq_handler_dma(hi2c); - }break; +void i2c_evt_irq_handler(i2c_handle_type *hi2c) { + switch (hi2c->mode) { + case I2C_INT_MA_TX: + case I2C_INT_MA_RX: { + i2c_master_irq_handler_int(hi2c); + } + break; + case I2C_INT_SLA_TX: + case I2C_INT_SLA_RX: { + i2c_slave_irq_handler_int(hi2c); + } + break; + case I2C_DMA_MA_TX: + case I2C_DMA_MA_RX: { + i2c_master_irq_handler_dma(hi2c); + } + break; + case I2C_DMA_SLA_TX: + case I2C_DMA_SLA_RX: { + i2c_slave_irq_handler_dma(hi2c); + } + break; - default:break; - } + default: + break; + } } /** @@ -2257,80 +2034,73 @@ void i2c_evt_irq_handler(i2c_handle_type* hi2c) * @param hi2c: the handle points to the operation information. * @retval none. */ -void i2c_err_irq_handler(i2c_handle_type* hi2c) -{ - /* buserr */ - if (i2c_flag_get(hi2c->i2cx, I2C_BUSERR_FLAG) != RESET) - { - hi2c->error_code = I2C_ERR_INTERRUPT; - - /* clear flag */ - i2c_flag_clear(hi2c->i2cx, I2C_BUSERR_FLAG); - - /* disable interrupts */ - i2c_interrupt_enable(hi2c->i2cx, I2C_ERR_INT, FALSE); - } +void i2c_err_irq_handler(i2c_handle_type *hi2c) { + /* buserr */ + if (i2c_flag_get(hi2c->i2cx, I2C_BUSERR_FLAG) != RESET) { + hi2c->error_code = I2C_ERR_INTERRUPT; - /* arlost */ - if (i2c_flag_get(hi2c->i2cx, I2C_ARLOST_FLAG) != RESET) - { - hi2c->error_code = I2C_ERR_INTERRUPT; - - /* clear flag */ - i2c_flag_clear(hi2c->i2cx, I2C_ARLOST_FLAG); - - /* disable interrupts */ - i2c_interrupt_enable(hi2c->i2cx, I2C_ERR_INT, FALSE); - } + /* clear flag */ + i2c_flag_clear(hi2c->i2cx, I2C_BUSERR_FLAG); - /* ouf */ - if (i2c_flag_get(hi2c->i2cx, I2C_OUF_FLAG) != RESET) - { - hi2c->error_code = I2C_ERR_INTERRUPT; - - /* clear flag */ - i2c_flag_clear(hi2c->i2cx, I2C_OUF_FLAG); - - /* disable interrupts */ - i2c_interrupt_enable(hi2c->i2cx, I2C_ERR_INT, FALSE); - } + /* disable interrupts */ + i2c_interrupt_enable(hi2c->i2cx, I2C_ERR_INT, FALSE); + } - /* pecerr */ - if (i2c_flag_get(hi2c->i2cx, I2C_PECERR_FLAG) != RESET) - { - hi2c->error_code = I2C_ERR_INTERRUPT; - - /* clear flag */ - i2c_flag_clear(hi2c->i2cx, I2C_PECERR_FLAG); - - /* disable interrupts */ - i2c_interrupt_enable(hi2c->i2cx, I2C_ERR_INT, FALSE); + /* arlost */ + if (i2c_flag_get(hi2c->i2cx, I2C_ARLOST_FLAG) != RESET) { + hi2c->error_code = I2C_ERR_INTERRUPT; - } + /* clear flag */ + i2c_flag_clear(hi2c->i2cx, I2C_ARLOST_FLAG); - /* timeout */ - if (i2c_flag_get(hi2c->i2cx, I2C_TMOUT_FLAG) != RESET) - { - hi2c->error_code = I2C_ERR_INTERRUPT; - - /* clear flag */ - i2c_flag_clear(hi2c->i2cx, I2C_TMOUT_FLAG); - - /* disable interrupts */ - i2c_interrupt_enable(hi2c->i2cx, I2C_ERR_INT, FALSE); - } + /* disable interrupts */ + i2c_interrupt_enable(hi2c->i2cx, I2C_ERR_INT, FALSE); + } - /* alertf */ - if (i2c_flag_get(hi2c->i2cx, I2C_ALERTF_FLAG) != RESET) - { - hi2c->error_code = I2C_ERR_INTERRUPT; - - /* clear flag */ - i2c_flag_clear(hi2c->i2cx, I2C_ALERTF_FLAG); - - /* disable interrupts */ - i2c_interrupt_enable(hi2c->i2cx, I2C_ERR_INT, FALSE); - } + /* ouf */ + if (i2c_flag_get(hi2c->i2cx, I2C_OUF_FLAG) != RESET) { + hi2c->error_code = I2C_ERR_INTERRUPT; + + /* clear flag */ + i2c_flag_clear(hi2c->i2cx, I2C_OUF_FLAG); + + /* disable interrupts */ + i2c_interrupt_enable(hi2c->i2cx, I2C_ERR_INT, FALSE); + } + + /* pecerr */ + if (i2c_flag_get(hi2c->i2cx, I2C_PECERR_FLAG) != RESET) { + hi2c->error_code = I2C_ERR_INTERRUPT; + + /* clear flag */ + i2c_flag_clear(hi2c->i2cx, I2C_PECERR_FLAG); + + /* disable interrupts */ + i2c_interrupt_enable(hi2c->i2cx, I2C_ERR_INT, FALSE); + + } + + /* timeout */ + if (i2c_flag_get(hi2c->i2cx, I2C_TMOUT_FLAG) != RESET) { + hi2c->error_code = I2C_ERR_INTERRUPT; + + /* clear flag */ + i2c_flag_clear(hi2c->i2cx, I2C_TMOUT_FLAG); + + /* disable interrupts */ + i2c_interrupt_enable(hi2c->i2cx, I2C_ERR_INT, FALSE); + } + + /* alertf */ + if (i2c_flag_get(hi2c->i2cx, I2C_ALERTF_FLAG) != RESET) { + hi2c->error_code = I2C_ERR_INTERRUPT; + + /* clear flag */ + i2c_flag_clear(hi2c->i2cx, I2C_ALERTF_FLAG); + + /* disable interrupts */ + i2c_interrupt_enable(hi2c->i2cx, I2C_ERR_INT, FALSE); + } } /** diff --git a/armlib/at32_i2c/at32f435_437_i2c_app.h b/armlib/at32_i2c/at32f435_437_i2c_app.h index 9852eebe5..653c6a6a0 100644 --- a/armlib/at32_i2c/at32f435_437_i2c_app.h +++ b/armlib/at32_i2c/at32f435_437_i2c_app.h @@ -56,10 +56,9 @@ extern "C" { * @{ */ -typedef enum -{ - I2C_MEM_ADDR_WIDIH_8 = 0x01, /*!< memory address is 8 bit */ - I2C_MEM_ADDR_WIDIH_16 = 0x02, /*!< memory address is 16 bit */ +typedef enum { + I2C_MEM_ADDR_WIDIH_8 = 0x01, /*!< memory address is 8 bit */ + I2C_MEM_ADDR_WIDIH_16 = 0x02, /*!< memory address is 16 bit */ } i2c_mem_address_width_type; /** @@ -70,16 +69,15 @@ typedef enum * @{ */ -typedef enum -{ - I2C_INT_MA_TX = 0, - I2C_INT_MA_RX, - I2C_INT_SLA_TX, - I2C_INT_SLA_RX, - I2C_DMA_MA_TX, - I2C_DMA_MA_RX, - I2C_DMA_SLA_TX, - I2C_DMA_SLA_RX, +typedef enum { + I2C_INT_MA_TX = 0, + I2C_INT_MA_RX, + I2C_INT_SLA_TX, + I2C_INT_SLA_RX, + I2C_DMA_MA_TX, + I2C_DMA_MA_RX, + I2C_DMA_SLA_TX, + I2C_DMA_SLA_RX, } i2c_mode_type; /** @@ -90,28 +88,27 @@ typedef enum * @{ */ -typedef enum -{ - I2C_OK = 0, /*!< no error */ - I2C_ERR_STEP_1, /*!< step 1 error */ - I2C_ERR_STEP_2, /*!< step 2 error */ - I2C_ERR_STEP_3, /*!< step 3 error */ - I2C_ERR_STEP_4, /*!< step 4 error */ - I2C_ERR_STEP_5, /*!< step 5 error */ - I2C_ERR_STEP_6, /*!< step 6 error */ - I2C_ERR_STEP_7, /*!< step 7 error */ - I2C_ERR_STEP_8, /*!< step 8 error */ - I2C_ERR_STEP_9, /*!< step 9 error */ - I2C_ERR_STEP_10, /*!< step 10 error */ - I2C_ERR_STEP_11, /*!< step 11 error */ - I2C_ERR_STEP_12, /*!< step 12 error */ - I2C_ERR_TCRLD, /*!< tcrld error */ - I2C_ERR_TDC, /*!< tdc error */ - I2C_ERR_ADDR, /*!< addr error */ - I2C_ERR_STOP, /*!< stop error */ - I2C_ERR_ACKFAIL, /*!< ackfail error */ - I2C_ERR_TIMEOUT, /*!< timeout error */ - I2C_ERR_INTERRUPT, /*!< interrupt error */ +typedef enum { + I2C_OK = 0, /*!< no error */ + I2C_ERR_STEP_1, /*!< step 1 error */ + I2C_ERR_STEP_2, /*!< step 2 error */ + I2C_ERR_STEP_3, /*!< step 3 error */ + I2C_ERR_STEP_4, /*!< step 4 error */ + I2C_ERR_STEP_5, /*!< step 5 error */ + I2C_ERR_STEP_6, /*!< step 6 error */ + I2C_ERR_STEP_7, /*!< step 7 error */ + I2C_ERR_STEP_8, /*!< step 8 error */ + I2C_ERR_STEP_9, /*!< step 9 error */ + I2C_ERR_STEP_10, /*!< step 10 error */ + I2C_ERR_STEP_11, /*!< step 11 error */ + I2C_ERR_STEP_12, /*!< step 12 error */ + I2C_ERR_TCRLD, /*!< tcrld error */ + I2C_ERR_TDC, /*!< tdc error */ + I2C_ERR_ADDR, /*!< addr error */ + I2C_ERR_STOP, /*!< stop error */ + I2C_ERR_ACKFAIL, /*!< ackfail error */ + I2C_ERR_TIMEOUT, /*!< timeout error */ + I2C_ERR_INTERRUPT, /*!< interrupt error */ } i2c_status_type; /** @@ -122,18 +119,17 @@ typedef enum * @{ */ -typedef struct -{ - i2c_type *i2cx; /*!< i2c registers base address */ - uint8_t *pbuff; /*!< pointer to i2c transfer buffer */ - __IO uint16_t psize; /*!< i2c transfer size */ - __IO uint16_t pcount; /*!< i2c transfer counter */ - __IO uint32_t mode; /*!< i2c communication mode */ - __IO uint32_t status; /*!< i2c communication status */ - __IO i2c_status_type error_code; /*!< i2c error code */ - dma_channel_type *dma_tx_channel; /*!< dma transmit channel */ - dma_channel_type *dma_rx_channel; /*!< dma receive channel */ - dma_init_type dma_init_struct; /*!< dma init parameters */ +typedef struct { + i2c_type *i2cx; /*!< i2c registers base address */ + uint8_t *pbuff; /*!< pointer to i2c transfer buffer */ + __IO uint16_t psize; /*!< i2c transfer size */ + __IO uint16_t pcount; /*!< i2c transfer counter */ + __IO uint32_t mode; /*!< i2c communication mode */ + __IO uint32_t status; /*!< i2c communication status */ + __IO i2c_status_type error_code; /*!< i2c error code */ + dma_channel_type *dma_tx_channel; /*!< dma transmit channel */ + dma_channel_type *dma_rx_channel; /*!< dma receive channel */ + dma_init_type dma_init_struct; /*!< dma init parameters */ } i2c_handle_type; /** @@ -144,43 +140,43 @@ typedef struct * @{ */ -void i2c_config (i2c_handle_type* hi2c); -void i2c_lowlevel_init (i2c_handle_type* hi2c); -void i2c_reset_ctrl2_register (i2c_handle_type* hi2c); -i2c_status_type i2c_wait_end (i2c_handle_type* hi2c, uint32_t timeout); -i2c_status_type i2c_wait_flag (i2c_handle_type* hi2c, uint32_t flag, uint32_t event_check, uint32_t timeout); +void i2c_config(i2c_handle_type *hi2c); +void i2c_lowlevel_init(i2c_handle_type *hi2c); +void i2c_reset_ctrl2_register(i2c_handle_type *hi2c); +i2c_status_type i2c_wait_end(i2c_handle_type *hi2c, uint32_t timeout); +i2c_status_type i2c_wait_flag(i2c_handle_type *hi2c, uint32_t flag, uint32_t event_check, uint32_t timeout); -i2c_status_type i2c_master_transmit (i2c_handle_type* hi2c, uint16_t address, uint8_t* pdata, uint16_t size, uint32_t timeout); -i2c_status_type i2c_master_receive (i2c_handle_type* hi2c, uint16_t address, uint8_t* pdata, uint16_t size, uint32_t timeout); -i2c_status_type i2c_slave_transmit (i2c_handle_type* hi2c, uint8_t* pdata, uint16_t size, uint32_t timeout); -i2c_status_type i2c_slave_receive (i2c_handle_type* hi2c, uint8_t* pdata, uint16_t size, uint32_t timeout); +i2c_status_type i2c_master_transmit(i2c_handle_type *hi2c, uint16_t address, uint8_t *pdata, uint16_t size, uint32_t timeout); +i2c_status_type i2c_master_receive(i2c_handle_type *hi2c, uint16_t address, uint8_t *pdata, uint16_t size, uint32_t timeout); +i2c_status_type i2c_slave_transmit(i2c_handle_type *hi2c, uint8_t *pdata, uint16_t size, uint32_t timeout); +i2c_status_type i2c_slave_receive(i2c_handle_type *hi2c, uint8_t *pdata, uint16_t size, uint32_t timeout); -i2c_status_type i2c_master_transmit_int (i2c_handle_type* hi2c, uint16_t address, uint8_t* pdata, uint16_t size, uint32_t timeout); -i2c_status_type i2c_master_receive_int (i2c_handle_type* hi2c, uint16_t address, uint8_t* pdata, uint16_t size, uint32_t timeout); -i2c_status_type i2c_slave_transmit_int (i2c_handle_type* hi2c, uint8_t* pdata, uint16_t size, uint32_t timeout); -i2c_status_type i2c_slave_receive_int (i2c_handle_type* hi2c, uint8_t* pdata, uint16_t size, uint32_t timeout); +i2c_status_type i2c_master_transmit_int(i2c_handle_type *hi2c, uint16_t address, uint8_t *pdata, uint16_t size, uint32_t timeout); +i2c_status_type i2c_master_receive_int(i2c_handle_type *hi2c, uint16_t address, uint8_t *pdata, uint16_t size, uint32_t timeout); +i2c_status_type i2c_slave_transmit_int(i2c_handle_type *hi2c, uint8_t *pdata, uint16_t size, uint32_t timeout); +i2c_status_type i2c_slave_receive_int(i2c_handle_type *hi2c, uint8_t *pdata, uint16_t size, uint32_t timeout); -i2c_status_type i2c_master_transmit_dma (i2c_handle_type* hi2c, uint16_t address, uint8_t* pdata, uint16_t size, uint32_t timeout); -i2c_status_type i2c_master_receive_dma (i2c_handle_type* hi2c, uint16_t address, uint8_t* pdata, uint16_t size, uint32_t timeout); -i2c_status_type i2c_slave_transmit_dma (i2c_handle_type* hi2c, uint8_t* pdata, uint16_t size, uint32_t timeout); -i2c_status_type i2c_slave_receive_dma (i2c_handle_type* hi2c, uint8_t* pdata, uint16_t size, uint32_t timeout); +i2c_status_type i2c_master_transmit_dma(i2c_handle_type *hi2c, uint16_t address, uint8_t *pdata, uint16_t size, uint32_t timeout); +i2c_status_type i2c_master_receive_dma(i2c_handle_type *hi2c, uint16_t address, uint8_t *pdata, uint16_t size, uint32_t timeout); +i2c_status_type i2c_slave_transmit_dma(i2c_handle_type *hi2c, uint8_t *pdata, uint16_t size, uint32_t timeout); +i2c_status_type i2c_slave_receive_dma(i2c_handle_type *hi2c, uint8_t *pdata, uint16_t size, uint32_t timeout); -i2c_status_type i2c_smbus_master_transmit (i2c_handle_type* hi2c, uint16_t address, uint8_t* pdata, uint16_t size, uint32_t timeout); -i2c_status_type i2c_smbus_master_receive (i2c_handle_type* hi2c, uint16_t address, uint8_t* pdata, uint16_t size, uint32_t timeout); -i2c_status_type i2c_smbus_slave_transmit (i2c_handle_type* hi2c, uint8_t* pdata, uint16_t size, uint32_t timeout); -i2c_status_type i2c_smbus_slave_receive (i2c_handle_type* hi2c, uint8_t* pdata, uint16_t size, uint32_t timeout); +i2c_status_type i2c_smbus_master_transmit(i2c_handle_type *hi2c, uint16_t address, uint8_t *pdata, uint16_t size, uint32_t timeout); +i2c_status_type i2c_smbus_master_receive(i2c_handle_type *hi2c, uint16_t address, uint8_t *pdata, uint16_t size, uint32_t timeout); +i2c_status_type i2c_smbus_slave_transmit(i2c_handle_type *hi2c, uint8_t *pdata, uint16_t size, uint32_t timeout); +i2c_status_type i2c_smbus_slave_receive(i2c_handle_type *hi2c, uint8_t *pdata, uint16_t size, uint32_t timeout); -i2c_status_type i2c_memory_write (i2c_handle_type* hi2c, i2c_mem_address_width_type mem_address_width, uint16_t address, uint16_t mem_address, uint8_t* pdata, uint16_t size, uint32_t timeout); -i2c_status_type i2c_memory_write_int (i2c_handle_type* hi2c, i2c_mem_address_width_type mem_address_width, uint16_t address, uint16_t mem_address, uint8_t* pdata, uint16_t size, uint32_t timeout); -i2c_status_type i2c_memory_write_dma (i2c_handle_type* hi2c, i2c_mem_address_width_type mem_address_width, uint16_t address, uint16_t mem_address, uint8_t* pdata, uint16_t size, uint32_t timeout); -i2c_status_type i2c_memory_read (i2c_handle_type* hi2c, i2c_mem_address_width_type mem_address_width, uint16_t address, uint16_t mem_address, uint8_t* pdata, uint16_t size, uint32_t timeout); -i2c_status_type i2c_memory_read_int (i2c_handle_type* hi2c, i2c_mem_address_width_type mem_address_width, uint16_t address, uint16_t mem_address, uint8_t* pdata, uint16_t size, uint32_t timeout); -i2c_status_type i2c_memory_read_dma (i2c_handle_type* hi2c, i2c_mem_address_width_type mem_address_width, uint16_t address, uint16_t mem_address, uint8_t* pdata, uint16_t size, uint32_t timeout); +i2c_status_type i2c_memory_write(i2c_handle_type *hi2c, i2c_mem_address_width_type mem_address_width, uint16_t address, uint16_t mem_address, uint8_t *pdata, uint16_t size, uint32_t timeout); +i2c_status_type i2c_memory_write_int(i2c_handle_type *hi2c, i2c_mem_address_width_type mem_address_width, uint16_t address, uint16_t mem_address, uint8_t *pdata, uint16_t size, uint32_t timeout); +i2c_status_type i2c_memory_write_dma(i2c_handle_type *hi2c, i2c_mem_address_width_type mem_address_width, uint16_t address, uint16_t mem_address, uint8_t *pdata, uint16_t size, uint32_t timeout); +i2c_status_type i2c_memory_read(i2c_handle_type *hi2c, i2c_mem_address_width_type mem_address_width, uint16_t address, uint16_t mem_address, uint8_t *pdata, uint16_t size, uint32_t timeout); +i2c_status_type i2c_memory_read_int(i2c_handle_type *hi2c, i2c_mem_address_width_type mem_address_width, uint16_t address, uint16_t mem_address, uint8_t *pdata, uint16_t size, uint32_t timeout); +i2c_status_type i2c_memory_read_dma(i2c_handle_type *hi2c, i2c_mem_address_width_type mem_address_width, uint16_t address, uint16_t mem_address, uint8_t *pdata, uint16_t size, uint32_t timeout); -void i2c_evt_irq_handler (i2c_handle_type* hi2c); -void i2c_err_irq_handler (i2c_handle_type* hi2c); -void i2c_dma_tx_irq_handler (i2c_handle_type* hi2c); -void i2c_dma_rx_irq_handler (i2c_handle_type* hi2c); +void i2c_evt_irq_handler(i2c_handle_type *hi2c); +void i2c_err_irq_handler(i2c_handle_type *hi2c); +void i2c_dma_tx_irq_handler(i2c_handle_type *hi2c); +void i2c_dma_rx_irq_handler(i2c_handle_type *hi2c); /** * @} diff --git a/armlib/at32_sys/cmsis/cm4/core_support/arm_common_tables.h b/armlib/at32_sys/cmsis/cm4/core_support/arm_common_tables.h index 3e72c806a..ab4fae04b 100644 --- a/armlib/at32_sys/cmsis/cm4/core_support/arm_common_tables.h +++ b/armlib/at32_sys/cmsis/cm4/core_support/arm_common_tables.h @@ -38,493 +38,493 @@ extern "C" #endif #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_FFT_ALLOW_TABLES) - /* Double Precision Float CFFT twiddles */ - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREV_1024) - extern const uint16_t armBitRevTable[1024]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ +/* Double Precision Float CFFT twiddles */ +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREV_1024) +extern const uint16_t armBitRevTable[1024]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F64_16) - extern const uint64_t twiddleCoefF64_16[32]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F64_16) +extern const uint64_t twiddleCoefF64_16[32]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F64_32) - extern const uint64_t twiddleCoefF64_32[64]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F64_32) +extern const uint64_t twiddleCoefF64_32[64]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F64_64) - extern const uint64_t twiddleCoefF64_64[128]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F64_64) +extern const uint64_t twiddleCoefF64_64[128]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F64_128) - extern const uint64_t twiddleCoefF64_128[256]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F64_128) +extern const uint64_t twiddleCoefF64_128[256]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F64_256) - extern const uint64_t twiddleCoefF64_256[512]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F64_256) +extern const uint64_t twiddleCoefF64_256[512]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F64_512) - extern const uint64_t twiddleCoefF64_512[1024]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F64_512) +extern const uint64_t twiddleCoefF64_512[1024]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F64_1024) - extern const uint64_t twiddleCoefF64_1024[2048]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F64_1024) +extern const uint64_t twiddleCoefF64_1024[2048]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F64_2048) - extern const uint64_t twiddleCoefF64_2048[4096]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F64_2048) +extern const uint64_t twiddleCoefF64_2048[4096]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F64_4096) - extern const uint64_t twiddleCoefF64_4096[8192]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F64_4096) +extern const uint64_t twiddleCoefF64_4096[8192]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F32_16) - extern const float32_t twiddleCoef_16[32]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F32_16) +extern const float32_t twiddleCoef_16[32]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F32_32) - extern const float32_t twiddleCoef_32[64]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F32_32) +extern const float32_t twiddleCoef_32[64]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F32_64) - extern const float32_t twiddleCoef_64[128]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F32_64) +extern const float32_t twiddleCoef_64[128]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F32_128) - extern const float32_t twiddleCoef_128[256]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F32_128) +extern const float32_t twiddleCoef_128[256]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F32_256) - extern const float32_t twiddleCoef_256[512]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F32_256) +extern const float32_t twiddleCoef_256[512]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F32_512) - extern const float32_t twiddleCoef_512[1024]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F32_512) +extern const float32_t twiddleCoef_512[1024]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F32_1024) - extern const float32_t twiddleCoef_1024[2048]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F32_1024) +extern const float32_t twiddleCoef_1024[2048]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F32_2048) - extern const float32_t twiddleCoef_2048[4096]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F32_2048) +extern const float32_t twiddleCoef_2048[4096]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F32_4096) - extern const float32_t twiddleCoef_4096[8192]; - #define twiddleCoef twiddleCoef_4096 - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F32_4096) +extern const float32_t twiddleCoef_4096[8192]; +#define twiddleCoef twiddleCoef_4096 +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - /* Q31 */ - - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q31_16) - extern const q31_t twiddleCoef_16_q31[24]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q31_32) - extern const q31_t twiddleCoef_32_q31[48]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ +/* Q31 */ + +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q31_16) +extern const q31_t twiddleCoef_16_q31[24]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ + +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q31_32) +extern const q31_t twiddleCoef_32_q31[48]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q31_64) - extern const q31_t twiddleCoef_64_q31[96]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q31_64) +extern const q31_t twiddleCoef_64_q31[96]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q31_128) - extern const q31_t twiddleCoef_128_q31[192]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q31_128) +extern const q31_t twiddleCoef_128_q31[192]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q31_256) - extern const q31_t twiddleCoef_256_q31[384]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q31_256) +extern const q31_t twiddleCoef_256_q31[384]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q31_512) - extern const q31_t twiddleCoef_512_q31[768]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q31_512) +extern const q31_t twiddleCoef_512_q31[768]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q31_1024) - extern const q31_t twiddleCoef_1024_q31[1536]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q31_1024) +extern const q31_t twiddleCoef_1024_q31[1536]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q31_2048) - extern const q31_t twiddleCoef_2048_q31[3072]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q31_2048) +extern const q31_t twiddleCoef_2048_q31[3072]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q31_4096) - extern const q31_t twiddleCoef_4096_q31[6144]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q31_4096) +extern const q31_t twiddleCoef_4096_q31[6144]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q15_16) - extern const q15_t twiddleCoef_16_q15[24]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q15_16) +extern const q15_t twiddleCoef_16_q15[24]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q15_32) - extern const q15_t twiddleCoef_32_q15[48]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q15_32) +extern const q15_t twiddleCoef_32_q15[48]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q15_64) - extern const q15_t twiddleCoef_64_q15[96]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q15_64) +extern const q15_t twiddleCoef_64_q15[96]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q15_128) - extern const q15_t twiddleCoef_128_q15[192]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q15_128) +extern const q15_t twiddleCoef_128_q15[192]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q15_256) - extern const q15_t twiddleCoef_256_q15[384]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q15_256) +extern const q15_t twiddleCoef_256_q15[384]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q15_512) - extern const q15_t twiddleCoef_512_q15[768]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q15_512) +extern const q15_t twiddleCoef_512_q15[768]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q15_1024) - extern const q15_t twiddleCoef_1024_q15[1536]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q15_1024) +extern const q15_t twiddleCoef_1024_q15[1536]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q15_2048) - extern const q15_t twiddleCoef_2048_q15[3072]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q15_2048) +extern const q15_t twiddleCoef_2048_q15[3072]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q15_4096) - extern const q15_t twiddleCoef_4096_q15[6144]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q15_4096) +extern const q15_t twiddleCoef_4096_q15[6144]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - /* Double Precision Float RFFT twiddles */ - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F64_32) - extern const uint64_t twiddleCoefF64_rfft_32[32]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ +/* Double Precision Float RFFT twiddles */ +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F64_32) +extern const uint64_t twiddleCoefF64_rfft_32[32]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F64_64) - extern const uint64_t twiddleCoefF64_rfft_64[64]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F64_64) +extern const uint64_t twiddleCoefF64_rfft_64[64]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F64_128) - extern const uint64_t twiddleCoefF64_rfft_128[128]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F64_128) +extern const uint64_t twiddleCoefF64_rfft_128[128]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F64_256) - extern const uint64_t twiddleCoefF64_rfft_256[256]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F64_256) +extern const uint64_t twiddleCoefF64_rfft_256[256]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F64_512) - extern const uint64_t twiddleCoefF64_rfft_512[512]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F64_512) +extern const uint64_t twiddleCoefF64_rfft_512[512]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F64_1024) - extern const uint64_t twiddleCoefF64_rfft_1024[1024]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F64_1024) +extern const uint64_t twiddleCoefF64_rfft_1024[1024]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F64_2048) - extern const uint64_t twiddleCoefF64_rfft_2048[2048]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F64_4096) - extern const uint64_t twiddleCoefF64_rfft_4096[4096]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - - - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F32_32) - extern const float32_t twiddleCoef_rfft_32[32]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F32_64) - extern const float32_t twiddleCoef_rfft_64[64]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F32_128) - extern const float32_t twiddleCoef_rfft_128[128]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F32_256) - extern const float32_t twiddleCoef_rfft_256[256]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F32_512) - extern const float32_t twiddleCoef_rfft_512[512]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F32_1024) - extern const float32_t twiddleCoef_rfft_1024[1024]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F32_2048) - extern const float32_t twiddleCoef_rfft_2048[2048]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F32_4096) - extern const float32_t twiddleCoef_rfft_4096[4096]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - - - /* Double precision floating-point bit reversal tables */ - - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FLT64_16) - #define ARMBITREVINDEXTABLEF64_16_TABLE_LENGTH ((uint16_t)12) - extern const uint16_t armBitRevIndexTableF64_16[ARMBITREVINDEXTABLEF64_16_TABLE_LENGTH]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FLT64_32) - #define ARMBITREVINDEXTABLEF64_32_TABLE_LENGTH ((uint16_t)24) - extern const uint16_t armBitRevIndexTableF64_32[ARMBITREVINDEXTABLEF64_32_TABLE_LENGTH]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FLT64_64) - #define ARMBITREVINDEXTABLEF64_64_TABLE_LENGTH ((uint16_t)56) - extern const uint16_t armBitRevIndexTableF64_64[ARMBITREVINDEXTABLEF64_64_TABLE_LENGTH]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FLT64_128) - #define ARMBITREVINDEXTABLEF64_128_TABLE_LENGTH ((uint16_t)112) - extern const uint16_t armBitRevIndexTableF64_128[ARMBITREVINDEXTABLEF64_128_TABLE_LENGTH]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FLT64_256) - #define ARMBITREVINDEXTABLEF64_256_TABLE_LENGTH ((uint16_t)240) - extern const uint16_t armBitRevIndexTableF64_256[ARMBITREVINDEXTABLEF64_256_TABLE_LENGTH]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FLT64_512) - #define ARMBITREVINDEXTABLEF64_512_TABLE_LENGTH ((uint16_t)480) - extern const uint16_t armBitRevIndexTableF64_512[ARMBITREVINDEXTABLEF64_512_TABLE_LENGTH]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FLT64_1024) - #define ARMBITREVINDEXTABLEF64_1024_TABLE_LENGTH ((uint16_t)992) - extern const uint16_t armBitRevIndexTableF64_1024[ARMBITREVINDEXTABLEF64_1024_TABLE_LENGTH]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FLT64_2048) - #define ARMBITREVINDEXTABLEF64_2048_TABLE_LENGTH ((uint16_t)1984) - extern const uint16_t armBitRevIndexTableF64_2048[ARMBITREVINDEXTABLEF64_2048_TABLE_LENGTH]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FLT64_4096) - #define ARMBITREVINDEXTABLEF64_4096_TABLE_LENGTH ((uint16_t)4032) - extern const uint16_t armBitRevIndexTableF64_4096[ARMBITREVINDEXTABLEF64_4096_TABLE_LENGTH]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - /* floating-point bit reversal tables */ - - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FLT_16) - #define ARMBITREVINDEXTABLE_16_TABLE_LENGTH ((uint16_t)20) - extern const uint16_t armBitRevIndexTable16[ARMBITREVINDEXTABLE_16_TABLE_LENGTH]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FLT_32) - #define ARMBITREVINDEXTABLE_32_TABLE_LENGTH ((uint16_t)48) - extern const uint16_t armBitRevIndexTable32[ARMBITREVINDEXTABLE_32_TABLE_LENGTH]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FLT_64) - #define ARMBITREVINDEXTABLE_64_TABLE_LENGTH ((uint16_t)56) - extern const uint16_t armBitRevIndexTable64[ARMBITREVINDEXTABLE_64_TABLE_LENGTH]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FLT_128) - #define ARMBITREVINDEXTABLE_128_TABLE_LENGTH ((uint16_t)208) - extern const uint16_t armBitRevIndexTable128[ARMBITREVINDEXTABLE_128_TABLE_LENGTH]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FLT_256) - #define ARMBITREVINDEXTABLE_256_TABLE_LENGTH ((uint16_t)440) - extern const uint16_t armBitRevIndexTable256[ARMBITREVINDEXTABLE_256_TABLE_LENGTH]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FLT_512) - #define ARMBITREVINDEXTABLE_512_TABLE_LENGTH ((uint16_t)448) - extern const uint16_t armBitRevIndexTable512[ARMBITREVINDEXTABLE_512_TABLE_LENGTH]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FLT_1024) - #define ARMBITREVINDEXTABLE_1024_TABLE_LENGTH ((uint16_t)1800) - extern const uint16_t armBitRevIndexTable1024[ARMBITREVINDEXTABLE_1024_TABLE_LENGTH]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FLT_2048) - #define ARMBITREVINDEXTABLE_2048_TABLE_LENGTH ((uint16_t)3808) - extern const uint16_t armBitRevIndexTable2048[ARMBITREVINDEXTABLE_2048_TABLE_LENGTH]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FLT_4096) - #define ARMBITREVINDEXTABLE_4096_TABLE_LENGTH ((uint16_t)4032) - extern const uint16_t armBitRevIndexTable4096[ARMBITREVINDEXTABLE_4096_TABLE_LENGTH]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - - - /* fixed-point bit reversal tables */ - - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FXT_16) - #define ARMBITREVINDEXTABLE_FIXED_16_TABLE_LENGTH ((uint16_t)12) - extern const uint16_t armBitRevIndexTable_fixed_16[ARMBITREVINDEXTABLE_FIXED_16_TABLE_LENGTH]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FXT_32) - #define ARMBITREVINDEXTABLE_FIXED_32_TABLE_LENGTH ((uint16_t)24) - extern const uint16_t armBitRevIndexTable_fixed_32[ARMBITREVINDEXTABLE_FIXED_32_TABLE_LENGTH]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FXT_64) - #define ARMBITREVINDEXTABLE_FIXED_64_TABLE_LENGTH ((uint16_t)56) - extern const uint16_t armBitRevIndexTable_fixed_64[ARMBITREVINDEXTABLE_FIXED_64_TABLE_LENGTH]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FXT_128) - #define ARMBITREVINDEXTABLE_FIXED_128_TABLE_LENGTH ((uint16_t)112) - extern const uint16_t armBitRevIndexTable_fixed_128[ARMBITREVINDEXTABLE_FIXED_128_TABLE_LENGTH]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FXT_256) - #define ARMBITREVINDEXTABLE_FIXED_256_TABLE_LENGTH ((uint16_t)240) - extern const uint16_t armBitRevIndexTable_fixed_256[ARMBITREVINDEXTABLE_FIXED_256_TABLE_LENGTH]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FXT_512) - #define ARMBITREVINDEXTABLE_FIXED_512_TABLE_LENGTH ((uint16_t)480) - extern const uint16_t armBitRevIndexTable_fixed_512[ARMBITREVINDEXTABLE_FIXED_512_TABLE_LENGTH]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FXT_1024) - #define ARMBITREVINDEXTABLE_FIXED_1024_TABLE_LENGTH ((uint16_t)992) - extern const uint16_t armBitRevIndexTable_fixed_1024[ARMBITREVINDEXTABLE_FIXED_1024_TABLE_LENGTH]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FXT_2048) - #define ARMBITREVINDEXTABLE_FIXED_2048_TABLE_LENGTH ((uint16_t)1984) - extern const uint16_t armBitRevIndexTable_fixed_2048[ARMBITREVINDEXTABLE_FIXED_2048_TABLE_LENGTH]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FXT_4096) - #define ARMBITREVINDEXTABLE_FIXED_4096_TABLE_LENGTH ((uint16_t)4032) - extern const uint16_t armBitRevIndexTable_fixed_4096[ARMBITREVINDEXTABLE_FIXED_4096_TABLE_LENGTH]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_REALCOEF_F32) - extern const float32_t realCoefA[8192]; - extern const float32_t realCoefB[8192]; - #endif - - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_REALCOEF_Q31) - extern const q31_t realCoefAQ31[8192]; - extern const q31_t realCoefBQ31[8192]; - #endif - - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_REALCOEF_Q15) - extern const q15_t realCoefAQ15[8192]; - extern const q15_t realCoefBQ15[8192]; - #endif - - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_DCT4_F32_128) - extern const float32_t Weights_128[256]; - extern const float32_t cos_factors_128[128]; - #endif - - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_DCT4_F32_512) - extern const float32_t Weights_512[1024]; - extern const float32_t cos_factors_512[512]; - #endif - - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_DCT4_F32_2048) - extern const float32_t Weights_2048[4096]; - extern const float32_t cos_factors_2048[2048]; - #endif - - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_DCT4_F32_8192) - extern const float32_t Weights_8192[16384]; - extern const float32_t cos_factors_8192[8192]; - #endif - - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_DCT4_Q15_128) - extern const q15_t WeightsQ15_128[256]; - extern const q15_t cos_factorsQ15_128[128]; - #endif - - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_DCT4_Q15_512) - extern const q15_t WeightsQ15_512[1024]; - extern const q15_t cos_factorsQ15_512[512]; - #endif - - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_DCT4_Q15_2048) - extern const q15_t WeightsQ15_2048[4096]; - extern const q15_t cos_factorsQ15_2048[2048]; - #endif - - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_DCT4_Q15_8192) - extern const q15_t WeightsQ15_8192[16384]; - extern const q15_t cos_factorsQ15_8192[8192]; - #endif - - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_DCT4_Q31_128) - extern const q31_t WeightsQ31_128[256]; - extern const q31_t cos_factorsQ31_128[128]; - #endif - - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_DCT4_Q31_512) - extern const q31_t WeightsQ31_512[1024]; - extern const q31_t cos_factorsQ31_512[512]; - #endif - - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_DCT4_Q31_2048) - extern const q31_t WeightsQ31_2048[4096]; - extern const q31_t cos_factorsQ31_2048[2048]; - #endif - - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_DCT4_Q31_8192) - extern const q31_t WeightsQ31_8192[16384]; - extern const q31_t cos_factorsQ31_8192[8192]; - #endif +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F64_2048) +extern const uint64_t twiddleCoefF64_rfft_2048[2048]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ + +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F64_4096) +extern const uint64_t twiddleCoefF64_rfft_4096[4096]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ + + +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F32_32) +extern const float32_t twiddleCoef_rfft_32[32]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ + +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F32_64) +extern const float32_t twiddleCoef_rfft_64[64]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ + +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F32_128) +extern const float32_t twiddleCoef_rfft_128[128]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ + +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F32_256) +extern const float32_t twiddleCoef_rfft_256[256]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ + +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F32_512) +extern const float32_t twiddleCoef_rfft_512[512]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ + +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F32_1024) +extern const float32_t twiddleCoef_rfft_1024[1024]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ + +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F32_2048) +extern const float32_t twiddleCoef_rfft_2048[2048]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ + +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F32_4096) +extern const float32_t twiddleCoef_rfft_4096[4096]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ + + +/* Double precision floating-point bit reversal tables */ + +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FLT64_16) +#define ARMBITREVINDEXTABLEF64_16_TABLE_LENGTH ((uint16_t)12) +extern const uint16_t armBitRevIndexTableF64_16[ARMBITREVINDEXTABLEF64_16_TABLE_LENGTH]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ + +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FLT64_32) +#define ARMBITREVINDEXTABLEF64_32_TABLE_LENGTH ((uint16_t)24) +extern const uint16_t armBitRevIndexTableF64_32[ARMBITREVINDEXTABLEF64_32_TABLE_LENGTH]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ + +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FLT64_64) +#define ARMBITREVINDEXTABLEF64_64_TABLE_LENGTH ((uint16_t)56) +extern const uint16_t armBitRevIndexTableF64_64[ARMBITREVINDEXTABLEF64_64_TABLE_LENGTH]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ + +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FLT64_128) +#define ARMBITREVINDEXTABLEF64_128_TABLE_LENGTH ((uint16_t)112) +extern const uint16_t armBitRevIndexTableF64_128[ARMBITREVINDEXTABLEF64_128_TABLE_LENGTH]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ + +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FLT64_256) +#define ARMBITREVINDEXTABLEF64_256_TABLE_LENGTH ((uint16_t)240) +extern const uint16_t armBitRevIndexTableF64_256[ARMBITREVINDEXTABLEF64_256_TABLE_LENGTH]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ + +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FLT64_512) +#define ARMBITREVINDEXTABLEF64_512_TABLE_LENGTH ((uint16_t)480) +extern const uint16_t armBitRevIndexTableF64_512[ARMBITREVINDEXTABLEF64_512_TABLE_LENGTH]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ + +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FLT64_1024) +#define ARMBITREVINDEXTABLEF64_1024_TABLE_LENGTH ((uint16_t)992) +extern const uint16_t armBitRevIndexTableF64_1024[ARMBITREVINDEXTABLEF64_1024_TABLE_LENGTH]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ + +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FLT64_2048) +#define ARMBITREVINDEXTABLEF64_2048_TABLE_LENGTH ((uint16_t)1984) +extern const uint16_t armBitRevIndexTableF64_2048[ARMBITREVINDEXTABLEF64_2048_TABLE_LENGTH]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ + +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FLT64_4096) +#define ARMBITREVINDEXTABLEF64_4096_TABLE_LENGTH ((uint16_t)4032) +extern const uint16_t armBitRevIndexTableF64_4096[ARMBITREVINDEXTABLEF64_4096_TABLE_LENGTH]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ +/* floating-point bit reversal tables */ + +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FLT_16) +#define ARMBITREVINDEXTABLE_16_TABLE_LENGTH ((uint16_t)20) +extern const uint16_t armBitRevIndexTable16[ARMBITREVINDEXTABLE_16_TABLE_LENGTH]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ + +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FLT_32) +#define ARMBITREVINDEXTABLE_32_TABLE_LENGTH ((uint16_t)48) +extern const uint16_t armBitRevIndexTable32[ARMBITREVINDEXTABLE_32_TABLE_LENGTH]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ + +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FLT_64) +#define ARMBITREVINDEXTABLE_64_TABLE_LENGTH ((uint16_t)56) +extern const uint16_t armBitRevIndexTable64[ARMBITREVINDEXTABLE_64_TABLE_LENGTH]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ + +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FLT_128) +#define ARMBITREVINDEXTABLE_128_TABLE_LENGTH ((uint16_t)208) +extern const uint16_t armBitRevIndexTable128[ARMBITREVINDEXTABLE_128_TABLE_LENGTH]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ + +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FLT_256) +#define ARMBITREVINDEXTABLE_256_TABLE_LENGTH ((uint16_t)440) +extern const uint16_t armBitRevIndexTable256[ARMBITREVINDEXTABLE_256_TABLE_LENGTH]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ + +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FLT_512) +#define ARMBITREVINDEXTABLE_512_TABLE_LENGTH ((uint16_t)448) +extern const uint16_t armBitRevIndexTable512[ARMBITREVINDEXTABLE_512_TABLE_LENGTH]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ + +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FLT_1024) +#define ARMBITREVINDEXTABLE_1024_TABLE_LENGTH ((uint16_t)1800) +extern const uint16_t armBitRevIndexTable1024[ARMBITREVINDEXTABLE_1024_TABLE_LENGTH]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ + +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FLT_2048) +#define ARMBITREVINDEXTABLE_2048_TABLE_LENGTH ((uint16_t)3808) +extern const uint16_t armBitRevIndexTable2048[ARMBITREVINDEXTABLE_2048_TABLE_LENGTH]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ + +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FLT_4096) +#define ARMBITREVINDEXTABLE_4096_TABLE_LENGTH ((uint16_t)4032) +extern const uint16_t armBitRevIndexTable4096[ARMBITREVINDEXTABLE_4096_TABLE_LENGTH]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ + + +/* fixed-point bit reversal tables */ + +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FXT_16) +#define ARMBITREVINDEXTABLE_FIXED_16_TABLE_LENGTH ((uint16_t)12) +extern const uint16_t armBitRevIndexTable_fixed_16[ARMBITREVINDEXTABLE_FIXED_16_TABLE_LENGTH]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ + +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FXT_32) +#define ARMBITREVINDEXTABLE_FIXED_32_TABLE_LENGTH ((uint16_t)24) +extern const uint16_t armBitRevIndexTable_fixed_32[ARMBITREVINDEXTABLE_FIXED_32_TABLE_LENGTH]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ + +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FXT_64) +#define ARMBITREVINDEXTABLE_FIXED_64_TABLE_LENGTH ((uint16_t)56) +extern const uint16_t armBitRevIndexTable_fixed_64[ARMBITREVINDEXTABLE_FIXED_64_TABLE_LENGTH]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ + +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FXT_128) +#define ARMBITREVINDEXTABLE_FIXED_128_TABLE_LENGTH ((uint16_t)112) +extern const uint16_t armBitRevIndexTable_fixed_128[ARMBITREVINDEXTABLE_FIXED_128_TABLE_LENGTH]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ + +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FXT_256) +#define ARMBITREVINDEXTABLE_FIXED_256_TABLE_LENGTH ((uint16_t)240) +extern const uint16_t armBitRevIndexTable_fixed_256[ARMBITREVINDEXTABLE_FIXED_256_TABLE_LENGTH]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ + +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FXT_512) +#define ARMBITREVINDEXTABLE_FIXED_512_TABLE_LENGTH ((uint16_t)480) +extern const uint16_t armBitRevIndexTable_fixed_512[ARMBITREVINDEXTABLE_FIXED_512_TABLE_LENGTH]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ + +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FXT_1024) +#define ARMBITREVINDEXTABLE_FIXED_1024_TABLE_LENGTH ((uint16_t)992) +extern const uint16_t armBitRevIndexTable_fixed_1024[ARMBITREVINDEXTABLE_FIXED_1024_TABLE_LENGTH]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ + +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FXT_2048) +#define ARMBITREVINDEXTABLE_FIXED_2048_TABLE_LENGTH ((uint16_t)1984) +extern const uint16_t armBitRevIndexTable_fixed_2048[ARMBITREVINDEXTABLE_FIXED_2048_TABLE_LENGTH]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ + +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FXT_4096) +#define ARMBITREVINDEXTABLE_FIXED_4096_TABLE_LENGTH ((uint16_t)4032) +extern const uint16_t armBitRevIndexTable_fixed_4096[ARMBITREVINDEXTABLE_FIXED_4096_TABLE_LENGTH]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ + +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_REALCOEF_F32) +extern const float32_t realCoefA[8192]; +extern const float32_t realCoefB[8192]; +#endif + +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_REALCOEF_Q31) +extern const q31_t realCoefAQ31[8192]; +extern const q31_t realCoefBQ31[8192]; +#endif + +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_REALCOEF_Q15) +extern const q15_t realCoefAQ15[8192]; +extern const q15_t realCoefBQ15[8192]; +#endif + +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_DCT4_F32_128) +extern const float32_t Weights_128[256]; +extern const float32_t cos_factors_128[128]; +#endif + +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_DCT4_F32_512) +extern const float32_t Weights_512[1024]; +extern const float32_t cos_factors_512[512]; +#endif + +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_DCT4_F32_2048) +extern const float32_t Weights_2048[4096]; +extern const float32_t cos_factors_2048[2048]; +#endif + +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_DCT4_F32_8192) +extern const float32_t Weights_8192[16384]; +extern const float32_t cos_factors_8192[8192]; +#endif + +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_DCT4_Q15_128) +extern const q15_t WeightsQ15_128[256]; +extern const q15_t cos_factorsQ15_128[128]; +#endif + +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_DCT4_Q15_512) +extern const q15_t WeightsQ15_512[1024]; +extern const q15_t cos_factorsQ15_512[512]; +#endif + +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_DCT4_Q15_2048) +extern const q15_t WeightsQ15_2048[4096]; +extern const q15_t cos_factorsQ15_2048[2048]; +#endif + +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_DCT4_Q15_8192) +extern const q15_t WeightsQ15_8192[16384]; +extern const q15_t cos_factorsQ15_8192[8192]; +#endif + +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_DCT4_Q31_128) +extern const q31_t WeightsQ31_128[256]; +extern const q31_t cos_factorsQ31_128[128]; +#endif + +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_DCT4_Q31_512) +extern const q31_t WeightsQ31_512[1024]; +extern const q31_t cos_factorsQ31_512[512]; +#endif + +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_DCT4_Q31_2048) +extern const q31_t WeightsQ31_2048[4096]; +extern const q31_t cos_factorsQ31_2048[2048]; +#endif + +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_DCT4_Q31_8192) +extern const q31_t WeightsQ31_8192[16384]; +extern const q31_t cos_factorsQ31_8192[8192]; +#endif #endif /* if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_FFT_TABLES) */ #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_FAST_ALLOW_TABLES) - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FAST_TABLES) || defined(ARM_TABLE_RECIP_Q15) - extern const q15_t armRecipTableQ15[64]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) defined(ARM_ALL_FAST_TABLES) */ +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FAST_TABLES) || defined(ARM_TABLE_RECIP_Q15) +extern const q15_t armRecipTableQ15[64]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) defined(ARM_ALL_FAST_TABLES) */ - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FAST_TABLES) || defined(ARM_TABLE_RECIP_Q31) - extern const q31_t armRecipTableQ31[64]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) defined(ARM_ALL_FAST_TABLES) */ +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FAST_TABLES) || defined(ARM_TABLE_RECIP_Q31) +extern const q31_t armRecipTableQ31[64]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) defined(ARM_ALL_FAST_TABLES) */ - /* Tables for Fast Math Sine and Cosine */ - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FAST_TABLES) || defined(ARM_TABLE_SIN_F32) - extern const float32_t sinTable_f32[FAST_MATH_TABLE_SIZE + 1]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) defined(ARM_ALL_FAST_TABLES) */ +/* Tables for Fast Math Sine and Cosine */ +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FAST_TABLES) || defined(ARM_TABLE_SIN_F32) +extern const float32_t sinTable_f32[FAST_MATH_TABLE_SIZE + 1]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) defined(ARM_ALL_FAST_TABLES) */ - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FAST_TABLES) || defined(ARM_TABLE_SIN_Q31) - extern const q31_t sinTable_q31[FAST_MATH_TABLE_SIZE + 1]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) defined(ARM_ALL_FAST_TABLES) */ +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FAST_TABLES) || defined(ARM_TABLE_SIN_Q31) +extern const q31_t sinTable_q31[FAST_MATH_TABLE_SIZE + 1]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) defined(ARM_ALL_FAST_TABLES) */ - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FAST_TABLES) || defined(ARM_TABLE_SIN_Q15) - extern const q15_t sinTable_q15[FAST_MATH_TABLE_SIZE + 1]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) defined(ARM_ALL_FAST_TABLES) */ +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FAST_TABLES) || defined(ARM_TABLE_SIN_Q15) +extern const q15_t sinTable_q15[FAST_MATH_TABLE_SIZE + 1]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) defined(ARM_ALL_FAST_TABLES) */ - /* Fast vector sqrt */ - #if defined(ARM_MATH_MVEI) && !defined(ARM_MATH_AUTOVECTORIZE) - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FAST_TABLES) || defined(ARM_TABLE_FAST_SQRT_Q31_MVE) - extern const q31_t sqrtTable_Q31[256]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) defined(ARM_ALL_FAST_TABLES) */ - #endif +/* Fast vector sqrt */ +#if defined(ARM_MATH_MVEI) && !defined(ARM_MATH_AUTOVECTORIZE) +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FAST_TABLES) || defined(ARM_TABLE_FAST_SQRT_Q31_MVE) +extern const q31_t sqrtTable_Q31[256]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) defined(ARM_ALL_FAST_TABLES) */ +#endif - /* Accurate scalar sqrt */ - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FAST_TABLES) || defined(ARM_TABLE_SQRT_Q31) - extern const q31_t sqrt_initial_lut_q31[32]; - #endif +/* Accurate scalar sqrt */ +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FAST_TABLES) || defined(ARM_TABLE_SQRT_Q31) +extern const q31_t sqrt_initial_lut_q31[32]; +#endif - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FAST_TABLES) || defined(ARM_TABLE_SQRT_Q15) - extern const q15_t sqrt_initial_lut_q15[16]; - #endif +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FAST_TABLES) || defined(ARM_TABLE_SQRT_Q15) +extern const q15_t sqrt_initial_lut_q15[16]; +#endif - #if defined(ARM_MATH_MVEI) && !defined(ARM_MATH_AUTOVECTORIZE) - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FAST_TABLES) || defined(ARM_TABLE_FAST_SQRT_Q15_MVE) - extern const q15_t sqrtTable_Q15[256]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) defined(ARM_ALL_FAST_TABLES) */ - #endif +#if defined(ARM_MATH_MVEI) && !defined(ARM_MATH_AUTOVECTORIZE) +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FAST_TABLES) || defined(ARM_TABLE_FAST_SQRT_Q15_MVE) +extern const q15_t sqrtTable_Q15[256]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) defined(ARM_ALL_FAST_TABLES) */ +#endif #endif /* if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_FAST_TABLES) */ #if (defined(ARM_MATH_MVEF) || defined(ARM_MATH_HELIUM)) && !defined(ARM_MATH_AUTOVECTORIZE) - extern const float32_t exp_tab[8]; - extern const float32_t __logf_lut_f32[8]; +extern const float32_t exp_tab[8]; +extern const float32_t __logf_lut_f32[8]; #endif /* (defined(ARM_MATH_MVEF) || defined(ARM_MATH_HELIUM)) && !defined(ARM_MATH_AUTOVECTORIZE) */ #if (defined(ARM_MATH_MVEI) || defined(ARM_MATH_HELIUM)) && !defined(ARM_MATH_AUTOVECTORIZE) diff --git a/armlib/at32_sys/cmsis/cm4/core_support/arm_common_tables_f16.h b/armlib/at32_sys/cmsis/cm4/core_support/arm_common_tables_f16.h index f9a63fee8..2286c127f 100644 --- a/armlib/at32_sys/cmsis/cm4/core_support/arm_common_tables_f16.h +++ b/armlib/at32_sys/cmsis/cm4/core_support/arm_common_tables_f16.h @@ -38,90 +38,90 @@ extern "C" #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_FFT_ALLOW_TABLES) - /* F16 */ - #if !defined(__CC_ARM) && defined(ARM_FLOAT16_SUPPORTED) - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F16_16) - extern const float16_t twiddleCoefF16_16[32]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ +/* F16 */ +#if !defined(__CC_ARM) && defined(ARM_FLOAT16_SUPPORTED) +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F16_16) +extern const float16_t twiddleCoefF16_16[32]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F16_32) - extern const float16_t twiddleCoefF16_32[64]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F16_32) +extern const float16_t twiddleCoefF16_32[64]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F16_64) - extern const float16_t twiddleCoefF16_64[128]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F16_64) +extern const float16_t twiddleCoefF16_64[128]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F16_128) - extern const float16_t twiddleCoefF16_128[256]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F16_128) +extern const float16_t twiddleCoefF16_128[256]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F16_256) - extern const float16_t twiddleCoefF16_256[512]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F16_256) +extern const float16_t twiddleCoefF16_256[512]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F16_512) - extern const float16_t twiddleCoefF16_512[1024]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F16_512) +extern const float16_t twiddleCoefF16_512[1024]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F16_1024) - extern const float16_t twiddleCoefF16_1024[2048]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F16_1024) +extern const float16_t twiddleCoefF16_1024[2048]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F16_2048) - extern const float16_t twiddleCoefF16_2048[4096]; - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F16_2048) +extern const float16_t twiddleCoefF16_2048[4096]; +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F16_4096) - extern const float16_t twiddleCoefF16_4096[8192]; - #define twiddleCoefF16 twiddleCoefF16_4096 - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - - - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F16_32) - extern const float16_t twiddleCoefF16_rfft_32[32]; - #endif +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F16_4096) +extern const float16_t twiddleCoefF16_4096[8192]; +#define twiddleCoefF16 twiddleCoefF16_4096 +#endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F16_64) - extern const float16_t twiddleCoefF16_rfft_64[64]; - #endif - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F16_128) - extern const float16_t twiddleCoefF16_rfft_128[128]; - #endif +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F16_32) +extern const float16_t twiddleCoefF16_rfft_32[32]; +#endif - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F16_256) - extern const float16_t twiddleCoefF16_rfft_256[256]; - #endif +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F16_64) +extern const float16_t twiddleCoefF16_rfft_64[64]; +#endif - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F16_512) - extern const float16_t twiddleCoefF16_rfft_512[512]; - #endif +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F16_128) +extern const float16_t twiddleCoefF16_rfft_128[128]; +#endif - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F16_1024) - extern const float16_t twiddleCoefF16_rfft_1024[1024]; - #endif +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F16_256) +extern const float16_t twiddleCoefF16_rfft_256[256]; +#endif - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F16_2048) - extern const float16_t twiddleCoefF16_rfft_2048[2048]; - #endif +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F16_512) +extern const float16_t twiddleCoefF16_rfft_512[512]; +#endif - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F16_4096) - extern const float16_t twiddleCoefF16_rfft_4096[4096]; - #endif +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F16_1024) +extern const float16_t twiddleCoefF16_rfft_1024[1024]; +#endif + +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F16_2048) +extern const float16_t twiddleCoefF16_rfft_2048[2048]; +#endif + +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F16_4096) +extern const float16_t twiddleCoefF16_rfft_4096[4096]; +#endif + +#endif /* ARMAC5 */ - #endif /* ARMAC5 */ - #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_FFT_ALLOW_TABLES) */ #if !defined(__CC_ARM) && defined(ARM_FLOAT16_SUPPORTED) #if (defined(ARM_MATH_MVEF) || defined(ARM_MATH_HELIUM)) && !defined(ARM_MATH_AUTOVECTORIZE) - extern const float16_t exp_tab_f16[8]; - extern const float16_t __logf_lut_f16[8]; +extern const float16_t exp_tab_f16[8]; +extern const float16_t __logf_lut_f16[8]; #endif /* (defined(ARM_MATH_MVEF) || defined(ARM_MATH_HELIUM)) && !defined(ARM_MATH_AUTOVECTORIZE) */ -#endif - +#endif + #ifdef __cplusplus } @@ -129,4 +129,4 @@ extern "C" #endif /* _ARM_COMMON_TABLES_F16_H */ - + diff --git a/armlib/at32_sys/cmsis/cm4/core_support/arm_const_structs.h b/armlib/at32_sys/cmsis/cm4/core_support/arm_const_structs.h index 59026db5d..39f49caf9 100644 --- a/armlib/at32_sys/cmsis/cm4/core_support/arm_const_structs.h +++ b/armlib/at32_sys/cmsis/cm4/core_support/arm_const_structs.h @@ -38,45 +38,45 @@ extern "C" { #endif - extern const arm_cfft_instance_f64 arm_cfft_sR_f64_len16; - extern const arm_cfft_instance_f64 arm_cfft_sR_f64_len32; - extern const arm_cfft_instance_f64 arm_cfft_sR_f64_len64; - extern const arm_cfft_instance_f64 arm_cfft_sR_f64_len128; - extern const arm_cfft_instance_f64 arm_cfft_sR_f64_len256; - extern const arm_cfft_instance_f64 arm_cfft_sR_f64_len512; - extern const arm_cfft_instance_f64 arm_cfft_sR_f64_len1024; - extern const arm_cfft_instance_f64 arm_cfft_sR_f64_len2048; - extern const arm_cfft_instance_f64 arm_cfft_sR_f64_len4096; +extern const arm_cfft_instance_f64 arm_cfft_sR_f64_len16; +extern const arm_cfft_instance_f64 arm_cfft_sR_f64_len32; +extern const arm_cfft_instance_f64 arm_cfft_sR_f64_len64; +extern const arm_cfft_instance_f64 arm_cfft_sR_f64_len128; +extern const arm_cfft_instance_f64 arm_cfft_sR_f64_len256; +extern const arm_cfft_instance_f64 arm_cfft_sR_f64_len512; +extern const arm_cfft_instance_f64 arm_cfft_sR_f64_len1024; +extern const arm_cfft_instance_f64 arm_cfft_sR_f64_len2048; +extern const arm_cfft_instance_f64 arm_cfft_sR_f64_len4096; - extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len16; - extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len32; - extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len64; - extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len128; - extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len256; - extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len512; - extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len1024; - extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len2048; - extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len4096; +extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len16; +extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len32; +extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len64; +extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len128; +extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len256; +extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len512; +extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len1024; +extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len2048; +extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len4096; - extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len16; - extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len32; - extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len64; - extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len128; - extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len256; - extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len512; - extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len1024; - extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len2048; - extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len4096; +extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len16; +extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len32; +extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len64; +extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len128; +extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len256; +extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len512; +extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len1024; +extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len2048; +extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len4096; - extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len16; - extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len32; - extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len64; - extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len128; - extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len256; - extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len512; - extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len1024; - extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len2048; - extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len4096; +extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len16; +extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len32; +extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len64; +extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len128; +extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len256; +extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len512; +extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len1024; +extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len2048; +extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len4096; #ifdef __cplusplus } diff --git a/armlib/at32_sys/cmsis/cm4/core_support/arm_const_structs_f16.h b/armlib/at32_sys/cmsis/cm4/core_support/arm_const_structs_f16.h index 0984d74a2..e9a15d7c5 100644 --- a/armlib/at32_sys/cmsis/cm4/core_support/arm_const_structs_f16.h +++ b/armlib/at32_sys/cmsis/cm4/core_support/arm_const_structs_f16.h @@ -41,33 +41,33 @@ extern "C" #endif #if !defined(__CC_ARM) && defined(ARM_FLOAT16_SUPPORTED) - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_F16_16) && defined(ARM_TABLE_BITREVIDX_FLT_16)) - extern const arm_cfft_instance_f16 arm_cfft_sR_f16_len16; - #endif - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_F16_32) && defined(ARM_TABLE_BITREVIDX_FLT_32)) - extern const arm_cfft_instance_f16 arm_cfft_sR_f16_len32; - #endif - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_F16_64) && defined(ARM_TABLE_BITREVIDX_FLT_64)) - extern const arm_cfft_instance_f16 arm_cfft_sR_f16_len64; - #endif - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_F16_128) && defined(ARM_TABLE_BITREVIDX_FLT_128)) - extern const arm_cfft_instance_f16 arm_cfft_sR_f16_len128; - #endif - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_F16_256) && defined(ARM_TABLE_BITREVIDX_FLT_256)) - extern const arm_cfft_instance_f16 arm_cfft_sR_f16_len256; - #endif - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_F16_512) && defined(ARM_TABLE_BITREVIDX_FLT_512)) - extern const arm_cfft_instance_f16 arm_cfft_sR_f16_len512; - #endif - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_F16_1024) && defined(ARM_TABLE_BITREVIDX_FLT_1024)) - extern const arm_cfft_instance_f16 arm_cfft_sR_f16_len1024; - #endif - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_F16_2048) && defined(ARM_TABLE_BITREVIDX_FLT_2048)) - extern const arm_cfft_instance_f16 arm_cfft_sR_f16_len2048; - #endif - #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_F16_4096) && defined(ARM_TABLE_BITREVIDX_FLT_4096)) - extern const arm_cfft_instance_f16 arm_cfft_sR_f16_len4096; - #endif +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_F16_16) && defined(ARM_TABLE_BITREVIDX_FLT_16)) +extern const arm_cfft_instance_f16 arm_cfft_sR_f16_len16; +#endif +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_F16_32) && defined(ARM_TABLE_BITREVIDX_FLT_32)) +extern const arm_cfft_instance_f16 arm_cfft_sR_f16_len32; +#endif +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_F16_64) && defined(ARM_TABLE_BITREVIDX_FLT_64)) +extern const arm_cfft_instance_f16 arm_cfft_sR_f16_len64; +#endif +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_F16_128) && defined(ARM_TABLE_BITREVIDX_FLT_128)) +extern const arm_cfft_instance_f16 arm_cfft_sR_f16_len128; +#endif +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_F16_256) && defined(ARM_TABLE_BITREVIDX_FLT_256)) +extern const arm_cfft_instance_f16 arm_cfft_sR_f16_len256; +#endif +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_F16_512) && defined(ARM_TABLE_BITREVIDX_FLT_512)) +extern const arm_cfft_instance_f16 arm_cfft_sR_f16_len512; +#endif +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_F16_1024) && defined(ARM_TABLE_BITREVIDX_FLT_1024)) +extern const arm_cfft_instance_f16 arm_cfft_sR_f16_len1024; +#endif +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_F16_2048) && defined(ARM_TABLE_BITREVIDX_FLT_2048)) +extern const arm_cfft_instance_f16 arm_cfft_sR_f16_len2048; +#endif +#if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || (defined(ARM_TABLE_TWIDDLECOEF_F16_4096) && defined(ARM_TABLE_BITREVIDX_FLT_4096)) +extern const arm_cfft_instance_f16 arm_cfft_sR_f16_len4096; +#endif #endif #ifdef __cplusplus diff --git a/armlib/at32_sys/cmsis/cm4/core_support/arm_helium_utils.h b/armlib/at32_sys/cmsis/cm4/core_support/arm_helium_utils.h index ae9037cfe..b7fdf8faf 100644 --- a/armlib/at32_sys/cmsis/cm4/core_support/arm_helium_utils.h +++ b/armlib/at32_sys/cmsis/cm4/core_support/arm_helium_utils.h @@ -53,8 +53,7 @@ Definitions available for MVEF only ***************************************/ #if (defined (ARM_MATH_HELIUM) || defined(ARM_MATH_MVEF)) && !defined(ARM_MATH_AUTOVECTORIZE) -__STATIC_FORCEINLINE float32_t vecAddAcrossF32Mve(float32x4_t in) -{ +__STATIC_FORCEINLINE float32_t vecAddAcrossF32Mve(float32x4_t in) { float32_t acc; acc = vgetq_lane(in, 0) + vgetq_lane(in, 1) + @@ -94,8 +93,7 @@ Definitions available for f16 datatype with HW acceleration only #if defined(ARM_FLOAT16_SUPPORTED) #if defined (ARM_MATH_MVE_FLOAT16) && !defined(ARM_MATH_AUTOVECTORIZE) -__STATIC_FORCEINLINE float16_t vecAddAcrossF16Mve(float16x8_t in) -{ +__STATIC_FORCEINLINE float16_t vecAddAcrossF16Mve(float16x8_t in) { float16x8_t tmpVec; _Float16 acc; @@ -109,8 +107,7 @@ __STATIC_FORCEINLINE float16_t vecAddAcrossF16Mve(float16x8_t in) } __STATIC_FORCEINLINE float16x8_t __mve_cmplx_sum_intra_vec_f16( - float16x8_t vecIn) -{ + float16x8_t vecIn) { float16x8_t vecTmp, vecOut; uint32_t tmp; @@ -127,7 +124,7 @@ __STATIC_FORCEINLINE float16x8_t __mve_cmplx_sum_intra_vec_f16( /* * shift left, random tmp insertion in bottom */ - vecOut = vreinterpretq_f16_s32(vshlcq_s32(vreinterpretq_s32_f16(vecOut) , &tmp, 32)); + vecOut = vreinterpretq_f16_s32(vshlcq_s32(vreinterpretq_s32_f16(vecOut), &tmp, 32)); /* * Compute: * DONTCARE | DONTCARE | re0+re1+re0+re1 |im0+im1+im0+im1 @@ -151,8 +148,7 @@ __STATIC_FORCEINLINE float16x8_t __mve_cmplx_sum_intra_vec_f16( __STATIC_FORCEINLINE void mve_cmplx_sum_intra_vec_f16( float16x8_t vecIn, - float16_t *pOut) -{ + float16_t *pOut) { float16x8_t vecOut = __mve_cmplx_sum_intra_vec_f16(vecIn); /* * Cmplx sum is in 4rd & 5th f16 elt @@ -179,7 +175,7 @@ __STATIC_FORCEINLINE void mve_cmplx_sum_intra_vec_f16( } #endif -#endif +#endif /*************************************** @@ -189,9 +185,8 @@ Definitions available for MVEI and MVEF only #if (defined (ARM_MATH_HELIUM) || defined(ARM_MATH_MVEF) || defined(ARM_MATH_MVEI)) && !defined(ARM_MATH_AUTOVECTORIZE) /* Following functions are used to transpose matrix in f32 and q31 cases */ __STATIC_INLINE arm_status arm_mat_trans_32bit_2x2_mve( - uint32_t * pDataSrc, - uint32_t * pDataDest) -{ + uint32_t *pDataSrc, + uint32_t *pDataDest) { static const uint32x4_t vecOffs = { 0, 2, 1, 3 }; /* * @@ -206,9 +201,8 @@ __STATIC_INLINE arm_status arm_mat_trans_32bit_2x2_mve( } __STATIC_INLINE arm_status arm_mat_trans_32bit_3x3_mve( - uint32_t * pDataSrc, - uint32_t * pDataDest) -{ + uint32_t *pDataSrc, + uint32_t *pDataDest) { const uint32x4_t vecOffs1 = { 0, 3, 6, 1}; const uint32x4_t vecOffs2 = { 4, 7, 2, 5}; /* @@ -229,8 +223,7 @@ __STATIC_INLINE arm_status arm_mat_trans_32bit_3x3_mve( return (ARM_MATH_SUCCESS); } -__STATIC_INLINE arm_status arm_mat_trans_32bit_4x4_mve(uint32_t * pDataSrc, uint32_t * pDataDest) -{ +__STATIC_INLINE arm_status arm_mat_trans_32bit_4x4_mve(uint32_t *pDataSrc, uint32_t *pDataDest) { /* * 4x4 Matrix transposition * is 4 x de-interleave operation @@ -259,9 +252,8 @@ __STATIC_INLINE arm_status arm_mat_trans_32bit_4x4_mve(uint32_t * pDataSrc, uint __STATIC_INLINE arm_status arm_mat_trans_32bit_generic_mve( uint16_t srcRows, uint16_t srcCols, - uint32_t * pDataSrc, - uint32_t * pDataDest) -{ + uint32_t *pDataSrc, + uint32_t *pDataDest) { uint32x4_t vecOffs; uint32_t i; uint32_t blkCnt; @@ -273,16 +265,14 @@ __STATIC_INLINE arm_status arm_mat_trans_32bit_generic_mve( vecOffs = vecOffs * srcCols; i = srcCols; - do - { + do { pDataC = (uint32_t const *) pDataSrc; pDataDestR = pDataDest; blkCnt = srcRows >> 2; - while (blkCnt > 0U) - { + while (blkCnt > 0U) { vecIn = vldrwq_gather_shifted_offset_u32(pDataC, vecOffs); - vstrwq(pDataDestR, vecIn); + vstrwq(pDataDestR, vecIn); pDataDestR += 4; pDataC = pDataC + srcCols * 4; /* @@ -295,8 +285,7 @@ __STATIC_INLINE arm_status arm_mat_trans_32bit_generic_mve( * tail */ blkCnt = srcRows & 3; - if (blkCnt > 0U) - { + if (blkCnt > 0U) { mve_pred16_t p0 = vctp32q(blkCnt); vecIn = vldrwq_gather_shifted_offset_u32(pDataC, vecOffs); vstrwq_p(pDataDestR, vecIn, p0); @@ -304,8 +293,7 @@ __STATIC_INLINE arm_status arm_mat_trans_32bit_generic_mve( pDataSrc += 1; pDataDest += srcRows; - } - while (--i); + } while (--i); return (ARM_MATH_SUCCESS); } @@ -316,8 +304,7 @@ __STATIC_INLINE arm_status arm_mat_cmplx_trans_32bit( uint32_t *pDataSrc, uint16_t dstRows, uint16_t dstCols, - uint32_t *pDataDest) -{ + uint32_t *pDataDest) { uint32_t i; uint32_t const *pDataC; uint32_t *pDataRow; @@ -330,8 +317,7 @@ __STATIC_INLINE arm_status arm_mat_cmplx_trans_32bit( /* * Check for matrix mismatch condition */ - if ((srcRows != dstCols) || (srcCols != dstRows)) - { + if ((srcRows != dstCols) || (srcCols != dstRows)) { /* * Set status as ARM_MATH_SIZE_MISMATCH */ @@ -352,31 +338,28 @@ __STATIC_INLINE arm_status arm_mat_cmplx_trans_32bit( pDataRow = pDataSrc; pDataDestRow = pDataDest; i = srcCols; - do - { + do { pDataC = (uint32_t const *) pDataRow; pDataDestR = pDataDestRow; vecOffsCur = vecOffsRef; blkCnt = (srcRows * CMPLX_DIM) >> 2; - while (blkCnt > 0U) - { + while (blkCnt > 0U) { vecIn = vldrwq_gather_shifted_offset(pDataC, vecOffsCur); - vstrwq(pDataDestR, vecIn); + vstrwq(pDataDestR, vecIn); pDataDestR += 4; vecOffsCur = vaddq(vecOffsCur, (srcCols << 2)); /* * Decrement the blockSize loop counter */ - blkCnt--; + blkCnt--; } /* * tail * (will be merged thru tail predication) */ blkCnt = (srcRows * CMPLX_DIM) & 3; - if (blkCnt > 0U) - { + if (blkCnt > 0U) { mve_pred16_t p0 = vctp32q(blkCnt); vecIn = vldrwq_gather_shifted_offset(pDataC, vecOffsCur); vstrwq_p(pDataDestR, vecIn, p0); @@ -384,14 +367,12 @@ __STATIC_INLINE arm_status arm_mat_cmplx_trans_32bit( pDataRow += CMPLX_DIM; pDataDestRow += (srcRows * CMPLX_DIM); - } - while (--i); + } while (--i); return (ARM_MATH_SUCCESS); } -__STATIC_INLINE arm_status arm_mat_trans_16bit_2x2(uint16_t * pDataSrc, uint16_t * pDataDest) -{ +__STATIC_INLINE arm_status arm_mat_trans_16bit_2x2(uint16_t *pDataSrc, uint16_t *pDataDest) { pDataDest[0] = pDataSrc[0]; pDataDest[3] = pDataSrc[3]; pDataDest[2] = pDataSrc[1]; @@ -400,8 +381,7 @@ __STATIC_INLINE arm_status arm_mat_trans_16bit_2x2(uint16_t * pDataSrc, uint16_t return (ARM_MATH_SUCCESS); } -__STATIC_INLINE arm_status arm_mat_trans_16bit_3x3_mve(uint16_t * pDataSrc, uint16_t * pDataDest) -{ +__STATIC_INLINE arm_status arm_mat_trans_16bit_3x3_mve(uint16_t *pDataSrc, uint16_t *pDataDest) { static const uint16_t stridesTr33[8] = { 0, 3, 6, 1, 4, 7, 2, 5 }; uint16x8_t vecOffs1; uint16x8_t vecIn1; @@ -423,13 +403,12 @@ __STATIC_INLINE arm_status arm_mat_trans_16bit_3x3_mve(uint16_t * pDataSrc, uint } -__STATIC_INLINE arm_status arm_mat_trans_16bit_4x4_mve(uint16_t * pDataSrc, uint16_t * pDataDest) -{ +__STATIC_INLINE arm_status arm_mat_trans_16bit_4x4_mve(uint16_t *pDataSrc, uint16_t *pDataDest) { static const uint16_t stridesTr44_1[8] = { 0, 4, 8, 12, 1, 5, 9, 13 }; static const uint16_t stridesTr44_2[8] = { 2, 6, 10, 14, 3, 7, 11, 15 }; uint16x8_t vecOffs1, vecOffs2; uint16x8_t vecIn1, vecIn2; - uint16_t const * pDataSrcVec = (uint16_t const *) pDataSrc; + uint16_t const *pDataSrcVec = (uint16_t const *) pDataSrc; /* * 4x4 Matrix transposition @@ -458,9 +437,8 @@ __STATIC_INLINE arm_status arm_mat_trans_16bit_4x4_mve(uint16_t * pDataSrc, uint __STATIC_INLINE arm_status arm_mat_trans_16bit_generic( uint16_t srcRows, uint16_t srcCols, - uint16_t * pDataSrc, - uint16_t * pDataDest) -{ + uint16_t *pDataSrc, + uint16_t *pDataDest) { uint16x8_t vecOffs; uint32_t i; uint32_t blkCnt; @@ -472,16 +450,14 @@ __STATIC_INLINE arm_status arm_mat_trans_16bit_generic( vecOffs = vecOffs * srcCols; i = srcCols; - while(i > 0U) - { + while (i > 0U) { pDataC = (uint16_t const *) pDataSrc; pDataDestR = pDataDest; blkCnt = srcRows >> 3; - while (blkCnt > 0U) - { + while (blkCnt > 0U) { vecIn = vldrhq_gather_shifted_offset_u16(pDataC, vecOffs); - vstrhq_u16(pDataDestR, vecIn); + vstrhq_u16(pDataDestR, vecIn); pDataDestR += 8; pDataC = pDataC + srcCols * 8; /* @@ -494,8 +470,7 @@ __STATIC_INLINE arm_status arm_mat_trans_16bit_generic( * tail */ blkCnt = srcRows & 7; - if (blkCnt > 0U) - { + if (blkCnt > 0U) { mve_pred16_t p0 = vctp16q(blkCnt); vecIn = vldrhq_gather_shifted_offset_u16(pDataC, vecOffs); vstrhq_p_u16(pDataDestR, vecIn, p0); @@ -515,8 +490,7 @@ __STATIC_INLINE arm_status arm_mat_cmplx_trans_16bit( uint16_t *pDataSrc, uint16_t dstRows, uint16_t dstCols, - uint16_t *pDataDest) -{ + uint16_t *pDataDest) { static const uint16_t loadCmplxCol[8] = { 0, 0, 1, 1, 2, 2, 3, 3 }; int i; uint16x8_t vecOffsRef, vecOffsCur; @@ -530,8 +504,7 @@ __STATIC_INLINE arm_status arm_mat_cmplx_trans_16bit( /* * Check for matrix mismatch condition */ - if ((srcRows != dstCols) || (srcCols != dstRows)) - { + if ((srcRows != dstCols) || (srcCols != dstRows)) { /* * Set status as ARM_MATH_SIZE_MISMATCH */ @@ -551,24 +524,22 @@ __STATIC_INLINE arm_status arm_mat_cmplx_trans_16bit( * build [0, 1, 2xcol, 2xcol+1, 4xcol, 4xcol+1, 6xcol, 6xcol+1] */ vecOffsRef = vldrhq_u16((uint16_t const *) loadCmplxCol); - vecOffsRef = vmulq(vecOffsRef, (uint16_t) (srcCols * CMPLX_DIM)) - + viwdupq_u16((uint32_t)0, (uint16_t) 2, 1); + vecOffsRef = vmulq(vecOffsRef, (uint16_t)(srcCols * CMPLX_DIM)) + + viwdupq_u16((uint32_t)0, (uint16_t) 2, 1); pDataRow = pDataSrc; pDataDestRow = pDataDest; i = srcCols; - do - { + do { pDataC = (uint16_t const *) pDataRow; pDataDestR = pDataDestRow; vecOffsCur = vecOffsRef; blkCnt = (srcRows * CMPLX_DIM) >> 3; - while (blkCnt > 0U) - { + while (blkCnt > 0U) { vecIn = vldrhq_gather_shifted_offset(pDataC, vecOffsCur); - vstrhq(pDataDestR, vecIn); - pDataDestR+= 8; // VEC_LANES_U16 + vstrhq(pDataDestR, vecIn); + pDataDestR += 8; // VEC_LANES_U16 vecOffsCur = vaddq(vecOffsCur, (srcCols << 3)); /* * Decrement the blockSize loop counter @@ -580,8 +551,7 @@ __STATIC_INLINE arm_status arm_mat_cmplx_trans_16bit( * (will be merged thru tail predication) */ blkCnt = (srcRows * CMPLX_DIM) & 0x7; - if (blkCnt > 0U) - { + if (blkCnt > 0U) { mve_pred16_t p0 = vctp16q(blkCnt); vecIn = vldrhq_gather_shifted_offset(pDataC, vecOffsCur); vstrhq_p(pDataDestR, vecIn, p0); @@ -589,8 +559,7 @@ __STATIC_INLINE arm_status arm_mat_cmplx_trans_16bit( pDataRow += CMPLX_DIM; pDataDestRow += (srcRows * CMPLX_DIM); - } - while (--i); + } while (--i); return (ARM_MATH_SUCCESS); } @@ -610,8 +579,7 @@ Definitions available for MVEI only #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FAST_TABLES) || defined(ARM_TABLE_FAST_SQRT_Q31_MVE) -__STATIC_INLINE q31x4_t FAST_VSQRT_Q31(q31x4_t vecIn) -{ +__STATIC_INLINE q31x4_t FAST_VSQRT_Q31(q31x4_t vecIn) { q63x2_t vecTmpLL; q31x4_t vecTmp0, vecTmp1; q31_t scale; @@ -678,8 +646,7 @@ __STATIC_INLINE q31x4_t FAST_VSQRT_Q31(q31x4_t vecIn) #endif #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FAST_TABLES) || defined(ARM_TABLE_FAST_SQRT_Q15_MVE) -__STATIC_INLINE q15x8_t FAST_VSQRT_Q15(q15x8_t vecIn) -{ +__STATIC_INLINE q15x8_t FAST_VSQRT_Q15(q15x8_t vecIn) { q31x4_t vecTmpLev, vecTmpLodd, vecSignL; q15x8_t vecTmp0, vecTmp1; q15x8_t vecNrm, vecDst, vecIdx, vecSignBits; diff --git a/armlib/at32_sys/cmsis/cm4/core_support/arm_math.h b/armlib/at32_sys/cmsis/cm4/core_support/arm_math.h index 300c5cf4a..f8c7f34b6 100644 --- a/armlib/at32_sys/cmsis/cm4/core_support/arm_math.h +++ b/armlib/at32_sys/cmsis/cm4/core_support/arm_math.h @@ -29,7 +29,7 @@ * \section intro Introduction * * This user manual describes the CMSIS DSP software library, - * a suite of common signal processing functions for use on Cortex-M and Cortex-A processor + * a suite of common signal processing functions for use on Cortex-M and Cortex-A processor * based devices. * * The library is divided into a number of functions each covering a specific category: @@ -101,12 +101,12 @@ * - ARM_MATH_NEON: * * Define macro ARM_MATH_NEON to enable Neon versions of the DSP functions. - * It is not enabled by default when Neon is available because performances are + * It is not enabled by default when Neon is available because performances are * dependent on the compiler and target architecture. * * - ARM_MATH_NEON_EXPERIMENTAL: * - * Define macro ARM_MATH_NEON_EXPERIMENTAL to enable experimental Neon versions of + * Define macro ARM_MATH_NEON_EXPERIMENTAL to enable experimental Neon versions of * of some DSP functions. Experimental Neon versions currently do not have better * performances than the scalar versions. * @@ -191,7 +191,7 @@ #include "dsp/none.h" #include "dsp/utils.h" -#include "dsp/basic_math_functions.h" +#include "dsp/basic_math_functions.h" #include "dsp/interpolation_functions.h" #include "dsp/bayes_functions.h" #include "dsp/matrix_functions.h" diff --git a/armlib/at32_sys/cmsis/cm4/core_support/arm_math_memory.h b/armlib/at32_sys/cmsis/cm4/core_support/arm_math_memory.h index 7bd83dc27..8dee51ed1 100644 --- a/armlib/at32_sys/cmsis/cm4/core_support/arm_math_memory.h +++ b/armlib/at32_sys/cmsis/cm4/core_support/arm_math_memory.h @@ -40,23 +40,23 @@ extern "C" @deprecated */ #if defined ( __CC_ARM ) - #define __SIMD32_TYPE int32_t __packed +#define __SIMD32_TYPE int32_t __packed #elif defined ( __ARMCC_VERSION ) && ( __ARMCC_VERSION >= 6010050 ) - #define __SIMD32_TYPE int32_t +#define __SIMD32_TYPE int32_t #elif defined ( __GNUC__ ) - #define __SIMD32_TYPE int32_t +#define __SIMD32_TYPE int32_t #elif defined ( __ICCARM__ ) - #define __SIMD32_TYPE int32_t __packed +#define __SIMD32_TYPE int32_t __packed #elif defined ( __TI_ARM__ ) - #define __SIMD32_TYPE int32_t +#define __SIMD32_TYPE int32_t #elif defined ( __CSMC__ ) - #define __SIMD32_TYPE int32_t +#define __SIMD32_TYPE int32_t #elif defined ( __TASKING__ ) - #define __SIMD32_TYPE __un(aligned) int32_t +#define __SIMD32_TYPE __un(aligned) int32_t #elif defined(_MSC_VER ) - #define __SIMD32_TYPE int32_t +#define __SIMD32_TYPE int32_t #else - #error Unknown compiler +#error Unknown compiler #endif #define __SIMD32(addr) (*(__SIMD32_TYPE **) & (addr)) @@ -73,18 +73,17 @@ extern "C" @param[in] pQ15 points to input value @return Q31 value */ -__STATIC_FORCEINLINE q31_t read_q15x2 ( - q15_t const * pQ15) -{ - q31_t val; +__STATIC_FORCEINLINE q31_t read_q15x2( + q15_t const *pQ15) { + q31_t val; #ifdef __ARM_FEATURE_UNALIGNED - memcpy (&val, pQ15, 4); + memcpy(&val, pQ15, 4); #else - val = (pQ15[1] << 16) | (pQ15[0] & 0x0FFFF) ; + val = (pQ15[1] << 16) | (pQ15[0] & 0x0FFFF) ; #endif - return (val); + return (val); } /** @@ -107,19 +106,18 @@ __STATIC_FORCEINLINE q31_t read_q15x2 ( @param[in] value Q31 value @return none */ -__STATIC_FORCEINLINE void write_q15x2_ia ( - q15_t ** pQ15, - q31_t value) -{ - q31_t val = value; +__STATIC_FORCEINLINE void write_q15x2_ia( + q15_t **pQ15, + q31_t value) { + q31_t val = value; #ifdef __ARM_FEATURE_UNALIGNED - memcpy (*pQ15, &val, 4); + memcpy(*pQ15, &val, 4); #else - (*pQ15)[0] = (q15_t)(val & 0x0FFFF); - (*pQ15)[1] = (q15_t)((val >> 16) & 0x0FFFF); + (*pQ15)[0] = (q15_t)(val & 0x0FFFF); + (*pQ15)[1] = (q15_t)((val >> 16) & 0x0FFFF); #endif - *pQ15 += 2; + *pQ15 += 2; } /** @@ -128,17 +126,16 @@ __STATIC_FORCEINLINE void write_q15x2_ia ( @param[in] value Q31 value @return none */ -__STATIC_FORCEINLINE void write_q15x2 ( - q15_t * pQ15, - q31_t value) -{ - q31_t val = value; +__STATIC_FORCEINLINE void write_q15x2( + q15_t *pQ15, + q31_t value) { + q31_t val = value; #ifdef __ARM_FEATURE_UNALIGNED - memcpy (pQ15, &val, 4); + memcpy(pQ15, &val, 4); #else - pQ15[0] = (q15_t)(val & 0x0FFFF); - pQ15[1] = (q15_t)(val >> 16); + pQ15[0] = (q15_t)(val & 0x0FFFF); + pQ15[1] = (q15_t)(val >> 16); #endif } @@ -148,17 +145,16 @@ __STATIC_FORCEINLINE void write_q15x2 ( @param[in] pQ7 points to input value @return Q31 value */ -__STATIC_FORCEINLINE q31_t read_q7x4 ( - q7_t const * pQ7) -{ - q31_t val; +__STATIC_FORCEINLINE q31_t read_q7x4( + q7_t const *pQ7) { + q31_t val; #ifdef __ARM_FEATURE_UNALIGNED - memcpy (&val, pQ7, 4); + memcpy(&val, pQ7, 4); #else - val =((pQ7[3] & 0x0FF) << 24) | ((pQ7[2] & 0x0FF) << 16) | ((pQ7[1] & 0x0FF) << 8) | (pQ7[0] & 0x0FF); -#endif - return (val); + val = ((pQ7[3] & 0x0FF) << 24) | ((pQ7[2] & 0x0FF) << 16) | ((pQ7[1] & 0x0FF) << 8) | (pQ7[0] & 0x0FF); +#endif + return (val); } /** @@ -181,21 +177,20 @@ __STATIC_FORCEINLINE q31_t read_q7x4 ( @param[in] value Q31 value @return none */ -__STATIC_FORCEINLINE void write_q7x4_ia ( - q7_t ** pQ7, - q31_t value) -{ - q31_t val = value; +__STATIC_FORCEINLINE void write_q7x4_ia( + q7_t **pQ7, + q31_t value) { + q31_t val = value; #ifdef __ARM_FEATURE_UNALIGNED - memcpy (*pQ7, &val, 4); + memcpy(*pQ7, &val, 4); #else - (*pQ7)[0] = (q7_t)(val & 0x0FF); - (*pQ7)[1] = (q7_t)((val >> 8) & 0x0FF); - (*pQ7)[2] = (q7_t)((val >> 16) & 0x0FF); - (*pQ7)[3] = (q7_t)((val >> 24) & 0x0FF); + (*pQ7)[0] = (q7_t)(val & 0x0FF); + (*pQ7)[1] = (q7_t)((val >> 8) & 0x0FF); + (*pQ7)[2] = (q7_t)((val >> 16) & 0x0FF); + (*pQ7)[3] = (q7_t)((val >> 24) & 0x0FF); #endif - *pQ7 += 4; + *pQ7 += 4; } diff --git a/armlib/at32_sys/cmsis/cm4/core_support/arm_math_types.h b/armlib/at32_sys/cmsis/cm4/core_support/arm_math_types.h index c615e667e..c45dadeb8 100644 --- a/armlib/at32_sys/cmsis/cm4/core_support/arm_math_types.h +++ b/armlib/at32_sys/cmsis/cm4/core_support/arm_math_types.h @@ -38,13 +38,13 @@ extern "C" #elif defined ( __ARMCC_VERSION ) && ( __ARMCC_VERSION >= 6010050 ) #elif defined ( __APPLE_CC__ ) - #pragma GCC diagnostic ignored "-Wold-style-cast" +#pragma GCC diagnostic ignored "-Wold-style-cast" #elif defined ( __GNUC__ ) - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wsign-conversion" - #pragma GCC diagnostic ignored "-Wconversion" - #pragma GCC diagnostic ignored "-Wunused-parameter" +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wsign-conversion" +#pragma GCC diagnostic ignored "-Wconversion" +#pragma GCC diagnostic ignored "-Wunused-parameter" #elif defined ( __ICCARM__ ) @@ -57,12 +57,12 @@ extern "C" #elif defined ( _MSC_VER ) #else - #error Unknown compiler +#error Unknown compiler #endif /* Included for instrinsics definitions */ -#if defined (_MSC_VER ) +#if defined (_MSC_VER ) #include #define __STATIC_FORCEINLINE static __forceinline #define __STATIC_INLINE static __inline @@ -70,12 +70,12 @@ extern "C" #elif defined ( __APPLE_CC__ ) #include #define __ALIGNED(x) __attribute__((aligned(x))) -#define __STATIC_FORCEINLINE static inline __attribute__((always_inline)) +#define __STATIC_FORCEINLINE static inline __attribute__((always_inline)) #define __STATIC_INLINE static inline #elif defined (__GNUC_PYTHON__) #include #define __ALIGNED(x) __attribute__((aligned(x))) -#define __STATIC_FORCEINLINE static inline __attribute__((always_inline)) +#define __STATIC_FORCEINLINE static inline __attribute__((always_inline)) #define __STATIC_INLINE static inline #else @@ -91,20 +91,20 @@ extern "C" /* evaluate ARM DSP feature */ #if (defined (__ARM_FEATURE_DSP) && (__ARM_FEATURE_DSP == 1)) - #define ARM_MATH_DSP 1 +#define ARM_MATH_DSP 1 #endif #if defined(ARM_MATH_NEON) - #if defined(_MSC_VER) && defined(_M_ARM64EC) - #include - #else - #include - #endif - #if defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC) && __ARM_FEATURE_FP16_VECTOR_ARITHMETIC - #if !defined(ARM_MATH_NEON_FLOAT16) - #define ARM_MATH_NEON_FLOAT16 - #endif - #endif +#if defined(_MSC_VER) && defined(_M_ARM64EC) +#include +#else +#include +#endif +#if defined(__ARM_FEATURE_FP16_VECTOR_ARITHMETIC) && __ARM_FEATURE_FP16_VECTOR_ARITHMETIC +#if !defined(ARM_MATH_NEON_FLOAT16) +#define ARM_MATH_NEON_FLOAT16 +#endif +#endif #endif #if !defined(ARM_MATH_AUTOVECTORIZE) @@ -112,18 +112,18 @@ extern "C" #if defined(__ARM_FEATURE_MVE) #if __ARM_FEATURE_MVE - #if !defined(ARM_MATH_MVEI) - #define ARM_MATH_MVEI - #endif +#if !defined(ARM_MATH_MVEI) +#define ARM_MATH_MVEI +#endif #endif #if (__ARM_FEATURE_MVE & 2) - #if !defined(ARM_MATH_MVEF) - #define ARM_MATH_MVEF - #endif - #if !defined(ARM_MATH_MVE_FLOAT16) - #define ARM_MATH_MVE_FLOAT16 - #endif +#if !defined(ARM_MATH_MVEF) +#define ARM_MATH_MVEF +#endif +#if !defined(ARM_MATH_MVE_FLOAT16) +#define ARM_MATH_MVE_FLOAT16 +#endif #endif #endif /*defined(__ARM_FEATURE_MVE)*/ @@ -131,110 +131,110 @@ extern "C" #if defined (ARM_MATH_HELIUM) - #if !defined(ARM_MATH_MVEF) - #define ARM_MATH_MVEF - #endif +#if !defined(ARM_MATH_MVEF) +#define ARM_MATH_MVEF +#endif - #if !defined(ARM_MATH_MVEI) - #define ARM_MATH_MVEI - #endif +#if !defined(ARM_MATH_MVEI) +#define ARM_MATH_MVEI +#endif - #if !defined(ARM_MATH_MVE_FLOAT16) - #define ARM_MATH_MVE_FLOAT16 - #endif +#if !defined(ARM_MATH_MVE_FLOAT16) +#define ARM_MATH_MVE_FLOAT16 +#endif #endif #if defined ( __CC_ARM ) - /* Enter low optimization region - place directly above function definition */ - #if defined( __ARM_ARCH_7EM__ ) - #define LOW_OPTIMIZATION_ENTER \ +/* Enter low optimization region - place directly above function definition */ +#if defined( __ARM_ARCH_7EM__ ) +#define LOW_OPTIMIZATION_ENTER \ _Pragma ("push") \ _Pragma ("O1") - #else - #define LOW_OPTIMIZATION_ENTER - #endif +#else +#define LOW_OPTIMIZATION_ENTER +#endif - /* Exit low optimization region - place directly after end of function definition */ - #if defined ( __ARM_ARCH_7EM__ ) - #define LOW_OPTIMIZATION_EXIT \ +/* Exit low optimization region - place directly after end of function definition */ +#if defined ( __ARM_ARCH_7EM__ ) +#define LOW_OPTIMIZATION_EXIT \ _Pragma ("pop") - #else - #define LOW_OPTIMIZATION_EXIT - #endif +#else +#define LOW_OPTIMIZATION_EXIT +#endif - /* Enter low optimization region - place directly above function definition */ - #define IAR_ONLY_LOW_OPTIMIZATION_ENTER +/* Enter low optimization region - place directly above function definition */ +#define IAR_ONLY_LOW_OPTIMIZATION_ENTER - /* Exit low optimization region - place directly after end of function definition */ - #define IAR_ONLY_LOW_OPTIMIZATION_EXIT +/* Exit low optimization region - place directly after end of function definition */ +#define IAR_ONLY_LOW_OPTIMIZATION_EXIT #elif defined (__ARMCC_VERSION ) && ( __ARMCC_VERSION >= 6010050 ) - #define LOW_OPTIMIZATION_ENTER - #define LOW_OPTIMIZATION_EXIT - #define IAR_ONLY_LOW_OPTIMIZATION_ENTER - #define IAR_ONLY_LOW_OPTIMIZATION_EXIT - +#define LOW_OPTIMIZATION_ENTER +#define LOW_OPTIMIZATION_EXIT +#define IAR_ONLY_LOW_OPTIMIZATION_ENTER +#define IAR_ONLY_LOW_OPTIMIZATION_EXIT + #elif defined ( __APPLE_CC__ ) - #define LOW_OPTIMIZATION_ENTER - #define LOW_OPTIMIZATION_EXIT - #define IAR_ONLY_LOW_OPTIMIZATION_ENTER - #define IAR_ONLY_LOW_OPTIMIZATION_EXIT +#define LOW_OPTIMIZATION_ENTER +#define LOW_OPTIMIZATION_EXIT +#define IAR_ONLY_LOW_OPTIMIZATION_ENTER +#define IAR_ONLY_LOW_OPTIMIZATION_EXIT #elif defined ( __GNUC__ ) - #define LOW_OPTIMIZATION_ENTER \ +#define LOW_OPTIMIZATION_ENTER \ __attribute__(( optimize("-O1") )) - #define LOW_OPTIMIZATION_EXIT - #define IAR_ONLY_LOW_OPTIMIZATION_ENTER - #define IAR_ONLY_LOW_OPTIMIZATION_EXIT +#define LOW_OPTIMIZATION_EXIT +#define IAR_ONLY_LOW_OPTIMIZATION_ENTER +#define IAR_ONLY_LOW_OPTIMIZATION_EXIT #elif defined ( __ICCARM__ ) - /* Enter low optimization region - place directly above function definition */ - #if defined ( __ARM_ARCH_7EM__ ) - #define LOW_OPTIMIZATION_ENTER \ +/* Enter low optimization region - place directly above function definition */ +#if defined ( __ARM_ARCH_7EM__ ) +#define LOW_OPTIMIZATION_ENTER \ _Pragma ("optimize=low") - #else - #define LOW_OPTIMIZATION_ENTER - #endif +#else +#define LOW_OPTIMIZATION_ENTER +#endif - /* Exit low optimization region - place directly after end of function definition */ - #define LOW_OPTIMIZATION_EXIT +/* Exit low optimization region - place directly after end of function definition */ +#define LOW_OPTIMIZATION_EXIT - /* Enter low optimization region - place directly above function definition */ - #if defined ( __ARM_ARCH_7EM__ ) - #define IAR_ONLY_LOW_OPTIMIZATION_ENTER \ +/* Enter low optimization region - place directly above function definition */ +#if defined ( __ARM_ARCH_7EM__ ) +#define IAR_ONLY_LOW_OPTIMIZATION_ENTER \ _Pragma ("optimize=low") - #else - #define IAR_ONLY_LOW_OPTIMIZATION_ENTER - #endif +#else +#define IAR_ONLY_LOW_OPTIMIZATION_ENTER +#endif - /* Exit low optimization region - place directly after end of function definition */ - #define IAR_ONLY_LOW_OPTIMIZATION_EXIT +/* Exit low optimization region - place directly after end of function definition */ +#define IAR_ONLY_LOW_OPTIMIZATION_EXIT #elif defined ( __TI_ARM__ ) - #define LOW_OPTIMIZATION_ENTER - #define LOW_OPTIMIZATION_EXIT - #define IAR_ONLY_LOW_OPTIMIZATION_ENTER - #define IAR_ONLY_LOW_OPTIMIZATION_EXIT +#define LOW_OPTIMIZATION_ENTER +#define LOW_OPTIMIZATION_EXIT +#define IAR_ONLY_LOW_OPTIMIZATION_ENTER +#define IAR_ONLY_LOW_OPTIMIZATION_EXIT #elif defined ( __CSMC__ ) - #define LOW_OPTIMIZATION_ENTER - #define LOW_OPTIMIZATION_EXIT - #define IAR_ONLY_LOW_OPTIMIZATION_ENTER - #define IAR_ONLY_LOW_OPTIMIZATION_EXIT +#define LOW_OPTIMIZATION_ENTER +#define LOW_OPTIMIZATION_EXIT +#define IAR_ONLY_LOW_OPTIMIZATION_ENTER +#define IAR_ONLY_LOW_OPTIMIZATION_EXIT #elif defined ( __TASKING__ ) - #define LOW_OPTIMIZATION_ENTER - #define LOW_OPTIMIZATION_EXIT - #define IAR_ONLY_LOW_OPTIMIZATION_ENTER - #define IAR_ONLY_LOW_OPTIMIZATION_EXIT - +#define LOW_OPTIMIZATION_ENTER +#define LOW_OPTIMIZATION_EXIT +#define IAR_ONLY_LOW_OPTIMIZATION_ENTER +#define IAR_ONLY_LOW_OPTIMIZATION_EXIT + #elif defined ( _MSC_VER ) || defined(__GNUC_PYTHON__) - #define LOW_OPTIMIZATION_ENTER - #define LOW_OPTIMIZATION_EXIT - #define IAR_ONLY_LOW_OPTIMIZATION_ENTER - #define IAR_ONLY_LOW_OPTIMIZATION_EXIT +#define LOW_OPTIMIZATION_ENTER +#define LOW_OPTIMIZATION_EXIT +#define IAR_ONLY_LOW_OPTIMIZATION_ENTER +#define IAR_ONLY_LOW_OPTIMIZATION_EXIT #endif @@ -260,7 +260,7 @@ extern "C" #elif defined ( _MSC_VER ) #else - #error Unknown compiler +#error Unknown compiler #endif #ifdef __cplusplus @@ -276,279 +276,277 @@ extern "C" { #endif - /** - * @brief 8-bit fractional data type in 1.7 format. - */ - typedef int8_t q7_t; +/** + * @brief 8-bit fractional data type in 1.7 format. + */ +typedef int8_t q7_t; - /** - * @brief 16-bit fractional data type in 1.15 format. - */ - typedef int16_t q15_t; +/** + * @brief 16-bit fractional data type in 1.15 format. + */ +typedef int16_t q15_t; - /** - * @brief 32-bit fractional data type in 1.31 format. - */ - typedef int32_t q31_t; +/** + * @brief 32-bit fractional data type in 1.31 format. + */ +typedef int32_t q31_t; - /** - * @brief 64-bit fractional data type in 1.63 format. - */ - typedef int64_t q63_t; +/** + * @brief 64-bit fractional data type in 1.63 format. + */ +typedef int64_t q63_t; - /** - * @brief 32-bit floating-point type definition. - */ +/** + * @brief 32-bit floating-point type definition. + */ #if !defined(__ICCARM__) || !(__ARM_FEATURE_MVE & 2) - typedef float float32_t; +typedef float float32_t; #endif - /** - * @brief 64-bit floating-point type definition. - */ - typedef double float64_t; +/** + * @brief 64-bit floating-point type definition. + */ +typedef double float64_t; - /** - * @brief vector types - */ +/** + * @brief vector types + */ #if defined(ARM_MATH_NEON) || (defined (ARM_MATH_MVEI) && !defined(ARM_MATH_AUTOVECTORIZE)) - /** - * @brief 64-bit fractional 128-bit vector data type in 1.63 format - */ - typedef int64x2_t q63x2_t; +/** + * @brief 64-bit fractional 128-bit vector data type in 1.63 format + */ +typedef int64x2_t q63x2_t; - /** - * @brief 32-bit fractional 128-bit vector data type in 1.31 format. - */ - typedef int32x4_t q31x4_t; +/** + * @brief 32-bit fractional 128-bit vector data type in 1.31 format. + */ +typedef int32x4_t q31x4_t; - /** - * @brief 16-bit fractional 128-bit vector data type with 16-bit alignment in 1.15 format. - */ - typedef __ALIGNED(2) int16x8_t q15x8_t; +/** + * @brief 16-bit fractional 128-bit vector data type with 16-bit alignment in 1.15 format. + */ +typedef __ALIGNED(2) int16x8_t q15x8_t; - /** - * @brief 8-bit fractional 128-bit vector data type with 8-bit alignment in 1.7 format. - */ - typedef __ALIGNED(1) int8x16_t q7x16_t; +/** + * @brief 8-bit fractional 128-bit vector data type with 8-bit alignment in 1.7 format. + */ +typedef __ALIGNED(1) int8x16_t q7x16_t; - /** - * @brief 32-bit fractional 128-bit vector pair data type in 1.31 format. - */ - typedef int32x4x2_t q31x4x2_t; +/** +* @brief 32-bit fractional 128-bit vector pair data type in 1.31 format. +*/ +typedef int32x4x2_t q31x4x2_t; - /** - * @brief 32-bit fractional 128-bit vector quadruplet data type in 1.31 format. - */ - typedef int32x4x4_t q31x4x4_t; +/** + * @brief 32-bit fractional 128-bit vector quadruplet data type in 1.31 format. + */ +typedef int32x4x4_t q31x4x4_t; - /** - * @brief 16-bit fractional 128-bit vector pair data type in 1.15 format. - */ - typedef int16x8x2_t q15x8x2_t; +/** + * @brief 16-bit fractional 128-bit vector pair data type in 1.15 format. + */ +typedef int16x8x2_t q15x8x2_t; - /** - * @brief 16-bit fractional 128-bit vector quadruplet data type in 1.15 format. - */ - typedef int16x8x4_t q15x8x4_t; +/** + * @brief 16-bit fractional 128-bit vector quadruplet data type in 1.15 format. + */ +typedef int16x8x4_t q15x8x4_t; - /** - * @brief 8-bit fractional 128-bit vector pair data type in 1.7 format. - */ - typedef int8x16x2_t q7x16x2_t; +/** + * @brief 8-bit fractional 128-bit vector pair data type in 1.7 format. + */ +typedef int8x16x2_t q7x16x2_t; - /** - * @brief 8-bit fractional 128-bit vector quadruplet data type in 1.7 format. - */ - typedef int8x16x4_t q7x16x4_t; +/** + * @brief 8-bit fractional 128-bit vector quadruplet data type in 1.7 format. + */ +typedef int8x16x4_t q7x16x4_t; - /** - * @brief 32-bit fractional data type in 9.23 format. - */ - typedef int32_t q23_t; +/** + * @brief 32-bit fractional data type in 9.23 format. + */ +typedef int32_t q23_t; - /** - * @brief 32-bit fractional 128-bit vector data type in 9.23 format. - */ - typedef int32x4_t q23x4_t; +/** + * @brief 32-bit fractional 128-bit vector data type in 9.23 format. + */ +typedef int32x4_t q23x4_t; - /** - * @brief 64-bit status 128-bit vector data type. - */ - typedef int64x2_t status64x2_t; +/** + * @brief 64-bit status 128-bit vector data type. + */ +typedef int64x2_t status64x2_t; - /** - * @brief 32-bit status 128-bit vector data type. - */ - typedef int32x4_t status32x4_t; +/** + * @brief 32-bit status 128-bit vector data type. + */ +typedef int32x4_t status32x4_t; - /** - * @brief 16-bit status 128-bit vector data type. - */ - typedef int16x8_t status16x8_t; +/** + * @brief 16-bit status 128-bit vector data type. + */ +typedef int16x8_t status16x8_t; - /** - * @brief 8-bit status 128-bit vector data type. - */ - typedef int8x16_t status8x16_t; +/** + * @brief 8-bit status 128-bit vector data type. + */ +typedef int8x16_t status8x16_t; #endif #if defined(ARM_MATH_NEON) || (defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE)) /* floating point vector*/ - /** - * @brief 32-bit floating-point 128-bit vector type - */ - typedef float32x4_t f32x4_t; +/** + * @brief 32-bit floating-point 128-bit vector type + */ +typedef float32x4_t f32x4_t; - /** - * @brief 32-bit floating-point 128-bit vector pair data type - */ - typedef float32x4x2_t f32x4x2_t; +/** + * @brief 32-bit floating-point 128-bit vector pair data type + */ +typedef float32x4x2_t f32x4x2_t; - /** - * @brief 32-bit floating-point 128-bit vector quadruplet data type - */ - typedef float32x4x4_t f32x4x4_t; +/** + * @brief 32-bit floating-point 128-bit vector quadruplet data type + */ +typedef float32x4x4_t f32x4x4_t; - /** - * @brief 32-bit ubiquitous 128-bit vector data type - */ - typedef union _any32x4_t - { - float32x4_t f; - int32x4_t i; - } any32x4_t; +/** + * @brief 32-bit ubiquitous 128-bit vector data type + */ +typedef union _any32x4_t { + float32x4_t f; + int32x4_t i; +} any32x4_t; #endif #if defined(ARM_MATH_NEON) - /** - * @brief 32-bit fractional 64-bit vector data type in 1.31 format. - */ - typedef int32x2_t q31x2_t; +/** + * @brief 32-bit fractional 64-bit vector data type in 1.31 format. + */ +typedef int32x2_t q31x2_t; - /** - * @brief 16-bit fractional 64-bit vector data type in 1.15 format. - */ - typedef __ALIGNED(2) int16x4_t q15x4_t; +/** + * @brief 16-bit fractional 64-bit vector data type in 1.15 format. + */ +typedef __ALIGNED(2) int16x4_t q15x4_t; - /** - * @brief 8-bit fractional 64-bit vector data type in 1.7 format. - */ - typedef __ALIGNED(1) int8x8_t q7x8_t; +/** + * @brief 8-bit fractional 64-bit vector data type in 1.7 format. + */ +typedef __ALIGNED(1) int8x8_t q7x8_t; - /** - * @brief 32-bit float 64-bit vector data type. - */ - typedef float32x2_t f32x2_t; +/** + * @brief 32-bit float 64-bit vector data type. + */ +typedef float32x2_t f32x2_t; - /** - * @brief 32-bit floating-point 128-bit vector triplet data type - */ - typedef float32x4x3_t f32x4x3_t; +/** + * @brief 32-bit floating-point 128-bit vector triplet data type + */ +typedef float32x4x3_t f32x4x3_t; - /** - * @brief 32-bit fractional 128-bit vector triplet data type in 1.31 format - */ - typedef int32x4x3_t q31x4x3_t; +/** + * @brief 32-bit fractional 128-bit vector triplet data type in 1.31 format + */ +typedef int32x4x3_t q31x4x3_t; - /** - * @brief 16-bit fractional 128-bit vector triplet data type in 1.15 format - */ - typedef int16x8x3_t q15x8x3_t; +/** + * @brief 16-bit fractional 128-bit vector triplet data type in 1.15 format + */ +typedef int16x8x3_t q15x8x3_t; - /** - * @brief 8-bit fractional 128-bit vector triplet data type in 1.7 format - */ - typedef int8x16x3_t q7x16x3_t; +/** + * @brief 8-bit fractional 128-bit vector triplet data type in 1.7 format + */ +typedef int8x16x3_t q7x16x3_t; - /** - * @brief 32-bit floating-point 64-bit vector pair data type - */ - typedef float32x2x2_t f32x2x2_t; +/** + * @brief 32-bit floating-point 64-bit vector pair data type + */ +typedef float32x2x2_t f32x2x2_t; - /** - * @brief 32-bit floating-point 64-bit vector triplet data type - */ - typedef float32x2x3_t f32x2x3_t; +/** + * @brief 32-bit floating-point 64-bit vector triplet data type + */ +typedef float32x2x3_t f32x2x3_t; - /** - * @brief 32-bit floating-point 64-bit vector quadruplet data type - */ - typedef float32x2x4_t f32x2x4_t; +/** + * @brief 32-bit floating-point 64-bit vector quadruplet data type + */ +typedef float32x2x4_t f32x2x4_t; - /** - * @brief 32-bit fractional 64-bit vector pair data type in 1.31 format - */ - typedef int32x2x2_t q31x2x2_t; +/** + * @brief 32-bit fractional 64-bit vector pair data type in 1.31 format + */ +typedef int32x2x2_t q31x2x2_t; - /** - * @brief 32-bit fractional 64-bit vector triplet data type in 1.31 format - */ - typedef int32x2x3_t q31x2x3_t; +/** + * @brief 32-bit fractional 64-bit vector triplet data type in 1.31 format + */ +typedef int32x2x3_t q31x2x3_t; - /** - * @brief 32-bit fractional 64-bit vector quadruplet data type in 1.31 format - */ - typedef int32x4x3_t q31x2x4_t; +/** + * @brief 32-bit fractional 64-bit vector quadruplet data type in 1.31 format + */ +typedef int32x4x3_t q31x2x4_t; - /** - * @brief 16-bit fractional 64-bit vector pair data type in 1.15 format - */ - typedef int16x4x2_t q15x4x2_t; +/** + * @brief 16-bit fractional 64-bit vector pair data type in 1.15 format + */ +typedef int16x4x2_t q15x4x2_t; - /** - * @brief 16-bit fractional 64-bit vector triplet data type in 1.15 format - */ - typedef int16x4x2_t q15x4x3_t; +/** + * @brief 16-bit fractional 64-bit vector triplet data type in 1.15 format + */ +typedef int16x4x2_t q15x4x3_t; - /** - * @brief 16-bit fractional 64-bit vector quadruplet data type in 1.15 format - */ - typedef int16x4x3_t q15x4x4_t; +/** + * @brief 16-bit fractional 64-bit vector quadruplet data type in 1.15 format + */ +typedef int16x4x3_t q15x4x4_t; - /** - * @brief 8-bit fractional 64-bit vector pair data type in 1.7 format - */ - typedef int8x8x2_t q7x8x2_t; +/** + * @brief 8-bit fractional 64-bit vector pair data type in 1.7 format + */ +typedef int8x8x2_t q7x8x2_t; - /** - * @brief 8-bit fractional 64-bit vector triplet data type in 1.7 format - */ - typedef int8x8x3_t q7x8x3_t; +/** + * @brief 8-bit fractional 64-bit vector triplet data type in 1.7 format + */ +typedef int8x8x3_t q7x8x3_t; - /** - * @brief 8-bit fractional 64-bit vector quadruplet data type in 1.7 format - */ - typedef int8x8x4_t q7x8x4_t; +/** + * @brief 8-bit fractional 64-bit vector quadruplet data type in 1.7 format + */ +typedef int8x8x4_t q7x8x4_t; - /** - * @brief 32-bit ubiquitous 64-bit vector data type - */ - typedef union _any32x2_t - { - float32x2_t f; - int32x2_t i; - } any32x2_t; +/** + * @brief 32-bit ubiquitous 64-bit vector data type + */ +typedef union _any32x2_t { + float32x2_t f; + int32x2_t i; +} any32x2_t; - /** - * @brief 32-bit status 64-bit vector data type. - */ - typedef int32x4_t status32x2_t; +/** + * @brief 32-bit status 64-bit vector data type. + */ +typedef int32x4_t status32x2_t; - /** - * @brief 16-bit status 64-bit vector data type. - */ - typedef int16x8_t status16x4_t; +/** + * @brief 16-bit status 64-bit vector data type. + */ +typedef int16x8_t status16x4_t; - /** - * @brief 8-bit status 64-bit vector data type. - */ - typedef int8x16_t status8x8_t; +/** + * @brief 8-bit status 64-bit vector data type. + */ +typedef int8x16_t status8x8_t; #endif @@ -589,15 +587,14 @@ extern "C" #define Q15_ABSMIN ((q15_t)0) #define Q7_ABSMIN ((q7_t)0) - /* Dimension C vector space */ - #define CMPLX_DIM 2 +/* Dimension C vector space */ +#define CMPLX_DIM 2 - /** - * @brief Error status returned by some functions in the library. - */ +/** + * @brief Error status returned by some functions in the library. + */ - typedef enum - { +typedef enum { ARM_MATH_SUCCESS = 0, /**< No error */ ARM_MATH_ARGUMENT_ERROR = -1, /**< One or more arguments are incorrect */ ARM_MATH_LENGTH_ERROR = -2, /**< Length of data buffer is incorrect */ @@ -606,7 +603,7 @@ extern "C" ARM_MATH_SINGULAR = -5, /**< Input matrix is singular and cannot be inverted */ ARM_MATH_TEST_FAILURE = -6, /**< Test Failed */ ARM_MATH_DECOMPOSITION_FAILURE = -7 /**< Decomposition Failed */ - } arm_status; +} arm_status; #ifdef __cplusplus diff --git a/armlib/at32_sys/cmsis/cm4/core_support/arm_math_types_f16.h b/armlib/at32_sys/cmsis/cm4/core_support/arm_math_types_f16.h index 744dc38f1..cc92e3a76 100644 --- a/armlib/at32_sys/cmsis/cm4/core_support/arm_math_types_f16.h +++ b/armlib/at32_sys/cmsis/cm4/core_support/arm_math_types_f16.h @@ -50,44 +50,43 @@ won't be built. */ #if !(__ARM_FEATURE_MVE & 2) - #if !defined(DISABLEFLOAT16) - #if defined(__ARM_FP16_FORMAT_IEEE) || defined(__ARM_FP16_FORMAT_ALTERNATIVE) - typedef __fp16 float16_t; - #define ARM_FLOAT16_SUPPORTED - #endif - #endif +#if !defined(DISABLEFLOAT16) +#if defined(__ARM_FP16_FORMAT_IEEE) || defined(__ARM_FP16_FORMAT_ALTERNATIVE) +typedef __fp16 float16_t; +#define ARM_FLOAT16_SUPPORTED +#endif +#endif #else - /* When Vector float16, this flag is always defined and can't be disabled */ - #define ARM_FLOAT16_SUPPORTED +/* When Vector float16, this flag is always defined and can't be disabled */ +#define ARM_FLOAT16_SUPPORTED #endif #if defined(ARM_MATH_NEON) || (defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE)) /* floating point vector*/ #if defined(ARM_MATH_MVE_FLOAT16) || defined(ARM_MATH_NEON_FLOAT16) - /** - * @brief 16-bit floating-point 128-bit vector data type - */ - typedef __ALIGNED(2) float16x8_t f16x8_t; +/** + * @brief 16-bit floating-point 128-bit vector data type + */ +typedef __ALIGNED(2) float16x8_t f16x8_t; - /** - * @brief 16-bit floating-point 128-bit vector pair data type - */ - typedef float16x8x2_t f16x8x2_t; +/** + * @brief 16-bit floating-point 128-bit vector pair data type + */ +typedef float16x8x2_t f16x8x2_t; - /** - * @brief 16-bit floating-point 128-bit vector quadruplet data type - */ - typedef float16x8x4_t f16x8x4_t; +/** + * @brief 16-bit floating-point 128-bit vector quadruplet data type + */ +typedef float16x8x4_t f16x8x4_t; - /** - * @brief 16-bit ubiquitous 128-bit vector data type - */ - typedef union _any16x8_t - { - float16x8_t f; - int16x8_t i; - } any16x8_t; +/** + * @brief 16-bit ubiquitous 128-bit vector data type + */ +typedef union _any16x8_t { + float16x8_t f; + int16x8_t i; +} any16x8_t; #endif #endif @@ -96,39 +95,38 @@ won't be built. #if defined(ARM_MATH_NEON_FLOAT16) - /** - * @brief 16-bit float 64-bit vector data type. - */ - typedef __ALIGNED(2) float16x4_t f16x4_t; +/** + * @brief 16-bit float 64-bit vector data type. + */ +typedef __ALIGNED(2) float16x4_t f16x4_t; - /** - * @brief 16-bit floating-point 128-bit vector triplet data type - */ - typedef float16x8x3_t f16x8x3_t; +/** + * @brief 16-bit floating-point 128-bit vector triplet data type + */ +typedef float16x8x3_t f16x8x3_t; - /** - * @brief 16-bit floating-point 64-bit vector pair data type - */ - typedef float16x4x2_t f16x4x2_t; +/** + * @brief 16-bit floating-point 64-bit vector pair data type + */ +typedef float16x4x2_t f16x4x2_t; - /** - * @brief 16-bit floating-point 64-bit vector triplet data type - */ - typedef float16x4x3_t f16x4x3_t; +/** + * @brief 16-bit floating-point 64-bit vector triplet data type + */ +typedef float16x4x3_t f16x4x3_t; - /** - * @brief 16-bit floating-point 64-bit vector quadruplet data type - */ - typedef float16x4x4_t f16x4x4_t; +/** + * @brief 16-bit floating-point 64-bit vector quadruplet data type + */ +typedef float16x4x4_t f16x4x4_t; - /** - * @brief 16-bit ubiquitous 64-bit vector data type - */ - typedef union _any16x4_t - { - float16x4_t f; - int16x4_t i; - } any16x4_t; +/** + * @brief 16-bit ubiquitous 64-bit vector data type + */ +typedef union _any16x4_t { + float16x4_t f; + int16x4_t i; +} any16x4_t; #endif #endif diff --git a/armlib/at32_sys/cmsis/cm4/core_support/arm_mve_tables.h b/armlib/at32_sys/cmsis/cm4/core_support/arm_mve_tables.h index c4f8bf082..03bc47c4d 100644 --- a/armlib/at32_sys/cmsis/cm4/core_support/arm_mve_tables.h +++ b/armlib/at32_sys/cmsis/cm4/core_support/arm_mve_tables.h @@ -27,8 +27,8 @@ * limitations under the License. */ - #ifndef _ARM_MVE_TABLES_H - #define _ARM_MVE_TABLES_H +#ifndef _ARM_MVE_TABLES_H +#define _ARM_MVE_TABLES_H #include "arm_math_types.h" @@ -38,7 +38,7 @@ extern "C" #endif - + #if defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) diff --git a/armlib/at32_sys/cmsis/cm4/core_support/arm_mve_tables_f16.h b/armlib/at32_sys/cmsis/cm4/core_support/arm_mve_tables_f16.h index dc9520309..256cc1bef 100644 --- a/armlib/at32_sys/cmsis/cm4/core_support/arm_mve_tables_f16.h +++ b/armlib/at32_sys/cmsis/cm4/core_support/arm_mve_tables_f16.h @@ -27,8 +27,8 @@ * limitations under the License. */ - #ifndef _ARM_MVE_TABLES_F16_H - #define _ARM_MVE_TABLES_F16_H +#ifndef _ARM_MVE_TABLES_F16_H +#define _ARM_MVE_TABLES_F16_H #include "arm_math_types_f16.h" @@ -38,7 +38,7 @@ extern "C" #endif - + #if defined(ARM_MATH_MVE_FLOAT16) && !defined(ARM_MATH_AUTOVECTORIZE) diff --git a/armlib/at32_sys/cmsis/cm4/core_support/arm_vec_math.h b/armlib/at32_sys/cmsis/cm4/core_support/arm_vec_math.h index d9134c541..e8b1e2867 100644 --- a/armlib/at32_sys/cmsis/cm4/core_support/arm_vec_math.h +++ b/armlib/at32_sys/cmsis/cm4/core_support/arm_vec_math.h @@ -39,13 +39,12 @@ extern "C" #define INV_NEWTON_INIT_F32 0x7EF127EA -static const float32_t __logf_rng_f32=0.693147180f; +static const float32_t __logf_rng_f32 = 0.693147180f; /* fast inverse approximation (3x newton) */ __STATIC_INLINE f32x4_t vrecip_medprec_f32( - f32x4_t x) -{ + f32x4_t x) { q31x4_t m; f32x4_t b; any32x4_t xinv; @@ -77,8 +76,7 @@ __STATIC_INLINE f32x4_t vrecip_medprec_f32( /* fast inverse approximation (4x newton) */ __STATIC_INLINE f32x4_t vrecip_hiprec_f32( - f32x4_t x) -{ + f32x4_t x) { q31x4_t m; f32x4_t b; any32x4_t xinv; @@ -113,8 +111,7 @@ __STATIC_INLINE f32x4_t vrecip_hiprec_f32( } __STATIC_INLINE f32x4_t vdiv_f32( - f32x4_t num, f32x4_t den) -{ + f32x4_t num, f32x4_t den) { return vmulq(num, vrecip_hiprec_f32(den)); } @@ -126,9 +123,8 @@ __STATIC_INLINE f32x4_t vdiv_f32( */ __STATIC_INLINE f32x4_t vtaylor_polyq_f32( - f32x4_t x, - const float32_t * coeffs) -{ + f32x4_t x, + const float32_t *coeffs) { f32x4_t A = vfmasq(vdupq_n_f32(coeffs[4]), x, coeffs[0]); f32x4_t B = vfmasq(vdupq_n_f32(coeffs[6]), x, coeffs[2]); f32x4_t C = vfmasq(vdupq_n_f32(coeffs[5]), x, coeffs[1]); @@ -142,8 +138,7 @@ __STATIC_INLINE f32x4_t vtaylor_polyq_f32( __STATIC_INLINE f32x4_t vmant_exp_f32( f32x4_t x, - int32x4_t * e) -{ + int32x4_t *e) { any32x4_t r; int32x4_t n; @@ -157,8 +152,7 @@ __STATIC_INLINE f32x4_t vmant_exp_f32( } -__STATIC_INLINE f32x4_t vlogq_f32(f32x4_t vecIn) -{ +__STATIC_INLINE f32x4_t vlogq_f32(f32x4_t vecIn) { q31x4_t vecExpUnBiased; f32x4_t vecTmpFlt0, vecTmpFlt1; f32x4_t vecAcc0, vecAcc1, vecAcc2, vecAcc3; @@ -218,8 +212,7 @@ __STATIC_INLINE f32x4_t vlogq_f32(f32x4_t vecIn) } __STATIC_INLINE f32x4_t vexpq_f32( - f32x4_t x) -{ + f32x4_t x) { // Perform range reduction [-log(2),log(2)] int32x4_t m = vcvtq_s32_f32(vmulq_n_f32(x, 1.4426950408f)); f32x4_t val = vfmsq_f32(x, vcvtq_f32_s32(m), vdupq_n_f32(0.6931471805f)); @@ -228,14 +221,13 @@ __STATIC_INLINE f32x4_t vexpq_f32( f32x4_t poly = vtaylor_polyq_f32(val, exp_tab); // Reconstruct - poly = (f32x4_t) (vqaddq_s32((q31x4_t) (poly), vqshlq_n_s32(m, 23))); + poly = (f32x4_t)(vqaddq_s32((q31x4_t)(poly), vqshlq_n_s32(m, 23))); poly = vdupq_m(poly, 0.0f, vcmpltq_n_s32(m, -126)); return poly; } -__STATIC_INLINE f32x4_t arm_vec_exponent_f32(f32x4_t x, int32_t nb) -{ +__STATIC_INLINE f32x4_t arm_vec_exponent_f32(f32x4_t x, int32_t nb) { f32x4_t r = x; nb--; while (nb > 0) { @@ -245,8 +237,7 @@ __STATIC_INLINE f32x4_t arm_vec_exponent_f32(f32x4_t x, int32_t nb) return (r); } -__STATIC_INLINE f32x4_t vrecip_f32(f32x4_t vecIn) -{ +__STATIC_INLINE f32x4_t vrecip_f32(f32x4_t vecIn) { f32x4_t vecSx, vecW, vecTmp; any32x4_t v; @@ -276,8 +267,7 @@ __STATIC_INLINE f32x4_t vrecip_f32(f32x4_t vecIn) } __STATIC_INLINE f32x4_t vtanhq_f32( - f32x4_t val) -{ + f32x4_t val) { f32x4_t x = vminnmq_f32(vmaxnmq_f32(val, vdupq_n_f32(-10.f)), vdupq_n_f32(10.0f)); f32x4_t exp2x = vexpq_f32(vmulq_n_f32(x, 2.f)); @@ -289,8 +279,7 @@ __STATIC_INLINE f32x4_t vtanhq_f32( __STATIC_INLINE f32x4_t vpowq_f32( f32x4_t val, - f32x4_t n) -{ + f32x4_t n) { return vexpq_f32(vmulq_f32(n, vlogq_f32(val))); } @@ -309,21 +298,18 @@ __STATIC_INLINE f32x4_t vpowq_f32( * @return x^nb * */ -__STATIC_INLINE float32x4_t arm_vec_exponent_f32(float32x4_t x, int32_t nb) -{ +__STATIC_INLINE float32x4_t arm_vec_exponent_f32(float32x4_t x, int32_t nb) { float32x4_t r = x; nb --; - while(nb > 0) - { - r = vmulq_f32(r , x); + while (nb > 0) { + r = vmulq_f32(r, x); nb--; } - return(r); + return (r); } -__STATIC_INLINE float32x4_t __arm_vec_sqrt_f32_neon(float32x4_t x) -{ +__STATIC_INLINE float32x4_t __arm_vec_sqrt_f32_neon(float32x4_t x) { float32x4_t x1 = vmaxq_f32(x, vdupq_n_f32(FLT_MIN)); float32x4_t e = vrsqrteq_f32(x1); e = vmulq_f32(vrsqrtsq_f32(vmulq_f32(x1, e), e), e); @@ -331,31 +317,29 @@ __STATIC_INLINE float32x4_t __arm_vec_sqrt_f32_neon(float32x4_t x) return vmulq_f32(x, e); } -__STATIC_INLINE int16x8_t __arm_vec_sqrt_q15_neon(int16x8_t vec) -{ +__STATIC_INLINE int16x8_t __arm_vec_sqrt_q15_neon(int16x8_t vec) { float32x4_t tempF; - int32x4_t tempHI,tempLO; + int32x4_t tempHI, tempLO; tempLO = vmovl_s16(vget_low_s16(vec)); - tempF = vcvtq_n_f32_s32(tempLO,15); + tempF = vcvtq_n_f32_s32(tempLO, 15); tempF = __arm_vec_sqrt_f32_neon(tempF); - tempLO = vcvtq_n_s32_f32(tempF,15); + tempLO = vcvtq_n_s32_f32(tempF, 15); tempHI = vmovl_s16(vget_high_s16(vec)); - tempF = vcvtq_n_f32_s32(tempHI,15); + tempF = vcvtq_n_f32_s32(tempHI, 15); tempF = __arm_vec_sqrt_f32_neon(tempF); - tempHI = vcvtq_n_s32_f32(tempF,15); + tempHI = vcvtq_n_s32_f32(tempF, 15); - return(vcombine_s16(vqmovn_s32(tempLO),vqmovn_s32(tempHI))); + return (vcombine_s16(vqmovn_s32(tempLO), vqmovn_s32(tempHI))); } -__STATIC_INLINE int32x4_t __arm_vec_sqrt_q31_neon(int32x4_t vec) -{ - float32x4_t temp; +__STATIC_INLINE int32x4_t __arm_vec_sqrt_q31_neon(int32x4_t vec) { + float32x4_t temp; - temp = vcvtq_n_f32_s32(vec,31); - temp = __arm_vec_sqrt_f32_neon(temp); - return(vcvtq_n_s32_f32(temp,31)); + temp = vcvtq_n_f32_s32(vec, 31); + temp = __arm_vec_sqrt_f32_neon(temp); + return (vcvtq_n_s32_f32(temp, 31)); } #endif /* (defined(ARM_MATH_NEON) || defined(ARM_MATH_NEON_EXPERIMENTAL)) && !defined(ARM_MATH_AUTOVECTORIZE) */ diff --git a/armlib/at32_sys/cmsis/cm4/core_support/arm_vec_math_f16.h b/armlib/at32_sys/cmsis/cm4/core_support/arm_vec_math_f16.h index 91bd28aaf..69375600d 100644 --- a/armlib/at32_sys/cmsis/cm4/core_support/arm_vec_math_f16.h +++ b/armlib/at32_sys/cmsis/cm4/core_support/arm_vec_math_f16.h @@ -41,12 +41,11 @@ extern "C" #if defined(ARM_MATH_MVE_FLOAT16) && !defined(ARM_MATH_AUTOVECTORIZE) -static const float16_t __logf_rng_f16=0.693147180f16; +static const float16_t __logf_rng_f16 = 0.693147180f16; /* fast inverse approximation (3x newton) */ __STATIC_INLINE f16x8_t vrecip_medprec_f16( - f16x8_t x) -{ + f16x8_t x) { q15x8_t m; f16x8_t b; any16x8_t xinv; @@ -79,8 +78,7 @@ __STATIC_INLINE f16x8_t vrecip_medprec_f16( /* fast inverse approximation (4x newton) */ __STATIC_INLINE f16x8_t vrecip_hiprec_f16( - f16x8_t x) -{ + f16x8_t x) { q15x8_t m; f16x8_t b; any16x8_t xinv; @@ -115,8 +113,7 @@ __STATIC_INLINE f16x8_t vrecip_hiprec_f16( } __STATIC_INLINE f16x8_t vdiv_f16( - f16x8_t num, f16x8_t den) -{ + f16x8_t num, f16x8_t den) { return vmulq(num, vrecip_hiprec_f16(den)); } @@ -129,9 +126,8 @@ __STATIC_INLINE f16x8_t vdiv_f16( */ __STATIC_INLINE float16x8_t vtaylor_polyq_f16( - float16x8_t x, - const float16_t * coeffs) -{ + float16x8_t x, + const float16_t *coeffs) { float16x8_t A = vfmasq(vdupq_n_f16(coeffs[4]), x, coeffs[0]); float16x8_t B = vfmasq(vdupq_n_f16(coeffs[6]), x, coeffs[2]); float16x8_t C = vfmasq(vdupq_n_f16(coeffs[5]), x, coeffs[1]); @@ -155,8 +151,7 @@ __STATIC_INLINE float16x8_t vtaylor_polyq_f16( vecExpUnBiased = n; \ vecTmpFlt1 = r.f; -__STATIC_INLINE float16x8_t vlogq_f16(float16x8_t vecIn) -{ +__STATIC_INLINE float16x8_t vlogq_f16(float16x8_t vecIn) { q15x8_t vecExpUnBiased; float16x8_t vecTmpFlt0, vecTmpFlt1; float16x8_t vecAcc0, vecAcc1, vecAcc2, vecAcc3; @@ -216,8 +211,7 @@ __STATIC_INLINE float16x8_t vlogq_f16(float16x8_t vecIn) } __STATIC_INLINE float16x8_t vexpq_f16( - float16x8_t x) -{ + float16x8_t x) { // Perform range reduction [-log(2),log(2)] int16x8_t m = vcvtq_s16_f16(vmulq_n_f16(x, 1.4426950408f16)); float16x8_t val = vfmsq_f16(x, vcvtq_f16_s16(m), vdupq_n_f16(0.6931471805f16)); @@ -226,14 +220,13 @@ __STATIC_INLINE float16x8_t vexpq_f16( float16x8_t poly = vtaylor_polyq_f16(val, exp_tab_f16); // Reconstruct - poly = (float16x8_t) (vqaddq_s16((int16x8_t) (poly), vqshlq_n_s16(m, 10))); + poly = (float16x8_t)(vqaddq_s16((int16x8_t)(poly), vqshlq_n_s16(m, 10))); poly = vdupq_m_n_f16(poly, 0.0f16, vcmpltq_n_s16(m, -14)); return poly; } -__STATIC_INLINE float16x8_t arm_vec_exponent_f16(float16x8_t x, int16_t nb) -{ +__STATIC_INLINE float16x8_t arm_vec_exponent_f16(float16x8_t x, int16_t nb) { float16x8_t r = x; nb--; while (nb > 0) { @@ -245,15 +238,13 @@ __STATIC_INLINE float16x8_t arm_vec_exponent_f16(float16x8_t x, int16_t nb) __STATIC_INLINE f16x8_t vpowq_f16( f16x8_t val, - f16x8_t n) -{ + f16x8_t n) { return vexpq_f16(vmulq_f16(n, vlogq_f16(val))); } #define INV_NEWTON_INIT_F16 0x7773 -__STATIC_INLINE f16x8_t vrecip_f16(f16x8_t vecIn) -{ +__STATIC_INLINE f16x8_t vrecip_f16(f16x8_t vecIn) { f16x8_t vecSx, vecW, vecTmp; any16x8_t v; @@ -283,8 +274,7 @@ __STATIC_INLINE f16x8_t vrecip_f16(f16x8_t vecIn) } __STATIC_INLINE f16x8_t vtanhq_f16( - f16x8_t val) -{ + f16x8_t val) { f16x8_t x = vminnmq_f16(vmaxnmq_f16(val, vdupq_n_f16(-10.f16)), vdupq_n_f16(10.0f16)); f16x8_t exp2x = vexpq_f16(vmulq_n_f16(x, 2.f16)); diff --git a/armlib/at32_sys/cmsis/cm4/core_support/cmsis_armcc.h b/armlib/at32_sys/cmsis/cm4/core_support/cmsis_armcc.h index a955d4713..a219313a0 100644 --- a/armlib/at32_sys/cmsis/cm4/core_support/cmsis_armcc.h +++ b/armlib/at32_sys/cmsis/cm4/core_support/cmsis_armcc.h @@ -27,86 +27,86 @@ #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 400677) - #error "Please use Arm Compiler Toolchain V4.0.677 or later!" +#error "Please use Arm Compiler Toolchain V4.0.677 or later!" #endif /* CMSIS compiler control architecture macros */ #if ((defined (__TARGET_ARCH_6_M ) && (__TARGET_ARCH_6_M == 1)) || \ (defined (__TARGET_ARCH_6S_M ) && (__TARGET_ARCH_6S_M == 1)) ) - #define __ARM_ARCH_6M__ 1 +#define __ARM_ARCH_6M__ 1 #endif #if (defined (__TARGET_ARCH_7_M ) && (__TARGET_ARCH_7_M == 1)) - #define __ARM_ARCH_7M__ 1 +#define __ARM_ARCH_7M__ 1 #endif #if (defined (__TARGET_ARCH_7E_M) && (__TARGET_ARCH_7E_M == 1)) - #define __ARM_ARCH_7EM__ 1 +#define __ARM_ARCH_7EM__ 1 #endif - /* __ARM_ARCH_8M_BASE__ not applicable */ - /* __ARM_ARCH_8M_MAIN__ not applicable */ - /* __ARM_ARCH_8_1M_MAIN__ not applicable */ +/* __ARM_ARCH_8M_BASE__ not applicable */ +/* __ARM_ARCH_8M_MAIN__ not applicable */ +/* __ARM_ARCH_8_1M_MAIN__ not applicable */ /* CMSIS compiler control DSP macros */ #if ((defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) ) - #define __ARM_FEATURE_DSP 1 +#define __ARM_FEATURE_DSP 1 #endif /* CMSIS compiler specific defines */ #ifndef __ASM - #define __ASM __asm +#define __ASM __asm #endif #ifndef __INLINE - #define __INLINE __inline +#define __INLINE __inline #endif #ifndef __STATIC_INLINE - #define __STATIC_INLINE static __inline +#define __STATIC_INLINE static __inline #endif #ifndef __STATIC_FORCEINLINE - #define __STATIC_FORCEINLINE static __forceinline +#define __STATIC_FORCEINLINE static __forceinline #endif #ifndef __NO_RETURN - #define __NO_RETURN __declspec(noreturn) +#define __NO_RETURN __declspec(noreturn) #endif #ifndef __USED - #define __USED __attribute__((used)) +#define __USED __attribute__((used)) #endif #ifndef __WEAK - #define __WEAK __attribute__((weak)) +#define __WEAK __attribute__((weak)) #endif #ifndef __PACKED - #define __PACKED __attribute__((packed)) +#define __PACKED __attribute__((packed)) #endif #ifndef __PACKED_STRUCT - #define __PACKED_STRUCT __packed struct +#define __PACKED_STRUCT __packed struct #endif #ifndef __PACKED_UNION - #define __PACKED_UNION __packed union +#define __PACKED_UNION __packed union #endif #ifndef __UNALIGNED_UINT32 /* deprecated */ - #define __UNALIGNED_UINT32(x) (*((__packed uint32_t *)(x))) +#define __UNALIGNED_UINT32(x) (*((__packed uint32_t *)(x))) #endif #ifndef __UNALIGNED_UINT16_WRITE - #define __UNALIGNED_UINT16_WRITE(addr, val) ((*((__packed uint16_t *)(addr))) = (val)) +#define __UNALIGNED_UINT16_WRITE(addr, val) ((*((__packed uint16_t *)(addr))) = (val)) #endif #ifndef __UNALIGNED_UINT16_READ - #define __UNALIGNED_UINT16_READ(addr) (*((const __packed uint16_t *)(addr))) +#define __UNALIGNED_UINT16_READ(addr) (*((const __packed uint16_t *)(addr))) #endif #ifndef __UNALIGNED_UINT32_WRITE - #define __UNALIGNED_UINT32_WRITE(addr, val) ((*((__packed uint32_t *)(addr))) = (val)) +#define __UNALIGNED_UINT32_WRITE(addr, val) ((*((__packed uint32_t *)(addr))) = (val)) #endif #ifndef __UNALIGNED_UINT32_READ - #define __UNALIGNED_UINT32_READ(addr) (*((const __packed uint32_t *)(addr))) +#define __UNALIGNED_UINT32_READ(addr) (*((const __packed uint32_t *)(addr))) #endif #ifndef __ALIGNED - #define __ALIGNED(x) __attribute__((aligned(x))) +#define __ALIGNED(x) __attribute__((aligned(x))) #endif #ifndef __RESTRICT - #define __RESTRICT __restrict +#define __RESTRICT __restrict #endif #ifndef __COMPILER_BARRIER - #define __COMPILER_BARRIER() __memory_changed() +#define __COMPILER_BARRIER() __memory_changed() #endif /* ######################### Startup and Lowlevel Init ######################## */ @@ -205,10 +205,9 @@ \return Reversed value */ #ifndef __NO_EMBEDDED_ASM -__attribute__((section(".rev16_text"))) __STATIC_INLINE __ASM uint32_t __REV16(uint32_t value) -{ - rev16 r0, r0 - bx lr +__attribute__((section(".rev16_text"))) __STATIC_INLINE __ASM uint32_t __REV16(uint32_t value) { + rev16 r0, r0 + bx lr } #endif @@ -220,10 +219,9 @@ __attribute__((section(".rev16_text"))) __STATIC_INLINE __ASM uint32_t __REV16(u \return Reversed value */ #ifndef __NO_EMBEDDED_ASM -__attribute__((section(".revsh_text"))) __STATIC_INLINE __ASM int16_t __REVSH(int16_t value) -{ - revsh r0, r0 - bx lr +__attribute__((section(".revsh_text"))) __STATIC_INLINE __ASM int16_t __REVSH(int16_t value) { + revsh r0, r0 + bx lr } #endif @@ -256,22 +254,20 @@ __attribute__((section(".revsh_text"))) __STATIC_INLINE __ASM int16_t __REVSH(in */ #if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ (defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) ) - #define __RBIT __rbit +#define __RBIT __rbit #else -__attribute__((always_inline)) __STATIC_INLINE uint32_t __RBIT(uint32_t value) -{ - uint32_t result; - uint32_t s = (4U /*sizeof(v)*/ * 8U) - 1U; /* extra shift needed at end */ +__attribute__((always_inline)) __STATIC_INLINE uint32_t __RBIT(uint32_t value) { + uint32_t result; + uint32_t s = (4U /*sizeof(v)*/ * 8U) - 1U; /* extra shift needed at end */ - result = value; /* r will be reversed bits of v; first get LSB of v */ - for (value >>= 1U; value != 0U; value >>= 1U) - { - result <<= 1U; - result |= value & 1U; - s--; - } - result <<= s; /* shift when v's highest bits are zero */ - return result; + result = value; /* r will be reversed bits of v; first get LSB of v */ + for (value >>= 1U; value != 0U; value >>= 1U) { + result <<= 1U; + result |= value & 1U; + s--; + } + result <<= s; /* shift when v's highest bits are zero */ + return result; } #endif @@ -295,9 +291,9 @@ __attribute__((always_inline)) __STATIC_INLINE uint32_t __RBIT(uint32_t value) \return value of type uint8_t at (*ptr) */ #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020) - #define __LDREXB(ptr) ((uint8_t ) __ldrex(ptr)) +#define __LDREXB(ptr) ((uint8_t ) __ldrex(ptr)) #else - #define __LDREXB(ptr) _Pragma("push") _Pragma("diag_suppress 3731") ((uint8_t ) __ldrex(ptr)) _Pragma("pop") +#define __LDREXB(ptr) _Pragma("push") _Pragma("diag_suppress 3731") ((uint8_t ) __ldrex(ptr)) _Pragma("pop") #endif @@ -308,9 +304,9 @@ __attribute__((always_inline)) __STATIC_INLINE uint32_t __RBIT(uint32_t value) \return value of type uint16_t at (*ptr) */ #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020) - #define __LDREXH(ptr) ((uint16_t) __ldrex(ptr)) +#define __LDREXH(ptr) ((uint16_t) __ldrex(ptr)) #else - #define __LDREXH(ptr) _Pragma("push") _Pragma("diag_suppress 3731") ((uint16_t) __ldrex(ptr)) _Pragma("pop") +#define __LDREXH(ptr) _Pragma("push") _Pragma("diag_suppress 3731") ((uint16_t) __ldrex(ptr)) _Pragma("pop") #endif @@ -321,9 +317,9 @@ __attribute__((always_inline)) __STATIC_INLINE uint32_t __RBIT(uint32_t value) \return value of type uint32_t at (*ptr) */ #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020) - #define __LDREXW(ptr) ((uint32_t ) __ldrex(ptr)) +#define __LDREXW(ptr) ((uint32_t ) __ldrex(ptr)) #else - #define __LDREXW(ptr) _Pragma("push") _Pragma("diag_suppress 3731") ((uint32_t ) __ldrex(ptr)) _Pragma("pop") +#define __LDREXW(ptr) _Pragma("push") _Pragma("diag_suppress 3731") ((uint32_t ) __ldrex(ptr)) _Pragma("pop") #endif @@ -336,9 +332,9 @@ __attribute__((always_inline)) __STATIC_INLINE uint32_t __RBIT(uint32_t value) \return 1 Function failed */ #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020) - #define __STREXB(value, ptr) __strex(value, ptr) +#define __STREXB(value, ptr) __strex(value, ptr) #else - #define __STREXB(value, ptr) _Pragma("push") _Pragma("diag_suppress 3731") __strex(value, ptr) _Pragma("pop") +#define __STREXB(value, ptr) _Pragma("push") _Pragma("diag_suppress 3731") __strex(value, ptr) _Pragma("pop") #endif @@ -351,9 +347,9 @@ __attribute__((always_inline)) __STATIC_INLINE uint32_t __RBIT(uint32_t value) \return 1 Function failed */ #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020) - #define __STREXH(value, ptr) __strex(value, ptr) +#define __STREXH(value, ptr) __strex(value, ptr) #else - #define __STREXH(value, ptr) _Pragma("push") _Pragma("diag_suppress 3731") __strex(value, ptr) _Pragma("pop") +#define __STREXH(value, ptr) _Pragma("push") _Pragma("diag_suppress 3731") __strex(value, ptr) _Pragma("pop") #endif @@ -366,9 +362,9 @@ __attribute__((always_inline)) __STATIC_INLINE uint32_t __RBIT(uint32_t value) \return 1 Function failed */ #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020) - #define __STREXW(value, ptr) __strex(value, ptr) +#define __STREXW(value, ptr) __strex(value, ptr) #else - #define __STREXW(value, ptr) _Pragma("push") _Pragma("diag_suppress 3731") __strex(value, ptr) _Pragma("pop") +#define __STREXW(value, ptr) _Pragma("push") _Pragma("diag_suppress 3731") __strex(value, ptr) _Pragma("pop") #endif @@ -407,10 +403,9 @@ __attribute__((always_inline)) __STATIC_INLINE uint32_t __RBIT(uint32_t value) \return Rotated value */ #ifndef __NO_EMBEDDED_ASM -__attribute__((section(".rrx_text"))) __STATIC_INLINE __ASM uint32_t __RRX(uint32_t value) -{ - rrx r0, r0 - bx lr +__attribute__((section(".rrx_text"))) __STATIC_INLINE __ASM uint32_t __RRX(uint32_t value) { + rrx r0, r0 + bx lr } #endif @@ -478,22 +473,17 @@ __attribute__((section(".rrx_text"))) __STATIC_INLINE __ASM uint32_t __RRX(uint3 \param [in] sat Bit position to saturate to (1..32) \return Saturated value */ -__attribute__((always_inline)) __STATIC_INLINE int32_t __SSAT(int32_t val, uint32_t sat) -{ - if ((sat >= 1U) && (sat <= 32U)) - { - const int32_t max = (int32_t)((1U << (sat - 1U)) - 1U); - const int32_t min = -1 - max ; - if (val > max) - { - return max; +__attribute__((always_inline)) __STATIC_INLINE int32_t __SSAT(int32_t val, uint32_t sat) { + if ((sat >= 1U) && (sat <= 32U)) { + const int32_t max = (int32_t)((1U << (sat - 1U)) - 1U); + const int32_t min = -1 - max ; + if (val > max) { + return max; + } else if (val < min) { + return min; + } } - else if (val < min) - { - return min; - } - } - return val; + return val; } /** @@ -503,21 +493,16 @@ __attribute__((always_inline)) __STATIC_INLINE int32_t __SSAT(int32_t val, uint3 \param [in] sat Bit position to saturate to (0..31) \return Saturated value */ -__attribute__((always_inline)) __STATIC_INLINE uint32_t __USAT(int32_t val, uint32_t sat) -{ - if (sat <= 31U) - { - const uint32_t max = ((1U << sat) - 1U); - if (val > (int32_t)max) - { - return max; +__attribute__((always_inline)) __STATIC_INLINE uint32_t __USAT(int32_t val, uint32_t sat) { + if (sat <= 31U) { + const uint32_t max = ((1U << sat) - 1U); + if (val > (int32_t)max) { + return max; + } else if (val < 0) { + return 0U; + } } - else if (val < 0) - { - return 0U; - } - } - return (uint32_t)val; + return (uint32_t)val; } #endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ @@ -552,10 +537,9 @@ __attribute__((always_inline)) __STATIC_INLINE uint32_t __USAT(int32_t val, uint \details Returns the content of the Control Register. \return Control Register value */ -__STATIC_INLINE uint32_t __get_CONTROL(void) -{ - register uint32_t __regControl __ASM("control"); - return(__regControl); +__STATIC_INLINE uint32_t __get_CONTROL(void) { + register uint32_t __regControl __ASM("control"); + return (__regControl); } @@ -564,11 +548,10 @@ __STATIC_INLINE uint32_t __get_CONTROL(void) \details Writes the given value to the Control Register. \param [in] control Control Register value to set */ -__STATIC_INLINE void __set_CONTROL(uint32_t control) -{ - register uint32_t __regControl __ASM("control"); - __regControl = control; - __ISB(); +__STATIC_INLINE void __set_CONTROL(uint32_t control) { + register uint32_t __regControl __ASM("control"); + __regControl = control; + __ISB(); } @@ -577,10 +560,9 @@ __STATIC_INLINE void __set_CONTROL(uint32_t control) \details Returns the content of the IPSR Register. \return IPSR Register value */ -__STATIC_INLINE uint32_t __get_IPSR(void) -{ - register uint32_t __regIPSR __ASM("ipsr"); - return(__regIPSR); +__STATIC_INLINE uint32_t __get_IPSR(void) { + register uint32_t __regIPSR __ASM("ipsr"); + return (__regIPSR); } @@ -589,10 +571,9 @@ __STATIC_INLINE uint32_t __get_IPSR(void) \details Returns the content of the APSR Register. \return APSR Register value */ -__STATIC_INLINE uint32_t __get_APSR(void) -{ - register uint32_t __regAPSR __ASM("apsr"); - return(__regAPSR); +__STATIC_INLINE uint32_t __get_APSR(void) { + register uint32_t __regAPSR __ASM("apsr"); + return (__regAPSR); } @@ -601,10 +582,9 @@ __STATIC_INLINE uint32_t __get_APSR(void) \details Returns the content of the xPSR Register. \return xPSR Register value */ -__STATIC_INLINE uint32_t __get_xPSR(void) -{ - register uint32_t __regXPSR __ASM("xpsr"); - return(__regXPSR); +__STATIC_INLINE uint32_t __get_xPSR(void) { + register uint32_t __regXPSR __ASM("xpsr"); + return (__regXPSR); } @@ -613,10 +593,9 @@ __STATIC_INLINE uint32_t __get_xPSR(void) \details Returns the current value of the Process Stack Pointer (PSP). \return PSP Register value */ -__STATIC_INLINE uint32_t __get_PSP(void) -{ - register uint32_t __regProcessStackPointer __ASM("psp"); - return(__regProcessStackPointer); +__STATIC_INLINE uint32_t __get_PSP(void) { + register uint32_t __regProcessStackPointer __ASM("psp"); + return (__regProcessStackPointer); } @@ -625,10 +604,9 @@ __STATIC_INLINE uint32_t __get_PSP(void) \details Assigns the given value to the Process Stack Pointer (PSP). \param [in] topOfProcStack Process Stack Pointer value to set */ -__STATIC_INLINE void __set_PSP(uint32_t topOfProcStack) -{ - register uint32_t __regProcessStackPointer __ASM("psp"); - __regProcessStackPointer = topOfProcStack; +__STATIC_INLINE void __set_PSP(uint32_t topOfProcStack) { + register uint32_t __regProcessStackPointer __ASM("psp"); + __regProcessStackPointer = topOfProcStack; } @@ -637,10 +615,9 @@ __STATIC_INLINE void __set_PSP(uint32_t topOfProcStack) \details Returns the current value of the Main Stack Pointer (MSP). \return MSP Register value */ -__STATIC_INLINE uint32_t __get_MSP(void) -{ - register uint32_t __regMainStackPointer __ASM("msp"); - return(__regMainStackPointer); +__STATIC_INLINE uint32_t __get_MSP(void) { + register uint32_t __regMainStackPointer __ASM("msp"); + return (__regMainStackPointer); } @@ -649,10 +626,9 @@ __STATIC_INLINE uint32_t __get_MSP(void) \details Assigns the given value to the Main Stack Pointer (MSP). \param [in] topOfMainStack Main Stack Pointer value to set */ -__STATIC_INLINE void __set_MSP(uint32_t topOfMainStack) -{ - register uint32_t __regMainStackPointer __ASM("msp"); - __regMainStackPointer = topOfMainStack; +__STATIC_INLINE void __set_MSP(uint32_t topOfMainStack) { + register uint32_t __regMainStackPointer __ASM("msp"); + __regMainStackPointer = topOfMainStack; } @@ -661,10 +637,9 @@ __STATIC_INLINE void __set_MSP(uint32_t topOfMainStack) \details Returns the current state of the priority mask bit from the Priority Mask Register. \return Priority Mask value */ -__STATIC_INLINE uint32_t __get_PRIMASK(void) -{ - register uint32_t __regPriMask __ASM("primask"); - return(__regPriMask); +__STATIC_INLINE uint32_t __get_PRIMASK(void) { + register uint32_t __regPriMask __ASM("primask"); + return (__regPriMask); } @@ -673,10 +648,9 @@ __STATIC_INLINE uint32_t __get_PRIMASK(void) \details Assigns the given value to the Priority Mask Register. \param [in] priMask Priority Mask */ -__STATIC_INLINE void __set_PRIMASK(uint32_t priMask) -{ - register uint32_t __regPriMask __ASM("primask"); - __regPriMask = (priMask); +__STATIC_INLINE void __set_PRIMASK(uint32_t priMask) { + register uint32_t __regPriMask __ASM("primask"); + __regPriMask = (priMask); } @@ -704,10 +678,9 @@ __STATIC_INLINE void __set_PRIMASK(uint32_t priMask) \details Returns the current value of the Base Priority register. \return Base Priority register value */ -__STATIC_INLINE uint32_t __get_BASEPRI(void) -{ - register uint32_t __regBasePri __ASM("basepri"); - return(__regBasePri); +__STATIC_INLINE uint32_t __get_BASEPRI(void) { + register uint32_t __regBasePri __ASM("basepri"); + return (__regBasePri); } @@ -716,10 +689,9 @@ __STATIC_INLINE uint32_t __get_BASEPRI(void) \details Assigns the given value to the Base Priority register. \param [in] basePri Base Priority value to set */ -__STATIC_INLINE void __set_BASEPRI(uint32_t basePri) -{ - register uint32_t __regBasePri __ASM("basepri"); - __regBasePri = (basePri & 0xFFU); +__STATIC_INLINE void __set_BASEPRI(uint32_t basePri) { + register uint32_t __regBasePri __ASM("basepri"); + __regBasePri = (basePri & 0xFFU); } @@ -729,10 +701,9 @@ __STATIC_INLINE void __set_BASEPRI(uint32_t basePri) or the new value increases the BASEPRI priority level. \param [in] basePri Base Priority value to set */ -__STATIC_INLINE void __set_BASEPRI_MAX(uint32_t basePri) -{ - register uint32_t __regBasePriMax __ASM("basepri_max"); - __regBasePriMax = (basePri & 0xFFU); +__STATIC_INLINE void __set_BASEPRI_MAX(uint32_t basePri) { + register uint32_t __regBasePriMax __ASM("basepri_max"); + __regBasePriMax = (basePri & 0xFFU); } @@ -741,10 +712,9 @@ __STATIC_INLINE void __set_BASEPRI_MAX(uint32_t basePri) \details Returns the current value of the Fault Mask register. \return Fault Mask register value */ -__STATIC_INLINE uint32_t __get_FAULTMASK(void) -{ - register uint32_t __regFaultMask __ASM("faultmask"); - return(__regFaultMask); +__STATIC_INLINE uint32_t __get_FAULTMASK(void) { + register uint32_t __regFaultMask __ASM("faultmask"); + return (__regFaultMask); } @@ -753,10 +723,9 @@ __STATIC_INLINE uint32_t __get_FAULTMASK(void) \details Assigns the given value to the Fault Mask register. \param [in] faultMask Fault Mask value to set */ -__STATIC_INLINE void __set_FAULTMASK(uint32_t faultMask) -{ - register uint32_t __regFaultMask __ASM("faultmask"); - __regFaultMask = (faultMask & (uint32_t)1U); +__STATIC_INLINE void __set_FAULTMASK(uint32_t faultMask) { + register uint32_t __regFaultMask __ASM("faultmask"); + __regFaultMask = (faultMask & (uint32_t)1U); } #endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ @@ -768,14 +737,13 @@ __STATIC_INLINE void __set_FAULTMASK(uint32_t faultMask) \details Returns the current value of the Floating Point Status/Control register. \return Floating Point Status/Control register value */ -__STATIC_INLINE uint32_t __get_FPSCR(void) -{ +__STATIC_INLINE uint32_t __get_FPSCR(void) { #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \ (defined (__FPU_USED ) && (__FPU_USED == 1U)) ) - register uint32_t __regfpscr __ASM("fpscr"); - return(__regfpscr); + register uint32_t __regfpscr __ASM("fpscr"); + return (__regfpscr); #else - return(0U); + return (0U); #endif } @@ -785,14 +753,13 @@ __STATIC_INLINE uint32_t __get_FPSCR(void) \details Assigns the given value to the Floating Point Status/Control register. \param [in] fpscr Floating Point Status/Control value to set */ -__STATIC_INLINE void __set_FPSCR(uint32_t fpscr) -{ +__STATIC_INLINE void __set_FPSCR(uint32_t fpscr) { #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \ (defined (__FPU_USED ) && (__FPU_USED == 1U)) ) - register uint32_t __regfpscr __ASM("fpscr"); - __regfpscr = (fpscr); + register uint32_t __regfpscr __ASM("fpscr"); + __regfpscr = (fpscr); #else - (void)fpscr; + (void)fpscr; #endif } diff --git a/armlib/at32_sys/cmsis/cm4/core_support/cmsis_armclang.h b/armlib/at32_sys/cmsis/cm4/core_support/cmsis_armclang.h index 691141774..f972249e0 100644 --- a/armlib/at32_sys/cmsis/cm4/core_support/cmsis_armclang.h +++ b/armlib/at32_sys/cmsis/cm4/core_support/cmsis_armclang.h @@ -31,83 +31,83 @@ /* CMSIS compiler specific defines */ #ifndef __ASM - #define __ASM __asm +#define __ASM __asm #endif #ifndef __INLINE - #define __INLINE __inline +#define __INLINE __inline #endif #ifndef __STATIC_INLINE - #define __STATIC_INLINE static __inline +#define __STATIC_INLINE static __inline #endif #ifndef __STATIC_FORCEINLINE - #define __STATIC_FORCEINLINE __attribute__((always_inline)) static __inline +#define __STATIC_FORCEINLINE __attribute__((always_inline)) static __inline #endif #ifndef __NO_RETURN - #define __NO_RETURN __attribute__((__noreturn__)) +#define __NO_RETURN __attribute__((__noreturn__)) #endif #ifndef __USED - #define __USED __attribute__((used)) +#define __USED __attribute__((used)) #endif #ifndef __WEAK - #define __WEAK __attribute__((weak)) +#define __WEAK __attribute__((weak)) #endif #ifndef __PACKED - #define __PACKED __attribute__((packed, aligned(1))) +#define __PACKED __attribute__((packed, aligned(1))) #endif #ifndef __PACKED_STRUCT - #define __PACKED_STRUCT struct __attribute__((packed, aligned(1))) +#define __PACKED_STRUCT struct __attribute__((packed, aligned(1))) #endif #ifndef __PACKED_UNION - #define __PACKED_UNION union __attribute__((packed, aligned(1))) +#define __PACKED_UNION union __attribute__((packed, aligned(1))) #endif #ifndef __UNALIGNED_UINT32 /* deprecated */ - #pragma clang diagnostic push - #pragma clang diagnostic ignored "-Wpacked" +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wpacked" /*lint -esym(9058, T_UINT32)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT32 */ - struct __attribute__((packed)) T_UINT32 { uint32_t v; }; - #pragma clang diagnostic pop - #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v) +struct __attribute__((packed)) T_UINT32 { uint32_t v; }; +#pragma clang diagnostic pop +#define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v) #endif #ifndef __UNALIGNED_UINT16_WRITE - #pragma clang diagnostic push - #pragma clang diagnostic ignored "-Wpacked" +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wpacked" /*lint -esym(9058, T_UINT16_WRITE)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT16_WRITE */ - __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; }; - #pragma clang diagnostic pop - #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val)) +__PACKED_STRUCT T_UINT16_WRITE { uint16_t v; }; +#pragma clang diagnostic pop +#define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val)) #endif #ifndef __UNALIGNED_UINT16_READ - #pragma clang diagnostic push - #pragma clang diagnostic ignored "-Wpacked" +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wpacked" /*lint -esym(9058, T_UINT16_READ)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT16_READ */ - __PACKED_STRUCT T_UINT16_READ { uint16_t v; }; - #pragma clang diagnostic pop - #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v) +__PACKED_STRUCT T_UINT16_READ { uint16_t v; }; +#pragma clang diagnostic pop +#define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v) #endif #ifndef __UNALIGNED_UINT32_WRITE - #pragma clang diagnostic push - #pragma clang diagnostic ignored "-Wpacked" +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wpacked" /*lint -esym(9058, T_UINT32_WRITE)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT32_WRITE */ - __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; }; - #pragma clang diagnostic pop - #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val)) +__PACKED_STRUCT T_UINT32_WRITE { uint32_t v; }; +#pragma clang diagnostic pop +#define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val)) #endif #ifndef __UNALIGNED_UINT32_READ - #pragma clang diagnostic push - #pragma clang diagnostic ignored "-Wpacked" +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wpacked" /*lint -esym(9058, T_UINT32_READ)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT32_READ */ - __PACKED_STRUCT T_UINT32_READ { uint32_t v; }; - #pragma clang diagnostic pop - #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v) +__PACKED_STRUCT T_UINT32_READ { uint32_t v; }; +#pragma clang diagnostic pop +#define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v) #endif #ifndef __ALIGNED - #define __ALIGNED(x) __attribute__((aligned(x))) +#define __ALIGNED(x) __attribute__((aligned(x))) #endif #ifndef __RESTRICT - #define __RESTRICT __restrict +#define __RESTRICT __restrict #endif #ifndef __COMPILER_BARRIER - #define __COMPILER_BARRIER() __ASM volatile("":::"memory") +#define __COMPILER_BARRIER() __ASM volatile("":::"memory") #endif /* ######################### Startup and Lowlevel Init ######################## */ @@ -146,8 +146,8 @@ #endif -__STATIC_FORCEINLINE void __TZ_set_STACKSEAL_S (uint32_t* stackTop) { - *((uint64_t *)stackTop) = __TZ_STACK_SEAL_VALUE; +__STATIC_FORCEINLINE void __TZ_set_STACKSEAL_S(uint32_t *stackTop) { + *((uint64_t *)stackTop) = __TZ_STACK_SEAL_VALUE; } #endif @@ -257,14 +257,12 @@ __STATIC_FORCEINLINE void __TZ_set_STACKSEAL_S (uint32_t* stackTop) { \param [in] op2 Number of Bits to rotate \return Rotated value */ -__STATIC_FORCEINLINE uint32_t __ROR(uint32_t op1, uint32_t op2) -{ - op2 %= 32U; - if (op2 == 0U) - { - return op1; - } - return (op1 >> op2) | (op1 << (32U - op2)); +__STATIC_FORCEINLINE uint32_t __ROR(uint32_t op1, uint32_t op2) { + op2 %= 32U; + if (op2 == 0U) { + return op1; + } + return (op1 >> op2) | (op1 << (32U - op2)); } @@ -292,22 +290,20 @@ __STATIC_FORCEINLINE uint32_t __ROR(uint32_t op1, uint32_t op2) \param [in] value Value to count the leading zeros \return number of leading zeros in value */ -__STATIC_FORCEINLINE uint8_t __CLZ(uint32_t value) -{ - /* Even though __builtin_clz produces a CLZ instruction on ARM, formally - __builtin_clz(0) is undefined behaviour, so handle this case specially. - This guarantees ARM-compatible results if happening to compile on a non-ARM - target, and ensures the compiler doesn't decide to activate any - optimisations using the logic "value was passed to __builtin_clz, so it - is non-zero". - ARM Compiler 6.10 and possibly earlier will optimise this test away, leaving a - single CLZ instruction. - */ - if (value == 0U) - { - return 32U; - } - return __builtin_clz(value); +__STATIC_FORCEINLINE uint8_t __CLZ(uint32_t value) { + /* Even though __builtin_clz produces a CLZ instruction on ARM, formally + __builtin_clz(0) is undefined behaviour, so handle this case specially. + This guarantees ARM-compatible results if happening to compile on a non-ARM + target, and ensures the compiler doesn't decide to activate any + optimisations using the logic "value was passed to __builtin_clz, so it + is non-zero". + ARM Compiler 6.10 and possibly earlier will optimise this test away, leaving a + single CLZ instruction. + */ + if (value == 0U) { + return 32U; + } + return __builtin_clz(value); } @@ -422,12 +418,11 @@ __STATIC_FORCEINLINE uint8_t __CLZ(uint32_t value) \param [in] value Value to rotate \return Rotated value */ -__STATIC_FORCEINLINE uint32_t __RRX(uint32_t value) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __RRX(uint32_t value) { + uint32_t result; - __ASM volatile ("rrx %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) ); - return(result); + __ASM volatile("rrx %0, %1" : __CMSIS_GCC_OUT_REG(result) : __CMSIS_GCC_USE_REG(value)); + return (result); } @@ -437,12 +432,11 @@ __STATIC_FORCEINLINE uint32_t __RRX(uint32_t value) \param [in] ptr Pointer to data \return value of type uint8_t at (*ptr) */ -__STATIC_FORCEINLINE uint8_t __LDRBT(volatile uint8_t *ptr) -{ - uint32_t result; +__STATIC_FORCEINLINE uint8_t __LDRBT(volatile uint8_t *ptr) { + uint32_t result; - __ASM volatile ("ldrbt %0, %1" : "=r" (result) : "Q" (*ptr) ); - return ((uint8_t) result); /* Add explicit type cast here */ + __ASM volatile("ldrbt %0, %1" : "=r"(result) : "Q"(*ptr)); + return ((uint8_t) result); /* Add explicit type cast here */ } @@ -452,12 +446,11 @@ __STATIC_FORCEINLINE uint8_t __LDRBT(volatile uint8_t *ptr) \param [in] ptr Pointer to data \return value of type uint16_t at (*ptr) */ -__STATIC_FORCEINLINE uint16_t __LDRHT(volatile uint16_t *ptr) -{ - uint32_t result; +__STATIC_FORCEINLINE uint16_t __LDRHT(volatile uint16_t *ptr) { + uint32_t result; - __ASM volatile ("ldrht %0, %1" : "=r" (result) : "Q" (*ptr) ); - return ((uint16_t) result); /* Add explicit type cast here */ + __ASM volatile("ldrht %0, %1" : "=r"(result) : "Q"(*ptr)); + return ((uint16_t) result); /* Add explicit type cast here */ } @@ -467,12 +460,11 @@ __STATIC_FORCEINLINE uint16_t __LDRHT(volatile uint16_t *ptr) \param [in] ptr Pointer to data \return value of type uint32_t at (*ptr) */ -__STATIC_FORCEINLINE uint32_t __LDRT(volatile uint32_t *ptr) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __LDRT(volatile uint32_t *ptr) { + uint32_t result; - __ASM volatile ("ldrt %0, %1" : "=r" (result) : "Q" (*ptr) ); - return(result); + __ASM volatile("ldrt %0, %1" : "=r"(result) : "Q"(*ptr)); + return (result); } @@ -482,9 +474,8 @@ __STATIC_FORCEINLINE uint32_t __LDRT(volatile uint32_t *ptr) \param [in] value Value to store \param [in] ptr Pointer to location */ -__STATIC_FORCEINLINE void __STRBT(uint8_t value, volatile uint8_t *ptr) -{ - __ASM volatile ("strbt %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) ); +__STATIC_FORCEINLINE void __STRBT(uint8_t value, volatile uint8_t *ptr) { + __ASM volatile("strbt %1, %0" : "=Q"(*ptr) : "r"((uint32_t)value)); } @@ -494,9 +485,8 @@ __STATIC_FORCEINLINE void __STRBT(uint8_t value, volatile uint8_t *ptr) \param [in] value Value to store \param [in] ptr Pointer to location */ -__STATIC_FORCEINLINE void __STRHT(uint16_t value, volatile uint16_t *ptr) -{ - __ASM volatile ("strht %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) ); +__STATIC_FORCEINLINE void __STRHT(uint16_t value, volatile uint16_t *ptr) { + __ASM volatile("strht %1, %0" : "=Q"(*ptr) : "r"((uint32_t)value)); } @@ -506,9 +496,8 @@ __STATIC_FORCEINLINE void __STRHT(uint16_t value, volatile uint16_t *ptr) \param [in] value Value to store \param [in] ptr Pointer to location */ -__STATIC_FORCEINLINE void __STRT(uint32_t value, volatile uint32_t *ptr) -{ - __ASM volatile ("strt %1, %0" : "=Q" (*ptr) : "r" (value) ); +__STATIC_FORCEINLINE void __STRT(uint32_t value, volatile uint32_t *ptr) { + __ASM volatile("strt %1, %0" : "=Q"(*ptr) : "r"(value)); } #else /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ @@ -523,22 +512,17 @@ __STATIC_FORCEINLINE void __STRT(uint32_t value, volatile uint32_t *ptr) \param [in] sat Bit position to saturate to (1..32) \return Saturated value */ -__STATIC_FORCEINLINE int32_t __SSAT(int32_t val, uint32_t sat) -{ - if ((sat >= 1U) && (sat <= 32U)) - { - const int32_t max = (int32_t)((1U << (sat - 1U)) - 1U); - const int32_t min = -1 - max ; - if (val > max) - { - return max; +__STATIC_FORCEINLINE int32_t __SSAT(int32_t val, uint32_t sat) { + if ((sat >= 1U) && (sat <= 32U)) { + const int32_t max = (int32_t)((1U << (sat - 1U)) - 1U); + const int32_t min = -1 - max ; + if (val > max) { + return max; + } else if (val < min) { + return min; + } } - else if (val < min) - { - return min; - } - } - return val; + return val; } /** @@ -548,21 +532,16 @@ __STATIC_FORCEINLINE int32_t __SSAT(int32_t val, uint32_t sat) \param [in] sat Bit position to saturate to (0..31) \return Saturated value */ -__STATIC_FORCEINLINE uint32_t __USAT(int32_t val, uint32_t sat) -{ - if (sat <= 31U) - { - const uint32_t max = ((1U << sat) - 1U); - if (val > (int32_t)max) - { - return max; +__STATIC_FORCEINLINE uint32_t __USAT(int32_t val, uint32_t sat) { + if (sat <= 31U) { + const uint32_t max = ((1U << sat) - 1U); + if (val > (int32_t)max) { + return max; + } else if (val < 0) { + return 0U; + } } - else if (val < 0) - { - return 0U; - } - } - return (uint32_t)val; + return (uint32_t)val; } #endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ @@ -581,12 +560,11 @@ __STATIC_FORCEINLINE uint32_t __USAT(int32_t val, uint32_t sat) \param [in] ptr Pointer to data \return value of type uint8_t at (*ptr) */ -__STATIC_FORCEINLINE uint8_t __LDAB(volatile uint8_t *ptr) -{ - uint32_t result; +__STATIC_FORCEINLINE uint8_t __LDAB(volatile uint8_t *ptr) { + uint32_t result; - __ASM volatile ("ldab %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" ); - return ((uint8_t) result); + __ASM volatile("ldab %0, %1" : "=r"(result) : "Q"(*ptr) : "memory"); + return ((uint8_t) result); } @@ -596,12 +574,11 @@ __STATIC_FORCEINLINE uint8_t __LDAB(volatile uint8_t *ptr) \param [in] ptr Pointer to data \return value of type uint16_t at (*ptr) */ -__STATIC_FORCEINLINE uint16_t __LDAH(volatile uint16_t *ptr) -{ - uint32_t result; +__STATIC_FORCEINLINE uint16_t __LDAH(volatile uint16_t *ptr) { + uint32_t result; - __ASM volatile ("ldah %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" ); - return ((uint16_t) result); + __ASM volatile("ldah %0, %1" : "=r"(result) : "Q"(*ptr) : "memory"); + return ((uint16_t) result); } @@ -611,12 +588,11 @@ __STATIC_FORCEINLINE uint16_t __LDAH(volatile uint16_t *ptr) \param [in] ptr Pointer to data \return value of type uint32_t at (*ptr) */ -__STATIC_FORCEINLINE uint32_t __LDA(volatile uint32_t *ptr) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __LDA(volatile uint32_t *ptr) { + uint32_t result; - __ASM volatile ("lda %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" ); - return(result); + __ASM volatile("lda %0, %1" : "=r"(result) : "Q"(*ptr) : "memory"); + return (result); } @@ -626,9 +602,8 @@ __STATIC_FORCEINLINE uint32_t __LDA(volatile uint32_t *ptr) \param [in] value Value to store \param [in] ptr Pointer to location */ -__STATIC_FORCEINLINE void __STLB(uint8_t value, volatile uint8_t *ptr) -{ - __ASM volatile ("stlb %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" ); +__STATIC_FORCEINLINE void __STLB(uint8_t value, volatile uint8_t *ptr) { + __ASM volatile("stlb %1, %0" : "=Q"(*ptr) : "r"((uint32_t)value) : "memory"); } @@ -638,9 +613,8 @@ __STATIC_FORCEINLINE void __STLB(uint8_t value, volatile uint8_t *ptr) \param [in] value Value to store \param [in] ptr Pointer to location */ -__STATIC_FORCEINLINE void __STLH(uint16_t value, volatile uint16_t *ptr) -{ - __ASM volatile ("stlh %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" ); +__STATIC_FORCEINLINE void __STLH(uint16_t value, volatile uint16_t *ptr) { + __ASM volatile("stlh %1, %0" : "=Q"(*ptr) : "r"((uint32_t)value) : "memory"); } @@ -650,9 +624,8 @@ __STATIC_FORCEINLINE void __STLH(uint16_t value, volatile uint16_t *ptr) \param [in] value Value to store \param [in] ptr Pointer to location */ -__STATIC_FORCEINLINE void __STL(uint32_t value, volatile uint32_t *ptr) -{ - __ASM volatile ("stl %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" ); +__STATIC_FORCEINLINE void __STL(uint32_t value, volatile uint32_t *ptr) { + __ASM volatile("stl %1, %0" : "=Q"(*ptr) : "r"((uint32_t)value) : "memory"); } @@ -734,9 +707,8 @@ __STATIC_FORCEINLINE void __STL(uint32_t value, volatile uint32_t *ptr) Can only be executed in Privileged modes. */ #ifndef __ARM_COMPAT_H -__STATIC_FORCEINLINE void __enable_irq(void) -{ - __ASM volatile ("cpsie i" : : : "memory"); +__STATIC_FORCEINLINE void __enable_irq(void) { + __ASM volatile("cpsie i" : : : "memory"); } #endif @@ -747,9 +719,8 @@ __STATIC_FORCEINLINE void __enable_irq(void) Can only be executed in Privileged modes. */ #ifndef __ARM_COMPAT_H -__STATIC_FORCEINLINE void __disable_irq(void) -{ - __ASM volatile ("cpsid i" : : : "memory"); +__STATIC_FORCEINLINE void __disable_irq(void) { + __ASM volatile("cpsid i" : : : "memory"); } #endif @@ -759,12 +730,11 @@ __STATIC_FORCEINLINE void __disable_irq(void) \details Returns the content of the Control Register. \return Control Register value */ -__STATIC_FORCEINLINE uint32_t __get_CONTROL(void) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __get_CONTROL(void) { + uint32_t result; - __ASM volatile ("MRS %0, control" : "=r" (result) ); - return(result); + __ASM volatile("MRS %0, control" : "=r"(result)); + return (result); } @@ -774,12 +744,11 @@ __STATIC_FORCEINLINE uint32_t __get_CONTROL(void) \details Returns the content of the non-secure Control Register when in secure mode. \return non-secure Control Register value */ -__STATIC_FORCEINLINE uint32_t __TZ_get_CONTROL_NS(void) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __TZ_get_CONTROL_NS(void) { + uint32_t result; - __ASM volatile ("MRS %0, control_ns" : "=r" (result) ); - return(result); + __ASM volatile("MRS %0, control_ns" : "=r"(result)); + return (result); } #endif @@ -789,10 +758,9 @@ __STATIC_FORCEINLINE uint32_t __TZ_get_CONTROL_NS(void) \details Writes the given value to the Control Register. \param [in] control Control Register value to set */ -__STATIC_FORCEINLINE void __set_CONTROL(uint32_t control) -{ - __ASM volatile ("MSR control, %0" : : "r" (control) : "memory"); - __ISB(); +__STATIC_FORCEINLINE void __set_CONTROL(uint32_t control) { + __ASM volatile("MSR control, %0" : : "r"(control) : "memory"); + __ISB(); } @@ -802,10 +770,9 @@ __STATIC_FORCEINLINE void __set_CONTROL(uint32_t control) \details Writes the given value to the non-secure Control Register when in secure state. \param [in] control Control Register value to set */ -__STATIC_FORCEINLINE void __TZ_set_CONTROL_NS(uint32_t control) -{ - __ASM volatile ("MSR control_ns, %0" : : "r" (control) : "memory"); - __ISB(); +__STATIC_FORCEINLINE void __TZ_set_CONTROL_NS(uint32_t control) { + __ASM volatile("MSR control_ns, %0" : : "r"(control) : "memory"); + __ISB(); } #endif @@ -815,12 +782,11 @@ __STATIC_FORCEINLINE void __TZ_set_CONTROL_NS(uint32_t control) \details Returns the content of the IPSR Register. \return IPSR Register value */ -__STATIC_FORCEINLINE uint32_t __get_IPSR(void) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __get_IPSR(void) { + uint32_t result; - __ASM volatile ("MRS %0, ipsr" : "=r" (result) ); - return(result); + __ASM volatile("MRS %0, ipsr" : "=r"(result)); + return (result); } @@ -829,12 +795,11 @@ __STATIC_FORCEINLINE uint32_t __get_IPSR(void) \details Returns the content of the APSR Register. \return APSR Register value */ -__STATIC_FORCEINLINE uint32_t __get_APSR(void) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __get_APSR(void) { + uint32_t result; - __ASM volatile ("MRS %0, apsr" : "=r" (result) ); - return(result); + __ASM volatile("MRS %0, apsr" : "=r"(result)); + return (result); } @@ -843,12 +808,11 @@ __STATIC_FORCEINLINE uint32_t __get_APSR(void) \details Returns the content of the xPSR Register. \return xPSR Register value */ -__STATIC_FORCEINLINE uint32_t __get_xPSR(void) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __get_xPSR(void) { + uint32_t result; - __ASM volatile ("MRS %0, xpsr" : "=r" (result) ); - return(result); + __ASM volatile("MRS %0, xpsr" : "=r"(result)); + return (result); } @@ -857,12 +821,11 @@ __STATIC_FORCEINLINE uint32_t __get_xPSR(void) \details Returns the current value of the Process Stack Pointer (PSP). \return PSP Register value */ -__STATIC_FORCEINLINE uint32_t __get_PSP(void) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __get_PSP(void) { + uint32_t result; - __ASM volatile ("MRS %0, psp" : "=r" (result) ); - return(result); + __ASM volatile("MRS %0, psp" : "=r"(result)); + return (result); } @@ -872,12 +835,11 @@ __STATIC_FORCEINLINE uint32_t __get_PSP(void) \details Returns the current value of the non-secure Process Stack Pointer (PSP) when in secure state. \return PSP Register value */ -__STATIC_FORCEINLINE uint32_t __TZ_get_PSP_NS(void) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __TZ_get_PSP_NS(void) { + uint32_t result; - __ASM volatile ("MRS %0, psp_ns" : "=r" (result) ); - return(result); + __ASM volatile("MRS %0, psp_ns" : "=r"(result)); + return (result); } #endif @@ -887,9 +849,8 @@ __STATIC_FORCEINLINE uint32_t __TZ_get_PSP_NS(void) \details Assigns the given value to the Process Stack Pointer (PSP). \param [in] topOfProcStack Process Stack Pointer value to set */ -__STATIC_FORCEINLINE void __set_PSP(uint32_t topOfProcStack) -{ - __ASM volatile ("MSR psp, %0" : : "r" (topOfProcStack) : ); +__STATIC_FORCEINLINE void __set_PSP(uint32_t topOfProcStack) { + __ASM volatile("MSR psp, %0" : : "r"(topOfProcStack) :); } @@ -899,9 +860,8 @@ __STATIC_FORCEINLINE void __set_PSP(uint32_t topOfProcStack) \details Assigns the given value to the non-secure Process Stack Pointer (PSP) when in secure state. \param [in] topOfProcStack Process Stack Pointer value to set */ -__STATIC_FORCEINLINE void __TZ_set_PSP_NS(uint32_t topOfProcStack) -{ - __ASM volatile ("MSR psp_ns, %0" : : "r" (topOfProcStack) : ); +__STATIC_FORCEINLINE void __TZ_set_PSP_NS(uint32_t topOfProcStack) { + __ASM volatile("MSR psp_ns, %0" : : "r"(topOfProcStack) :); } #endif @@ -911,12 +871,11 @@ __STATIC_FORCEINLINE void __TZ_set_PSP_NS(uint32_t topOfProcStack) \details Returns the current value of the Main Stack Pointer (MSP). \return MSP Register value */ -__STATIC_FORCEINLINE uint32_t __get_MSP(void) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __get_MSP(void) { + uint32_t result; - __ASM volatile ("MRS %0, msp" : "=r" (result) ); - return(result); + __ASM volatile("MRS %0, msp" : "=r"(result)); + return (result); } @@ -926,12 +885,11 @@ __STATIC_FORCEINLINE uint32_t __get_MSP(void) \details Returns the current value of the non-secure Main Stack Pointer (MSP) when in secure state. \return MSP Register value */ -__STATIC_FORCEINLINE uint32_t __TZ_get_MSP_NS(void) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __TZ_get_MSP_NS(void) { + uint32_t result; - __ASM volatile ("MRS %0, msp_ns" : "=r" (result) ); - return(result); + __ASM volatile("MRS %0, msp_ns" : "=r"(result)); + return (result); } #endif @@ -941,9 +899,8 @@ __STATIC_FORCEINLINE uint32_t __TZ_get_MSP_NS(void) \details Assigns the given value to the Main Stack Pointer (MSP). \param [in] topOfMainStack Main Stack Pointer value to set */ -__STATIC_FORCEINLINE void __set_MSP(uint32_t topOfMainStack) -{ - __ASM volatile ("MSR msp, %0" : : "r" (topOfMainStack) : ); +__STATIC_FORCEINLINE void __set_MSP(uint32_t topOfMainStack) { + __ASM volatile("MSR msp, %0" : : "r"(topOfMainStack) :); } @@ -953,9 +910,8 @@ __STATIC_FORCEINLINE void __set_MSP(uint32_t topOfMainStack) \details Assigns the given value to the non-secure Main Stack Pointer (MSP) when in secure state. \param [in] topOfMainStack Main Stack Pointer value to set */ -__STATIC_FORCEINLINE void __TZ_set_MSP_NS(uint32_t topOfMainStack) -{ - __ASM volatile ("MSR msp_ns, %0" : : "r" (topOfMainStack) : ); +__STATIC_FORCEINLINE void __TZ_set_MSP_NS(uint32_t topOfMainStack) { + __ASM volatile("MSR msp_ns, %0" : : "r"(topOfMainStack) :); } #endif @@ -966,12 +922,11 @@ __STATIC_FORCEINLINE void __TZ_set_MSP_NS(uint32_t topOfMainStack) \details Returns the current value of the non-secure Stack Pointer (SP) when in secure state. \return SP Register value */ -__STATIC_FORCEINLINE uint32_t __TZ_get_SP_NS(void) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __TZ_get_SP_NS(void) { + uint32_t result; - __ASM volatile ("MRS %0, sp_ns" : "=r" (result) ); - return(result); + __ASM volatile("MRS %0, sp_ns" : "=r"(result)); + return (result); } @@ -980,9 +935,8 @@ __STATIC_FORCEINLINE uint32_t __TZ_get_SP_NS(void) \details Assigns the given value to the non-secure Stack Pointer (SP) when in secure state. \param [in] topOfStack Stack Pointer value to set */ -__STATIC_FORCEINLINE void __TZ_set_SP_NS(uint32_t topOfStack) -{ - __ASM volatile ("MSR sp_ns, %0" : : "r" (topOfStack) : ); +__STATIC_FORCEINLINE void __TZ_set_SP_NS(uint32_t topOfStack) { + __ASM volatile("MSR sp_ns, %0" : : "r"(topOfStack) :); } #endif @@ -992,12 +946,11 @@ __STATIC_FORCEINLINE void __TZ_set_SP_NS(uint32_t topOfStack) \details Returns the current state of the priority mask bit from the Priority Mask Register. \return Priority Mask value */ -__STATIC_FORCEINLINE uint32_t __get_PRIMASK(void) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __get_PRIMASK(void) { + uint32_t result; - __ASM volatile ("MRS %0, primask" : "=r" (result) ); - return(result); + __ASM volatile("MRS %0, primask" : "=r"(result)); + return (result); } @@ -1007,12 +960,11 @@ __STATIC_FORCEINLINE uint32_t __get_PRIMASK(void) \details Returns the current state of the non-secure priority mask bit from the Priority Mask Register when in secure state. \return Priority Mask value */ -__STATIC_FORCEINLINE uint32_t __TZ_get_PRIMASK_NS(void) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __TZ_get_PRIMASK_NS(void) { + uint32_t result; - __ASM volatile ("MRS %0, primask_ns" : "=r" (result) ); - return(result); + __ASM volatile("MRS %0, primask_ns" : "=r"(result)); + return (result); } #endif @@ -1022,9 +974,8 @@ __STATIC_FORCEINLINE uint32_t __TZ_get_PRIMASK_NS(void) \details Assigns the given value to the Priority Mask Register. \param [in] priMask Priority Mask */ -__STATIC_FORCEINLINE void __set_PRIMASK(uint32_t priMask) -{ - __ASM volatile ("MSR primask, %0" : : "r" (priMask) : "memory"); +__STATIC_FORCEINLINE void __set_PRIMASK(uint32_t priMask) { + __ASM volatile("MSR primask, %0" : : "r"(priMask) : "memory"); } @@ -1034,9 +985,8 @@ __STATIC_FORCEINLINE void __set_PRIMASK(uint32_t priMask) \details Assigns the given value to the non-secure Priority Mask Register when in secure state. \param [in] priMask Priority Mask */ -__STATIC_FORCEINLINE void __TZ_set_PRIMASK_NS(uint32_t priMask) -{ - __ASM volatile ("MSR primask_ns, %0" : : "r" (priMask) : "memory"); +__STATIC_FORCEINLINE void __TZ_set_PRIMASK_NS(uint32_t priMask) { + __ASM volatile("MSR primask_ns, %0" : : "r"(priMask) : "memory"); } #endif @@ -1050,9 +1000,8 @@ __STATIC_FORCEINLINE void __TZ_set_PRIMASK_NS(uint32_t priMask) \details Enables FIQ interrupts by clearing special-purpose register FAULTMASK. Can only be executed in Privileged modes. */ -__STATIC_FORCEINLINE void __enable_fault_irq(void) -{ - __ASM volatile ("cpsie f" : : : "memory"); +__STATIC_FORCEINLINE void __enable_fault_irq(void) { + __ASM volatile("cpsie f" : : : "memory"); } @@ -1061,9 +1010,8 @@ __STATIC_FORCEINLINE void __enable_fault_irq(void) \details Disables FIQ interrupts by setting special-purpose register FAULTMASK. Can only be executed in Privileged modes. */ -__STATIC_FORCEINLINE void __disable_fault_irq(void) -{ - __ASM volatile ("cpsid f" : : : "memory"); +__STATIC_FORCEINLINE void __disable_fault_irq(void) { + __ASM volatile("cpsid f" : : : "memory"); } @@ -1072,12 +1020,11 @@ __STATIC_FORCEINLINE void __disable_fault_irq(void) \details Returns the current value of the Base Priority register. \return Base Priority register value */ -__STATIC_FORCEINLINE uint32_t __get_BASEPRI(void) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __get_BASEPRI(void) { + uint32_t result; - __ASM volatile ("MRS %0, basepri" : "=r" (result) ); - return(result); + __ASM volatile("MRS %0, basepri" : "=r"(result)); + return (result); } @@ -1087,12 +1034,11 @@ __STATIC_FORCEINLINE uint32_t __get_BASEPRI(void) \details Returns the current value of the non-secure Base Priority register when in secure state. \return Base Priority register value */ -__STATIC_FORCEINLINE uint32_t __TZ_get_BASEPRI_NS(void) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __TZ_get_BASEPRI_NS(void) { + uint32_t result; - __ASM volatile ("MRS %0, basepri_ns" : "=r" (result) ); - return(result); + __ASM volatile("MRS %0, basepri_ns" : "=r"(result)); + return (result); } #endif @@ -1102,9 +1048,8 @@ __STATIC_FORCEINLINE uint32_t __TZ_get_BASEPRI_NS(void) \details Assigns the given value to the Base Priority register. \param [in] basePri Base Priority value to set */ -__STATIC_FORCEINLINE void __set_BASEPRI(uint32_t basePri) -{ - __ASM volatile ("MSR basepri, %0" : : "r" (basePri) : "memory"); +__STATIC_FORCEINLINE void __set_BASEPRI(uint32_t basePri) { + __ASM volatile("MSR basepri, %0" : : "r"(basePri) : "memory"); } @@ -1114,9 +1059,8 @@ __STATIC_FORCEINLINE void __set_BASEPRI(uint32_t basePri) \details Assigns the given value to the non-secure Base Priority register when in secure state. \param [in] basePri Base Priority value to set */ -__STATIC_FORCEINLINE void __TZ_set_BASEPRI_NS(uint32_t basePri) -{ - __ASM volatile ("MSR basepri_ns, %0" : : "r" (basePri) : "memory"); +__STATIC_FORCEINLINE void __TZ_set_BASEPRI_NS(uint32_t basePri) { + __ASM volatile("MSR basepri_ns, %0" : : "r"(basePri) : "memory"); } #endif @@ -1127,9 +1071,8 @@ __STATIC_FORCEINLINE void __TZ_set_BASEPRI_NS(uint32_t basePri) or the new value increases the BASEPRI priority level. \param [in] basePri Base Priority value to set */ -__STATIC_FORCEINLINE void __set_BASEPRI_MAX(uint32_t basePri) -{ - __ASM volatile ("MSR basepri_max, %0" : : "r" (basePri) : "memory"); +__STATIC_FORCEINLINE void __set_BASEPRI_MAX(uint32_t basePri) { + __ASM volatile("MSR basepri_max, %0" : : "r"(basePri) : "memory"); } @@ -1138,12 +1081,11 @@ __STATIC_FORCEINLINE void __set_BASEPRI_MAX(uint32_t basePri) \details Returns the current value of the Fault Mask register. \return Fault Mask register value */ -__STATIC_FORCEINLINE uint32_t __get_FAULTMASK(void) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __get_FAULTMASK(void) { + uint32_t result; - __ASM volatile ("MRS %0, faultmask" : "=r" (result) ); - return(result); + __ASM volatile("MRS %0, faultmask" : "=r"(result)); + return (result); } @@ -1153,12 +1095,11 @@ __STATIC_FORCEINLINE uint32_t __get_FAULTMASK(void) \details Returns the current value of the non-secure Fault Mask register when in secure state. \return Fault Mask register value */ -__STATIC_FORCEINLINE uint32_t __TZ_get_FAULTMASK_NS(void) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __TZ_get_FAULTMASK_NS(void) { + uint32_t result; - __ASM volatile ("MRS %0, faultmask_ns" : "=r" (result) ); - return(result); + __ASM volatile("MRS %0, faultmask_ns" : "=r"(result)); + return (result); } #endif @@ -1168,9 +1109,8 @@ __STATIC_FORCEINLINE uint32_t __TZ_get_FAULTMASK_NS(void) \details Assigns the given value to the Fault Mask register. \param [in] faultMask Fault Mask value to set */ -__STATIC_FORCEINLINE void __set_FAULTMASK(uint32_t faultMask) -{ - __ASM volatile ("MSR faultmask, %0" : : "r" (faultMask) : "memory"); +__STATIC_FORCEINLINE void __set_FAULTMASK(uint32_t faultMask) { + __ASM volatile("MSR faultmask, %0" : : "r"(faultMask) : "memory"); } @@ -1180,9 +1120,8 @@ __STATIC_FORCEINLINE void __set_FAULTMASK(uint32_t faultMask) \details Assigns the given value to the non-secure Fault Mask register when in secure state. \param [in] faultMask Fault Mask value to set */ -__STATIC_FORCEINLINE void __TZ_set_FAULTMASK_NS(uint32_t faultMask) -{ - __ASM volatile ("MSR faultmask_ns, %0" : : "r" (faultMask) : "memory"); +__STATIC_FORCEINLINE void __TZ_set_FAULTMASK_NS(uint32_t faultMask) { + __ASM volatile("MSR faultmask_ns, %0" : : "r"(faultMask) : "memory"); } #endif @@ -1205,17 +1144,16 @@ __STATIC_FORCEINLINE void __TZ_set_FAULTMASK_NS(uint32_t faultMask) \details Returns the current value of the Process Stack Pointer Limit (PSPLIM). \return PSPLIM Register value */ -__STATIC_FORCEINLINE uint32_t __get_PSPLIM(void) -{ +__STATIC_FORCEINLINE uint32_t __get_PSPLIM(void) { #if (!((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ (defined (__ARM_ARCH_8_1M_MAIN__ ) && (__ARM_ARCH_8_1M_MAIN__ == 1)) ) && \ (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))) // without main extensions, the non-secure PSPLIM is RAZ/WI - return 0U; + return 0U; #else - uint32_t result; - __ASM volatile ("MRS %0, psplim" : "=r" (result) ); - return result; + uint32_t result; + __ASM volatile("MRS %0, psplim" : "=r"(result)); + return result; #endif } @@ -1229,16 +1167,15 @@ __STATIC_FORCEINLINE uint32_t __get_PSPLIM(void) \details Returns the current value of the non-secure Process Stack Pointer Limit (PSPLIM) when in secure state. \return PSPLIM Register value */ -__STATIC_FORCEINLINE uint32_t __TZ_get_PSPLIM_NS(void) -{ +__STATIC_FORCEINLINE uint32_t __TZ_get_PSPLIM_NS(void) { #if (!((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ (defined (__ARM_ARCH_8_1M_MAIN__ ) && (__ARM_ARCH_8_1M_MAIN__ == 1)) ) ) - // without main extensions, the non-secure PSPLIM is RAZ/WI - return 0U; + // without main extensions, the non-secure PSPLIM is RAZ/WI + return 0U; #else - uint32_t result; - __ASM volatile ("MRS %0, psplim_ns" : "=r" (result) ); - return result; + uint32_t result; + __ASM volatile("MRS %0, psplim_ns" : "=r"(result)); + return result; #endif } #endif @@ -1253,15 +1190,14 @@ __STATIC_FORCEINLINE uint32_t __TZ_get_PSPLIM_NS(void) \details Assigns the given value to the Process Stack Pointer Limit (PSPLIM). \param [in] ProcStackPtrLimit Process Stack Pointer Limit value to set */ -__STATIC_FORCEINLINE void __set_PSPLIM(uint32_t ProcStackPtrLimit) -{ +__STATIC_FORCEINLINE void __set_PSPLIM(uint32_t ProcStackPtrLimit) { #if (!((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ (defined (__ARM_ARCH_8_1M_MAIN__ ) && (__ARM_ARCH_8_1M_MAIN__ == 1)) ) && \ (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))) - // without main extensions, the non-secure PSPLIM is RAZ/WI - (void)ProcStackPtrLimit; + // without main extensions, the non-secure PSPLIM is RAZ/WI + (void)ProcStackPtrLimit; #else - __ASM volatile ("MSR psplim, %0" : : "r" (ProcStackPtrLimit)); + __ASM volatile("MSR psplim, %0" : : "r"(ProcStackPtrLimit)); #endif } @@ -1276,14 +1212,13 @@ __STATIC_FORCEINLINE void __set_PSPLIM(uint32_t ProcStackPtrLimit) \details Assigns the given value to the non-secure Process Stack Pointer Limit (PSPLIM) when in secure state. \param [in] ProcStackPtrLimit Process Stack Pointer Limit value to set */ -__STATIC_FORCEINLINE void __TZ_set_PSPLIM_NS(uint32_t ProcStackPtrLimit) -{ +__STATIC_FORCEINLINE void __TZ_set_PSPLIM_NS(uint32_t ProcStackPtrLimit) { #if (!((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ (defined (__ARM_ARCH_8_1M_MAIN__ ) && (__ARM_ARCH_8_1M_MAIN__ == 1)) ) ) - // without main extensions, the non-secure PSPLIM is RAZ/WI - (void)ProcStackPtrLimit; + // without main extensions, the non-secure PSPLIM is RAZ/WI + (void)ProcStackPtrLimit; #else - __ASM volatile ("MSR psplim_ns, %0\n" : : "r" (ProcStackPtrLimit)); + __ASM volatile("MSR psplim_ns, %0\n" : : "r"(ProcStackPtrLimit)); #endif } #endif @@ -1297,17 +1232,16 @@ __STATIC_FORCEINLINE void __TZ_set_PSPLIM_NS(uint32_t ProcStackPtrLimit) \details Returns the current value of the Main Stack Pointer Limit (MSPLIM). \return MSPLIM Register value */ -__STATIC_FORCEINLINE uint32_t __get_MSPLIM(void) -{ +__STATIC_FORCEINLINE uint32_t __get_MSPLIM(void) { #if (!((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ (defined (__ARM_ARCH_8_1M_MAIN__ ) && (__ARM_ARCH_8_1M_MAIN__ == 1)) ) && \ (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))) - // without main extensions, the non-secure MSPLIM is RAZ/WI - return 0U; + // without main extensions, the non-secure MSPLIM is RAZ/WI + return 0U; #else - uint32_t result; - __ASM volatile ("MRS %0, msplim" : "=r" (result) ); - return result; + uint32_t result; + __ASM volatile("MRS %0, msplim" : "=r"(result)); + return result; #endif } @@ -1321,16 +1255,15 @@ __STATIC_FORCEINLINE uint32_t __get_MSPLIM(void) \details Returns the current value of the non-secure Main Stack Pointer Limit(MSPLIM) when in secure state. \return MSPLIM Register value */ -__STATIC_FORCEINLINE uint32_t __TZ_get_MSPLIM_NS(void) -{ +__STATIC_FORCEINLINE uint32_t __TZ_get_MSPLIM_NS(void) { #if (!((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ (defined (__ARM_ARCH_8_1M_MAIN__ ) && (__ARM_ARCH_8_1M_MAIN__ == 1)) ) ) - // without main extensions, the non-secure MSPLIM is RAZ/WI - return 0U; + // without main extensions, the non-secure MSPLIM is RAZ/WI + return 0U; #else - uint32_t result; - __ASM volatile ("MRS %0, msplim_ns" : "=r" (result) ); - return result; + uint32_t result; + __ASM volatile("MRS %0, msplim_ns" : "=r"(result)); + return result; #endif } #endif @@ -1344,15 +1277,14 @@ __STATIC_FORCEINLINE uint32_t __TZ_get_MSPLIM_NS(void) \details Assigns the given value to the Main Stack Pointer Limit (MSPLIM). \param [in] MainStackPtrLimit Main Stack Pointer Limit value to set */ -__STATIC_FORCEINLINE void __set_MSPLIM(uint32_t MainStackPtrLimit) -{ +__STATIC_FORCEINLINE void __set_MSPLIM(uint32_t MainStackPtrLimit) { #if (!((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ (defined (__ARM_ARCH_8_1M_MAIN__ ) && (__ARM_ARCH_8_1M_MAIN__ == 1)) ) && \ (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))) - // without main extensions, the non-secure MSPLIM is RAZ/WI - (void)MainStackPtrLimit; + // without main extensions, the non-secure MSPLIM is RAZ/WI + (void)MainStackPtrLimit; #else - __ASM volatile ("MSR msplim, %0" : : "r" (MainStackPtrLimit)); + __ASM volatile("MSR msplim, %0" : : "r"(MainStackPtrLimit)); #endif } @@ -1366,14 +1298,13 @@ __STATIC_FORCEINLINE void __set_MSPLIM(uint32_t MainStackPtrLimit) \details Assigns the given value to the non-secure Main Stack Pointer Limit (MSPLIM) when in secure state. \param [in] MainStackPtrLimit Main Stack Pointer value to set */ -__STATIC_FORCEINLINE void __TZ_set_MSPLIM_NS(uint32_t MainStackPtrLimit) -{ +__STATIC_FORCEINLINE void __TZ_set_MSPLIM_NS(uint32_t MainStackPtrLimit) { #if (!((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ (defined (__ARM_ARCH_8_1M_MAIN__ ) && (__ARM_ARCH_8_1M_MAIN__ == 1)) ) ) - // without main extensions, the non-secure MSPLIM is RAZ/WI - (void)MainStackPtrLimit; + // without main extensions, the non-secure MSPLIM is RAZ/WI + (void)MainStackPtrLimit; #else - __ASM volatile ("MSR msplim_ns, %0" : : "r" (MainStackPtrLimit)); + __ASM volatile("MSR msplim_ns, %0" : : "r"(MainStackPtrLimit)); #endif } #endif @@ -1488,12 +1419,11 @@ __STATIC_FORCEINLINE void __TZ_set_MSPLIM_NS(uint32_t MainStackPtrLimit) #define __SXTAB16_RORn(ARG1, ARG2, ARG3) __SXTAB16(ARG1, __ROR(ARG2, ARG3)) -__STATIC_FORCEINLINE int32_t __SMMLA (int32_t op1, int32_t op2, int32_t op3) -{ - int32_t result; +__STATIC_FORCEINLINE int32_t __SMMLA(int32_t op1, int32_t op2, int32_t op3) { + int32_t result; - __ASM volatile ("smmla %0, %1, %2, %3" : "=r" (result): "r" (op1), "r" (op2), "r" (op3) ); - return(result); + __ASM volatile("smmla %0, %1, %2, %3" : "=r"(result): "r"(op1), "r"(op2), "r"(op3)); + return (result); } #endif /* (__ARM_FEATURE_DSP == 1) */ diff --git a/armlib/at32_sys/cmsis/cm4/core_support/cmsis_armclang_ltm.h b/armlib/at32_sys/cmsis/cm4/core_support/cmsis_armclang_ltm.h index 1e255d590..e6aa56dab 100644 --- a/armlib/at32_sys/cmsis/cm4/core_support/cmsis_armclang_ltm.h +++ b/armlib/at32_sys/cmsis/cm4/core_support/cmsis_armclang_ltm.h @@ -31,83 +31,83 @@ /* CMSIS compiler specific defines */ #ifndef __ASM - #define __ASM __asm +#define __ASM __asm #endif #ifndef __INLINE - #define __INLINE __inline +#define __INLINE __inline #endif #ifndef __STATIC_INLINE - #define __STATIC_INLINE static __inline +#define __STATIC_INLINE static __inline #endif #ifndef __STATIC_FORCEINLINE - #define __STATIC_FORCEINLINE __attribute__((always_inline)) static __inline +#define __STATIC_FORCEINLINE __attribute__((always_inline)) static __inline #endif #ifndef __NO_RETURN - #define __NO_RETURN __attribute__((__noreturn__)) +#define __NO_RETURN __attribute__((__noreturn__)) #endif #ifndef __USED - #define __USED __attribute__((used)) +#define __USED __attribute__((used)) #endif #ifndef __WEAK - #define __WEAK __attribute__((weak)) +#define __WEAK __attribute__((weak)) #endif #ifndef __PACKED - #define __PACKED __attribute__((packed, aligned(1))) +#define __PACKED __attribute__((packed, aligned(1))) #endif #ifndef __PACKED_STRUCT - #define __PACKED_STRUCT struct __attribute__((packed, aligned(1))) +#define __PACKED_STRUCT struct __attribute__((packed, aligned(1))) #endif #ifndef __PACKED_UNION - #define __PACKED_UNION union __attribute__((packed, aligned(1))) +#define __PACKED_UNION union __attribute__((packed, aligned(1))) #endif #ifndef __UNALIGNED_UINT32 /* deprecated */ - #pragma clang diagnostic push - #pragma clang diagnostic ignored "-Wpacked" +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wpacked" /*lint -esym(9058, T_UINT32)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT32 */ - struct __attribute__((packed)) T_UINT32 { uint32_t v; }; - #pragma clang diagnostic pop - #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v) +struct __attribute__((packed)) T_UINT32 { uint32_t v; }; +#pragma clang diagnostic pop +#define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v) #endif #ifndef __UNALIGNED_UINT16_WRITE - #pragma clang diagnostic push - #pragma clang diagnostic ignored "-Wpacked" +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wpacked" /*lint -esym(9058, T_UINT16_WRITE)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT16_WRITE */ - __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; }; - #pragma clang diagnostic pop - #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val)) +__PACKED_STRUCT T_UINT16_WRITE { uint16_t v; }; +#pragma clang diagnostic pop +#define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val)) #endif #ifndef __UNALIGNED_UINT16_READ - #pragma clang diagnostic push - #pragma clang diagnostic ignored "-Wpacked" +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wpacked" /*lint -esym(9058, T_UINT16_READ)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT16_READ */ - __PACKED_STRUCT T_UINT16_READ { uint16_t v; }; - #pragma clang diagnostic pop - #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v) +__PACKED_STRUCT T_UINT16_READ { uint16_t v; }; +#pragma clang diagnostic pop +#define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v) #endif #ifndef __UNALIGNED_UINT32_WRITE - #pragma clang diagnostic push - #pragma clang diagnostic ignored "-Wpacked" +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wpacked" /*lint -esym(9058, T_UINT32_WRITE)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT32_WRITE */ - __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; }; - #pragma clang diagnostic pop - #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val)) +__PACKED_STRUCT T_UINT32_WRITE { uint32_t v; }; +#pragma clang diagnostic pop +#define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val)) #endif #ifndef __UNALIGNED_UINT32_READ - #pragma clang diagnostic push - #pragma clang diagnostic ignored "-Wpacked" +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wpacked" /*lint -esym(9058, T_UINT32_READ)*/ /* disable MISRA 2012 Rule 2.4 for T_UINT32_READ */ - __PACKED_STRUCT T_UINT32_READ { uint32_t v; }; - #pragma clang diagnostic pop - #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v) +__PACKED_STRUCT T_UINT32_READ { uint32_t v; }; +#pragma clang diagnostic pop +#define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v) #endif #ifndef __ALIGNED - #define __ALIGNED(x) __attribute__((aligned(x))) +#define __ALIGNED(x) __attribute__((aligned(x))) #endif #ifndef __RESTRICT - #define __RESTRICT __restrict +#define __RESTRICT __restrict #endif #ifndef __COMPILER_BARRIER - #define __COMPILER_BARRIER() __ASM volatile("":::"memory") +#define __COMPILER_BARRIER() __ASM volatile("":::"memory") #endif /* ######################### Startup and Lowlevel Init ######################## */ @@ -146,8 +146,8 @@ #endif -__STATIC_FORCEINLINE void __TZ_set_STACKSEAL_S (uint32_t* stackTop) { - *((uint64_t *)stackTop) = __TZ_STACK_SEAL_VALUE; +__STATIC_FORCEINLINE void __TZ_set_STACKSEAL_S(uint32_t *stackTop) { + *((uint64_t *)stackTop) = __TZ_STACK_SEAL_VALUE; } #endif @@ -255,14 +255,12 @@ __STATIC_FORCEINLINE void __TZ_set_STACKSEAL_S (uint32_t* stackTop) { \param [in] op2 Number of Bits to rotate \return Rotated value */ -__STATIC_FORCEINLINE uint32_t __ROR(uint32_t op1, uint32_t op2) -{ - op2 %= 32U; - if (op2 == 0U) - { - return op1; - } - return (op1 >> op2) | (op1 << (32U - op2)); +__STATIC_FORCEINLINE uint32_t __ROR(uint32_t op1, uint32_t op2) { + op2 %= 32U; + if (op2 == 0U) { + return op1; + } + return (op1 >> op2) | (op1 << (32U - op2)); } @@ -290,22 +288,20 @@ __STATIC_FORCEINLINE uint32_t __ROR(uint32_t op1, uint32_t op2) \param [in] value Value to count the leading zeros \return number of leading zeros in value */ -__STATIC_FORCEINLINE uint8_t __CLZ(uint32_t value) -{ - /* Even though __builtin_clz produces a CLZ instruction on ARM, formally - __builtin_clz(0) is undefined behaviour, so handle this case specially. - This guarantees ARM-compatible results if happening to compile on a non-ARM - target, and ensures the compiler doesn't decide to activate any - optimisations using the logic "value was passed to __builtin_clz, so it - is non-zero". - ARM Compiler 6.10 and possibly earlier will optimise this test away, leaving a - single CLZ instruction. - */ - if (value == 0U) - { - return 32U; - } - return __builtin_clz(value); +__STATIC_FORCEINLINE uint8_t __CLZ(uint32_t value) { + /* Even though __builtin_clz produces a CLZ instruction on ARM, formally + __builtin_clz(0) is undefined behaviour, so handle this case specially. + This guarantees ARM-compatible results if happening to compile on a non-ARM + target, and ensures the compiler doesn't decide to activate any + optimisations using the logic "value was passed to __builtin_clz, so it + is non-zero". + ARM Compiler 6.10 and possibly earlier will optimise this test away, leaving a + single CLZ instruction. + */ + if (value == 0U) { + return 32U; + } + return __builtin_clz(value); } @@ -416,12 +412,11 @@ __STATIC_FORCEINLINE uint8_t __CLZ(uint32_t value) \param [in] value Value to rotate \return Rotated value */ -__STATIC_FORCEINLINE uint32_t __RRX(uint32_t value) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __RRX(uint32_t value) { + uint32_t result; - __ASM volatile ("rrx %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) ); - return(result); + __ASM volatile("rrx %0, %1" : __CMSIS_GCC_OUT_REG(result) : __CMSIS_GCC_USE_REG(value)); + return (result); } @@ -431,12 +426,11 @@ __STATIC_FORCEINLINE uint32_t __RRX(uint32_t value) \param [in] ptr Pointer to data \return value of type uint8_t at (*ptr) */ -__STATIC_FORCEINLINE uint8_t __LDRBT(volatile uint8_t *ptr) -{ - uint32_t result; +__STATIC_FORCEINLINE uint8_t __LDRBT(volatile uint8_t *ptr) { + uint32_t result; - __ASM volatile ("ldrbt %0, %1" : "=r" (result) : "Q" (*ptr) ); - return ((uint8_t) result); /* Add explicit type cast here */ + __ASM volatile("ldrbt %0, %1" : "=r"(result) : "Q"(*ptr)); + return ((uint8_t) result); /* Add explicit type cast here */ } @@ -446,12 +440,11 @@ __STATIC_FORCEINLINE uint8_t __LDRBT(volatile uint8_t *ptr) \param [in] ptr Pointer to data \return value of type uint16_t at (*ptr) */ -__STATIC_FORCEINLINE uint16_t __LDRHT(volatile uint16_t *ptr) -{ - uint32_t result; +__STATIC_FORCEINLINE uint16_t __LDRHT(volatile uint16_t *ptr) { + uint32_t result; - __ASM volatile ("ldrht %0, %1" : "=r" (result) : "Q" (*ptr) ); - return ((uint16_t) result); /* Add explicit type cast here */ + __ASM volatile("ldrht %0, %1" : "=r"(result) : "Q"(*ptr)); + return ((uint16_t) result); /* Add explicit type cast here */ } @@ -461,12 +454,11 @@ __STATIC_FORCEINLINE uint16_t __LDRHT(volatile uint16_t *ptr) \param [in] ptr Pointer to data \return value of type uint32_t at (*ptr) */ -__STATIC_FORCEINLINE uint32_t __LDRT(volatile uint32_t *ptr) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __LDRT(volatile uint32_t *ptr) { + uint32_t result; - __ASM volatile ("ldrt %0, %1" : "=r" (result) : "Q" (*ptr) ); - return(result); + __ASM volatile("ldrt %0, %1" : "=r"(result) : "Q"(*ptr)); + return (result); } @@ -476,9 +468,8 @@ __STATIC_FORCEINLINE uint32_t __LDRT(volatile uint32_t *ptr) \param [in] value Value to store \param [in] ptr Pointer to location */ -__STATIC_FORCEINLINE void __STRBT(uint8_t value, volatile uint8_t *ptr) -{ - __ASM volatile ("strbt %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) ); +__STATIC_FORCEINLINE void __STRBT(uint8_t value, volatile uint8_t *ptr) { + __ASM volatile("strbt %1, %0" : "=Q"(*ptr) : "r"((uint32_t)value)); } @@ -488,9 +479,8 @@ __STATIC_FORCEINLINE void __STRBT(uint8_t value, volatile uint8_t *ptr) \param [in] value Value to store \param [in] ptr Pointer to location */ -__STATIC_FORCEINLINE void __STRHT(uint16_t value, volatile uint16_t *ptr) -{ - __ASM volatile ("strht %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) ); +__STATIC_FORCEINLINE void __STRHT(uint16_t value, volatile uint16_t *ptr) { + __ASM volatile("strht %1, %0" : "=Q"(*ptr) : "r"((uint32_t)value)); } @@ -500,9 +490,8 @@ __STATIC_FORCEINLINE void __STRHT(uint16_t value, volatile uint16_t *ptr) \param [in] value Value to store \param [in] ptr Pointer to location */ -__STATIC_FORCEINLINE void __STRT(uint32_t value, volatile uint32_t *ptr) -{ - __ASM volatile ("strt %1, %0" : "=Q" (*ptr) : "r" (value) ); +__STATIC_FORCEINLINE void __STRT(uint32_t value, volatile uint32_t *ptr) { + __ASM volatile("strt %1, %0" : "=Q"(*ptr) : "r"(value)); } #else /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ @@ -516,22 +505,17 @@ __STATIC_FORCEINLINE void __STRT(uint32_t value, volatile uint32_t *ptr) \param [in] sat Bit position to saturate to (1..32) \return Saturated value */ -__STATIC_FORCEINLINE int32_t __SSAT(int32_t val, uint32_t sat) -{ - if ((sat >= 1U) && (sat <= 32U)) - { - const int32_t max = (int32_t)((1U << (sat - 1U)) - 1U); - const int32_t min = -1 - max ; - if (val > max) - { - return max; +__STATIC_FORCEINLINE int32_t __SSAT(int32_t val, uint32_t sat) { + if ((sat >= 1U) && (sat <= 32U)) { + const int32_t max = (int32_t)((1U << (sat - 1U)) - 1U); + const int32_t min = -1 - max ; + if (val > max) { + return max; + } else if (val < min) { + return min; + } } - else if (val < min) - { - return min; - } - } - return val; + return val; } /** @@ -541,21 +525,16 @@ __STATIC_FORCEINLINE int32_t __SSAT(int32_t val, uint32_t sat) \param [in] sat Bit position to saturate to (0..31) \return Saturated value */ -__STATIC_FORCEINLINE uint32_t __USAT(int32_t val, uint32_t sat) -{ - if (sat <= 31U) - { - const uint32_t max = ((1U << sat) - 1U); - if (val > (int32_t)max) - { - return max; +__STATIC_FORCEINLINE uint32_t __USAT(int32_t val, uint32_t sat) { + if (sat <= 31U) { + const uint32_t max = ((1U << sat) - 1U); + if (val > (int32_t)max) { + return max; + } else if (val < 0) { + return 0U; + } } - else if (val < 0) - { - return 0U; - } - } - return (uint32_t)val; + return (uint32_t)val; } #endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ @@ -571,12 +550,11 @@ __STATIC_FORCEINLINE uint32_t __USAT(int32_t val, uint32_t sat) \param [in] ptr Pointer to data \return value of type uint8_t at (*ptr) */ -__STATIC_FORCEINLINE uint8_t __LDAB(volatile uint8_t *ptr) -{ - uint32_t result; +__STATIC_FORCEINLINE uint8_t __LDAB(volatile uint8_t *ptr) { + uint32_t result; - __ASM volatile ("ldab %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" ); - return ((uint8_t) result); + __ASM volatile("ldab %0, %1" : "=r"(result) : "Q"(*ptr) : "memory"); + return ((uint8_t) result); } @@ -586,12 +564,11 @@ __STATIC_FORCEINLINE uint8_t __LDAB(volatile uint8_t *ptr) \param [in] ptr Pointer to data \return value of type uint16_t at (*ptr) */ -__STATIC_FORCEINLINE uint16_t __LDAH(volatile uint16_t *ptr) -{ - uint32_t result; +__STATIC_FORCEINLINE uint16_t __LDAH(volatile uint16_t *ptr) { + uint32_t result; - __ASM volatile ("ldah %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" ); - return ((uint16_t) result); + __ASM volatile("ldah %0, %1" : "=r"(result) : "Q"(*ptr) : "memory"); + return ((uint16_t) result); } @@ -601,12 +578,11 @@ __STATIC_FORCEINLINE uint16_t __LDAH(volatile uint16_t *ptr) \param [in] ptr Pointer to data \return value of type uint32_t at (*ptr) */ -__STATIC_FORCEINLINE uint32_t __LDA(volatile uint32_t *ptr) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __LDA(volatile uint32_t *ptr) { + uint32_t result; - __ASM volatile ("lda %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" ); - return(result); + __ASM volatile("lda %0, %1" : "=r"(result) : "Q"(*ptr) : "memory"); + return (result); } @@ -616,9 +592,8 @@ __STATIC_FORCEINLINE uint32_t __LDA(volatile uint32_t *ptr) \param [in] value Value to store \param [in] ptr Pointer to location */ -__STATIC_FORCEINLINE void __STLB(uint8_t value, volatile uint8_t *ptr) -{ - __ASM volatile ("stlb %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" ); +__STATIC_FORCEINLINE void __STLB(uint8_t value, volatile uint8_t *ptr) { + __ASM volatile("stlb %1, %0" : "=Q"(*ptr) : "r"((uint32_t)value) : "memory"); } @@ -628,9 +603,8 @@ __STATIC_FORCEINLINE void __STLB(uint8_t value, volatile uint8_t *ptr) \param [in] value Value to store \param [in] ptr Pointer to location */ -__STATIC_FORCEINLINE void __STLH(uint16_t value, volatile uint16_t *ptr) -{ - __ASM volatile ("stlh %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" ); +__STATIC_FORCEINLINE void __STLH(uint16_t value, volatile uint16_t *ptr) { + __ASM volatile("stlh %1, %0" : "=Q"(*ptr) : "r"((uint32_t)value) : "memory"); } @@ -640,9 +614,8 @@ __STATIC_FORCEINLINE void __STLH(uint16_t value, volatile uint16_t *ptr) \param [in] value Value to store \param [in] ptr Pointer to location */ -__STATIC_FORCEINLINE void __STL(uint32_t value, volatile uint32_t *ptr) -{ - __ASM volatile ("stl %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" ); +__STATIC_FORCEINLINE void __STL(uint32_t value, volatile uint32_t *ptr) { + __ASM volatile("stl %1, %0" : "=Q"(*ptr) : "r"((uint32_t)value) : "memory"); } @@ -723,9 +696,8 @@ __STATIC_FORCEINLINE void __STL(uint32_t value, volatile uint32_t *ptr) Can only be executed in Privileged modes. */ #ifndef __ARM_COMPAT_H -__STATIC_FORCEINLINE void __enable_irq(void) -{ - __ASM volatile ("cpsie i" : : : "memory"); +__STATIC_FORCEINLINE void __enable_irq(void) { + __ASM volatile("cpsie i" : : : "memory"); } #endif @@ -736,9 +708,8 @@ __STATIC_FORCEINLINE void __enable_irq(void) Can only be executed in Privileged modes. */ #ifndef __ARM_COMPAT_H -__STATIC_FORCEINLINE void __disable_irq(void) -{ - __ASM volatile ("cpsid i" : : : "memory"); +__STATIC_FORCEINLINE void __disable_irq(void) { + __ASM volatile("cpsid i" : : : "memory"); } #endif @@ -748,12 +719,11 @@ __STATIC_FORCEINLINE void __disable_irq(void) \details Returns the content of the Control Register. \return Control Register value */ -__STATIC_FORCEINLINE uint32_t __get_CONTROL(void) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __get_CONTROL(void) { + uint32_t result; - __ASM volatile ("MRS %0, control" : "=r" (result) ); - return(result); + __ASM volatile("MRS %0, control" : "=r"(result)); + return (result); } @@ -763,12 +733,11 @@ __STATIC_FORCEINLINE uint32_t __get_CONTROL(void) \details Returns the content of the non-secure Control Register when in secure mode. \return non-secure Control Register value */ -__STATIC_FORCEINLINE uint32_t __TZ_get_CONTROL_NS(void) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __TZ_get_CONTROL_NS(void) { + uint32_t result; - __ASM volatile ("MRS %0, control_ns" : "=r" (result) ); - return(result); + __ASM volatile("MRS %0, control_ns" : "=r"(result)); + return (result); } #endif @@ -778,10 +747,9 @@ __STATIC_FORCEINLINE uint32_t __TZ_get_CONTROL_NS(void) \details Writes the given value to the Control Register. \param [in] control Control Register value to set */ -__STATIC_FORCEINLINE void __set_CONTROL(uint32_t control) -{ - __ASM volatile ("MSR control, %0" : : "r" (control) : "memory"); - __ISB(); +__STATIC_FORCEINLINE void __set_CONTROL(uint32_t control) { + __ASM volatile("MSR control, %0" : : "r"(control) : "memory"); + __ISB(); } @@ -791,10 +759,9 @@ __STATIC_FORCEINLINE void __set_CONTROL(uint32_t control) \details Writes the given value to the non-secure Control Register when in secure state. \param [in] control Control Register value to set */ -__STATIC_FORCEINLINE void __TZ_set_CONTROL_NS(uint32_t control) -{ - __ASM volatile ("MSR control_ns, %0" : : "r" (control) : "memory"); - __ISB(); +__STATIC_FORCEINLINE void __TZ_set_CONTROL_NS(uint32_t control) { + __ASM volatile("MSR control_ns, %0" : : "r"(control) : "memory"); + __ISB(); } #endif @@ -804,12 +771,11 @@ __STATIC_FORCEINLINE void __TZ_set_CONTROL_NS(uint32_t control) \details Returns the content of the IPSR Register. \return IPSR Register value */ -__STATIC_FORCEINLINE uint32_t __get_IPSR(void) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __get_IPSR(void) { + uint32_t result; - __ASM volatile ("MRS %0, ipsr" : "=r" (result) ); - return(result); + __ASM volatile("MRS %0, ipsr" : "=r"(result)); + return (result); } @@ -818,12 +784,11 @@ __STATIC_FORCEINLINE uint32_t __get_IPSR(void) \details Returns the content of the APSR Register. \return APSR Register value */ -__STATIC_FORCEINLINE uint32_t __get_APSR(void) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __get_APSR(void) { + uint32_t result; - __ASM volatile ("MRS %0, apsr" : "=r" (result) ); - return(result); + __ASM volatile("MRS %0, apsr" : "=r"(result)); + return (result); } @@ -832,12 +797,11 @@ __STATIC_FORCEINLINE uint32_t __get_APSR(void) \details Returns the content of the xPSR Register. \return xPSR Register value */ -__STATIC_FORCEINLINE uint32_t __get_xPSR(void) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __get_xPSR(void) { + uint32_t result; - __ASM volatile ("MRS %0, xpsr" : "=r" (result) ); - return(result); + __ASM volatile("MRS %0, xpsr" : "=r"(result)); + return (result); } @@ -846,12 +810,11 @@ __STATIC_FORCEINLINE uint32_t __get_xPSR(void) \details Returns the current value of the Process Stack Pointer (PSP). \return PSP Register value */ -__STATIC_FORCEINLINE uint32_t __get_PSP(void) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __get_PSP(void) { + uint32_t result; - __ASM volatile ("MRS %0, psp" : "=r" (result) ); - return(result); + __ASM volatile("MRS %0, psp" : "=r"(result)); + return (result); } @@ -861,12 +824,11 @@ __STATIC_FORCEINLINE uint32_t __get_PSP(void) \details Returns the current value of the non-secure Process Stack Pointer (PSP) when in secure state. \return PSP Register value */ -__STATIC_FORCEINLINE uint32_t __TZ_get_PSP_NS(void) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __TZ_get_PSP_NS(void) { + uint32_t result; - __ASM volatile ("MRS %0, psp_ns" : "=r" (result) ); - return(result); + __ASM volatile("MRS %0, psp_ns" : "=r"(result)); + return (result); } #endif @@ -876,9 +838,8 @@ __STATIC_FORCEINLINE uint32_t __TZ_get_PSP_NS(void) \details Assigns the given value to the Process Stack Pointer (PSP). \param [in] topOfProcStack Process Stack Pointer value to set */ -__STATIC_FORCEINLINE void __set_PSP(uint32_t topOfProcStack) -{ - __ASM volatile ("MSR psp, %0" : : "r" (topOfProcStack) : ); +__STATIC_FORCEINLINE void __set_PSP(uint32_t topOfProcStack) { + __ASM volatile("MSR psp, %0" : : "r"(topOfProcStack) :); } @@ -888,9 +849,8 @@ __STATIC_FORCEINLINE void __set_PSP(uint32_t topOfProcStack) \details Assigns the given value to the non-secure Process Stack Pointer (PSP) when in secure state. \param [in] topOfProcStack Process Stack Pointer value to set */ -__STATIC_FORCEINLINE void __TZ_set_PSP_NS(uint32_t topOfProcStack) -{ - __ASM volatile ("MSR psp_ns, %0" : : "r" (topOfProcStack) : ); +__STATIC_FORCEINLINE void __TZ_set_PSP_NS(uint32_t topOfProcStack) { + __ASM volatile("MSR psp_ns, %0" : : "r"(topOfProcStack) :); } #endif @@ -900,12 +860,11 @@ __STATIC_FORCEINLINE void __TZ_set_PSP_NS(uint32_t topOfProcStack) \details Returns the current value of the Main Stack Pointer (MSP). \return MSP Register value */ -__STATIC_FORCEINLINE uint32_t __get_MSP(void) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __get_MSP(void) { + uint32_t result; - __ASM volatile ("MRS %0, msp" : "=r" (result) ); - return(result); + __ASM volatile("MRS %0, msp" : "=r"(result)); + return (result); } @@ -915,12 +874,11 @@ __STATIC_FORCEINLINE uint32_t __get_MSP(void) \details Returns the current value of the non-secure Main Stack Pointer (MSP) when in secure state. \return MSP Register value */ -__STATIC_FORCEINLINE uint32_t __TZ_get_MSP_NS(void) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __TZ_get_MSP_NS(void) { + uint32_t result; - __ASM volatile ("MRS %0, msp_ns" : "=r" (result) ); - return(result); + __ASM volatile("MRS %0, msp_ns" : "=r"(result)); + return (result); } #endif @@ -930,9 +888,8 @@ __STATIC_FORCEINLINE uint32_t __TZ_get_MSP_NS(void) \details Assigns the given value to the Main Stack Pointer (MSP). \param [in] topOfMainStack Main Stack Pointer value to set */ -__STATIC_FORCEINLINE void __set_MSP(uint32_t topOfMainStack) -{ - __ASM volatile ("MSR msp, %0" : : "r" (topOfMainStack) : ); +__STATIC_FORCEINLINE void __set_MSP(uint32_t topOfMainStack) { + __ASM volatile("MSR msp, %0" : : "r"(topOfMainStack) :); } @@ -942,9 +899,8 @@ __STATIC_FORCEINLINE void __set_MSP(uint32_t topOfMainStack) \details Assigns the given value to the non-secure Main Stack Pointer (MSP) when in secure state. \param [in] topOfMainStack Main Stack Pointer value to set */ -__STATIC_FORCEINLINE void __TZ_set_MSP_NS(uint32_t topOfMainStack) -{ - __ASM volatile ("MSR msp_ns, %0" : : "r" (topOfMainStack) : ); +__STATIC_FORCEINLINE void __TZ_set_MSP_NS(uint32_t topOfMainStack) { + __ASM volatile("MSR msp_ns, %0" : : "r"(topOfMainStack) :); } #endif @@ -955,12 +911,11 @@ __STATIC_FORCEINLINE void __TZ_set_MSP_NS(uint32_t topOfMainStack) \details Returns the current value of the non-secure Stack Pointer (SP) when in secure state. \return SP Register value */ -__STATIC_FORCEINLINE uint32_t __TZ_get_SP_NS(void) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __TZ_get_SP_NS(void) { + uint32_t result; - __ASM volatile ("MRS %0, sp_ns" : "=r" (result) ); - return(result); + __ASM volatile("MRS %0, sp_ns" : "=r"(result)); + return (result); } @@ -969,9 +924,8 @@ __STATIC_FORCEINLINE uint32_t __TZ_get_SP_NS(void) \details Assigns the given value to the non-secure Stack Pointer (SP) when in secure state. \param [in] topOfStack Stack Pointer value to set */ -__STATIC_FORCEINLINE void __TZ_set_SP_NS(uint32_t topOfStack) -{ - __ASM volatile ("MSR sp_ns, %0" : : "r" (topOfStack) : ); +__STATIC_FORCEINLINE void __TZ_set_SP_NS(uint32_t topOfStack) { + __ASM volatile("MSR sp_ns, %0" : : "r"(topOfStack) :); } #endif @@ -981,12 +935,11 @@ __STATIC_FORCEINLINE void __TZ_set_SP_NS(uint32_t topOfStack) \details Returns the current state of the priority mask bit from the Priority Mask Register. \return Priority Mask value */ -__STATIC_FORCEINLINE uint32_t __get_PRIMASK(void) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __get_PRIMASK(void) { + uint32_t result; - __ASM volatile ("MRS %0, primask" : "=r" (result) ); - return(result); + __ASM volatile("MRS %0, primask" : "=r"(result)); + return (result); } @@ -996,12 +949,11 @@ __STATIC_FORCEINLINE uint32_t __get_PRIMASK(void) \details Returns the current state of the non-secure priority mask bit from the Priority Mask Register when in secure state. \return Priority Mask value */ -__STATIC_FORCEINLINE uint32_t __TZ_get_PRIMASK_NS(void) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __TZ_get_PRIMASK_NS(void) { + uint32_t result; - __ASM volatile ("MRS %0, primask_ns" : "=r" (result) ); - return(result); + __ASM volatile("MRS %0, primask_ns" : "=r"(result)); + return (result); } #endif @@ -1011,9 +963,8 @@ __STATIC_FORCEINLINE uint32_t __TZ_get_PRIMASK_NS(void) \details Assigns the given value to the Priority Mask Register. \param [in] priMask Priority Mask */ -__STATIC_FORCEINLINE void __set_PRIMASK(uint32_t priMask) -{ - __ASM volatile ("MSR primask, %0" : : "r" (priMask) : "memory"); +__STATIC_FORCEINLINE void __set_PRIMASK(uint32_t priMask) { + __ASM volatile("MSR primask, %0" : : "r"(priMask) : "memory"); } @@ -1023,9 +974,8 @@ __STATIC_FORCEINLINE void __set_PRIMASK(uint32_t priMask) \details Assigns the given value to the non-secure Priority Mask Register when in secure state. \param [in] priMask Priority Mask */ -__STATIC_FORCEINLINE void __TZ_set_PRIMASK_NS(uint32_t priMask) -{ - __ASM volatile ("MSR primask_ns, %0" : : "r" (priMask) : "memory"); +__STATIC_FORCEINLINE void __TZ_set_PRIMASK_NS(uint32_t priMask) { + __ASM volatile("MSR primask_ns, %0" : : "r"(priMask) : "memory"); } #endif @@ -1038,9 +988,8 @@ __STATIC_FORCEINLINE void __TZ_set_PRIMASK_NS(uint32_t priMask) \details Enables FIQ interrupts by clearing special-purpose register FAULTMASK. Can only be executed in Privileged modes. */ -__STATIC_FORCEINLINE void __enable_fault_irq(void) -{ - __ASM volatile ("cpsie f" : : : "memory"); +__STATIC_FORCEINLINE void __enable_fault_irq(void) { + __ASM volatile("cpsie f" : : : "memory"); } @@ -1049,9 +998,8 @@ __STATIC_FORCEINLINE void __enable_fault_irq(void) \details Disables FIQ interrupts by setting special-purpose register FAULTMASK. Can only be executed in Privileged modes. */ -__STATIC_FORCEINLINE void __disable_fault_irq(void) -{ - __ASM volatile ("cpsid f" : : : "memory"); +__STATIC_FORCEINLINE void __disable_fault_irq(void) { + __ASM volatile("cpsid f" : : : "memory"); } @@ -1060,12 +1008,11 @@ __STATIC_FORCEINLINE void __disable_fault_irq(void) \details Returns the current value of the Base Priority register. \return Base Priority register value */ -__STATIC_FORCEINLINE uint32_t __get_BASEPRI(void) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __get_BASEPRI(void) { + uint32_t result; - __ASM volatile ("MRS %0, basepri" : "=r" (result) ); - return(result); + __ASM volatile("MRS %0, basepri" : "=r"(result)); + return (result); } @@ -1075,12 +1022,11 @@ __STATIC_FORCEINLINE uint32_t __get_BASEPRI(void) \details Returns the current value of the non-secure Base Priority register when in secure state. \return Base Priority register value */ -__STATIC_FORCEINLINE uint32_t __TZ_get_BASEPRI_NS(void) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __TZ_get_BASEPRI_NS(void) { + uint32_t result; - __ASM volatile ("MRS %0, basepri_ns" : "=r" (result) ); - return(result); + __ASM volatile("MRS %0, basepri_ns" : "=r"(result)); + return (result); } #endif @@ -1090,9 +1036,8 @@ __STATIC_FORCEINLINE uint32_t __TZ_get_BASEPRI_NS(void) \details Assigns the given value to the Base Priority register. \param [in] basePri Base Priority value to set */ -__STATIC_FORCEINLINE void __set_BASEPRI(uint32_t basePri) -{ - __ASM volatile ("MSR basepri, %0" : : "r" (basePri) : "memory"); +__STATIC_FORCEINLINE void __set_BASEPRI(uint32_t basePri) { + __ASM volatile("MSR basepri, %0" : : "r"(basePri) : "memory"); } @@ -1102,9 +1047,8 @@ __STATIC_FORCEINLINE void __set_BASEPRI(uint32_t basePri) \details Assigns the given value to the non-secure Base Priority register when in secure state. \param [in] basePri Base Priority value to set */ -__STATIC_FORCEINLINE void __TZ_set_BASEPRI_NS(uint32_t basePri) -{ - __ASM volatile ("MSR basepri_ns, %0" : : "r" (basePri) : "memory"); +__STATIC_FORCEINLINE void __TZ_set_BASEPRI_NS(uint32_t basePri) { + __ASM volatile("MSR basepri_ns, %0" : : "r"(basePri) : "memory"); } #endif @@ -1115,9 +1059,8 @@ __STATIC_FORCEINLINE void __TZ_set_BASEPRI_NS(uint32_t basePri) or the new value increases the BASEPRI priority level. \param [in] basePri Base Priority value to set */ -__STATIC_FORCEINLINE void __set_BASEPRI_MAX(uint32_t basePri) -{ - __ASM volatile ("MSR basepri_max, %0" : : "r" (basePri) : "memory"); +__STATIC_FORCEINLINE void __set_BASEPRI_MAX(uint32_t basePri) { + __ASM volatile("MSR basepri_max, %0" : : "r"(basePri) : "memory"); } @@ -1126,12 +1069,11 @@ __STATIC_FORCEINLINE void __set_BASEPRI_MAX(uint32_t basePri) \details Returns the current value of the Fault Mask register. \return Fault Mask register value */ -__STATIC_FORCEINLINE uint32_t __get_FAULTMASK(void) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __get_FAULTMASK(void) { + uint32_t result; - __ASM volatile ("MRS %0, faultmask" : "=r" (result) ); - return(result); + __ASM volatile("MRS %0, faultmask" : "=r"(result)); + return (result); } @@ -1141,12 +1083,11 @@ __STATIC_FORCEINLINE uint32_t __get_FAULTMASK(void) \details Returns the current value of the non-secure Fault Mask register when in secure state. \return Fault Mask register value */ -__STATIC_FORCEINLINE uint32_t __TZ_get_FAULTMASK_NS(void) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __TZ_get_FAULTMASK_NS(void) { + uint32_t result; - __ASM volatile ("MRS %0, faultmask_ns" : "=r" (result) ); - return(result); + __ASM volatile("MRS %0, faultmask_ns" : "=r"(result)); + return (result); } #endif @@ -1156,9 +1097,8 @@ __STATIC_FORCEINLINE uint32_t __TZ_get_FAULTMASK_NS(void) \details Assigns the given value to the Fault Mask register. \param [in] faultMask Fault Mask value to set */ -__STATIC_FORCEINLINE void __set_FAULTMASK(uint32_t faultMask) -{ - __ASM volatile ("MSR faultmask, %0" : : "r" (faultMask) : "memory"); +__STATIC_FORCEINLINE void __set_FAULTMASK(uint32_t faultMask) { + __ASM volatile("MSR faultmask, %0" : : "r"(faultMask) : "memory"); } @@ -1168,9 +1108,8 @@ __STATIC_FORCEINLINE void __set_FAULTMASK(uint32_t faultMask) \details Assigns the given value to the non-secure Fault Mask register when in secure state. \param [in] faultMask Fault Mask value to set */ -__STATIC_FORCEINLINE void __TZ_set_FAULTMASK_NS(uint32_t faultMask) -{ - __ASM volatile ("MSR faultmask_ns, %0" : : "r" (faultMask) : "memory"); +__STATIC_FORCEINLINE void __TZ_set_FAULTMASK_NS(uint32_t faultMask) { + __ASM volatile("MSR faultmask_ns, %0" : : "r"(faultMask) : "memory"); } #endif @@ -1191,16 +1130,15 @@ __STATIC_FORCEINLINE void __TZ_set_FAULTMASK_NS(uint32_t faultMask) \details Returns the current value of the Process Stack Pointer Limit (PSPLIM). \return PSPLIM Register value */ -__STATIC_FORCEINLINE uint32_t __get_PSPLIM(void) -{ +__STATIC_FORCEINLINE uint32_t __get_PSPLIM(void) { #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))) // without main extensions, the non-secure PSPLIM is RAZ/WI - return 0U; + return 0U; #else - uint32_t result; - __ASM volatile ("MRS %0, psplim" : "=r" (result) ); - return result; + uint32_t result; + __ASM volatile("MRS %0, psplim" : "=r"(result)); + return result; #endif } @@ -1214,15 +1152,14 @@ __STATIC_FORCEINLINE uint32_t __get_PSPLIM(void) \details Returns the current value of the non-secure Process Stack Pointer Limit (PSPLIM) when in secure state. \return PSPLIM Register value */ -__STATIC_FORCEINLINE uint32_t __TZ_get_PSPLIM_NS(void) -{ +__STATIC_FORCEINLINE uint32_t __TZ_get_PSPLIM_NS(void) { #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1))) - // without main extensions, the non-secure PSPLIM is RAZ/WI - return 0U; + // without main extensions, the non-secure PSPLIM is RAZ/WI + return 0U; #else - uint32_t result; - __ASM volatile ("MRS %0, psplim_ns" : "=r" (result) ); - return result; + uint32_t result; + __ASM volatile("MRS %0, psplim_ns" : "=r"(result)); + return result; #endif } #endif @@ -1237,14 +1174,13 @@ __STATIC_FORCEINLINE uint32_t __TZ_get_PSPLIM_NS(void) \details Assigns the given value to the Process Stack Pointer Limit (PSPLIM). \param [in] ProcStackPtrLimit Process Stack Pointer Limit value to set */ -__STATIC_FORCEINLINE void __set_PSPLIM(uint32_t ProcStackPtrLimit) -{ +__STATIC_FORCEINLINE void __set_PSPLIM(uint32_t ProcStackPtrLimit) { #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))) - // without main extensions, the non-secure PSPLIM is RAZ/WI - (void)ProcStackPtrLimit; + // without main extensions, the non-secure PSPLIM is RAZ/WI + (void)ProcStackPtrLimit; #else - __ASM volatile ("MSR psplim, %0" : : "r" (ProcStackPtrLimit)); + __ASM volatile("MSR psplim, %0" : : "r"(ProcStackPtrLimit)); #endif } @@ -1259,13 +1195,12 @@ __STATIC_FORCEINLINE void __set_PSPLIM(uint32_t ProcStackPtrLimit) \details Assigns the given value to the non-secure Process Stack Pointer Limit (PSPLIM) when in secure state. \param [in] ProcStackPtrLimit Process Stack Pointer Limit value to set */ -__STATIC_FORCEINLINE void __TZ_set_PSPLIM_NS(uint32_t ProcStackPtrLimit) -{ +__STATIC_FORCEINLINE void __TZ_set_PSPLIM_NS(uint32_t ProcStackPtrLimit) { #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1))) - // without main extensions, the non-secure PSPLIM is RAZ/WI - (void)ProcStackPtrLimit; + // without main extensions, the non-secure PSPLIM is RAZ/WI + (void)ProcStackPtrLimit; #else - __ASM volatile ("MSR psplim_ns, %0\n" : : "r" (ProcStackPtrLimit)); + __ASM volatile("MSR psplim_ns, %0\n" : : "r"(ProcStackPtrLimit)); #endif } #endif @@ -1279,16 +1214,15 @@ __STATIC_FORCEINLINE void __TZ_set_PSPLIM_NS(uint32_t ProcStackPtrLimit) \details Returns the current value of the Main Stack Pointer Limit (MSPLIM). \return MSPLIM Register value */ -__STATIC_FORCEINLINE uint32_t __get_MSPLIM(void) -{ +__STATIC_FORCEINLINE uint32_t __get_MSPLIM(void) { #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))) - // without main extensions, the non-secure MSPLIM is RAZ/WI - return 0U; + // without main extensions, the non-secure MSPLIM is RAZ/WI + return 0U; #else - uint32_t result; - __ASM volatile ("MRS %0, msplim" : "=r" (result) ); - return result; + uint32_t result; + __ASM volatile("MRS %0, msplim" : "=r"(result)); + return result; #endif } @@ -1302,15 +1236,14 @@ __STATIC_FORCEINLINE uint32_t __get_MSPLIM(void) \details Returns the current value of the non-secure Main Stack Pointer Limit(MSPLIM) when in secure state. \return MSPLIM Register value */ -__STATIC_FORCEINLINE uint32_t __TZ_get_MSPLIM_NS(void) -{ +__STATIC_FORCEINLINE uint32_t __TZ_get_MSPLIM_NS(void) { #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1))) - // without main extensions, the non-secure MSPLIM is RAZ/WI - return 0U; + // without main extensions, the non-secure MSPLIM is RAZ/WI + return 0U; #else - uint32_t result; - __ASM volatile ("MRS %0, msplim_ns" : "=r" (result) ); - return result; + uint32_t result; + __ASM volatile("MRS %0, msplim_ns" : "=r"(result)); + return result; #endif } #endif @@ -1324,14 +1257,13 @@ __STATIC_FORCEINLINE uint32_t __TZ_get_MSPLIM_NS(void) \details Assigns the given value to the Main Stack Pointer Limit (MSPLIM). \param [in] MainStackPtrLimit Main Stack Pointer Limit value to set */ -__STATIC_FORCEINLINE void __set_MSPLIM(uint32_t MainStackPtrLimit) -{ +__STATIC_FORCEINLINE void __set_MSPLIM(uint32_t MainStackPtrLimit) { #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))) - // without main extensions, the non-secure MSPLIM is RAZ/WI - (void)MainStackPtrLimit; + // without main extensions, the non-secure MSPLIM is RAZ/WI + (void)MainStackPtrLimit; #else - __ASM volatile ("MSR msplim, %0" : : "r" (MainStackPtrLimit)); + __ASM volatile("MSR msplim, %0" : : "r"(MainStackPtrLimit)); #endif } @@ -1345,13 +1277,12 @@ __STATIC_FORCEINLINE void __set_MSPLIM(uint32_t MainStackPtrLimit) \details Assigns the given value to the non-secure Main Stack Pointer Limit (MSPLIM) when in secure state. \param [in] MainStackPtrLimit Main Stack Pointer value to set */ -__STATIC_FORCEINLINE void __TZ_set_MSPLIM_NS(uint32_t MainStackPtrLimit) -{ +__STATIC_FORCEINLINE void __TZ_set_MSPLIM_NS(uint32_t MainStackPtrLimit) { #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1))) - // without main extensions, the non-secure MSPLIM is RAZ/WI - (void)MainStackPtrLimit; + // without main extensions, the non-secure MSPLIM is RAZ/WI + (void)MainStackPtrLimit; #else - __ASM volatile ("MSR msplim_ns, %0" : : "r" (MainStackPtrLimit)); + __ASM volatile("MSR msplim_ns, %0" : : "r"(MainStackPtrLimit)); #endif } #endif @@ -1395,310 +1326,272 @@ __STATIC_FORCEINLINE void __TZ_set_MSPLIM_NS(uint32_t MainStackPtrLimit) #if (defined (__ARM_FEATURE_DSP) && (__ARM_FEATURE_DSP == 1)) -__STATIC_FORCEINLINE uint32_t __SADD8(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __SADD8(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM volatile ("sadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM volatile("sadd8 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __QADD8(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __QADD8(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM volatile ("qadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM volatile("qadd8 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __SHADD8(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __SHADD8(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM volatile ("shadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM volatile("shadd8 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __UADD8(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __UADD8(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM volatile ("uadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM volatile("uadd8 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __UQADD8(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __UQADD8(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM volatile ("uqadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM volatile("uqadd8 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __UHADD8(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __UHADD8(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM volatile ("uhadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM volatile("uhadd8 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __SSUB8(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __SSUB8(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM volatile ("ssub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM volatile("ssub8 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __QSUB8(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __QSUB8(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM volatile ("qsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM volatile("qsub8 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __SHSUB8(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __SHSUB8(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM volatile ("shsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM volatile("shsub8 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __USUB8(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __USUB8(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM volatile ("usub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM volatile("usub8 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __UQSUB8(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __UQSUB8(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM volatile ("uqsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM volatile("uqsub8 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __UHSUB8(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __UHSUB8(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM volatile ("uhsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM volatile("uhsub8 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __SADD16(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __SADD16(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM volatile ("sadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM volatile("sadd16 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __QADD16(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __QADD16(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM volatile ("qadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM volatile("qadd16 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __SHADD16(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __SHADD16(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM volatile ("shadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM volatile("shadd16 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __UADD16(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __UADD16(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM volatile ("uadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM volatile("uadd16 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __UQADD16(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __UQADD16(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM volatile ("uqadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM volatile("uqadd16 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __UHADD16(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __UHADD16(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM volatile ("uhadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM volatile("uhadd16 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __SSUB16(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __SSUB16(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM volatile ("ssub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM volatile("ssub16 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __QSUB16(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __QSUB16(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM volatile ("qsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM volatile("qsub16 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __SHSUB16(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __SHSUB16(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM volatile ("shsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM volatile("shsub16 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __USUB16(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __USUB16(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM volatile ("usub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM volatile("usub16 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __UQSUB16(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __UQSUB16(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM volatile ("uqsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM volatile("uqsub16 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __UHSUB16(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __UHSUB16(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM volatile ("uhsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM volatile("uhsub16 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __SASX(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __SASX(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM volatile ("sasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM volatile("sasx %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __QASX(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __QASX(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM volatile ("qasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM volatile("qasx %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __SHASX(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __SHASX(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM volatile ("shasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM volatile("shasx %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __UASX(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __UASX(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM volatile ("uasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM volatile("uasx %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __UQASX(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __UQASX(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM volatile ("uqasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM volatile("uqasx %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __UHASX(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __UHASX(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM volatile ("uhasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM volatile("uhasx %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __SSAX(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __SSAX(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM volatile ("ssax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM volatile("ssax %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __QSAX(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __QSAX(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM volatile ("qsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM volatile("qsax %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __SHSAX(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __SHSAX(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM volatile ("shsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM volatile("shsax %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __USAX(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __USAX(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM volatile ("usax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM volatile("usax %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __UQSAX(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __UQSAX(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM volatile ("uqsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM volatile("uqsax %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __UHSAX(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __UHSAX(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM volatile ("uhsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM volatile("uhsax %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __USAD8(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __USAD8(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM volatile ("usad8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM volatile("usad8 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __USADA8(uint32_t op1, uint32_t op2, uint32_t op3) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __USADA8(uint32_t op1, uint32_t op2, uint32_t op3) { + uint32_t result; - __ASM volatile ("usada8 %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) ); - return(result); + __ASM volatile("usada8 %0, %1, %2, %3" : "=r"(result) : "r"(op1), "r"(op2), "r"(op3)); + return (result); } #define __SSAT16(ARG1,ARG2) \ @@ -1715,192 +1608,173 @@ __STATIC_FORCEINLINE uint32_t __USADA8(uint32_t op1, uint32_t op2, uint32_t op3) __RES; \ }) -__STATIC_FORCEINLINE uint32_t __UXTB16(uint32_t op1) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __UXTB16(uint32_t op1) { + uint32_t result; - __ASM volatile ("uxtb16 %0, %1" : "=r" (result) : "r" (op1)); - return(result); + __ASM volatile("uxtb16 %0, %1" : "=r"(result) : "r"(op1)); + return (result); } -__STATIC_FORCEINLINE uint32_t __UXTAB16(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __UXTAB16(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM volatile ("uxtab16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM volatile("uxtab16 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __SXTB16(uint32_t op1) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __SXTB16(uint32_t op1) { + uint32_t result; - __ASM volatile ("sxtb16 %0, %1" : "=r" (result) : "r" (op1)); - return(result); + __ASM volatile("sxtb16 %0, %1" : "=r"(result) : "r"(op1)); + return (result); } -__STATIC_FORCEINLINE uint32_t __SXTAB16(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __SXTAB16(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM volatile ("sxtab16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM volatile("sxtab16 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __SMUAD (uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __SMUAD(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM volatile ("smuad %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM volatile("smuad %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __SMUADX (uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __SMUADX(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM volatile ("smuadx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM volatile("smuadx %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __SMLAD (uint32_t op1, uint32_t op2, uint32_t op3) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __SMLAD(uint32_t op1, uint32_t op2, uint32_t op3) { + uint32_t result; - __ASM volatile ("smlad %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) ); - return(result); + __ASM volatile("smlad %0, %1, %2, %3" : "=r"(result) : "r"(op1), "r"(op2), "r"(op3)); + return (result); } -__STATIC_FORCEINLINE uint32_t __SMLADX (uint32_t op1, uint32_t op2, uint32_t op3) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __SMLADX(uint32_t op1, uint32_t op2, uint32_t op3) { + uint32_t result; - __ASM volatile ("smladx %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) ); - return(result); + __ASM volatile("smladx %0, %1, %2, %3" : "=r"(result) : "r"(op1), "r"(op2), "r"(op3)); + return (result); } -__STATIC_FORCEINLINE uint64_t __SMLALD (uint32_t op1, uint32_t op2, uint64_t acc) -{ - union llreg_u{ - uint32_t w32[2]; - uint64_t w64; - } llr; - llr.w64 = acc; +__STATIC_FORCEINLINE uint64_t __SMLALD(uint32_t op1, uint32_t op2, uint64_t acc) { + union llreg_u { + uint32_t w32[2]; + uint64_t w64; + } llr; + llr.w64 = acc; #ifndef __ARMEB__ /* Little endian */ - __ASM volatile ("smlald %0, %1, %2, %3" : "=r" (llr.w32[0]), "=r" (llr.w32[1]): "r" (op1), "r" (op2) , "0" (llr.w32[0]), "1" (llr.w32[1]) ); + __ASM volatile("smlald %0, %1, %2, %3" : "=r"(llr.w32[0]), "=r"(llr.w32[1]): "r"(op1), "r"(op2), "0"(llr.w32[0]), "1"(llr.w32[1])); #else /* Big endian */ - __ASM volatile ("smlald %0, %1, %2, %3" : "=r" (llr.w32[1]), "=r" (llr.w32[0]): "r" (op1), "r" (op2) , "0" (llr.w32[1]), "1" (llr.w32[0]) ); + __ASM volatile("smlald %0, %1, %2, %3" : "=r"(llr.w32[1]), "=r"(llr.w32[0]): "r"(op1), "r"(op2), "0"(llr.w32[1]), "1"(llr.w32[0])); #endif - return(llr.w64); + return (llr.w64); } -__STATIC_FORCEINLINE uint64_t __SMLALDX (uint32_t op1, uint32_t op2, uint64_t acc) -{ - union llreg_u{ - uint32_t w32[2]; - uint64_t w64; - } llr; - llr.w64 = acc; +__STATIC_FORCEINLINE uint64_t __SMLALDX(uint32_t op1, uint32_t op2, uint64_t acc) { + union llreg_u { + uint32_t w32[2]; + uint64_t w64; + } llr; + llr.w64 = acc; #ifndef __ARMEB__ /* Little endian */ - __ASM volatile ("smlaldx %0, %1, %2, %3" : "=r" (llr.w32[0]), "=r" (llr.w32[1]): "r" (op1), "r" (op2) , "0" (llr.w32[0]), "1" (llr.w32[1]) ); + __ASM volatile("smlaldx %0, %1, %2, %3" : "=r"(llr.w32[0]), "=r"(llr.w32[1]): "r"(op1), "r"(op2), "0"(llr.w32[0]), "1"(llr.w32[1])); #else /* Big endian */ - __ASM volatile ("smlaldx %0, %1, %2, %3" : "=r" (llr.w32[1]), "=r" (llr.w32[0]): "r" (op1), "r" (op2) , "0" (llr.w32[1]), "1" (llr.w32[0]) ); + __ASM volatile("smlaldx %0, %1, %2, %3" : "=r"(llr.w32[1]), "=r"(llr.w32[0]): "r"(op1), "r"(op2), "0"(llr.w32[1]), "1"(llr.w32[0])); #endif - return(llr.w64); + return (llr.w64); } -__STATIC_FORCEINLINE uint32_t __SMUSD (uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __SMUSD(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM volatile ("smusd %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM volatile("smusd %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __SMUSDX (uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __SMUSDX(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM volatile ("smusdx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM volatile("smusdx %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __SMLSD (uint32_t op1, uint32_t op2, uint32_t op3) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __SMLSD(uint32_t op1, uint32_t op2, uint32_t op3) { + uint32_t result; - __ASM volatile ("smlsd %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) ); - return(result); + __ASM volatile("smlsd %0, %1, %2, %3" : "=r"(result) : "r"(op1), "r"(op2), "r"(op3)); + return (result); } -__STATIC_FORCEINLINE uint32_t __SMLSDX (uint32_t op1, uint32_t op2, uint32_t op3) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __SMLSDX(uint32_t op1, uint32_t op2, uint32_t op3) { + uint32_t result; - __ASM volatile ("smlsdx %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) ); - return(result); + __ASM volatile("smlsdx %0, %1, %2, %3" : "=r"(result) : "r"(op1), "r"(op2), "r"(op3)); + return (result); } -__STATIC_FORCEINLINE uint64_t __SMLSLD (uint32_t op1, uint32_t op2, uint64_t acc) -{ - union llreg_u{ - uint32_t w32[2]; - uint64_t w64; - } llr; - llr.w64 = acc; +__STATIC_FORCEINLINE uint64_t __SMLSLD(uint32_t op1, uint32_t op2, uint64_t acc) { + union llreg_u { + uint32_t w32[2]; + uint64_t w64; + } llr; + llr.w64 = acc; #ifndef __ARMEB__ /* Little endian */ - __ASM volatile ("smlsld %0, %1, %2, %3" : "=r" (llr.w32[0]), "=r" (llr.w32[1]): "r" (op1), "r" (op2) , "0" (llr.w32[0]), "1" (llr.w32[1]) ); + __ASM volatile("smlsld %0, %1, %2, %3" : "=r"(llr.w32[0]), "=r"(llr.w32[1]): "r"(op1), "r"(op2), "0"(llr.w32[0]), "1"(llr.w32[1])); #else /* Big endian */ - __ASM volatile ("smlsld %0, %1, %2, %3" : "=r" (llr.w32[1]), "=r" (llr.w32[0]): "r" (op1), "r" (op2) , "0" (llr.w32[1]), "1" (llr.w32[0]) ); + __ASM volatile("smlsld %0, %1, %2, %3" : "=r"(llr.w32[1]), "=r"(llr.w32[0]): "r"(op1), "r"(op2), "0"(llr.w32[1]), "1"(llr.w32[0])); #endif - return(llr.w64); + return (llr.w64); } -__STATIC_FORCEINLINE uint64_t __SMLSLDX (uint32_t op1, uint32_t op2, uint64_t acc) -{ - union llreg_u{ - uint32_t w32[2]; - uint64_t w64; - } llr; - llr.w64 = acc; +__STATIC_FORCEINLINE uint64_t __SMLSLDX(uint32_t op1, uint32_t op2, uint64_t acc) { + union llreg_u { + uint32_t w32[2]; + uint64_t w64; + } llr; + llr.w64 = acc; #ifndef __ARMEB__ /* Little endian */ - __ASM volatile ("smlsldx %0, %1, %2, %3" : "=r" (llr.w32[0]), "=r" (llr.w32[1]): "r" (op1), "r" (op2) , "0" (llr.w32[0]), "1" (llr.w32[1]) ); + __ASM volatile("smlsldx %0, %1, %2, %3" : "=r"(llr.w32[0]), "=r"(llr.w32[1]): "r"(op1), "r"(op2), "0"(llr.w32[0]), "1"(llr.w32[1])); #else /* Big endian */ - __ASM volatile ("smlsldx %0, %1, %2, %3" : "=r" (llr.w32[1]), "=r" (llr.w32[0]): "r" (op1), "r" (op2) , "0" (llr.w32[1]), "1" (llr.w32[0]) ); + __ASM volatile("smlsldx %0, %1, %2, %3" : "=r"(llr.w32[1]), "=r"(llr.w32[0]): "r"(op1), "r"(op2), "0"(llr.w32[1]), "1"(llr.w32[0])); #endif - return(llr.w64); + return (llr.w64); } -__STATIC_FORCEINLINE uint32_t __SEL (uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __SEL(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM volatile ("sel %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM volatile("sel %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE int32_t __QADD( int32_t op1, int32_t op2) -{ - int32_t result; +__STATIC_FORCEINLINE int32_t __QADD(int32_t op1, int32_t op2) { + int32_t result; - __ASM volatile ("qadd %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM volatile("qadd %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE int32_t __QSUB( int32_t op1, int32_t op2) -{ - int32_t result; +__STATIC_FORCEINLINE int32_t __QSUB(int32_t op1, int32_t op2) { + int32_t result; - __ASM volatile ("qsub %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM volatile("qsub %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } #define __PKHBT(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0x0000FFFFUL) | \ @@ -1913,12 +1787,11 @@ __STATIC_FORCEINLINE int32_t __QSUB( int32_t op1, int32_t op2) #define __SXTAB16_RORn(ARG1, ARG2, ARG3) __SXTAB16(ARG1, __ROR(ARG2, ARG3)) -__STATIC_FORCEINLINE int32_t __SMMLA (int32_t op1, int32_t op2, int32_t op3) -{ - int32_t result; +__STATIC_FORCEINLINE int32_t __SMMLA(int32_t op1, int32_t op2, int32_t op3) { + int32_t result; - __ASM volatile ("smmla %0, %1, %2, %3" : "=r" (result): "r" (op1), "r" (op2), "r" (op3) ); - return(result); + __ASM volatile("smmla %0, %1, %2, %3" : "=r"(result): "r"(op1), "r"(op2), "r"(op3)); + return (result); } #endif /* (__ARM_FEATURE_DSP == 1) */ diff --git a/armlib/at32_sys/cmsis/cm4/core_support/cmsis_compiler.h b/armlib/at32_sys/cmsis/cm4/core_support/cmsis_compiler.h index adbf296f1..e099b022e 100644 --- a/armlib/at32_sys/cmsis/cm4/core_support/cmsis_compiler.h +++ b/armlib/at32_sys/cmsis/cm4/core_support/cmsis_compiler.h @@ -31,251 +31,251 @@ * Arm Compiler 4/5 */ #if defined ( __CC_ARM ) - #include "cmsis_armcc.h" +#include "cmsis_armcc.h" /* * Arm Compiler 6.6 LTM (armclang) */ #elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) && (__ARMCC_VERSION < 6100100) - #include "cmsis_armclang_ltm.h" +#include "cmsis_armclang_ltm.h" - /* - * Arm Compiler above 6.10.1 (armclang) - */ +/* +* Arm Compiler above 6.10.1 (armclang) +*/ #elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6100100) - #include "cmsis_armclang.h" +#include "cmsis_armclang.h" /* * GNU Compiler */ #elif defined ( __GNUC__ ) - #include "cmsis_gcc.h" +#include "cmsis_gcc.h" /* * IAR Compiler */ #elif defined ( __ICCARM__ ) - #include +#include /* * TI Arm Compiler */ #elif defined ( __TI_ARM__ ) - #include +#include - #ifndef __ASM - #define __ASM __asm - #endif - #ifndef __INLINE - #define __INLINE inline - #endif - #ifndef __STATIC_INLINE - #define __STATIC_INLINE static inline - #endif - #ifndef __STATIC_FORCEINLINE - #define __STATIC_FORCEINLINE __STATIC_INLINE - #endif - #ifndef __NO_RETURN - #define __NO_RETURN __attribute__((noreturn)) - #endif - #ifndef __USED - #define __USED __attribute__((used)) - #endif - #ifndef __WEAK - #define __WEAK __attribute__((weak)) - #endif - #ifndef __PACKED - #define __PACKED __attribute__((packed)) - #endif - #ifndef __PACKED_STRUCT - #define __PACKED_STRUCT struct __attribute__((packed)) - #endif - #ifndef __PACKED_UNION - #define __PACKED_UNION union __attribute__((packed)) - #endif - #ifndef __UNALIGNED_UINT32 /* deprecated */ - struct __attribute__((packed)) T_UINT32 { uint32_t v; }; - #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v) - #endif - #ifndef __UNALIGNED_UINT16_WRITE - __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; }; - #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void*)(addr))->v) = (val)) - #endif - #ifndef __UNALIGNED_UINT16_READ - __PACKED_STRUCT T_UINT16_READ { uint16_t v; }; - #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v) - #endif - #ifndef __UNALIGNED_UINT32_WRITE - __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; }; - #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val)) - #endif - #ifndef __UNALIGNED_UINT32_READ - __PACKED_STRUCT T_UINT32_READ { uint32_t v; }; - #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v) - #endif - #ifndef __ALIGNED - #define __ALIGNED(x) __attribute__((aligned(x))) - #endif - #ifndef __RESTRICT - #define __RESTRICT __restrict - #endif - #ifndef __COMPILER_BARRIER - #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored. - #define __COMPILER_BARRIER() (void)0 - #endif +#ifndef __ASM +#define __ASM __asm +#endif +#ifndef __INLINE +#define __INLINE inline +#endif +#ifndef __STATIC_INLINE +#define __STATIC_INLINE static inline +#endif +#ifndef __STATIC_FORCEINLINE +#define __STATIC_FORCEINLINE __STATIC_INLINE +#endif +#ifndef __NO_RETURN +#define __NO_RETURN __attribute__((noreturn)) +#endif +#ifndef __USED +#define __USED __attribute__((used)) +#endif +#ifndef __WEAK +#define __WEAK __attribute__((weak)) +#endif +#ifndef __PACKED +#define __PACKED __attribute__((packed)) +#endif +#ifndef __PACKED_STRUCT +#define __PACKED_STRUCT struct __attribute__((packed)) +#endif +#ifndef __PACKED_UNION +#define __PACKED_UNION union __attribute__((packed)) +#endif +#ifndef __UNALIGNED_UINT32 /* deprecated */ +struct __attribute__((packed)) T_UINT32 { uint32_t v; }; +#define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v) +#endif +#ifndef __UNALIGNED_UINT16_WRITE +__PACKED_STRUCT T_UINT16_WRITE { uint16_t v; }; +#define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void*)(addr))->v) = (val)) +#endif +#ifndef __UNALIGNED_UINT16_READ +__PACKED_STRUCT T_UINT16_READ { uint16_t v; }; +#define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v) +#endif +#ifndef __UNALIGNED_UINT32_WRITE +__PACKED_STRUCT T_UINT32_WRITE { uint32_t v; }; +#define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val)) +#endif +#ifndef __UNALIGNED_UINT32_READ +__PACKED_STRUCT T_UINT32_READ { uint32_t v; }; +#define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v) +#endif +#ifndef __ALIGNED +#define __ALIGNED(x) __attribute__((aligned(x))) +#endif +#ifndef __RESTRICT +#define __RESTRICT __restrict +#endif +#ifndef __COMPILER_BARRIER +#warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored. +#define __COMPILER_BARRIER() (void)0 +#endif /* * TASKING Compiler */ #elif defined ( __TASKING__ ) - /* - * The CMSIS functions have been implemented as intrinsics in the compiler. - * Please use "carm -?i" to get an up to date list of all intrinsics, - * Including the CMSIS ones. - */ +/* + * The CMSIS functions have been implemented as intrinsics in the compiler. + * Please use "carm -?i" to get an up to date list of all intrinsics, + * Including the CMSIS ones. + */ - #ifndef __ASM - #define __ASM __asm - #endif - #ifndef __INLINE - #define __INLINE inline - #endif - #ifndef __STATIC_INLINE - #define __STATIC_INLINE static inline - #endif - #ifndef __STATIC_FORCEINLINE - #define __STATIC_FORCEINLINE __STATIC_INLINE - #endif - #ifndef __NO_RETURN - #define __NO_RETURN __attribute__((noreturn)) - #endif - #ifndef __USED - #define __USED __attribute__((used)) - #endif - #ifndef __WEAK - #define __WEAK __attribute__((weak)) - #endif - #ifndef __PACKED - #define __PACKED __packed__ - #endif - #ifndef __PACKED_STRUCT - #define __PACKED_STRUCT struct __packed__ - #endif - #ifndef __PACKED_UNION - #define __PACKED_UNION union __packed__ - #endif - #ifndef __UNALIGNED_UINT32 /* deprecated */ - struct __packed__ T_UINT32 { uint32_t v; }; - #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v) - #endif - #ifndef __UNALIGNED_UINT16_WRITE - __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; }; - #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val)) - #endif - #ifndef __UNALIGNED_UINT16_READ - __PACKED_STRUCT T_UINT16_READ { uint16_t v; }; - #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v) - #endif - #ifndef __UNALIGNED_UINT32_WRITE - __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; }; - #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val)) - #endif - #ifndef __UNALIGNED_UINT32_READ - __PACKED_STRUCT T_UINT32_READ { uint32_t v; }; - #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v) - #endif - #ifndef __ALIGNED - #define __ALIGNED(x) __align(x) - #endif - #ifndef __RESTRICT - #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored. - #define __RESTRICT - #endif - #ifndef __COMPILER_BARRIER - #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored. - #define __COMPILER_BARRIER() (void)0 - #endif +#ifndef __ASM +#define __ASM __asm +#endif +#ifndef __INLINE +#define __INLINE inline +#endif +#ifndef __STATIC_INLINE +#define __STATIC_INLINE static inline +#endif +#ifndef __STATIC_FORCEINLINE +#define __STATIC_FORCEINLINE __STATIC_INLINE +#endif +#ifndef __NO_RETURN +#define __NO_RETURN __attribute__((noreturn)) +#endif +#ifndef __USED +#define __USED __attribute__((used)) +#endif +#ifndef __WEAK +#define __WEAK __attribute__((weak)) +#endif +#ifndef __PACKED +#define __PACKED __packed__ +#endif +#ifndef __PACKED_STRUCT +#define __PACKED_STRUCT struct __packed__ +#endif +#ifndef __PACKED_UNION +#define __PACKED_UNION union __packed__ +#endif +#ifndef __UNALIGNED_UINT32 /* deprecated */ +struct __packed__ T_UINT32 { uint32_t v; }; +#define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v) +#endif +#ifndef __UNALIGNED_UINT16_WRITE +__PACKED_STRUCT T_UINT16_WRITE { uint16_t v; }; +#define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val)) +#endif +#ifndef __UNALIGNED_UINT16_READ +__PACKED_STRUCT T_UINT16_READ { uint16_t v; }; +#define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v) +#endif +#ifndef __UNALIGNED_UINT32_WRITE +__PACKED_STRUCT T_UINT32_WRITE { uint32_t v; }; +#define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val)) +#endif +#ifndef __UNALIGNED_UINT32_READ +__PACKED_STRUCT T_UINT32_READ { uint32_t v; }; +#define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v) +#endif +#ifndef __ALIGNED +#define __ALIGNED(x) __align(x) +#endif +#ifndef __RESTRICT +#warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored. +#define __RESTRICT +#endif +#ifndef __COMPILER_BARRIER +#warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored. +#define __COMPILER_BARRIER() (void)0 +#endif /* * COSMIC Compiler */ #elif defined ( __CSMC__ ) - #include +#include - #ifndef __ASM - #define __ASM _asm - #endif - #ifndef __INLINE - #define __INLINE inline - #endif - #ifndef __STATIC_INLINE - #define __STATIC_INLINE static inline - #endif - #ifndef __STATIC_FORCEINLINE - #define __STATIC_FORCEINLINE __STATIC_INLINE - #endif - #ifndef __NO_RETURN - // NO RETURN is automatically detected hence no warning here - #define __NO_RETURN - #endif - #ifndef __USED - #warning No compiler specific solution for __USED. __USED is ignored. - #define __USED - #endif - #ifndef __WEAK - #define __WEAK __weak - #endif - #ifndef __PACKED - #define __PACKED @packed - #endif - #ifndef __PACKED_STRUCT - #define __PACKED_STRUCT @packed struct - #endif - #ifndef __PACKED_UNION - #define __PACKED_UNION @packed union - #endif - #ifndef __UNALIGNED_UINT32 /* deprecated */ - @packed struct T_UINT32 { uint32_t v; }; - #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v) - #endif - #ifndef __UNALIGNED_UINT16_WRITE - __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; }; - #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val)) - #endif - #ifndef __UNALIGNED_UINT16_READ - __PACKED_STRUCT T_UINT16_READ { uint16_t v; }; - #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v) - #endif - #ifndef __UNALIGNED_UINT32_WRITE - __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; }; - #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val)) - #endif - #ifndef __UNALIGNED_UINT32_READ - __PACKED_STRUCT T_UINT32_READ { uint32_t v; }; - #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v) - #endif - #ifndef __ALIGNED - #warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored. - #define __ALIGNED(x) - #endif - #ifndef __RESTRICT - #warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored. - #define __RESTRICT - #endif - #ifndef __COMPILER_BARRIER - #warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored. - #define __COMPILER_BARRIER() (void)0 - #endif +#ifndef __ASM +#define __ASM _asm +#endif +#ifndef __INLINE +#define __INLINE inline +#endif +#ifndef __STATIC_INLINE +#define __STATIC_INLINE static inline +#endif +#ifndef __STATIC_FORCEINLINE +#define __STATIC_FORCEINLINE __STATIC_INLINE +#endif +#ifndef __NO_RETURN +// NO RETURN is automatically detected hence no warning here +#define __NO_RETURN +#endif +#ifndef __USED +#warning No compiler specific solution for __USED. __USED is ignored. +#define __USED +#endif +#ifndef __WEAK +#define __WEAK __weak +#endif +#ifndef __PACKED +#define __PACKED @packed +#endif +#ifndef __PACKED_STRUCT +#define __PACKED_STRUCT @packed struct +#endif +#ifndef __PACKED_UNION +#define __PACKED_UNION @packed union +#endif +#ifndef __UNALIGNED_UINT32 /* deprecated */ +@packed struct T_UINT32 { uint32_t v; }; +#define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v) +#endif +#ifndef __UNALIGNED_UINT16_WRITE +__PACKED_STRUCT T_UINT16_WRITE { uint16_t v; }; +#define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val)) +#endif +#ifndef __UNALIGNED_UINT16_READ +__PACKED_STRUCT T_UINT16_READ { uint16_t v; }; +#define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v) +#endif +#ifndef __UNALIGNED_UINT32_WRITE +__PACKED_STRUCT T_UINT32_WRITE { uint32_t v; }; +#define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val)) +#endif +#ifndef __UNALIGNED_UINT32_READ +__PACKED_STRUCT T_UINT32_READ { uint32_t v; }; +#define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v) +#endif +#ifndef __ALIGNED +#warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored. +#define __ALIGNED(x) +#endif +#ifndef __RESTRICT +#warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored. +#define __RESTRICT +#endif +#ifndef __COMPILER_BARRIER +#warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored. +#define __COMPILER_BARRIER() (void)0 +#endif #else - #error Unknown compiler. +#error Unknown compiler. #endif diff --git a/armlib/at32_sys/cmsis/cm4/core_support/cmsis_gcc.h b/armlib/at32_sys/cmsis/cm4/core_support/cmsis_gcc.h index c6e4d8c4d..8f4be7c4c 100644 --- a/armlib/at32_sys/cmsis/cm4/core_support/cmsis_gcc.h +++ b/armlib/at32_sys/cmsis/cm4/core_support/cmsis_gcc.h @@ -34,88 +34,88 @@ /* Fallback for __has_builtin */ #ifndef __has_builtin - #define __has_builtin(x) (0) +#define __has_builtin(x) (0) #endif /* CMSIS compiler specific defines */ #ifndef __ASM - #define __ASM __asm +#define __ASM __asm #endif #ifndef __INLINE - #define __INLINE inline +#define __INLINE inline #endif #ifndef __STATIC_INLINE - #define __STATIC_INLINE static inline +#define __STATIC_INLINE static inline #endif #ifndef __STATIC_FORCEINLINE - #define __STATIC_FORCEINLINE __attribute__((always_inline)) static inline +#define __STATIC_FORCEINLINE __attribute__((always_inline)) static inline #endif #ifndef __NO_RETURN - #define __NO_RETURN __attribute__((__noreturn__)) +#define __NO_RETURN __attribute__((__noreturn__)) #endif #ifndef __USED - #define __USED __attribute__((used)) +#define __USED __attribute__((used)) #endif #ifndef __WEAK - #define __WEAK __attribute__((weak)) +#define __WEAK __attribute__((weak)) #endif #ifndef __PACKED - #define __PACKED __attribute__((packed, aligned(1))) +#define __PACKED __attribute__((packed, aligned(1))) #endif #ifndef __PACKED_STRUCT - #define __PACKED_STRUCT struct __attribute__((packed, aligned(1))) +#define __PACKED_STRUCT struct __attribute__((packed, aligned(1))) #endif #ifndef __PACKED_UNION - #define __PACKED_UNION union __attribute__((packed, aligned(1))) +#define __PACKED_UNION union __attribute__((packed, aligned(1))) #endif #ifndef __UNALIGNED_UINT32 /* deprecated */ - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wpacked" - #pragma GCC diagnostic ignored "-Wattributes" - struct __attribute__((packed)) T_UINT32 { uint32_t v; }; - #pragma GCC diagnostic pop - #define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wpacked" +#pragma GCC diagnostic ignored "-Wattributes" +struct __attribute__((packed)) T_UINT32 { uint32_t v; }; +#pragma GCC diagnostic pop +#define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v) #endif #ifndef __UNALIGNED_UINT16_WRITE - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wpacked" - #pragma GCC diagnostic ignored "-Wattributes" - __PACKED_STRUCT T_UINT16_WRITE { uint16_t v; }; - #pragma GCC diagnostic pop - #define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val)) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wpacked" +#pragma GCC diagnostic ignored "-Wattributes" +__PACKED_STRUCT T_UINT16_WRITE { uint16_t v; }; +#pragma GCC diagnostic pop +#define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val)) #endif #ifndef __UNALIGNED_UINT16_READ - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wpacked" - #pragma GCC diagnostic ignored "-Wattributes" - __PACKED_STRUCT T_UINT16_READ { uint16_t v; }; - #pragma GCC diagnostic pop - #define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wpacked" +#pragma GCC diagnostic ignored "-Wattributes" +__PACKED_STRUCT T_UINT16_READ { uint16_t v; }; +#pragma GCC diagnostic pop +#define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v) #endif #ifndef __UNALIGNED_UINT32_WRITE - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wpacked" - #pragma GCC diagnostic ignored "-Wattributes" - __PACKED_STRUCT T_UINT32_WRITE { uint32_t v; }; - #pragma GCC diagnostic pop - #define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val)) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wpacked" +#pragma GCC diagnostic ignored "-Wattributes" +__PACKED_STRUCT T_UINT32_WRITE { uint32_t v; }; +#pragma GCC diagnostic pop +#define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val)) #endif #ifndef __UNALIGNED_UINT32_READ - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wpacked" - #pragma GCC diagnostic ignored "-Wattributes" - __PACKED_STRUCT T_UINT32_READ { uint32_t v; }; - #pragma GCC diagnostic pop - #define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wpacked" +#pragma GCC diagnostic ignored "-Wattributes" +__PACKED_STRUCT T_UINT32_READ { uint32_t v; }; +#pragma GCC diagnostic pop +#define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v) #endif #ifndef __ALIGNED - #define __ALIGNED(x) __attribute__((aligned(x))) +#define __ALIGNED(x) __attribute__((aligned(x))) #endif #ifndef __RESTRICT - #define __RESTRICT __restrict +#define __RESTRICT __restrict #endif #ifndef __COMPILER_BARRIER - #define __COMPILER_BARRIER() __ASM volatile("":::"memory") +#define __COMPILER_BARRIER() __ASM volatile("":::"memory") #endif /* ######################### Startup and Lowlevel Init ######################## */ @@ -129,39 +129,38 @@ in the used linker script. */ -__STATIC_FORCEINLINE __NO_RETURN void __cmsis_start(void) -{ - extern void _start(void) __NO_RETURN; +__STATIC_FORCEINLINE __NO_RETURN void __cmsis_start(void) { + extern void _start(void) __NO_RETURN; - typedef struct { - uint32_t const* src; - uint32_t* dest; - uint32_t wlen; - } __copy_table_t; + typedef struct { + uint32_t const *src; + uint32_t *dest; + uint32_t wlen; + } __copy_table_t; - typedef struct { - uint32_t* dest; - uint32_t wlen; - } __zero_table_t; + typedef struct { + uint32_t *dest; + uint32_t wlen; + } __zero_table_t; - extern const __copy_table_t __copy_table_start__; - extern const __copy_table_t __copy_table_end__; - extern const __zero_table_t __zero_table_start__; - extern const __zero_table_t __zero_table_end__; + extern const __copy_table_t __copy_table_start__; + extern const __copy_table_t __copy_table_end__; + extern const __zero_table_t __zero_table_start__; + extern const __zero_table_t __zero_table_end__; - for (__copy_table_t const* pTable = &__copy_table_start__; pTable < &__copy_table_end__; ++pTable) { - for(uint32_t i=0u; iwlen; ++i) { - pTable->dest[i] = pTable->src[i]; + for (__copy_table_t const *pTable = &__copy_table_start__; pTable < &__copy_table_end__; ++pTable) { + for (uint32_t i = 0u; i < pTable->wlen; ++i) { + pTable->dest[i] = pTable->src[i]; + } } - } - for (__zero_table_t const* pTable = &__zero_table_start__; pTable < &__zero_table_end__; ++pTable) { - for(uint32_t i=0u; iwlen; ++i) { - pTable->dest[i] = 0u; + for (__zero_table_t const *pTable = &__zero_table_start__; pTable < &__zero_table_end__; ++pTable) { + for (uint32_t i = 0u; i < pTable->wlen; ++i) { + pTable->dest[i] = 0u; + } } - } - _start(); + _start(); } #define __PROGRAM_START __cmsis_start @@ -197,8 +196,8 @@ __STATIC_FORCEINLINE __NO_RETURN void __cmsis_start(void) #endif -__STATIC_FORCEINLINE void __TZ_set_STACKSEAL_S (uint32_t* stackTop) { - *((uint64_t *)stackTop) = __TZ_STACK_SEAL_VALUE; +__STATIC_FORCEINLINE void __TZ_set_STACKSEAL_S(uint32_t *stackTop) { + *((uint64_t *)stackTop) = __TZ_STACK_SEAL_VALUE; } #endif @@ -256,9 +255,8 @@ __STATIC_FORCEINLINE void __TZ_set_STACKSEAL_S (uint32_t* stackTop) { so that all instructions following the ISB are fetched from cache or memory, after the instruction has been completed. */ -__STATIC_FORCEINLINE void __ISB(void) -{ - __ASM volatile ("isb 0xF":::"memory"); +__STATIC_FORCEINLINE void __ISB(void) { + __ASM volatile("isb 0xF"::: "memory"); } @@ -267,9 +265,8 @@ __STATIC_FORCEINLINE void __ISB(void) \details Acts as a special kind of Data Memory Barrier. It completes when all explicit memory accesses before this instruction complete. */ -__STATIC_FORCEINLINE void __DSB(void) -{ - __ASM volatile ("dsb 0xF":::"memory"); +__STATIC_FORCEINLINE void __DSB(void) { + __ASM volatile("dsb 0xF"::: "memory"); } @@ -278,9 +275,8 @@ __STATIC_FORCEINLINE void __DSB(void) \details Ensures the apparent order of the explicit memory operations before and after the instruction, without ensuring their completion. */ -__STATIC_FORCEINLINE void __DMB(void) -{ - __ASM volatile ("dmb 0xF":::"memory"); +__STATIC_FORCEINLINE void __DMB(void) { + __ASM volatile("dmb 0xF"::: "memory"); } @@ -290,15 +286,14 @@ __STATIC_FORCEINLINE void __DMB(void) \param [in] value Value to reverse \return Reversed value */ -__STATIC_FORCEINLINE uint32_t __REV(uint32_t value) -{ +__STATIC_FORCEINLINE uint32_t __REV(uint32_t value) { #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5) - return __builtin_bswap32(value); + return __builtin_bswap32(value); #else - uint32_t result; + uint32_t result; - __ASM ("rev %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) ); - return result; + __ASM("rev %0, %1" : __CMSIS_GCC_OUT_REG(result) : __CMSIS_GCC_USE_REG(value)); + return result; #endif } @@ -309,12 +304,11 @@ __STATIC_FORCEINLINE uint32_t __REV(uint32_t value) \param [in] value Value to reverse \return Reversed value */ -__STATIC_FORCEINLINE uint32_t __REV16(uint32_t value) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __REV16(uint32_t value) { + uint32_t result; - __ASM ("rev16 %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) ); - return result; + __ASM("rev16 %0, %1" : __CMSIS_GCC_OUT_REG(result) : __CMSIS_GCC_USE_REG(value)); + return result; } @@ -324,15 +318,14 @@ __STATIC_FORCEINLINE uint32_t __REV16(uint32_t value) \param [in] value Value to reverse \return Reversed value */ -__STATIC_FORCEINLINE int16_t __REVSH(int16_t value) -{ +__STATIC_FORCEINLINE int16_t __REVSH(int16_t value) { #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8) - return (int16_t)__builtin_bswap16(value); + return (int16_t)__builtin_bswap16(value); #else - int16_t result; + int16_t result; - __ASM ("revsh %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) ); - return result; + __ASM("revsh %0, %1" : __CMSIS_GCC_OUT_REG(result) : __CMSIS_GCC_USE_REG(value)); + return result; #endif } @@ -344,14 +337,12 @@ __STATIC_FORCEINLINE int16_t __REVSH(int16_t value) \param [in] op2 Number of Bits to rotate \return Rotated value */ -__STATIC_FORCEINLINE uint32_t __ROR(uint32_t op1, uint32_t op2) -{ - op2 %= 32U; - if (op2 == 0U) - { - return op1; - } - return (op1 >> op2) | (op1 << (32U - op2)); +__STATIC_FORCEINLINE uint32_t __ROR(uint32_t op1, uint32_t op2) { + op2 %= 32U; + if (op2 == 0U) { + return op1; + } + return (op1 >> op2) | (op1 << (32U - op2)); } @@ -371,27 +362,25 @@ __STATIC_FORCEINLINE uint32_t __ROR(uint32_t op1, uint32_t op2) \param [in] value Value to reverse \return Reversed value */ -__STATIC_FORCEINLINE uint32_t __RBIT(uint32_t value) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __RBIT(uint32_t value) { + uint32_t result; #if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ (defined (__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \ (defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) ) - __ASM ("rbit %0, %1" : "=r" (result) : "r" (value) ); + __ASM("rbit %0, %1" : "=r"(result) : "r"(value)); #else - uint32_t s = (4U /*sizeof(v)*/ * 8U) - 1U; /* extra shift needed at end */ + uint32_t s = (4U /*sizeof(v)*/ * 8U) - 1U; /* extra shift needed at end */ - result = value; /* r will be reversed bits of v; first get LSB of v */ - for (value >>= 1U; value != 0U; value >>= 1U) - { - result <<= 1U; - result |= value & 1U; - s--; - } - result <<= s; /* shift when v's highest bits are zero */ + result = value; /* r will be reversed bits of v; first get LSB of v */ + for (value >>= 1U; value != 0U; value >>= 1U) { + result <<= 1U; + result |= value & 1U; + s--; + } + result <<= s; /* shift when v's highest bits are zero */ #endif - return result; + return result; } @@ -401,22 +390,20 @@ __STATIC_FORCEINLINE uint32_t __RBIT(uint32_t value) \param [in] value Value to count the leading zeros \return number of leading zeros in value */ -__STATIC_FORCEINLINE uint8_t __CLZ(uint32_t value) -{ - /* Even though __builtin_clz produces a CLZ instruction on ARM, formally - __builtin_clz(0) is undefined behaviour, so handle this case specially. - This guarantees ARM-compatible results if happening to compile on a non-ARM - target, and ensures the compiler doesn't decide to activate any - optimisations using the logic "value was passed to __builtin_clz, so it - is non-zero". - ARM GCC 7.3 and possibly earlier will optimise this test away, leaving a - single CLZ instruction. - */ - if (value == 0U) - { - return 32U; - } - return __builtin_clz(value); +__STATIC_FORCEINLINE uint8_t __CLZ(uint32_t value) { + /* Even though __builtin_clz produces a CLZ instruction on ARM, formally + __builtin_clz(0) is undefined behaviour, so handle this case specially. + This guarantees ARM-compatible results if happening to compile on a non-ARM + target, and ensures the compiler doesn't decide to activate any + optimisations using the logic "value was passed to __builtin_clz, so it + is non-zero". + ARM GCC 7.3 and possibly earlier will optimise this test away, leaving a + single CLZ instruction. + */ + if (value == 0U) { + return 32U; + } + return __builtin_clz(value); } @@ -430,19 +417,18 @@ __STATIC_FORCEINLINE uint8_t __CLZ(uint32_t value) \param [in] ptr Pointer to data \return value of type uint8_t at (*ptr) */ -__STATIC_FORCEINLINE uint8_t __LDREXB(volatile uint8_t *addr) -{ +__STATIC_FORCEINLINE uint8_t __LDREXB(volatile uint8_t *addr) { uint32_t result; #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8) - __ASM volatile ("ldrexb %0, %1" : "=r" (result) : "Q" (*addr) ); + __ASM volatile("ldrexb %0, %1" : "=r"(result) : "Q"(*addr)); #else /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not accepted by assembler. So has to use following less efficient pattern. */ - __ASM volatile ("ldrexb %0, [%1]" : "=r" (result) : "r" (addr) : "memory" ); + __ASM volatile("ldrexb %0, [%1]" : "=r"(result) : "r"(addr) : "memory"); #endif - return ((uint8_t) result); /* Add explicit type cast here */ + return ((uint8_t) result); /* Add explicit type cast here */ } @@ -452,19 +438,18 @@ __STATIC_FORCEINLINE uint8_t __LDREXB(volatile uint8_t *addr) \param [in] ptr Pointer to data \return value of type uint16_t at (*ptr) */ -__STATIC_FORCEINLINE uint16_t __LDREXH(volatile uint16_t *addr) -{ +__STATIC_FORCEINLINE uint16_t __LDREXH(volatile uint16_t *addr) { uint32_t result; #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8) - __ASM volatile ("ldrexh %0, %1" : "=r" (result) : "Q" (*addr) ); + __ASM volatile("ldrexh %0, %1" : "=r"(result) : "Q"(*addr)); #else /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not accepted by assembler. So has to use following less efficient pattern. */ - __ASM volatile ("ldrexh %0, [%1]" : "=r" (result) : "r" (addr) : "memory" ); + __ASM volatile("ldrexh %0, [%1]" : "=r"(result) : "r"(addr) : "memory"); #endif - return ((uint16_t) result); /* Add explicit type cast here */ + return ((uint16_t) result); /* Add explicit type cast here */ } @@ -474,12 +459,11 @@ __STATIC_FORCEINLINE uint16_t __LDREXH(volatile uint16_t *addr) \param [in] ptr Pointer to data \return value of type uint32_t at (*ptr) */ -__STATIC_FORCEINLINE uint32_t __LDREXW(volatile uint32_t *addr) -{ +__STATIC_FORCEINLINE uint32_t __LDREXW(volatile uint32_t *addr) { uint32_t result; - __ASM volatile ("ldrex %0, %1" : "=r" (result) : "Q" (*addr) ); - return(result); + __ASM volatile("ldrex %0, %1" : "=r"(result) : "Q"(*addr)); + return (result); } @@ -491,12 +475,11 @@ __STATIC_FORCEINLINE uint32_t __LDREXW(volatile uint32_t *addr) \return 0 Function succeeded \return 1 Function failed */ -__STATIC_FORCEINLINE uint32_t __STREXB(uint8_t value, volatile uint8_t *addr) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __STREXB(uint8_t value, volatile uint8_t *addr) { + uint32_t result; - __ASM volatile ("strexb %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" ((uint32_t)value) ); - return(result); + __ASM volatile("strexb %0, %2, %1" : "=&r"(result), "=Q"(*addr) : "r"((uint32_t)value)); + return (result); } @@ -508,12 +491,11 @@ __STATIC_FORCEINLINE uint32_t __STREXB(uint8_t value, volatile uint8_t *addr) \return 0 Function succeeded \return 1 Function failed */ -__STATIC_FORCEINLINE uint32_t __STREXH(uint16_t value, volatile uint16_t *addr) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __STREXH(uint16_t value, volatile uint16_t *addr) { + uint32_t result; - __ASM volatile ("strexh %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" ((uint32_t)value) ); - return(result); + __ASM volatile("strexh %0, %2, %1" : "=&r"(result), "=Q"(*addr) : "r"((uint32_t)value)); + return (result); } @@ -525,12 +507,11 @@ __STATIC_FORCEINLINE uint32_t __STREXH(uint16_t value, volatile uint16_t *addr) \return 0 Function succeeded \return 1 Function failed */ -__STATIC_FORCEINLINE uint32_t __STREXW(uint32_t value, volatile uint32_t *addr) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __STREXW(uint32_t value, volatile uint32_t *addr) { + uint32_t result; - __ASM volatile ("strex %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" (value) ); - return(result); + __ASM volatile("strex %0, %2, %1" : "=&r"(result), "=Q"(*addr) : "r"(value)); + return (result); } @@ -538,9 +519,8 @@ __STATIC_FORCEINLINE uint32_t __STREXW(uint32_t value, volatile uint32_t *addr) \brief Remove the exclusive lock \details Removes the exclusive lock which is created by LDREX. */ -__STATIC_FORCEINLINE void __CLREX(void) -{ - __ASM volatile ("clrex" ::: "memory"); +__STATIC_FORCEINLINE void __CLREX(void) { + __ASM volatile("clrex" ::: "memory"); } #endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ @@ -591,12 +571,11 @@ __extension__ \ \param [in] value Value to rotate \return Rotated value */ -__STATIC_FORCEINLINE uint32_t __RRX(uint32_t value) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __RRX(uint32_t value) { + uint32_t result; - __ASM volatile ("rrx %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) ); - return(result); + __ASM volatile("rrx %0, %1" : __CMSIS_GCC_OUT_REG(result) : __CMSIS_GCC_USE_REG(value)); + return (result); } @@ -606,19 +585,18 @@ __STATIC_FORCEINLINE uint32_t __RRX(uint32_t value) \param [in] ptr Pointer to data \return value of type uint8_t at (*ptr) */ -__STATIC_FORCEINLINE uint8_t __LDRBT(volatile uint8_t *ptr) -{ +__STATIC_FORCEINLINE uint8_t __LDRBT(volatile uint8_t *ptr) { uint32_t result; #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8) - __ASM volatile ("ldrbt %0, %1" : "=r" (result) : "Q" (*ptr) ); + __ASM volatile("ldrbt %0, %1" : "=r"(result) : "Q"(*ptr)); #else /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not accepted by assembler. So has to use following less efficient pattern. */ - __ASM volatile ("ldrbt %0, [%1]" : "=r" (result) : "r" (ptr) : "memory" ); + __ASM volatile("ldrbt %0, [%1]" : "=r"(result) : "r"(ptr) : "memory"); #endif - return ((uint8_t) result); /* Add explicit type cast here */ + return ((uint8_t) result); /* Add explicit type cast here */ } @@ -628,19 +606,18 @@ __STATIC_FORCEINLINE uint8_t __LDRBT(volatile uint8_t *ptr) \param [in] ptr Pointer to data \return value of type uint16_t at (*ptr) */ -__STATIC_FORCEINLINE uint16_t __LDRHT(volatile uint16_t *ptr) -{ +__STATIC_FORCEINLINE uint16_t __LDRHT(volatile uint16_t *ptr) { uint32_t result; #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8) - __ASM volatile ("ldrht %0, %1" : "=r" (result) : "Q" (*ptr) ); + __ASM volatile("ldrht %0, %1" : "=r"(result) : "Q"(*ptr)); #else /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not accepted by assembler. So has to use following less efficient pattern. */ - __ASM volatile ("ldrht %0, [%1]" : "=r" (result) : "r" (ptr) : "memory" ); + __ASM volatile("ldrht %0, [%1]" : "=r"(result) : "r"(ptr) : "memory"); #endif - return ((uint16_t) result); /* Add explicit type cast here */ + return ((uint16_t) result); /* Add explicit type cast here */ } @@ -650,12 +627,11 @@ __STATIC_FORCEINLINE uint16_t __LDRHT(volatile uint16_t *ptr) \param [in] ptr Pointer to data \return value of type uint32_t at (*ptr) */ -__STATIC_FORCEINLINE uint32_t __LDRT(volatile uint32_t *ptr) -{ +__STATIC_FORCEINLINE uint32_t __LDRT(volatile uint32_t *ptr) { uint32_t result; - __ASM volatile ("ldrt %0, %1" : "=r" (result) : "Q" (*ptr) ); - return(result); + __ASM volatile("ldrt %0, %1" : "=r"(result) : "Q"(*ptr)); + return (result); } @@ -665,9 +641,8 @@ __STATIC_FORCEINLINE uint32_t __LDRT(volatile uint32_t *ptr) \param [in] value Value to store \param [in] ptr Pointer to location */ -__STATIC_FORCEINLINE void __STRBT(uint8_t value, volatile uint8_t *ptr) -{ - __ASM volatile ("strbt %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) ); +__STATIC_FORCEINLINE void __STRBT(uint8_t value, volatile uint8_t *ptr) { + __ASM volatile("strbt %1, %0" : "=Q"(*ptr) : "r"((uint32_t)value)); } @@ -677,9 +652,8 @@ __STATIC_FORCEINLINE void __STRBT(uint8_t value, volatile uint8_t *ptr) \param [in] value Value to store \param [in] ptr Pointer to location */ -__STATIC_FORCEINLINE void __STRHT(uint16_t value, volatile uint16_t *ptr) -{ - __ASM volatile ("strht %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) ); +__STATIC_FORCEINLINE void __STRHT(uint16_t value, volatile uint16_t *ptr) { + __ASM volatile("strht %1, %0" : "=Q"(*ptr) : "r"((uint32_t)value)); } @@ -689,9 +663,8 @@ __STATIC_FORCEINLINE void __STRHT(uint16_t value, volatile uint16_t *ptr) \param [in] value Value to store \param [in] ptr Pointer to location */ -__STATIC_FORCEINLINE void __STRT(uint32_t value, volatile uint32_t *ptr) -{ - __ASM volatile ("strt %1, %0" : "=Q" (*ptr) : "r" (value) ); +__STATIC_FORCEINLINE void __STRT(uint32_t value, volatile uint32_t *ptr) { + __ASM volatile("strt %1, %0" : "=Q"(*ptr) : "r"(value)); } #else /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ @@ -705,22 +678,17 @@ __STATIC_FORCEINLINE void __STRT(uint32_t value, volatile uint32_t *ptr) \param [in] sat Bit position to saturate to (1..32) \return Saturated value */ -__STATIC_FORCEINLINE int32_t __SSAT(int32_t val, uint32_t sat) -{ - if ((sat >= 1U) && (sat <= 32U)) - { - const int32_t max = (int32_t)((1U << (sat - 1U)) - 1U); - const int32_t min = -1 - max ; - if (val > max) - { - return max; +__STATIC_FORCEINLINE int32_t __SSAT(int32_t val, uint32_t sat) { + if ((sat >= 1U) && (sat <= 32U)) { + const int32_t max = (int32_t)((1U << (sat - 1U)) - 1U); + const int32_t min = -1 - max ; + if (val > max) { + return max; + } else if (val < min) { + return min; + } } - else if (val < min) - { - return min; - } - } - return val; + return val; } /** @@ -730,21 +698,16 @@ __STATIC_FORCEINLINE int32_t __SSAT(int32_t val, uint32_t sat) \param [in] sat Bit position to saturate to (0..31) \return Saturated value */ -__STATIC_FORCEINLINE uint32_t __USAT(int32_t val, uint32_t sat) -{ - if (sat <= 31U) - { - const uint32_t max = ((1U << sat) - 1U); - if (val > (int32_t)max) - { - return max; +__STATIC_FORCEINLINE uint32_t __USAT(int32_t val, uint32_t sat) { + if (sat <= 31U) { + const uint32_t max = ((1U << sat) - 1U); + if (val > (int32_t)max) { + return max; + } else if (val < 0) { + return 0U; + } } - else if (val < 0) - { - return 0U; - } - } - return (uint32_t)val; + return (uint32_t)val; } #endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \ @@ -760,12 +723,11 @@ __STATIC_FORCEINLINE uint32_t __USAT(int32_t val, uint32_t sat) \param [in] ptr Pointer to data \return value of type uint8_t at (*ptr) */ -__STATIC_FORCEINLINE uint8_t __LDAB(volatile uint8_t *ptr) -{ +__STATIC_FORCEINLINE uint8_t __LDAB(volatile uint8_t *ptr) { uint32_t result; - __ASM volatile ("ldab %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" ); - return ((uint8_t) result); + __ASM volatile("ldab %0, %1" : "=r"(result) : "Q"(*ptr) : "memory"); + return ((uint8_t) result); } @@ -775,12 +737,11 @@ __STATIC_FORCEINLINE uint8_t __LDAB(volatile uint8_t *ptr) \param [in] ptr Pointer to data \return value of type uint16_t at (*ptr) */ -__STATIC_FORCEINLINE uint16_t __LDAH(volatile uint16_t *ptr) -{ +__STATIC_FORCEINLINE uint16_t __LDAH(volatile uint16_t *ptr) { uint32_t result; - __ASM volatile ("ldah %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" ); - return ((uint16_t) result); + __ASM volatile("ldah %0, %1" : "=r"(result) : "Q"(*ptr) : "memory"); + return ((uint16_t) result); } @@ -790,12 +751,11 @@ __STATIC_FORCEINLINE uint16_t __LDAH(volatile uint16_t *ptr) \param [in] ptr Pointer to data \return value of type uint32_t at (*ptr) */ -__STATIC_FORCEINLINE uint32_t __LDA(volatile uint32_t *ptr) -{ +__STATIC_FORCEINLINE uint32_t __LDA(volatile uint32_t *ptr) { uint32_t result; - __ASM volatile ("lda %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" ); - return(result); + __ASM volatile("lda %0, %1" : "=r"(result) : "Q"(*ptr) : "memory"); + return (result); } @@ -805,9 +765,8 @@ __STATIC_FORCEINLINE uint32_t __LDA(volatile uint32_t *ptr) \param [in] value Value to store \param [in] ptr Pointer to location */ -__STATIC_FORCEINLINE void __STLB(uint8_t value, volatile uint8_t *ptr) -{ - __ASM volatile ("stlb %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" ); +__STATIC_FORCEINLINE void __STLB(uint8_t value, volatile uint8_t *ptr) { + __ASM volatile("stlb %1, %0" : "=Q"(*ptr) : "r"((uint32_t)value) : "memory"); } @@ -817,9 +776,8 @@ __STATIC_FORCEINLINE void __STLB(uint8_t value, volatile uint8_t *ptr) \param [in] value Value to store \param [in] ptr Pointer to location */ -__STATIC_FORCEINLINE void __STLH(uint16_t value, volatile uint16_t *ptr) -{ - __ASM volatile ("stlh %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" ); +__STATIC_FORCEINLINE void __STLH(uint16_t value, volatile uint16_t *ptr) { + __ASM volatile("stlh %1, %0" : "=Q"(*ptr) : "r"((uint32_t)value) : "memory"); } @@ -829,9 +787,8 @@ __STATIC_FORCEINLINE void __STLH(uint16_t value, volatile uint16_t *ptr) \param [in] value Value to store \param [in] ptr Pointer to location */ -__STATIC_FORCEINLINE void __STL(uint32_t value, volatile uint32_t *ptr) -{ - __ASM volatile ("stl %1, %0" : "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" ); +__STATIC_FORCEINLINE void __STL(uint32_t value, volatile uint32_t *ptr) { + __ASM volatile("stl %1, %0" : "=Q"(*ptr) : "r"((uint32_t)value) : "memory"); } @@ -841,12 +798,11 @@ __STATIC_FORCEINLINE void __STL(uint32_t value, volatile uint32_t *ptr) \param [in] ptr Pointer to data \return value of type uint8_t at (*ptr) */ -__STATIC_FORCEINLINE uint8_t __LDAEXB(volatile uint8_t *ptr) -{ +__STATIC_FORCEINLINE uint8_t __LDAEXB(volatile uint8_t *ptr) { uint32_t result; - __ASM volatile ("ldaexb %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" ); - return ((uint8_t) result); + __ASM volatile("ldaexb %0, %1" : "=r"(result) : "Q"(*ptr) : "memory"); + return ((uint8_t) result); } @@ -856,12 +812,11 @@ __STATIC_FORCEINLINE uint8_t __LDAEXB(volatile uint8_t *ptr) \param [in] ptr Pointer to data \return value of type uint16_t at (*ptr) */ -__STATIC_FORCEINLINE uint16_t __LDAEXH(volatile uint16_t *ptr) -{ +__STATIC_FORCEINLINE uint16_t __LDAEXH(volatile uint16_t *ptr) { uint32_t result; - __ASM volatile ("ldaexh %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" ); - return ((uint16_t) result); + __ASM volatile("ldaexh %0, %1" : "=r"(result) : "Q"(*ptr) : "memory"); + return ((uint16_t) result); } @@ -871,12 +826,11 @@ __STATIC_FORCEINLINE uint16_t __LDAEXH(volatile uint16_t *ptr) \param [in] ptr Pointer to data \return value of type uint32_t at (*ptr) */ -__STATIC_FORCEINLINE uint32_t __LDAEX(volatile uint32_t *ptr) -{ +__STATIC_FORCEINLINE uint32_t __LDAEX(volatile uint32_t *ptr) { uint32_t result; - __ASM volatile ("ldaex %0, %1" : "=r" (result) : "Q" (*ptr) : "memory" ); - return(result); + __ASM volatile("ldaex %0, %1" : "=r"(result) : "Q"(*ptr) : "memory"); + return (result); } @@ -888,12 +842,11 @@ __STATIC_FORCEINLINE uint32_t __LDAEX(volatile uint32_t *ptr) \return 0 Function succeeded \return 1 Function failed */ -__STATIC_FORCEINLINE uint32_t __STLEXB(uint8_t value, volatile uint8_t *ptr) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __STLEXB(uint8_t value, volatile uint8_t *ptr) { + uint32_t result; - __ASM volatile ("stlexb %0, %2, %1" : "=&r" (result), "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" ); - return(result); + __ASM volatile("stlexb %0, %2, %1" : "=&r"(result), "=Q"(*ptr) : "r"((uint32_t)value) : "memory"); + return (result); } @@ -905,12 +858,11 @@ __STATIC_FORCEINLINE uint32_t __STLEXB(uint8_t value, volatile uint8_t *ptr) \return 0 Function succeeded \return 1 Function failed */ -__STATIC_FORCEINLINE uint32_t __STLEXH(uint16_t value, volatile uint16_t *ptr) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __STLEXH(uint16_t value, volatile uint16_t *ptr) { + uint32_t result; - __ASM volatile ("stlexh %0, %2, %1" : "=&r" (result), "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" ); - return(result); + __ASM volatile("stlexh %0, %2, %1" : "=&r"(result), "=Q"(*ptr) : "r"((uint32_t)value) : "memory"); + return (result); } @@ -922,12 +874,11 @@ __STATIC_FORCEINLINE uint32_t __STLEXH(uint16_t value, volatile uint16_t *ptr) \return 0 Function succeeded \return 1 Function failed */ -__STATIC_FORCEINLINE uint32_t __STLEX(uint32_t value, volatile uint32_t *ptr) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __STLEX(uint32_t value, volatile uint32_t *ptr) { + uint32_t result; - __ASM volatile ("stlex %0, %2, %1" : "=&r" (result), "=Q" (*ptr) : "r" ((uint32_t)value) : "memory" ); - return(result); + __ASM volatile("stlex %0, %2, %1" : "=&r"(result), "=Q"(*ptr) : "r"((uint32_t)value) : "memory"); + return (result); } #endif /* ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ @@ -947,9 +898,8 @@ __STATIC_FORCEINLINE uint32_t __STLEX(uint32_t value, volatile uint32_t *ptr) \details Enables IRQ interrupts by clearing special-purpose register PRIMASK. Can only be executed in Privileged modes. */ -__STATIC_FORCEINLINE void __enable_irq(void) -{ - __ASM volatile ("cpsie i" : : : "memory"); +__STATIC_FORCEINLINE void __enable_irq(void) { + __ASM volatile("cpsie i" : : : "memory"); } @@ -958,9 +908,8 @@ __STATIC_FORCEINLINE void __enable_irq(void) \details Disables IRQ interrupts by setting special-purpose register PRIMASK. Can only be executed in Privileged modes. */ -__STATIC_FORCEINLINE void __disable_irq(void) -{ - __ASM volatile ("cpsid i" : : : "memory"); +__STATIC_FORCEINLINE void __disable_irq(void) { + __ASM volatile("cpsid i" : : : "memory"); } @@ -969,12 +918,11 @@ __STATIC_FORCEINLINE void __disable_irq(void) \details Returns the content of the Control Register. \return Control Register value */ -__STATIC_FORCEINLINE uint32_t __get_CONTROL(void) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __get_CONTROL(void) { + uint32_t result; - __ASM volatile ("MRS %0, control" : "=r" (result) ); - return(result); + __ASM volatile("MRS %0, control" : "=r"(result)); + return (result); } @@ -984,12 +932,11 @@ __STATIC_FORCEINLINE uint32_t __get_CONTROL(void) \details Returns the content of the non-secure Control Register when in secure mode. \return non-secure Control Register value */ -__STATIC_FORCEINLINE uint32_t __TZ_get_CONTROL_NS(void) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __TZ_get_CONTROL_NS(void) { + uint32_t result; - __ASM volatile ("MRS %0, control_ns" : "=r" (result) ); - return(result); + __ASM volatile("MRS %0, control_ns" : "=r"(result)); + return (result); } #endif @@ -999,10 +946,9 @@ __STATIC_FORCEINLINE uint32_t __TZ_get_CONTROL_NS(void) \details Writes the given value to the Control Register. \param [in] control Control Register value to set */ -__STATIC_FORCEINLINE void __set_CONTROL(uint32_t control) -{ - __ASM volatile ("MSR control, %0" : : "r" (control) : "memory"); - __ISB(); +__STATIC_FORCEINLINE void __set_CONTROL(uint32_t control) { + __ASM volatile("MSR control, %0" : : "r"(control) : "memory"); + __ISB(); } @@ -1012,10 +958,9 @@ __STATIC_FORCEINLINE void __set_CONTROL(uint32_t control) \details Writes the given value to the non-secure Control Register when in secure state. \param [in] control Control Register value to set */ -__STATIC_FORCEINLINE void __TZ_set_CONTROL_NS(uint32_t control) -{ - __ASM volatile ("MSR control_ns, %0" : : "r" (control) : "memory"); - __ISB(); +__STATIC_FORCEINLINE void __TZ_set_CONTROL_NS(uint32_t control) { + __ASM volatile("MSR control_ns, %0" : : "r"(control) : "memory"); + __ISB(); } #endif @@ -1025,12 +970,11 @@ __STATIC_FORCEINLINE void __TZ_set_CONTROL_NS(uint32_t control) \details Returns the content of the IPSR Register. \return IPSR Register value */ -__STATIC_FORCEINLINE uint32_t __get_IPSR(void) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __get_IPSR(void) { + uint32_t result; - __ASM volatile ("MRS %0, ipsr" : "=r" (result) ); - return(result); + __ASM volatile("MRS %0, ipsr" : "=r"(result)); + return (result); } @@ -1039,12 +983,11 @@ __STATIC_FORCEINLINE uint32_t __get_IPSR(void) \details Returns the content of the APSR Register. \return APSR Register value */ -__STATIC_FORCEINLINE uint32_t __get_APSR(void) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __get_APSR(void) { + uint32_t result; - __ASM volatile ("MRS %0, apsr" : "=r" (result) ); - return(result); + __ASM volatile("MRS %0, apsr" : "=r"(result)); + return (result); } @@ -1053,12 +996,11 @@ __STATIC_FORCEINLINE uint32_t __get_APSR(void) \details Returns the content of the xPSR Register. \return xPSR Register value */ -__STATIC_FORCEINLINE uint32_t __get_xPSR(void) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __get_xPSR(void) { + uint32_t result; - __ASM volatile ("MRS %0, xpsr" : "=r" (result) ); - return(result); + __ASM volatile("MRS %0, xpsr" : "=r"(result)); + return (result); } @@ -1067,12 +1009,11 @@ __STATIC_FORCEINLINE uint32_t __get_xPSR(void) \details Returns the current value of the Process Stack Pointer (PSP). \return PSP Register value */ -__STATIC_FORCEINLINE uint32_t __get_PSP(void) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __get_PSP(void) { + uint32_t result; - __ASM volatile ("MRS %0, psp" : "=r" (result) ); - return(result); + __ASM volatile("MRS %0, psp" : "=r"(result)); + return (result); } @@ -1082,12 +1023,11 @@ __STATIC_FORCEINLINE uint32_t __get_PSP(void) \details Returns the current value of the non-secure Process Stack Pointer (PSP) when in secure state. \return PSP Register value */ -__STATIC_FORCEINLINE uint32_t __TZ_get_PSP_NS(void) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __TZ_get_PSP_NS(void) { + uint32_t result; - __ASM volatile ("MRS %0, psp_ns" : "=r" (result) ); - return(result); + __ASM volatile("MRS %0, psp_ns" : "=r"(result)); + return (result); } #endif @@ -1097,9 +1037,8 @@ __STATIC_FORCEINLINE uint32_t __TZ_get_PSP_NS(void) \details Assigns the given value to the Process Stack Pointer (PSP). \param [in] topOfProcStack Process Stack Pointer value to set */ -__STATIC_FORCEINLINE void __set_PSP(uint32_t topOfProcStack) -{ - __ASM volatile ("MSR psp, %0" : : "r" (topOfProcStack) : ); +__STATIC_FORCEINLINE void __set_PSP(uint32_t topOfProcStack) { + __ASM volatile("MSR psp, %0" : : "r"(topOfProcStack) :); } @@ -1109,9 +1048,8 @@ __STATIC_FORCEINLINE void __set_PSP(uint32_t topOfProcStack) \details Assigns the given value to the non-secure Process Stack Pointer (PSP) when in secure state. \param [in] topOfProcStack Process Stack Pointer value to set */ -__STATIC_FORCEINLINE void __TZ_set_PSP_NS(uint32_t topOfProcStack) -{ - __ASM volatile ("MSR psp_ns, %0" : : "r" (topOfProcStack) : ); +__STATIC_FORCEINLINE void __TZ_set_PSP_NS(uint32_t topOfProcStack) { + __ASM volatile("MSR psp_ns, %0" : : "r"(topOfProcStack) :); } #endif @@ -1121,12 +1059,11 @@ __STATIC_FORCEINLINE void __TZ_set_PSP_NS(uint32_t topOfProcStack) \details Returns the current value of the Main Stack Pointer (MSP). \return MSP Register value */ -__STATIC_FORCEINLINE uint32_t __get_MSP(void) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __get_MSP(void) { + uint32_t result; - __ASM volatile ("MRS %0, msp" : "=r" (result) ); - return(result); + __ASM volatile("MRS %0, msp" : "=r"(result)); + return (result); } @@ -1136,12 +1073,11 @@ __STATIC_FORCEINLINE uint32_t __get_MSP(void) \details Returns the current value of the non-secure Main Stack Pointer (MSP) when in secure state. \return MSP Register value */ -__STATIC_FORCEINLINE uint32_t __TZ_get_MSP_NS(void) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __TZ_get_MSP_NS(void) { + uint32_t result; - __ASM volatile ("MRS %0, msp_ns" : "=r" (result) ); - return(result); + __ASM volatile("MRS %0, msp_ns" : "=r"(result)); + return (result); } #endif @@ -1151,9 +1087,8 @@ __STATIC_FORCEINLINE uint32_t __TZ_get_MSP_NS(void) \details Assigns the given value to the Main Stack Pointer (MSP). \param [in] topOfMainStack Main Stack Pointer value to set */ -__STATIC_FORCEINLINE void __set_MSP(uint32_t topOfMainStack) -{ - __ASM volatile ("MSR msp, %0" : : "r" (topOfMainStack) : ); +__STATIC_FORCEINLINE void __set_MSP(uint32_t topOfMainStack) { + __ASM volatile("MSR msp, %0" : : "r"(topOfMainStack) :); } @@ -1163,9 +1098,8 @@ __STATIC_FORCEINLINE void __set_MSP(uint32_t topOfMainStack) \details Assigns the given value to the non-secure Main Stack Pointer (MSP) when in secure state. \param [in] topOfMainStack Main Stack Pointer value to set */ -__STATIC_FORCEINLINE void __TZ_set_MSP_NS(uint32_t topOfMainStack) -{ - __ASM volatile ("MSR msp_ns, %0" : : "r" (topOfMainStack) : ); +__STATIC_FORCEINLINE void __TZ_set_MSP_NS(uint32_t topOfMainStack) { + __ASM volatile("MSR msp_ns, %0" : : "r"(topOfMainStack) :); } #endif @@ -1176,12 +1110,11 @@ __STATIC_FORCEINLINE void __TZ_set_MSP_NS(uint32_t topOfMainStack) \details Returns the current value of the non-secure Stack Pointer (SP) when in secure state. \return SP Register value */ -__STATIC_FORCEINLINE uint32_t __TZ_get_SP_NS(void) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __TZ_get_SP_NS(void) { + uint32_t result; - __ASM volatile ("MRS %0, sp_ns" : "=r" (result) ); - return(result); + __ASM volatile("MRS %0, sp_ns" : "=r"(result)); + return (result); } @@ -1190,9 +1123,8 @@ __STATIC_FORCEINLINE uint32_t __TZ_get_SP_NS(void) \details Assigns the given value to the non-secure Stack Pointer (SP) when in secure state. \param [in] topOfStack Stack Pointer value to set */ -__STATIC_FORCEINLINE void __TZ_set_SP_NS(uint32_t topOfStack) -{ - __ASM volatile ("MSR sp_ns, %0" : : "r" (topOfStack) : ); +__STATIC_FORCEINLINE void __TZ_set_SP_NS(uint32_t topOfStack) { + __ASM volatile("MSR sp_ns, %0" : : "r"(topOfStack) :); } #endif @@ -1202,12 +1134,11 @@ __STATIC_FORCEINLINE void __TZ_set_SP_NS(uint32_t topOfStack) \details Returns the current state of the priority mask bit from the Priority Mask Register. \return Priority Mask value */ -__STATIC_FORCEINLINE uint32_t __get_PRIMASK(void) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __get_PRIMASK(void) { + uint32_t result; - __ASM volatile ("MRS %0, primask" : "=r" (result) ); - return(result); + __ASM volatile("MRS %0, primask" : "=r"(result)); + return (result); } @@ -1217,12 +1148,11 @@ __STATIC_FORCEINLINE uint32_t __get_PRIMASK(void) \details Returns the current state of the non-secure priority mask bit from the Priority Mask Register when in secure state. \return Priority Mask value */ -__STATIC_FORCEINLINE uint32_t __TZ_get_PRIMASK_NS(void) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __TZ_get_PRIMASK_NS(void) { + uint32_t result; - __ASM volatile ("MRS %0, primask_ns" : "=r" (result) ); - return(result); + __ASM volatile("MRS %0, primask_ns" : "=r"(result)); + return (result); } #endif @@ -1232,9 +1162,8 @@ __STATIC_FORCEINLINE uint32_t __TZ_get_PRIMASK_NS(void) \details Assigns the given value to the Priority Mask Register. \param [in] priMask Priority Mask */ -__STATIC_FORCEINLINE void __set_PRIMASK(uint32_t priMask) -{ - __ASM volatile ("MSR primask, %0" : : "r" (priMask) : "memory"); +__STATIC_FORCEINLINE void __set_PRIMASK(uint32_t priMask) { + __ASM volatile("MSR primask, %0" : : "r"(priMask) : "memory"); } @@ -1244,9 +1173,8 @@ __STATIC_FORCEINLINE void __set_PRIMASK(uint32_t priMask) \details Assigns the given value to the non-secure Priority Mask Register when in secure state. \param [in] priMask Priority Mask */ -__STATIC_FORCEINLINE void __TZ_set_PRIMASK_NS(uint32_t priMask) -{ - __ASM volatile ("MSR primask_ns, %0" : : "r" (priMask) : "memory"); +__STATIC_FORCEINLINE void __TZ_set_PRIMASK_NS(uint32_t priMask) { + __ASM volatile("MSR primask_ns, %0" : : "r"(priMask) : "memory"); } #endif @@ -1259,9 +1187,8 @@ __STATIC_FORCEINLINE void __TZ_set_PRIMASK_NS(uint32_t priMask) \details Enables FIQ interrupts by clearing special-purpose register FAULTMASK. Can only be executed in Privileged modes. */ -__STATIC_FORCEINLINE void __enable_fault_irq(void) -{ - __ASM volatile ("cpsie f" : : : "memory"); +__STATIC_FORCEINLINE void __enable_fault_irq(void) { + __ASM volatile("cpsie f" : : : "memory"); } @@ -1270,9 +1197,8 @@ __STATIC_FORCEINLINE void __enable_fault_irq(void) \details Disables FIQ interrupts by setting special-purpose register FAULTMASK. Can only be executed in Privileged modes. */ -__STATIC_FORCEINLINE void __disable_fault_irq(void) -{ - __ASM volatile ("cpsid f" : : : "memory"); +__STATIC_FORCEINLINE void __disable_fault_irq(void) { + __ASM volatile("cpsid f" : : : "memory"); } @@ -1281,12 +1207,11 @@ __STATIC_FORCEINLINE void __disable_fault_irq(void) \details Returns the current value of the Base Priority register. \return Base Priority register value */ -__STATIC_FORCEINLINE uint32_t __get_BASEPRI(void) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __get_BASEPRI(void) { + uint32_t result; - __ASM volatile ("MRS %0, basepri" : "=r" (result) ); - return(result); + __ASM volatile("MRS %0, basepri" : "=r"(result)); + return (result); } @@ -1296,12 +1221,11 @@ __STATIC_FORCEINLINE uint32_t __get_BASEPRI(void) \details Returns the current value of the non-secure Base Priority register when in secure state. \return Base Priority register value */ -__STATIC_FORCEINLINE uint32_t __TZ_get_BASEPRI_NS(void) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __TZ_get_BASEPRI_NS(void) { + uint32_t result; - __ASM volatile ("MRS %0, basepri_ns" : "=r" (result) ); - return(result); + __ASM volatile("MRS %0, basepri_ns" : "=r"(result)); + return (result); } #endif @@ -1311,9 +1235,8 @@ __STATIC_FORCEINLINE uint32_t __TZ_get_BASEPRI_NS(void) \details Assigns the given value to the Base Priority register. \param [in] basePri Base Priority value to set */ -__STATIC_FORCEINLINE void __set_BASEPRI(uint32_t basePri) -{ - __ASM volatile ("MSR basepri, %0" : : "r" (basePri) : "memory"); +__STATIC_FORCEINLINE void __set_BASEPRI(uint32_t basePri) { + __ASM volatile("MSR basepri, %0" : : "r"(basePri) : "memory"); } @@ -1323,9 +1246,8 @@ __STATIC_FORCEINLINE void __set_BASEPRI(uint32_t basePri) \details Assigns the given value to the non-secure Base Priority register when in secure state. \param [in] basePri Base Priority value to set */ -__STATIC_FORCEINLINE void __TZ_set_BASEPRI_NS(uint32_t basePri) -{ - __ASM volatile ("MSR basepri_ns, %0" : : "r" (basePri) : "memory"); +__STATIC_FORCEINLINE void __TZ_set_BASEPRI_NS(uint32_t basePri) { + __ASM volatile("MSR basepri_ns, %0" : : "r"(basePri) : "memory"); } #endif @@ -1336,9 +1258,8 @@ __STATIC_FORCEINLINE void __TZ_set_BASEPRI_NS(uint32_t basePri) or the new value increases the BASEPRI priority level. \param [in] basePri Base Priority value to set */ -__STATIC_FORCEINLINE void __set_BASEPRI_MAX(uint32_t basePri) -{ - __ASM volatile ("MSR basepri_max, %0" : : "r" (basePri) : "memory"); +__STATIC_FORCEINLINE void __set_BASEPRI_MAX(uint32_t basePri) { + __ASM volatile("MSR basepri_max, %0" : : "r"(basePri) : "memory"); } @@ -1347,12 +1268,11 @@ __STATIC_FORCEINLINE void __set_BASEPRI_MAX(uint32_t basePri) \details Returns the current value of the Fault Mask register. \return Fault Mask register value */ -__STATIC_FORCEINLINE uint32_t __get_FAULTMASK(void) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __get_FAULTMASK(void) { + uint32_t result; - __ASM volatile ("MRS %0, faultmask" : "=r" (result) ); - return(result); + __ASM volatile("MRS %0, faultmask" : "=r"(result)); + return (result); } @@ -1362,12 +1282,11 @@ __STATIC_FORCEINLINE uint32_t __get_FAULTMASK(void) \details Returns the current value of the non-secure Fault Mask register when in secure state. \return Fault Mask register value */ -__STATIC_FORCEINLINE uint32_t __TZ_get_FAULTMASK_NS(void) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __TZ_get_FAULTMASK_NS(void) { + uint32_t result; - __ASM volatile ("MRS %0, faultmask_ns" : "=r" (result) ); - return(result); + __ASM volatile("MRS %0, faultmask_ns" : "=r"(result)); + return (result); } #endif @@ -1377,9 +1296,8 @@ __STATIC_FORCEINLINE uint32_t __TZ_get_FAULTMASK_NS(void) \details Assigns the given value to the Fault Mask register. \param [in] faultMask Fault Mask value to set */ -__STATIC_FORCEINLINE void __set_FAULTMASK(uint32_t faultMask) -{ - __ASM volatile ("MSR faultmask, %0" : : "r" (faultMask) : "memory"); +__STATIC_FORCEINLINE void __set_FAULTMASK(uint32_t faultMask) { + __ASM volatile("MSR faultmask, %0" : : "r"(faultMask) : "memory"); } @@ -1389,9 +1307,8 @@ __STATIC_FORCEINLINE void __set_FAULTMASK(uint32_t faultMask) \details Assigns the given value to the non-secure Fault Mask register when in secure state. \param [in] faultMask Fault Mask value to set */ -__STATIC_FORCEINLINE void __TZ_set_FAULTMASK_NS(uint32_t faultMask) -{ - __ASM volatile ("MSR faultmask_ns, %0" : : "r" (faultMask) : "memory"); +__STATIC_FORCEINLINE void __TZ_set_FAULTMASK_NS(uint32_t faultMask) { + __ASM volatile("MSR faultmask_ns, %0" : : "r"(faultMask) : "memory"); } #endif @@ -1412,16 +1329,15 @@ __STATIC_FORCEINLINE void __TZ_set_FAULTMASK_NS(uint32_t faultMask) \details Returns the current value of the Process Stack Pointer Limit (PSPLIM). \return PSPLIM Register value */ -__STATIC_FORCEINLINE uint32_t __get_PSPLIM(void) -{ +__STATIC_FORCEINLINE uint32_t __get_PSPLIM(void) { #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))) // without main extensions, the non-secure PSPLIM is RAZ/WI - return 0U; + return 0U; #else - uint32_t result; - __ASM volatile ("MRS %0, psplim" : "=r" (result) ); - return result; + uint32_t result; + __ASM volatile("MRS %0, psplim" : "=r"(result)); + return result; #endif } @@ -1434,15 +1350,14 @@ __STATIC_FORCEINLINE uint32_t __get_PSPLIM(void) \details Returns the current value of the non-secure Process Stack Pointer Limit (PSPLIM) when in secure state. \return PSPLIM Register value */ -__STATIC_FORCEINLINE uint32_t __TZ_get_PSPLIM_NS(void) -{ +__STATIC_FORCEINLINE uint32_t __TZ_get_PSPLIM_NS(void) { #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1))) - // without main extensions, the non-secure PSPLIM is RAZ/WI - return 0U; + // without main extensions, the non-secure PSPLIM is RAZ/WI + return 0U; #else - uint32_t result; - __ASM volatile ("MRS %0, psplim_ns" : "=r" (result) ); - return result; + uint32_t result; + __ASM volatile("MRS %0, psplim_ns" : "=r"(result)); + return result; #endif } #endif @@ -1457,14 +1372,13 @@ __STATIC_FORCEINLINE uint32_t __TZ_get_PSPLIM_NS(void) \details Assigns the given value to the Process Stack Pointer Limit (PSPLIM). \param [in] ProcStackPtrLimit Process Stack Pointer Limit value to set */ -__STATIC_FORCEINLINE void __set_PSPLIM(uint32_t ProcStackPtrLimit) -{ +__STATIC_FORCEINLINE void __set_PSPLIM(uint32_t ProcStackPtrLimit) { #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))) - // without main extensions, the non-secure PSPLIM is RAZ/WI - (void)ProcStackPtrLimit; + // without main extensions, the non-secure PSPLIM is RAZ/WI + (void)ProcStackPtrLimit; #else - __ASM volatile ("MSR psplim, %0" : : "r" (ProcStackPtrLimit)); + __ASM volatile("MSR psplim, %0" : : "r"(ProcStackPtrLimit)); #endif } @@ -1478,13 +1392,12 @@ __STATIC_FORCEINLINE void __set_PSPLIM(uint32_t ProcStackPtrLimit) \details Assigns the given value to the non-secure Process Stack Pointer Limit (PSPLIM) when in secure state. \param [in] ProcStackPtrLimit Process Stack Pointer Limit value to set */ -__STATIC_FORCEINLINE void __TZ_set_PSPLIM_NS(uint32_t ProcStackPtrLimit) -{ +__STATIC_FORCEINLINE void __TZ_set_PSPLIM_NS(uint32_t ProcStackPtrLimit) { #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1))) - // without main extensions, the non-secure PSPLIM is RAZ/WI - (void)ProcStackPtrLimit; + // without main extensions, the non-secure PSPLIM is RAZ/WI + (void)ProcStackPtrLimit; #else - __ASM volatile ("MSR psplim_ns, %0\n" : : "r" (ProcStackPtrLimit)); + __ASM volatile("MSR psplim_ns, %0\n" : : "r"(ProcStackPtrLimit)); #endif } #endif @@ -1499,16 +1412,15 @@ __STATIC_FORCEINLINE void __TZ_set_PSPLIM_NS(uint32_t ProcStackPtrLimit) \details Returns the current value of the Main Stack Pointer Limit (MSPLIM). \return MSPLIM Register value */ -__STATIC_FORCEINLINE uint32_t __get_MSPLIM(void) -{ +__STATIC_FORCEINLINE uint32_t __get_MSPLIM(void) { #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))) - // without main extensions, the non-secure MSPLIM is RAZ/WI - return 0U; + // without main extensions, the non-secure MSPLIM is RAZ/WI + return 0U; #else - uint32_t result; - __ASM volatile ("MRS %0, msplim" : "=r" (result) ); - return result; + uint32_t result; + __ASM volatile("MRS %0, msplim" : "=r"(result)); + return result; #endif } @@ -1522,15 +1434,14 @@ __STATIC_FORCEINLINE uint32_t __get_MSPLIM(void) \details Returns the current value of the non-secure Main Stack Pointer Limit(MSPLIM) when in secure state. \return MSPLIM Register value */ -__STATIC_FORCEINLINE uint32_t __TZ_get_MSPLIM_NS(void) -{ +__STATIC_FORCEINLINE uint32_t __TZ_get_MSPLIM_NS(void) { #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1))) - // without main extensions, the non-secure MSPLIM is RAZ/WI - return 0U; + // without main extensions, the non-secure MSPLIM is RAZ/WI + return 0U; #else - uint32_t result; - __ASM volatile ("MRS %0, msplim_ns" : "=r" (result) ); - return result; + uint32_t result; + __ASM volatile("MRS %0, msplim_ns" : "=r"(result)); + return result; #endif } #endif @@ -1545,14 +1456,13 @@ __STATIC_FORCEINLINE uint32_t __TZ_get_MSPLIM_NS(void) \details Assigns the given value to the Main Stack Pointer Limit (MSPLIM). \param [in] MainStackPtrLimit Main Stack Pointer Limit value to set */ -__STATIC_FORCEINLINE void __set_MSPLIM(uint32_t MainStackPtrLimit) -{ +__STATIC_FORCEINLINE void __set_MSPLIM(uint32_t MainStackPtrLimit) { #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))) - // without main extensions, the non-secure MSPLIM is RAZ/WI - (void)MainStackPtrLimit; + // without main extensions, the non-secure MSPLIM is RAZ/WI + (void)MainStackPtrLimit; #else - __ASM volatile ("MSR msplim, %0" : : "r" (MainStackPtrLimit)); + __ASM volatile("MSR msplim, %0" : : "r"(MainStackPtrLimit)); #endif } @@ -1566,13 +1476,12 @@ __STATIC_FORCEINLINE void __set_MSPLIM(uint32_t MainStackPtrLimit) \details Assigns the given value to the non-secure Main Stack Pointer Limit (MSPLIM) when in secure state. \param [in] MainStackPtrLimit Main Stack Pointer value to set */ -__STATIC_FORCEINLINE void __TZ_set_MSPLIM_NS(uint32_t MainStackPtrLimit) -{ +__STATIC_FORCEINLINE void __TZ_set_MSPLIM_NS(uint32_t MainStackPtrLimit) { #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1))) - // without main extensions, the non-secure MSPLIM is RAZ/WI - (void)MainStackPtrLimit; + // without main extensions, the non-secure MSPLIM is RAZ/WI + (void)MainStackPtrLimit; #else - __ASM volatile ("MSR msplim_ns, %0" : : "r" (MainStackPtrLimit)); + __ASM volatile("MSR msplim_ns, %0" : : "r"(MainStackPtrLimit)); #endif } #endif @@ -1586,23 +1495,22 @@ __STATIC_FORCEINLINE void __TZ_set_MSPLIM_NS(uint32_t MainStackPtrLimit) \details Returns the current value of the Floating Point Status/Control register. \return Floating Point Status/Control register value */ -__STATIC_FORCEINLINE uint32_t __get_FPSCR(void) -{ +__STATIC_FORCEINLINE uint32_t __get_FPSCR(void) { #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \ (defined (__FPU_USED ) && (__FPU_USED == 1U)) ) #if __has_builtin(__builtin_arm_get_fpscr) // Re-enable using built-in when GCC has been fixed // || (__GNUC__ > 7) || (__GNUC__ == 7 && __GNUC_MINOR__ >= 2) - /* see https://gcc.gnu.org/ml/gcc-patches/2017-04/msg00443.html */ - return __builtin_arm_get_fpscr(); + /* see https://gcc.gnu.org/ml/gcc-patches/2017-04/msg00443.html */ + return __builtin_arm_get_fpscr(); #else - uint32_t result; + uint32_t result; - __ASM volatile ("VMRS %0, fpscr" : "=r" (result) ); - return(result); + __ASM volatile("VMRS %0, fpscr" : "=r"(result)); + return (result); #endif #else - return(0U); + return (0U); #endif } @@ -1612,20 +1520,19 @@ __STATIC_FORCEINLINE uint32_t __get_FPSCR(void) \details Assigns the given value to the Floating Point Status/Control register. \param [in] fpscr Floating Point Status/Control value to set */ -__STATIC_FORCEINLINE void __set_FPSCR(uint32_t fpscr) -{ +__STATIC_FORCEINLINE void __set_FPSCR(uint32_t fpscr) { #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \ (defined (__FPU_USED ) && (__FPU_USED == 1U)) ) #if __has_builtin(__builtin_arm_set_fpscr) // Re-enable using built-in when GCC has been fixed // || (__GNUC__ > 7) || (__GNUC__ == 7 && __GNUC_MINOR__ >= 2) - /* see https://gcc.gnu.org/ml/gcc-patches/2017-04/msg00443.html */ - __builtin_arm_set_fpscr(fpscr); + /* see https://gcc.gnu.org/ml/gcc-patches/2017-04/msg00443.html */ + __builtin_arm_set_fpscr(fpscr); #else - __ASM volatile ("VMSR fpscr, %0" : : "r" (fpscr) : "vfpcc", "memory"); + __ASM volatile("VMSR fpscr, %0" : : "r"(fpscr) : "vfpcc", "memory"); #endif #else - (void)fpscr; + (void)fpscr; #endif } @@ -1641,310 +1548,272 @@ __STATIC_FORCEINLINE void __set_FPSCR(uint32_t fpscr) #if (defined (__ARM_FEATURE_DSP) && (__ARM_FEATURE_DSP == 1)) -__STATIC_FORCEINLINE uint32_t __SADD8(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __SADD8(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM volatile ("sadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM volatile("sadd8 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __QADD8(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __QADD8(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM ("qadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM("qadd8 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __SHADD8(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __SHADD8(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM ("shadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM("shadd8 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __UADD8(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __UADD8(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM volatile ("uadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM volatile("uadd8 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __UQADD8(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __UQADD8(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM ("uqadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM("uqadd8 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __UHADD8(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __UHADD8(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM ("uhadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM("uhadd8 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __SSUB8(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __SSUB8(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM volatile ("ssub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM volatile("ssub8 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __QSUB8(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __QSUB8(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM ("qsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM("qsub8 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __SHSUB8(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __SHSUB8(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM ("shsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM("shsub8 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __USUB8(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __USUB8(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM volatile ("usub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM volatile("usub8 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __UQSUB8(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __UQSUB8(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM ("uqsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM("uqsub8 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __UHSUB8(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __UHSUB8(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM ("uhsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM("uhsub8 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __SADD16(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __SADD16(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM volatile ("sadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM volatile("sadd16 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __QADD16(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __QADD16(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM ("qadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM("qadd16 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __SHADD16(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __SHADD16(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM ("shadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM("shadd16 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __UADD16(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __UADD16(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM volatile ("uadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM volatile("uadd16 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __UQADD16(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __UQADD16(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM ("uqadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM("uqadd16 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __UHADD16(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __UHADD16(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM ("uhadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM("uhadd16 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __SSUB16(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __SSUB16(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM volatile ("ssub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM volatile("ssub16 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __QSUB16(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __QSUB16(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM ("qsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM("qsub16 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __SHSUB16(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __SHSUB16(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM ("shsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM("shsub16 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __USUB16(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __USUB16(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM volatile ("usub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM volatile("usub16 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __UQSUB16(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __UQSUB16(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM ("uqsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM("uqsub16 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __UHSUB16(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __UHSUB16(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM ("uhsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM("uhsub16 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __SASX(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __SASX(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM volatile ("sasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM volatile("sasx %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __QASX(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __QASX(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM ("qasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM("qasx %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __SHASX(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __SHASX(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM ("shasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM("shasx %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __UASX(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __UASX(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM volatile ("uasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM volatile("uasx %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __UQASX(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __UQASX(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM ("uqasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM("uqasx %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __UHASX(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __UHASX(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM ("uhasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM("uhasx %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __SSAX(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __SSAX(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM volatile ("ssax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM volatile("ssax %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __QSAX(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __QSAX(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM ("qsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM("qsax %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __SHSAX(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __SHSAX(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM ("shsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM("shsax %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __USAX(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __USAX(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM volatile ("usax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM volatile("usax %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __UQSAX(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __UQSAX(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM ("uqsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM("uqsax %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __UHSAX(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __UHSAX(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM ("uhsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM("uhsax %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __USAD8(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __USAD8(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM ("usad8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM("usad8 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __USADA8(uint32_t op1, uint32_t op2, uint32_t op3) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __USADA8(uint32_t op1, uint32_t op2, uint32_t op3) { + uint32_t result; - __ASM ("usada8 %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) ); - return(result); + __ASM("usada8 %0, %1, %2, %3" : "=r"(result) : "r"(op1), "r"(op2), "r"(op3)); + return (result); } #define __SSAT16(ARG1, ARG2) \ @@ -1963,215 +1832,194 @@ __extension__ \ __RES; \ }) -__STATIC_FORCEINLINE uint32_t __UXTB16(uint32_t op1) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __UXTB16(uint32_t op1) { + uint32_t result; - __ASM ("uxtb16 %0, %1" : "=r" (result) : "r" (op1)); - return(result); + __ASM("uxtb16 %0, %1" : "=r"(result) : "r"(op1)); + return (result); } -__STATIC_FORCEINLINE uint32_t __UXTAB16(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __UXTAB16(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM ("uxtab16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM("uxtab16 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __SXTB16(uint32_t op1) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __SXTB16(uint32_t op1) { + uint32_t result; - __ASM ("sxtb16 %0, %1" : "=r" (result) : "r" (op1)); - return(result); + __ASM("sxtb16 %0, %1" : "=r"(result) : "r"(op1)); + return (result); } -__STATIC_FORCEINLINE uint32_t __SXTB16_RORn(uint32_t op1, uint32_t rotate) -{ - uint32_t result; - if (__builtin_constant_p(rotate) && ((rotate == 8U) || (rotate == 16U) || (rotate == 24U))) { - __ASM volatile ("sxtb16 %0, %1, ROR %2" : "=r" (result) : "r" (op1), "i" (rotate) ); - } else { - result = __SXTB16(__ROR(op1, rotate)) ; - } - return result; +__STATIC_FORCEINLINE uint32_t __SXTB16_RORn(uint32_t op1, uint32_t rotate) { + uint32_t result; + if (__builtin_constant_p(rotate) && ((rotate == 8U) || (rotate == 16U) || (rotate == 24U))) { + __ASM volatile("sxtb16 %0, %1, ROR %2" : "=r"(result) : "r"(op1), "i"(rotate)); + } else { + result = __SXTB16(__ROR(op1, rotate)) ; + } + return result; } -__STATIC_FORCEINLINE uint32_t __SXTAB16(uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __SXTAB16(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM ("sxtab16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM("sxtab16 %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __SXTAB16_RORn(uint32_t op1, uint32_t op2, uint32_t rotate) -{ - uint32_t result; - if (__builtin_constant_p(rotate) && ((rotate == 8U) || (rotate == 16U) || (rotate == 24U))) { - __ASM volatile ("sxtab16 %0, %1, %2, ROR %3" : "=r" (result) : "r" (op1) , "r" (op2) , "i" (rotate)); - } else { - result = __SXTAB16(op1, __ROR(op2, rotate)); - } - return result; +__STATIC_FORCEINLINE uint32_t __SXTAB16_RORn(uint32_t op1, uint32_t op2, uint32_t rotate) { + uint32_t result; + if (__builtin_constant_p(rotate) && ((rotate == 8U) || (rotate == 16U) || (rotate == 24U))) { + __ASM volatile("sxtab16 %0, %1, %2, ROR %3" : "=r"(result) : "r"(op1), "r"(op2), "i"(rotate)); + } else { + result = __SXTAB16(op1, __ROR(op2, rotate)); + } + return result; } -__STATIC_FORCEINLINE uint32_t __SMUAD (uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __SMUAD(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM volatile ("smuad %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM volatile("smuad %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __SMUADX (uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __SMUADX(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM volatile ("smuadx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM volatile("smuadx %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __SMLAD (uint32_t op1, uint32_t op2, uint32_t op3) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __SMLAD(uint32_t op1, uint32_t op2, uint32_t op3) { + uint32_t result; - __ASM volatile ("smlad %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) ); - return(result); + __ASM volatile("smlad %0, %1, %2, %3" : "=r"(result) : "r"(op1), "r"(op2), "r"(op3)); + return (result); } -__STATIC_FORCEINLINE uint32_t __SMLADX (uint32_t op1, uint32_t op2, uint32_t op3) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __SMLADX(uint32_t op1, uint32_t op2, uint32_t op3) { + uint32_t result; - __ASM volatile ("smladx %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) ); - return(result); + __ASM volatile("smladx %0, %1, %2, %3" : "=r"(result) : "r"(op1), "r"(op2), "r"(op3)); + return (result); } -__STATIC_FORCEINLINE uint64_t __SMLALD (uint32_t op1, uint32_t op2, uint64_t acc) -{ - union llreg_u{ - uint32_t w32[2]; - uint64_t w64; - } llr; - llr.w64 = acc; +__STATIC_FORCEINLINE uint64_t __SMLALD(uint32_t op1, uint32_t op2, uint64_t acc) { + union llreg_u { + uint32_t w32[2]; + uint64_t w64; + } llr; + llr.w64 = acc; #ifndef __ARMEB__ /* Little endian */ - __ASM volatile ("smlald %0, %1, %2, %3" : "=r" (llr.w32[0]), "=r" (llr.w32[1]): "r" (op1), "r" (op2) , "0" (llr.w32[0]), "1" (llr.w32[1]) ); + __ASM volatile("smlald %0, %1, %2, %3" : "=r"(llr.w32[0]), "=r"(llr.w32[1]): "r"(op1), "r"(op2), "0"(llr.w32[0]), "1"(llr.w32[1])); #else /* Big endian */ - __ASM volatile ("smlald %0, %1, %2, %3" : "=r" (llr.w32[1]), "=r" (llr.w32[0]): "r" (op1), "r" (op2) , "0" (llr.w32[1]), "1" (llr.w32[0]) ); + __ASM volatile("smlald %0, %1, %2, %3" : "=r"(llr.w32[1]), "=r"(llr.w32[0]): "r"(op1), "r"(op2), "0"(llr.w32[1]), "1"(llr.w32[0])); #endif - return(llr.w64); + return (llr.w64); } -__STATIC_FORCEINLINE uint64_t __SMLALDX (uint32_t op1, uint32_t op2, uint64_t acc) -{ - union llreg_u{ - uint32_t w32[2]; - uint64_t w64; - } llr; - llr.w64 = acc; +__STATIC_FORCEINLINE uint64_t __SMLALDX(uint32_t op1, uint32_t op2, uint64_t acc) { + union llreg_u { + uint32_t w32[2]; + uint64_t w64; + } llr; + llr.w64 = acc; #ifndef __ARMEB__ /* Little endian */ - __ASM volatile ("smlaldx %0, %1, %2, %3" : "=r" (llr.w32[0]), "=r" (llr.w32[1]): "r" (op1), "r" (op2) , "0" (llr.w32[0]), "1" (llr.w32[1]) ); + __ASM volatile("smlaldx %0, %1, %2, %3" : "=r"(llr.w32[0]), "=r"(llr.w32[1]): "r"(op1), "r"(op2), "0"(llr.w32[0]), "1"(llr.w32[1])); #else /* Big endian */ - __ASM volatile ("smlaldx %0, %1, %2, %3" : "=r" (llr.w32[1]), "=r" (llr.w32[0]): "r" (op1), "r" (op2) , "0" (llr.w32[1]), "1" (llr.w32[0]) ); + __ASM volatile("smlaldx %0, %1, %2, %3" : "=r"(llr.w32[1]), "=r"(llr.w32[0]): "r"(op1), "r"(op2), "0"(llr.w32[1]), "1"(llr.w32[0])); #endif - return(llr.w64); + return (llr.w64); } -__STATIC_FORCEINLINE uint32_t __SMUSD (uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __SMUSD(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM volatile ("smusd %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM volatile("smusd %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __SMUSDX (uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __SMUSDX(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM volatile ("smusdx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM volatile("smusdx %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE uint32_t __SMLSD (uint32_t op1, uint32_t op2, uint32_t op3) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __SMLSD(uint32_t op1, uint32_t op2, uint32_t op3) { + uint32_t result; - __ASM volatile ("smlsd %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) ); - return(result); + __ASM volatile("smlsd %0, %1, %2, %3" : "=r"(result) : "r"(op1), "r"(op2), "r"(op3)); + return (result); } -__STATIC_FORCEINLINE uint32_t __SMLSDX (uint32_t op1, uint32_t op2, uint32_t op3) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __SMLSDX(uint32_t op1, uint32_t op2, uint32_t op3) { + uint32_t result; - __ASM volatile ("smlsdx %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) ); - return(result); + __ASM volatile("smlsdx %0, %1, %2, %3" : "=r"(result) : "r"(op1), "r"(op2), "r"(op3)); + return (result); } -__STATIC_FORCEINLINE uint64_t __SMLSLD (uint32_t op1, uint32_t op2, uint64_t acc) -{ - union llreg_u{ - uint32_t w32[2]; - uint64_t w64; - } llr; - llr.w64 = acc; +__STATIC_FORCEINLINE uint64_t __SMLSLD(uint32_t op1, uint32_t op2, uint64_t acc) { + union llreg_u { + uint32_t w32[2]; + uint64_t w64; + } llr; + llr.w64 = acc; #ifndef __ARMEB__ /* Little endian */ - __ASM volatile ("smlsld %0, %1, %2, %3" : "=r" (llr.w32[0]), "=r" (llr.w32[1]): "r" (op1), "r" (op2) , "0" (llr.w32[0]), "1" (llr.w32[1]) ); + __ASM volatile("smlsld %0, %1, %2, %3" : "=r"(llr.w32[0]), "=r"(llr.w32[1]): "r"(op1), "r"(op2), "0"(llr.w32[0]), "1"(llr.w32[1])); #else /* Big endian */ - __ASM volatile ("smlsld %0, %1, %2, %3" : "=r" (llr.w32[1]), "=r" (llr.w32[0]): "r" (op1), "r" (op2) , "0" (llr.w32[1]), "1" (llr.w32[0]) ); + __ASM volatile("smlsld %0, %1, %2, %3" : "=r"(llr.w32[1]), "=r"(llr.w32[0]): "r"(op1), "r"(op2), "0"(llr.w32[1]), "1"(llr.w32[0])); #endif - return(llr.w64); + return (llr.w64); } -__STATIC_FORCEINLINE uint64_t __SMLSLDX (uint32_t op1, uint32_t op2, uint64_t acc) -{ - union llreg_u{ - uint32_t w32[2]; - uint64_t w64; - } llr; - llr.w64 = acc; +__STATIC_FORCEINLINE uint64_t __SMLSLDX(uint32_t op1, uint32_t op2, uint64_t acc) { + union llreg_u { + uint32_t w32[2]; + uint64_t w64; + } llr; + llr.w64 = acc; #ifndef __ARMEB__ /* Little endian */ - __ASM volatile ("smlsldx %0, %1, %2, %3" : "=r" (llr.w32[0]), "=r" (llr.w32[1]): "r" (op1), "r" (op2) , "0" (llr.w32[0]), "1" (llr.w32[1]) ); + __ASM volatile("smlsldx %0, %1, %2, %3" : "=r"(llr.w32[0]), "=r"(llr.w32[1]): "r"(op1), "r"(op2), "0"(llr.w32[0]), "1"(llr.w32[1])); #else /* Big endian */ - __ASM volatile ("smlsldx %0, %1, %2, %3" : "=r" (llr.w32[1]), "=r" (llr.w32[0]): "r" (op1), "r" (op2) , "0" (llr.w32[1]), "1" (llr.w32[0]) ); + __ASM volatile("smlsldx %0, %1, %2, %3" : "=r"(llr.w32[1]), "=r"(llr.w32[0]): "r"(op1), "r"(op2), "0"(llr.w32[1]), "1"(llr.w32[0])); #endif - return(llr.w64); + return (llr.w64); } -__STATIC_FORCEINLINE uint32_t __SEL (uint32_t op1, uint32_t op2) -{ - uint32_t result; +__STATIC_FORCEINLINE uint32_t __SEL(uint32_t op1, uint32_t op2) { + uint32_t result; - __ASM volatile ("sel %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM volatile("sel %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE int32_t __QADD( int32_t op1, int32_t op2) -{ - int32_t result; +__STATIC_FORCEINLINE int32_t __QADD(int32_t op1, int32_t op2) { + int32_t result; - __ASM volatile ("qadd %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM volatile("qadd %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } -__STATIC_FORCEINLINE int32_t __QSUB( int32_t op1, int32_t op2) -{ - int32_t result; +__STATIC_FORCEINLINE int32_t __QSUB(int32_t op1, int32_t op2) { + int32_t result; - __ASM volatile ("qsub %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); - return(result); + __ASM volatile("qsub %0, %1, %2" : "=r"(result) : "r"(op1), "r"(op2)); + return (result); } @@ -2195,12 +2043,11 @@ __extension__ \ }) -__STATIC_FORCEINLINE int32_t __SMMLA (int32_t op1, int32_t op2, int32_t op3) -{ - int32_t result; +__STATIC_FORCEINLINE int32_t __SMMLA(int32_t op1, int32_t op2, int32_t op3) { + int32_t result; - __ASM ("smmla %0, %1, %2, %3" : "=r" (result): "r" (op1), "r" (op2), "r" (op3) ); - return(result); + __ASM("smmla %0, %1, %2, %3" : "=r"(result): "r"(op1), "r"(op2), "r"(op3)); + return (result); } #endif /* (__ARM_FEATURE_DSP == 1) */ diff --git a/armlib/at32_sys/cmsis/cm4/core_support/cmsis_iccarm.h b/armlib/at32_sys/cmsis/cm4/core_support/cmsis_iccarm.h index 65b824b00..ac6d1aba6 100644 --- a/armlib/at32_sys/cmsis/cm4/core_support/cmsis_iccarm.h +++ b/armlib/at32_sys/cmsis/cm4/core_support/cmsis_iccarm.h @@ -30,7 +30,7 @@ #define __CMSIS_ICCARM_H__ #ifndef __ICCARM__ - #error This file should only be compiled by ICCARM +#error This file should only be compiled by ICCARM #endif #pragma system_include @@ -38,21 +38,21 @@ #define __IAR_FT _Pragma("inline=forced") __intrinsic #if (__VER__ >= 8000000) - #define __ICCARM_V8 1 +#define __ICCARM_V8 1 #else - #define __ICCARM_V8 0 +#define __ICCARM_V8 0 #endif #ifndef __ALIGNED - #if __ICCARM_V8 - #define __ALIGNED(x) __attribute__((aligned(x))) - #elif (__VER__ >= 7080000) - /* Needs IAR language extensions */ - #define __ALIGNED(x) __attribute__((aligned(x))) - #else - #warning No compiler specific solution for __ALIGNED.__ALIGNED is ignored. - #define __ALIGNED(x) - #endif +#if __ICCARM_V8 +#define __ALIGNED(x) __attribute__((aligned(x))) +#elif (__VER__ >= 7080000) +/* Needs IAR language extensions */ +#define __ALIGNED(x) __attribute__((aligned(x))) +#else +#warning No compiler specific solution for __ALIGNED.__ALIGNED is ignored. +#define __ALIGNED(x) +#endif #endif @@ -61,128 +61,127 @@ #if __ARM_ARCH_6M__ || __ARM_ARCH_7M__ || __ARM_ARCH_7EM__ || __ARM_ARCH_8M_BASE__ || __ARM_ARCH_8M_MAIN__ /* Macros already defined */ #else - #if defined(__ARM8M_MAINLINE__) || defined(__ARM8EM_MAINLINE__) - #define __ARM_ARCH_8M_MAIN__ 1 - #elif defined(__ARM8M_BASELINE__) - #define __ARM_ARCH_8M_BASE__ 1 - #elif defined(__ARM_ARCH_PROFILE) && __ARM_ARCH_PROFILE == 'M' - #if __ARM_ARCH == 6 - #define __ARM_ARCH_6M__ 1 - #elif __ARM_ARCH == 7 - #if __ARM_FEATURE_DSP - #define __ARM_ARCH_7EM__ 1 - #else - #define __ARM_ARCH_7M__ 1 - #endif - #endif /* __ARM_ARCH */ - #endif /* __ARM_ARCH_PROFILE == 'M' */ +#if defined(__ARM8M_MAINLINE__) || defined(__ARM8EM_MAINLINE__) +#define __ARM_ARCH_8M_MAIN__ 1 +#elif defined(__ARM8M_BASELINE__) +#define __ARM_ARCH_8M_BASE__ 1 +#elif defined(__ARM_ARCH_PROFILE) && __ARM_ARCH_PROFILE == 'M' +#if __ARM_ARCH == 6 +#define __ARM_ARCH_6M__ 1 +#elif __ARM_ARCH == 7 +#if __ARM_FEATURE_DSP +#define __ARM_ARCH_7EM__ 1 +#else +#define __ARM_ARCH_7M__ 1 +#endif +#endif /* __ARM_ARCH */ +#endif /* __ARM_ARCH_PROFILE == 'M' */ #endif /* Alternativ core deduction for older ICCARM's */ #if !defined(__ARM_ARCH_6M__) && !defined(__ARM_ARCH_7M__) && !defined(__ARM_ARCH_7EM__) && \ !defined(__ARM_ARCH_8M_BASE__) && !defined(__ARM_ARCH_8M_MAIN__) - #if defined(__ARM6M__) && (__CORE__ == __ARM6M__) - #define __ARM_ARCH_6M__ 1 - #elif defined(__ARM7M__) && (__CORE__ == __ARM7M__) - #define __ARM_ARCH_7M__ 1 - #elif defined(__ARM7EM__) && (__CORE__ == __ARM7EM__) - #define __ARM_ARCH_7EM__ 1 - #elif defined(__ARM8M_BASELINE__) && (__CORE == __ARM8M_BASELINE__) - #define __ARM_ARCH_8M_BASE__ 1 - #elif defined(__ARM8M_MAINLINE__) && (__CORE == __ARM8M_MAINLINE__) - #define __ARM_ARCH_8M_MAIN__ 1 - #elif defined(__ARM8EM_MAINLINE__) && (__CORE == __ARM8EM_MAINLINE__) - #define __ARM_ARCH_8M_MAIN__ 1 - #else - #error "Unknown target." - #endif +#if defined(__ARM6M__) && (__CORE__ == __ARM6M__) +#define __ARM_ARCH_6M__ 1 +#elif defined(__ARM7M__) && (__CORE__ == __ARM7M__) +#define __ARM_ARCH_7M__ 1 +#elif defined(__ARM7EM__) && (__CORE__ == __ARM7EM__) +#define __ARM_ARCH_7EM__ 1 +#elif defined(__ARM8M_BASELINE__) && (__CORE == __ARM8M_BASELINE__) +#define __ARM_ARCH_8M_BASE__ 1 +#elif defined(__ARM8M_MAINLINE__) && (__CORE == __ARM8M_MAINLINE__) +#define __ARM_ARCH_8M_MAIN__ 1 +#elif defined(__ARM8EM_MAINLINE__) && (__CORE == __ARM8EM_MAINLINE__) +#define __ARM_ARCH_8M_MAIN__ 1 +#else +#error "Unknown target." +#endif #endif #if defined(__ARM_ARCH_6M__) && __ARM_ARCH_6M__==1 - #define __IAR_M0_FAMILY 1 +#define __IAR_M0_FAMILY 1 #elif defined(__ARM_ARCH_8M_BASE__) && __ARM_ARCH_8M_BASE__==1 - #define __IAR_M0_FAMILY 1 +#define __IAR_M0_FAMILY 1 #else - #define __IAR_M0_FAMILY 0 +#define __IAR_M0_FAMILY 0 #endif #ifndef __ASM - #define __ASM __asm +#define __ASM __asm #endif #ifndef __COMPILER_BARRIER - #define __COMPILER_BARRIER() __ASM volatile("":::"memory") +#define __COMPILER_BARRIER() __ASM volatile("":::"memory") #endif #ifndef __INLINE - #define __INLINE inline +#define __INLINE inline #endif #ifndef __NO_RETURN - #if __ICCARM_V8 - #define __NO_RETURN __attribute__((__noreturn__)) - #else - #define __NO_RETURN _Pragma("object_attribute=__noreturn") - #endif +#if __ICCARM_V8 +#define __NO_RETURN __attribute__((__noreturn__)) +#else +#define __NO_RETURN _Pragma("object_attribute=__noreturn") +#endif #endif #ifndef __PACKED - #if __ICCARM_V8 - #define __PACKED __attribute__((packed, aligned(1))) - #else - /* Needs IAR language extensions */ - #define __PACKED __packed - #endif +#if __ICCARM_V8 +#define __PACKED __attribute__((packed, aligned(1))) +#else +/* Needs IAR language extensions */ +#define __PACKED __packed +#endif #endif #ifndef __PACKED_STRUCT - #if __ICCARM_V8 - #define __PACKED_STRUCT struct __attribute__((packed, aligned(1))) - #else - /* Needs IAR language extensions */ - #define __PACKED_STRUCT __packed struct - #endif +#if __ICCARM_V8 +#define __PACKED_STRUCT struct __attribute__((packed, aligned(1))) +#else +/* Needs IAR language extensions */ +#define __PACKED_STRUCT __packed struct +#endif #endif #ifndef __PACKED_UNION - #if __ICCARM_V8 - #define __PACKED_UNION union __attribute__((packed, aligned(1))) - #else - /* Needs IAR language extensions */ - #define __PACKED_UNION __packed union - #endif +#if __ICCARM_V8 +#define __PACKED_UNION union __attribute__((packed, aligned(1))) +#else +/* Needs IAR language extensions */ +#define __PACKED_UNION __packed union +#endif #endif #ifndef __RESTRICT - #if __ICCARM_V8 - #define __RESTRICT __restrict - #else - /* Needs IAR language extensions */ - #define __RESTRICT restrict - #endif +#if __ICCARM_V8 +#define __RESTRICT __restrict +#else +/* Needs IAR language extensions */ +#define __RESTRICT restrict +#endif #endif #ifndef __STATIC_INLINE - #define __STATIC_INLINE static inline +#define __STATIC_INLINE static inline #endif #ifndef __FORCEINLINE - #define __FORCEINLINE _Pragma("inline=forced") +#define __FORCEINLINE _Pragma("inline=forced") #endif #ifndef __STATIC_FORCEINLINE - #define __STATIC_FORCEINLINE __FORCEINLINE __STATIC_INLINE +#define __STATIC_FORCEINLINE __FORCEINLINE __STATIC_INLINE #endif #ifndef __UNALIGNED_UINT16_READ #pragma language=save #pragma language=extended -__IAR_FT uint16_t __iar_uint16_read(void const *ptr) -{ - return *(__packed uint16_t*)(ptr); +__IAR_FT uint16_t __iar_uint16_read(void const *ptr) { + return *(__packed uint16_t *)(ptr); } #pragma language=restore #define __UNALIGNED_UINT16_READ(PTR) __iar_uint16_read(PTR) @@ -192,9 +191,8 @@ __IAR_FT uint16_t __iar_uint16_read(void const *ptr) #ifndef __UNALIGNED_UINT16_WRITE #pragma language=save #pragma language=extended -__IAR_FT void __iar_uint16_write(void const *ptr, uint16_t val) -{ - *(__packed uint16_t*)(ptr) = val;; +__IAR_FT void __iar_uint16_write(void const *ptr, uint16_t val) { + *(__packed uint16_t *)(ptr) = val;; } #pragma language=restore #define __UNALIGNED_UINT16_WRITE(PTR,VAL) __iar_uint16_write(PTR,VAL) @@ -203,9 +201,8 @@ __IAR_FT void __iar_uint16_write(void const *ptr, uint16_t val) #ifndef __UNALIGNED_UINT32_READ #pragma language=save #pragma language=extended -__IAR_FT uint32_t __iar_uint32_read(void const *ptr) -{ - return *(__packed uint32_t*)(ptr); +__IAR_FT uint32_t __iar_uint32_read(void const *ptr) { + return *(__packed uint32_t *)(ptr); } #pragma language=restore #define __UNALIGNED_UINT32_READ(PTR) __iar_uint32_read(PTR) @@ -214,9 +211,8 @@ __IAR_FT uint32_t __iar_uint32_read(void const *ptr) #ifndef __UNALIGNED_UINT32_WRITE #pragma language=save #pragma language=extended -__IAR_FT void __iar_uint32_write(void const *ptr, uint32_t val) -{ - *(__packed uint32_t*)(ptr) = val;; +__IAR_FT void __iar_uint32_write(void const *ptr, uint32_t val) { + *(__packed uint32_t *)(ptr) = val;; } #pragma language=restore #define __UNALIGNED_UINT32_WRITE(PTR,VAL) __iar_uint32_write(PTR,VAL) @@ -231,20 +227,20 @@ __packed struct __iar_u32 { uint32_t v; }; #endif #ifndef __USED - #if __ICCARM_V8 - #define __USED __attribute__((used)) - #else - #define __USED _Pragma("__root") - #endif +#if __ICCARM_V8 +#define __USED __attribute__((used)) +#else +#define __USED _Pragma("__root") +#endif #endif #undef __WEAK /* undo the definition from DLib_Defaults.h */ #ifndef __WEAK - #if __ICCARM_V8 - #define __WEAK __attribute__((weak)) - #else - #define __WEAK _Pragma("__weak") - #endif +#if __ICCARM_V8 +#define __WEAK __attribute__((weak)) +#else +#define __WEAK _Pragma("__weak") +#endif #endif #ifndef __PROGRAM_START @@ -280,627 +276,576 @@ __packed struct __iar_u32 { uint32_t v; }; #define __TZ_STACK_SEAL_VALUE 0xFEF5EDA5FEF5EDA5ULL #endif -__STATIC_FORCEINLINE void __TZ_set_STACKSEAL_S (uint32_t* stackTop) { - *((uint64_t *)stackTop) = __TZ_STACK_SEAL_VALUE; +__STATIC_FORCEINLINE void __TZ_set_STACKSEAL_S(uint32_t *stackTop) { + *((uint64_t *)stackTop) = __TZ_STACK_SEAL_VALUE; } #endif #ifndef __ICCARM_INTRINSICS_VERSION__ - #define __ICCARM_INTRINSICS_VERSION__ 0 +#define __ICCARM_INTRINSICS_VERSION__ 0 #endif #if __ICCARM_INTRINSICS_VERSION__ == 2 - #if defined(__CLZ) - #undef __CLZ - #endif - #if defined(__REVSH) - #undef __REVSH - #endif - #if defined(__RBIT) - #undef __RBIT - #endif - #if defined(__SSAT) - #undef __SSAT - #endif - #if defined(__USAT) - #undef __USAT - #endif +#if defined(__CLZ) +#undef __CLZ +#endif +#if defined(__REVSH) +#undef __REVSH +#endif +#if defined(__RBIT) +#undef __RBIT +#endif +#if defined(__SSAT) +#undef __SSAT +#endif +#if defined(__USAT) +#undef __USAT +#endif - #include "iccarm_builtin.h" +#include "iccarm_builtin.h" - #define __disable_fault_irq __iar_builtin_disable_fiq - #define __disable_irq __iar_builtin_disable_interrupt - #define __enable_fault_irq __iar_builtin_enable_fiq - #define __enable_irq __iar_builtin_enable_interrupt - #define __arm_rsr __iar_builtin_rsr - #define __arm_wsr __iar_builtin_wsr +#define __disable_fault_irq __iar_builtin_disable_fiq +#define __disable_irq __iar_builtin_disable_interrupt +#define __enable_fault_irq __iar_builtin_enable_fiq +#define __enable_irq __iar_builtin_enable_interrupt +#define __arm_rsr __iar_builtin_rsr +#define __arm_wsr __iar_builtin_wsr - #define __get_APSR() (__arm_rsr("APSR")) - #define __get_BASEPRI() (__arm_rsr("BASEPRI")) - #define __get_CONTROL() (__arm_rsr("CONTROL")) - #define __get_FAULTMASK() (__arm_rsr("FAULTMASK")) +#define __get_APSR() (__arm_rsr("APSR")) +#define __get_BASEPRI() (__arm_rsr("BASEPRI")) +#define __get_CONTROL() (__arm_rsr("CONTROL")) +#define __get_FAULTMASK() (__arm_rsr("FAULTMASK")) - #if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \ +#if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \ (defined (__FPU_USED ) && (__FPU_USED == 1U)) ) - #define __get_FPSCR() (__arm_rsr("FPSCR")) - #define __set_FPSCR(VALUE) (__arm_wsr("FPSCR", (VALUE))) - #else - #define __get_FPSCR() ( 0 ) - #define __set_FPSCR(VALUE) ((void)VALUE) - #endif +#define __get_FPSCR() (__arm_rsr("FPSCR")) +#define __set_FPSCR(VALUE) (__arm_wsr("FPSCR", (VALUE))) +#else +#define __get_FPSCR() ( 0 ) +#define __set_FPSCR(VALUE) ((void)VALUE) +#endif - #define __get_IPSR() (__arm_rsr("IPSR")) - #define __get_MSP() (__arm_rsr("MSP")) - #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ +#define __get_IPSR() (__arm_rsr("IPSR")) +#define __get_MSP() (__arm_rsr("MSP")) +#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))) - // without main extensions, the non-secure MSPLIM is RAZ/WI - #define __get_MSPLIM() (0U) - #else - #define __get_MSPLIM() (__arm_rsr("MSPLIM")) - #endif - #define __get_PRIMASK() (__arm_rsr("PRIMASK")) - #define __get_PSP() (__arm_rsr("PSP")) +// without main extensions, the non-secure MSPLIM is RAZ/WI +#define __get_MSPLIM() (0U) +#else +#define __get_MSPLIM() (__arm_rsr("MSPLIM")) +#endif +#define __get_PRIMASK() (__arm_rsr("PRIMASK")) +#define __get_PSP() (__arm_rsr("PSP")) - #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ +#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))) - // without main extensions, the non-secure PSPLIM is RAZ/WI - #define __get_PSPLIM() (0U) - #else - #define __get_PSPLIM() (__arm_rsr("PSPLIM")) - #endif +// without main extensions, the non-secure PSPLIM is RAZ/WI +#define __get_PSPLIM() (0U) +#else +#define __get_PSPLIM() (__arm_rsr("PSPLIM")) +#endif - #define __get_xPSR() (__arm_rsr("xPSR")) +#define __get_xPSR() (__arm_rsr("xPSR")) - #define __set_BASEPRI(VALUE) (__arm_wsr("BASEPRI", (VALUE))) - #define __set_BASEPRI_MAX(VALUE) (__arm_wsr("BASEPRI_MAX", (VALUE))) +#define __set_BASEPRI(VALUE) (__arm_wsr("BASEPRI", (VALUE))) +#define __set_BASEPRI_MAX(VALUE) (__arm_wsr("BASEPRI_MAX", (VALUE))) -__STATIC_FORCEINLINE void __set_CONTROL(uint32_t control) -{ - __arm_wsr("CONTROL", control); - __iar_builtin_ISB(); +__STATIC_FORCEINLINE void __set_CONTROL(uint32_t control) { + __arm_wsr("CONTROL", control); + __iar_builtin_ISB(); } - #define __set_FAULTMASK(VALUE) (__arm_wsr("FAULTMASK", (VALUE))) - #define __set_MSP(VALUE) (__arm_wsr("MSP", (VALUE))) +#define __set_FAULTMASK(VALUE) (__arm_wsr("FAULTMASK", (VALUE))) +#define __set_MSP(VALUE) (__arm_wsr("MSP", (VALUE))) - #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ +#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))) - // without main extensions, the non-secure MSPLIM is RAZ/WI - #define __set_MSPLIM(VALUE) ((void)(VALUE)) - #else - #define __set_MSPLIM(VALUE) (__arm_wsr("MSPLIM", (VALUE))) - #endif - #define __set_PRIMASK(VALUE) (__arm_wsr("PRIMASK", (VALUE))) - #define __set_PSP(VALUE) (__arm_wsr("PSP", (VALUE))) - #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ +// without main extensions, the non-secure MSPLIM is RAZ/WI +#define __set_MSPLIM(VALUE) ((void)(VALUE)) +#else +#define __set_MSPLIM(VALUE) (__arm_wsr("MSPLIM", (VALUE))) +#endif +#define __set_PRIMASK(VALUE) (__arm_wsr("PRIMASK", (VALUE))) +#define __set_PSP(VALUE) (__arm_wsr("PSP", (VALUE))) +#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))) - // without main extensions, the non-secure PSPLIM is RAZ/WI - #define __set_PSPLIM(VALUE) ((void)(VALUE)) - #else - #define __set_PSPLIM(VALUE) (__arm_wsr("PSPLIM", (VALUE))) - #endif +// without main extensions, the non-secure PSPLIM is RAZ/WI +#define __set_PSPLIM(VALUE) ((void)(VALUE)) +#else +#define __set_PSPLIM(VALUE) (__arm_wsr("PSPLIM", (VALUE))) +#endif - #define __TZ_get_CONTROL_NS() (__arm_rsr("CONTROL_NS")) +#define __TZ_get_CONTROL_NS() (__arm_rsr("CONTROL_NS")) -__STATIC_FORCEINLINE void __TZ_set_CONTROL_NS(uint32_t control) -{ - __arm_wsr("CONTROL_NS", control); - __iar_builtin_ISB(); +__STATIC_FORCEINLINE void __TZ_set_CONTROL_NS(uint32_t control) { + __arm_wsr("CONTROL_NS", control); + __iar_builtin_ISB(); } - #define __TZ_get_PSP_NS() (__arm_rsr("PSP_NS")) - #define __TZ_set_PSP_NS(VALUE) (__arm_wsr("PSP_NS", (VALUE))) - #define __TZ_get_MSP_NS() (__arm_rsr("MSP_NS")) - #define __TZ_set_MSP_NS(VALUE) (__arm_wsr("MSP_NS", (VALUE))) - #define __TZ_get_SP_NS() (__arm_rsr("SP_NS")) - #define __TZ_set_SP_NS(VALUE) (__arm_wsr("SP_NS", (VALUE))) - #define __TZ_get_PRIMASK_NS() (__arm_rsr("PRIMASK_NS")) - #define __TZ_set_PRIMASK_NS(VALUE) (__arm_wsr("PRIMASK_NS", (VALUE))) - #define __TZ_get_BASEPRI_NS() (__arm_rsr("BASEPRI_NS")) - #define __TZ_set_BASEPRI_NS(VALUE) (__arm_wsr("BASEPRI_NS", (VALUE))) - #define __TZ_get_FAULTMASK_NS() (__arm_rsr("FAULTMASK_NS")) - #define __TZ_set_FAULTMASK_NS(VALUE)(__arm_wsr("FAULTMASK_NS", (VALUE))) +#define __TZ_get_PSP_NS() (__arm_rsr("PSP_NS")) +#define __TZ_set_PSP_NS(VALUE) (__arm_wsr("PSP_NS", (VALUE))) +#define __TZ_get_MSP_NS() (__arm_rsr("MSP_NS")) +#define __TZ_set_MSP_NS(VALUE) (__arm_wsr("MSP_NS", (VALUE))) +#define __TZ_get_SP_NS() (__arm_rsr("SP_NS")) +#define __TZ_set_SP_NS(VALUE) (__arm_wsr("SP_NS", (VALUE))) +#define __TZ_get_PRIMASK_NS() (__arm_rsr("PRIMASK_NS")) +#define __TZ_set_PRIMASK_NS(VALUE) (__arm_wsr("PRIMASK_NS", (VALUE))) +#define __TZ_get_BASEPRI_NS() (__arm_rsr("BASEPRI_NS")) +#define __TZ_set_BASEPRI_NS(VALUE) (__arm_wsr("BASEPRI_NS", (VALUE))) +#define __TZ_get_FAULTMASK_NS() (__arm_rsr("FAULTMASK_NS")) +#define __TZ_set_FAULTMASK_NS(VALUE)(__arm_wsr("FAULTMASK_NS", (VALUE))) - #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ +#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ (!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3))) - // without main extensions, the non-secure PSPLIM is RAZ/WI - #define __TZ_get_PSPLIM_NS() (0U) - #define __TZ_set_PSPLIM_NS(VALUE) ((void)(VALUE)) - #else - #define __TZ_get_PSPLIM_NS() (__arm_rsr("PSPLIM_NS")) - #define __TZ_set_PSPLIM_NS(VALUE) (__arm_wsr("PSPLIM_NS", (VALUE))) - #endif +// without main extensions, the non-secure PSPLIM is RAZ/WI +#define __TZ_get_PSPLIM_NS() (0U) +#define __TZ_set_PSPLIM_NS(VALUE) ((void)(VALUE)) +#else +#define __TZ_get_PSPLIM_NS() (__arm_rsr("PSPLIM_NS")) +#define __TZ_set_PSPLIM_NS(VALUE) (__arm_wsr("PSPLIM_NS", (VALUE))) +#endif - #define __TZ_get_MSPLIM_NS() (__arm_rsr("MSPLIM_NS")) - #define __TZ_set_MSPLIM_NS(VALUE) (__arm_wsr("MSPLIM_NS", (VALUE))) +#define __TZ_get_MSPLIM_NS() (__arm_rsr("MSPLIM_NS")) +#define __TZ_set_MSPLIM_NS(VALUE) (__arm_wsr("MSPLIM_NS", (VALUE))) - #define __NOP __iar_builtin_no_operation +#define __NOP __iar_builtin_no_operation - #define __CLZ __iar_builtin_CLZ - #define __CLREX __iar_builtin_CLREX +#define __CLZ __iar_builtin_CLZ +#define __CLREX __iar_builtin_CLREX - #define __DMB __iar_builtin_DMB - #define __DSB __iar_builtin_DSB - #define __ISB __iar_builtin_ISB +#define __DMB __iar_builtin_DMB +#define __DSB __iar_builtin_DSB +#define __ISB __iar_builtin_ISB - #define __LDREXB __iar_builtin_LDREXB - #define __LDREXH __iar_builtin_LDREXH - #define __LDREXW __iar_builtin_LDREX +#define __LDREXB __iar_builtin_LDREXB +#define __LDREXH __iar_builtin_LDREXH +#define __LDREXW __iar_builtin_LDREX - #define __RBIT __iar_builtin_RBIT - #define __REV __iar_builtin_REV - #define __REV16 __iar_builtin_REV16 +#define __RBIT __iar_builtin_RBIT +#define __REV __iar_builtin_REV +#define __REV16 __iar_builtin_REV16 - __IAR_FT int16_t __REVSH(int16_t val) - { +__IAR_FT int16_t __REVSH(int16_t val) { return (int16_t) __iar_builtin_REVSH(val); - } +} - #define __ROR __iar_builtin_ROR - #define __RRX __iar_builtin_RRX +#define __ROR __iar_builtin_ROR +#define __RRX __iar_builtin_RRX - #define __SEV __iar_builtin_SEV +#define __SEV __iar_builtin_SEV - #if !__IAR_M0_FAMILY - #define __SSAT __iar_builtin_SSAT - #endif +#if !__IAR_M0_FAMILY +#define __SSAT __iar_builtin_SSAT +#endif - #define __STREXB __iar_builtin_STREXB - #define __STREXH __iar_builtin_STREXH - #define __STREXW __iar_builtin_STREX +#define __STREXB __iar_builtin_STREXB +#define __STREXH __iar_builtin_STREXH +#define __STREXW __iar_builtin_STREX - #if !__IAR_M0_FAMILY - #define __USAT __iar_builtin_USAT - #endif +#if !__IAR_M0_FAMILY +#define __USAT __iar_builtin_USAT +#endif - #define __WFE __iar_builtin_WFE - #define __WFI __iar_builtin_WFI +#define __WFE __iar_builtin_WFE +#define __WFI __iar_builtin_WFI - #if __ARM_MEDIA__ - #define __SADD8 __iar_builtin_SADD8 - #define __QADD8 __iar_builtin_QADD8 - #define __SHADD8 __iar_builtin_SHADD8 - #define __UADD8 __iar_builtin_UADD8 - #define __UQADD8 __iar_builtin_UQADD8 - #define __UHADD8 __iar_builtin_UHADD8 - #define __SSUB8 __iar_builtin_SSUB8 - #define __QSUB8 __iar_builtin_QSUB8 - #define __SHSUB8 __iar_builtin_SHSUB8 - #define __USUB8 __iar_builtin_USUB8 - #define __UQSUB8 __iar_builtin_UQSUB8 - #define __UHSUB8 __iar_builtin_UHSUB8 - #define __SADD16 __iar_builtin_SADD16 - #define __QADD16 __iar_builtin_QADD16 - #define __SHADD16 __iar_builtin_SHADD16 - #define __UADD16 __iar_builtin_UADD16 - #define __UQADD16 __iar_builtin_UQADD16 - #define __UHADD16 __iar_builtin_UHADD16 - #define __SSUB16 __iar_builtin_SSUB16 - #define __QSUB16 __iar_builtin_QSUB16 - #define __SHSUB16 __iar_builtin_SHSUB16 - #define __USUB16 __iar_builtin_USUB16 - #define __UQSUB16 __iar_builtin_UQSUB16 - #define __UHSUB16 __iar_builtin_UHSUB16 - #define __SASX __iar_builtin_SASX - #define __QASX __iar_builtin_QASX - #define __SHASX __iar_builtin_SHASX - #define __UASX __iar_builtin_UASX - #define __UQASX __iar_builtin_UQASX - #define __UHASX __iar_builtin_UHASX - #define __SSAX __iar_builtin_SSAX - #define __QSAX __iar_builtin_QSAX - #define __SHSAX __iar_builtin_SHSAX - #define __USAX __iar_builtin_USAX - #define __UQSAX __iar_builtin_UQSAX - #define __UHSAX __iar_builtin_UHSAX - #define __USAD8 __iar_builtin_USAD8 - #define __USADA8 __iar_builtin_USADA8 - #define __SSAT16 __iar_builtin_SSAT16 - #define __USAT16 __iar_builtin_USAT16 - #define __UXTB16 __iar_builtin_UXTB16 - #define __UXTAB16 __iar_builtin_UXTAB16 - #define __SXTB16 __iar_builtin_SXTB16 - #define __SXTAB16 __iar_builtin_SXTAB16 - #define __SMUAD __iar_builtin_SMUAD - #define __SMUADX __iar_builtin_SMUADX - #define __SMMLA __iar_builtin_SMMLA - #define __SMLAD __iar_builtin_SMLAD - #define __SMLADX __iar_builtin_SMLADX - #define __SMLALD __iar_builtin_SMLALD - #define __SMLALDX __iar_builtin_SMLALDX - #define __SMUSD __iar_builtin_SMUSD - #define __SMUSDX __iar_builtin_SMUSDX - #define __SMLSD __iar_builtin_SMLSD - #define __SMLSDX __iar_builtin_SMLSDX - #define __SMLSLD __iar_builtin_SMLSLD - #define __SMLSLDX __iar_builtin_SMLSLDX - #define __SEL __iar_builtin_SEL - #define __QADD __iar_builtin_QADD - #define __QSUB __iar_builtin_QSUB - #define __PKHBT __iar_builtin_PKHBT - #define __PKHTB __iar_builtin_PKHTB - #endif +#if __ARM_MEDIA__ +#define __SADD8 __iar_builtin_SADD8 +#define __QADD8 __iar_builtin_QADD8 +#define __SHADD8 __iar_builtin_SHADD8 +#define __UADD8 __iar_builtin_UADD8 +#define __UQADD8 __iar_builtin_UQADD8 +#define __UHADD8 __iar_builtin_UHADD8 +#define __SSUB8 __iar_builtin_SSUB8 +#define __QSUB8 __iar_builtin_QSUB8 +#define __SHSUB8 __iar_builtin_SHSUB8 +#define __USUB8 __iar_builtin_USUB8 +#define __UQSUB8 __iar_builtin_UQSUB8 +#define __UHSUB8 __iar_builtin_UHSUB8 +#define __SADD16 __iar_builtin_SADD16 +#define __QADD16 __iar_builtin_QADD16 +#define __SHADD16 __iar_builtin_SHADD16 +#define __UADD16 __iar_builtin_UADD16 +#define __UQADD16 __iar_builtin_UQADD16 +#define __UHADD16 __iar_builtin_UHADD16 +#define __SSUB16 __iar_builtin_SSUB16 +#define __QSUB16 __iar_builtin_QSUB16 +#define __SHSUB16 __iar_builtin_SHSUB16 +#define __USUB16 __iar_builtin_USUB16 +#define __UQSUB16 __iar_builtin_UQSUB16 +#define __UHSUB16 __iar_builtin_UHSUB16 +#define __SASX __iar_builtin_SASX +#define __QASX __iar_builtin_QASX +#define __SHASX __iar_builtin_SHASX +#define __UASX __iar_builtin_UASX +#define __UQASX __iar_builtin_UQASX +#define __UHASX __iar_builtin_UHASX +#define __SSAX __iar_builtin_SSAX +#define __QSAX __iar_builtin_QSAX +#define __SHSAX __iar_builtin_SHSAX +#define __USAX __iar_builtin_USAX +#define __UQSAX __iar_builtin_UQSAX +#define __UHSAX __iar_builtin_UHSAX +#define __USAD8 __iar_builtin_USAD8 +#define __USADA8 __iar_builtin_USADA8 +#define __SSAT16 __iar_builtin_SSAT16 +#define __USAT16 __iar_builtin_USAT16 +#define __UXTB16 __iar_builtin_UXTB16 +#define __UXTAB16 __iar_builtin_UXTAB16 +#define __SXTB16 __iar_builtin_SXTB16 +#define __SXTAB16 __iar_builtin_SXTAB16 +#define __SMUAD __iar_builtin_SMUAD +#define __SMUADX __iar_builtin_SMUADX +#define __SMMLA __iar_builtin_SMMLA +#define __SMLAD __iar_builtin_SMLAD +#define __SMLADX __iar_builtin_SMLADX +#define __SMLALD __iar_builtin_SMLALD +#define __SMLALDX __iar_builtin_SMLALDX +#define __SMUSD __iar_builtin_SMUSD +#define __SMUSDX __iar_builtin_SMUSDX +#define __SMLSD __iar_builtin_SMLSD +#define __SMLSDX __iar_builtin_SMLSDX +#define __SMLSLD __iar_builtin_SMLSLD +#define __SMLSLDX __iar_builtin_SMLSLDX +#define __SEL __iar_builtin_SEL +#define __QADD __iar_builtin_QADD +#define __QSUB __iar_builtin_QSUB +#define __PKHBT __iar_builtin_PKHBT +#define __PKHTB __iar_builtin_PKHTB +#endif #else /* __ICCARM_INTRINSICS_VERSION__ == 2 */ - #if __IAR_M0_FAMILY - /* Avoid clash between intrinsics.h and arm_math.h when compiling for Cortex-M0. */ - #define __CLZ __cmsis_iar_clz_not_active - #define __SSAT __cmsis_iar_ssat_not_active - #define __USAT __cmsis_iar_usat_not_active - #define __RBIT __cmsis_iar_rbit_not_active - #define __get_APSR __cmsis_iar_get_APSR_not_active - #endif +#if __IAR_M0_FAMILY +/* Avoid clash between intrinsics.h and arm_math.h when compiling for Cortex-M0. */ +#define __CLZ __cmsis_iar_clz_not_active +#define __SSAT __cmsis_iar_ssat_not_active +#define __USAT __cmsis_iar_usat_not_active +#define __RBIT __cmsis_iar_rbit_not_active +#define __get_APSR __cmsis_iar_get_APSR_not_active +#endif - #if (!((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \ +#if (!((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \ (defined (__FPU_USED ) && (__FPU_USED == 1U)) )) - #define __get_FPSCR __cmsis_iar_get_FPSR_not_active - #define __set_FPSCR __cmsis_iar_set_FPSR_not_active - #endif +#define __get_FPSCR __cmsis_iar_get_FPSR_not_active +#define __set_FPSCR __cmsis_iar_set_FPSR_not_active +#endif - #ifdef __INTRINSICS_INCLUDED - #error intrinsics.h is already included previously! - #endif +#ifdef __INTRINSICS_INCLUDED +#error intrinsics.h is already included previously! +#endif - #include +#include - #if __IAR_M0_FAMILY - /* Avoid clash between intrinsics.h and arm_math.h when compiling for Cortex-M0. */ - #undef __CLZ - #undef __SSAT - #undef __USAT - #undef __RBIT - #undef __get_APSR +#if __IAR_M0_FAMILY +/* Avoid clash between intrinsics.h and arm_math.h when compiling for Cortex-M0. */ +#undef __CLZ +#undef __SSAT +#undef __USAT +#undef __RBIT +#undef __get_APSR - __STATIC_INLINE uint8_t __CLZ(uint32_t data) - { - if (data == 0U) { return 32U; } +__STATIC_INLINE uint8_t __CLZ(uint32_t data) { + if (data == 0U) { return 32U; } - uint32_t count = 0U; - uint32_t mask = 0x80000000U; + uint32_t count = 0U; + uint32_t mask = 0x80000000U; - while ((data & mask) == 0U) - { + while ((data & mask) == 0U) { count += 1U; mask = mask >> 1U; - } - return count; } + return count; +} - __STATIC_INLINE uint32_t __RBIT(uint32_t v) - { - uint8_t sc = 31U; - uint32_t r = v; - for (v >>= 1U; v; v >>= 1U) - { +__STATIC_INLINE uint32_t __RBIT(uint32_t v) { + uint8_t sc = 31U; + uint32_t r = v; + for (v >>= 1U; v; v >>= 1U) { r <<= 1U; r |= v & 1U; sc--; - } - return (r << sc); } + return (r << sc); +} - __STATIC_INLINE uint32_t __get_APSR(void) - { - uint32_t res; - __asm("MRS %0,APSR" : "=r" (res)); - return res; - } +__STATIC_INLINE uint32_t __get_APSR(void) { + uint32_t res; + __asm("MRS %0,APSR" : "=r"(res)); + return res; +} - #endif +#endif - #if (!((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \ +#if (!((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \ (defined (__FPU_USED ) && (__FPU_USED == 1U)) )) - #undef __get_FPSCR - #undef __set_FPSCR - #define __get_FPSCR() (0) - #define __set_FPSCR(VALUE) ((void)VALUE) - #endif +#undef __get_FPSCR +#undef __set_FPSCR +#define __get_FPSCR() (0) +#define __set_FPSCR(VALUE) ((void)VALUE) +#endif - #pragma diag_suppress=Pe940 - #pragma diag_suppress=Pe177 +#pragma diag_suppress=Pe940 +#pragma diag_suppress=Pe177 - #define __enable_irq __enable_interrupt - #define __disable_irq __disable_interrupt - #define __NOP __no_operation +#define __enable_irq __enable_interrupt +#define __disable_irq __disable_interrupt +#define __NOP __no_operation - #define __get_xPSR __get_PSR +#define __get_xPSR __get_PSR - #if (!defined(__ARM_ARCH_6M__) || __ARM_ARCH_6M__==0) +#if (!defined(__ARM_ARCH_6M__) || __ARM_ARCH_6M__==0) - __IAR_FT uint32_t __LDREXW(uint32_t volatile *ptr) - { - return __LDREX((unsigned long *)ptr); - } +__IAR_FT uint32_t __LDREXW(uint32_t volatile *ptr) { + return __LDREX((unsigned long *)ptr); +} - __IAR_FT uint32_t __STREXW(uint32_t value, uint32_t volatile *ptr) - { - return __STREX(value, (unsigned long *)ptr); - } - #endif +__IAR_FT uint32_t __STREXW(uint32_t value, uint32_t volatile *ptr) { + return __STREX(value, (unsigned long *)ptr); +} +#endif - /* __CORTEX_M is defined in core_cm0.h, core_cm3.h and core_cm4.h. */ - #if (__CORTEX_M >= 0x03) +/* __CORTEX_M is defined in core_cm0.h, core_cm3.h and core_cm4.h. */ +#if (__CORTEX_M >= 0x03) - __IAR_FT uint32_t __RRX(uint32_t value) - { - uint32_t result; - __ASM volatile("RRX %0, %1" : "=r"(result) : "r" (value)); - return(result); - } +__IAR_FT uint32_t __RRX(uint32_t value) { + uint32_t result; + __ASM volatile("RRX %0, %1" : "=r"(result) : "r"(value)); + return (result); +} - __IAR_FT void __set_BASEPRI_MAX(uint32_t value) - { - __asm volatile("MSR BASEPRI_MAX,%0"::"r" (value)); - } +__IAR_FT void __set_BASEPRI_MAX(uint32_t value) { + __asm volatile("MSR BASEPRI_MAX,%0"::"r"(value)); +} - #define __enable_fault_irq __enable_fiq - #define __disable_fault_irq __disable_fiq +#define __enable_fault_irq __enable_fiq +#define __disable_fault_irq __disable_fiq - #endif /* (__CORTEX_M >= 0x03) */ +#endif /* (__CORTEX_M >= 0x03) */ - __IAR_FT uint32_t __ROR(uint32_t op1, uint32_t op2) - { - return (op1 >> op2) | (op1 << ((sizeof(op1)*8)-op2)); - } +__IAR_FT uint32_t __ROR(uint32_t op1, uint32_t op2) { + return (op1 >> op2) | (op1 << ((sizeof(op1) * 8) - op2)); +} - #if ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ +#if ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \ (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) - __IAR_FT uint32_t __get_MSPLIM(void) - { - uint32_t res; - #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ +__IAR_FT uint32_t __get_MSPLIM(void) { + uint32_t res; +#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ (!defined (__ARM_FEATURE_CMSE ) || (__ARM_FEATURE_CMSE < 3))) - // without main extensions, the non-secure MSPLIM is RAZ/WI - res = 0U; - #else - __asm volatile("MRS %0,MSPLIM" : "=r" (res)); - #endif - return res; - } + // without main extensions, the non-secure MSPLIM is RAZ/WI + res = 0U; +#else + __asm volatile("MRS %0,MSPLIM" : "=r"(res)); +#endif + return res; +} - __IAR_FT void __set_MSPLIM(uint32_t value) - { - #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ +__IAR_FT void __set_MSPLIM(uint32_t value) { +#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ (!defined (__ARM_FEATURE_CMSE ) || (__ARM_FEATURE_CMSE < 3))) - // without main extensions, the non-secure MSPLIM is RAZ/WI - (void)value; - #else - __asm volatile("MSR MSPLIM,%0" :: "r" (value)); - #endif - } + // without main extensions, the non-secure MSPLIM is RAZ/WI + (void)value; +#else + __asm volatile("MSR MSPLIM,%0" :: "r"(value)); +#endif +} - __IAR_FT uint32_t __get_PSPLIM(void) - { - uint32_t res; - #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ +__IAR_FT uint32_t __get_PSPLIM(void) { + uint32_t res; +#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ (!defined (__ARM_FEATURE_CMSE ) || (__ARM_FEATURE_CMSE < 3))) - // without main extensions, the non-secure PSPLIM is RAZ/WI - res = 0U; - #else - __asm volatile("MRS %0,PSPLIM" : "=r" (res)); - #endif - return res; - } + // without main extensions, the non-secure PSPLIM is RAZ/WI + res = 0U; +#else + __asm volatile("MRS %0,PSPLIM" : "=r"(res)); +#endif + return res; +} - __IAR_FT void __set_PSPLIM(uint32_t value) - { - #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ +__IAR_FT void __set_PSPLIM(uint32_t value) { +#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ (!defined (__ARM_FEATURE_CMSE ) || (__ARM_FEATURE_CMSE < 3))) - // without main extensions, the non-secure PSPLIM is RAZ/WI - (void)value; - #else - __asm volatile("MSR PSPLIM,%0" :: "r" (value)); - #endif - } + // without main extensions, the non-secure PSPLIM is RAZ/WI + (void)value; +#else + __asm volatile("MSR PSPLIM,%0" :: "r"(value)); +#endif +} - __IAR_FT uint32_t __TZ_get_CONTROL_NS(void) - { - uint32_t res; - __asm volatile("MRS %0,CONTROL_NS" : "=r" (res)); - return res; - } +__IAR_FT uint32_t __TZ_get_CONTROL_NS(void) { + uint32_t res; + __asm volatile("MRS %0,CONTROL_NS" : "=r"(res)); + return res; +} - __IAR_FT void __TZ_set_CONTROL_NS(uint32_t value) - { - __asm volatile("MSR CONTROL_NS,%0" :: "r" (value)); - __iar_builtin_ISB(); - } +__IAR_FT void __TZ_set_CONTROL_NS(uint32_t value) { + __asm volatile("MSR CONTROL_NS,%0" :: "r"(value)); + __iar_builtin_ISB(); +} - __IAR_FT uint32_t __TZ_get_PSP_NS(void) - { - uint32_t res; - __asm volatile("MRS %0,PSP_NS" : "=r" (res)); - return res; - } +__IAR_FT uint32_t __TZ_get_PSP_NS(void) { + uint32_t res; + __asm volatile("MRS %0,PSP_NS" : "=r"(res)); + return res; +} - __IAR_FT void __TZ_set_PSP_NS(uint32_t value) - { - __asm volatile("MSR PSP_NS,%0" :: "r" (value)); - } +__IAR_FT void __TZ_set_PSP_NS(uint32_t value) { + __asm volatile("MSR PSP_NS,%0" :: "r"(value)); +} - __IAR_FT uint32_t __TZ_get_MSP_NS(void) - { - uint32_t res; - __asm volatile("MRS %0,MSP_NS" : "=r" (res)); - return res; - } +__IAR_FT uint32_t __TZ_get_MSP_NS(void) { + uint32_t res; + __asm volatile("MRS %0,MSP_NS" : "=r"(res)); + return res; +} - __IAR_FT void __TZ_set_MSP_NS(uint32_t value) - { - __asm volatile("MSR MSP_NS,%0" :: "r" (value)); - } +__IAR_FT void __TZ_set_MSP_NS(uint32_t value) { + __asm volatile("MSR MSP_NS,%0" :: "r"(value)); +} - __IAR_FT uint32_t __TZ_get_SP_NS(void) - { - uint32_t res; - __asm volatile("MRS %0,SP_NS" : "=r" (res)); - return res; - } - __IAR_FT void __TZ_set_SP_NS(uint32_t value) - { - __asm volatile("MSR SP_NS,%0" :: "r" (value)); - } +__IAR_FT uint32_t __TZ_get_SP_NS(void) { + uint32_t res; + __asm volatile("MRS %0,SP_NS" : "=r"(res)); + return res; +} +__IAR_FT void __TZ_set_SP_NS(uint32_t value) { + __asm volatile("MSR SP_NS,%0" :: "r"(value)); +} - __IAR_FT uint32_t __TZ_get_PRIMASK_NS(void) - { - uint32_t res; - __asm volatile("MRS %0,PRIMASK_NS" : "=r" (res)); - return res; - } +__IAR_FT uint32_t __TZ_get_PRIMASK_NS(void) { + uint32_t res; + __asm volatile("MRS %0,PRIMASK_NS" : "=r"(res)); + return res; +} - __IAR_FT void __TZ_set_PRIMASK_NS(uint32_t value) - { - __asm volatile("MSR PRIMASK_NS,%0" :: "r" (value)); - } +__IAR_FT void __TZ_set_PRIMASK_NS(uint32_t value) { + __asm volatile("MSR PRIMASK_NS,%0" :: "r"(value)); +} - __IAR_FT uint32_t __TZ_get_BASEPRI_NS(void) - { - uint32_t res; - __asm volatile("MRS %0,BASEPRI_NS" : "=r" (res)); - return res; - } +__IAR_FT uint32_t __TZ_get_BASEPRI_NS(void) { + uint32_t res; + __asm volatile("MRS %0,BASEPRI_NS" : "=r"(res)); + return res; +} - __IAR_FT void __TZ_set_BASEPRI_NS(uint32_t value) - { - __asm volatile("MSR BASEPRI_NS,%0" :: "r" (value)); - } +__IAR_FT void __TZ_set_BASEPRI_NS(uint32_t value) { + __asm volatile("MSR BASEPRI_NS,%0" :: "r"(value)); +} - __IAR_FT uint32_t __TZ_get_FAULTMASK_NS(void) - { - uint32_t res; - __asm volatile("MRS %0,FAULTMASK_NS" : "=r" (res)); - return res; - } +__IAR_FT uint32_t __TZ_get_FAULTMASK_NS(void) { + uint32_t res; + __asm volatile("MRS %0,FAULTMASK_NS" : "=r"(res)); + return res; +} - __IAR_FT void __TZ_set_FAULTMASK_NS(uint32_t value) - { - __asm volatile("MSR FAULTMASK_NS,%0" :: "r" (value)); - } +__IAR_FT void __TZ_set_FAULTMASK_NS(uint32_t value) { + __asm volatile("MSR FAULTMASK_NS,%0" :: "r"(value)); +} - __IAR_FT uint32_t __TZ_get_PSPLIM_NS(void) - { - uint32_t res; - #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ +__IAR_FT uint32_t __TZ_get_PSPLIM_NS(void) { + uint32_t res; +#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ (!defined (__ARM_FEATURE_CMSE ) || (__ARM_FEATURE_CMSE < 3))) - // without main extensions, the non-secure PSPLIM is RAZ/WI - res = 0U; - #else - __asm volatile("MRS %0,PSPLIM_NS" : "=r" (res)); - #endif - return res; - } + // without main extensions, the non-secure PSPLIM is RAZ/WI + res = 0U; +#else + __asm volatile("MRS %0,PSPLIM_NS" : "=r"(res)); +#endif + return res; +} - __IAR_FT void __TZ_set_PSPLIM_NS(uint32_t value) - { - #if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ +__IAR_FT void __TZ_set_PSPLIM_NS(uint32_t value) { +#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \ (!defined (__ARM_FEATURE_CMSE ) || (__ARM_FEATURE_CMSE < 3))) - // without main extensions, the non-secure PSPLIM is RAZ/WI - (void)value; - #else - __asm volatile("MSR PSPLIM_NS,%0" :: "r" (value)); - #endif - } + // without main extensions, the non-secure PSPLIM is RAZ/WI + (void)value; +#else + __asm volatile("MSR PSPLIM_NS,%0" :: "r"(value)); +#endif +} - __IAR_FT uint32_t __TZ_get_MSPLIM_NS(void) - { - uint32_t res; - __asm volatile("MRS %0,MSPLIM_NS" : "=r" (res)); - return res; - } +__IAR_FT uint32_t __TZ_get_MSPLIM_NS(void) { + uint32_t res; + __asm volatile("MRS %0,MSPLIM_NS" : "=r"(res)); + return res; +} - __IAR_FT void __TZ_set_MSPLIM_NS(uint32_t value) - { - __asm volatile("MSR MSPLIM_NS,%0" :: "r" (value)); - } +__IAR_FT void __TZ_set_MSPLIM_NS(uint32_t value) { + __asm volatile("MSR MSPLIM_NS,%0" :: "r"(value)); +} - #endif /* __ARM_ARCH_8M_MAIN__ or __ARM_ARCH_8M_BASE__ */ +#endif /* __ARM_ARCH_8M_MAIN__ or __ARM_ARCH_8M_BASE__ */ #endif /* __ICCARM_INTRINSICS_VERSION__ == 2 */ #define __BKPT(value) __asm volatile ("BKPT %0" : : "i"(value)) #if __IAR_M0_FAMILY - __STATIC_INLINE int32_t __SSAT(int32_t val, uint32_t sat) - { - if ((sat >= 1U) && (sat <= 32U)) - { - const int32_t max = (int32_t)((1U << (sat - 1U)) - 1U); - const int32_t min = -1 - max ; - if (val > max) - { - return max; - } - else if (val < min) - { - return min; - } +__STATIC_INLINE int32_t __SSAT(int32_t val, uint32_t sat) { + if ((sat >= 1U) && (sat <= 32U)) { + const int32_t max = (int32_t)((1U << (sat - 1U)) - 1U); + const int32_t min = -1 - max ; + if (val > max) { + return max; + } else if (val < min) { + return min; + } } return val; - } +} - __STATIC_INLINE uint32_t __USAT(int32_t val, uint32_t sat) - { - if (sat <= 31U) - { - const uint32_t max = ((1U << sat) - 1U); - if (val > (int32_t)max) - { - return max; - } - else if (val < 0) - { - return 0U; - } +__STATIC_INLINE uint32_t __USAT(int32_t val, uint32_t sat) { + if (sat <= 31U) { + const uint32_t max = ((1U << sat) - 1U); + if (val > (int32_t)max) { + return max; + } else if (val < 0) { + return 0U; + } } return (uint32_t)val; - } +} #endif #if (__CORTEX_M >= 0x03) /* __CORTEX_M is defined in core_cm0.h, core_cm3.h and core_cm4.h. */ - __IAR_FT uint8_t __LDRBT(volatile uint8_t *addr) - { +__IAR_FT uint8_t __LDRBT(volatile uint8_t *addr) { uint32_t res; - __ASM volatile ("LDRBT %0, [%1]" : "=r" (res) : "r" (addr) : "memory"); + __ASM volatile("LDRBT %0, [%1]" : "=r"(res) : "r"(addr) : "memory"); return ((uint8_t)res); - } +} - __IAR_FT uint16_t __LDRHT(volatile uint16_t *addr) - { +__IAR_FT uint16_t __LDRHT(volatile uint16_t *addr) { uint32_t res; - __ASM volatile ("LDRHT %0, [%1]" : "=r" (res) : "r" (addr) : "memory"); + __ASM volatile("LDRHT %0, [%1]" : "=r"(res) : "r"(addr) : "memory"); return ((uint16_t)res); - } +} - __IAR_FT uint32_t __LDRT(volatile uint32_t *addr) - { +__IAR_FT uint32_t __LDRT(volatile uint32_t *addr) { uint32_t res; - __ASM volatile ("LDRT %0, [%1]" : "=r" (res) : "r" (addr) : "memory"); + __ASM volatile("LDRT %0, [%1]" : "=r"(res) : "r"(addr) : "memory"); return res; - } +} - __IAR_FT void __STRBT(uint8_t value, volatile uint8_t *addr) - { - __ASM volatile ("STRBT %1, [%0]" : : "r" (addr), "r" ((uint32_t)value) : "memory"); - } +__IAR_FT void __STRBT(uint8_t value, volatile uint8_t *addr) { + __ASM volatile("STRBT %1, [%0]" : : "r"(addr), "r"((uint32_t)value) : "memory"); +} - __IAR_FT void __STRHT(uint16_t value, volatile uint16_t *addr) - { - __ASM volatile ("STRHT %1, [%0]" : : "r" (addr), "r" ((uint32_t)value) : "memory"); - } +__IAR_FT void __STRHT(uint16_t value, volatile uint16_t *addr) { + __ASM volatile("STRHT %1, [%0]" : : "r"(addr), "r"((uint32_t)value) : "memory"); +} - __IAR_FT void __STRT(uint32_t value, volatile uint32_t *addr) - { - __ASM volatile ("STRT %1, [%0]" : : "r" (addr), "r" (value) : "memory"); - } +__IAR_FT void __STRT(uint32_t value, volatile uint32_t *addr) { + __ASM volatile("STRT %1, [%0]" : : "r"(addr), "r"(value) : "memory"); +} #endif /* (__CORTEX_M >= 0x03) */ @@ -908,83 +853,71 @@ __STATIC_FORCEINLINE void __TZ_set_CONTROL_NS(uint32_t control) (defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) ) - __IAR_FT uint8_t __LDAB(volatile uint8_t *ptr) - { +__IAR_FT uint8_t __LDAB(volatile uint8_t *ptr) { uint32_t res; - __ASM volatile ("LDAB %0, [%1]" : "=r" (res) : "r" (ptr) : "memory"); + __ASM volatile("LDAB %0, [%1]" : "=r"(res) : "r"(ptr) : "memory"); return ((uint8_t)res); - } +} - __IAR_FT uint16_t __LDAH(volatile uint16_t *ptr) - { +__IAR_FT uint16_t __LDAH(volatile uint16_t *ptr) { uint32_t res; - __ASM volatile ("LDAH %0, [%1]" : "=r" (res) : "r" (ptr) : "memory"); + __ASM volatile("LDAH %0, [%1]" : "=r"(res) : "r"(ptr) : "memory"); return ((uint16_t)res); - } +} - __IAR_FT uint32_t __LDA(volatile uint32_t *ptr) - { +__IAR_FT uint32_t __LDA(volatile uint32_t *ptr) { uint32_t res; - __ASM volatile ("LDA %0, [%1]" : "=r" (res) : "r" (ptr) : "memory"); + __ASM volatile("LDA %0, [%1]" : "=r"(res) : "r"(ptr) : "memory"); return res; - } +} - __IAR_FT void __STLB(uint8_t value, volatile uint8_t *ptr) - { - __ASM volatile ("STLB %1, [%0]" :: "r" (ptr), "r" (value) : "memory"); - } +__IAR_FT void __STLB(uint8_t value, volatile uint8_t *ptr) { + __ASM volatile("STLB %1, [%0]" :: "r"(ptr), "r"(value) : "memory"); +} - __IAR_FT void __STLH(uint16_t value, volatile uint16_t *ptr) - { - __ASM volatile ("STLH %1, [%0]" :: "r" (ptr), "r" (value) : "memory"); - } +__IAR_FT void __STLH(uint16_t value, volatile uint16_t *ptr) { + __ASM volatile("STLH %1, [%0]" :: "r"(ptr), "r"(value) : "memory"); +} - __IAR_FT void __STL(uint32_t value, volatile uint32_t *ptr) - { - __ASM volatile ("STL %1, [%0]" :: "r" (ptr), "r" (value) : "memory"); - } +__IAR_FT void __STL(uint32_t value, volatile uint32_t *ptr) { + __ASM volatile("STL %1, [%0]" :: "r"(ptr), "r"(value) : "memory"); +} - __IAR_FT uint8_t __LDAEXB(volatile uint8_t *ptr) - { +__IAR_FT uint8_t __LDAEXB(volatile uint8_t *ptr) { uint32_t res; - __ASM volatile ("LDAEXB %0, [%1]" : "=r" (res) : "r" (ptr) : "memory"); + __ASM volatile("LDAEXB %0, [%1]" : "=r"(res) : "r"(ptr) : "memory"); return ((uint8_t)res); - } +} - __IAR_FT uint16_t __LDAEXH(volatile uint16_t *ptr) - { +__IAR_FT uint16_t __LDAEXH(volatile uint16_t *ptr) { uint32_t res; - __ASM volatile ("LDAEXH %0, [%1]" : "=r" (res) : "r" (ptr) : "memory"); + __ASM volatile("LDAEXH %0, [%1]" : "=r"(res) : "r"(ptr) : "memory"); return ((uint16_t)res); - } +} - __IAR_FT uint32_t __LDAEX(volatile uint32_t *ptr) - { +__IAR_FT uint32_t __LDAEX(volatile uint32_t *ptr) { uint32_t res; - __ASM volatile ("LDAEX %0, [%1]" : "=r" (res) : "r" (ptr) : "memory"); + __ASM volatile("LDAEX %0, [%1]" : "=r"(res) : "r"(ptr) : "memory"); return res; - } +} - __IAR_FT uint32_t __STLEXB(uint8_t value, volatile uint8_t *ptr) - { +__IAR_FT uint32_t __STLEXB(uint8_t value, volatile uint8_t *ptr) { uint32_t res; - __ASM volatile ("STLEXB %0, %2, [%1]" : "=r" (res) : "r" (ptr), "r" (value) : "memory"); + __ASM volatile("STLEXB %0, %2, [%1]" : "=r"(res) : "r"(ptr), "r"(value) : "memory"); return res; - } +} - __IAR_FT uint32_t __STLEXH(uint16_t value, volatile uint16_t *ptr) - { +__IAR_FT uint32_t __STLEXH(uint16_t value, volatile uint16_t *ptr) { uint32_t res; - __ASM volatile ("STLEXH %0, %2, [%1]" : "=r" (res) : "r" (ptr), "r" (value) : "memory"); + __ASM volatile("STLEXH %0, %2, [%1]" : "=r"(res) : "r"(ptr), "r"(value) : "memory"); return res; - } +} - __IAR_FT uint32_t __STLEX(uint32_t value, volatile uint32_t *ptr) - { +__IAR_FT uint32_t __STLEX(uint32_t value, volatile uint32_t *ptr) { uint32_t res; - __ASM volatile ("STLEX %0, %2, [%1]" : "=r" (res) : "r" (ptr), "r" (value) : "memory"); + __ASM volatile("STLEX %0, %2, [%1]" : "=r"(res) : "r"(ptr), "r"(value) : "memory"); return res; - } +} #endif /* __ARM_ARCH_8M_MAIN__ or __ARM_ARCH_8M_BASE__ */ diff --git a/armlib/at32_sys/cmsis/cm4/core_support/cmsis_version.h b/armlib/at32_sys/cmsis/cm4/core_support/cmsis_version.h index 8b4765f18..e0619a92b 100644 --- a/armlib/at32_sys/cmsis/cm4/core_support/cmsis_version.h +++ b/armlib/at32_sys/cmsis/cm4/core_support/cmsis_version.h @@ -23,9 +23,9 @@ */ #if defined ( __ICCARM__ ) - #pragma system_include /* treat file as system include file for MISRA check */ +#pragma system_include /* treat file as system include file for MISRA check */ #elif defined (__clang__) - #pragma clang system_header /* treat file as system include file */ +#pragma clang system_header /* treat file as system include file */ #endif #ifndef __CMSIS_VERSION_H diff --git a/armlib/at32_sys/cmsis/cm4/core_support/core_cm4.h b/armlib/at32_sys/cmsis/cm4/core_support/core_cm4.h index e21cd1492..e8ca97daf 100644 --- a/armlib/at32_sys/cmsis/cm4/core_support/core_cm4.h +++ b/armlib/at32_sys/cmsis/cm4/core_support/core_cm4.h @@ -23,9 +23,9 @@ */ #if defined ( __ICCARM__ ) - #pragma system_include /* treat file as system include file for MISRA check */ +#pragma system_include /* treat file as system include file for MISRA check */ #elif defined (__clang__) - #pragma clang system_header /* treat file as system include file */ +#pragma clang system_header /* treat file as system include file */ #endif #ifndef __CORE_CM4_H_GENERIC @@ -34,7 +34,7 @@ #include #ifdef __cplusplus - extern "C" { +extern "C" { #endif /** @@ -74,88 +74,88 @@ For this, __FPU_PRESENT has to be checked prior to making use of FPU specific registers and functions. */ #if defined ( __CC_ARM ) - #if defined __TARGET_FPU_VFP - #if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U) - #define __FPU_USED 1U - #else - #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" - #define __FPU_USED 0U - #endif - #else - #define __FPU_USED 0U - #endif +#if defined __TARGET_FPU_VFP +#if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U) +#define __FPU_USED 1U +#else +#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" +#define __FPU_USED 0U +#endif +#else +#define __FPU_USED 0U +#endif #elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) - #if defined __ARM_FP - #if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U) - #define __FPU_USED 1U - #else - #warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" - #define __FPU_USED 0U - #endif - #else - #define __FPU_USED 0U - #endif +#if defined __ARM_FP +#if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U) +#define __FPU_USED 1U +#else +#warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" +#define __FPU_USED 0U +#endif +#else +#define __FPU_USED 0U +#endif #elif defined ( __GNUC__ ) - #if defined (__VFP_FP__) && !defined(__SOFTFP__) - #if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U) - #define __FPU_USED 1U - #else - #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" - #define __FPU_USED 0U - #endif - #else - #define __FPU_USED 0U - #endif +#if defined (__VFP_FP__) && !defined(__SOFTFP__) +#if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U) +#define __FPU_USED 1U +#else +#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" +#define __FPU_USED 0U +#endif +#else +#define __FPU_USED 0U +#endif #elif defined ( __ICCARM__ ) - #if defined __ARMVFP__ - #if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U) - #define __FPU_USED 1U - #else - #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" - #define __FPU_USED 0U - #endif - #else - #define __FPU_USED 0U - #endif +#if defined __ARMVFP__ +#if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U) +#define __FPU_USED 1U +#else +#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" +#define __FPU_USED 0U +#endif +#else +#define __FPU_USED 0U +#endif #elif defined ( __TI_ARM__ ) - #if defined __TI_VFP_SUPPORT__ - #if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U) - #define __FPU_USED 1U - #else - #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" - #define __FPU_USED 0U - #endif - #else - #define __FPU_USED 0U - #endif +#if defined __TI_VFP_SUPPORT__ +#if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U) +#define __FPU_USED 1U +#else +#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" +#define __FPU_USED 0U +#endif +#else +#define __FPU_USED 0U +#endif #elif defined ( __TASKING__ ) - #if defined __FPU_VFP__ - #if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U) - #define __FPU_USED 1U - #else - #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" - #define __FPU_USED 0U - #endif - #else - #define __FPU_USED 0U - #endif +#if defined __FPU_VFP__ +#if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U) +#define __FPU_USED 1U +#else +#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" +#define __FPU_USED 0U +#endif +#else +#define __FPU_USED 0U +#endif #elif defined ( __CSMC__ ) - #if ( __CSMC__ & 0x400U) - #if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U) - #define __FPU_USED 1U - #else - #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" - #define __FPU_USED 0U - #endif - #else - #define __FPU_USED 0U - #endif +#if ( __CSMC__ & 0x400U) +#if defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U) +#define __FPU_USED 1U +#else +#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" +#define __FPU_USED 0U +#endif +#else +#define __FPU_USED 0U +#endif #endif @@ -174,40 +174,40 @@ #define __CORE_CM4_H_DEPENDANT #ifdef __cplusplus - extern "C" { +extern "C" { #endif /* check device defines and use defaults */ #if defined __CHECK_DEVICE_DEFINES - #ifndef __CM4_REV - #define __CM4_REV 0x0000U - #warning "__CM4_REV not defined in device header file; using default!" - #endif +#ifndef __CM4_REV +#define __CM4_REV 0x0000U +#warning "__CM4_REV not defined in device header file; using default!" +#endif - #ifndef __FPU_PRESENT - #define __FPU_PRESENT 0U - #warning "__FPU_PRESENT not defined in device header file; using default!" - #endif +#ifndef __FPU_PRESENT +#define __FPU_PRESENT 0U +#warning "__FPU_PRESENT not defined in device header file; using default!" +#endif - #ifndef __MPU_PRESENT - #define __MPU_PRESENT 0U - #warning "__MPU_PRESENT not defined in device header file; using default!" - #endif +#ifndef __MPU_PRESENT +#define __MPU_PRESENT 0U +#warning "__MPU_PRESENT not defined in device header file; using default!" +#endif - #ifndef __VTOR_PRESENT - #define __VTOR_PRESENT 1U - #warning "__VTOR_PRESENT not defined in device header file; using default!" - #endif +#ifndef __VTOR_PRESENT +#define __VTOR_PRESENT 1U +#warning "__VTOR_PRESENT not defined in device header file; using default!" +#endif - #ifndef __NVIC_PRIO_BITS - #define __NVIC_PRIO_BITS 3U - #warning "__NVIC_PRIO_BITS not defined in device header file; using default!" - #endif +#ifndef __NVIC_PRIO_BITS +#define __NVIC_PRIO_BITS 3U +#warning "__NVIC_PRIO_BITS not defined in device header file; using default!" +#endif - #ifndef __Vendor_SysTickConfig - #define __Vendor_SysTickConfig 0U - #warning "__Vendor_SysTickConfig not defined in device header file; using default!" - #endif +#ifndef __Vendor_SysTickConfig +#define __Vendor_SysTickConfig 0U +#warning "__Vendor_SysTickConfig not defined in device header file; using default!" +#endif #endif /* IO definitions (access restrictions to peripheral registers) */ @@ -219,9 +219,9 @@ \li for automatic generation of peripheral register debug information. */ #ifdef __cplusplus - #define __I volatile /*!< Defines 'read only' permissions */ +#define __I volatile /*!< Defines 'read only' permissions */ #else - #define __I volatile const /*!< Defines 'read only' permissions */ +#define __I volatile const /*!< Defines 'read only' permissions */ #endif #define __O volatile /*!< Defines 'write only' permissions */ #define __IO volatile /*!< Defines 'read / write' permissions */ @@ -261,20 +261,18 @@ /** \brief Union type to access the Application Program Status Register (APSR). */ -typedef union -{ - struct - { - uint32_t _reserved0:16; /*!< bit: 0..15 Reserved */ - uint32_t GE:4; /*!< bit: 16..19 Greater than or Equal flags */ - uint32_t _reserved1:7; /*!< bit: 20..26 Reserved */ - uint32_t Q:1; /*!< bit: 27 Saturation condition flag */ - uint32_t V:1; /*!< bit: 28 Overflow condition code flag */ - uint32_t C:1; /*!< bit: 29 Carry condition code flag */ - uint32_t Z:1; /*!< bit: 30 Zero condition code flag */ - uint32_t N:1; /*!< bit: 31 Negative condition code flag */ - } b; /*!< Structure used for bit access */ - uint32_t w; /*!< Type used for word access */ +typedef union { + struct { + uint32_t _reserved0: 16; /*!< bit: 0..15 Reserved */ + uint32_t GE: 4; /*!< bit: 16..19 Greater than or Equal flags */ + uint32_t _reserved1: 7; /*!< bit: 20..26 Reserved */ + uint32_t Q: 1; /*!< bit: 27 Saturation condition flag */ + uint32_t V: 1; /*!< bit: 28 Overflow condition code flag */ + uint32_t C: 1; /*!< bit: 29 Carry condition code flag */ + uint32_t Z: 1; /*!< bit: 30 Zero condition code flag */ + uint32_t N: 1; /*!< bit: 31 Negative condition code flag */ + } b; /*!< Structure used for bit access */ + uint32_t w; /*!< Type used for word access */ } APSR_Type; /* APSR Register Definitions */ @@ -300,14 +298,12 @@ typedef union /** \brief Union type to access the Interrupt Program Status Register (IPSR). */ -typedef union -{ - struct - { - uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */ - uint32_t _reserved0:23; /*!< bit: 9..31 Reserved */ - } b; /*!< Structure used for bit access */ - uint32_t w; /*!< Type used for word access */ +typedef union { + struct { + uint32_t ISR: 9; /*!< bit: 0.. 8 Exception number */ + uint32_t _reserved0: 23; /*!< bit: 9..31 Reserved */ + } b; /*!< Structure used for bit access */ + uint32_t w; /*!< Type used for word access */ } IPSR_Type; /* IPSR Register Definitions */ @@ -318,24 +314,22 @@ typedef union /** \brief Union type to access the Special-Purpose Program Status Registers (xPSR). */ -typedef union -{ - struct - { - uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */ - uint32_t _reserved0:1; /*!< bit: 9 Reserved */ - uint32_t ICI_IT_1:6; /*!< bit: 10..15 ICI/IT part 1 */ - uint32_t GE:4; /*!< bit: 16..19 Greater than or Equal flags */ - uint32_t _reserved1:4; /*!< bit: 20..23 Reserved */ - uint32_t T:1; /*!< bit: 24 Thumb bit */ - uint32_t ICI_IT_2:2; /*!< bit: 25..26 ICI/IT part 2 */ - uint32_t Q:1; /*!< bit: 27 Saturation condition flag */ - uint32_t V:1; /*!< bit: 28 Overflow condition code flag */ - uint32_t C:1; /*!< bit: 29 Carry condition code flag */ - uint32_t Z:1; /*!< bit: 30 Zero condition code flag */ - uint32_t N:1; /*!< bit: 31 Negative condition code flag */ - } b; /*!< Structure used for bit access */ - uint32_t w; /*!< Type used for word access */ +typedef union { + struct { + uint32_t ISR: 9; /*!< bit: 0.. 8 Exception number */ + uint32_t _reserved0: 1; /*!< bit: 9 Reserved */ + uint32_t ICI_IT_1: 6; /*!< bit: 10..15 ICI/IT part 1 */ + uint32_t GE: 4; /*!< bit: 16..19 Greater than or Equal flags */ + uint32_t _reserved1: 4; /*!< bit: 20..23 Reserved */ + uint32_t T: 1; /*!< bit: 24 Thumb bit */ + uint32_t ICI_IT_2: 2; /*!< bit: 25..26 ICI/IT part 2 */ + uint32_t Q: 1; /*!< bit: 27 Saturation condition flag */ + uint32_t V: 1; /*!< bit: 28 Overflow condition code flag */ + uint32_t C: 1; /*!< bit: 29 Carry condition code flag */ + uint32_t Z: 1; /*!< bit: 30 Zero condition code flag */ + uint32_t N: 1; /*!< bit: 31 Negative condition code flag */ + } b; /*!< Structure used for bit access */ + uint32_t w; /*!< Type used for word access */ } xPSR_Type; /* xPSR Register Definitions */ @@ -373,16 +367,14 @@ typedef union /** \brief Union type to access the Control Registers (CONTROL). */ -typedef union -{ - struct - { - uint32_t nPRIV:1; /*!< bit: 0 Execution privilege in Thread mode */ - uint32_t SPSEL:1; /*!< bit: 1 Stack to be used */ - uint32_t FPCA:1; /*!< bit: 2 FP extension active flag */ - uint32_t _reserved0:29; /*!< bit: 3..31 Reserved */ - } b; /*!< Structure used for bit access */ - uint32_t w; /*!< Type used for word access */ +typedef union { + struct { + uint32_t nPRIV: 1; /*!< bit: 0 Execution privilege in Thread mode */ + uint32_t SPSEL: 1; /*!< bit: 1 Stack to be used */ + uint32_t FPCA: 1; /*!< bit: 2 FP extension active flag */ + uint32_t _reserved0: 29; /*!< bit: 3..31 Reserved */ + } b; /*!< Structure used for bit access */ + uint32_t w; /*!< Type used for word access */ } CONTROL_Type; /* CONTROL Register Definitions */ @@ -408,21 +400,20 @@ typedef union /** \brief Structure type to access the Nested Vectored Interrupt Controller (NVIC). */ -typedef struct -{ - __IOM uint32_t ISER[8U]; /*!< Offset: 0x000 (R/W) Interrupt Set Enable Register */ - uint32_t RESERVED0[24U]; - __IOM uint32_t ICER[8U]; /*!< Offset: 0x080 (R/W) Interrupt Clear Enable Register */ - uint32_t RESERVED1[24U]; - __IOM uint32_t ISPR[8U]; /*!< Offset: 0x100 (R/W) Interrupt Set Pending Register */ - uint32_t RESERVED2[24U]; - __IOM uint32_t ICPR[8U]; /*!< Offset: 0x180 (R/W) Interrupt Clear Pending Register */ - uint32_t RESERVED3[24U]; - __IOM uint32_t IABR[8U]; /*!< Offset: 0x200 (R/W) Interrupt Active bit Register */ - uint32_t RESERVED4[56U]; - __IOM uint8_t IP[240U]; /*!< Offset: 0x300 (R/W) Interrupt Priority Register (8Bit wide) */ - uint32_t RESERVED5[644U]; - __OM uint32_t STIR; /*!< Offset: 0xE00 ( /W) Software Trigger Interrupt Register */ +typedef struct { + __IOM uint32_t ISER[8U]; /*!< Offset: 0x000 (R/W) Interrupt Set Enable Register */ + uint32_t RESERVED0[24U]; + __IOM uint32_t ICER[8U]; /*!< Offset: 0x080 (R/W) Interrupt Clear Enable Register */ + uint32_t RESERVED1[24U]; + __IOM uint32_t ISPR[8U]; /*!< Offset: 0x100 (R/W) Interrupt Set Pending Register */ + uint32_t RESERVED2[24U]; + __IOM uint32_t ICPR[8U]; /*!< Offset: 0x180 (R/W) Interrupt Clear Pending Register */ + uint32_t RESERVED3[24U]; + __IOM uint32_t IABR[8U]; /*!< Offset: 0x200 (R/W) Interrupt Active bit Register */ + uint32_t RESERVED4[56U]; + __IOM uint8_t IP[240U]; /*!< Offset: 0x300 (R/W) Interrupt Priority Register (8Bit wide) */ + uint32_t RESERVED5[644U]; + __OM uint32_t STIR; /*!< Offset: 0xE00 ( /W) Software Trigger Interrupt Register */ } NVIC_Type; /* Software Triggered Interrupt Register Definitions */ @@ -442,29 +433,28 @@ typedef struct /** \brief Structure type to access the System Control Block (SCB). */ -typedef struct -{ - __IM uint32_t CPUID; /*!< Offset: 0x000 (R/ ) CPUID Base Register */ - __IOM uint32_t ICSR; /*!< Offset: 0x004 (R/W) Interrupt Control and State Register */ - __IOM uint32_t VTOR; /*!< Offset: 0x008 (R/W) Vector Table Offset Register */ - __IOM uint32_t AIRCR; /*!< Offset: 0x00C (R/W) Application Interrupt and Reset Control Register */ - __IOM uint32_t SCR; /*!< Offset: 0x010 (R/W) System Control Register */ - __IOM uint32_t CCR; /*!< Offset: 0x014 (R/W) Configuration Control Register */ - __IOM uint8_t SHP[12U]; /*!< Offset: 0x018 (R/W) System Handlers Priority Registers (4-7, 8-11, 12-15) */ - __IOM uint32_t SHCSR; /*!< Offset: 0x024 (R/W) System Handler Control and State Register */ - __IOM uint32_t CFSR; /*!< Offset: 0x028 (R/W) Configurable Fault Status Register */ - __IOM uint32_t HFSR; /*!< Offset: 0x02C (R/W) HardFault Status Register */ - __IOM uint32_t DFSR; /*!< Offset: 0x030 (R/W) Debug Fault Status Register */ - __IOM uint32_t MMFAR; /*!< Offset: 0x034 (R/W) MemManage Fault Address Register */ - __IOM uint32_t BFAR; /*!< Offset: 0x038 (R/W) BusFault Address Register */ - __IOM uint32_t AFSR; /*!< Offset: 0x03C (R/W) Auxiliary Fault Status Register */ - __IM uint32_t PFR[2U]; /*!< Offset: 0x040 (R/ ) Processor Feature Register */ - __IM uint32_t DFR; /*!< Offset: 0x048 (R/ ) Debug Feature Register */ - __IM uint32_t ADR; /*!< Offset: 0x04C (R/ ) Auxiliary Feature Register */ - __IM uint32_t MMFR[4U]; /*!< Offset: 0x050 (R/ ) Memory Model Feature Register */ - __IM uint32_t ISAR[5U]; /*!< Offset: 0x060 (R/ ) Instruction Set Attributes Register */ - uint32_t RESERVED0[5U]; - __IOM uint32_t CPACR; /*!< Offset: 0x088 (R/W) Coprocessor Access Control Register */ +typedef struct { + __IM uint32_t CPUID; /*!< Offset: 0x000 (R/ ) CPUID Base Register */ + __IOM uint32_t ICSR; /*!< Offset: 0x004 (R/W) Interrupt Control and State Register */ + __IOM uint32_t VTOR; /*!< Offset: 0x008 (R/W) Vector Table Offset Register */ + __IOM uint32_t AIRCR; /*!< Offset: 0x00C (R/W) Application Interrupt and Reset Control Register */ + __IOM uint32_t SCR; /*!< Offset: 0x010 (R/W) System Control Register */ + __IOM uint32_t CCR; /*!< Offset: 0x014 (R/W) Configuration Control Register */ + __IOM uint8_t SHP[12U]; /*!< Offset: 0x018 (R/W) System Handlers Priority Registers (4-7, 8-11, 12-15) */ + __IOM uint32_t SHCSR; /*!< Offset: 0x024 (R/W) System Handler Control and State Register */ + __IOM uint32_t CFSR; /*!< Offset: 0x028 (R/W) Configurable Fault Status Register */ + __IOM uint32_t HFSR; /*!< Offset: 0x02C (R/W) HardFault Status Register */ + __IOM uint32_t DFSR; /*!< Offset: 0x030 (R/W) Debug Fault Status Register */ + __IOM uint32_t MMFAR; /*!< Offset: 0x034 (R/W) MemManage Fault Address Register */ + __IOM uint32_t BFAR; /*!< Offset: 0x038 (R/W) BusFault Address Register */ + __IOM uint32_t AFSR; /*!< Offset: 0x03C (R/W) Auxiliary Fault Status Register */ + __IM uint32_t PFR[2U]; /*!< Offset: 0x040 (R/ ) Processor Feature Register */ + __IM uint32_t DFR; /*!< Offset: 0x048 (R/ ) Debug Feature Register */ + __IM uint32_t ADR; /*!< Offset: 0x04C (R/ ) Auxiliary Feature Register */ + __IM uint32_t MMFR[4U]; /*!< Offset: 0x050 (R/ ) Memory Model Feature Register */ + __IM uint32_t ISAR[5U]; /*!< Offset: 0x060 (R/ ) Instruction Set Attributes Register */ + uint32_t RESERVED0[5U]; + __IOM uint32_t CPACR; /*!< Offset: 0x088 (R/W) Coprocessor Access Control Register */ } SCB_Type; /* SCB CPUID Register Definitions */ @@ -721,11 +711,10 @@ typedef struct /** \brief Structure type to access the System Control and ID Register not in the SCB. */ -typedef struct -{ - uint32_t RESERVED0[1U]; - __IM uint32_t ICTR; /*!< Offset: 0x004 (R/ ) Interrupt Controller Type Register */ - __IOM uint32_t ACTLR; /*!< Offset: 0x008 (R/W) Auxiliary Control Register */ +typedef struct { + uint32_t RESERVED0[1U]; + __IM uint32_t ICTR; /*!< Offset: 0x004 (R/ ) Interrupt Controller Type Register */ + __IOM uint32_t ACTLR; /*!< Offset: 0x008 (R/W) Auxiliary Control Register */ } SCnSCB_Type; /* Interrupt Controller Type Register Definitions */ @@ -761,12 +750,11 @@ typedef struct /** \brief Structure type to access the System Timer (SysTick). */ -typedef struct -{ - __IOM uint32_t CTRL; /*!< Offset: 0x000 (R/W) SysTick Control and Status Register */ - __IOM uint32_t LOAD; /*!< Offset: 0x004 (R/W) SysTick Reload Value Register */ - __IOM uint32_t VAL; /*!< Offset: 0x008 (R/W) SysTick Current Value Register */ - __IM uint32_t CALIB; /*!< Offset: 0x00C (R/ ) SysTick Calibration Register */ +typedef struct { + __IOM uint32_t CTRL; /*!< Offset: 0x000 (R/W) SysTick Control and Status Register */ + __IOM uint32_t LOAD; /*!< Offset: 0x004 (R/W) SysTick Reload Value Register */ + __IOM uint32_t VAL; /*!< Offset: 0x008 (R/W) SysTick Current Value Register */ + __IM uint32_t CALIB; /*!< Offset: 0x00C (R/ ) SysTick Calibration Register */ } SysTick_Type; /* SysTick Control / Status Register Definitions */ @@ -813,37 +801,35 @@ typedef struct /** \brief Structure type to access the Instrumentation Trace Macrocell Register (ITM). */ -typedef struct -{ - __OM union - { - __OM uint8_t u8; /*!< Offset: 0x000 ( /W) ITM Stimulus Port 8-bit */ - __OM uint16_t u16; /*!< Offset: 0x000 ( /W) ITM Stimulus Port 16-bit */ - __OM uint32_t u32; /*!< Offset: 0x000 ( /W) ITM Stimulus Port 32-bit */ - } PORT [32U]; /*!< Offset: 0x000 ( /W) ITM Stimulus Port Registers */ - uint32_t RESERVED0[864U]; - __IOM uint32_t TER; /*!< Offset: 0xE00 (R/W) ITM Trace Enable Register */ - uint32_t RESERVED1[15U]; - __IOM uint32_t TPR; /*!< Offset: 0xE40 (R/W) ITM Trace Privilege Register */ - uint32_t RESERVED2[15U]; - __IOM uint32_t TCR; /*!< Offset: 0xE80 (R/W) ITM Trace Control Register */ - uint32_t RESERVED3[32U]; - uint32_t RESERVED4[43U]; - __OM uint32_t LAR; /*!< Offset: 0xFB0 ( /W) ITM Lock Access Register */ - __IM uint32_t LSR; /*!< Offset: 0xFB4 (R/ ) ITM Lock Status Register */ - uint32_t RESERVED5[6U]; - __IM uint32_t PID4; /*!< Offset: 0xFD0 (R/ ) ITM Peripheral Identification Register #4 */ - __IM uint32_t PID5; /*!< Offset: 0xFD4 (R/ ) ITM Peripheral Identification Register #5 */ - __IM uint32_t PID6; /*!< Offset: 0xFD8 (R/ ) ITM Peripheral Identification Register #6 */ - __IM uint32_t PID7; /*!< Offset: 0xFDC (R/ ) ITM Peripheral Identification Register #7 */ - __IM uint32_t PID0; /*!< Offset: 0xFE0 (R/ ) ITM Peripheral Identification Register #0 */ - __IM uint32_t PID1; /*!< Offset: 0xFE4 (R/ ) ITM Peripheral Identification Register #1 */ - __IM uint32_t PID2; /*!< Offset: 0xFE8 (R/ ) ITM Peripheral Identification Register #2 */ - __IM uint32_t PID3; /*!< Offset: 0xFEC (R/ ) ITM Peripheral Identification Register #3 */ - __IM uint32_t CID0; /*!< Offset: 0xFF0 (R/ ) ITM Component Identification Register #0 */ - __IM uint32_t CID1; /*!< Offset: 0xFF4 (R/ ) ITM Component Identification Register #1 */ - __IM uint32_t CID2; /*!< Offset: 0xFF8 (R/ ) ITM Component Identification Register #2 */ - __IM uint32_t CID3; /*!< Offset: 0xFFC (R/ ) ITM Component Identification Register #3 */ +typedef struct { + __OM union { + __OM uint8_t u8; /*!< Offset: 0x000 ( /W) ITM Stimulus Port 8-bit */ + __OM uint16_t u16; /*!< Offset: 0x000 ( /W) ITM Stimulus Port 16-bit */ + __OM uint32_t u32; /*!< Offset: 0x000 ( /W) ITM Stimulus Port 32-bit */ + } PORT [32U]; /*!< Offset: 0x000 ( /W) ITM Stimulus Port Registers */ + uint32_t RESERVED0[864U]; + __IOM uint32_t TER; /*!< Offset: 0xE00 (R/W) ITM Trace Enable Register */ + uint32_t RESERVED1[15U]; + __IOM uint32_t TPR; /*!< Offset: 0xE40 (R/W) ITM Trace Privilege Register */ + uint32_t RESERVED2[15U]; + __IOM uint32_t TCR; /*!< Offset: 0xE80 (R/W) ITM Trace Control Register */ + uint32_t RESERVED3[32U]; + uint32_t RESERVED4[43U]; + __OM uint32_t LAR; /*!< Offset: 0xFB0 ( /W) ITM Lock Access Register */ + __IM uint32_t LSR; /*!< Offset: 0xFB4 (R/ ) ITM Lock Status Register */ + uint32_t RESERVED5[6U]; + __IM uint32_t PID4; /*!< Offset: 0xFD0 (R/ ) ITM Peripheral Identification Register #4 */ + __IM uint32_t PID5; /*!< Offset: 0xFD4 (R/ ) ITM Peripheral Identification Register #5 */ + __IM uint32_t PID6; /*!< Offset: 0xFD8 (R/ ) ITM Peripheral Identification Register #6 */ + __IM uint32_t PID7; /*!< Offset: 0xFDC (R/ ) ITM Peripheral Identification Register #7 */ + __IM uint32_t PID0; /*!< Offset: 0xFE0 (R/ ) ITM Peripheral Identification Register #0 */ + __IM uint32_t PID1; /*!< Offset: 0xFE4 (R/ ) ITM Peripheral Identification Register #1 */ + __IM uint32_t PID2; /*!< Offset: 0xFE8 (R/ ) ITM Peripheral Identification Register #2 */ + __IM uint32_t PID3; /*!< Offset: 0xFEC (R/ ) ITM Peripheral Identification Register #3 */ + __IM uint32_t CID0; /*!< Offset: 0xFF0 (R/ ) ITM Component Identification Register #0 */ + __IM uint32_t CID1; /*!< Offset: 0xFF4 (R/ ) ITM Component Identification Register #1 */ + __IM uint32_t CID2; /*!< Offset: 0xFF8 (R/ ) ITM Component Identification Register #2 */ + __IM uint32_t CID3; /*!< Offset: 0xFFC (R/ ) ITM Component Identification Register #3 */ } ITM_Type; /* ITM Trace Privilege Register Definitions */ @@ -901,31 +887,30 @@ typedef struct /** \brief Structure type to access the Data Watchpoint and Trace Register (DWT). */ -typedef struct -{ - __IOM uint32_t CTRL; /*!< Offset: 0x000 (R/W) Control Register */ - __IOM uint32_t CYCCNT; /*!< Offset: 0x004 (R/W) Cycle Count Register */ - __IOM uint32_t CPICNT; /*!< Offset: 0x008 (R/W) CPI Count Register */ - __IOM uint32_t EXCCNT; /*!< Offset: 0x00C (R/W) Exception Overhead Count Register */ - __IOM uint32_t SLEEPCNT; /*!< Offset: 0x010 (R/W) Sleep Count Register */ - __IOM uint32_t LSUCNT; /*!< Offset: 0x014 (R/W) LSU Count Register */ - __IOM uint32_t FOLDCNT; /*!< Offset: 0x018 (R/W) Folded-instruction Count Register */ - __IM uint32_t PCSR; /*!< Offset: 0x01C (R/ ) Program Counter Sample Register */ - __IOM uint32_t COMP0; /*!< Offset: 0x020 (R/W) Comparator Register 0 */ - __IOM uint32_t MASK0; /*!< Offset: 0x024 (R/W) Mask Register 0 */ - __IOM uint32_t FUNCTION0; /*!< Offset: 0x028 (R/W) Function Register 0 */ - uint32_t RESERVED0[1U]; - __IOM uint32_t COMP1; /*!< Offset: 0x030 (R/W) Comparator Register 1 */ - __IOM uint32_t MASK1; /*!< Offset: 0x034 (R/W) Mask Register 1 */ - __IOM uint32_t FUNCTION1; /*!< Offset: 0x038 (R/W) Function Register 1 */ - uint32_t RESERVED1[1U]; - __IOM uint32_t COMP2; /*!< Offset: 0x040 (R/W) Comparator Register 2 */ - __IOM uint32_t MASK2; /*!< Offset: 0x044 (R/W) Mask Register 2 */ - __IOM uint32_t FUNCTION2; /*!< Offset: 0x048 (R/W) Function Register 2 */ - uint32_t RESERVED2[1U]; - __IOM uint32_t COMP3; /*!< Offset: 0x050 (R/W) Comparator Register 3 */ - __IOM uint32_t MASK3; /*!< Offset: 0x054 (R/W) Mask Register 3 */ - __IOM uint32_t FUNCTION3; /*!< Offset: 0x058 (R/W) Function Register 3 */ +typedef struct { + __IOM uint32_t CTRL; /*!< Offset: 0x000 (R/W) Control Register */ + __IOM uint32_t CYCCNT; /*!< Offset: 0x004 (R/W) Cycle Count Register */ + __IOM uint32_t CPICNT; /*!< Offset: 0x008 (R/W) CPI Count Register */ + __IOM uint32_t EXCCNT; /*!< Offset: 0x00C (R/W) Exception Overhead Count Register */ + __IOM uint32_t SLEEPCNT; /*!< Offset: 0x010 (R/W) Sleep Count Register */ + __IOM uint32_t LSUCNT; /*!< Offset: 0x014 (R/W) LSU Count Register */ + __IOM uint32_t FOLDCNT; /*!< Offset: 0x018 (R/W) Folded-instruction Count Register */ + __IM uint32_t PCSR; /*!< Offset: 0x01C (R/ ) Program Counter Sample Register */ + __IOM uint32_t COMP0; /*!< Offset: 0x020 (R/W) Comparator Register 0 */ + __IOM uint32_t MASK0; /*!< Offset: 0x024 (R/W) Mask Register 0 */ + __IOM uint32_t FUNCTION0; /*!< Offset: 0x028 (R/W) Function Register 0 */ + uint32_t RESERVED0[1U]; + __IOM uint32_t COMP1; /*!< Offset: 0x030 (R/W) Comparator Register 1 */ + __IOM uint32_t MASK1; /*!< Offset: 0x034 (R/W) Mask Register 1 */ + __IOM uint32_t FUNCTION1; /*!< Offset: 0x038 (R/W) Function Register 1 */ + uint32_t RESERVED1[1U]; + __IOM uint32_t COMP2; /*!< Offset: 0x040 (R/W) Comparator Register 2 */ + __IOM uint32_t MASK2; /*!< Offset: 0x044 (R/W) Mask Register 2 */ + __IOM uint32_t FUNCTION2; /*!< Offset: 0x048 (R/W) Function Register 2 */ + uint32_t RESERVED2[1U]; + __IOM uint32_t COMP3; /*!< Offset: 0x050 (R/W) Comparator Register 3 */ + __IOM uint32_t MASK3; /*!< Offset: 0x054 (R/W) Mask Register 3 */ + __IOM uint32_t FUNCTION3; /*!< Offset: 0x058 (R/W) Function Register 3 */ } DWT_Type; /* DWT Control Register Definitions */ @@ -1048,32 +1033,31 @@ typedef struct /** \brief Structure type to access the Trace Port Interface Register (TPI). */ -typedef struct -{ - __IM uint32_t SSPSR; /*!< Offset: 0x000 (R/ ) Supported Parallel Port Size Register */ - __IOM uint32_t CSPSR; /*!< Offset: 0x004 (R/W) Current Parallel Port Size Register */ - uint32_t RESERVED0[2U]; - __IOM uint32_t ACPR; /*!< Offset: 0x010 (R/W) Asynchronous Clock Prescaler Register */ - uint32_t RESERVED1[55U]; - __IOM uint32_t SPPR; /*!< Offset: 0x0F0 (R/W) Selected Pin Protocol Register */ - uint32_t RESERVED2[131U]; - __IM uint32_t FFSR; /*!< Offset: 0x300 (R/ ) Formatter and Flush Status Register */ - __IOM uint32_t FFCR; /*!< Offset: 0x304 (R/W) Formatter and Flush Control Register */ - __IM uint32_t FSCR; /*!< Offset: 0x308 (R/ ) Formatter Synchronization Counter Register */ - uint32_t RESERVED3[759U]; - __IM uint32_t TRIGGER; /*!< Offset: 0xEE8 (R/ ) TRIGGER Register */ - __IM uint32_t FIFO0; /*!< Offset: 0xEEC (R/ ) Integration ETM Data */ - __IM uint32_t ITATBCTR2; /*!< Offset: 0xEF0 (R/ ) ITATBCTR2 */ - uint32_t RESERVED4[1U]; - __IM uint32_t ITATBCTR0; /*!< Offset: 0xEF8 (R/ ) ITATBCTR0 */ - __IM uint32_t FIFO1; /*!< Offset: 0xEFC (R/ ) Integration ITM Data */ - __IOM uint32_t ITCTRL; /*!< Offset: 0xF00 (R/W) Integration Mode Control */ - uint32_t RESERVED5[39U]; - __IOM uint32_t CLAIMSET; /*!< Offset: 0xFA0 (R/W) Claim tag set */ - __IOM uint32_t CLAIMCLR; /*!< Offset: 0xFA4 (R/W) Claim tag clear */ - uint32_t RESERVED7[8U]; - __IM uint32_t DEVID; /*!< Offset: 0xFC8 (R/ ) TPIU_DEVID */ - __IM uint32_t DEVTYPE; /*!< Offset: 0xFCC (R/ ) TPIU_DEVTYPE */ +typedef struct { + __IM uint32_t SSPSR; /*!< Offset: 0x000 (R/ ) Supported Parallel Port Size Register */ + __IOM uint32_t CSPSR; /*!< Offset: 0x004 (R/W) Current Parallel Port Size Register */ + uint32_t RESERVED0[2U]; + __IOM uint32_t ACPR; /*!< Offset: 0x010 (R/W) Asynchronous Clock Prescaler Register */ + uint32_t RESERVED1[55U]; + __IOM uint32_t SPPR; /*!< Offset: 0x0F0 (R/W) Selected Pin Protocol Register */ + uint32_t RESERVED2[131U]; + __IM uint32_t FFSR; /*!< Offset: 0x300 (R/ ) Formatter and Flush Status Register */ + __IOM uint32_t FFCR; /*!< Offset: 0x304 (R/W) Formatter and Flush Control Register */ + __IM uint32_t FSCR; /*!< Offset: 0x308 (R/ ) Formatter Synchronization Counter Register */ + uint32_t RESERVED3[759U]; + __IM uint32_t TRIGGER; /*!< Offset: 0xEE8 (R/ ) TRIGGER Register */ + __IM uint32_t FIFO0; /*!< Offset: 0xEEC (R/ ) Integration ETM Data */ + __IM uint32_t ITATBCTR2; /*!< Offset: 0xEF0 (R/ ) ITATBCTR2 */ + uint32_t RESERVED4[1U]; + __IM uint32_t ITATBCTR0; /*!< Offset: 0xEF8 (R/ ) ITATBCTR0 */ + __IM uint32_t FIFO1; /*!< Offset: 0xEFC (R/ ) Integration ITM Data */ + __IOM uint32_t ITCTRL; /*!< Offset: 0xF00 (R/W) Integration Mode Control */ + uint32_t RESERVED5[39U]; + __IOM uint32_t CLAIMSET; /*!< Offset: 0xFA0 (R/W) Claim tag set */ + __IOM uint32_t CLAIMCLR; /*!< Offset: 0xFA4 (R/W) Claim tag clear */ + uint32_t RESERVED7[8U]; + __IM uint32_t DEVID; /*!< Offset: 0xFC8 (R/ ) TPIU_DEVID */ + __IM uint32_t DEVTYPE; /*!< Offset: 0xFCC (R/ ) TPIU_DEVTYPE */ } TPI_Type; /* TPI Asynchronous Clock Prescaler Register Definitions */ @@ -1210,19 +1194,18 @@ typedef struct /** \brief Structure type to access the Memory Protection Unit (MPU). */ -typedef struct -{ - __IM uint32_t TYPE; /*!< Offset: 0x000 (R/ ) MPU Type Register */ - __IOM uint32_t CTRL; /*!< Offset: 0x004 (R/W) MPU Control Register */ - __IOM uint32_t RNR; /*!< Offset: 0x008 (R/W) MPU Region RNRber Register */ - __IOM uint32_t RBAR; /*!< Offset: 0x00C (R/W) MPU Region Base Address Register */ - __IOM uint32_t RASR; /*!< Offset: 0x010 (R/W) MPU Region Attribute and Size Register */ - __IOM uint32_t RBAR_A1; /*!< Offset: 0x014 (R/W) MPU Alias 1 Region Base Address Register */ - __IOM uint32_t RASR_A1; /*!< Offset: 0x018 (R/W) MPU Alias 1 Region Attribute and Size Register */ - __IOM uint32_t RBAR_A2; /*!< Offset: 0x01C (R/W) MPU Alias 2 Region Base Address Register */ - __IOM uint32_t RASR_A2; /*!< Offset: 0x020 (R/W) MPU Alias 2 Region Attribute and Size Register */ - __IOM uint32_t RBAR_A3; /*!< Offset: 0x024 (R/W) MPU Alias 3 Region Base Address Register */ - __IOM uint32_t RASR_A3; /*!< Offset: 0x028 (R/W) MPU Alias 3 Region Attribute and Size Register */ +typedef struct { + __IM uint32_t TYPE; /*!< Offset: 0x000 (R/ ) MPU Type Register */ + __IOM uint32_t CTRL; /*!< Offset: 0x004 (R/W) MPU Control Register */ + __IOM uint32_t RNR; /*!< Offset: 0x008 (R/W) MPU Region RNRber Register */ + __IOM uint32_t RBAR; /*!< Offset: 0x00C (R/W) MPU Region Base Address Register */ + __IOM uint32_t RASR; /*!< Offset: 0x010 (R/W) MPU Region Attribute and Size Register */ + __IOM uint32_t RBAR_A1; /*!< Offset: 0x014 (R/W) MPU Alias 1 Region Base Address Register */ + __IOM uint32_t RASR_A1; /*!< Offset: 0x018 (R/W) MPU Alias 1 Region Attribute and Size Register */ + __IOM uint32_t RBAR_A2; /*!< Offset: 0x01C (R/W) MPU Alias 2 Region Base Address Register */ + __IOM uint32_t RASR_A2; /*!< Offset: 0x020 (R/W) MPU Alias 2 Region Attribute and Size Register */ + __IOM uint32_t RBAR_A3; /*!< Offset: 0x024 (R/W) MPU Alias 3 Region Base Address Register */ + __IOM uint32_t RASR_A3; /*!< Offset: 0x028 (R/W) MPU Alias 3 Region Attribute and Size Register */ } MPU_Type; #define MPU_TYPE_RALIASES 4U @@ -1306,15 +1289,14 @@ typedef struct /** \brief Structure type to access the Floating Point Unit (FPU). */ -typedef struct -{ - uint32_t RESERVED0[1U]; - __IOM uint32_t FPCCR; /*!< Offset: 0x004 (R/W) Floating-Point Context Control Register */ - __IOM uint32_t FPCAR; /*!< Offset: 0x008 (R/W) Floating-Point Context Address Register */ - __IOM uint32_t FPDSCR; /*!< Offset: 0x00C (R/W) Floating-Point Default Status Control Register */ - __IM uint32_t MVFR0; /*!< Offset: 0x010 (R/ ) Media and FP Feature Register 0 */ - __IM uint32_t MVFR1; /*!< Offset: 0x014 (R/ ) Media and FP Feature Register 1 */ - __IM uint32_t MVFR2; /*!< Offset: 0x018 (R/ ) Media and FP Feature Register 2 */ +typedef struct { + uint32_t RESERVED0[1U]; + __IOM uint32_t FPCCR; /*!< Offset: 0x004 (R/W) Floating-Point Context Control Register */ + __IOM uint32_t FPCAR; /*!< Offset: 0x008 (R/W) Floating-Point Context Address Register */ + __IOM uint32_t FPDSCR; /*!< Offset: 0x00C (R/W) Floating-Point Default Status Control Register */ + __IM uint32_t MVFR0; /*!< Offset: 0x010 (R/ ) Media and FP Feature Register 0 */ + __IM uint32_t MVFR1; /*!< Offset: 0x014 (R/ ) Media and FP Feature Register 1 */ + __IM uint32_t MVFR2; /*!< Offset: 0x018 (R/ ) Media and FP Feature Register 2 */ } FPU_Type; /* Floating-Point Context Control Register Definitions */ @@ -1418,12 +1400,11 @@ typedef struct /** \brief Structure type to access the Core Debug Register (CoreDebug). */ -typedef struct -{ - __IOM uint32_t DHCSR; /*!< Offset: 0x000 (R/W) Debug Halting Control and Status Register */ - __OM uint32_t DCRSR; /*!< Offset: 0x004 ( /W) Debug Core Register Selector Register */ - __IOM uint32_t DCRDR; /*!< Offset: 0x008 (R/W) Debug Core Register Data Register */ - __IOM uint32_t DEMCR; /*!< Offset: 0x00C (R/W) Debug Exception and Monitor Control Register */ +typedef struct { + __IOM uint32_t DHCSR; /*!< Offset: 0x000 (R/W) Debug Halting Control and Status Register */ + __OM uint32_t DCRSR; /*!< Offset: 0x004 ( /W) Debug Core Register Selector Register */ + __IOM uint32_t DCRDR; /*!< Offset: 0x008 (R/W) Debug Core Register Data Register */ + __IOM uint32_t DEMCR; /*!< Offset: 0x00C (R/W) Debug Exception and Monitor Control Register */ } CoreDebug_Type; /* Debug Halting Control and Status Register Definitions */ @@ -1566,8 +1547,8 @@ typedef struct #define CoreDebug ((CoreDebug_Type *) CoreDebug_BASE) /*!< Core Debug configuration struct */ #if defined (__MPU_PRESENT) && (__MPU_PRESENT == 1U) - #define MPU_BASE (SCS_BASE + 0x0D90UL) /*!< Memory Protection Unit */ - #define MPU ((MPU_Type *) MPU_BASE ) /*!< Memory Protection Unit */ +#define MPU_BASE (SCS_BASE + 0x0D90UL) /*!< Memory Protection Unit */ +#define MPU ((MPU_Type *) MPU_BASE ) /*!< Memory Protection Unit */ #endif #define FPU_BASE (SCS_BASE + 0x0F30UL) /*!< Floating Point Unit */ @@ -1600,33 +1581,33 @@ typedef struct */ #ifdef CMSIS_NVIC_VIRTUAL - #ifndef CMSIS_NVIC_VIRTUAL_HEADER_FILE - #define CMSIS_NVIC_VIRTUAL_HEADER_FILE "cmsis_nvic_virtual.h" - #endif - #include CMSIS_NVIC_VIRTUAL_HEADER_FILE +#ifndef CMSIS_NVIC_VIRTUAL_HEADER_FILE +#define CMSIS_NVIC_VIRTUAL_HEADER_FILE "cmsis_nvic_virtual.h" +#endif +#include CMSIS_NVIC_VIRTUAL_HEADER_FILE #else - #define NVIC_SetPriorityGrouping __NVIC_SetPriorityGrouping - #define NVIC_GetPriorityGrouping __NVIC_GetPriorityGrouping - #define NVIC_EnableIRQ __NVIC_EnableIRQ - #define NVIC_GetEnableIRQ __NVIC_GetEnableIRQ - #define NVIC_DisableIRQ __NVIC_DisableIRQ - #define NVIC_GetPendingIRQ __NVIC_GetPendingIRQ - #define NVIC_SetPendingIRQ __NVIC_SetPendingIRQ - #define NVIC_ClearPendingIRQ __NVIC_ClearPendingIRQ - #define NVIC_GetActive __NVIC_GetActive - #define NVIC_SetPriority __NVIC_SetPriority - #define NVIC_GetPriority __NVIC_GetPriority - #define NVIC_SystemReset __NVIC_SystemReset +#define NVIC_SetPriorityGrouping __NVIC_SetPriorityGrouping +#define NVIC_GetPriorityGrouping __NVIC_GetPriorityGrouping +#define NVIC_EnableIRQ __NVIC_EnableIRQ +#define NVIC_GetEnableIRQ __NVIC_GetEnableIRQ +#define NVIC_DisableIRQ __NVIC_DisableIRQ +#define NVIC_GetPendingIRQ __NVIC_GetPendingIRQ +#define NVIC_SetPendingIRQ __NVIC_SetPendingIRQ +#define NVIC_ClearPendingIRQ __NVIC_ClearPendingIRQ +#define NVIC_GetActive __NVIC_GetActive +#define NVIC_SetPriority __NVIC_SetPriority +#define NVIC_GetPriority __NVIC_GetPriority +#define NVIC_SystemReset __NVIC_SystemReset #endif /* CMSIS_NVIC_VIRTUAL */ #ifdef CMSIS_VECTAB_VIRTUAL - #ifndef CMSIS_VECTAB_VIRTUAL_HEADER_FILE - #define CMSIS_VECTAB_VIRTUAL_HEADER_FILE "cmsis_vectab_virtual.h" - #endif - #include CMSIS_VECTAB_VIRTUAL_HEADER_FILE +#ifndef CMSIS_VECTAB_VIRTUAL_HEADER_FILE +#define CMSIS_VECTAB_VIRTUAL_HEADER_FILE "cmsis_vectab_virtual.h" +#endif +#include CMSIS_VECTAB_VIRTUAL_HEADER_FILE #else - #define NVIC_SetVector __NVIC_SetVector - #define NVIC_GetVector __NVIC_GetVector +#define NVIC_SetVector __NVIC_SetVector +#define NVIC_GetVector __NVIC_GetVector #endif /* (CMSIS_VECTAB_VIRTUAL) */ #define NVIC_USER_IRQ_OFFSET 16 @@ -1650,17 +1631,16 @@ typedef struct priority bits (__NVIC_PRIO_BITS), the smallest possible priority group is set. \param [in] PriorityGroup Priority grouping field. */ -__STATIC_INLINE void __NVIC_SetPriorityGrouping(uint32_t PriorityGroup) -{ - uint32_t reg_value; - uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07UL); /* only values 0..7 are used */ +__STATIC_INLINE void __NVIC_SetPriorityGrouping(uint32_t PriorityGroup) { + uint32_t reg_value; + uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07UL); /* only values 0..7 are used */ - reg_value = SCB->AIRCR; /* read old register configuration */ - reg_value &= ~((uint32_t)(SCB_AIRCR_VECTKEY_Msk | SCB_AIRCR_PRIGROUP_Msk)); /* clear bits to change */ - reg_value = (reg_value | - ((uint32_t)0x5FAUL << SCB_AIRCR_VECTKEY_Pos) | - (PriorityGroupTmp << SCB_AIRCR_PRIGROUP_Pos) ); /* Insert write key and priority group */ - SCB->AIRCR = reg_value; + reg_value = SCB->AIRCR; /* read old register configuration */ + reg_value &= ~((uint32_t)(SCB_AIRCR_VECTKEY_Msk | SCB_AIRCR_PRIGROUP_Msk)); /* clear bits to change */ + reg_value = (reg_value | + ((uint32_t)0x5FAUL << SCB_AIRCR_VECTKEY_Pos) | + (PriorityGroupTmp << SCB_AIRCR_PRIGROUP_Pos)); /* Insert write key and priority group */ + SCB->AIRCR = reg_value; } @@ -1669,9 +1649,8 @@ __STATIC_INLINE void __NVIC_SetPriorityGrouping(uint32_t PriorityGroup) \details Reads the priority grouping field from the NVIC Interrupt Controller. \return Priority grouping field (SCB->AIRCR [10:8] PRIGROUP field). */ -__STATIC_INLINE uint32_t __NVIC_GetPriorityGrouping(void) -{ - return ((uint32_t)((SCB->AIRCR & SCB_AIRCR_PRIGROUP_Msk) >> SCB_AIRCR_PRIGROUP_Pos)); +__STATIC_INLINE uint32_t __NVIC_GetPriorityGrouping(void) { + return ((uint32_t)((SCB->AIRCR & SCB_AIRCR_PRIGROUP_Msk) >> SCB_AIRCR_PRIGROUP_Pos)); } @@ -1681,14 +1660,12 @@ __STATIC_INLINE uint32_t __NVIC_GetPriorityGrouping(void) \param [in] IRQn Device specific interrupt number. \note IRQn must not be negative. */ -__STATIC_INLINE void __NVIC_EnableIRQ(IRQn_Type IRQn) -{ - if ((int32_t)(IRQn) >= 0) - { - __COMPILER_BARRIER(); - NVIC->ISER[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); - __COMPILER_BARRIER(); - } +__STATIC_INLINE void __NVIC_EnableIRQ(IRQn_Type IRQn) { + if ((int32_t)(IRQn) >= 0) { + __COMPILER_BARRIER(); + NVIC->ISER[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); + __COMPILER_BARRIER(); + } } @@ -1700,16 +1677,12 @@ __STATIC_INLINE void __NVIC_EnableIRQ(IRQn_Type IRQn) \return 1 Interrupt is enabled. \note IRQn must not be negative. */ -__STATIC_INLINE uint32_t __NVIC_GetEnableIRQ(IRQn_Type IRQn) -{ - if ((int32_t)(IRQn) >= 0) - { - return((uint32_t)(((NVIC->ISER[(((uint32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL)); - } - else - { - return(0U); - } +__STATIC_INLINE uint32_t __NVIC_GetEnableIRQ(IRQn_Type IRQn) { + if ((int32_t)(IRQn) >= 0) { + return ((uint32_t)(((NVIC->ISER[(((uint32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL)); + } else { + return (0U); + } } @@ -1719,14 +1692,12 @@ __STATIC_INLINE uint32_t __NVIC_GetEnableIRQ(IRQn_Type IRQn) \param [in] IRQn Device specific interrupt number. \note IRQn must not be negative. */ -__STATIC_INLINE void __NVIC_DisableIRQ(IRQn_Type IRQn) -{ - if ((int32_t)(IRQn) >= 0) - { - NVIC->ICER[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); - __DSB(); - __ISB(); - } +__STATIC_INLINE void __NVIC_DisableIRQ(IRQn_Type IRQn) { + if ((int32_t)(IRQn) >= 0) { + NVIC->ICER[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); + __DSB(); + __ISB(); + } } @@ -1738,16 +1709,12 @@ __STATIC_INLINE void __NVIC_DisableIRQ(IRQn_Type IRQn) \return 1 Interrupt status is pending. \note IRQn must not be negative. */ -__STATIC_INLINE uint32_t __NVIC_GetPendingIRQ(IRQn_Type IRQn) -{ - if ((int32_t)(IRQn) >= 0) - { - return((uint32_t)(((NVIC->ISPR[(((uint32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL)); - } - else - { - return(0U); - } +__STATIC_INLINE uint32_t __NVIC_GetPendingIRQ(IRQn_Type IRQn) { + if ((int32_t)(IRQn) >= 0) { + return ((uint32_t)(((NVIC->ISPR[(((uint32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL)); + } else { + return (0U); + } } @@ -1757,12 +1724,10 @@ __STATIC_INLINE uint32_t __NVIC_GetPendingIRQ(IRQn_Type IRQn) \param [in] IRQn Device specific interrupt number. \note IRQn must not be negative. */ -__STATIC_INLINE void __NVIC_SetPendingIRQ(IRQn_Type IRQn) -{ - if ((int32_t)(IRQn) >= 0) - { - NVIC->ISPR[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); - } +__STATIC_INLINE void __NVIC_SetPendingIRQ(IRQn_Type IRQn) { + if ((int32_t)(IRQn) >= 0) { + NVIC->ISPR[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); + } } @@ -1772,12 +1737,10 @@ __STATIC_INLINE void __NVIC_SetPendingIRQ(IRQn_Type IRQn) \param [in] IRQn Device specific interrupt number. \note IRQn must not be negative. */ -__STATIC_INLINE void __NVIC_ClearPendingIRQ(IRQn_Type IRQn) -{ - if ((int32_t)(IRQn) >= 0) - { - NVIC->ICPR[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); - } +__STATIC_INLINE void __NVIC_ClearPendingIRQ(IRQn_Type IRQn) { + if ((int32_t)(IRQn) >= 0) { + NVIC->ICPR[(((uint32_t)IRQn) >> 5UL)] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL)); + } } @@ -1789,16 +1752,12 @@ __STATIC_INLINE void __NVIC_ClearPendingIRQ(IRQn_Type IRQn) \return 1 Interrupt status is active. \note IRQn must not be negative. */ -__STATIC_INLINE uint32_t __NVIC_GetActive(IRQn_Type IRQn) -{ - if ((int32_t)(IRQn) >= 0) - { - return((uint32_t)(((NVIC->IABR[(((uint32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL)); - } - else - { - return(0U); - } +__STATIC_INLINE uint32_t __NVIC_GetActive(IRQn_Type IRQn) { + if ((int32_t)(IRQn) >= 0) { + return ((uint32_t)(((NVIC->IABR[(((uint32_t)IRQn) >> 5UL)] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL)); + } else { + return (0U); + } } @@ -1811,16 +1770,12 @@ __STATIC_INLINE uint32_t __NVIC_GetActive(IRQn_Type IRQn) \param [in] priority Priority to set. \note The priority cannot be set for every processor exception. */ -__STATIC_INLINE void __NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority) -{ - if ((int32_t)(IRQn) >= 0) - { - NVIC->IP[((uint32_t)IRQn)] = (uint8_t)((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL); - } - else - { - SCB->SHP[(((uint32_t)IRQn) & 0xFUL)-4UL] = (uint8_t)((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL); - } +__STATIC_INLINE void __NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority) { + if ((int32_t)(IRQn) >= 0) { + NVIC->IP[((uint32_t)IRQn)] = (uint8_t)((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL); + } else { + SCB->SHP[(((uint32_t)IRQn) & 0xFUL) - 4UL] = (uint8_t)((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL); + } } @@ -1833,17 +1788,13 @@ __STATIC_INLINE void __NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority) \return Interrupt Priority. Value is aligned automatically to the implemented priority bits of the microcontroller. */ -__STATIC_INLINE uint32_t __NVIC_GetPriority(IRQn_Type IRQn) -{ +__STATIC_INLINE uint32_t __NVIC_GetPriority(IRQn_Type IRQn) { - if ((int32_t)(IRQn) >= 0) - { - return(((uint32_t)NVIC->IP[((uint32_t)IRQn)] >> (8U - __NVIC_PRIO_BITS))); - } - else - { - return(((uint32_t)SCB->SHP[(((uint32_t)IRQn) & 0xFUL)-4UL] >> (8U - __NVIC_PRIO_BITS))); - } + if ((int32_t)(IRQn) >= 0) { + return (((uint32_t)NVIC->IP[((uint32_t)IRQn)] >> (8U - __NVIC_PRIO_BITS))); + } else { + return (((uint32_t)SCB->SHP[(((uint32_t)IRQn) & 0xFUL) - 4UL] >> (8U - __NVIC_PRIO_BITS))); + } } @@ -1858,19 +1809,18 @@ __STATIC_INLINE uint32_t __NVIC_GetPriority(IRQn_Type IRQn) \param [in] SubPriority Subpriority value (starting from 0). \return Encoded priority. Value can be used in the function \ref NVIC_SetPriority(). */ -__STATIC_INLINE uint32_t NVIC_EncodePriority (uint32_t PriorityGroup, uint32_t PreemptPriority, uint32_t SubPriority) -{ - uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07UL); /* only values 0..7 are used */ - uint32_t PreemptPriorityBits; - uint32_t SubPriorityBits; +__STATIC_INLINE uint32_t NVIC_EncodePriority(uint32_t PriorityGroup, uint32_t PreemptPriority, uint32_t SubPriority) { + uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07UL); /* only values 0..7 are used */ + uint32_t PreemptPriorityBits; + uint32_t SubPriorityBits; - PreemptPriorityBits = ((7UL - PriorityGroupTmp) > (uint32_t)(__NVIC_PRIO_BITS)) ? (uint32_t)(__NVIC_PRIO_BITS) : (uint32_t)(7UL - PriorityGroupTmp); - SubPriorityBits = ((PriorityGroupTmp + (uint32_t)(__NVIC_PRIO_BITS)) < (uint32_t)7UL) ? (uint32_t)0UL : (uint32_t)((PriorityGroupTmp - 7UL) + (uint32_t)(__NVIC_PRIO_BITS)); + PreemptPriorityBits = ((7UL - PriorityGroupTmp) > (uint32_t)(__NVIC_PRIO_BITS)) ? (uint32_t)(__NVIC_PRIO_BITS) : (uint32_t)(7UL - PriorityGroupTmp); + SubPriorityBits = ((PriorityGroupTmp + (uint32_t)(__NVIC_PRIO_BITS)) < (uint32_t)7UL) ? (uint32_t)0UL : (uint32_t)((PriorityGroupTmp - 7UL) + (uint32_t)(__NVIC_PRIO_BITS)); - return ( - ((PreemptPriority & (uint32_t)((1UL << (PreemptPriorityBits)) - 1UL)) << SubPriorityBits) | - ((SubPriority & (uint32_t)((1UL << (SubPriorityBits )) - 1UL))) - ); + return ( + ((PreemptPriority & (uint32_t)((1UL << (PreemptPriorityBits)) - 1UL)) << SubPriorityBits) | + ((SubPriority & (uint32_t)((1UL << (SubPriorityBits)) - 1UL))) + ); } @@ -1885,17 +1835,16 @@ __STATIC_INLINE uint32_t NVIC_EncodePriority (uint32_t PriorityGroup, uint32_t P \param [out] pPreemptPriority Preemptive priority value (starting from 0). \param [out] pSubPriority Subpriority value (starting from 0). */ -__STATIC_INLINE void NVIC_DecodePriority (uint32_t Priority, uint32_t PriorityGroup, uint32_t* const pPreemptPriority, uint32_t* const pSubPriority) -{ - uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07UL); /* only values 0..7 are used */ - uint32_t PreemptPriorityBits; - uint32_t SubPriorityBits; +__STATIC_INLINE void NVIC_DecodePriority(uint32_t Priority, uint32_t PriorityGroup, uint32_t *const pPreemptPriority, uint32_t *const pSubPriority) { + uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07UL); /* only values 0..7 are used */ + uint32_t PreemptPriorityBits; + uint32_t SubPriorityBits; - PreemptPriorityBits = ((7UL - PriorityGroupTmp) > (uint32_t)(__NVIC_PRIO_BITS)) ? (uint32_t)(__NVIC_PRIO_BITS) : (uint32_t)(7UL - PriorityGroupTmp); - SubPriorityBits = ((PriorityGroupTmp + (uint32_t)(__NVIC_PRIO_BITS)) < (uint32_t)7UL) ? (uint32_t)0UL : (uint32_t)((PriorityGroupTmp - 7UL) + (uint32_t)(__NVIC_PRIO_BITS)); + PreemptPriorityBits = ((7UL - PriorityGroupTmp) > (uint32_t)(__NVIC_PRIO_BITS)) ? (uint32_t)(__NVIC_PRIO_BITS) : (uint32_t)(7UL - PriorityGroupTmp); + SubPriorityBits = ((PriorityGroupTmp + (uint32_t)(__NVIC_PRIO_BITS)) < (uint32_t)7UL) ? (uint32_t)0UL : (uint32_t)((PriorityGroupTmp - 7UL) + (uint32_t)(__NVIC_PRIO_BITS)); - *pPreemptPriority = (Priority >> SubPriorityBits) & (uint32_t)((1UL << (PreemptPriorityBits)) - 1UL); - *pSubPriority = (Priority ) & (uint32_t)((1UL << (SubPriorityBits )) - 1UL); + *pPreemptPriority = (Priority >> SubPriorityBits) & (uint32_t)((1UL << (PreemptPriorityBits)) - 1UL); + *pSubPriority = (Priority) & (uint32_t)((1UL << (SubPriorityBits)) - 1UL); } @@ -1908,11 +1857,10 @@ __STATIC_INLINE void NVIC_DecodePriority (uint32_t Priority, uint32_t PriorityGr \param [in] IRQn Interrupt number \param [in] vector Address of interrupt handler function */ -__STATIC_INLINE void __NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) -{ - uint32_t *vectors = (uint32_t *)SCB->VTOR; - vectors[(int32_t)IRQn + NVIC_USER_IRQ_OFFSET] = vector; - /* ARM Application Note 321 states that the M4 does not require the architectural barrier */ +__STATIC_INLINE void __NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) { + uint32_t *vectors = (uint32_t *)SCB->VTOR; + vectors[(int32_t)IRQn + NVIC_USER_IRQ_OFFSET] = vector; + /* ARM Application Note 321 states that the M4 does not require the architectural barrier */ } @@ -1924,10 +1872,9 @@ __STATIC_INLINE void __NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) \param [in] IRQn Interrupt number. \return Address of interrupt handler function */ -__STATIC_INLINE uint32_t __NVIC_GetVector(IRQn_Type IRQn) -{ - uint32_t *vectors = (uint32_t *)SCB->VTOR; - return vectors[(int32_t)IRQn + NVIC_USER_IRQ_OFFSET]; +__STATIC_INLINE uint32_t __NVIC_GetVector(IRQn_Type IRQn) { + uint32_t *vectors = (uint32_t *)SCB->VTOR; + return vectors[(int32_t)IRQn + NVIC_USER_IRQ_OFFSET]; } @@ -1935,19 +1882,17 @@ __STATIC_INLINE uint32_t __NVIC_GetVector(IRQn_Type IRQn) \brief System Reset \details Initiates a system reset request to reset the MCU. */ -__NO_RETURN __STATIC_INLINE void __NVIC_SystemReset(void) -{ - __DSB(); /* Ensure all outstanding memory accesses included +__NO_RETURN __STATIC_INLINE void __NVIC_SystemReset(void) { + __DSB(); /* Ensure all outstanding memory accesses included buffered write are completed before reset */ - SCB->AIRCR = (uint32_t)((0x5FAUL << SCB_AIRCR_VECTKEY_Pos) | - (SCB->AIRCR & SCB_AIRCR_PRIGROUP_Msk) | - SCB_AIRCR_SYSRESETREQ_Msk ); /* Keep priority group unchanged */ - __DSB(); /* Ensure completion of memory access */ + SCB->AIRCR = (uint32_t)((0x5FAUL << SCB_AIRCR_VECTKEY_Pos) | + (SCB->AIRCR & SCB_AIRCR_PRIGROUP_Msk) | + SCB_AIRCR_SYSRESETREQ_Msk); /* Keep priority group unchanged */ + __DSB(); /* Ensure completion of memory access */ - for(;;) /* wait until reset */ - { - __NOP(); - } + for (;;) { /* wait until reset */ + __NOP(); + } } /*@} end of CMSIS_Core_NVICFunctions */ @@ -1978,19 +1923,15 @@ __NO_RETURN __STATIC_INLINE void __NVIC_SystemReset(void) - \b 1: Single precision FPU - \b 2: Double + Single precision FPU */ -__STATIC_INLINE uint32_t SCB_GetFPUType(void) -{ - uint32_t mvfr0; +__STATIC_INLINE uint32_t SCB_GetFPUType(void) { + uint32_t mvfr0; - mvfr0 = FPU->MVFR0; - if ((mvfr0 & (FPU_MVFR0_Single_precision_Msk | FPU_MVFR0_Double_precision_Msk)) == 0x020U) - { - return 1U; /* Single precision FPU */ - } - else - { - return 0U; /* No FPU */ - } + mvfr0 = FPU->MVFR0; + if ((mvfr0 & (FPU_MVFR0_Single_precision_Msk | FPU_MVFR0_Double_precision_Msk)) == 0x020U) { + return 1U; /* Single precision FPU */ + } else { + return 0U; /* No FPU */ + } } @@ -2019,20 +1960,18 @@ __STATIC_INLINE uint32_t SCB_GetFPUType(void) function SysTick_Config is not included. In this case, the file device.h must contain a vendor-specific implementation of this function. */ -__STATIC_INLINE uint32_t SysTick_Config(uint32_t ticks) -{ - if ((ticks - 1UL) > SysTick_LOAD_RELOAD_Msk) - { - return (1UL); /* Reload value impossible */ - } +__STATIC_INLINE uint32_t SysTick_Config(uint32_t ticks) { + if ((ticks - 1UL) > SysTick_LOAD_RELOAD_Msk) { + return (1UL); /* Reload value impossible */ + } - SysTick->LOAD = (uint32_t)(ticks - 1UL); /* set reload register */ - NVIC_SetPriority (SysTick_IRQn, (1UL << __NVIC_PRIO_BITS) - 1UL); /* set Priority for Systick Interrupt */ - SysTick->VAL = 0UL; /* Load the SysTick Counter Value */ - SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | - SysTick_CTRL_TICKINT_Msk | - SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */ - return (0UL); /* Function successful */ + SysTick->LOAD = (uint32_t)(ticks - 1UL); /* set reload register */ + NVIC_SetPriority(SysTick_IRQn, (1UL << __NVIC_PRIO_BITS) - 1UL); /* set Priority for Systick Interrupt */ + SysTick->VAL = 0UL; /* Load the SysTick Counter Value */ + SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | + SysTick_CTRL_TICKINT_Msk | + SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */ + return (0UL); /* Function successful */ } #endif @@ -2061,18 +2000,15 @@ extern volatile int32_t ITM_RxBuffer; /*!< External \param [in] ch Character to transmit. \returns Character to transmit. */ -__STATIC_INLINE uint32_t ITM_SendChar (uint32_t ch) -{ - if (((ITM->TCR & ITM_TCR_ITMENA_Msk) != 0UL) && /* ITM enabled */ - ((ITM->TER & 1UL ) != 0UL) ) /* ITM Port #0 enabled */ - { - while (ITM->PORT[0U].u32 == 0UL) - { - __NOP(); +__STATIC_INLINE uint32_t ITM_SendChar(uint32_t ch) { + if (((ITM->TCR & ITM_TCR_ITMENA_Msk) != 0UL) && /* ITM enabled */ + ((ITM->TER & 1UL) != 0UL)) { /* ITM Port #0 enabled */ + while (ITM->PORT[0U].u32 == 0UL) { + __NOP(); + } + ITM->PORT[0U].u8 = (uint8_t)ch; } - ITM->PORT[0U].u8 = (uint8_t)ch; - } - return (ch); + return (ch); } @@ -2082,17 +2018,15 @@ __STATIC_INLINE uint32_t ITM_SendChar (uint32_t ch) \return Received character. \return -1 No character pending. */ -__STATIC_INLINE int32_t ITM_ReceiveChar (void) -{ - int32_t ch = -1; /* no character available */ +__STATIC_INLINE int32_t ITM_ReceiveChar(void) { + int32_t ch = -1; /* no character available */ - if (ITM_RxBuffer != ITM_RXBUFFER_EMPTY) - { - ch = ITM_RxBuffer; - ITM_RxBuffer = ITM_RXBUFFER_EMPTY; /* ready for next character */ - } + if (ITM_RxBuffer != ITM_RXBUFFER_EMPTY) { + ch = ITM_RxBuffer; + ITM_RxBuffer = ITM_RXBUFFER_EMPTY; /* ready for next character */ + } - return (ch); + return (ch); } @@ -2102,17 +2036,13 @@ __STATIC_INLINE int32_t ITM_ReceiveChar (void) \return 0 No character available. \return 1 Character available. */ -__STATIC_INLINE int32_t ITM_CheckChar (void) -{ +__STATIC_INLINE int32_t ITM_CheckChar(void) { - if (ITM_RxBuffer == ITM_RXBUFFER_EMPTY) - { - return (0); /* no character available */ - } - else - { - return (1); /* character available */ - } + if (ITM_RxBuffer == ITM_RXBUFFER_EMPTY) { + return (0); /* no character available */ + } else { + return (1); /* character available */ + } } /*@} end of CMSIS_core_DebugFunctions */ diff --git a/armlib/at32_sys/cmsis/cm4/core_support/mpu_armv7.h b/armlib/at32_sys/cmsis/cm4/core_support/mpu_armv7.h index d9eedf81a..f3fcd4662 100644 --- a/armlib/at32_sys/cmsis/cm4/core_support/mpu_armv7.h +++ b/armlib/at32_sys/cmsis/cm4/core_support/mpu_armv7.h @@ -21,13 +21,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - + #if defined ( __ICCARM__ ) - #pragma system_include /* treat file as system include file for MISRA check */ +#pragma system_include /* treat file as system include file for MISRA check */ #elif defined (__clang__) - #pragma clang system_header /* treat file as system include file */ +#pragma clang system_header /* treat file as system include file */ #endif - + #ifndef ARM_MPU_ARMV7_H #define ARM_MPU_ARMV7_H @@ -79,12 +79,12 @@ /** * MPU Memory Access Attributes -* +* * \param TypeExtField Type extension field, allows you to configure memory access type, for example strongly ordered, peripheral. * \param IsShareable Region is shareable between multiple bus masters. * \param IsCacheable Region is cacheable, i.e. its value may be kept in cache. * \param IsBufferable Region is bufferable, i.e. using write-back caching. Cacheable but non-bufferable regions use write-through policy. -*/ +*/ #define ARM_MPU_ACCESS_(TypeExtField, IsShareable, IsCacheable, IsBufferable) \ ((((TypeExtField) << MPU_RASR_TEX_Pos) & MPU_RASR_TEX_Msk) | \ (((IsShareable) << MPU_RASR_S_Pos) & MPU_RASR_S_Msk) | \ @@ -93,7 +93,7 @@ /** * MPU Region Attribute and Size Register Value -* +* * \param DisableExec Instruction access disable bit, 1= disable instruction fetches. * \param AccessPermission Data access permissions, allows you to configure read/write access for User and Privileged mode. * \param AccessAttributes Memory access attribution, see \ref ARM_MPU_ACCESS_. @@ -110,7 +110,7 @@ /** * MPU Region Attribute and Size Register Value -* +* * \param DisableExec Instruction access disable bit, 1= disable instruction fetches. * \param AccessPermission Data access permissions, allows you to configure read/write access for User and Privileged mode. * \param TypeExtField Type extension field, allows you to configure memory access type, for example strongly ordered, peripheral. @@ -119,7 +119,7 @@ * \param IsBufferable Region is bufferable, i.e. using write-back caching. Cacheable but non-bufferable regions use write-through policy. * \param SubRegionDisable Sub-region disable field. * \param Size Region size of the region to be configured, for example 4K, 8K. -*/ +*/ #define ARM_MPU_RASR(DisableExec, AccessPermission, TypeExtField, IsShareable, IsCacheable, IsBufferable, SubRegionDisable, Size) \ ARM_MPU_RASR_EX(DisableExec, AccessPermission, ARM_MPU_ACCESS_(TypeExtField, IsShareable, IsCacheable, IsBufferable), SubRegionDisable, Size) @@ -129,7 +129,7 @@ * - Shareable * - Non-cacheable * - Non-bufferable -*/ +*/ #define ARM_MPU_ACCESS_ORDERED ARM_MPU_ACCESS_(0U, 1U, 0U, 0U) /** @@ -140,7 +140,7 @@ * - Bufferable (if shareable) or non-bufferable (if non-shareable) * * \param IsShareable Configures the device memory as shareable or non-shareable. -*/ +*/ #define ARM_MPU_ACCESS_DEVICE(IsShareable) ((IsShareable) ? ARM_MPU_ACCESS_(0U, 1U, 0U, 1U) : ARM_MPU_ACCESS_(2U, 0U, 0U, 0U)) /** @@ -153,7 +153,7 @@ * \param OuterCp Configures the outer cache policy. * \param InnerCp Configures the inner cache policy. * \param IsShareable Configures the memory as shareable or non-shareable. -*/ +*/ #define ARM_MPU_ACCESS_NORMAL(OuterCp, InnerCp, IsShareable) ARM_MPU_ACCESS_((4U | (OuterCp)), IsShareable, ((InnerCp) >> 1U), ((InnerCp) & 1U)) /** @@ -181,66 +181,61 @@ * Struct for a single MPU Region */ typedef struct { - uint32_t RBAR; //!< The region base address register value (RBAR) - uint32_t RASR; //!< The region attribute and size register value (RASR) \ref MPU_RASR + uint32_t RBAR; //!< The region base address register value (RBAR) + uint32_t RASR; //!< The region attribute and size register value (RASR) \ref MPU_RASR } ARM_MPU_Region_t; - + /** Enable the MPU. * \param MPU_Control Default access permissions for unconfigured regions. */ -__STATIC_INLINE void ARM_MPU_Enable(uint32_t MPU_Control) -{ - __DMB(); - MPU->CTRL = MPU_Control | MPU_CTRL_ENABLE_Msk; +__STATIC_INLINE void ARM_MPU_Enable(uint32_t MPU_Control) { + __DMB(); + MPU->CTRL = MPU_Control | MPU_CTRL_ENABLE_Msk; #ifdef SCB_SHCSR_MEMFAULTENA_Msk - SCB->SHCSR |= SCB_SHCSR_MEMFAULTENA_Msk; + SCB->SHCSR |= SCB_SHCSR_MEMFAULTENA_Msk; #endif - __DSB(); - __ISB(); + __DSB(); + __ISB(); } /** Disable the MPU. */ -__STATIC_INLINE void ARM_MPU_Disable(void) -{ - __DMB(); +__STATIC_INLINE void ARM_MPU_Disable(void) { + __DMB(); #ifdef SCB_SHCSR_MEMFAULTENA_Msk - SCB->SHCSR &= ~SCB_SHCSR_MEMFAULTENA_Msk; + SCB->SHCSR &= ~SCB_SHCSR_MEMFAULTENA_Msk; #endif - MPU->CTRL &= ~MPU_CTRL_ENABLE_Msk; - __DSB(); - __ISB(); + MPU->CTRL &= ~MPU_CTRL_ENABLE_Msk; + __DSB(); + __ISB(); } /** Clear and disable the given MPU region. * \param rnr Region number to be cleared. */ -__STATIC_INLINE void ARM_MPU_ClrRegion(uint32_t rnr) -{ - MPU->RNR = rnr; - MPU->RASR = 0U; +__STATIC_INLINE void ARM_MPU_ClrRegion(uint32_t rnr) { + MPU->RNR = rnr; + MPU->RASR = 0U; } /** Configure an MPU region. * \param rbar Value for RBAR register. * \param rasr Value for RASR register. -*/ -__STATIC_INLINE void ARM_MPU_SetRegion(uint32_t rbar, uint32_t rasr) -{ - MPU->RBAR = rbar; - MPU->RASR = rasr; +*/ +__STATIC_INLINE void ARM_MPU_SetRegion(uint32_t rbar, uint32_t rasr) { + MPU->RBAR = rbar; + MPU->RASR = rasr; } /** Configure the given MPU region. * \param rnr Region number to be configured. * \param rbar Value for RBAR register. * \param rasr Value for RASR register. -*/ -__STATIC_INLINE void ARM_MPU_SetRegionEx(uint32_t rnr, uint32_t rbar, uint32_t rasr) -{ - MPU->RNR = rnr; - MPU->RBAR = rbar; - MPU->RASR = rasr; +*/ +__STATIC_INLINE void ARM_MPU_SetRegionEx(uint32_t rnr, uint32_t rbar, uint32_t rasr) { + MPU->RNR = rnr; + MPU->RBAR = rbar; + MPU->RASR = rasr; } /** Memcpy with strictly ordered memory access, e.g. used by code in ARM_MPU_Load(). @@ -248,28 +243,25 @@ __STATIC_INLINE void ARM_MPU_SetRegionEx(uint32_t rnr, uint32_t rbar, uint32_t r * \param src Source data is copied from. * \param len Amount of data words to be copied. */ -__STATIC_INLINE void ARM_MPU_OrderedMemcpy(volatile uint32_t* dst, const uint32_t* __RESTRICT src, uint32_t len) -{ - uint32_t i; - for (i = 0U; i < len; ++i) - { - dst[i] = src[i]; - } +__STATIC_INLINE void ARM_MPU_OrderedMemcpy(volatile uint32_t *dst, const uint32_t *__RESTRICT src, uint32_t len) { + uint32_t i; + for (i = 0U; i < len; ++i) { + dst[i] = src[i]; + } } /** Load the given number of MPU regions from a table. * \param table Pointer to the MPU configuration table. * \param cnt Amount of regions to be configured. */ -__STATIC_INLINE void ARM_MPU_Load(ARM_MPU_Region_t const* table, uint32_t cnt) -{ - const uint32_t rowWordSize = sizeof(ARM_MPU_Region_t)/4U; - while (cnt > MPU_TYPE_RALIASES) { - ARM_MPU_OrderedMemcpy(&(MPU->RBAR), &(table->RBAR), MPU_TYPE_RALIASES*rowWordSize); - table += MPU_TYPE_RALIASES; - cnt -= MPU_TYPE_RALIASES; - } - ARM_MPU_OrderedMemcpy(&(MPU->RBAR), &(table->RBAR), cnt*rowWordSize); +__STATIC_INLINE void ARM_MPU_Load(ARM_MPU_Region_t const *table, uint32_t cnt) { + const uint32_t rowWordSize = sizeof(ARM_MPU_Region_t) / 4U; + while (cnt > MPU_TYPE_RALIASES) { + ARM_MPU_OrderedMemcpy(&(MPU->RBAR), &(table->RBAR), MPU_TYPE_RALIASES * rowWordSize); + table += MPU_TYPE_RALIASES; + cnt -= MPU_TYPE_RALIASES; + } + ARM_MPU_OrderedMemcpy(&(MPU->RBAR), &(table->RBAR), cnt * rowWordSize); } #endif diff --git a/armlib/at32_sys/cmsis/cm4/core_support/mpu_armv8.h b/armlib/at32_sys/cmsis/cm4/core_support/mpu_armv8.h index 3de16efc8..9e35661a7 100644 --- a/armlib/at32_sys/cmsis/cm4/core_support/mpu_armv8.h +++ b/armlib/at32_sys/cmsis/cm4/core_support/mpu_armv8.h @@ -23,9 +23,9 @@ */ #if defined ( __ICCARM__ ) - #pragma system_include /* treat file as system include file for MISRA check */ +#pragma system_include /* treat file as system include file for MISRA check */ #elif defined (__clang__) - #pragma clang system_header /* treat file as system include file */ +#pragma clang system_header /* treat file as system include file */ #endif #ifndef ARM_MPU_ARMV8_H @@ -102,7 +102,7 @@ (MPU_RLAR_EN_Msk)) #if defined(MPU_RLAR_PXN_Pos) - + /** \brief Region Limit Address Register with PXN value * \param LIMIT The limit address bits [31:5] for this memory region. The value is one extended. * \param PXN Privileged execute never. Defines whether code can be executed from this privileged region. @@ -113,70 +113,66 @@ (((PXN) << MPU_RLAR_PXN_Pos) & MPU_RLAR_PXN_Msk) | \ (((IDX) << MPU_RLAR_AttrIndx_Pos) & MPU_RLAR_AttrIndx_Msk) | \ (MPU_RLAR_EN_Msk)) - + #endif /** * Struct for a single MPU Region */ typedef struct { - uint32_t RBAR; /*!< Region Base Address Register value */ - uint32_t RLAR; /*!< Region Limit Address Register value */ + uint32_t RBAR; /*!< Region Base Address Register value */ + uint32_t RLAR; /*!< Region Limit Address Register value */ } ARM_MPU_Region_t; - + /** Enable the MPU. * \param MPU_Control Default access permissions for unconfigured regions. */ -__STATIC_INLINE void ARM_MPU_Enable(uint32_t MPU_Control) -{ - __DMB(); - MPU->CTRL = MPU_Control | MPU_CTRL_ENABLE_Msk; +__STATIC_INLINE void ARM_MPU_Enable(uint32_t MPU_Control) { + __DMB(); + MPU->CTRL = MPU_Control | MPU_CTRL_ENABLE_Msk; #ifdef SCB_SHCSR_MEMFAULTENA_Msk - SCB->SHCSR |= SCB_SHCSR_MEMFAULTENA_Msk; + SCB->SHCSR |= SCB_SHCSR_MEMFAULTENA_Msk; #endif - __DSB(); - __ISB(); + __DSB(); + __ISB(); } /** Disable the MPU. */ -__STATIC_INLINE void ARM_MPU_Disable(void) -{ - __DMB(); +__STATIC_INLINE void ARM_MPU_Disable(void) { + __DMB(); #ifdef SCB_SHCSR_MEMFAULTENA_Msk - SCB->SHCSR &= ~SCB_SHCSR_MEMFAULTENA_Msk; + SCB->SHCSR &= ~SCB_SHCSR_MEMFAULTENA_Msk; #endif - MPU->CTRL &= ~MPU_CTRL_ENABLE_Msk; - __DSB(); - __ISB(); + MPU->CTRL &= ~MPU_CTRL_ENABLE_Msk; + __DSB(); + __ISB(); } #ifdef MPU_NS /** Enable the Non-secure MPU. * \param MPU_Control Default access permissions for unconfigured regions. */ -__STATIC_INLINE void ARM_MPU_Enable_NS(uint32_t MPU_Control) -{ - __DMB(); - MPU_NS->CTRL = MPU_Control | MPU_CTRL_ENABLE_Msk; +__STATIC_INLINE void ARM_MPU_Enable_NS(uint32_t MPU_Control) { + __DMB(); + MPU_NS->CTRL = MPU_Control | MPU_CTRL_ENABLE_Msk; #ifdef SCB_SHCSR_MEMFAULTENA_Msk - SCB_NS->SHCSR |= SCB_SHCSR_MEMFAULTENA_Msk; + SCB_NS->SHCSR |= SCB_SHCSR_MEMFAULTENA_Msk; #endif - __DSB(); - __ISB(); + __DSB(); + __ISB(); } /** Disable the Non-secure MPU. */ -__STATIC_INLINE void ARM_MPU_Disable_NS(void) -{ - __DMB(); +__STATIC_INLINE void ARM_MPU_Disable_NS(void) { + __DMB(); #ifdef SCB_SHCSR_MEMFAULTENA_Msk - SCB_NS->SHCSR &= ~SCB_SHCSR_MEMFAULTENA_Msk; + SCB_NS->SHCSR &= ~SCB_SHCSR_MEMFAULTENA_Msk; #endif - MPU_NS->CTRL &= ~MPU_CTRL_ENABLE_Msk; - __DSB(); - __ISB(); + MPU_NS->CTRL &= ~MPU_CTRL_ENABLE_Msk; + __DSB(); + __ISB(); } #endif @@ -185,26 +181,24 @@ __STATIC_INLINE void ARM_MPU_Disable_NS(void) * \param idx The attribute index to be set [0-7] * \param attr The attribute value to be set. */ -__STATIC_INLINE void ARM_MPU_SetMemAttrEx(MPU_Type* mpu, uint8_t idx, uint8_t attr) -{ - const uint8_t reg = idx / 4U; - const uint32_t pos = ((idx % 4U) * 8U); - const uint32_t mask = 0xFFU << pos; - - if (reg >= (sizeof(mpu->MAIR) / sizeof(mpu->MAIR[0]))) { - return; // invalid index - } - - mpu->MAIR[reg] = ((mpu->MAIR[reg] & ~mask) | ((attr << pos) & mask)); +__STATIC_INLINE void ARM_MPU_SetMemAttrEx(MPU_Type *mpu, uint8_t idx, uint8_t attr) { + const uint8_t reg = idx / 4U; + const uint32_t pos = ((idx % 4U) * 8U); + const uint32_t mask = 0xFFU << pos; + + if (reg >= (sizeof(mpu->MAIR) / sizeof(mpu->MAIR[0]))) { + return; // invalid index + } + + mpu->MAIR[reg] = ((mpu->MAIR[reg] & ~mask) | ((attr << pos) & mask)); } /** Set the memory attribute encoding. * \param idx The attribute index to be set [0-7] * \param attr The attribute value to be set. */ -__STATIC_INLINE void ARM_MPU_SetMemAttr(uint8_t idx, uint8_t attr) -{ - ARM_MPU_SetMemAttrEx(MPU, idx, attr); +__STATIC_INLINE void ARM_MPU_SetMemAttr(uint8_t idx, uint8_t attr) { + ARM_MPU_SetMemAttrEx(MPU, idx, attr); } #ifdef MPU_NS @@ -212,9 +206,8 @@ __STATIC_INLINE void ARM_MPU_SetMemAttr(uint8_t idx, uint8_t attr) * \param idx The attribute index to be set [0-7] * \param attr The attribute value to be set. */ -__STATIC_INLINE void ARM_MPU_SetMemAttr_NS(uint8_t idx, uint8_t attr) -{ - ARM_MPU_SetMemAttrEx(MPU_NS, idx, attr); +__STATIC_INLINE void ARM_MPU_SetMemAttr_NS(uint8_t idx, uint8_t attr) { + ARM_MPU_SetMemAttrEx(MPU_NS, idx, attr); } #endif @@ -222,27 +215,24 @@ __STATIC_INLINE void ARM_MPU_SetMemAttr_NS(uint8_t idx, uint8_t attr) * \param mpu Pointer to MPU to be used. * \param rnr Region number to be cleared. */ -__STATIC_INLINE void ARM_MPU_ClrRegionEx(MPU_Type* mpu, uint32_t rnr) -{ - mpu->RNR = rnr; - mpu->RLAR = 0U; +__STATIC_INLINE void ARM_MPU_ClrRegionEx(MPU_Type *mpu, uint32_t rnr) { + mpu->RNR = rnr; + mpu->RLAR = 0U; } /** Clear and disable the given MPU region. * \param rnr Region number to be cleared. */ -__STATIC_INLINE void ARM_MPU_ClrRegion(uint32_t rnr) -{ - ARM_MPU_ClrRegionEx(MPU, rnr); +__STATIC_INLINE void ARM_MPU_ClrRegion(uint32_t rnr) { + ARM_MPU_ClrRegionEx(MPU, rnr); } #ifdef MPU_NS /** Clear and disable the given Non-secure MPU region. * \param rnr Region number to be cleared. */ -__STATIC_INLINE void ARM_MPU_ClrRegion_NS(uint32_t rnr) -{ - ARM_MPU_ClrRegionEx(MPU_NS, rnr); +__STATIC_INLINE void ARM_MPU_ClrRegion_NS(uint32_t rnr) { + ARM_MPU_ClrRegionEx(MPU_NS, rnr); } #endif @@ -251,22 +241,20 @@ __STATIC_INLINE void ARM_MPU_ClrRegion_NS(uint32_t rnr) * \param rnr Region number to be configured. * \param rbar Value for RBAR register. * \param rlar Value for RLAR register. -*/ -__STATIC_INLINE void ARM_MPU_SetRegionEx(MPU_Type* mpu, uint32_t rnr, uint32_t rbar, uint32_t rlar) -{ - mpu->RNR = rnr; - mpu->RBAR = rbar; - mpu->RLAR = rlar; +*/ +__STATIC_INLINE void ARM_MPU_SetRegionEx(MPU_Type *mpu, uint32_t rnr, uint32_t rbar, uint32_t rlar) { + mpu->RNR = rnr; + mpu->RBAR = rbar; + mpu->RLAR = rlar; } /** Configure the given MPU region. * \param rnr Region number to be configured. * \param rbar Value for RBAR register. * \param rlar Value for RLAR register. -*/ -__STATIC_INLINE void ARM_MPU_SetRegion(uint32_t rnr, uint32_t rbar, uint32_t rlar) -{ - ARM_MPU_SetRegionEx(MPU, rnr, rbar, rlar); +*/ +__STATIC_INLINE void ARM_MPU_SetRegion(uint32_t rnr, uint32_t rbar, uint32_t rlar) { + ARM_MPU_SetRegionEx(MPU, rnr, rbar, rlar); } #ifdef MPU_NS @@ -274,10 +262,9 @@ __STATIC_INLINE void ARM_MPU_SetRegion(uint32_t rnr, uint32_t rbar, uint32_t rla * \param rnr Region number to be configured. * \param rbar Value for RBAR register. * \param rlar Value for RLAR register. -*/ -__STATIC_INLINE void ARM_MPU_SetRegion_NS(uint32_t rnr, uint32_t rbar, uint32_t rlar) -{ - ARM_MPU_SetRegionEx(MPU_NS, rnr, rbar, rlar); +*/ +__STATIC_INLINE void ARM_MPU_SetRegion_NS(uint32_t rnr, uint32_t rbar, uint32_t rlar) { + ARM_MPU_SetRegionEx(MPU_NS, rnr, rbar, rlar); } #endif @@ -286,13 +273,11 @@ __STATIC_INLINE void ARM_MPU_SetRegion_NS(uint32_t rnr, uint32_t rbar, uint32_t * \param src Source data is copied from. * \param len Amount of data words to be copied. */ -__STATIC_INLINE void ARM_MPU_OrderedMemcpy(volatile uint32_t* dst, const uint32_t* __RESTRICT src, uint32_t len) -{ - uint32_t i; - for (i = 0U; i < len; ++i) - { - dst[i] = src[i]; - } +__STATIC_INLINE void ARM_MPU_OrderedMemcpy(volatile uint32_t *dst, const uint32_t *__RESTRICT src, uint32_t len) { + uint32_t i; + for (i = 0U; i < len; ++i) { + dst[i] = src[i]; + } } /** Load the given number of MPU regions from a table to the given MPU. @@ -301,29 +286,28 @@ __STATIC_INLINE void ARM_MPU_OrderedMemcpy(volatile uint32_t* dst, const uint32_ * \param table Pointer to the MPU configuration table. * \param cnt Amount of regions to be configured. */ -__STATIC_INLINE void ARM_MPU_LoadEx(MPU_Type* mpu, uint32_t rnr, ARM_MPU_Region_t const* table, uint32_t cnt) -{ - const uint32_t rowWordSize = sizeof(ARM_MPU_Region_t)/4U; - if (cnt == 1U) { - mpu->RNR = rnr; - ARM_MPU_OrderedMemcpy(&(mpu->RBAR), &(table->RBAR), rowWordSize); - } else { - uint32_t rnrBase = rnr & ~(MPU_TYPE_RALIASES-1U); - uint32_t rnrOffset = rnr % MPU_TYPE_RALIASES; - - mpu->RNR = rnrBase; - while ((rnrOffset + cnt) > MPU_TYPE_RALIASES) { - uint32_t c = MPU_TYPE_RALIASES - rnrOffset; - ARM_MPU_OrderedMemcpy(&(mpu->RBAR)+(rnrOffset*2U), &(table->RBAR), c*rowWordSize); - table += c; - cnt -= c; - rnrOffset = 0U; - rnrBase += MPU_TYPE_RALIASES; - mpu->RNR = rnrBase; +__STATIC_INLINE void ARM_MPU_LoadEx(MPU_Type *mpu, uint32_t rnr, ARM_MPU_Region_t const *table, uint32_t cnt) { + const uint32_t rowWordSize = sizeof(ARM_MPU_Region_t) / 4U; + if (cnt == 1U) { + mpu->RNR = rnr; + ARM_MPU_OrderedMemcpy(&(mpu->RBAR), &(table->RBAR), rowWordSize); + } else { + uint32_t rnrBase = rnr & ~(MPU_TYPE_RALIASES - 1U); + uint32_t rnrOffset = rnr % MPU_TYPE_RALIASES; + + mpu->RNR = rnrBase; + while ((rnrOffset + cnt) > MPU_TYPE_RALIASES) { + uint32_t c = MPU_TYPE_RALIASES - rnrOffset; + ARM_MPU_OrderedMemcpy(&(mpu->RBAR) + (rnrOffset * 2U), &(table->RBAR), c * rowWordSize); + table += c; + cnt -= c; + rnrOffset = 0U; + rnrBase += MPU_TYPE_RALIASES; + mpu->RNR = rnrBase; + } + + ARM_MPU_OrderedMemcpy(&(mpu->RBAR) + (rnrOffset * 2U), &(table->RBAR), cnt * rowWordSize); } - - ARM_MPU_OrderedMemcpy(&(mpu->RBAR)+(rnrOffset*2U), &(table->RBAR), cnt*rowWordSize); - } } /** Load the given number of MPU regions from a table. @@ -331,9 +315,8 @@ __STATIC_INLINE void ARM_MPU_LoadEx(MPU_Type* mpu, uint32_t rnr, ARM_MPU_Region_ * \param table Pointer to the MPU configuration table. * \param cnt Amount of regions to be configured. */ -__STATIC_INLINE void ARM_MPU_Load(uint32_t rnr, ARM_MPU_Region_t const* table, uint32_t cnt) -{ - ARM_MPU_LoadEx(MPU, rnr, table, cnt); +__STATIC_INLINE void ARM_MPU_Load(uint32_t rnr, ARM_MPU_Region_t const *table, uint32_t cnt) { + ARM_MPU_LoadEx(MPU, rnr, table, cnt); } #ifdef MPU_NS @@ -342,9 +325,8 @@ __STATIC_INLINE void ARM_MPU_Load(uint32_t rnr, ARM_MPU_Region_t const* table, u * \param table Pointer to the MPU configuration table. * \param cnt Amount of regions to be configured. */ -__STATIC_INLINE void ARM_MPU_Load_NS(uint32_t rnr, ARM_MPU_Region_t const* table, uint32_t cnt) -{ - ARM_MPU_LoadEx(MPU_NS, rnr, table, cnt); +__STATIC_INLINE void ARM_MPU_Load_NS(uint32_t rnr, ARM_MPU_Region_t const *table, uint32_t cnt) { + ARM_MPU_LoadEx(MPU_NS, rnr, table, cnt); } #endif diff --git a/armlib/at32_sys/cmsis/cm4/core_support/pmu_armv8.h b/armlib/at32_sys/cmsis/cm4/core_support/pmu_armv8.h index 0db9b17ba..35881ef4d 100644 --- a/armlib/at32_sys/cmsis/cm4/core_support/pmu_armv8.h +++ b/armlib/at32_sys/cmsis/cm4/core_support/pmu_armv8.h @@ -23,9 +23,9 @@ */ #if defined ( __ICCARM__ ) - #pragma system_include /* treat file as system include file for MISRA check */ +#pragma system_include /* treat file as system include file for MISRA check */ #elif defined (__clang__) - #pragma clang system_header /* treat file as system include file */ +#pragma clang system_header /* treat file as system include file */ #endif #ifndef ARM_PMU_ARMV8_H @@ -192,146 +192,132 @@ __STATIC_INLINE void ARM_PMU_Set_CNTR_IRQ_Disable(uint32_t mask); __STATIC_INLINE void ARM_PMU_CNTR_Increment(uint32_t mask); -/** +/** \brief Enable the PMU */ -__STATIC_INLINE void ARM_PMU_Enable(void) -{ - PMU->CTRL |= PMU_CTRL_ENABLE_Msk; +__STATIC_INLINE void ARM_PMU_Enable(void) { + PMU->CTRL |= PMU_CTRL_ENABLE_Msk; } -/** +/** \brief Disable the PMU */ -__STATIC_INLINE void ARM_PMU_Disable(void) -{ - PMU->CTRL &= ~PMU_CTRL_ENABLE_Msk; +__STATIC_INLINE void ARM_PMU_Disable(void) { + PMU->CTRL &= ~PMU_CTRL_ENABLE_Msk; } -/** +/** \brief Set event to count for PMU eventer counter \param [in] num Event counter (0-30) to configure \param [in] type Event to count */ -__STATIC_INLINE void ARM_PMU_Set_EVTYPER(uint32_t num, uint32_t type) -{ - PMU->EVTYPER[num] = type; +__STATIC_INLINE void ARM_PMU_Set_EVTYPER(uint32_t num, uint32_t type) { + PMU->EVTYPER[num] = type; } -/** +/** \brief Reset cycle counter */ -__STATIC_INLINE void ARM_PMU_CYCCNT_Reset(void) -{ - PMU->CTRL |= PMU_CTRL_CYCCNT_RESET_Msk; +__STATIC_INLINE void ARM_PMU_CYCCNT_Reset(void) { + PMU->CTRL |= PMU_CTRL_CYCCNT_RESET_Msk; } -/** +/** \brief Reset all event counters */ -__STATIC_INLINE void ARM_PMU_EVCNTR_ALL_Reset(void) -{ - PMU->CTRL |= PMU_CTRL_EVENTCNT_RESET_Msk; +__STATIC_INLINE void ARM_PMU_EVCNTR_ALL_Reset(void) { + PMU->CTRL |= PMU_CTRL_EVENTCNT_RESET_Msk; } -/** - \brief Enable counters +/** + \brief Enable counters \param [in] mask Counters to enable \note Enables one or more of the following: - event counters (0-30) - cycle counter */ -__STATIC_INLINE void ARM_PMU_CNTR_Enable(uint32_t mask) -{ - PMU->CNTENSET = mask; +__STATIC_INLINE void ARM_PMU_CNTR_Enable(uint32_t mask) { + PMU->CNTENSET = mask; } -/** +/** \brief Disable counters \param [in] mask Counters to enable \note Disables one or more of the following: - event counters (0-30) - cycle counter */ -__STATIC_INLINE void ARM_PMU_CNTR_Disable(uint32_t mask) -{ - PMU->CNTENCLR = mask; +__STATIC_INLINE void ARM_PMU_CNTR_Disable(uint32_t mask) { + PMU->CNTENCLR = mask; } -/** +/** \brief Read cycle counter \return Cycle count */ -__STATIC_INLINE uint32_t ARM_PMU_Get_CCNTR(void) -{ - return PMU->CCNTR; +__STATIC_INLINE uint32_t ARM_PMU_Get_CCNTR(void) { + return PMU->CCNTR; } -/** +/** \brief Read event counter \param [in] num Event counter (0-30) to read \return Event count */ -__STATIC_INLINE uint32_t ARM_PMU_Get_EVCNTR(uint32_t num) -{ - return PMU_EVCNTR_CNT_Msk & PMU->EVCNTR[num]; +__STATIC_INLINE uint32_t ARM_PMU_Get_EVCNTR(uint32_t num) { + return PMU_EVCNTR_CNT_Msk & PMU->EVCNTR[num]; } -/** +/** \brief Read counter overflow status \return Counter overflow status bits for the following: - event counters (0-30) - cycle counter */ -__STATIC_INLINE uint32_t ARM_PMU_Get_CNTR_OVS(void) -{ - return PMU->OVSSET; +__STATIC_INLINE uint32_t ARM_PMU_Get_CNTR_OVS(void) { + return PMU->OVSSET; } -/** +/** \brief Clear counter overflow status \param [in] mask Counter overflow status bits to clear \note Clears overflow status bits for one or more of the following: - event counters (0-30) - cycle counter */ -__STATIC_INLINE void ARM_PMU_Set_CNTR_OVS(uint32_t mask) -{ - PMU->OVSCLR = mask; +__STATIC_INLINE void ARM_PMU_Set_CNTR_OVS(uint32_t mask) { + PMU->OVSCLR = mask; } -/** - \brief Enable counter overflow interrupt request +/** + \brief Enable counter overflow interrupt request \param [in] mask Counter overflow interrupt request bits to set \note Sets overflow interrupt request bits for one or more of the following: - event counters (0-30) - cycle counter */ -__STATIC_INLINE void ARM_PMU_Set_CNTR_IRQ_Enable(uint32_t mask) -{ - PMU->INTENSET = mask; +__STATIC_INLINE void ARM_PMU_Set_CNTR_IRQ_Enable(uint32_t mask) { + PMU->INTENSET = mask; } -/** - \brief Disable counter overflow interrupt request +/** + \brief Disable counter overflow interrupt request \param [in] mask Counter overflow interrupt request bits to clear \note Clears overflow interrupt request bits for one or more of the following: - event counters (0-30) - cycle counter */ -__STATIC_INLINE void ARM_PMU_Set_CNTR_IRQ_Disable(uint32_t mask) -{ - PMU->INTENCLR = mask; +__STATIC_INLINE void ARM_PMU_Set_CNTR_IRQ_Disable(uint32_t mask) { + PMU->INTENCLR = mask; } -/** - \brief Software increment event counter +/** + \brief Software increment event counter \param [in] mask Counters to increment \note Software increment bits for one or more event counters (0-30) */ -__STATIC_INLINE void ARM_PMU_CNTR_Increment(uint32_t mask) -{ - PMU->SWINC = mask; +__STATIC_INLINE void ARM_PMU_CNTR_Increment(uint32_t mask) { + PMU->SWINC = mask; } #endif diff --git a/armlib/at32_sys/cmsis/cm4/device_support/at32f435_437.h b/armlib/at32_sys/cmsis/cm4/device_support/at32f435_437.h index d04e5efb4..c6cf22e57 100644 --- a/armlib/at32_sys/cmsis/cm4/device_support/at32f435_437.h +++ b/armlib/at32_sys/cmsis/cm4/device_support/at32f435_437.h @@ -30,7 +30,7 @@ extern "C" { #endif #if defined (__CC_ARM) - #pragma anon_unions +#pragma anon_unions #endif @@ -63,7 +63,7 @@ extern "C" { !defined (AT32F435VDT7) && !defined (AT32F435ZDT7) && !defined (AT32F437RDT7) && \ !defined (AT32F437VDT7) && !defined (AT32F437ZDT7) - #error "Please select first the target device used in your application (in at32f435_437.h file)" +#error "Please select first the target device used in your application (in at32f435_437.h file)" #endif #if defined (AT32F435CCU7) || defined (AT32F435CGU7) || defined (AT32F435CMU7) || \ @@ -74,7 +74,7 @@ extern "C" { defined (AT32F435CDU7) || defined (AT32F435CDT7) || defined (AT32F435RDT7) || \ defined (AT32F435VDT7) || defined (AT32F435ZDT7) - #define AT32F435xx +#define AT32F435xx #endif #if defined (AT32F437RCT7) || defined (AT32F437RGT7) || defined (AT32F437RMT7) || \ @@ -82,7 +82,7 @@ extern "C" { defined (AT32F437ZCT7) || defined (AT32F437ZGT7) || defined (AT32F437ZMT7) || \ defined (AT32F437RDT7) || defined (AT32F437VDT7) || defined (AT32F437ZDT7) - #define AT32F437xx +#define AT32F437xx #endif /** @@ -91,44 +91,44 @@ extern "C" { #if defined (AT32F435ZCT7) || defined (AT32F435ZGT7) || defined (AT32F435ZMT7) || \ defined (AT32F435ZDT7) - #define AT32F435Zx +#define AT32F435Zx #endif #if defined (AT32F435VCT7) || defined (AT32F435VGT7) || defined (AT32F435VMT7) || \ defined (AT32F435VDT7) - #define AT32F435Vx +#define AT32F435Vx #endif #if defined (AT32F435RCT7) || defined (AT32F435RGT7) || defined (AT32F435RMT7) || \ defined (AT32F435RDT7) - #define AT32F435Rx +#define AT32F435Rx #endif #if defined (AT32F435CCU7) || defined (AT32F435CGU7) || defined (AT32F435CMU7) || \ defined (AT32F435CCT7) || defined (AT32F435CGT7) || defined (AT32F435CMT7) || \ defined (AT32F435CDU7) || defined (AT32F435CDT7) - #define AT32F435Cx +#define AT32F435Cx #endif #if defined (AT32F437ZCT7) || defined (AT32F437ZGT7) || defined (AT32F437ZMT7) || \ defined (AT32F437ZDT7) - #define AT32F437Zx +#define AT32F437Zx #endif #if defined (AT32F437VCT7) || defined (AT32F437VGT7) || defined (AT32F437VMT7) || \ defined (AT32F437VDT7) - #define AT32F437Vx +#define AT32F437Vx #endif #if defined (AT32F437RCT7) || defined (AT32F437RGT7) || defined (AT32F437RMT7) || \ defined (AT32F437RDT7) - #define AT32F437Rx +#define AT32F437Rx #endif /** @@ -137,45 +137,45 @@ extern "C" { #if defined (AT32F435CCU7) || defined (AT32F435CCT7) || defined (AT32F435RCT7) || \ defined (AT32F435VCT7) || defined (AT32F435ZCT7) - #define AT32F435xC +#define AT32F435xC #endif #if defined (AT32F435CDU7) || defined (AT32F435CDT7) || defined (AT32F435RDT7) || \ defined (AT32F435VDT7) || defined (AT32F435ZDT7) - #define AT32F435xD +#define AT32F435xD #endif #if defined (AT32F435CGU7) || defined (AT32F435CGT7) || defined (AT32F435RGT7) || \ defined (AT32F435VGT7) || defined (AT32F435ZGT7) - #define AT32F435xG +#define AT32F435xG #endif #if defined (AT32F435CMU7) || defined (AT32F435CMT7) || defined (AT32F435RMT7) || \ defined (AT32F435VMT7) || defined (AT32F435ZMT7) - #define AT32F435xM +#define AT32F435xM #endif #if defined (AT32F437RCT7) || defined (AT32F437VCT7) || defined (AT32F437ZCT7) - #define AT32F437xC +#define AT32F437xC #endif #if defined (AT32F437RDT7) || defined (AT32F437VDT7) || defined (AT32F437ZDT7) - #define AT32F437xD +#define AT32F437xD #endif #if defined (AT32F437RGT7) || defined (AT32F437VGT7) || defined (AT32F437ZGT7) - #define AT32F437xG +#define AT32F437xG #endif #if defined (AT32F437RMT7) || defined (AT32F437VMT7) || defined (AT32F437ZMT7) - #define AT32F437xM +#define AT32F437xM #endif #ifndef USE_STDPERIPH_DRIVER @@ -184,12 +184,12 @@ extern "C" { * in this case, these drivers will not be included and the application code will * be based on direct access to peripherals registers */ - #ifdef _RTE_ - #include "RTE_Components.h" - #ifdef RTE_DEVICE_STDPERIPH_FRAMEWORK - #define USE_STDPERIPH_DRIVER - #endif - #endif +#ifdef _RTE_ +#include "RTE_Components.h" +#ifdef RTE_DEVICE_STDPERIPH_FRAMEWORK +#define USE_STDPERIPH_DRIVER +#endif +#endif #endif /** @@ -225,8 +225,7 @@ extern "C" { * @brief at32f435_437 interrupt number definition, according to the selected device * in @ref library_configuration_section */ -typedef enum IRQn -{ +typedef enum IRQn { /****** cortex-m4 processor exceptions numbers ***************************************************/ Reset_IRQn = -15, /*!< 1 reset vector, invoked on power up and warm reset */ NonMaskableInt_IRQn = -14, /*!< 2 non maskable interrupt */ @@ -339,84 +338,84 @@ typedef enum IRQn #endif #if defined (AT32F437xx) - ADC1_2_3_IRQn = 18, /*!< adc1 adc2 and adc3 global interrupt */ - CAN1_TX_IRQn = 19, /*!< can1 tx interrupts */ - CAN1_RX0_IRQn = 20, /*!< can1 rx0 interrupts */ - CAN1_RX1_IRQn = 21, /*!< can1 rx1 interrupt */ - CAN1_SE_IRQn = 22, /*!< can1 se interrupt */ - EXINT9_5_IRQn = 23, /*!< external line[9:5] interrupts */ - TMR1_BRK_TMR9_IRQn = 24, /*!< tmr1 brake interrupt */ - TMR1_OVF_TMR10_IRQn = 25, /*!< tmr1 overflow interrupt */ - TMR1_TRG_HALL_TMR11_IRQn = 26, /*!< tmr1 trigger and hall interrupt */ - TMR1_CH_IRQn = 27, /*!< tmr1 channel interrupt */ - TMR2_GLOBAL_IRQn = 28, /*!< tmr2 global interrupt */ - TMR3_GLOBAL_IRQn = 29, /*!< tmr3 global interrupt */ - TMR4_GLOBAL_IRQn = 30, /*!< tmr4 global interrupt */ - I2C1_EVT_IRQn = 31, /*!< i2c1 event interrupt */ - I2C1_ERR_IRQn = 32, /*!< i2c1 error interrupt */ - I2C2_EVT_IRQn = 33, /*!< i2c2 event interrupt */ - I2C2_ERR_IRQn = 34, /*!< i2c2 error interrupt */ - SPI1_IRQn = 35, /*!< spi1 global interrupt */ - SPI2_I2S2EXT_IRQn = 36, /*!< spi2 global interrupt */ - USART1_IRQn = 37, /*!< usart1 global interrupt */ - USART2_IRQn = 38, /*!< usart2 global interrupt */ - USART3_IRQn = 39, /*!< usart3 global interrupt */ - EXINT15_10_IRQn = 40, /*!< external line[15:10] interrupts */ - ERTCAlarm_IRQn = 41, /*!< ertc alarm through exint line interrupt */ - OTGFS1_WKUP_IRQn = 42, /*!< otgfs1 wakeup from suspend through exint line interrupt */ - TMR8_BRK_TMR12_IRQn = 43, /*!< tmr8 brake interrupt */ - TMR8_OVF_TMR13_IRQn = 44, /*!< tmr8 overflow interrupt */ - TMR8_TRG_HALL_TMR14_IRQn = 45, /*!< tmr8 trigger and hall interrupt */ - TMR8_CH_IRQn = 46, /*!< tmr8 channel interrupt */ - EDMA_Stream8_IRQn = 47, /*!< dma1 stream 8 global interrupt */ - XMC_IRQn = 48, /*!< xmc global interrupt */ - SDIO1_IRQn = 49, /*!< sdio global interrupt */ - TMR5_GLOBAL_IRQn = 50, /*!< tmr5 global interrupt */ - SPI3_I2S3EXT_IRQn = 51, /*!< spi3 global interrupt */ - UART4_IRQn = 52, /*!< uart4 global interrupt */ - UART5_IRQn = 53, /*!< uart5 global interrupt */ - TMR6_DAC_GLOBAL_IRQn = 54, /*!< tmr6 and dac global interrupt */ - TMR7_GLOBAL_IRQn = 55, /*!< tmr7 global interrupt */ - DMA1_Channel1_IRQn = 56, /*!< dma1 channel 0 global interrupt */ - DMA1_Channel2_IRQn = 57, /*!< dma1 channel 1 global interrupt */ - DMA1_Channel3_IRQn = 58, /*!< dma1 channel 2 global interrupt */ - DMA1_Channel4_IRQn = 59, /*!< dma1 channel 3 global interrupt */ - DMA1_Channel5_IRQn = 60, /*!< dma1 channel 4 global interrupt */ - EMAC_IRQn = 61, /*!< emac interrupt */ - EMAC_WKUP_IRQn = 62, /*!< emac wakeup interrupt */ - CAN2_TX_IRQn = 63, /*!< can2 tx interrupt */ - CAN2_RX0_IRQn = 64, /*!< can2 rx0 interrupt */ - CAN2_RX1_IRQn = 65, /*!< can2 rx1 interrupt */ - CAN2_SE_IRQn = 66, /*!< can2 se interrupt */ - OTGFS1_IRQn = 67, /*!< otgfs1 interrupt */ - DMA1_Channel6_IRQn = 68, /*!< dma1 channel 5 global interrupt */ - DMA1_Channel7_IRQn = 69, /*!< dma1 channel 6 global interrupt */ - USART6_IRQn = 71, /*!< usart6 interrupt */ - I2C3_EVT_IRQn = 72, /*!< i2c3 event interrupt */ - I2C3_ERR_IRQn = 73, /*!< i2c3 error interrupt */ - OTGFS2_WKUP_IRQn = 76, /*!< otgfs2 wakeup from suspend through exint line interrupt */ - OTGFS2_IRQn = 77, /*!< otgfs2 interrupt */ - DVP_IRQn = 78, /*!< dvp interrupt */ - FPU_IRQn = 81, /*!< fpu interrupt */ - UART7_IRQn = 82, /*!< uart7 interrupt */ - UART8_IRQn = 83, /*!< uart8 interrupt */ - SPI4_IRQn = 84, /*!< spi4 global interrupt */ - QSPI2_IRQn = 91, /*!< qspi2 global interrupt */ - QSPI1_IRQn = 92, /*!< qspi1 global interrupt */ - DMAMUX_IRQn = 94, /*!< dmamux global interrupt */ - SDIO2_IRQn = 102, /*!< sdio2 global interrupt */ - ACC_IRQn = 103, /*!< acc interrupt */ - TMR20_BRK_IRQn = 104, /*!< tmr20 brake interrupt */ - TMR20_OVF_IRQn = 105, /*!< tmr20 overflow interrupt */ - TMR20_TRG_HALL_IRQn = 106, /*!< tmr20 trigger and hall interrupt */ - TMR20_CH_IRQn = 107, /*!< tmr20 channel interrupt */ - DMA2_Channel1_IRQn = 108, /*!< dma2 channel 1 global interrupt */ - DMA2_Channel2_IRQn = 109, /*!< dma2 channel 2 global interrupt */ - DMA2_Channel3_IRQn = 110, /*!< dma2 channel 3 global interrupt */ - DMA2_Channel4_IRQn = 111, /*!< dma2 channel 4 global interrupt */ - DMA2_Channel5_IRQn = 112, /*!< dma2 channel 5 global interrupt */ - DMA2_Channel6_IRQn = 113, /*!< dma2 channel 6 global interrupt */ - DMA2_Channel7_IRQn = 114 /*!< dma2 channel 7 global interrupt */ + ADC1_2_3_IRQn = 18, /*!< adc1 adc2 and adc3 global interrupt */ + CAN1_TX_IRQn = 19, /*!< can1 tx interrupts */ + CAN1_RX0_IRQn = 20, /*!< can1 rx0 interrupts */ + CAN1_RX1_IRQn = 21, /*!< can1 rx1 interrupt */ + CAN1_SE_IRQn = 22, /*!< can1 se interrupt */ + EXINT9_5_IRQn = 23, /*!< external line[9:5] interrupts */ + TMR1_BRK_TMR9_IRQn = 24, /*!< tmr1 brake interrupt */ + TMR1_OVF_TMR10_IRQn = 25, /*!< tmr1 overflow interrupt */ + TMR1_TRG_HALL_TMR11_IRQn = 26, /*!< tmr1 trigger and hall interrupt */ + TMR1_CH_IRQn = 27, /*!< tmr1 channel interrupt */ + TMR2_GLOBAL_IRQn = 28, /*!< tmr2 global interrupt */ + TMR3_GLOBAL_IRQn = 29, /*!< tmr3 global interrupt */ + TMR4_GLOBAL_IRQn = 30, /*!< tmr4 global interrupt */ + I2C1_EVT_IRQn = 31, /*!< i2c1 event interrupt */ + I2C1_ERR_IRQn = 32, /*!< i2c1 error interrupt */ + I2C2_EVT_IRQn = 33, /*!< i2c2 event interrupt */ + I2C2_ERR_IRQn = 34, /*!< i2c2 error interrupt */ + SPI1_IRQn = 35, /*!< spi1 global interrupt */ + SPI2_I2S2EXT_IRQn = 36, /*!< spi2 global interrupt */ + USART1_IRQn = 37, /*!< usart1 global interrupt */ + USART2_IRQn = 38, /*!< usart2 global interrupt */ + USART3_IRQn = 39, /*!< usart3 global interrupt */ + EXINT15_10_IRQn = 40, /*!< external line[15:10] interrupts */ + ERTCAlarm_IRQn = 41, /*!< ertc alarm through exint line interrupt */ + OTGFS1_WKUP_IRQn = 42, /*!< otgfs1 wakeup from suspend through exint line interrupt */ + TMR8_BRK_TMR12_IRQn = 43, /*!< tmr8 brake interrupt */ + TMR8_OVF_TMR13_IRQn = 44, /*!< tmr8 overflow interrupt */ + TMR8_TRG_HALL_TMR14_IRQn = 45, /*!< tmr8 trigger and hall interrupt */ + TMR8_CH_IRQn = 46, /*!< tmr8 channel interrupt */ + EDMA_Stream8_IRQn = 47, /*!< dma1 stream 8 global interrupt */ + XMC_IRQn = 48, /*!< xmc global interrupt */ + SDIO1_IRQn = 49, /*!< sdio global interrupt */ + TMR5_GLOBAL_IRQn = 50, /*!< tmr5 global interrupt */ + SPI3_I2S3EXT_IRQn = 51, /*!< spi3 global interrupt */ + UART4_IRQn = 52, /*!< uart4 global interrupt */ + UART5_IRQn = 53, /*!< uart5 global interrupt */ + TMR6_DAC_GLOBAL_IRQn = 54, /*!< tmr6 and dac global interrupt */ + TMR7_GLOBAL_IRQn = 55, /*!< tmr7 global interrupt */ + DMA1_Channel1_IRQn = 56, /*!< dma1 channel 0 global interrupt */ + DMA1_Channel2_IRQn = 57, /*!< dma1 channel 1 global interrupt */ + DMA1_Channel3_IRQn = 58, /*!< dma1 channel 2 global interrupt */ + DMA1_Channel4_IRQn = 59, /*!< dma1 channel 3 global interrupt */ + DMA1_Channel5_IRQn = 60, /*!< dma1 channel 4 global interrupt */ + EMAC_IRQn = 61, /*!< emac interrupt */ + EMAC_WKUP_IRQn = 62, /*!< emac wakeup interrupt */ + CAN2_TX_IRQn = 63, /*!< can2 tx interrupt */ + CAN2_RX0_IRQn = 64, /*!< can2 rx0 interrupt */ + CAN2_RX1_IRQn = 65, /*!< can2 rx1 interrupt */ + CAN2_SE_IRQn = 66, /*!< can2 se interrupt */ + OTGFS1_IRQn = 67, /*!< otgfs1 interrupt */ + DMA1_Channel6_IRQn = 68, /*!< dma1 channel 5 global interrupt */ + DMA1_Channel7_IRQn = 69, /*!< dma1 channel 6 global interrupt */ + USART6_IRQn = 71, /*!< usart6 interrupt */ + I2C3_EVT_IRQn = 72, /*!< i2c3 event interrupt */ + I2C3_ERR_IRQn = 73, /*!< i2c3 error interrupt */ + OTGFS2_WKUP_IRQn = 76, /*!< otgfs2 wakeup from suspend through exint line interrupt */ + OTGFS2_IRQn = 77, /*!< otgfs2 interrupt */ + DVP_IRQn = 78, /*!< dvp interrupt */ + FPU_IRQn = 81, /*!< fpu interrupt */ + UART7_IRQn = 82, /*!< uart7 interrupt */ + UART8_IRQn = 83, /*!< uart8 interrupt */ + SPI4_IRQn = 84, /*!< spi4 global interrupt */ + QSPI2_IRQn = 91, /*!< qspi2 global interrupt */ + QSPI1_IRQn = 92, /*!< qspi1 global interrupt */ + DMAMUX_IRQn = 94, /*!< dmamux global interrupt */ + SDIO2_IRQn = 102, /*!< sdio2 global interrupt */ + ACC_IRQn = 103, /*!< acc interrupt */ + TMR20_BRK_IRQn = 104, /*!< tmr20 brake interrupt */ + TMR20_OVF_IRQn = 105, /*!< tmr20 overflow interrupt */ + TMR20_TRG_HALL_IRQn = 106, /*!< tmr20 trigger and hall interrupt */ + TMR20_CH_IRQn = 107, /*!< tmr20 channel interrupt */ + DMA2_Channel1_IRQn = 108, /*!< dma2 channel 1 global interrupt */ + DMA2_Channel2_IRQn = 109, /*!< dma2 channel 2 global interrupt */ + DMA2_Channel3_IRQn = 110, /*!< dma2 channel 3 global interrupt */ + DMA2_Channel4_IRQn = 111, /*!< dma2 channel 4 global interrupt */ + DMA2_Channel5_IRQn = 112, /*!< dma2 channel 5 global interrupt */ + DMA2_Channel6_IRQn = 113, /*!< dma2 channel 6 global interrupt */ + DMA2_Channel7_IRQn = 114 /*!< dma2 channel 7 global interrupt */ #endif } IRQn_Type; diff --git a/armlib/at32_sys/cmsis/cm4/device_support/system_at32f435_437.c b/armlib/at32_sys/cmsis/cm4/device_support/system_at32f435_437.c index e1927db4c..af7c28c2d 100644 --- a/armlib/at32_sys/cmsis/cm4/device_support/system_at32f435_437.c +++ b/armlib/at32_sys/cmsis/cm4/device_support/system_at32f435_437.c @@ -60,49 +60,48 @@ unsigned int system_core_clock = HICK_VALUE; /*!< system clock frequen * @param none * @retval none */ -void SystemInit (void) -{ +void SystemInit(void) { #if defined (__FPU_USED) && (__FPU_USED == 1U) - SCB->CPACR |= ((3U << 10U * 2U) | /* set cp10 full access */ - (3U << 11U * 2U) ); /* set cp11 full access */ + SCB->CPACR |= ((3U << 10U * 2U) | /* set cp10 full access */ + (3U << 11U * 2U)); /* set cp11 full access */ #endif - /* reset the crm clock configuration to the default reset state(for debug purpose) */ - /* set hicken bit */ - CRM->ctrl_bit.hicken = TRUE; + /* reset the crm clock configuration to the default reset state(for debug purpose) */ + /* set hicken bit */ + CRM->ctrl_bit.hicken = TRUE; - /* wait hick stable */ - while(CRM->ctrl_bit.hickstbl != SET); + /* wait hick stable */ + while (CRM->ctrl_bit.hickstbl != SET); - /* hick used as system clock */ - CRM->cfg_bit.sclksel = CRM_SCLK_HICK; + /* hick used as system clock */ + CRM->cfg_bit.sclksel = CRM_SCLK_HICK; - /* wait sclk switch status */ - while(CRM->cfg_bit.sclksts != CRM_SCLK_HICK); + /* wait sclk switch status */ + while (CRM->cfg_bit.sclksts != CRM_SCLK_HICK); - /* reset hexten, hextbyps, cfden and pllen bits */ - CRM->ctrl &= ~(0x010D0000U); + /* reset hexten, hextbyps, cfden and pllen bits */ + CRM->ctrl &= ~(0x010D0000U); - /* reset cfg register, include sclk switch, ahbdiv, apb1div, apb2div, adcdiv, clkout bits */ - CRM->cfg = 0; + /* reset cfg register, include sclk switch, ahbdiv, apb1div, apb2div, adcdiv, clkout bits */ + CRM->cfg = 0; - /* reset pllms pllns pllfr pllrcs bits */ - CRM->pllcfg = 0x00033002U; + /* reset pllms pllns pllfr pllrcs bits */ + CRM->pllcfg = 0x00033002U; - /* reset clkout[3], usbbufs, hickdiv, clkoutdiv */ - CRM->misc1 = 0; + /* reset clkout[3], usbbufs, hickdiv, clkoutdiv */ + CRM->misc1 = 0; - /* disable all interrupts enable and clear pending bits */ - CRM->clkint = 0x009F0000U; + /* disable all interrupts enable and clear pending bits */ + CRM->clkint = 0x009F0000U; - /* - * TODO DXL 这里重新设置了中断向量表,有问题 -#ifdef VECT_TAB_SRAM - SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; // vector table relocation in internal sram. -#else - SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; // vector table relocation in internal flash. -#endif - */ + /* + * TODO DXL 这里重新设置了中断向量表,有问题 + #ifdef VECT_TAB_SRAM + SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; // vector table relocation in internal sram. + #else + SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; // vector table relocation in internal flash. + #endif + */ } /** @@ -113,72 +112,67 @@ void SystemInit (void) * @param none * @retval none */ -void system_core_clock_update(void) -{ - uint32_t pll_ns = 0, pll_ms = 0, pll_fr = 0, pll_clock_source = 0, pllrcsfreq = 0; - uint32_t temp = 0, div_value = 0; - crm_sclk_type sclk_source; +void system_core_clock_update(void) { + uint32_t pll_ns = 0, pll_ms = 0, pll_fr = 0, pll_clock_source = 0, pllrcsfreq = 0; + uint32_t temp = 0, div_value = 0; + crm_sclk_type sclk_source; - static const uint8_t sys_ahb_div_table[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9}; - static const uint8_t pll_fr_table[6] = {1, 2, 4, 8, 16, 32}; + static const uint8_t sys_ahb_div_table[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9}; + static const uint8_t pll_fr_table[6] = {1, 2, 4, 8, 16, 32}; - /* get sclk source */ - sclk_source = crm_sysclk_switch_status_get(); + /* get sclk source */ + sclk_source = crm_sysclk_switch_status_get(); - switch(sclk_source) - { - case CRM_SCLK_HICK: - if(((CRM->misc1_bit.hick_to_sclk) != RESET) && ((CRM->misc1_bit.hickdiv) != RESET)) - system_core_clock = HICK_VALUE * 6; - else - system_core_clock = HICK_VALUE; - break; - case CRM_SCLK_HEXT: - system_core_clock = HEXT_VALUE; - break; - case CRM_SCLK_PLL: - /* get pll clock source */ - pll_clock_source = CRM->pllcfg_bit.pllrcs; + switch (sclk_source) { + case CRM_SCLK_HICK: + if (((CRM->misc1_bit.hick_to_sclk) != RESET) && ((CRM->misc1_bit.hickdiv) != RESET)) + system_core_clock = HICK_VALUE * 6; + else + system_core_clock = HICK_VALUE; + break; + case CRM_SCLK_HEXT: + system_core_clock = HEXT_VALUE; + break; + case CRM_SCLK_PLL: + /* get pll clock source */ + pll_clock_source = CRM->pllcfg_bit.pllrcs; - /* get multiplication factor */ - pll_ns = CRM->pllcfg_bit.pllns; - pll_ms = CRM->pllcfg_bit.pllms; - pll_fr = pll_fr_table[CRM->pllcfg_bit.pllfr]; + /* get multiplication factor */ + pll_ns = CRM->pllcfg_bit.pllns; + pll_ms = CRM->pllcfg_bit.pllms; + pll_fr = pll_fr_table[CRM->pllcfg_bit.pllfr]; - if (pll_clock_source == CRM_PLL_SOURCE_HICK) - { - /* hick selected as pll clock entry */ - pllrcsfreq = HICK_VALUE; - } - else - { - /* hext selected as pll clock entry */ - pllrcsfreq = HEXT_VALUE; - } + if (pll_clock_source == CRM_PLL_SOURCE_HICK) { + /* hick selected as pll clock entry */ + pllrcsfreq = HICK_VALUE; + } else { + /* hext selected as pll clock entry */ + pllrcsfreq = HEXT_VALUE; + } - // TODO DXL For fix error: undefined reference to `__aeabi_uldivmod' - // 1. After code review, I found that pll_ns generally does not exceed 144, that is, it can be treated as u32. - // However, for the robustness of firmware, we still need to make error judgments. - if (pllrcsfreq * pll_ns > UINT32_MAX) { - while (1) { - __NOP(); // !!! Fix me !!! - } - } - system_core_clock = pllrcsfreq * pll_ns / (pll_ms * pll_fr); - // 2. If u64 division is necessary, it is better to link to gcc(-lgcc), but the firmware size will increase. - // system_core_clock = (uint32_t)(((uint64_t)pllrcsfreq * pll_ns) / (pll_ms * pll_fr)); - break; - default: - system_core_clock = HICK_VALUE; - break; - } + // TODO DXL For fix error: undefined reference to `__aeabi_uldivmod' + // 1. After code review, I found that pll_ns generally does not exceed 144, that is, it can be treated as u32. + // However, for the robustness of firmware, we still need to make error judgments. + if (pllrcsfreq * pll_ns > UINT32_MAX) { + while (1) { + __NOP(); // !!! Fix me !!! + } + } + system_core_clock = pllrcsfreq * pll_ns / (pll_ms * pll_fr); + // 2. If u64 division is necessary, it is better to link to gcc(-lgcc), but the firmware size will increase. + // system_core_clock = (uint32_t)(((uint64_t)pllrcsfreq * pll_ns) / (pll_ms * pll_fr)); + break; + default: + system_core_clock = HICK_VALUE; + break; + } - /* compute sclk, ahbclk frequency */ - /* get ahb division */ - temp = CRM->cfg_bit.ahbdiv; - div_value = sys_ahb_div_table[temp]; - /* ahbclk frequency */ - system_core_clock = system_core_clock >> div_value; + /* compute sclk, ahbclk frequency */ + /* get ahb division */ + temp = CRM->cfg_bit.ahbdiv; + div_value = sys_ahb_div_table[temp]; + /* ahbclk frequency */ + system_core_clock = system_core_clock >> div_value; } /** * @} diff --git a/armlib/at32_sys/drivers/inc/at32f435_437_acc.h b/armlib/at32_sys/drivers/inc/at32f435_437_acc.h index 91c0d91c5..3ff6a3c5f 100644 --- a/armlib/at32_sys/drivers/inc/at32f435_437_acc.h +++ b/armlib/at32_sys/drivers/inc/at32f435_437_acc.h @@ -69,94 +69,81 @@ extern "C" { /** * @brief type define acc register all */ -typedef struct -{ +typedef struct { - /** - * @brief acc sts register, offset:0x00 + /** + * @brief acc sts register, offset:0x00 + */ + union { + __IO uint32_t sts; + struct { + __IO uint32_t calrdy : 1; /* [0] */ + __IO uint32_t rslost : 1; /* [1] */ + __IO uint32_t reserved1 : 30;/* [31:2] */ + } sts_bit; + }; + + /** + * @brief acc ctrl1 register, offset:0x04 + */ + union { + __IO uint32_t ctrl1; + struct { + __IO uint32_t calon : 1; /* [0] */ + __IO uint32_t entrim : 1; /* [1] */ + __IO uint32_t reserved1 : 2; /* [3:2] */ + __IO uint32_t eien : 1; /* [4] */ + __IO uint32_t calrdyien : 1; /* [5] */ + __IO uint32_t reserved2 : 2; /* [7:6] */ + __IO uint32_t step : 4; /* [11:8] */ + __IO uint32_t reserved3 : 20;/* [31:12] */ + } ctrl1_bit; + }; + + /** + * @brief acc ctrl2 register, offset:0x08 + */ + union { + __IO uint32_t ctrl2; + struct { + __IO uint32_t hickcal : 8; /* [7:0] */ + __IO uint32_t hicktrim : 6; /* [13:8] */ + __IO uint32_t reserved1 : 18;/* [31:14] */ + } ctrl2_bit; + }; + + /** + * @brief acc acc_c1 register, offset:0x0C */ - union - { - __IO uint32_t sts; - struct - { - __IO uint32_t calrdy : 1; /* [0] */ - __IO uint32_t rslost : 1; /* [1] */ - __IO uint32_t reserved1 : 30;/* [31:2] */ - } sts_bit; - }; + union { + __IO uint32_t c1; + struct { + __IO uint32_t c1 : 16;/* [15:0] */ + __IO uint32_t reserved1 : 16;/* [31:16] */ + } c1_bit; + }; - /** - * @brief acc ctrl1 register, offset:0x04 + /** + * @brief acc acc_c2 register, offset:0x10 */ - union - { - __IO uint32_t ctrl1; - struct - { - __IO uint32_t calon : 1; /* [0] */ - __IO uint32_t entrim : 1; /* [1] */ - __IO uint32_t reserved1 : 2; /* [3:2] */ - __IO uint32_t eien : 1; /* [4] */ - __IO uint32_t calrdyien : 1; /* [5] */ - __IO uint32_t reserved2 : 2; /* [7:6] */ - __IO uint32_t step : 4; /* [11:8] */ - __IO uint32_t reserved3 : 20;/* [31:12] */ - } ctrl1_bit; - }; + union { + __IO uint32_t c2; + struct { + __IO uint32_t c2 : 16;/* [15:0] */ + __IO uint32_t reserved1 : 16;/* [31:16] */ + } c2_bit; + }; - /** - * @brief acc ctrl2 register, offset:0x08 + /** + * @brief acc acc_c3 register, offset:0x14 */ - union - { - __IO uint32_t ctrl2; - struct - { - __IO uint32_t hickcal : 8; /* [7:0] */ - __IO uint32_t hicktrim : 6; /* [13:8] */ - __IO uint32_t reserved1 : 18;/* [31:14] */ - } ctrl2_bit; - }; - - /** - * @brief acc acc_c1 register, offset:0x0C - */ - union - { - __IO uint32_t c1; - struct - { - __IO uint32_t c1 : 16;/* [15:0] */ - __IO uint32_t reserved1 : 16;/* [31:16] */ - } c1_bit; - }; - - /** - * @brief acc acc_c2 register, offset:0x10 - */ - union - { - __IO uint32_t c2; - struct - { - __IO uint32_t c2 : 16;/* [15:0] */ - __IO uint32_t reserved1 : 16;/* [31:16] */ - } c2_bit; - }; - - /** - * @brief acc acc_c3 register, offset:0x14 - */ - union - { - __IO uint32_t c3; - struct - { - __IO uint32_t c3 : 16;/* [15:0] */ - __IO uint32_t reserved1 : 16;/* [31:16] */ - } c3_bit; - }; + union { + __IO uint32_t c3; + struct { + __IO uint32_t c3 : 16;/* [15:0] */ + __IO uint32_t reserved1 : 16;/* [31:16] */ + } c3_bit; + }; } acc_type; /** diff --git a/armlib/at32_sys/drivers/inc/at32f435_437_adc.h b/armlib/at32_sys/drivers/inc/at32f435_437_adc.h index 4d72dd95e..439516738 100644 --- a/armlib/at32_sys/drivers/inc/at32f435_437_adc.h +++ b/armlib/at32_sys/drivers/inc/at32f435_437_adc.h @@ -81,780 +81,709 @@ extern "C" { /** * @brief adc division type */ -typedef enum -{ - ADC_HCLK_DIV_2 = 0x00, /*!< adcclk is hclk/2 */ - ADC_HCLK_DIV_3 = 0x01, /*!< adcclk is hclk/3 */ - ADC_HCLK_DIV_4 = 0x02, /*!< adcclk is hclk/4 */ - ADC_HCLK_DIV_5 = 0x03, /*!< adcclk is hclk/5 */ - ADC_HCLK_DIV_6 = 0x04, /*!< adcclk is hclk/6 */ - ADC_HCLK_DIV_7 = 0x05, /*!< adcclk is hclk/7 */ - ADC_HCLK_DIV_8 = 0x06, /*!< adcclk is hclk/8 */ - ADC_HCLK_DIV_9 = 0x07, /*!< adcclk is hclk/9 */ - ADC_HCLK_DIV_10 = 0x08, /*!< adcclk is hclk/10 */ - ADC_HCLK_DIV_11 = 0x09, /*!< adcclk is hclk/11 */ - ADC_HCLK_DIV_12 = 0x0A, /*!< adcclk is hclk/12 */ - ADC_HCLK_DIV_13 = 0x0B, /*!< adcclk is hclk/13 */ - ADC_HCLK_DIV_14 = 0x0C, /*!< adcclk is hclk/14 */ - ADC_HCLK_DIV_15 = 0x0D, /*!< adcclk is hclk/15 */ - ADC_HCLK_DIV_16 = 0x0E, /*!< adcclk is hclk/16 */ - ADC_HCLK_DIV_17 = 0x0F /*!< adcclk is hclk/17 */ +typedef enum { + ADC_HCLK_DIV_2 = 0x00, /*!< adcclk is hclk/2 */ + ADC_HCLK_DIV_3 = 0x01, /*!< adcclk is hclk/3 */ + ADC_HCLK_DIV_4 = 0x02, /*!< adcclk is hclk/4 */ + ADC_HCLK_DIV_5 = 0x03, /*!< adcclk is hclk/5 */ + ADC_HCLK_DIV_6 = 0x04, /*!< adcclk is hclk/6 */ + ADC_HCLK_DIV_7 = 0x05, /*!< adcclk is hclk/7 */ + ADC_HCLK_DIV_8 = 0x06, /*!< adcclk is hclk/8 */ + ADC_HCLK_DIV_9 = 0x07, /*!< adcclk is hclk/9 */ + ADC_HCLK_DIV_10 = 0x08, /*!< adcclk is hclk/10 */ + ADC_HCLK_DIV_11 = 0x09, /*!< adcclk is hclk/11 */ + ADC_HCLK_DIV_12 = 0x0A, /*!< adcclk is hclk/12 */ + ADC_HCLK_DIV_13 = 0x0B, /*!< adcclk is hclk/13 */ + ADC_HCLK_DIV_14 = 0x0C, /*!< adcclk is hclk/14 */ + ADC_HCLK_DIV_15 = 0x0D, /*!< adcclk is hclk/15 */ + ADC_HCLK_DIV_16 = 0x0E, /*!< adcclk is hclk/16 */ + ADC_HCLK_DIV_17 = 0x0F /*!< adcclk is hclk/17 */ } adc_div_type; /** * @brief adc combine mode type */ -typedef enum -{ - ADC_INDEPENDENT_MODE = 0x00, /*!< independent mode */ - ADC_ORDINARY_SMLT_PREEMPT_SMLT_ONESLAVE_MODE = 0x01, /*!< single slaver combined ordinary simultaneous + preempt simultaneous mode */ - ADC_ORDINARY_SMLT_PREEMPT_INTERLTRIG_ONESLAVE_MODE = 0x02, /*!< single slaver combined ordinary simultaneous + preempt interleaved trigger mode */ - ADC_PREEMPT_SMLT_ONLY_ONESLAVE_MODE = 0x05, /*!< single slaver preempt simultaneous mode only */ - ADC_ORDINARY_SMLT_ONLY_ONESLAVE_MODE = 0x06, /*!< single slaver ordinary simultaneous mode only */ - ADC_ORDINARY_SHIFT_ONLY_ONESLAVE_MODE = 0x07, /*!< single slaver ordinary shifting mode only */ - ADC_PREEMPT_INTERLTRIG_ONLY_ONESLAVE_MODE = 0x09, /*!< single slaver preempt interleaved trigger mode only */ - ADC_ORDINARY_SMLT_PREEMPT_SMLT_TWOSLAVE_MODE = 0x11, /*!< double slaver combined ordinary simultaneous + preempt simultaneous mode */ - ADC_ORDINARY_SMLT_PREEMPT_INTERLTRIG_TWOSLAVE_MODE = 0x12, /*!< double slaver combined ordinary simultaneous + preempt interleaved trigger mode */ - ADC_PREEMPT_SMLT_ONLY_TWOSLAVE_MODE = 0x15, /*!< double slaver preempt simultaneous mode only */ - ADC_ORDINARY_SMLT_ONLY_TWOSLAVE_MODE = 0x16, /*!< double slaver ordinary simultaneous mode only */ - ADC_ORDINARY_SHIFT_ONLY_TWOSLAVE_MODE = 0x17, /*!< double slaver ordinary shifting mode only */ - ADC_PREEMPT_INTERLTRIG_ONLY_TWOSLAVE_MODE = 0x19 /*!< double slaver preempt interleaved trigger mode only */ +typedef enum { + ADC_INDEPENDENT_MODE = 0x00, /*!< independent mode */ + ADC_ORDINARY_SMLT_PREEMPT_SMLT_ONESLAVE_MODE = 0x01, /*!< single slaver combined ordinary simultaneous + preempt simultaneous mode */ + ADC_ORDINARY_SMLT_PREEMPT_INTERLTRIG_ONESLAVE_MODE = 0x02, /*!< single slaver combined ordinary simultaneous + preempt interleaved trigger mode */ + ADC_PREEMPT_SMLT_ONLY_ONESLAVE_MODE = 0x05, /*!< single slaver preempt simultaneous mode only */ + ADC_ORDINARY_SMLT_ONLY_ONESLAVE_MODE = 0x06, /*!< single slaver ordinary simultaneous mode only */ + ADC_ORDINARY_SHIFT_ONLY_ONESLAVE_MODE = 0x07, /*!< single slaver ordinary shifting mode only */ + ADC_PREEMPT_INTERLTRIG_ONLY_ONESLAVE_MODE = 0x09, /*!< single slaver preempt interleaved trigger mode only */ + ADC_ORDINARY_SMLT_PREEMPT_SMLT_TWOSLAVE_MODE = 0x11, /*!< double slaver combined ordinary simultaneous + preempt simultaneous mode */ + ADC_ORDINARY_SMLT_PREEMPT_INTERLTRIG_TWOSLAVE_MODE = 0x12, /*!< double slaver combined ordinary simultaneous + preempt interleaved trigger mode */ + ADC_PREEMPT_SMLT_ONLY_TWOSLAVE_MODE = 0x15, /*!< double slaver preempt simultaneous mode only */ + ADC_ORDINARY_SMLT_ONLY_TWOSLAVE_MODE = 0x16, /*!< double slaver ordinary simultaneous mode only */ + ADC_ORDINARY_SHIFT_ONLY_TWOSLAVE_MODE = 0x17, /*!< double slaver ordinary shifting mode only */ + ADC_PREEMPT_INTERLTRIG_ONLY_TWOSLAVE_MODE = 0x19 /*!< double slaver preempt interleaved trigger mode only */ } adc_combine_mode_type; /** * @brief adc common dma mode type */ -typedef enum -{ - ADC_COMMON_DMAMODE_DISABLE = 0x00, /*!< dma mode disabled */ - ADC_COMMON_DMAMODE_1 = 0x01, /*!< dma mode1: each dma request trans a half-word data(reference manual account the rule of data package) */ - ADC_COMMON_DMAMODE_2 = 0x02, /*!< dma mode2: each dma request trans two half-word data(reference manual account the rule of data package) */ - ADC_COMMON_DMAMODE_3 = 0x03, /*!< dma mode3: each dma request trans two bytes data(reference manual account the rule of data package) */ - ADC_COMMON_DMAMODE_4 = 0x04, /*!< dma mode4: each dma request trans three bytes data(reference manual account the rule of data package) */ - ADC_COMMON_DMAMODE_5 = 0x05 /*!< dma mode5: odd dma request trans two half-word data,even dma request trans a half-word data(reference manual account the rule of data package) */ +typedef enum { + ADC_COMMON_DMAMODE_DISABLE = 0x00, /*!< dma mode disabled */ + ADC_COMMON_DMAMODE_1 = 0x01, /*!< dma mode1: each dma request trans a half-word data(reference manual account the rule of data package) */ + ADC_COMMON_DMAMODE_2 = 0x02, /*!< dma mode2: each dma request trans two half-word data(reference manual account the rule of data package) */ + ADC_COMMON_DMAMODE_3 = 0x03, /*!< dma mode3: each dma request trans two bytes data(reference manual account the rule of data package) */ + ADC_COMMON_DMAMODE_4 = 0x04, /*!< dma mode4: each dma request trans three bytes data(reference manual account the rule of data package) */ + ADC_COMMON_DMAMODE_5 = 0x05 /*!< dma mode5: odd dma request trans two half-word data,even dma request trans a half-word data(reference manual account the rule of data package) */ } adc_common_dma_mode_type; /** * @brief adc common sampling interval type */ -typedef enum -{ - ADC_SAMPLING_INTERVAL_5CYCLES = 0x00, /*!< ordinary shifting mode adjacent adc sampling interval 5 adcclk */ - ADC_SAMPLING_INTERVAL_6CYCLES = 0x01, /*!< ordinary shifting mode adjacent adc sampling interval 6 adcclk */ - ADC_SAMPLING_INTERVAL_7CYCLES = 0x02, /*!< ordinary shifting mode adjacent adc sampling interval 7 adcclk */ - ADC_SAMPLING_INTERVAL_8CYCLES = 0x03, /*!< ordinary shifting mode adjacent adc sampling interval 8 adcclk */ - ADC_SAMPLING_INTERVAL_9CYCLES = 0x04, /*!< ordinary shifting mode adjacent adc sampling interval 9 adcclk */ - ADC_SAMPLING_INTERVAL_10CYCLES = 0x05, /*!< ordinary shifting mode adjacent adc sampling interval 10 adcclk */ - ADC_SAMPLING_INTERVAL_11CYCLES = 0x06, /*!< ordinary shifting mode adjacent adc sampling interval 11 adcclk */ - ADC_SAMPLING_INTERVAL_12CYCLES = 0x07, /*!< ordinary shifting mode adjacent adc sampling interval 12 adcclk */ - ADC_SAMPLING_INTERVAL_13CYCLES = 0x08, /*!< ordinary shifting mode adjacent adc sampling interval 13 adcclk */ - ADC_SAMPLING_INTERVAL_14CYCLES = 0x09, /*!< ordinary shifting mode adjacent adc sampling interval 14 adcclk */ - ADC_SAMPLING_INTERVAL_15CYCLES = 0x0A, /*!< ordinary shifting mode adjacent adc sampling interval 15 adcclk */ - ADC_SAMPLING_INTERVAL_16CYCLES = 0x0B, /*!< ordinary shifting mode adjacent adc sampling interval 16 adcclk */ - ADC_SAMPLING_INTERVAL_17CYCLES = 0x0C, /*!< ordinary shifting mode adjacent adc sampling interval 17 adcclk */ - ADC_SAMPLING_INTERVAL_18CYCLES = 0x0D, /*!< ordinary shifting mode adjacent adc sampling interval 18 adcclk */ - ADC_SAMPLING_INTERVAL_19CYCLES = 0x0E, /*!< ordinary shifting mode adjacent adc sampling interval 19 adcclk */ - ADC_SAMPLING_INTERVAL_20CYCLES = 0x0F /*!< ordinary shifting mode adjacent adc sampling interval 20 adcclk */ +typedef enum { + ADC_SAMPLING_INTERVAL_5CYCLES = 0x00, /*!< ordinary shifting mode adjacent adc sampling interval 5 adcclk */ + ADC_SAMPLING_INTERVAL_6CYCLES = 0x01, /*!< ordinary shifting mode adjacent adc sampling interval 6 adcclk */ + ADC_SAMPLING_INTERVAL_7CYCLES = 0x02, /*!< ordinary shifting mode adjacent adc sampling interval 7 adcclk */ + ADC_SAMPLING_INTERVAL_8CYCLES = 0x03, /*!< ordinary shifting mode adjacent adc sampling interval 8 adcclk */ + ADC_SAMPLING_INTERVAL_9CYCLES = 0x04, /*!< ordinary shifting mode adjacent adc sampling interval 9 adcclk */ + ADC_SAMPLING_INTERVAL_10CYCLES = 0x05, /*!< ordinary shifting mode adjacent adc sampling interval 10 adcclk */ + ADC_SAMPLING_INTERVAL_11CYCLES = 0x06, /*!< ordinary shifting mode adjacent adc sampling interval 11 adcclk */ + ADC_SAMPLING_INTERVAL_12CYCLES = 0x07, /*!< ordinary shifting mode adjacent adc sampling interval 12 adcclk */ + ADC_SAMPLING_INTERVAL_13CYCLES = 0x08, /*!< ordinary shifting mode adjacent adc sampling interval 13 adcclk */ + ADC_SAMPLING_INTERVAL_14CYCLES = 0x09, /*!< ordinary shifting mode adjacent adc sampling interval 14 adcclk */ + ADC_SAMPLING_INTERVAL_15CYCLES = 0x0A, /*!< ordinary shifting mode adjacent adc sampling interval 15 adcclk */ + ADC_SAMPLING_INTERVAL_16CYCLES = 0x0B, /*!< ordinary shifting mode adjacent adc sampling interval 16 adcclk */ + ADC_SAMPLING_INTERVAL_17CYCLES = 0x0C, /*!< ordinary shifting mode adjacent adc sampling interval 17 adcclk */ + ADC_SAMPLING_INTERVAL_18CYCLES = 0x0D, /*!< ordinary shifting mode adjacent adc sampling interval 18 adcclk */ + ADC_SAMPLING_INTERVAL_19CYCLES = 0x0E, /*!< ordinary shifting mode adjacent adc sampling interval 19 adcclk */ + ADC_SAMPLING_INTERVAL_20CYCLES = 0x0F /*!< ordinary shifting mode adjacent adc sampling interval 20 adcclk */ } adc_sampling_interval_type; /** * @brief adc conversion resolution type */ -typedef enum -{ - ADC_RESOLUTION_12B = 0x00, /*!< conversion resolution 12 bit */ - ADC_RESOLUTION_10B = 0x01, /*!< conversion resolution 10 bit */ - ADC_RESOLUTION_8B = 0x02, /*!< conversion resolution 8 bit */ - ADC_RESOLUTION_6B = 0x03 /*!< conversion resolution 6 bit */ +typedef enum { + ADC_RESOLUTION_12B = 0x00, /*!< conversion resolution 12 bit */ + ADC_RESOLUTION_10B = 0x01, /*!< conversion resolution 10 bit */ + ADC_RESOLUTION_8B = 0x02, /*!< conversion resolution 8 bit */ + ADC_RESOLUTION_6B = 0x03 /*!< conversion resolution 6 bit */ } adc_resolution_type; /** * @brief adc data align type */ -typedef enum -{ - ADC_RIGHT_ALIGNMENT = 0x00, /*!< data right alignment */ - ADC_LEFT_ALIGNMENT = 0x01 /*!< data left alignment */ +typedef enum { + ADC_RIGHT_ALIGNMENT = 0x00, /*!< data right alignment */ + ADC_LEFT_ALIGNMENT = 0x01 /*!< data left alignment */ } adc_data_align_type; /** * @brief adc channel select type */ -typedef enum -{ - ADC_CHANNEL_0 = 0x00, /*!< adc channel 0 */ - ADC_CHANNEL_1 = 0x01, /*!< adc channel 1 */ - ADC_CHANNEL_2 = 0x02, /*!< adc channel 2 */ - ADC_CHANNEL_3 = 0x03, /*!< adc channel 3 */ - ADC_CHANNEL_4 = 0x04, /*!< adc channel 4 */ - ADC_CHANNEL_5 = 0x05, /*!< adc channel 5 */ - ADC_CHANNEL_6 = 0x06, /*!< adc channel 6 */ - ADC_CHANNEL_7 = 0x07, /*!< adc channel 7 */ - ADC_CHANNEL_8 = 0x08, /*!< adc channel 8 */ - ADC_CHANNEL_9 = 0x09, /*!< adc channel 9 */ - ADC_CHANNEL_10 = 0x0A, /*!< adc channel 10 */ - ADC_CHANNEL_11 = 0x0B, /*!< adc channel 11 */ - ADC_CHANNEL_12 = 0x0C, /*!< adc channel 12 */ - ADC_CHANNEL_13 = 0x0D, /*!< adc channel 13 */ - ADC_CHANNEL_14 = 0x0E, /*!< adc channel 14 */ - ADC_CHANNEL_15 = 0x0F, /*!< adc channel 15 */ - ADC_CHANNEL_16 = 0x10, /*!< adc channel 16 */ - ADC_CHANNEL_17 = 0x11, /*!< adc channel 17 */ - ADC_CHANNEL_18 = 0x12 /*!< adc channel 18 */ +typedef enum { + ADC_CHANNEL_0 = 0x00, /*!< adc channel 0 */ + ADC_CHANNEL_1 = 0x01, /*!< adc channel 1 */ + ADC_CHANNEL_2 = 0x02, /*!< adc channel 2 */ + ADC_CHANNEL_3 = 0x03, /*!< adc channel 3 */ + ADC_CHANNEL_4 = 0x04, /*!< adc channel 4 */ + ADC_CHANNEL_5 = 0x05, /*!< adc channel 5 */ + ADC_CHANNEL_6 = 0x06, /*!< adc channel 6 */ + ADC_CHANNEL_7 = 0x07, /*!< adc channel 7 */ + ADC_CHANNEL_8 = 0x08, /*!< adc channel 8 */ + ADC_CHANNEL_9 = 0x09, /*!< adc channel 9 */ + ADC_CHANNEL_10 = 0x0A, /*!< adc channel 10 */ + ADC_CHANNEL_11 = 0x0B, /*!< adc channel 11 */ + ADC_CHANNEL_12 = 0x0C, /*!< adc channel 12 */ + ADC_CHANNEL_13 = 0x0D, /*!< adc channel 13 */ + ADC_CHANNEL_14 = 0x0E, /*!< adc channel 14 */ + ADC_CHANNEL_15 = 0x0F, /*!< adc channel 15 */ + ADC_CHANNEL_16 = 0x10, /*!< adc channel 16 */ + ADC_CHANNEL_17 = 0x11, /*!< adc channel 17 */ + ADC_CHANNEL_18 = 0x12 /*!< adc channel 18 */ } adc_channel_select_type; /** * @brief adc sampletime select type */ -typedef enum -{ - ADC_SAMPLETIME_2_5 = 0x00, /*!< adc sample time 2.5 cycle */ - ADC_SAMPLETIME_6_5 = 0x01, /*!< adc sample time 6.5 cycle */ - ADC_SAMPLETIME_12_5 = 0x02, /*!< adc sample time 12.5 cycle */ - ADC_SAMPLETIME_24_5 = 0x03, /*!< adc sample time 24.5 cycle */ - ADC_SAMPLETIME_47_5 = 0x04, /*!< adc sample time 47.5 cycle */ - ADC_SAMPLETIME_92_5 = 0x05, /*!< adc sample time 92.5 cycle */ - ADC_SAMPLETIME_247_5 = 0x06, /*!< adc sample time 247.5 cycle */ - ADC_SAMPLETIME_640_5 = 0x07 /*!< adc sample time 640.5 cycle */ +typedef enum { + ADC_SAMPLETIME_2_5 = 0x00, /*!< adc sample time 2.5 cycle */ + ADC_SAMPLETIME_6_5 = 0x01, /*!< adc sample time 6.5 cycle */ + ADC_SAMPLETIME_12_5 = 0x02, /*!< adc sample time 12.5 cycle */ + ADC_SAMPLETIME_24_5 = 0x03, /*!< adc sample time 24.5 cycle */ + ADC_SAMPLETIME_47_5 = 0x04, /*!< adc sample time 47.5 cycle */ + ADC_SAMPLETIME_92_5 = 0x05, /*!< adc sample time 92.5 cycle */ + ADC_SAMPLETIME_247_5 = 0x06, /*!< adc sample time 247.5 cycle */ + ADC_SAMPLETIME_640_5 = 0x07 /*!< adc sample time 640.5 cycle */ } adc_sampletime_select_type; /** * @brief adc ordinary group trigger event select type */ -typedef enum -{ - ADC_ORDINARY_TRIG_TMR1CH1 = 0x00, /*!< timer1 ch1 event as trigger source of ordinary sequence */ - ADC_ORDINARY_TRIG_TMR1CH2 = 0x01, /*!< timer1 ch2 event as trigger source of ordinary sequence */ - ADC_ORDINARY_TRIG_TMR1CH3 = 0x02, /*!< timer1 ch3 event as trigger source of ordinary sequence */ - ADC_ORDINARY_TRIG_TMR2CH2 = 0x03, /*!< timer2 ch2 event as trigger source of ordinary sequence */ - ADC_ORDINARY_TRIG_TMR2CH3 = 0x04, /*!< timer2 ch3 event as trigger source of ordinary sequence */ - ADC_ORDINARY_TRIG_TMR2CH4 = 0x05, /*!< timer2 ch4 event as trigger source of ordinary sequence */ - ADC_ORDINARY_TRIG_TMR2TRGOUT = 0x06, /*!< timer2 trgout event as trigger source of ordinary sequence */ - ADC_ORDINARY_TRIG_TMR3CH1 = 0x07, /*!< timer3 ch1 event as trigger source of ordinary sequence */ - ADC_ORDINARY_TRIG_TMR3TRGOUT = 0x08, /*!< timer3 trgout event as trigger source of ordinary sequence */ - ADC_ORDINARY_TRIG_TMR4CH4 = 0x09, /*!< timer4 ch4 event as trigger source of ordinary sequence */ - ADC_ORDINARY_TRIG_TMR5CH1 = 0x0A, /*!< timer5 ch1 event as trigger source of ordinary sequence */ - ADC_ORDINARY_TRIG_TMR5CH2 = 0x0B, /*!< timer5 ch2 event as trigger source of ordinary sequence */ - ADC_ORDINARY_TRIG_TMR5CH3 = 0x0C, /*!< timer5 ch3 event as trigger source of ordinary sequence */ - ADC_ORDINARY_TRIG_TMR8CH1 = 0x0D, /*!< timer8 ch1 event as trigger source of ordinary sequence */ - ADC_ORDINARY_TRIG_TMR8TRGOUT = 0x0E, /*!< timer8 trgout event as trigger source of ordinary sequence */ - ADC_ORDINARY_TRIG_EXINT11 = 0x0F, /*!< exint line11 event as trigger source of ordinary sequence */ - ADC_ORDINARY_TRIG_TMR20TRGOUT = 0x10, /*!< timer20 trgout event as trigger source of ordinary sequence */ - ADC_ORDINARY_TRIG_TMR20TRGOUT2 = 0x11, /*!< timer20 trgout2 event as trigger source of ordinary sequence */ - ADC_ORDINARY_TRIG_TMR20CH1 = 0x12, /*!< timer20 ch1 event as trigger source of ordinary sequence */ - ADC_ORDINARY_TRIG_TMR20CH2 = 0x13, /*!< timer20 ch2 event as trigger source of ordinary sequence */ - ADC_ORDINARY_TRIG_TMR20CH3 = 0x14, /*!< timer20 ch3 event as trigger source of ordinary sequence */ - ADC_ORDINARY_TRIG_TMR8TRGOUT2 = 0x15, /*!< timer8 trgout2 event as trigger source of ordinary sequence */ - ADC_ORDINARY_TRIG_TMR1TRGOUT2 = 0x16, /*!< timer1 trgout2 event as trigger source of ordinary sequence */ - ADC_ORDINARY_TRIG_TMR4TRGOUT = 0x17, /*!< timer4 trgout event as trigger source of ordinary sequence */ - ADC_ORDINARY_TRIG_TMR6TRGOUT = 0x18, /*!< timer6 trgout event as trigger source of ordinary sequence */ - ADC_ORDINARY_TRIG_TMR3CH4 = 0x19, /*!< timer3 ch4 event as trigger source of ordinary sequence */ - ADC_ORDINARY_TRIG_TMR4CH1 = 0x1A, /*!< timer4 ch1 event as trigger source of ordinary sequence */ - ADC_ORDINARY_TRIG_TMR1TRGOUT = 0x1B, /*!< timer1 trgout event as trigger source of ordinary sequence */ - ADC_ORDINARY_TRIG_TMR2CH1 = 0x1C, /*!< timer2 ch1 event as trigger source of ordinary sequence */ - ADC_ORDINARY_TRIG_TMR7TRGOUT = 0x1E /*!< timer7 trgout event as trigger source of ordinary sequence */ +typedef enum { + ADC_ORDINARY_TRIG_TMR1CH1 = 0x00, /*!< timer1 ch1 event as trigger source of ordinary sequence */ + ADC_ORDINARY_TRIG_TMR1CH2 = 0x01, /*!< timer1 ch2 event as trigger source of ordinary sequence */ + ADC_ORDINARY_TRIG_TMR1CH3 = 0x02, /*!< timer1 ch3 event as trigger source of ordinary sequence */ + ADC_ORDINARY_TRIG_TMR2CH2 = 0x03, /*!< timer2 ch2 event as trigger source of ordinary sequence */ + ADC_ORDINARY_TRIG_TMR2CH3 = 0x04, /*!< timer2 ch3 event as trigger source of ordinary sequence */ + ADC_ORDINARY_TRIG_TMR2CH4 = 0x05, /*!< timer2 ch4 event as trigger source of ordinary sequence */ + ADC_ORDINARY_TRIG_TMR2TRGOUT = 0x06, /*!< timer2 trgout event as trigger source of ordinary sequence */ + ADC_ORDINARY_TRIG_TMR3CH1 = 0x07, /*!< timer3 ch1 event as trigger source of ordinary sequence */ + ADC_ORDINARY_TRIG_TMR3TRGOUT = 0x08, /*!< timer3 trgout event as trigger source of ordinary sequence */ + ADC_ORDINARY_TRIG_TMR4CH4 = 0x09, /*!< timer4 ch4 event as trigger source of ordinary sequence */ + ADC_ORDINARY_TRIG_TMR5CH1 = 0x0A, /*!< timer5 ch1 event as trigger source of ordinary sequence */ + ADC_ORDINARY_TRIG_TMR5CH2 = 0x0B, /*!< timer5 ch2 event as trigger source of ordinary sequence */ + ADC_ORDINARY_TRIG_TMR5CH3 = 0x0C, /*!< timer5 ch3 event as trigger source of ordinary sequence */ + ADC_ORDINARY_TRIG_TMR8CH1 = 0x0D, /*!< timer8 ch1 event as trigger source of ordinary sequence */ + ADC_ORDINARY_TRIG_TMR8TRGOUT = 0x0E, /*!< timer8 trgout event as trigger source of ordinary sequence */ + ADC_ORDINARY_TRIG_EXINT11 = 0x0F, /*!< exint line11 event as trigger source of ordinary sequence */ + ADC_ORDINARY_TRIG_TMR20TRGOUT = 0x10, /*!< timer20 trgout event as trigger source of ordinary sequence */ + ADC_ORDINARY_TRIG_TMR20TRGOUT2 = 0x11, /*!< timer20 trgout2 event as trigger source of ordinary sequence */ + ADC_ORDINARY_TRIG_TMR20CH1 = 0x12, /*!< timer20 ch1 event as trigger source of ordinary sequence */ + ADC_ORDINARY_TRIG_TMR20CH2 = 0x13, /*!< timer20 ch2 event as trigger source of ordinary sequence */ + ADC_ORDINARY_TRIG_TMR20CH3 = 0x14, /*!< timer20 ch3 event as trigger source of ordinary sequence */ + ADC_ORDINARY_TRIG_TMR8TRGOUT2 = 0x15, /*!< timer8 trgout2 event as trigger source of ordinary sequence */ + ADC_ORDINARY_TRIG_TMR1TRGOUT2 = 0x16, /*!< timer1 trgout2 event as trigger source of ordinary sequence */ + ADC_ORDINARY_TRIG_TMR4TRGOUT = 0x17, /*!< timer4 trgout event as trigger source of ordinary sequence */ + ADC_ORDINARY_TRIG_TMR6TRGOUT = 0x18, /*!< timer6 trgout event as trigger source of ordinary sequence */ + ADC_ORDINARY_TRIG_TMR3CH4 = 0x19, /*!< timer3 ch4 event as trigger source of ordinary sequence */ + ADC_ORDINARY_TRIG_TMR4CH1 = 0x1A, /*!< timer4 ch1 event as trigger source of ordinary sequence */ + ADC_ORDINARY_TRIG_TMR1TRGOUT = 0x1B, /*!< timer1 trgout event as trigger source of ordinary sequence */ + ADC_ORDINARY_TRIG_TMR2CH1 = 0x1C, /*!< timer2 ch1 event as trigger source of ordinary sequence */ + ADC_ORDINARY_TRIG_TMR7TRGOUT = 0x1E /*!< timer7 trgout event as trigger source of ordinary sequence */ } adc_ordinary_trig_select_type; /** * @brief adc ordinary channel conversion's external_trigger_edge type */ -typedef enum -{ - ADC_ORDINARY_TRIG_EDGE_NONE = 0x00, /*!< ordinary channels trigger detection disabled */ - ADC_ORDINARY_TRIG_EDGE_RISING = 0x01, /*!< ordinary channels trigger detection on the rising edge */ - ADC_ORDINARY_TRIG_EDGE_FALLING = 0x02, /*!< ordinary channels trigger detection on the falling edge */ - ADC_ORDINARY_TRIG_EDGE_RISING_FALLING = 0x03 /*!< ordinary channels trigger detection on both the rising and falling edges */ +typedef enum { + ADC_ORDINARY_TRIG_EDGE_NONE = 0x00, /*!< ordinary channels trigger detection disabled */ + ADC_ORDINARY_TRIG_EDGE_RISING = 0x01, /*!< ordinary channels trigger detection on the rising edge */ + ADC_ORDINARY_TRIG_EDGE_FALLING = 0x02, /*!< ordinary channels trigger detection on the falling edge */ + ADC_ORDINARY_TRIG_EDGE_RISING_FALLING = 0x03 /*!< ordinary channels trigger detection on both the rising and falling edges */ } adc_ordinary_trig_edge_type; /** * @brief adc preempt group external trigger event select type */ -typedef enum -{ - ADC_PREEMPT_TRIG_TMR1CH4 = 0x00, /*!< timer1 ch4 event as trigger source of preempt sequence */ - ADC_PREEMPT_TRIG_TMR1TRGOUT = 0x01, /*!< timer1 trgout event as trigger source of preempt sequence */ - ADC_PREEMPT_TRIG_TMR2CH1 = 0x02, /*!< timer2 ch1 event as trigger source of preempt sequence */ - ADC_PREEMPT_TRIG_TMR2TRGOUT = 0x03, /*!< timer2 trgout event as trigger source of preempt sequence */ - ADC_PREEMPT_TRIG_TMR3CH2 = 0x04, /*!< timer3 ch2 event as trigger source of preempt sequence */ - ADC_PREEMPT_TRIG_TMR3CH4 = 0x05, /*!< timer3 ch4 event as trigger source of preempt sequence */ - ADC_PREEMPT_TRIG_TMR4CH1 = 0x06, /*!< timer4 ch1 event as trigger source of preempt sequence */ - ADC_PREEMPT_TRIG_TMR4CH2 = 0x07, /*!< timer4 ch2 event as trigger source of preempt sequence */ - ADC_PREEMPT_TRIG_TMR4CH3 = 0x08, /*!< timer4 ch3 event as trigger source of preempt sequence */ - ADC_PREEMPT_TRIG_TMR4TRGOUT = 0x09, /*!< timer4 trgout event as trigger source of preempt sequence */ - ADC_PREEMPT_TRIG_TMR5CH4 = 0x0A, /*!< timer5 ch4 event as trigger source of preempt sequence */ - ADC_PREEMPT_TRIG_TMR5TRGOUT = 0x0B, /*!< timer5 trgout event as trigger source of preempt sequence */ - ADC_PREEMPT_TRIG_TMR8CH2 = 0x0C, /*!< timer8 ch2 event as trigger source of preempt sequence */ - ADC_PREEMPT_TRIG_TMR8CH3 = 0x0D, /*!< timer8 ch3 event as trigger source of preempt sequence */ - ADC_PREEMPT_TRIG_TMR8CH4 = 0x0E, /*!< timer8 ch4 event as trigger source of preempt sequence */ - ADC_PREEMPT_TRIG_EXINT15 = 0x0F, /*!< exint line15 event as trigger source of preempt sequence */ - ADC_PREEMPT_TRIG_TMR20TRGOUT = 0x10, /*!< timer20 trgout event as trigger source of preempt sequence */ - ADC_PREEMPT_TRIG_TMR20TRGOUT2 = 0x11, /*!< timer20 trgout2 event as trigger source of preempt sequence */ - ADC_PREEMPT_TRIG_TMR20CH4 = 0x12, /*!< timer20 ch4 event as trigger source of preempt sequence */ - ADC_PREEMPT_TRIG_TMR1TRGOUT2 = 0x13, /*!< timer1 trgout2 event as trigger source of preempt sequence */ - ADC_PREEMPT_TRIG_TMR8TRGOUT = 0x14, /*!< timer8 trgout event as trigger source of preempt sequence */ - ADC_PREEMPT_TRIG_TMR8TRGOUT2 = 0x15, /*!< timer8 trgout2 event as trigger source of preempt sequence */ - ADC_PREEMPT_TRIG_TMR3CH3 = 0x16, /*!< timer3 ch3 event as trigger source of preempt sequence */ - ADC_PREEMPT_TRIG_TMR3TRGOUT = 0x17, /*!< timer3 trgout event as trigger source of preempt sequence */ - ADC_PREEMPT_TRIG_TMR3CH1 = 0x18, /*!< timer3 ch1 event as trigger source of preempt sequence */ - ADC_PREEMPT_TRIG_TMR6TRGOUT = 0x19, /*!< timer6 trgout event as trigger source of preempt sequence */ - ADC_PREEMPT_TRIG_TMR4CH4 = 0x1A, /*!< timer4 ch4 event as trigger source of preempt sequence */ - ADC_PREEMPT_TRIG_TMR1CH3 = 0x1B, /*!< timer1 ch3 event as trigger source of preempt sequence */ - ADC_PREEMPT_TRIG_TMR20CH2 = 0x1C, /*!< timer20 ch2 event as trigger source of preempt sequence */ - ADC_PREEMPT_TRIG_TMR7TRGOUT = 0x1E /*!< timer7 trgout event as trigger source of preempt sequence */ +typedef enum { + ADC_PREEMPT_TRIG_TMR1CH4 = 0x00, /*!< timer1 ch4 event as trigger source of preempt sequence */ + ADC_PREEMPT_TRIG_TMR1TRGOUT = 0x01, /*!< timer1 trgout event as trigger source of preempt sequence */ + ADC_PREEMPT_TRIG_TMR2CH1 = 0x02, /*!< timer2 ch1 event as trigger source of preempt sequence */ + ADC_PREEMPT_TRIG_TMR2TRGOUT = 0x03, /*!< timer2 trgout event as trigger source of preempt sequence */ + ADC_PREEMPT_TRIG_TMR3CH2 = 0x04, /*!< timer3 ch2 event as trigger source of preempt sequence */ + ADC_PREEMPT_TRIG_TMR3CH4 = 0x05, /*!< timer3 ch4 event as trigger source of preempt sequence */ + ADC_PREEMPT_TRIG_TMR4CH1 = 0x06, /*!< timer4 ch1 event as trigger source of preempt sequence */ + ADC_PREEMPT_TRIG_TMR4CH2 = 0x07, /*!< timer4 ch2 event as trigger source of preempt sequence */ + ADC_PREEMPT_TRIG_TMR4CH3 = 0x08, /*!< timer4 ch3 event as trigger source of preempt sequence */ + ADC_PREEMPT_TRIG_TMR4TRGOUT = 0x09, /*!< timer4 trgout event as trigger source of preempt sequence */ + ADC_PREEMPT_TRIG_TMR5CH4 = 0x0A, /*!< timer5 ch4 event as trigger source of preempt sequence */ + ADC_PREEMPT_TRIG_TMR5TRGOUT = 0x0B, /*!< timer5 trgout event as trigger source of preempt sequence */ + ADC_PREEMPT_TRIG_TMR8CH2 = 0x0C, /*!< timer8 ch2 event as trigger source of preempt sequence */ + ADC_PREEMPT_TRIG_TMR8CH3 = 0x0D, /*!< timer8 ch3 event as trigger source of preempt sequence */ + ADC_PREEMPT_TRIG_TMR8CH4 = 0x0E, /*!< timer8 ch4 event as trigger source of preempt sequence */ + ADC_PREEMPT_TRIG_EXINT15 = 0x0F, /*!< exint line15 event as trigger source of preempt sequence */ + ADC_PREEMPT_TRIG_TMR20TRGOUT = 0x10, /*!< timer20 trgout event as trigger source of preempt sequence */ + ADC_PREEMPT_TRIG_TMR20TRGOUT2 = 0x11, /*!< timer20 trgout2 event as trigger source of preempt sequence */ + ADC_PREEMPT_TRIG_TMR20CH4 = 0x12, /*!< timer20 ch4 event as trigger source of preempt sequence */ + ADC_PREEMPT_TRIG_TMR1TRGOUT2 = 0x13, /*!< timer1 trgout2 event as trigger source of preempt sequence */ + ADC_PREEMPT_TRIG_TMR8TRGOUT = 0x14, /*!< timer8 trgout event as trigger source of preempt sequence */ + ADC_PREEMPT_TRIG_TMR8TRGOUT2 = 0x15, /*!< timer8 trgout2 event as trigger source of preempt sequence */ + ADC_PREEMPT_TRIG_TMR3CH3 = 0x16, /*!< timer3 ch3 event as trigger source of preempt sequence */ + ADC_PREEMPT_TRIG_TMR3TRGOUT = 0x17, /*!< timer3 trgout event as trigger source of preempt sequence */ + ADC_PREEMPT_TRIG_TMR3CH1 = 0x18, /*!< timer3 ch1 event as trigger source of preempt sequence */ + ADC_PREEMPT_TRIG_TMR6TRGOUT = 0x19, /*!< timer6 trgout event as trigger source of preempt sequence */ + ADC_PREEMPT_TRIG_TMR4CH4 = 0x1A, /*!< timer4 ch4 event as trigger source of preempt sequence */ + ADC_PREEMPT_TRIG_TMR1CH3 = 0x1B, /*!< timer1 ch3 event as trigger source of preempt sequence */ + ADC_PREEMPT_TRIG_TMR20CH2 = 0x1C, /*!< timer20 ch2 event as trigger source of preempt sequence */ + ADC_PREEMPT_TRIG_TMR7TRGOUT = 0x1E /*!< timer7 trgout event as trigger source of preempt sequence */ } adc_preempt_trig_select_type; /** * @brief adc preempt channel conversion's external_trigger_edge type */ -typedef enum -{ - ADC_PREEMPT_TRIG_EDGE_NONE = 0x00, /*!< preempt channels trigger detection disabled */ - ADC_PREEMPT_TRIG_EDGE_RISING = 0x01, /*!< preempt channels trigger detection on the rising edge */ - ADC_PREEMPT_TRIG_EDGE_FALLING = 0x02, /*!< preempt channels trigger detection on the falling edge */ - ADC_PREEMPT_TRIG_EDGE_RISING_FALLING = 0x03 /*!< preempt channels trigger detection on both the rising and falling edges */ +typedef enum { + ADC_PREEMPT_TRIG_EDGE_NONE = 0x00, /*!< preempt channels trigger detection disabled */ + ADC_PREEMPT_TRIG_EDGE_RISING = 0x01, /*!< preempt channels trigger detection on the rising edge */ + ADC_PREEMPT_TRIG_EDGE_FALLING = 0x02, /*!< preempt channels trigger detection on the falling edge */ + ADC_PREEMPT_TRIG_EDGE_RISING_FALLING = 0x03 /*!< preempt channels trigger detection on both the rising and falling edges */ } adc_preempt_trig_edge_type; /** * @brief adc preempt channel type */ -typedef enum -{ - ADC_PREEMPT_CHANNEL_1 = 0x00, /*!< adc preempt channel 1 */ - ADC_PREEMPT_CHANNEL_2 = 0x01, /*!< adc preempt channel 2 */ - ADC_PREEMPT_CHANNEL_3 = 0x02, /*!< adc preempt channel 3 */ - ADC_PREEMPT_CHANNEL_4 = 0x03 /*!< adc preempt channel 4 */ +typedef enum { + ADC_PREEMPT_CHANNEL_1 = 0x00, /*!< adc preempt channel 1 */ + ADC_PREEMPT_CHANNEL_2 = 0x01, /*!< adc preempt channel 2 */ + ADC_PREEMPT_CHANNEL_3 = 0x02, /*!< adc preempt channel 3 */ + ADC_PREEMPT_CHANNEL_4 = 0x03 /*!< adc preempt channel 4 */ } adc_preempt_channel_type; /** * @brief adc voltage_monitoring type */ -typedef enum -{ - ADC_VMONITOR_SINGLE_ORDINARY = 0x00800200, /*!< voltage_monitoring on a single ordinary channel */ - ADC_VMONITOR_SINGLE_PREEMPT = 0x00400200, /*!< voltage_monitoring on a single preempt channel */ - ADC_VMONITOR_SINGLE_ORDINARY_PREEMPT = 0x00C00200, /*!< voltage_monitoring on a single ordinary or preempt channel */ - ADC_VMONITOR_ALL_ORDINARY = 0x00800000, /*!< voltage_monitoring on all ordinary channel */ - ADC_VMONITOR_ALL_PREEMPT = 0x00400000, /*!< voltage_monitoring on all preempt channel */ - ADC_VMONITOR_ALL_ORDINARY_PREEMPT = 0x00C00000, /*!< voltage_monitoring on all ordinary and preempt channel */ - ADC_VMONITOR_NONE = 0x00000000 /*!< no channel guarded by the voltage_monitoring */ +typedef enum { + ADC_VMONITOR_SINGLE_ORDINARY = 0x00800200, /*!< voltage_monitoring on a single ordinary channel */ + ADC_VMONITOR_SINGLE_PREEMPT = 0x00400200, /*!< voltage_monitoring on a single preempt channel */ + ADC_VMONITOR_SINGLE_ORDINARY_PREEMPT = 0x00C00200, /*!< voltage_monitoring on a single ordinary or preempt channel */ + ADC_VMONITOR_ALL_ORDINARY = 0x00800000, /*!< voltage_monitoring on all ordinary channel */ + ADC_VMONITOR_ALL_PREEMPT = 0x00400000, /*!< voltage_monitoring on all preempt channel */ + ADC_VMONITOR_ALL_ORDINARY_PREEMPT = 0x00C00000, /*!< voltage_monitoring on all ordinary and preempt channel */ + ADC_VMONITOR_NONE = 0x00000000 /*!< no channel guarded by the voltage_monitoring */ } adc_voltage_monitoring_type; /** * @brief adc oversample ratio type */ -typedef enum -{ - ADC_OVERSAMPLE_RATIO_2 = 0x00, /*!< adc oversample ratio 2 */ - ADC_OVERSAMPLE_RATIO_4 = 0x01, /*!< adc oversample ratio 4 */ - ADC_OVERSAMPLE_RATIO_8 = 0x02, /*!< adc oversample ratio 8 */ - ADC_OVERSAMPLE_RATIO_16 = 0x03, /*!< adc oversample ratio 16 */ - ADC_OVERSAMPLE_RATIO_32 = 0x04, /*!< adc oversample ratio 32 */ - ADC_OVERSAMPLE_RATIO_64 = 0x05, /*!< adc oversample ratio 64 */ - ADC_OVERSAMPLE_RATIO_128 = 0x06, /*!< adc oversample ratio 128 */ - ADC_OVERSAMPLE_RATIO_256 = 0x07 /*!< adc oversample ratio 256 */ +typedef enum { + ADC_OVERSAMPLE_RATIO_2 = 0x00, /*!< adc oversample ratio 2 */ + ADC_OVERSAMPLE_RATIO_4 = 0x01, /*!< adc oversample ratio 4 */ + ADC_OVERSAMPLE_RATIO_8 = 0x02, /*!< adc oversample ratio 8 */ + ADC_OVERSAMPLE_RATIO_16 = 0x03, /*!< adc oversample ratio 16 */ + ADC_OVERSAMPLE_RATIO_32 = 0x04, /*!< adc oversample ratio 32 */ + ADC_OVERSAMPLE_RATIO_64 = 0x05, /*!< adc oversample ratio 64 */ + ADC_OVERSAMPLE_RATIO_128 = 0x06, /*!< adc oversample ratio 128 */ + ADC_OVERSAMPLE_RATIO_256 = 0x07 /*!< adc oversample ratio 256 */ } adc_oversample_ratio_type; /** * @brief adc oversample shift type */ -typedef enum -{ - ADC_OVERSAMPLE_SHIFT_0 = 0x00, /*!< adc oversample shift 0 */ - ADC_OVERSAMPLE_SHIFT_1 = 0x01, /*!< adc oversample shift 1 */ - ADC_OVERSAMPLE_SHIFT_2 = 0x02, /*!< adc oversample shift 2 */ - ADC_OVERSAMPLE_SHIFT_3 = 0x03, /*!< adc oversample shift 3 */ - ADC_OVERSAMPLE_SHIFT_4 = 0x04, /*!< adc oversample shift 4 */ - ADC_OVERSAMPLE_SHIFT_5 = 0x05, /*!< adc oversample shift 5 */ - ADC_OVERSAMPLE_SHIFT_6 = 0x06, /*!< adc oversample shift 6 */ - ADC_OVERSAMPLE_SHIFT_7 = 0x07, /*!< adc oversample shift 7 */ - ADC_OVERSAMPLE_SHIFT_8 = 0x08 /*!< adc oversample shift 8 */ +typedef enum { + ADC_OVERSAMPLE_SHIFT_0 = 0x00, /*!< adc oversample shift 0 */ + ADC_OVERSAMPLE_SHIFT_1 = 0x01, /*!< adc oversample shift 1 */ + ADC_OVERSAMPLE_SHIFT_2 = 0x02, /*!< adc oversample shift 2 */ + ADC_OVERSAMPLE_SHIFT_3 = 0x03, /*!< adc oversample shift 3 */ + ADC_OVERSAMPLE_SHIFT_4 = 0x04, /*!< adc oversample shift 4 */ + ADC_OVERSAMPLE_SHIFT_5 = 0x05, /*!< adc oversample shift 5 */ + ADC_OVERSAMPLE_SHIFT_6 = 0x06, /*!< adc oversample shift 6 */ + ADC_OVERSAMPLE_SHIFT_7 = 0x07, /*!< adc oversample shift 7 */ + ADC_OVERSAMPLE_SHIFT_8 = 0x08 /*!< adc oversample shift 8 */ } adc_oversample_shift_type; /** * @brief adc ordinary oversample recover type */ -typedef enum -{ - ADC_OVERSAMPLE_CONTINUE = 0x00, /*!< continue mode:when preempt triggered,oversampling is temporary stopped and continued after preempt sequence */ - ADC_OVERSAMPLE_RESTART = 0x01 /*!< restart mode:when preempt triggered,oversampling is aborted and resumed from start after preempt sequence */ +typedef enum { + ADC_OVERSAMPLE_CONTINUE = 0x00, /*!< continue mode:when preempt triggered,oversampling is temporary stopped and continued after preempt sequence */ + ADC_OVERSAMPLE_RESTART = 0x01 /*!< restart mode:when preempt triggered,oversampling is aborted and resumed from start after preempt sequence */ } adc_ordinary_oversample_restart_type; /** * @brief adc common config type */ -typedef struct -{ - adc_combine_mode_type combine_mode; /*!< adc combine mode select */ - adc_div_type div; /*!< adc division select */ - adc_common_dma_mode_type common_dma_mode; /*!< adc common dma mode select */ - confirm_state common_dma_request_repeat_state; /*!< adc common dma repeat state */ - adc_sampling_interval_type sampling_interval; /*!< ordinary shifting mode adjacent adc sampling interval select */ - confirm_state tempervintrv_state; /*!< adc temperature sensor and vintrv state */ - confirm_state vbat_state; /*!< adc voltage battery state */ +typedef struct { + adc_combine_mode_type combine_mode; /*!< adc combine mode select */ + adc_div_type div; /*!< adc division select */ + adc_common_dma_mode_type common_dma_mode; /*!< adc common dma mode select */ + confirm_state common_dma_request_repeat_state; /*!< adc common dma repeat state */ + adc_sampling_interval_type sampling_interval; /*!< ordinary shifting mode adjacent adc sampling interval select */ + confirm_state tempervintrv_state; /*!< adc temperature sensor and vintrv state */ + confirm_state vbat_state; /*!< adc voltage battery state */ } adc_common_config_type; /** * @brief adc base config type */ -typedef struct -{ - confirm_state sequence_mode; /*!< adc sequence mode */ - confirm_state repeat_mode; /*!< adc repeat mode */ - adc_data_align_type data_align; /*!< adc data alignment */ - uint8_t ordinary_channel_length; /*!< adc ordinary channel sequence length*/ +typedef struct { + confirm_state sequence_mode; /*!< adc sequence mode */ + confirm_state repeat_mode; /*!< adc repeat mode */ + adc_data_align_type data_align; /*!< adc data alignment */ + uint8_t ordinary_channel_length; /*!< adc ordinary channel sequence length*/ } adc_base_config_type; /** * @brief type define adc register all */ -typedef struct -{ +typedef struct { - /** - * @brief adc sts register, offset:0x00 + /** + * @brief adc sts register, offset:0x00 + */ + union { + __IO uint32_t sts; + struct { + __IO uint32_t vmor : 1; /* [0] */ + __IO uint32_t occe : 1; /* [1] */ + __IO uint32_t pcce : 1; /* [2] */ + __IO uint32_t pccs : 1; /* [3] */ + __IO uint32_t occs : 1; /* [4] */ + __IO uint32_t occo : 1; /* [5] */ + __IO uint32_t rdy : 1; /* [6] */ + __IO uint32_t reserved1 : 25;/* [31:7] */ + } sts_bit; + }; + + /** + * @brief adc ctrl1 register, offset:0x04 + */ + union { + __IO uint32_t ctrl1; + struct { + __IO uint32_t vmcsel : 5; /* [4:0] */ + __IO uint32_t occeien : 1; /* [5] */ + __IO uint32_t vmorien : 1; /* [6] */ + __IO uint32_t pcceien : 1; /* [7] */ + __IO uint32_t sqen : 1; /* [8] */ + __IO uint32_t vmsgen : 1; /* [9] */ + __IO uint32_t pcautoen : 1; /* [10] */ + __IO uint32_t ocpen : 1; /* [11] */ + __IO uint32_t pcpen : 1; /* [12] */ + __IO uint32_t ocpcnt : 3; /* [15:13] */ + __IO uint32_t reserved1 : 6; /* [21:16] */ + __IO uint32_t pcvmen : 1; /* [22] */ + __IO uint32_t ocvmen : 1; /* [23] */ + __IO uint32_t crsel : 2; /* [25:24] */ + __IO uint32_t occoien : 1; /* [26] */ + __IO uint32_t reserved2 : 5; /* [31:27] */ + } ctrl1_bit; + }; + + /** + * @brief adc ctrl2 register, offset:0x08 + */ + union { + __IO uint32_t ctrl2; + struct { + __IO uint32_t adcen : 1; /* [0] */ + __IO uint32_t rpen : 1; /* [1] */ + __IO uint32_t adcal : 1; /* [2] */ + __IO uint32_t adcalinit : 1; /* [3] */ + __IO uint32_t adabrt : 1; /* [4] */ + __IO uint32_t reserved1 : 3; /* [7:5] */ + __IO uint32_t ocdmaen : 1; /* [8] */ + __IO uint32_t ocdrcen : 1; /* [9] */ + __IO uint32_t eocsfen : 1; /* [10] */ + __IO uint32_t dtalign : 1; /* [11] */ + __IO uint32_t reserved2 : 4; /* [15:12] */ + __IO uint32_t pctesel_l : 4; /* [19:16] */ + __IO uint32_t pcete : 2; /* [21:20] */ + __IO uint32_t pcswtrg : 1; /* [22] */ + __IO uint32_t pctesel_h : 1; /* [23] */ + __IO uint32_t octesel_l : 4; /* [27:24] */ + __IO uint32_t ocete : 2; /* [29:28] */ + __IO uint32_t ocswtrg : 1; /* [30] */ + __IO uint32_t octesel_h : 1; /* [31] */ + } ctrl2_bit; + }; + + /** + * @brief adc spt1 register, offset:0x0C */ - union - { - __IO uint32_t sts; - struct - { - __IO uint32_t vmor : 1; /* [0] */ - __IO uint32_t occe : 1; /* [1] */ - __IO uint32_t pcce : 1; /* [2] */ - __IO uint32_t pccs : 1; /* [3] */ - __IO uint32_t occs : 1; /* [4] */ - __IO uint32_t occo : 1; /* [5] */ - __IO uint32_t rdy : 1; /* [6] */ - __IO uint32_t reserved1 : 25;/* [31:7] */ - } sts_bit; - }; + union { + __IO uint32_t spt1; + struct { + __IO uint32_t cspt10 : 3; /* [2:0] */ + __IO uint32_t cspt11 : 3; /* [5:3] */ + __IO uint32_t cspt12 : 3; /* [8:6] */ + __IO uint32_t cspt13 : 3; /* [11:9] */ + __IO uint32_t cspt14 : 3; /* [14:12] */ + __IO uint32_t cspt15 : 3; /* [17:15] */ + __IO uint32_t cspt16 : 3; /* [20:18] */ + __IO uint32_t cspt17 : 3; /* [23:21] */ + __IO uint32_t cspt18 : 3; /* [26:24] */ + __IO uint32_t reserved1 : 5;/* [31:27] */ + } spt1_bit; + }; - /** - * @brief adc ctrl1 register, offset:0x04 + /** + * @brief adc spt2 register, offset:0x10 */ - union - { - __IO uint32_t ctrl1; - struct - { - __IO uint32_t vmcsel : 5; /* [4:0] */ - __IO uint32_t occeien : 1; /* [5] */ - __IO uint32_t vmorien : 1; /* [6] */ - __IO uint32_t pcceien : 1; /* [7] */ - __IO uint32_t sqen : 1; /* [8] */ - __IO uint32_t vmsgen : 1; /* [9] */ - __IO uint32_t pcautoen : 1; /* [10] */ - __IO uint32_t ocpen : 1; /* [11] */ - __IO uint32_t pcpen : 1; /* [12] */ - __IO uint32_t ocpcnt : 3; /* [15:13] */ - __IO uint32_t reserved1 : 6; /* [21:16] */ - __IO uint32_t pcvmen : 1; /* [22] */ - __IO uint32_t ocvmen : 1; /* [23] */ - __IO uint32_t crsel : 2; /* [25:24] */ - __IO uint32_t occoien : 1; /* [26] */ - __IO uint32_t reserved2 : 5; /* [31:27] */ - } ctrl1_bit; - }; + union { + __IO uint32_t spt2; + struct { + __IO uint32_t cspt0 : 3;/* [2:0] */ + __IO uint32_t cspt1 : 3;/* [5:3] */ + __IO uint32_t cspt2 : 3;/* [8:6] */ + __IO uint32_t cspt3 : 3;/* [11:9] */ + __IO uint32_t cspt4 : 3;/* [14:12] */ + __IO uint32_t cspt5 : 3;/* [17:15] */ + __IO uint32_t cspt6 : 3;/* [20:18] */ + __IO uint32_t cspt7 : 3;/* [23:21] */ + __IO uint32_t cspt8 : 3;/* [26:24] */ + __IO uint32_t cspt9 : 3;/* [29:27] */ + __IO uint32_t reserved1 : 2;/* [31:30] */ + } spt2_bit; + }; - /** - * @brief adc ctrl2 register, offset:0x08 + /** + * @brief adc pcdto1 register, offset:0x14 */ - union - { - __IO uint32_t ctrl2; - struct - { - __IO uint32_t adcen : 1; /* [0] */ - __IO uint32_t rpen : 1; /* [1] */ - __IO uint32_t adcal : 1; /* [2] */ - __IO uint32_t adcalinit : 1; /* [3] */ - __IO uint32_t adabrt : 1; /* [4] */ - __IO uint32_t reserved1 : 3; /* [7:5] */ - __IO uint32_t ocdmaen : 1; /* [8] */ - __IO uint32_t ocdrcen : 1; /* [9] */ - __IO uint32_t eocsfen : 1; /* [10] */ - __IO uint32_t dtalign : 1; /* [11] */ - __IO uint32_t reserved2 : 4; /* [15:12] */ - __IO uint32_t pctesel_l : 4; /* [19:16] */ - __IO uint32_t pcete : 2; /* [21:20] */ - __IO uint32_t pcswtrg : 1; /* [22] */ - __IO uint32_t pctesel_h : 1; /* [23] */ - __IO uint32_t octesel_l : 4; /* [27:24] */ - __IO uint32_t ocete : 2; /* [29:28] */ - __IO uint32_t ocswtrg : 1; /* [30] */ - __IO uint32_t octesel_h : 1; /* [31] */ - } ctrl2_bit; - }; + union { + __IO uint32_t pcdto1; + struct { + __IO uint32_t pcdto1 : 12; /* [11:0] */ + __IO uint32_t reserved1 : 20; /* [31:12] */ + } pcdto1_bit; + }; - /** - * @brief adc spt1 register, offset:0x0C - */ - union - { - __IO uint32_t spt1; - struct - { - __IO uint32_t cspt10 : 3; /* [2:0] */ - __IO uint32_t cspt11 : 3; /* [5:3] */ - __IO uint32_t cspt12 : 3; /* [8:6] */ - __IO uint32_t cspt13 : 3; /* [11:9] */ - __IO uint32_t cspt14 : 3; /* [14:12] */ - __IO uint32_t cspt15 : 3; /* [17:15] */ - __IO uint32_t cspt16 : 3; /* [20:18] */ - __IO uint32_t cspt17 : 3; /* [23:21] */ - __IO uint32_t cspt18 : 3; /* [26:24] */ - __IO uint32_t reserved1 : 5;/* [31:27] */ - } spt1_bit; - }; + /** + * @brief adc pcdto2 register, offset:0x18 + */ + union { + __IO uint32_t pcdto2; + struct { + __IO uint32_t pcdto2 : 12; /* [11:0] */ + __IO uint32_t reserved1 : 20; /* [31:12] */ + } pcdto2_bit; + }; - /** - * @brief adc spt2 register, offset:0x10 - */ - union - { - __IO uint32_t spt2; - struct - { - __IO uint32_t cspt0 : 3;/* [2:0] */ - __IO uint32_t cspt1 : 3;/* [5:3] */ - __IO uint32_t cspt2 : 3;/* [8:6] */ - __IO uint32_t cspt3 : 3;/* [11:9] */ - __IO uint32_t cspt4 : 3;/* [14:12] */ - __IO uint32_t cspt5 : 3;/* [17:15] */ - __IO uint32_t cspt6 : 3;/* [20:18] */ - __IO uint32_t cspt7 : 3;/* [23:21] */ - __IO uint32_t cspt8 : 3;/* [26:24] */ - __IO uint32_t cspt9 : 3;/* [29:27] */ - __IO uint32_t reserved1 : 2;/* [31:30] */ - } spt2_bit; - }; + /** + * @brief adc pcdto3 register, offset:0x1C + */ + union { + __IO uint32_t pcdto3; + struct { + __IO uint32_t pcdto3 : 12; /* [11:0] */ + __IO uint32_t reserved1 : 20; /* [31:12] */ + } pcdto3_bit; + }; - /** - * @brief adc pcdto1 register, offset:0x14 - */ - union - { - __IO uint32_t pcdto1; - struct - { - __IO uint32_t pcdto1 : 12; /* [11:0] */ - __IO uint32_t reserved1 : 20; /* [31:12] */ - } pcdto1_bit; - }; + /** + * @brief adc pcdto4 register, offset:0x20 + */ + union { + __IO uint32_t pcdto4; + struct { + __IO uint32_t pcdto4 : 12; /* [11:0] */ + __IO uint32_t reserved1 : 20; /* [31:12] */ + } pcdto4_bit; + }; - /** - * @brief adc pcdto2 register, offset:0x18 - */ - union - { - __IO uint32_t pcdto2; - struct - { - __IO uint32_t pcdto2 : 12; /* [11:0] */ - __IO uint32_t reserved1 : 20; /* [31:12] */ - } pcdto2_bit; - }; + /** + * @brief adc vmhb register, offset:0x24 + */ + union { + __IO uint32_t vmhb; + struct { + __IO uint32_t vmhb : 16; /* [15:0] */ + __IO uint32_t reserved1 : 16; /* [31:16] */ + } vmhb_bit; + }; - /** - * @brief adc pcdto3 register, offset:0x1C - */ - union - { - __IO uint32_t pcdto3; - struct - { - __IO uint32_t pcdto3 : 12; /* [11:0] */ - __IO uint32_t reserved1 : 20; /* [31:12] */ - } pcdto3_bit; - }; + /** + * @brief adc vmlb register, offset:0x28 + */ + union { + __IO uint32_t vmlb; + struct { + __IO uint32_t vmlb : 16; /* [15:0] */ + __IO uint32_t reserved1 : 16; /* [31:16] */ + } vmlb_bit; + }; - /** - * @brief adc pcdto4 register, offset:0x20 - */ - union - { - __IO uint32_t pcdto4; - struct - { - __IO uint32_t pcdto4 : 12; /* [11:0] */ - __IO uint32_t reserved1 : 20; /* [31:12] */ - } pcdto4_bit; - }; + /** + * @brief adc osq1 register, offset:0x2C + */ + union { + __IO uint32_t osq1; + struct { + __IO uint32_t osn13 : 5; /* [4:0] */ + __IO uint32_t osn14 : 5; /* [9:5] */ + __IO uint32_t osn15 : 5; /* [14:10] */ + __IO uint32_t osn16 : 5; /* [19:15] */ + __IO uint32_t oclen : 4; /* [23:20] */ + __IO uint32_t reserved1 : 8; /* [31:24] */ + } osq1_bit; + }; - /** - * @brief adc vmhb register, offset:0x24 - */ - union - { - __IO uint32_t vmhb; - struct - { - __IO uint32_t vmhb : 16; /* [15:0] */ - __IO uint32_t reserved1 : 16; /* [31:16] */ - } vmhb_bit; - }; + /** + * @brief adc osq2 register, offset:0x30 + */ + union { + __IO uint32_t osq2; + struct { + __IO uint32_t osn7 : 5; /* [4:0] */ + __IO uint32_t osn8 : 5; /* [9:5] */ + __IO uint32_t osn9 : 5; /* [14:10] */ + __IO uint32_t osn10 : 5; /* [19:15] */ + __IO uint32_t osn11 : 5; /* [24:20] */ + __IO uint32_t osn12 : 5; /* [29:25] */ + __IO uint32_t reserved1 : 2; /* [31:30] */ + } osq2_bit; + }; - /** - * @brief adc vmlb register, offset:0x28 - */ - union - { - __IO uint32_t vmlb; - struct - { - __IO uint32_t vmlb : 16; /* [15:0] */ - __IO uint32_t reserved1 : 16; /* [31:16] */ - } vmlb_bit; - }; + /** + * @brief adc osq3 register, offset:0x34 + */ + union { + __IO uint32_t osq3; + struct { + __IO uint32_t osn1 : 5; /* [4:0] */ + __IO uint32_t osn2 : 5; /* [9:5] */ + __IO uint32_t osn3 : 5; /* [14:10] */ + __IO uint32_t osn4 : 5; /* [19:15] */ + __IO uint32_t osn5 : 5; /* [24:20] */ + __IO uint32_t osn6 : 5; /* [29:25] */ + __IO uint32_t reserved1 : 2; /* [31:30] */ + } osq3_bit; + }; - /** - * @brief adc osq1 register, offset:0x2C - */ - union - { - __IO uint32_t osq1; - struct - { - __IO uint32_t osn13 : 5; /* [4:0] */ - __IO uint32_t osn14 : 5; /* [9:5] */ - __IO uint32_t osn15 : 5; /* [14:10] */ - __IO uint32_t osn16 : 5; /* [19:15] */ - __IO uint32_t oclen : 4; /* [23:20] */ - __IO uint32_t reserved1 : 8; /* [31:24] */ - } osq1_bit; - }; + /** + * @brief adc psq register, offset:0x38 + */ + union { + __IO uint32_t psq; + struct { + __IO uint32_t psn1 : 5; /* [4:0] */ + __IO uint32_t psn2 : 5; /* [9:5] */ + __IO uint32_t psn3 : 5; /* [14:10] */ + __IO uint32_t psn4 : 5; /* [19:15] */ + __IO uint32_t pclen : 2; /* [21:20] */ + __IO uint32_t reserved1 : 10;/* [31:22] */ + } psq_bit; + }; - /** - * @brief adc osq2 register, offset:0x30 - */ - union - { - __IO uint32_t osq2; - struct - { - __IO uint32_t osn7 : 5; /* [4:0] */ - __IO uint32_t osn8 : 5; /* [9:5] */ - __IO uint32_t osn9 : 5; /* [14:10] */ - __IO uint32_t osn10 : 5; /* [19:15] */ - __IO uint32_t osn11 : 5; /* [24:20] */ - __IO uint32_t osn12 : 5; /* [29:25] */ - __IO uint32_t reserved1 : 2; /* [31:30] */ - } osq2_bit; - }; + /** + * @brief adc pdt1 register, offset:0x3C + */ + union { + __IO uint32_t pdt1; + struct { + __IO uint32_t pdt1 : 16; /* [15:0] */ + __IO uint32_t reserved1 : 16; /* [31:16] */ + } pdt1_bit; + }; - /** - * @brief adc osq3 register, offset:0x34 - */ - union - { - __IO uint32_t osq3; - struct - { - __IO uint32_t osn1 : 5; /* [4:0] */ - __IO uint32_t osn2 : 5; /* [9:5] */ - __IO uint32_t osn3 : 5; /* [14:10] */ - __IO uint32_t osn4 : 5; /* [19:15] */ - __IO uint32_t osn5 : 5; /* [24:20] */ - __IO uint32_t osn6 : 5; /* [29:25] */ - __IO uint32_t reserved1 : 2; /* [31:30] */ - } osq3_bit; - }; + /** + * @brief adc pdt2 register, offset:0x40 + */ + union { + __IO uint32_t pdt2; + struct { + __IO uint32_t pdt2 : 16; /* [15:0] */ + __IO uint32_t reserved1 : 16; /* [31:16] */ + } pdt2_bit; + }; - /** - * @brief adc psq register, offset:0x38 - */ - union - { - __IO uint32_t psq; - struct - { - __IO uint32_t psn1 : 5; /* [4:0] */ - __IO uint32_t psn2 : 5; /* [9:5] */ - __IO uint32_t psn3 : 5; /* [14:10] */ - __IO uint32_t psn4 : 5; /* [19:15] */ - __IO uint32_t pclen : 2; /* [21:20] */ - __IO uint32_t reserved1 : 10;/* [31:22] */ - } psq_bit; - }; + /** + * @brief adc pdt3 register, offset:0x44 + */ + union { + __IO uint32_t pdt3; + struct { + __IO uint32_t pdt3 : 16; /* [15:0] */ + __IO uint32_t reserved1 : 16; /* [31:16] */ + } pdt3_bit; + }; - /** - * @brief adc pdt1 register, offset:0x3C - */ - union - { - __IO uint32_t pdt1; - struct - { - __IO uint32_t pdt1 : 16; /* [15:0] */ - __IO uint32_t reserved1 : 16; /* [31:16] */ - } pdt1_bit; - }; + /** + * @brief adc pdt4 register, offset:0x48 + */ + union { + __IO uint32_t pdt4; + struct { + __IO uint32_t pdt4 : 16; /* [15:0] */ + __IO uint32_t reserved1 : 16; /* [31:16] */ + } pdt4_bit; + }; - /** - * @brief adc pdt2 register, offset:0x40 - */ - union - { - __IO uint32_t pdt2; - struct - { - __IO uint32_t pdt2 : 16; /* [15:0] */ - __IO uint32_t reserved1 : 16; /* [31:16] */ - } pdt2_bit; - }; + /** + * @brief adc odt register, offset:0x4C + */ + union { + __IO uint32_t odt; + struct { + __IO uint32_t odt : 16; /* [15:0] */ + __IO uint32_t reserved1 : 16; /* [31:16] */ + } odt_bit; + }; - /** - * @brief adc pdt3 register, offset:0x44 - */ - union - { - __IO uint32_t pdt3; - struct - { - __IO uint32_t pdt3 : 16; /* [15:0] */ - __IO uint32_t reserved1 : 16; /* [31:16] */ - } pdt3_bit; - }; + __IO uint32_t reserved1[12]; - /** - * @brief adc pdt4 register, offset:0x48 - */ - union - { - __IO uint32_t pdt4; - struct - { - __IO uint32_t pdt4 : 16; /* [15:0] */ - __IO uint32_t reserved1 : 16; /* [31:16] */ - } pdt4_bit; - }; + /** + * @brief adc ovsp register, offset:0x80 + */ + union { + __IO uint32_t ovsp; + struct { + __IO uint32_t oosen : 1; /* [0] */ + __IO uint32_t posen : 1; /* [1] */ + __IO uint32_t osrsel : 3; /* [4:2] */ + __IO uint32_t osssel : 4; /* [8:5] */ + __IO uint32_t oostren : 1; /* [9] */ + __IO uint32_t oosrsel : 1; /* [10] */ + __IO uint32_t reserved1 : 21; /* [31:11] */ + } ovsp_bit; + }; - /** - * @brief adc odt register, offset:0x4C - */ - union - { - __IO uint32_t odt; - struct - { - __IO uint32_t odt : 16; /* [15:0] */ - __IO uint32_t reserved1 : 16; /* [31:16] */ - } odt_bit; - }; + __IO uint32_t reserved2[12]; - __IO uint32_t reserved1[12]; - - /** - * @brief adc ovsp register, offset:0x80 - */ - union - { - __IO uint32_t ovsp; - struct - { - __IO uint32_t oosen : 1; /* [0] */ - __IO uint32_t posen : 1; /* [1] */ - __IO uint32_t osrsel : 3; /* [4:2] */ - __IO uint32_t osssel : 4; /* [8:5] */ - __IO uint32_t oostren : 1; /* [9] */ - __IO uint32_t oosrsel : 1; /* [10] */ - __IO uint32_t reserved1 : 21; /* [31:11] */ - } ovsp_bit; - }; - - __IO uint32_t reserved2[12]; - - /** - * @brief adc calval register, offset:0xB4 - */ - union - { - __IO uint32_t calval; - struct - { - __IO uint32_t calval : 7; /* [6:0] */ - __IO uint32_t reserved1 : 25; /* [31:7] */ - } calval_bit; - }; + /** + * @brief adc calval register, offset:0xB4 + */ + union { + __IO uint32_t calval; + struct { + __IO uint32_t calval : 7; /* [6:0] */ + __IO uint32_t reserved1 : 25; /* [31:7] */ + } calval_bit; + }; } adc_type; /** * @brief type define adc register all */ -typedef struct -{ +typedef struct { - /** - * @brief adc csts register, offset:0x00 + /** + * @brief adc csts register, offset:0x00 + */ + union { + __IO uint32_t csts; + struct { + __IO uint32_t vmor1 : 1; /* [0] */ + __IO uint32_t occe1 : 1; /* [1] */ + __IO uint32_t pcce1 : 1; /* [2] */ + __IO uint32_t pccs1 : 1; /* [3] */ + __IO uint32_t occs1 : 1; /* [4] */ + __IO uint32_t occo1 : 1; /* [5] */ + __IO uint32_t rdy1 : 1; /* [6] */ + __IO uint32_t reserved1 : 1; /* [7] */ + __IO uint32_t vmor2 : 1; /* [8] */ + __IO uint32_t occe2 : 1; /* [9] */ + __IO uint32_t pcce2 : 1; /* [10] */ + __IO uint32_t pccs2 : 1; /* [11] */ + __IO uint32_t occs2 : 1; /* [12] */ + __IO uint32_t occo2 : 1; /* [13] */ + __IO uint32_t rdy2 : 1; /* [14] */ + __IO uint32_t reserved2 : 1; /* [15] */ + __IO uint32_t vmor3 : 1; /* [16] */ + __IO uint32_t occe3 : 1; /* [17] */ + __IO uint32_t pcce3 : 1; /* [18] */ + __IO uint32_t pccs3 : 1; /* [19] */ + __IO uint32_t occs3 : 1; /* [20] */ + __IO uint32_t occo3 : 1; /* [21] */ + __IO uint32_t rdy3 : 1; /* [22] */ + __IO uint32_t reserved3 : 9; /* [31:23] */ + } csts_bit; + }; + + /** + * @brief adc cctrl register, offset:0x04 + */ + union { + __IO uint32_t cctrl; + struct { + __IO uint32_t mssel : 5; /* [4_0] */ + __IO uint32_t reserved1 : 3; /* [7:5] */ + __IO uint32_t asisel : 4; /* [11:8] */ + __IO uint32_t reserved2 : 1; /* [12] */ + __IO uint32_t msdrcen : 1; /* [13] */ + __IO uint32_t msdmasel_l : 2; /* [15:14] */ + __IO uint32_t adcdiv : 4; /* [19:16] */ + __IO uint32_t reserved3 : 2; /* [21:20] */ + __IO uint32_t vbaten : 1; /* [22] */ + __IO uint32_t itsrven : 1; /* [23] */ + __IO uint32_t reserved4 : 4; /* [27:24] */ + __IO uint32_t msdmasel_h : 1; /* [28] */ + __IO uint32_t reserved5 : 3; /* [31:29] */ + } cctrl_bit; + }; + + /** + * @brief adc codt register, offset:0x08 */ - union - { - __IO uint32_t csts; - struct - { - __IO uint32_t vmor1 : 1; /* [0] */ - __IO uint32_t occe1 : 1; /* [1] */ - __IO uint32_t pcce1 : 1; /* [2] */ - __IO uint32_t pccs1 : 1; /* [3] */ - __IO uint32_t occs1 : 1; /* [4] */ - __IO uint32_t occo1 : 1; /* [5] */ - __IO uint32_t rdy1 : 1; /* [6] */ - __IO uint32_t reserved1 : 1; /* [7] */ - __IO uint32_t vmor2 : 1; /* [8] */ - __IO uint32_t occe2 : 1; /* [9] */ - __IO uint32_t pcce2 : 1; /* [10] */ - __IO uint32_t pccs2 : 1; /* [11] */ - __IO uint32_t occs2 : 1; /* [12] */ - __IO uint32_t occo2 : 1; /* [13] */ - __IO uint32_t rdy2 : 1; /* [14] */ - __IO uint32_t reserved2 : 1; /* [15] */ - __IO uint32_t vmor3 : 1; /* [16] */ - __IO uint32_t occe3 : 1; /* [17] */ - __IO uint32_t pcce3 : 1; /* [18] */ - __IO uint32_t pccs3 : 1; /* [19] */ - __IO uint32_t occs3 : 1; /* [20] */ - __IO uint32_t occo3 : 1; /* [21] */ - __IO uint32_t rdy3 : 1; /* [22] */ - __IO uint32_t reserved3 : 9; /* [31:23] */ - } csts_bit; - }; - - /** - * @brief adc cctrl register, offset:0x04 - */ - union - { - __IO uint32_t cctrl; - struct - { - __IO uint32_t mssel : 5; /* [4_0] */ - __IO uint32_t reserved1 : 3; /* [7:5] */ - __IO uint32_t asisel : 4; /* [11:8] */ - __IO uint32_t reserved2 : 1; /* [12] */ - __IO uint32_t msdrcen : 1; /* [13] */ - __IO uint32_t msdmasel_l : 2; /* [15:14] */ - __IO uint32_t adcdiv : 4; /* [19:16] */ - __IO uint32_t reserved3 : 2; /* [21:20] */ - __IO uint32_t vbaten : 1; /* [22] */ - __IO uint32_t itsrven : 1; /* [23] */ - __IO uint32_t reserved4 : 4; /* [27:24] */ - __IO uint32_t msdmasel_h : 1; /* [28] */ - __IO uint32_t reserved5 : 3; /* [31:29] */ - } cctrl_bit; - }; - - /** - * @brief adc codt register, offset:0x08 - */ - union - { - __IO uint32_t codt; - struct - { - __IO uint32_t codtl : 16; /* [15:0] */ - __IO uint32_t codth : 16; /* [31:16] */ - } codt_bit; - }; + union { + __IO uint32_t codt; + struct { + __IO uint32_t codtl : 16; /* [15:0] */ + __IO uint32_t codth : 16; /* [31:16] */ + } codt_bit; + }; } adccom_type; /** diff --git a/armlib/at32_sys/drivers/inc/at32f435_437_can.h b/armlib/at32_sys/drivers/inc/at32f435_437_can.h index 3dd901138..3ff4707cf 100644 --- a/armlib/at32_sys/drivers/inc/at32f435_437_can.h +++ b/armlib/at32_sys/drivers/inc/at32f435_437_can.h @@ -131,290 +131,267 @@ extern "C" { /** * @brief can filter fifo */ -typedef enum -{ - CAN_FILTER_FIFO0 = 0x00, /*!< filter fifo 0 assignment for filter x */ - CAN_FILTER_FIFO1 = 0x01 /*!< filter fifo 1 assignment for filter x */ +typedef enum { + CAN_FILTER_FIFO0 = 0x00, /*!< filter fifo 0 assignment for filter x */ + CAN_FILTER_FIFO1 = 0x01 /*!< filter fifo 1 assignment for filter x */ } can_filter_fifo_type; /** * @brief can filter mode */ -typedef enum -{ - CAN_FILTER_MODE_ID_MASK = 0x00, /*!< identifier mask mode */ - CAN_FILTER_MODE_ID_LIST = 0x01 /*!< identifier list mode */ +typedef enum { + CAN_FILTER_MODE_ID_MASK = 0x00, /*!< identifier mask mode */ + CAN_FILTER_MODE_ID_LIST = 0x01 /*!< identifier list mode */ } can_filter_mode_type; /** * @brief can filter bit width select */ -typedef enum -{ - CAN_FILTER_16BIT = 0x00, /*!< two 16-bit filters */ - CAN_FILTER_32BIT = 0x01 /*!< one 32-bit filter */ +typedef enum { + CAN_FILTER_16BIT = 0x00, /*!< two 16-bit filters */ + CAN_FILTER_32BIT = 0x01 /*!< one 32-bit filter */ } can_filter_bit_width_type; /** * @brief can mode */ -typedef enum -{ - CAN_MODE_COMMUNICATE = 0x00, /*!< communication mode */ - CAN_MODE_LOOPBACK = 0x01, /*!< loopback mode */ - CAN_MODE_LISTENONLY = 0x02, /*!< listen-only mode */ - CAN_MODE_LISTENONLY_LOOPBACK = 0x03 /*!< loopback combined with listen-only mode */ +typedef enum { + CAN_MODE_COMMUNICATE = 0x00, /*!< communication mode */ + CAN_MODE_LOOPBACK = 0x01, /*!< loopback mode */ + CAN_MODE_LISTENONLY = 0x02, /*!< listen-only mode */ + CAN_MODE_LISTENONLY_LOOPBACK = 0x03 /*!< loopback combined with listen-only mode */ } can_mode_type; /** * @brief can operating mode */ -typedef enum -{ - CAN_OPERATINGMODE_FREEZE = 0x00, /*!< freeze mode */ - CAN_OPERATINGMODE_DOZE = 0x01, /*!< doze mode */ - CAN_OPERATINGMODE_COMMUNICATE = 0x02 /*!< communication mode */ +typedef enum { + CAN_OPERATINGMODE_FREEZE = 0x00, /*!< freeze mode */ + CAN_OPERATINGMODE_DOZE = 0x01, /*!< doze mode */ + CAN_OPERATINGMODE_COMMUNICATE = 0x02 /*!< communication mode */ } can_operating_mode_type; /** * @brief can resynchronization adjust width */ -typedef enum -{ - CAN_RSAW_1TQ = 0x00, /*!< 1 time quantum */ - CAN_RSAW_2TQ = 0x01, /*!< 2 time quantum */ - CAN_RSAW_3TQ = 0x02, /*!< 3 time quantum */ - CAN_RSAW_4TQ = 0x03 /*!< 4 time quantum */ +typedef enum { + CAN_RSAW_1TQ = 0x00, /*!< 1 time quantum */ + CAN_RSAW_2TQ = 0x01, /*!< 2 time quantum */ + CAN_RSAW_3TQ = 0x02, /*!< 3 time quantum */ + CAN_RSAW_4TQ = 0x03 /*!< 4 time quantum */ } can_rsaw_type; /** * @brief can bit time segment 1 */ -typedef enum -{ - CAN_BTS1_1TQ = 0x00, /*!< 1 time quantum */ - CAN_BTS1_2TQ = 0x01, /*!< 2 time quantum */ - CAN_BTS1_3TQ = 0x02, /*!< 3 time quantum */ - CAN_BTS1_4TQ = 0x03, /*!< 4 time quantum */ - CAN_BTS1_5TQ = 0x04, /*!< 5 time quantum */ - CAN_BTS1_6TQ = 0x05, /*!< 6 time quantum */ - CAN_BTS1_7TQ = 0x06, /*!< 7 time quantum */ - CAN_BTS1_8TQ = 0x07, /*!< 8 time quantum */ - CAN_BTS1_9TQ = 0x08, /*!< 9 time quantum */ - CAN_BTS1_10TQ = 0x09, /*!< 10 time quantum */ - CAN_BTS1_11TQ = 0x0A, /*!< 11 time quantum */ - CAN_BTS1_12TQ = 0x0B, /*!< 12 time quantum */ - CAN_BTS1_13TQ = 0x0C, /*!< 13 time quantum */ - CAN_BTS1_14TQ = 0x0D, /*!< 14 time quantum */ - CAN_BTS1_15TQ = 0x0E, /*!< 15 time quantum */ - CAN_BTS1_16TQ = 0x0F /*!< 16 time quantum */ +typedef enum { + CAN_BTS1_1TQ = 0x00, /*!< 1 time quantum */ + CAN_BTS1_2TQ = 0x01, /*!< 2 time quantum */ + CAN_BTS1_3TQ = 0x02, /*!< 3 time quantum */ + CAN_BTS1_4TQ = 0x03, /*!< 4 time quantum */ + CAN_BTS1_5TQ = 0x04, /*!< 5 time quantum */ + CAN_BTS1_6TQ = 0x05, /*!< 6 time quantum */ + CAN_BTS1_7TQ = 0x06, /*!< 7 time quantum */ + CAN_BTS1_8TQ = 0x07, /*!< 8 time quantum */ + CAN_BTS1_9TQ = 0x08, /*!< 9 time quantum */ + CAN_BTS1_10TQ = 0x09, /*!< 10 time quantum */ + CAN_BTS1_11TQ = 0x0A, /*!< 11 time quantum */ + CAN_BTS1_12TQ = 0x0B, /*!< 12 time quantum */ + CAN_BTS1_13TQ = 0x0C, /*!< 13 time quantum */ + CAN_BTS1_14TQ = 0x0D, /*!< 14 time quantum */ + CAN_BTS1_15TQ = 0x0E, /*!< 15 time quantum */ + CAN_BTS1_16TQ = 0x0F /*!< 16 time quantum */ } can_bts1_type; /** * @brief can bit time segment 2 */ -typedef enum -{ - CAN_BTS2_1TQ = 0x00, /*!< 1 time quantum */ - CAN_BTS2_2TQ = 0x01, /*!< 2 time quantum */ - CAN_BTS2_3TQ = 0x02, /*!< 3 time quantum */ - CAN_BTS2_4TQ = 0x03, /*!< 4 time quantum */ - CAN_BTS2_5TQ = 0x04, /*!< 5 time quantum */ - CAN_BTS2_6TQ = 0x05, /*!< 6 time quantum */ - CAN_BTS2_7TQ = 0x06, /*!< 7 time quantum */ - CAN_BTS2_8TQ = 0x07 /*!< 8 time quantum */ +typedef enum { + CAN_BTS2_1TQ = 0x00, /*!< 1 time quantum */ + CAN_BTS2_2TQ = 0x01, /*!< 2 time quantum */ + CAN_BTS2_3TQ = 0x02, /*!< 3 time quantum */ + CAN_BTS2_4TQ = 0x03, /*!< 4 time quantum */ + CAN_BTS2_5TQ = 0x04, /*!< 5 time quantum */ + CAN_BTS2_6TQ = 0x05, /*!< 6 time quantum */ + CAN_BTS2_7TQ = 0x06, /*!< 7 time quantum */ + CAN_BTS2_8TQ = 0x07 /*!< 8 time quantum */ } can_bts2_type; /** * @brief can identifier type */ -typedef enum -{ - CAN_ID_STANDARD = 0x00, /*!< standard Id */ - CAN_ID_EXTENDED = 0x01 /*!< extended Id */ +typedef enum { + CAN_ID_STANDARD = 0x00, /*!< standard Id */ + CAN_ID_EXTENDED = 0x01 /*!< extended Id */ } can_identifier_type; /** * @brief can transmission frame type */ -typedef enum -{ - CAN_TFT_DATA = 0x00, /*!< data frame */ - CAN_TFT_REMOTE = 0x01 /*!< remote frame */ +typedef enum { + CAN_TFT_DATA = 0x00, /*!< data frame */ + CAN_TFT_REMOTE = 0x01 /*!< remote frame */ } can_trans_frame_type; /** * @brief can tx mailboxes */ -typedef enum -{ - CAN_TX_MAILBOX0 = 0x00, /*!< can tx mailbox 0 */ - CAN_TX_MAILBOX1 = 0x01, /*!< can tx mailbox 1 */ - CAN_TX_MAILBOX2 = 0x02 /*!< can tx mailbox 2 */ +typedef enum { + CAN_TX_MAILBOX0 = 0x00, /*!< can tx mailbox 0 */ + CAN_TX_MAILBOX1 = 0x01, /*!< can tx mailbox 1 */ + CAN_TX_MAILBOX2 = 0x02 /*!< can tx mailbox 2 */ } can_tx_mailbox_num_type; /** * @brief can receive fifo */ -typedef enum -{ - CAN_RX_FIFO0 = 0x00, /*!< can fifo 0 used to receive */ - CAN_RX_FIFO1 = 0x01 /*!< can fifo 1 used to receive */ +typedef enum { + CAN_RX_FIFO0 = 0x00, /*!< can fifo 0 used to receive */ + CAN_RX_FIFO1 = 0x01 /*!< can fifo 1 used to receive */ } can_rx_fifo_num_type; /** * @brief can transmit status */ -typedef enum -{ - CAN_TX_STATUS_FAILED = 0x00, /*!< can transmission failed */ - CAN_TX_STATUS_SUCCESSFUL = 0x01, /*!< can transmission successful */ - CAN_TX_STATUS_PENDING = 0x02, /*!< can transmission pending */ - CAN_TX_STATUS_NO_EMPTY = 0x04 /*!< can transmission no empty mailbox */ +typedef enum { + CAN_TX_STATUS_FAILED = 0x00, /*!< can transmission failed */ + CAN_TX_STATUS_SUCCESSFUL = 0x01, /*!< can transmission successful */ + CAN_TX_STATUS_PENDING = 0x02, /*!< can transmission pending */ + CAN_TX_STATUS_NO_EMPTY = 0x04 /*!< can transmission no empty mailbox */ } can_transmit_status_type; /** * @brief can enter doze mode status */ -typedef enum -{ - CAN_ENTER_DOZE_FAILED = 0x00, /*!< can enter the doze mode failed */ - CAN_ENTER_DOZE_SUCCESSFUL = 0x01 /*!< can enter the doze mode successful */ +typedef enum { + CAN_ENTER_DOZE_FAILED = 0x00, /*!< can enter the doze mode failed */ + CAN_ENTER_DOZE_SUCCESSFUL = 0x01 /*!< can enter the doze mode successful */ } can_enter_doze_status_type; /** * @brief can quit doze mode status */ -typedef enum -{ - CAN_QUIT_DOZE_FAILED = 0x00, /*!< can quit doze mode failed */ - CAN_QUIT_DOZE_SUCCESSFUL = 0x01 /*!< can quit doze mode successful */ +typedef enum { + CAN_QUIT_DOZE_FAILED = 0x00, /*!< can quit doze mode failed */ + CAN_QUIT_DOZE_SUCCESSFUL = 0x01 /*!< can quit doze mode successful */ } can_quit_doze_status_type; /** * @brief can message discarding rule select when overflow */ -typedef enum -{ - CAN_DISCARDING_FIRST_RECEIVED = 0x00, /*!< can discarding the first received message */ - CAN_DISCARDING_LAST_RECEIVED = 0x01 /*!< can discarding the last received message */ +typedef enum { + CAN_DISCARDING_FIRST_RECEIVED = 0x00, /*!< can discarding the first received message */ + CAN_DISCARDING_LAST_RECEIVED = 0x01 /*!< can discarding the last received message */ } can_msg_discarding_rule_type; /** * @brief can multiple message sending sequence rule */ -typedef enum -{ - CAN_SENDING_BY_ID = 0x00, /*!< can sending the minimum id message first*/ - CAN_SENDING_BY_REQUEST = 0x01 /*!< can sending the first request message first */ +typedef enum { + CAN_SENDING_BY_ID = 0x00, /*!< can sending the minimum id message first*/ + CAN_SENDING_BY_REQUEST = 0x01 /*!< can sending the first request message first */ } can_msg_sending_rule_type; /** * @brief can error type record */ -typedef enum -{ - CAN_ERRORRECORD_NOERR = 0x00, /*!< no error */ - CAN_ERRORRECORD_STUFFERR = 0x01, /*!< stuff error */ - CAN_ERRORRECORD_FORMERR = 0x02, /*!< form error */ - CAN_ERRORRECORD_ACKERR = 0x03, /*!< acknowledgment error */ - CAN_ERRORRECORD_BITRECESSIVEERR = 0x04, /*!< bit recessive error */ - CAN_ERRORRECORD_BITDOMINANTERR = 0x05, /*!< bit dominant error */ - CAN_ERRORRECORD_CRCERR = 0x06, /*!< crc error */ - CAN_ERRORRECORD_SOFTWARESETERR = 0x07 /*!< software set error */ +typedef enum { + CAN_ERRORRECORD_NOERR = 0x00, /*!< no error */ + CAN_ERRORRECORD_STUFFERR = 0x01, /*!< stuff error */ + CAN_ERRORRECORD_FORMERR = 0x02, /*!< form error */ + CAN_ERRORRECORD_ACKERR = 0x03, /*!< acknowledgment error */ + CAN_ERRORRECORD_BITRECESSIVEERR = 0x04, /*!< bit recessive error */ + CAN_ERRORRECORD_BITDOMINANTERR = 0x05, /*!< bit dominant error */ + CAN_ERRORRECORD_CRCERR = 0x06, /*!< crc error */ + CAN_ERRORRECORD_SOFTWARESETERR = 0x07 /*!< software set error */ } can_error_record_type; /** * @brief can init structure definition */ -typedef struct -{ - can_mode_type mode_selection; /*!< specifies the can mode.*/ +typedef struct { + can_mode_type mode_selection; /*!< specifies the can mode.*/ - confirm_state ttc_enable; /*!< time triggered communication mode enable */ + confirm_state ttc_enable; /*!< time triggered communication mode enable */ - confirm_state aebo_enable; /*!< automatic exit bus-off enable */ + confirm_state aebo_enable; /*!< automatic exit bus-off enable */ - confirm_state aed_enable; /*!< automatic exit doze mode enable */ + confirm_state aed_enable; /*!< automatic exit doze mode enable */ - confirm_state prsf_enable; /*!< prohibit retransmission when sending fails enable */ + confirm_state prsf_enable; /*!< prohibit retransmission when sending fails enable */ - can_msg_discarding_rule_type mdrsel_selection; /*!< message discarding rule select when overflow */ + can_msg_discarding_rule_type mdrsel_selection; /*!< message discarding rule select when overflow */ - can_msg_sending_rule_type mmssr_selection; /*!< multiple message sending sequence rule */ + can_msg_sending_rule_type mmssr_selection; /*!< multiple message sending sequence rule */ } can_base_type; /** * @brief can baudrate structure definition */ -typedef struct -{ - uint16_t baudrate_div; /*!< baudrate division,this parameter can be 0x001~0x1000.*/ +typedef struct { + uint16_t baudrate_div; /*!< baudrate division,this parameter can be 0x001~0x1000.*/ - can_rsaw_type rsaw_size; /*!< resynchronization adjust width */ + can_rsaw_type rsaw_size; /*!< resynchronization adjust width */ - can_bts1_type bts1_size; /*!< bit time segment 1 */ + can_bts1_type bts1_size; /*!< bit time segment 1 */ - can_bts2_type bts2_size; /*!< bit time segment 2 */ + can_bts2_type bts2_size; /*!< bit time segment 2 */ } can_baudrate_type; /** * @brief can filter init structure definition */ -typedef struct -{ - confirm_state filter_activate_enable; /*!< enable or disable the filter activate.*/ +typedef struct { + confirm_state filter_activate_enable; /*!< enable or disable the filter activate.*/ - can_filter_mode_type filter_mode; /*!< config the filter mode mask or list.*/ + can_filter_mode_type filter_mode; /*!< config the filter mode mask or list.*/ - can_filter_fifo_type filter_fifo; /*!< config the fifo which will be assigned to the filter. */ + can_filter_fifo_type filter_fifo; /*!< config the fifo which will be assigned to the filter. */ - uint8_t filter_number; /*!< config the filter number, parameter ranges from 0 to 13. */ + uint8_t filter_number; /*!< config the filter number, parameter ranges from 0 to 13. */ - can_filter_bit_width_type filter_bit; /*!< config the filter bit width 16bit or 32bit.*/ + can_filter_bit_width_type filter_bit; /*!< config the filter bit width 16bit or 32bit.*/ - uint16_t filter_id_high; /*!< config the filter identification, for 32-bit configuration + uint16_t filter_id_high; /*!< config the filter identification, for 32-bit configuration it's high 16 bits, for 16-bit configuration it's first. */ - uint16_t filter_id_low; /*!< config the filter identification, for 32-bit configuration + uint16_t filter_id_low; /*!< config the filter identification, for 32-bit configuration it's low 16 bits, for 16-bit configuration it's second. */ - uint16_t filter_mask_high; /*!< config the filter mask or identification, according to the filtering mode, + uint16_t filter_mask_high; /*!< config the filter mask or identification, according to the filtering mode, for 32-bit configuration it's high 16 bits, for 16-bit configuration it's first. */ - uint16_t filter_mask_low; /*!< config the filter mask or identification, according to the filtering mode, + uint16_t filter_mask_low; /*!< config the filter mask or identification, according to the filtering mode, for 32-bit configuration it's low 16 bits, for 16-bit configuration it's second. */ } can_filter_init_type; /** * @brief can tx message structure definition */ -typedef struct -{ - uint32_t standard_id; /*!< specifies the 11 bits standard identifier. +typedef struct { + uint32_t standard_id; /*!< specifies the 11 bits standard identifier. this parameter can be a value between 0 to 0x7FF. */ - uint32_t extended_id; /*!< specifies the 29 bits extended identifier. + uint32_t extended_id; /*!< specifies the 29 bits extended identifier. this parameter can be a value between 0 to 0x1FFFFFFF. */ - can_identifier_type id_type; /*!< specifies identifier type for the transmit message.*/ + can_identifier_type id_type; /*!< specifies identifier type for the transmit message.*/ - can_trans_frame_type frame_type; /*!< specifies frame type for the transmit message.*/ + can_trans_frame_type frame_type; /*!< specifies frame type for the transmit message.*/ - uint8_t dlc; /*!< specifies frame data length that will be transmitted. + uint8_t dlc; /*!< specifies frame data length that will be transmitted. this parameter can be a value between 0 to 8 */ - uint8_t data[8]; /*!< contains the transmit data. it ranges from 0 to 0xFF. */ + uint8_t data[8]; /*!< contains the transmit data. it ranges from 0 to 0xFF. */ } can_tx_message_type; /** * @brief can rx message structure definition */ -typedef struct -{ +typedef struct { uint32_t standard_id; /*!< specifies the 11 bits standard identifier this parameter can be a value between 0 to 0x7FF. */ @@ -437,552 +414,506 @@ typedef struct /** * @brief can controller area network tx mailbox */ -typedef struct -{ - /** - * @brief can tmi register - */ - union - { - __IO uint32_t tmi; - struct - { - __IO uint32_t tmsr : 1; /* [0] */ - __IO uint32_t tmfrsel : 1; /* [1] */ - __IO uint32_t tmidsel : 1; /* [2] */ - __IO uint32_t tmeid : 18;/* [20:3] */ - __IO uint32_t tmsid : 11;/* [31:21] */ - } tmi_bit; - }; +typedef struct { + /** + * @brief can tmi register + */ + union { + __IO uint32_t tmi; + struct { + __IO uint32_t tmsr : 1; /* [0] */ + __IO uint32_t tmfrsel : 1; /* [1] */ + __IO uint32_t tmidsel : 1; /* [2] */ + __IO uint32_t tmeid : 18;/* [20:3] */ + __IO uint32_t tmsid : 11;/* [31:21] */ + } tmi_bit; + }; - /** - * @brief can tmc register - */ - union - { - __IO uint32_t tmc; - struct - { - __IO uint32_t tmdtbl : 4; /* [3:0] */ - __IO uint32_t reserved1 : 4; /* [7:4] */ - __IO uint32_t tmtsten : 1; /* [8] */ - __IO uint32_t reserved2 : 7; /* [15:9] */ - __IO uint32_t tmts : 16;/* [31:16] */ - } tmc_bit; - }; + /** + * @brief can tmc register + */ + union { + __IO uint32_t tmc; + struct { + __IO uint32_t tmdtbl : 4; /* [3:0] */ + __IO uint32_t reserved1 : 4; /* [7:4] */ + __IO uint32_t tmtsten : 1; /* [8] */ + __IO uint32_t reserved2 : 7; /* [15:9] */ + __IO uint32_t tmts : 16;/* [31:16] */ + } tmc_bit; + }; - /** - * @brief can tmdtl register - */ - union - { - __IO uint32_t tmdtl; - struct - { - __IO uint32_t tmdt0 : 8; /* [7:0] */ - __IO uint32_t tmdt1 : 8; /* [15:8] */ - __IO uint32_t tmdt2 : 8; /* [23:16] */ - __IO uint32_t tmdt3 : 8; /* [31:24] */ - } tmdtl_bit; - }; + /** + * @brief can tmdtl register + */ + union { + __IO uint32_t tmdtl; + struct { + __IO uint32_t tmdt0 : 8; /* [7:0] */ + __IO uint32_t tmdt1 : 8; /* [15:8] */ + __IO uint32_t tmdt2 : 8; /* [23:16] */ + __IO uint32_t tmdt3 : 8; /* [31:24] */ + } tmdtl_bit; + }; - /** - * @brief can tmdth register - */ - union - { - __IO uint32_t tmdth; - struct - { - __IO uint32_t tmdt4 : 8; /* [7:0] */ - __IO uint32_t tmdt5 : 8; /* [15:8] */ - __IO uint32_t tmdt6 : 8; /* [23:16] */ - __IO uint32_t tmdt7 : 8; /* [31:24] */ - } tmdth_bit; - }; + /** + * @brief can tmdth register + */ + union { + __IO uint32_t tmdth; + struct { + __IO uint32_t tmdt4 : 8; /* [7:0] */ + __IO uint32_t tmdt5 : 8; /* [15:8] */ + __IO uint32_t tmdt6 : 8; /* [23:16] */ + __IO uint32_t tmdt7 : 8; /* [31:24] */ + } tmdth_bit; + }; } can_tx_mailbox_type; /** * @brief can controller area network fifo mailbox */ -typedef struct -{ - /** - * @brief can rfi register - */ - union - { - __IO uint32_t rfi; - struct - { - __IO uint32_t reserved1 : 1; /* [0] */ - __IO uint32_t rffri : 1; /* [1] */ - __IO uint32_t rfidi : 1; /* [2] */ - __IO uint32_t rfeid : 18;/* [20:3] */ - __IO uint32_t rfsid : 11;/* [31:21] */ - } rfi_bit; - }; +typedef struct { + /** + * @brief can rfi register + */ + union { + __IO uint32_t rfi; + struct { + __IO uint32_t reserved1 : 1; /* [0] */ + __IO uint32_t rffri : 1; /* [1] */ + __IO uint32_t rfidi : 1; /* [2] */ + __IO uint32_t rfeid : 18;/* [20:3] */ + __IO uint32_t rfsid : 11;/* [31:21] */ + } rfi_bit; + }; - /** - * @brief can rfc register - */ - union - { - __IO uint32_t rfc; - struct - { - __IO uint32_t rfdtl : 4; /* [3:0] */ - __IO uint32_t reserved1 : 4; /* [7:4] */ - __IO uint32_t rffmn : 8; /* [15:8] */ - __IO uint32_t rfts : 16;/* [31:16] */ - } rfc_bit; - }; + /** + * @brief can rfc register + */ + union { + __IO uint32_t rfc; + struct { + __IO uint32_t rfdtl : 4; /* [3:0] */ + __IO uint32_t reserved1 : 4; /* [7:4] */ + __IO uint32_t rffmn : 8; /* [15:8] */ + __IO uint32_t rfts : 16;/* [31:16] */ + } rfc_bit; + }; - /** - * @brief can rfdtl register - */ - union - { - __IO uint32_t rfdtl; - struct - { - __IO uint32_t rfdt0 : 8; /* [7:0] */ - __IO uint32_t rfdt1 : 8; /* [15:8] */ - __IO uint32_t rfdt2 : 8; /* [23:16] */ - __IO uint32_t rfdt3 : 8; /* [31:24] */ - } rfdtl_bit; - }; + /** + * @brief can rfdtl register + */ + union { + __IO uint32_t rfdtl; + struct { + __IO uint32_t rfdt0 : 8; /* [7:0] */ + __IO uint32_t rfdt1 : 8; /* [15:8] */ + __IO uint32_t rfdt2 : 8; /* [23:16] */ + __IO uint32_t rfdt3 : 8; /* [31:24] */ + } rfdtl_bit; + }; - /** - * @brief can rfdth register - */ - union - { - __IO uint32_t rfdth; - struct - { - __IO uint32_t rfdt4 : 8; /* [7:0] */ - __IO uint32_t rfdt5 : 8; /* [15:8] */ - __IO uint32_t rfdt6 : 8; /* [23:16] */ - __IO uint32_t rfdt7 : 8; /* [31:24] */ - } rfdth_bit; - }; + /** + * @brief can rfdth register + */ + union { + __IO uint32_t rfdth; + struct { + __IO uint32_t rfdt4 : 8; /* [7:0] */ + __IO uint32_t rfdt5 : 8; /* [15:8] */ + __IO uint32_t rfdt6 : 8; /* [23:16] */ + __IO uint32_t rfdt7 : 8; /* [31:24] */ + } rfdth_bit; + }; } can_fifo_mailbox_type; /** * @brief can controller area network filter bit register */ -typedef struct -{ - __IO uint32_t ffdb1; - __IO uint32_t ffdb2; +typedef struct { + __IO uint32_t ffdb1; + __IO uint32_t ffdb2; } can_filter_register_type; /** * @brief type define can register all */ -typedef struct -{ +typedef struct { - /** - * @brief can mctrl register, offset:0x00 - */ - union - { - __IO uint32_t mctrl; - struct - { - __IO uint32_t fzen : 1; /* [0] */ - __IO uint32_t dzen : 1; /* [1] */ - __IO uint32_t mmssr : 1; /* [2] */ - __IO uint32_t mdrsel : 1; /* [3] */ - __IO uint32_t prsfen : 1; /* [4] */ - __IO uint32_t aeden : 1; /* [5] */ - __IO uint32_t aeboen : 1; /* [6] */ - __IO uint32_t ttcen : 1; /* [7] */ - __IO uint32_t reserved1 : 7; /* [14:8] */ - __IO uint32_t sprst : 1; /* [15] */ - __IO uint32_t ptd : 1; /* [16] */ - __IO uint32_t reserved2 : 15;/*[31:17] */ - } mctrl_bit; - }; + /** + * @brief can mctrl register, offset:0x00 + */ + union { + __IO uint32_t mctrl; + struct { + __IO uint32_t fzen : 1; /* [0] */ + __IO uint32_t dzen : 1; /* [1] */ + __IO uint32_t mmssr : 1; /* [2] */ + __IO uint32_t mdrsel : 1; /* [3] */ + __IO uint32_t prsfen : 1; /* [4] */ + __IO uint32_t aeden : 1; /* [5] */ + __IO uint32_t aeboen : 1; /* [6] */ + __IO uint32_t ttcen : 1; /* [7] */ + __IO uint32_t reserved1 : 7; /* [14:8] */ + __IO uint32_t sprst : 1; /* [15] */ + __IO uint32_t ptd : 1; /* [16] */ + __IO uint32_t reserved2 : 15;/*[31:17] */ + } mctrl_bit; + }; - /** - * @brief can msts register, offset:0x04 - */ - union - { - __IO uint32_t msts; - struct - { - __IO uint32_t fzc : 1; /* [0] */ - __IO uint32_t dzc : 1; /* [1] */ - __IO uint32_t eoif : 1; /* [2] */ - __IO uint32_t qdzif : 1; /* [3] */ - __IO uint32_t edzif : 1; /* [4] */ - __IO uint32_t reserved1 : 3; /* [7:5] */ - __IO uint32_t cuss : 1; /* [8] */ - __IO uint32_t curs : 1; /* [9] */ - __IO uint32_t lsamprx : 1; /* [10] */ - __IO uint32_t realrx : 1; /* [11] */ - __IO uint32_t reserved2 : 20;/*[31:12] */ - } msts_bit; - }; + /** + * @brief can msts register, offset:0x04 + */ + union { + __IO uint32_t msts; + struct { + __IO uint32_t fzc : 1; /* [0] */ + __IO uint32_t dzc : 1; /* [1] */ + __IO uint32_t eoif : 1; /* [2] */ + __IO uint32_t qdzif : 1; /* [3] */ + __IO uint32_t edzif : 1; /* [4] */ + __IO uint32_t reserved1 : 3; /* [7:5] */ + __IO uint32_t cuss : 1; /* [8] */ + __IO uint32_t curs : 1; /* [9] */ + __IO uint32_t lsamprx : 1; /* [10] */ + __IO uint32_t realrx : 1; /* [11] */ + __IO uint32_t reserved2 : 20;/*[31:12] */ + } msts_bit; + }; - /** - * @brief can tsts register, offset:0x08 - */ - union - { - __IO uint32_t tsts; - struct - { - __IO uint32_t tm0tcf : 1; /* [0] */ - __IO uint32_t tm0tsf : 1; /* [1] */ - __IO uint32_t tm0alf : 1; /* [2] */ - __IO uint32_t tm0tef : 1; /* [3] */ - __IO uint32_t reserved1 : 3; /* [6:4] */ - __IO uint32_t tm0ct : 1; /* [7] */ - __IO uint32_t tm1tcf : 1; /* [8] */ - __IO uint32_t tm1tsf : 1; /* [9] */ - __IO uint32_t tm1alf : 1; /* [10] */ - __IO uint32_t tm1tef : 1; /* [11] */ - __IO uint32_t reserved2 : 3; /* [14:12] */ - __IO uint32_t tm1ct : 1; /* [15] */ - __IO uint32_t tm2tcf : 1; /* [16] */ - __IO uint32_t tm2tsf : 1; /* [17] */ - __IO uint32_t tm2alf : 1; /* [18] */ - __IO uint32_t tm2tef : 1; /* [19] */ - __IO uint32_t reserved3 : 3; /* [22:20] */ - __IO uint32_t tm2ct : 1; /* [23] */ - __IO uint32_t tmnr : 2; /* [25:24] */ - __IO uint32_t tm0ef : 1; /* [26] */ - __IO uint32_t tm1ef : 1; /* [27] */ - __IO uint32_t tm2ef : 1; /* [28] */ - __IO uint32_t tm0lpf : 1; /* [29] */ - __IO uint32_t tm1lpf : 1; /* [30] */ - __IO uint32_t tm2lpf : 1; /* [31] */ - } tsts_bit; - }; + /** + * @brief can tsts register, offset:0x08 + */ + union { + __IO uint32_t tsts; + struct { + __IO uint32_t tm0tcf : 1; /* [0] */ + __IO uint32_t tm0tsf : 1; /* [1] */ + __IO uint32_t tm0alf : 1; /* [2] */ + __IO uint32_t tm0tef : 1; /* [3] */ + __IO uint32_t reserved1 : 3; /* [6:4] */ + __IO uint32_t tm0ct : 1; /* [7] */ + __IO uint32_t tm1tcf : 1; /* [8] */ + __IO uint32_t tm1tsf : 1; /* [9] */ + __IO uint32_t tm1alf : 1; /* [10] */ + __IO uint32_t tm1tef : 1; /* [11] */ + __IO uint32_t reserved2 : 3; /* [14:12] */ + __IO uint32_t tm1ct : 1; /* [15] */ + __IO uint32_t tm2tcf : 1; /* [16] */ + __IO uint32_t tm2tsf : 1; /* [17] */ + __IO uint32_t tm2alf : 1; /* [18] */ + __IO uint32_t tm2tef : 1; /* [19] */ + __IO uint32_t reserved3 : 3; /* [22:20] */ + __IO uint32_t tm2ct : 1; /* [23] */ + __IO uint32_t tmnr : 2; /* [25:24] */ + __IO uint32_t tm0ef : 1; /* [26] */ + __IO uint32_t tm1ef : 1; /* [27] */ + __IO uint32_t tm2ef : 1; /* [28] */ + __IO uint32_t tm0lpf : 1; /* [29] */ + __IO uint32_t tm1lpf : 1; /* [30] */ + __IO uint32_t tm2lpf : 1; /* [31] */ + } tsts_bit; + }; - /** - * @brief can rf0 register, offset:0x0C - */ - union - { - __IO uint32_t rf0; - struct - { - __IO uint32_t rf0mn : 2; /* [1:0] */ - __IO uint32_t reserved1 : 1; /* [2] */ - __IO uint32_t rf0ff : 1; /* [3] */ - __IO uint32_t rf0of : 1; /* [4] */ - __IO uint32_t rf0r : 1; /* [5] */ - __IO uint32_t reserved2 : 26;/* [31:6] */ - } rf0_bit; - }; + /** + * @brief can rf0 register, offset:0x0C + */ + union { + __IO uint32_t rf0; + struct { + __IO uint32_t rf0mn : 2; /* [1:0] */ + __IO uint32_t reserved1 : 1; /* [2] */ + __IO uint32_t rf0ff : 1; /* [3] */ + __IO uint32_t rf0of : 1; /* [4] */ + __IO uint32_t rf0r : 1; /* [5] */ + __IO uint32_t reserved2 : 26;/* [31:6] */ + } rf0_bit; + }; - /** - * @brief can rf1 register, offset:0x10 - */ - union - { - __IO uint32_t rf1; - struct - { - __IO uint32_t rf1mn : 2; /* [1:0] */ - __IO uint32_t reserved1 : 1; /* [2] */ - __IO uint32_t rf1ff : 1; /* [3] */ - __IO uint32_t rf1of : 1; /* [4] */ - __IO uint32_t rf1r : 1; /* [5] */ - __IO uint32_t reserved2 : 26;/* [31:6] */ - } rf1_bit; - }; + /** + * @brief can rf1 register, offset:0x10 + */ + union { + __IO uint32_t rf1; + struct { + __IO uint32_t rf1mn : 2; /* [1:0] */ + __IO uint32_t reserved1 : 1; /* [2] */ + __IO uint32_t rf1ff : 1; /* [3] */ + __IO uint32_t rf1of : 1; /* [4] */ + __IO uint32_t rf1r : 1; /* [5] */ + __IO uint32_t reserved2 : 26;/* [31:6] */ + } rf1_bit; + }; - /** - * @brief can inten register, offset:0x14 - */ - union - { - __IO uint32_t inten; - struct - { - __IO uint32_t tcien : 1; /* [0] */ - __IO uint32_t rf0mien : 1; /* [1] */ - __IO uint32_t rf0fien : 1; /* [2] */ - __IO uint32_t rf0oien : 1; /* [3] */ - __IO uint32_t rf1mien : 1; /* [4] */ - __IO uint32_t rf1fien : 1; /* [5] */ - __IO uint32_t rf1oien : 1; /* [6] */ - __IO uint32_t reserved1 : 1; /* [7] */ - __IO uint32_t eaien : 1; /* [8] */ - __IO uint32_t epien : 1; /* [9] */ - __IO uint32_t boien : 1; /* [10] */ - __IO uint32_t etrien : 1; /* [11] */ - __IO uint32_t reserved2 : 3; /* [14:12] */ - __IO uint32_t eoien : 1; /* [15] */ - __IO uint32_t qdzien : 1; /* [16] */ - __IO uint32_t edzien : 1; /* [17] */ - __IO uint32_t reserved3 : 14;/* [31:18] */ - } inten_bit; - }; + /** + * @brief can inten register, offset:0x14 + */ + union { + __IO uint32_t inten; + struct { + __IO uint32_t tcien : 1; /* [0] */ + __IO uint32_t rf0mien : 1; /* [1] */ + __IO uint32_t rf0fien : 1; /* [2] */ + __IO uint32_t rf0oien : 1; /* [3] */ + __IO uint32_t rf1mien : 1; /* [4] */ + __IO uint32_t rf1fien : 1; /* [5] */ + __IO uint32_t rf1oien : 1; /* [6] */ + __IO uint32_t reserved1 : 1; /* [7] */ + __IO uint32_t eaien : 1; /* [8] */ + __IO uint32_t epien : 1; /* [9] */ + __IO uint32_t boien : 1; /* [10] */ + __IO uint32_t etrien : 1; /* [11] */ + __IO uint32_t reserved2 : 3; /* [14:12] */ + __IO uint32_t eoien : 1; /* [15] */ + __IO uint32_t qdzien : 1; /* [16] */ + __IO uint32_t edzien : 1; /* [17] */ + __IO uint32_t reserved3 : 14;/* [31:18] */ + } inten_bit; + }; - /** - * @brief can ests register, offset:0x18 - */ - union - { - __IO uint32_t ests; - struct - { - __IO uint32_t eaf : 1; /* [0] */ - __IO uint32_t epf : 1; /* [1] */ - __IO uint32_t bof : 1; /* [2] */ - __IO uint32_t reserved1 : 1; /* [3] */ - __IO uint32_t etr : 3; /* [6:4] */ - __IO uint32_t reserved2 : 9; /* [15:7] */ - __IO uint32_t tec : 8; /* [23:16] */ - __IO uint32_t rec : 8; /* [31:24] */ - } ests_bit; - }; + /** + * @brief can ests register, offset:0x18 + */ + union { + __IO uint32_t ests; + struct { + __IO uint32_t eaf : 1; /* [0] */ + __IO uint32_t epf : 1; /* [1] */ + __IO uint32_t bof : 1; /* [2] */ + __IO uint32_t reserved1 : 1; /* [3] */ + __IO uint32_t etr : 3; /* [6:4] */ + __IO uint32_t reserved2 : 9; /* [15:7] */ + __IO uint32_t tec : 8; /* [23:16] */ + __IO uint32_t rec : 8; /* [31:24] */ + } ests_bit; + }; - /** - * @brief can btmg register, offset:0x1C - */ - union - { - __IO uint32_t btmg; - struct - { - __IO uint32_t brdiv : 12;/* [11:0] */ - __IO uint32_t reserved1 : 4; /* [15:12] */ - __IO uint32_t bts1 : 4; /* [19:16] */ - __IO uint32_t bts2 : 3; /* [22:20] */ - __IO uint32_t reserved2 : 1; /* [23] */ - __IO uint32_t rsaw : 2; /* [25:24] */ - __IO uint32_t reserved3 : 4; /* [29:26] */ - __IO uint32_t lben : 1; /* [30] */ - __IO uint32_t loen : 1; /* [31] */ - } btmg_bit; - }; + /** + * @brief can btmg register, offset:0x1C + */ + union { + __IO uint32_t btmg; + struct { + __IO uint32_t brdiv : 12;/* [11:0] */ + __IO uint32_t reserved1 : 4; /* [15:12] */ + __IO uint32_t bts1 : 4; /* [19:16] */ + __IO uint32_t bts2 : 3; /* [22:20] */ + __IO uint32_t reserved2 : 1; /* [23] */ + __IO uint32_t rsaw : 2; /* [25:24] */ + __IO uint32_t reserved3 : 4; /* [29:26] */ + __IO uint32_t lben : 1; /* [30] */ + __IO uint32_t loen : 1; /* [31] */ + } btmg_bit; + }; - /** - * @brief can reserved register, offset:0x20~0x17C - */ - __IO uint32_t reserved1[88]; + /** + * @brief can reserved register, offset:0x20~0x17C + */ + __IO uint32_t reserved1[88]; - /** - * @brief can controller area network tx mailbox register, offset:0x180~0x1AC - */ - can_tx_mailbox_type tx_mailbox[3]; + /** + * @brief can controller area network tx mailbox register, offset:0x180~0x1AC + */ + can_tx_mailbox_type tx_mailbox[3]; - /** - * @brief can controller area network fifo mailbox register, offset:0x1B0~0x1CC - */ - can_fifo_mailbox_type fifo_mailbox[2]; + /** + * @brief can controller area network fifo mailbox register, offset:0x1B0~0x1CC + */ + can_fifo_mailbox_type fifo_mailbox[2]; - /** - * @brief can reserved register, offset:0x1D0~0x1FC - */ - __IO uint32_t reserved2[12]; + /** + * @brief can reserved register, offset:0x1D0~0x1FC + */ + __IO uint32_t reserved2[12]; - /** - * @brief can fctrl register, offset:0x200 - */ - union - { - __IO uint32_t fctrl; - struct - { - __IO uint32_t fcs : 1; /* [0] */ - __IO uint32_t reserved1 : 31;/* [31:1] */ - } fctrl_bit; - }; + /** + * @brief can fctrl register, offset:0x200 + */ + union { + __IO uint32_t fctrl; + struct { + __IO uint32_t fcs : 1; /* [0] */ + __IO uint32_t reserved1 : 31;/* [31:1] */ + } fctrl_bit; + }; - /** - * @brief can fmcfg register, offset:0x204 - */ - union - { - __IO uint32_t fmcfg; - struct - { - __IO uint32_t fmsel0 : 1; /* [0] */ - __IO uint32_t fmsel1 : 1; /* [1] */ - __IO uint32_t fmsel2 : 1; /* [2] */ - __IO uint32_t fmsel3 : 1; /* [3] */ - __IO uint32_t fmsel4 : 1; /* [4] */ - __IO uint32_t fmsel5 : 1; /* [5] */ - __IO uint32_t fmsel6 : 1; /* [6] */ - __IO uint32_t fmsel7 : 1; /* [7] */ - __IO uint32_t fmsel8 : 1; /* [8] */ - __IO uint32_t fmsel9 : 1; /* [9] */ - __IO uint32_t fmsel10 : 1; /* [10] */ - __IO uint32_t fmsel11 : 1; /* [11] */ - __IO uint32_t fmsel12 : 1; /* [12] */ - __IO uint32_t fmsel13 : 1; /* [13] */ - __IO uint32_t fmsel14 : 1; /* [14] */ - __IO uint32_t fmsel15 : 1; /* [15] */ - __IO uint32_t fmsel16 : 1; /* [16] */ - __IO uint32_t fmsel17 : 1; /* [17] */ - __IO uint32_t fmsel18 : 1; /* [18] */ - __IO uint32_t fmsel19 : 1; /* [19] */ - __IO uint32_t fmsel20 : 1; /* [20] */ - __IO uint32_t fmsel21 : 1; /* [21] */ - __IO uint32_t fmsel22 : 1; /* [22] */ - __IO uint32_t fmsel23 : 1; /* [23] */ - __IO uint32_t fmsel24 : 1; /* [24] */ - __IO uint32_t fmsel25 : 1; /* [25] */ - __IO uint32_t fmsel26 : 1; /* [26] */ - __IO uint32_t fmsel27 : 1; /* [27] */ - __IO uint32_t reserved1 : 4;/* [31:28] */ - } fmcfg_bit; - }; + /** + * @brief can fmcfg register, offset:0x204 + */ + union { + __IO uint32_t fmcfg; + struct { + __IO uint32_t fmsel0 : 1; /* [0] */ + __IO uint32_t fmsel1 : 1; /* [1] */ + __IO uint32_t fmsel2 : 1; /* [2] */ + __IO uint32_t fmsel3 : 1; /* [3] */ + __IO uint32_t fmsel4 : 1; /* [4] */ + __IO uint32_t fmsel5 : 1; /* [5] */ + __IO uint32_t fmsel6 : 1; /* [6] */ + __IO uint32_t fmsel7 : 1; /* [7] */ + __IO uint32_t fmsel8 : 1; /* [8] */ + __IO uint32_t fmsel9 : 1; /* [9] */ + __IO uint32_t fmsel10 : 1; /* [10] */ + __IO uint32_t fmsel11 : 1; /* [11] */ + __IO uint32_t fmsel12 : 1; /* [12] */ + __IO uint32_t fmsel13 : 1; /* [13] */ + __IO uint32_t fmsel14 : 1; /* [14] */ + __IO uint32_t fmsel15 : 1; /* [15] */ + __IO uint32_t fmsel16 : 1; /* [16] */ + __IO uint32_t fmsel17 : 1; /* [17] */ + __IO uint32_t fmsel18 : 1; /* [18] */ + __IO uint32_t fmsel19 : 1; /* [19] */ + __IO uint32_t fmsel20 : 1; /* [20] */ + __IO uint32_t fmsel21 : 1; /* [21] */ + __IO uint32_t fmsel22 : 1; /* [22] */ + __IO uint32_t fmsel23 : 1; /* [23] */ + __IO uint32_t fmsel24 : 1; /* [24] */ + __IO uint32_t fmsel25 : 1; /* [25] */ + __IO uint32_t fmsel26 : 1; /* [26] */ + __IO uint32_t fmsel27 : 1; /* [27] */ + __IO uint32_t reserved1 : 4;/* [31:28] */ + } fmcfg_bit; + }; - /** - * @brief can reserved register, offset:0x208 - */ - __IO uint32_t reserved3; + /** + * @brief can reserved register, offset:0x208 + */ + __IO uint32_t reserved3; - /** - * @brief can fbwcfg register, offset:0x20C - */ - union - { - __IO uint32_t fbwcfg; - struct - { - __IO uint32_t fbwsel0 : 1; /* [0] */ - __IO uint32_t fbwsel1 : 1; /* [1] */ - __IO uint32_t fbwsel2 : 1; /* [2] */ - __IO uint32_t fbwsel3 : 1; /* [3] */ - __IO uint32_t fbwsel4 : 1; /* [4] */ - __IO uint32_t fbwsel5 : 1; /* [5] */ - __IO uint32_t fbwsel6 : 1; /* [6] */ - __IO uint32_t fbwsel7 : 1; /* [7] */ - __IO uint32_t fbwsel8 : 1; /* [8] */ - __IO uint32_t fbwsel9 : 1; /* [9] */ - __IO uint32_t fbwsel10 : 1; /* [10] */ - __IO uint32_t fbwsel11 : 1; /* [11] */ - __IO uint32_t fbwsel12 : 1; /* [12] */ - __IO uint32_t fbwsel13 : 1; /* [13] */ - __IO uint32_t fbwsel14 : 1; /* [14] */ - __IO uint32_t fbwsel15 : 1; /* [15] */ - __IO uint32_t fbwsel16 : 1; /* [16] */ - __IO uint32_t fbwsel17 : 1; /* [17] */ - __IO uint32_t fbwsel18 : 1; /* [18] */ - __IO uint32_t fbwsel19 : 1; /* [19] */ - __IO uint32_t fbwsel20 : 1; /* [20] */ - __IO uint32_t fbwsel21 : 1; /* [21] */ - __IO uint32_t fbwsel22 : 1; /* [22] */ - __IO uint32_t fbwsel23 : 1; /* [23] */ - __IO uint32_t fbwsel24 : 1; /* [24] */ - __IO uint32_t fbwsel25 : 1; /* [25] */ - __IO uint32_t fbwsel26 : 1; /* [26] */ - __IO uint32_t fbwsel27 : 1; /* [27] */ - __IO uint32_t reserved1 : 4;/* [31:28] */ - } fbwcfg_bit; - }; + /** + * @brief can fbwcfg register, offset:0x20C + */ + union { + __IO uint32_t fbwcfg; + struct { + __IO uint32_t fbwsel0 : 1; /* [0] */ + __IO uint32_t fbwsel1 : 1; /* [1] */ + __IO uint32_t fbwsel2 : 1; /* [2] */ + __IO uint32_t fbwsel3 : 1; /* [3] */ + __IO uint32_t fbwsel4 : 1; /* [4] */ + __IO uint32_t fbwsel5 : 1; /* [5] */ + __IO uint32_t fbwsel6 : 1; /* [6] */ + __IO uint32_t fbwsel7 : 1; /* [7] */ + __IO uint32_t fbwsel8 : 1; /* [8] */ + __IO uint32_t fbwsel9 : 1; /* [9] */ + __IO uint32_t fbwsel10 : 1; /* [10] */ + __IO uint32_t fbwsel11 : 1; /* [11] */ + __IO uint32_t fbwsel12 : 1; /* [12] */ + __IO uint32_t fbwsel13 : 1; /* [13] */ + __IO uint32_t fbwsel14 : 1; /* [14] */ + __IO uint32_t fbwsel15 : 1; /* [15] */ + __IO uint32_t fbwsel16 : 1; /* [16] */ + __IO uint32_t fbwsel17 : 1; /* [17] */ + __IO uint32_t fbwsel18 : 1; /* [18] */ + __IO uint32_t fbwsel19 : 1; /* [19] */ + __IO uint32_t fbwsel20 : 1; /* [20] */ + __IO uint32_t fbwsel21 : 1; /* [21] */ + __IO uint32_t fbwsel22 : 1; /* [22] */ + __IO uint32_t fbwsel23 : 1; /* [23] */ + __IO uint32_t fbwsel24 : 1; /* [24] */ + __IO uint32_t fbwsel25 : 1; /* [25] */ + __IO uint32_t fbwsel26 : 1; /* [26] */ + __IO uint32_t fbwsel27 : 1; /* [27] */ + __IO uint32_t reserved1 : 4;/* [31:28] */ + } fbwcfg_bit; + }; - /** - * @brief can reserved register, offset:0x210 - */ - __IO uint32_t reserved4; + /** + * @brief can reserved register, offset:0x210 + */ + __IO uint32_t reserved4; - /** - * @brief can frf register, offset:0x214 - */ - union - { - __IO uint32_t frf; - struct - { - __IO uint32_t frfsel0 : 1; /* [0] */ - __IO uint32_t frfsel1 : 1; /* [1] */ - __IO uint32_t frfsel2 : 1; /* [2] */ - __IO uint32_t frfsel3 : 1; /* [3] */ - __IO uint32_t frfsel4 : 1; /* [4] */ - __IO uint32_t frfsel5 : 1; /* [5] */ - __IO uint32_t frfsel6 : 1; /* [6] */ - __IO uint32_t frfsel7 : 1; /* [7] */ - __IO uint32_t frfsel8 : 1; /* [8] */ - __IO uint32_t frfsel9 : 1; /* [9] */ - __IO uint32_t frfsel10 : 1; /* [10] */ - __IO uint32_t frfsel11 : 1; /* [11] */ - __IO uint32_t frfsel12 : 1; /* [12] */ - __IO uint32_t frfsel13 : 1; /* [13] */ - __IO uint32_t frfsel14 : 1; /* [14] */ - __IO uint32_t frfsel15 : 1; /* [15] */ - __IO uint32_t frfsel16 : 1; /* [16] */ - __IO uint32_t frfsel17 : 1; /* [17] */ - __IO uint32_t frfsel18 : 1; /* [18] */ - __IO uint32_t frfsel19 : 1; /* [19] */ - __IO uint32_t frfsel20 : 1; /* [20] */ - __IO uint32_t frfsel21 : 1; /* [21] */ - __IO uint32_t frfsel22 : 1; /* [22] */ - __IO uint32_t frfsel23 : 1; /* [23] */ - __IO uint32_t frfsel24 : 1; /* [24] */ - __IO uint32_t frfsel25 : 1; /* [25] */ - __IO uint32_t frfsel26 : 1; /* [26] */ - __IO uint32_t frfsel27 : 1; /* [27] */ - __IO uint32_t reserved1 : 4;/* [31:28] */ - } frf_bit; - }; + /** + * @brief can frf register, offset:0x214 + */ + union { + __IO uint32_t frf; + struct { + __IO uint32_t frfsel0 : 1; /* [0] */ + __IO uint32_t frfsel1 : 1; /* [1] */ + __IO uint32_t frfsel2 : 1; /* [2] */ + __IO uint32_t frfsel3 : 1; /* [3] */ + __IO uint32_t frfsel4 : 1; /* [4] */ + __IO uint32_t frfsel5 : 1; /* [5] */ + __IO uint32_t frfsel6 : 1; /* [6] */ + __IO uint32_t frfsel7 : 1; /* [7] */ + __IO uint32_t frfsel8 : 1; /* [8] */ + __IO uint32_t frfsel9 : 1; /* [9] */ + __IO uint32_t frfsel10 : 1; /* [10] */ + __IO uint32_t frfsel11 : 1; /* [11] */ + __IO uint32_t frfsel12 : 1; /* [12] */ + __IO uint32_t frfsel13 : 1; /* [13] */ + __IO uint32_t frfsel14 : 1; /* [14] */ + __IO uint32_t frfsel15 : 1; /* [15] */ + __IO uint32_t frfsel16 : 1; /* [16] */ + __IO uint32_t frfsel17 : 1; /* [17] */ + __IO uint32_t frfsel18 : 1; /* [18] */ + __IO uint32_t frfsel19 : 1; /* [19] */ + __IO uint32_t frfsel20 : 1; /* [20] */ + __IO uint32_t frfsel21 : 1; /* [21] */ + __IO uint32_t frfsel22 : 1; /* [22] */ + __IO uint32_t frfsel23 : 1; /* [23] */ + __IO uint32_t frfsel24 : 1; /* [24] */ + __IO uint32_t frfsel25 : 1; /* [25] */ + __IO uint32_t frfsel26 : 1; /* [26] */ + __IO uint32_t frfsel27 : 1; /* [27] */ + __IO uint32_t reserved1 : 4;/* [31:28] */ + } frf_bit; + }; - /** - * @brief can reserved register, offset:0x218 - */ - __IO uint32_t reserved5; + /** + * @brief can reserved register, offset:0x218 + */ + __IO uint32_t reserved5; - /** - * @brief can facfg register, offset:0x21C - */ - union - { - __IO uint32_t facfg; - struct - { - __IO uint32_t faen0 : 1; /* [0] */ - __IO uint32_t faen1 : 1; /* [1] */ - __IO uint32_t faen2 : 1; /* [2] */ - __IO uint32_t faen3 : 1; /* [3] */ - __IO uint32_t faen4 : 1; /* [4] */ - __IO uint32_t faen5 : 1; /* [5] */ - __IO uint32_t faen6 : 1; /* [6] */ - __IO uint32_t faen7 : 1; /* [7] */ - __IO uint32_t faen8 : 1; /* [8] */ - __IO uint32_t faen9 : 1; /* [9] */ - __IO uint32_t faen10 : 1; /* [10] */ - __IO uint32_t faen11 : 1; /* [11] */ - __IO uint32_t faen12 : 1; /* [12] */ - __IO uint32_t faen13 : 1; /* [13] */ - __IO uint32_t faen14 : 1; /* [14] */ - __IO uint32_t faen15 : 1; /* [15] */ - __IO uint32_t faen16 : 1; /* [16] */ - __IO uint32_t faen17 : 1; /* [17] */ - __IO uint32_t faen18 : 1; /* [18] */ - __IO uint32_t faen19 : 1; /* [19] */ - __IO uint32_t faen20 : 1; /* [20] */ - __IO uint32_t faen21 : 1; /* [21] */ - __IO uint32_t faen22 : 1; /* [22] */ - __IO uint32_t faen23 : 1; /* [23] */ - __IO uint32_t faen24 : 1; /* [24] */ - __IO uint32_t faen25 : 1; /* [25] */ - __IO uint32_t faen26 : 1; /* [26] */ - __IO uint32_t faen27 : 1; /* [27] */ - __IO uint32_t reserved1 : 4;/* [31:28] */ - } facfg_bit; - }; + /** + * @brief can facfg register, offset:0x21C + */ + union { + __IO uint32_t facfg; + struct { + __IO uint32_t faen0 : 1; /* [0] */ + __IO uint32_t faen1 : 1; /* [1] */ + __IO uint32_t faen2 : 1; /* [2] */ + __IO uint32_t faen3 : 1; /* [3] */ + __IO uint32_t faen4 : 1; /* [4] */ + __IO uint32_t faen5 : 1; /* [5] */ + __IO uint32_t faen6 : 1; /* [6] */ + __IO uint32_t faen7 : 1; /* [7] */ + __IO uint32_t faen8 : 1; /* [8] */ + __IO uint32_t faen9 : 1; /* [9] */ + __IO uint32_t faen10 : 1; /* [10] */ + __IO uint32_t faen11 : 1; /* [11] */ + __IO uint32_t faen12 : 1; /* [12] */ + __IO uint32_t faen13 : 1; /* [13] */ + __IO uint32_t faen14 : 1; /* [14] */ + __IO uint32_t faen15 : 1; /* [15] */ + __IO uint32_t faen16 : 1; /* [16] */ + __IO uint32_t faen17 : 1; /* [17] */ + __IO uint32_t faen18 : 1; /* [18] */ + __IO uint32_t faen19 : 1; /* [19] */ + __IO uint32_t faen20 : 1; /* [20] */ + __IO uint32_t faen21 : 1; /* [21] */ + __IO uint32_t faen22 : 1; /* [22] */ + __IO uint32_t faen23 : 1; /* [23] */ + __IO uint32_t faen24 : 1; /* [24] */ + __IO uint32_t faen25 : 1; /* [25] */ + __IO uint32_t faen26 : 1; /* [26] */ + __IO uint32_t faen27 : 1; /* [27] */ + __IO uint32_t reserved1 : 4;/* [31:28] */ + } facfg_bit; + }; - /** - * @brief can reserved register, offset:0x220~0x23C - */ - __IO uint32_t reserved6[8]; + /** + * @brief can reserved register, offset:0x220~0x23C + */ + __IO uint32_t reserved6[8]; - /** - * @brief can ffb register, offset:0x240~0x2AC - */ - can_filter_register_type ffb[28]; + /** + * @brief can ffb register, offset:0x240~0x2AC + */ + can_filter_register_type ffb[28]; } can_type; /** @@ -996,31 +927,31 @@ typedef struct * @{ */ -void can_reset(can_type* can_x); -void can_baudrate_default_para_init(can_baudrate_type* can_baudrate_struct); -error_status can_baudrate_set(can_type* can_x, can_baudrate_type* can_baudrate_struct); -void can_default_para_init(can_base_type* can_base_struct); -error_status can_base_init(can_type* can_x, can_base_type* can_base_struct); -void can_filter_default_para_init(can_filter_init_type* can_filter_init_struct); -void can_filter_init(can_type* can_x, can_filter_init_type* can_filter_init_struct); -void can_debug_transmission_prohibit(can_type* can_x, confirm_state new_state); -void can_ttc_mode_enable(can_type* can_x, confirm_state new_state); -uint8_t can_message_transmit(can_type* can_x, can_tx_message_type* tx_message_struct); -can_transmit_status_type can_transmit_status_get(can_type* can_x, can_tx_mailbox_num_type transmit_mailbox); -void can_transmit_cancel(can_type* can_x, can_tx_mailbox_num_type transmit_mailbox); -void can_message_receive(can_type* can_x, can_rx_fifo_num_type fifo_number, can_rx_message_type* rx_message_struct); -void can_receive_fifo_release(can_type* can_x, can_rx_fifo_num_type fifo_number); -uint8_t can_receive_message_pending_get(can_type* can_x, can_rx_fifo_num_type fifo_number); -error_status can_operating_mode_set(can_type* can_x, can_operating_mode_type can_operating_mode); -can_enter_doze_status_type can_doze_mode_enter(can_type* can_x); -can_quit_doze_status_type can_doze_mode_exit(can_type* can_x); -can_error_record_type can_error_type_record_get(can_type* can_x); -uint8_t can_receive_error_counter_get(can_type* can_x); -uint8_t can_transmit_error_counter_get(can_type* can_x); -void can_interrupt_enable(can_type* can_x, uint32_t can_int, confirm_state new_state); -flag_status can_interrupt_flag_get(can_type* can_x, uint32_t can_flag); -flag_status can_flag_get(can_type* can_x, uint32_t can_flag); -void can_flag_clear(can_type* can_x, uint32_t can_flag); +void can_reset(can_type *can_x); +void can_baudrate_default_para_init(can_baudrate_type *can_baudrate_struct); +error_status can_baudrate_set(can_type *can_x, can_baudrate_type *can_baudrate_struct); +void can_default_para_init(can_base_type *can_base_struct); +error_status can_base_init(can_type *can_x, can_base_type *can_base_struct); +void can_filter_default_para_init(can_filter_init_type *can_filter_init_struct); +void can_filter_init(can_type *can_x, can_filter_init_type *can_filter_init_struct); +void can_debug_transmission_prohibit(can_type *can_x, confirm_state new_state); +void can_ttc_mode_enable(can_type *can_x, confirm_state new_state); +uint8_t can_message_transmit(can_type *can_x, can_tx_message_type *tx_message_struct); +can_transmit_status_type can_transmit_status_get(can_type *can_x, can_tx_mailbox_num_type transmit_mailbox); +void can_transmit_cancel(can_type *can_x, can_tx_mailbox_num_type transmit_mailbox); +void can_message_receive(can_type *can_x, can_rx_fifo_num_type fifo_number, can_rx_message_type *rx_message_struct); +void can_receive_fifo_release(can_type *can_x, can_rx_fifo_num_type fifo_number); +uint8_t can_receive_message_pending_get(can_type *can_x, can_rx_fifo_num_type fifo_number); +error_status can_operating_mode_set(can_type *can_x, can_operating_mode_type can_operating_mode); +can_enter_doze_status_type can_doze_mode_enter(can_type *can_x); +can_quit_doze_status_type can_doze_mode_exit(can_type *can_x); +can_error_record_type can_error_type_record_get(can_type *can_x); +uint8_t can_receive_error_counter_get(can_type *can_x); +uint8_t can_transmit_error_counter_get(can_type *can_x); +void can_interrupt_enable(can_type *can_x, uint32_t can_int, confirm_state new_state); +flag_status can_interrupt_flag_get(can_type *can_x, uint32_t can_flag); +flag_status can_flag_get(can_type *can_x, uint32_t can_flag); +void can_flag_clear(can_type *can_x, uint32_t can_flag); /** * @} diff --git a/armlib/at32_sys/drivers/inc/at32f435_437_crc.h b/armlib/at32_sys/drivers/inc/at32f435_437_crc.h index d97b3846d..e151995d0 100644 --- a/armlib/at32_sys/drivers/inc/at32f435_437_crc.h +++ b/armlib/at32_sys/drivers/inc/at32f435_437_crc.h @@ -49,109 +49,95 @@ extern "C" { /** * @brief crc reverse input data */ -typedef enum -{ - CRC_REVERSE_INPUT_NO_AFFECTE = 0x00, /*!< input data no reverse */ - CRC_REVERSE_INPUT_BY_BYTE = 0x01, /*!< input data reverse by byte */ - CRC_REVERSE_INPUT_BY_HALFWORD = 0x02, /*!< input data reverse by half word */ - CRC_REVERSE_INPUT_BY_WORD = 0x03 /*!< input data reverse by word */ +typedef enum { + CRC_REVERSE_INPUT_NO_AFFECTE = 0x00, /*!< input data no reverse */ + CRC_REVERSE_INPUT_BY_BYTE = 0x01, /*!< input data reverse by byte */ + CRC_REVERSE_INPUT_BY_HALFWORD = 0x02, /*!< input data reverse by half word */ + CRC_REVERSE_INPUT_BY_WORD = 0x03 /*!< input data reverse by word */ } crc_reverse_input_type; /** * @brief crc reverse output data */ -typedef enum -{ - CRC_REVERSE_OUTPUT_NO_AFFECTE = 0x00, /*!< output data no reverse */ - CRC_REVERSE_OUTPUT_DATA = 0x01 /*!< output data reverse by word */ +typedef enum { + CRC_REVERSE_OUTPUT_NO_AFFECTE = 0x00, /*!< output data no reverse */ + CRC_REVERSE_OUTPUT_DATA = 0x01 /*!< output data reverse by word */ } crc_reverse_output_type; /** * @brief crc polynomial size */ -typedef enum -{ - CRC_POLY_SIZE_32B = 0x00, /*!< polynomial size 32 bits */ - CRC_POLY_SIZE_16B = 0x01, /*!< polynomial size 16 bits */ - CRC_POLY_SIZE_8B = 0x02, /*!< polynomial size 8 bits */ - CRC_POLY_SIZE_7B = 0x03 /*!< polynomial size 7 bits */ +typedef enum { + CRC_POLY_SIZE_32B = 0x00, /*!< polynomial size 32 bits */ + CRC_POLY_SIZE_16B = 0x01, /*!< polynomial size 16 bits */ + CRC_POLY_SIZE_8B = 0x02, /*!< polynomial size 8 bits */ + CRC_POLY_SIZE_7B = 0x03 /*!< polynomial size 7 bits */ } crc_poly_size_type; /** * @brief type define crc register all */ -typedef struct -{ - /** - * @brief crc dt register, offset:0x00 - */ - union - { - __IO uint32_t dt; - struct - { - __IO uint32_t dt : 32; /* [31:0] */ - } dt_bit; - }; +typedef struct { + /** + * @brief crc dt register, offset:0x00 + */ + union { + __IO uint32_t dt; + struct { + __IO uint32_t dt : 32; /* [31:0] */ + } dt_bit; + }; - /** - * @brief crc cdt register, offset:0x04 - */ - union - { - __IO uint32_t cdt; - struct - { - __IO uint32_t cdt : 8 ; /* [7:0] */ - __IO uint32_t reserved1 : 24 ;/* [31:8] */ - } cdt_bit; - }; + /** + * @brief crc cdt register, offset:0x04 + */ + union { + __IO uint32_t cdt; + struct { + __IO uint32_t cdt : 8 ; /* [7:0] */ + __IO uint32_t reserved1 : 24 ;/* [31:8] */ + } cdt_bit; + }; - /** - * @brief crc ctrl register, offset:0x08 - */ - union - { - __IO uint32_t ctrl; - struct - { - __IO uint32_t rst : 1 ; /* [0] */ - __IO uint32_t reserved1 : 2 ; /* [2:1] */ - __IO uint32_t poly_size : 2 ; /* [4:3] */ - __IO uint32_t revid : 2 ; /* [6:5] */ - __IO uint32_t revod : 1 ; /* [7] */ - __IO uint32_t reserved2 : 24 ;/* [31:8] */ - } ctrl_bit; - }; + /** + * @brief crc ctrl register, offset:0x08 + */ + union { + __IO uint32_t ctrl; + struct { + __IO uint32_t rst : 1 ; /* [0] */ + __IO uint32_t reserved1 : 2 ; /* [2:1] */ + __IO uint32_t poly_size : 2 ; /* [4:3] */ + __IO uint32_t revid : 2 ; /* [6:5] */ + __IO uint32_t revod : 1 ; /* [7] */ + __IO uint32_t reserved2 : 24 ;/* [31:8] */ + } ctrl_bit; + }; - /** - * @brief crm reserved1 register, offset:0x0C - */ - __IO uint32_t reserved1; + /** + * @brief crm reserved1 register, offset:0x0C + */ + __IO uint32_t reserved1; - /** - * @brief crc idt register, offset:0x10 - */ - union - { - __IO uint32_t idt; - struct - { - __IO uint32_t idt : 32; /* [31:0] */ - } idt_bit; - }; + /** + * @brief crc idt register, offset:0x10 + */ + union { + __IO uint32_t idt; + struct { + __IO uint32_t idt : 32; /* [31:0] */ + } idt_bit; + }; - /** - * @brief crc polynomial register, offset:0x14 - */ - union - { - __IO uint32_t poly; - struct - { - __IO uint32_t poly : 32; /* [31:0] */ - } poly_bit; - }; + /** + * @brief crc polynomial register, offset:0x14 + */ + union { + __IO uint32_t poly; + struct { + __IO uint32_t poly : 32; /* [31:0] */ + } poly_bit; + }; } crc_type; diff --git a/armlib/at32_sys/drivers/inc/at32f435_437_crm.h b/armlib/at32_sys/drivers/inc/at32f435_437_crm.h index 4e24d97e1..17251853d 100644 --- a/armlib/at32_sys/drivers/inc/at32f435_437_crm.h +++ b/armlib/at32_sys/drivers/inc/at32f435_437_crm.h @@ -96,146 +96,145 @@ extern "C" { /** * @brief crm periph clock */ -typedef enum -{ +typedef enum { #if defined (AT32F435xx) - /* ahb periph1 */ - CRM_GPIOA_PERIPH_CLOCK = MAKE_VALUE(0x30, 0), /*!< gpioa periph clock */ - CRM_GPIOB_PERIPH_CLOCK = MAKE_VALUE(0x30, 1), /*!< gpiob periph clock */ - CRM_GPIOC_PERIPH_CLOCK = MAKE_VALUE(0x30, 2), /*!< gpioc periph clock */ - CRM_GPIOD_PERIPH_CLOCK = MAKE_VALUE(0x30, 3), /*!< gpiod periph clock */ - CRM_GPIOE_PERIPH_CLOCK = MAKE_VALUE(0x30, 4), /*!< gpioe periph clock */ - CRM_GPIOF_PERIPH_CLOCK = MAKE_VALUE(0x30, 5), /*!< gpiof periph clock */ - CRM_GPIOG_PERIPH_CLOCK = MAKE_VALUE(0x30, 6), /*!< gpiog periph clock */ - CRM_GPIOH_PERIPH_CLOCK = MAKE_VALUE(0x30, 7), /*!< gpioh periph clock */ - CRM_CRC_PERIPH_CLOCK = MAKE_VALUE(0x30, 12), /*!< crc periph clock */ - CRM_EDMA_PERIPH_CLOCK = MAKE_VALUE(0x30, 21), /*!< edma periph clock */ - CRM_DMA1_PERIPH_CLOCK = MAKE_VALUE(0x30, 22), /*!< dma1 periph clock */ - CRM_DMA2_PERIPH_CLOCK = MAKE_VALUE(0x30, 24), /*!< dma2 periph clock */ - CRM_OTGFS2_PERIPH_CLOCK = MAKE_VALUE(0x30, 29), /*!< otgfs2 periph clock */ - /* ahb periph2 */ - CRM_DVP_PERIPH_CLOCK = MAKE_VALUE(0x34, 0), /*!< dvp periph clock */ - CRM_OTGFS1_PERIPH_CLOCK = MAKE_VALUE(0x34, 7), /*!< otgfs1 periph clock */ - CRM_SDIO1_PERIPH_CLOCK = MAKE_VALUE(0x34, 15), /*!< sdio1 periph clock */ - /* ahb periph3 */ - CRM_XMC_PERIPH_CLOCK = MAKE_VALUE(0x38, 0), /*!< xmc periph clock */ - CRM_QSPI1_PERIPH_CLOCK = MAKE_VALUE(0x38, 1), /*!< qspi1 periph clock */ - CRM_QSPI2_PERIPH_CLOCK = MAKE_VALUE(0x38, 14), /*!< qspi2 periph clock */ - CRM_SDIO2_PERIPH_CLOCK = MAKE_VALUE(0x38, 15), /*!< sdio2 periph clock */ - /* apb1 periph */ - CRM_TMR2_PERIPH_CLOCK = MAKE_VALUE(0x40, 0), /*!< tmr2 periph clock */ - CRM_TMR3_PERIPH_CLOCK = MAKE_VALUE(0x40, 1), /*!< tmr3 periph clock */ - CRM_TMR4_PERIPH_CLOCK = MAKE_VALUE(0x40, 2), /*!< tmr4 periph clock */ - CRM_TMR5_PERIPH_CLOCK = MAKE_VALUE(0x40, 3), /*!< tmr5 periph clock */ - CRM_TMR6_PERIPH_CLOCK = MAKE_VALUE(0x40, 4), /*!< tmr6 periph clock */ - CRM_TMR7_PERIPH_CLOCK = MAKE_VALUE(0x40, 5), /*!< tmr7 periph clock */ - CRM_TMR12_PERIPH_CLOCK = MAKE_VALUE(0x40, 6), /*!< tmr12 periph clock */ - CRM_TMR13_PERIPH_CLOCK = MAKE_VALUE(0x40, 7), /*!< tmr13 periph clock */ - CRM_TMR14_PERIPH_CLOCK = MAKE_VALUE(0x40, 8), /*!< tmr14 periph clock */ - CRM_WWDT_PERIPH_CLOCK = MAKE_VALUE(0x40, 11), /*!< wwdt periph clock */ - CRM_SPI2_PERIPH_CLOCK = MAKE_VALUE(0x40, 14), /*!< spi2 periph clock */ - CRM_SPI3_PERIPH_CLOCK = MAKE_VALUE(0x40, 15), /*!< spi3 periph clock */ - CRM_USART2_PERIPH_CLOCK = MAKE_VALUE(0x40, 17), /*!< usart2 periph clock */ - CRM_USART3_PERIPH_CLOCK = MAKE_VALUE(0x40, 18), /*!< usart3 periph clock */ - CRM_UART4_PERIPH_CLOCK = MAKE_VALUE(0x40, 19), /*!< uart4 periph clock */ - CRM_UART5_PERIPH_CLOCK = MAKE_VALUE(0x40, 20), /*!< uart5 periph clock */ - CRM_I2C1_PERIPH_CLOCK = MAKE_VALUE(0x40, 21), /*!< i2c1 periph clock */ - CRM_I2C2_PERIPH_CLOCK = MAKE_VALUE(0x40, 22), /*!< i2c2 periph clock */ - CRM_I2C3_PERIPH_CLOCK = MAKE_VALUE(0x40, 23), /*!< i2c3 periph clock */ - CRM_CAN1_PERIPH_CLOCK = MAKE_VALUE(0x40, 25), /*!< can1 periph clock */ - CRM_CAN2_PERIPH_CLOCK = MAKE_VALUE(0x40, 26), /*!< can2 periph clock */ - CRM_PWC_PERIPH_CLOCK = MAKE_VALUE(0x40, 28), /*!< pwc periph clock */ - CRM_DAC_PERIPH_CLOCK = MAKE_VALUE(0x40, 29), /*!< dac periph clock */ - CRM_UART7_PERIPH_CLOCK = MAKE_VALUE(0x40, 30), /*!< uart7 periph clock */ - CRM_UART8_PERIPH_CLOCK = MAKE_VALUE(0x40, 31), /*!< uart8 periph clock */ - /* apb2 periph */ - CRM_TMR1_PERIPH_CLOCK = MAKE_VALUE(0x44, 0), /*!< tmr1 periph clock */ - CRM_TMR8_PERIPH_CLOCK = MAKE_VALUE(0x44, 1), /*!< tmr8 periph clock */ - CRM_USART1_PERIPH_CLOCK = MAKE_VALUE(0x44, 4), /*!< usart1 periph clock */ - CRM_USART6_PERIPH_CLOCK = MAKE_VALUE(0x44, 5), /*!< usart6 periph clock */ - CRM_ADC1_PERIPH_CLOCK = MAKE_VALUE(0x44, 8), /*!< adc1 periph clock */ - CRM_ADC2_PERIPH_CLOCK = MAKE_VALUE(0x44, 9), /*!< adc2 periph clock */ - CRM_ADC3_PERIPH_CLOCK = MAKE_VALUE(0x44, 10), /*!< adc3 periph clock */ - CRM_SPI1_PERIPH_CLOCK = MAKE_VALUE(0x44, 12), /*!< spi1 periph clock */ - CRM_SPI4_PERIPH_CLOCK = MAKE_VALUE(0x44, 13), /*!< spi4 periph clock */ - CRM_SCFG_PERIPH_CLOCK = MAKE_VALUE(0x44, 14), /*!< scfg periph clock */ - CRM_TMR9_PERIPH_CLOCK = MAKE_VALUE(0x44, 16), /*!< tmr9 periph clock */ - CRM_TMR10_PERIPH_CLOCK = MAKE_VALUE(0x44, 17), /*!< tmr10 periph clock */ - CRM_TMR11_PERIPH_CLOCK = MAKE_VALUE(0x44, 18), /*!< tmr11 periph clock */ - CRM_TMR20_PERIPH_CLOCK = MAKE_VALUE(0x44, 20), /*!< tmr20 periph clock */ - CRM_ACC_PERIPH_CLOCK = MAKE_VALUE(0x44, 29) /*!< acc periph clock */ + /* ahb periph1 */ + CRM_GPIOA_PERIPH_CLOCK = MAKE_VALUE(0x30, 0), /*!< gpioa periph clock */ + CRM_GPIOB_PERIPH_CLOCK = MAKE_VALUE(0x30, 1), /*!< gpiob periph clock */ + CRM_GPIOC_PERIPH_CLOCK = MAKE_VALUE(0x30, 2), /*!< gpioc periph clock */ + CRM_GPIOD_PERIPH_CLOCK = MAKE_VALUE(0x30, 3), /*!< gpiod periph clock */ + CRM_GPIOE_PERIPH_CLOCK = MAKE_VALUE(0x30, 4), /*!< gpioe periph clock */ + CRM_GPIOF_PERIPH_CLOCK = MAKE_VALUE(0x30, 5), /*!< gpiof periph clock */ + CRM_GPIOG_PERIPH_CLOCK = MAKE_VALUE(0x30, 6), /*!< gpiog periph clock */ + CRM_GPIOH_PERIPH_CLOCK = MAKE_VALUE(0x30, 7), /*!< gpioh periph clock */ + CRM_CRC_PERIPH_CLOCK = MAKE_VALUE(0x30, 12), /*!< crc periph clock */ + CRM_EDMA_PERIPH_CLOCK = MAKE_VALUE(0x30, 21), /*!< edma periph clock */ + CRM_DMA1_PERIPH_CLOCK = MAKE_VALUE(0x30, 22), /*!< dma1 periph clock */ + CRM_DMA2_PERIPH_CLOCK = MAKE_VALUE(0x30, 24), /*!< dma2 periph clock */ + CRM_OTGFS2_PERIPH_CLOCK = MAKE_VALUE(0x30, 29), /*!< otgfs2 periph clock */ + /* ahb periph2 */ + CRM_DVP_PERIPH_CLOCK = MAKE_VALUE(0x34, 0), /*!< dvp periph clock */ + CRM_OTGFS1_PERIPH_CLOCK = MAKE_VALUE(0x34, 7), /*!< otgfs1 periph clock */ + CRM_SDIO1_PERIPH_CLOCK = MAKE_VALUE(0x34, 15), /*!< sdio1 periph clock */ + /* ahb periph3 */ + CRM_XMC_PERIPH_CLOCK = MAKE_VALUE(0x38, 0), /*!< xmc periph clock */ + CRM_QSPI1_PERIPH_CLOCK = MAKE_VALUE(0x38, 1), /*!< qspi1 periph clock */ + CRM_QSPI2_PERIPH_CLOCK = MAKE_VALUE(0x38, 14), /*!< qspi2 periph clock */ + CRM_SDIO2_PERIPH_CLOCK = MAKE_VALUE(0x38, 15), /*!< sdio2 periph clock */ + /* apb1 periph */ + CRM_TMR2_PERIPH_CLOCK = MAKE_VALUE(0x40, 0), /*!< tmr2 periph clock */ + CRM_TMR3_PERIPH_CLOCK = MAKE_VALUE(0x40, 1), /*!< tmr3 periph clock */ + CRM_TMR4_PERIPH_CLOCK = MAKE_VALUE(0x40, 2), /*!< tmr4 periph clock */ + CRM_TMR5_PERIPH_CLOCK = MAKE_VALUE(0x40, 3), /*!< tmr5 periph clock */ + CRM_TMR6_PERIPH_CLOCK = MAKE_VALUE(0x40, 4), /*!< tmr6 periph clock */ + CRM_TMR7_PERIPH_CLOCK = MAKE_VALUE(0x40, 5), /*!< tmr7 periph clock */ + CRM_TMR12_PERIPH_CLOCK = MAKE_VALUE(0x40, 6), /*!< tmr12 periph clock */ + CRM_TMR13_PERIPH_CLOCK = MAKE_VALUE(0x40, 7), /*!< tmr13 periph clock */ + CRM_TMR14_PERIPH_CLOCK = MAKE_VALUE(0x40, 8), /*!< tmr14 periph clock */ + CRM_WWDT_PERIPH_CLOCK = MAKE_VALUE(0x40, 11), /*!< wwdt periph clock */ + CRM_SPI2_PERIPH_CLOCK = MAKE_VALUE(0x40, 14), /*!< spi2 periph clock */ + CRM_SPI3_PERIPH_CLOCK = MAKE_VALUE(0x40, 15), /*!< spi3 periph clock */ + CRM_USART2_PERIPH_CLOCK = MAKE_VALUE(0x40, 17), /*!< usart2 periph clock */ + CRM_USART3_PERIPH_CLOCK = MAKE_VALUE(0x40, 18), /*!< usart3 periph clock */ + CRM_UART4_PERIPH_CLOCK = MAKE_VALUE(0x40, 19), /*!< uart4 periph clock */ + CRM_UART5_PERIPH_CLOCK = MAKE_VALUE(0x40, 20), /*!< uart5 periph clock */ + CRM_I2C1_PERIPH_CLOCK = MAKE_VALUE(0x40, 21), /*!< i2c1 periph clock */ + CRM_I2C2_PERIPH_CLOCK = MAKE_VALUE(0x40, 22), /*!< i2c2 periph clock */ + CRM_I2C3_PERIPH_CLOCK = MAKE_VALUE(0x40, 23), /*!< i2c3 periph clock */ + CRM_CAN1_PERIPH_CLOCK = MAKE_VALUE(0x40, 25), /*!< can1 periph clock */ + CRM_CAN2_PERIPH_CLOCK = MAKE_VALUE(0x40, 26), /*!< can2 periph clock */ + CRM_PWC_PERIPH_CLOCK = MAKE_VALUE(0x40, 28), /*!< pwc periph clock */ + CRM_DAC_PERIPH_CLOCK = MAKE_VALUE(0x40, 29), /*!< dac periph clock */ + CRM_UART7_PERIPH_CLOCK = MAKE_VALUE(0x40, 30), /*!< uart7 periph clock */ + CRM_UART8_PERIPH_CLOCK = MAKE_VALUE(0x40, 31), /*!< uart8 periph clock */ + /* apb2 periph */ + CRM_TMR1_PERIPH_CLOCK = MAKE_VALUE(0x44, 0), /*!< tmr1 periph clock */ + CRM_TMR8_PERIPH_CLOCK = MAKE_VALUE(0x44, 1), /*!< tmr8 periph clock */ + CRM_USART1_PERIPH_CLOCK = MAKE_VALUE(0x44, 4), /*!< usart1 periph clock */ + CRM_USART6_PERIPH_CLOCK = MAKE_VALUE(0x44, 5), /*!< usart6 periph clock */ + CRM_ADC1_PERIPH_CLOCK = MAKE_VALUE(0x44, 8), /*!< adc1 periph clock */ + CRM_ADC2_PERIPH_CLOCK = MAKE_VALUE(0x44, 9), /*!< adc2 periph clock */ + CRM_ADC3_PERIPH_CLOCK = MAKE_VALUE(0x44, 10), /*!< adc3 periph clock */ + CRM_SPI1_PERIPH_CLOCK = MAKE_VALUE(0x44, 12), /*!< spi1 periph clock */ + CRM_SPI4_PERIPH_CLOCK = MAKE_VALUE(0x44, 13), /*!< spi4 periph clock */ + CRM_SCFG_PERIPH_CLOCK = MAKE_VALUE(0x44, 14), /*!< scfg periph clock */ + CRM_TMR9_PERIPH_CLOCK = MAKE_VALUE(0x44, 16), /*!< tmr9 periph clock */ + CRM_TMR10_PERIPH_CLOCK = MAKE_VALUE(0x44, 17), /*!< tmr10 periph clock */ + CRM_TMR11_PERIPH_CLOCK = MAKE_VALUE(0x44, 18), /*!< tmr11 periph clock */ + CRM_TMR20_PERIPH_CLOCK = MAKE_VALUE(0x44, 20), /*!< tmr20 periph clock */ + CRM_ACC_PERIPH_CLOCK = MAKE_VALUE(0x44, 29) /*!< acc periph clock */ #endif #if defined (AT32F437xx) - /* ahb periph1 */ - CRM_GPIOA_PERIPH_CLOCK = MAKE_VALUE(0x30, 0), /*!< gpioa periph clock */ - CRM_GPIOB_PERIPH_CLOCK = MAKE_VALUE(0x30, 1), /*!< gpiob periph clock */ - CRM_GPIOC_PERIPH_CLOCK = MAKE_VALUE(0x30, 2), /*!< gpioc periph clock */ - CRM_GPIOD_PERIPH_CLOCK = MAKE_VALUE(0x30, 3), /*!< gpiod periph clock */ - CRM_GPIOE_PERIPH_CLOCK = MAKE_VALUE(0x30, 4), /*!< gpioe periph clock */ - CRM_GPIOF_PERIPH_CLOCK = MAKE_VALUE(0x30, 5), /*!< gpiof periph clock */ - CRM_GPIOG_PERIPH_CLOCK = MAKE_VALUE(0x30, 6), /*!< gpiog periph clock */ - CRM_GPIOH_PERIPH_CLOCK = MAKE_VALUE(0x30, 7), /*!< gpioh periph clock */ - CRM_CRC_PERIPH_CLOCK = MAKE_VALUE(0x30, 12), /*!< crc periph clock */ - CRM_EDMA_PERIPH_CLOCK = MAKE_VALUE(0x30, 21), /*!< edma periph clock */ - CRM_DMA1_PERIPH_CLOCK = MAKE_VALUE(0x30, 22), /*!< dma1 periph clock */ - CRM_DMA2_PERIPH_CLOCK = MAKE_VALUE(0x30, 24), /*!< dma2 periph clock */ - CRM_EMAC_PERIPH_CLOCK = MAKE_VALUE(0x30, 25), /*!< emac periph clock */ - CRM_EMACTX_PERIPH_CLOCK = MAKE_VALUE(0x30, 26), /*!< emac tx periph clock */ - CRM_EMACRX_PERIPH_CLOCK = MAKE_VALUE(0x30, 27), /*!< emac rx periph clock */ - CRM_EMACPTP_PERIPH_CLOCK = MAKE_VALUE(0x30, 28), /*!< emac ptp periph clock */ - CRM_OTGFS2_PERIPH_CLOCK = MAKE_VALUE(0x30, 29), /*!< otgfs2 periph clock */ - /* ahb periph2 */ - CRM_DVP_PERIPH_CLOCK = MAKE_VALUE(0x34, 0), /*!< dvp periph clock */ - CRM_OTGFS1_PERIPH_CLOCK = MAKE_VALUE(0x34, 7), /*!< otgfs1 periph clock */ - CRM_SDIO1_PERIPH_CLOCK = MAKE_VALUE(0x34, 15), /*!< sdio1 periph clock */ - /* ahb periph3 */ - CRM_XMC_PERIPH_CLOCK = MAKE_VALUE(0x38, 0), /*!< xmc periph clock */ - CRM_QSPI1_PERIPH_CLOCK = MAKE_VALUE(0x38, 1), /*!< qspi1 periph clock */ - CRM_QSPI2_PERIPH_CLOCK = MAKE_VALUE(0x38, 14), /*!< qspi2 periph clock */ - CRM_SDIO2_PERIPH_CLOCK = MAKE_VALUE(0x38, 15), /*!< sdio2 periph clock */ - /* apb1 periph */ - CRM_TMR2_PERIPH_CLOCK = MAKE_VALUE(0x40, 0), /*!< tmr2 periph clock */ - CRM_TMR3_PERIPH_CLOCK = MAKE_VALUE(0x40, 1), /*!< tmr3 periph clock */ - CRM_TMR4_PERIPH_CLOCK = MAKE_VALUE(0x40, 2), /*!< tmr4 periph clock */ - CRM_TMR5_PERIPH_CLOCK = MAKE_VALUE(0x40, 3), /*!< tmr5 periph clock */ - CRM_TMR6_PERIPH_CLOCK = MAKE_VALUE(0x40, 4), /*!< tmr6 periph clock */ - CRM_TMR7_PERIPH_CLOCK = MAKE_VALUE(0x40, 5), /*!< tmr7 periph clock */ - CRM_TMR12_PERIPH_CLOCK = MAKE_VALUE(0x40, 6), /*!< tmr12 periph clock */ - CRM_TMR13_PERIPH_CLOCK = MAKE_VALUE(0x40, 7), /*!< tmr13 periph clock */ - CRM_TMR14_PERIPH_CLOCK = MAKE_VALUE(0x40, 8), /*!< tmr14 periph clock */ - CRM_WWDT_PERIPH_CLOCK = MAKE_VALUE(0x40, 11), /*!< wwdt periph clock */ - CRM_SPI2_PERIPH_CLOCK = MAKE_VALUE(0x40, 14), /*!< spi2 periph clock */ - CRM_SPI3_PERIPH_CLOCK = MAKE_VALUE(0x40, 15), /*!< spi3 periph clock */ - CRM_USART2_PERIPH_CLOCK = MAKE_VALUE(0x40, 17), /*!< usart2 periph clock */ - CRM_USART3_PERIPH_CLOCK = MAKE_VALUE(0x40, 18), /*!< usart3 periph clock */ - CRM_UART4_PERIPH_CLOCK = MAKE_VALUE(0x40, 19), /*!< uart4 periph clock */ - CRM_UART5_PERIPH_CLOCK = MAKE_VALUE(0x40, 20), /*!< uart5 periph clock */ - CRM_I2C1_PERIPH_CLOCK = MAKE_VALUE(0x40, 21), /*!< i2c1 periph clock */ - CRM_I2C2_PERIPH_CLOCK = MAKE_VALUE(0x40, 22), /*!< i2c2 periph clock */ - CRM_I2C3_PERIPH_CLOCK = MAKE_VALUE(0x40, 23), /*!< i2c3 periph clock */ - CRM_CAN1_PERIPH_CLOCK = MAKE_VALUE(0x40, 25), /*!< can1 periph clock */ - CRM_CAN2_PERIPH_CLOCK = MAKE_VALUE(0x40, 26), /*!< can2 periph clock */ - CRM_PWC_PERIPH_CLOCK = MAKE_VALUE(0x40, 28), /*!< pwc periph clock */ - CRM_DAC_PERIPH_CLOCK = MAKE_VALUE(0x40, 29), /*!< dac periph clock */ - CRM_UART7_PERIPH_CLOCK = MAKE_VALUE(0x40, 30), /*!< uart7 periph clock */ - CRM_UART8_PERIPH_CLOCK = MAKE_VALUE(0x40, 31), /*!< uart8 periph clock */ - /* apb2 periph */ - CRM_TMR1_PERIPH_CLOCK = MAKE_VALUE(0x44, 0), /*!< tmr1 periph clock */ - CRM_TMR8_PERIPH_CLOCK = MAKE_VALUE(0x44, 1), /*!< tmr8 periph clock */ - CRM_USART1_PERIPH_CLOCK = MAKE_VALUE(0x44, 4), /*!< usart1 periph clock */ - CRM_USART6_PERIPH_CLOCK = MAKE_VALUE(0x44, 5), /*!< usart6 periph clock */ - CRM_ADC1_PERIPH_CLOCK = MAKE_VALUE(0x44, 8), /*!< adc1 periph clock */ - CRM_ADC2_PERIPH_CLOCK = MAKE_VALUE(0x44, 9), /*!< adc2 periph clock */ - CRM_ADC3_PERIPH_CLOCK = MAKE_VALUE(0x44, 10), /*!< adc3 periph clock */ - CRM_SPI1_PERIPH_CLOCK = MAKE_VALUE(0x44, 12), /*!< spi1 periph clock */ - CRM_SPI4_PERIPH_CLOCK = MAKE_VALUE(0x44, 13), /*!< spi4 periph clock */ - CRM_SCFG_PERIPH_CLOCK = MAKE_VALUE(0x44, 14), /*!< scfg periph clock */ - CRM_TMR9_PERIPH_CLOCK = MAKE_VALUE(0x44, 16), /*!< tmr9 periph clock */ - CRM_TMR10_PERIPH_CLOCK = MAKE_VALUE(0x44, 17), /*!< tmr10 periph clock */ - CRM_TMR11_PERIPH_CLOCK = MAKE_VALUE(0x44, 18), /*!< tmr11 periph clock */ - CRM_TMR20_PERIPH_CLOCK = MAKE_VALUE(0x44, 20), /*!< tmr20 periph clock */ - CRM_ACC_PERIPH_CLOCK = MAKE_VALUE(0x44, 29) /*!< acc periph clock */ + /* ahb periph1 */ + CRM_GPIOA_PERIPH_CLOCK = MAKE_VALUE(0x30, 0), /*!< gpioa periph clock */ + CRM_GPIOB_PERIPH_CLOCK = MAKE_VALUE(0x30, 1), /*!< gpiob periph clock */ + CRM_GPIOC_PERIPH_CLOCK = MAKE_VALUE(0x30, 2), /*!< gpioc periph clock */ + CRM_GPIOD_PERIPH_CLOCK = MAKE_VALUE(0x30, 3), /*!< gpiod periph clock */ + CRM_GPIOE_PERIPH_CLOCK = MAKE_VALUE(0x30, 4), /*!< gpioe periph clock */ + CRM_GPIOF_PERIPH_CLOCK = MAKE_VALUE(0x30, 5), /*!< gpiof periph clock */ + CRM_GPIOG_PERIPH_CLOCK = MAKE_VALUE(0x30, 6), /*!< gpiog periph clock */ + CRM_GPIOH_PERIPH_CLOCK = MAKE_VALUE(0x30, 7), /*!< gpioh periph clock */ + CRM_CRC_PERIPH_CLOCK = MAKE_VALUE(0x30, 12), /*!< crc periph clock */ + CRM_EDMA_PERIPH_CLOCK = MAKE_VALUE(0x30, 21), /*!< edma periph clock */ + CRM_DMA1_PERIPH_CLOCK = MAKE_VALUE(0x30, 22), /*!< dma1 periph clock */ + CRM_DMA2_PERIPH_CLOCK = MAKE_VALUE(0x30, 24), /*!< dma2 periph clock */ + CRM_EMAC_PERIPH_CLOCK = MAKE_VALUE(0x30, 25), /*!< emac periph clock */ + CRM_EMACTX_PERIPH_CLOCK = MAKE_VALUE(0x30, 26), /*!< emac tx periph clock */ + CRM_EMACRX_PERIPH_CLOCK = MAKE_VALUE(0x30, 27), /*!< emac rx periph clock */ + CRM_EMACPTP_PERIPH_CLOCK = MAKE_VALUE(0x30, 28), /*!< emac ptp periph clock */ + CRM_OTGFS2_PERIPH_CLOCK = MAKE_VALUE(0x30, 29), /*!< otgfs2 periph clock */ + /* ahb periph2 */ + CRM_DVP_PERIPH_CLOCK = MAKE_VALUE(0x34, 0), /*!< dvp periph clock */ + CRM_OTGFS1_PERIPH_CLOCK = MAKE_VALUE(0x34, 7), /*!< otgfs1 periph clock */ + CRM_SDIO1_PERIPH_CLOCK = MAKE_VALUE(0x34, 15), /*!< sdio1 periph clock */ + /* ahb periph3 */ + CRM_XMC_PERIPH_CLOCK = MAKE_VALUE(0x38, 0), /*!< xmc periph clock */ + CRM_QSPI1_PERIPH_CLOCK = MAKE_VALUE(0x38, 1), /*!< qspi1 periph clock */ + CRM_QSPI2_PERIPH_CLOCK = MAKE_VALUE(0x38, 14), /*!< qspi2 periph clock */ + CRM_SDIO2_PERIPH_CLOCK = MAKE_VALUE(0x38, 15), /*!< sdio2 periph clock */ + /* apb1 periph */ + CRM_TMR2_PERIPH_CLOCK = MAKE_VALUE(0x40, 0), /*!< tmr2 periph clock */ + CRM_TMR3_PERIPH_CLOCK = MAKE_VALUE(0x40, 1), /*!< tmr3 periph clock */ + CRM_TMR4_PERIPH_CLOCK = MAKE_VALUE(0x40, 2), /*!< tmr4 periph clock */ + CRM_TMR5_PERIPH_CLOCK = MAKE_VALUE(0x40, 3), /*!< tmr5 periph clock */ + CRM_TMR6_PERIPH_CLOCK = MAKE_VALUE(0x40, 4), /*!< tmr6 periph clock */ + CRM_TMR7_PERIPH_CLOCK = MAKE_VALUE(0x40, 5), /*!< tmr7 periph clock */ + CRM_TMR12_PERIPH_CLOCK = MAKE_VALUE(0x40, 6), /*!< tmr12 periph clock */ + CRM_TMR13_PERIPH_CLOCK = MAKE_VALUE(0x40, 7), /*!< tmr13 periph clock */ + CRM_TMR14_PERIPH_CLOCK = MAKE_VALUE(0x40, 8), /*!< tmr14 periph clock */ + CRM_WWDT_PERIPH_CLOCK = MAKE_VALUE(0x40, 11), /*!< wwdt periph clock */ + CRM_SPI2_PERIPH_CLOCK = MAKE_VALUE(0x40, 14), /*!< spi2 periph clock */ + CRM_SPI3_PERIPH_CLOCK = MAKE_VALUE(0x40, 15), /*!< spi3 periph clock */ + CRM_USART2_PERIPH_CLOCK = MAKE_VALUE(0x40, 17), /*!< usart2 periph clock */ + CRM_USART3_PERIPH_CLOCK = MAKE_VALUE(0x40, 18), /*!< usart3 periph clock */ + CRM_UART4_PERIPH_CLOCK = MAKE_VALUE(0x40, 19), /*!< uart4 periph clock */ + CRM_UART5_PERIPH_CLOCK = MAKE_VALUE(0x40, 20), /*!< uart5 periph clock */ + CRM_I2C1_PERIPH_CLOCK = MAKE_VALUE(0x40, 21), /*!< i2c1 periph clock */ + CRM_I2C2_PERIPH_CLOCK = MAKE_VALUE(0x40, 22), /*!< i2c2 periph clock */ + CRM_I2C3_PERIPH_CLOCK = MAKE_VALUE(0x40, 23), /*!< i2c3 periph clock */ + CRM_CAN1_PERIPH_CLOCK = MAKE_VALUE(0x40, 25), /*!< can1 periph clock */ + CRM_CAN2_PERIPH_CLOCK = MAKE_VALUE(0x40, 26), /*!< can2 periph clock */ + CRM_PWC_PERIPH_CLOCK = MAKE_VALUE(0x40, 28), /*!< pwc periph clock */ + CRM_DAC_PERIPH_CLOCK = MAKE_VALUE(0x40, 29), /*!< dac periph clock */ + CRM_UART7_PERIPH_CLOCK = MAKE_VALUE(0x40, 30), /*!< uart7 periph clock */ + CRM_UART8_PERIPH_CLOCK = MAKE_VALUE(0x40, 31), /*!< uart8 periph clock */ + /* apb2 periph */ + CRM_TMR1_PERIPH_CLOCK = MAKE_VALUE(0x44, 0), /*!< tmr1 periph clock */ + CRM_TMR8_PERIPH_CLOCK = MAKE_VALUE(0x44, 1), /*!< tmr8 periph clock */ + CRM_USART1_PERIPH_CLOCK = MAKE_VALUE(0x44, 4), /*!< usart1 periph clock */ + CRM_USART6_PERIPH_CLOCK = MAKE_VALUE(0x44, 5), /*!< usart6 periph clock */ + CRM_ADC1_PERIPH_CLOCK = MAKE_VALUE(0x44, 8), /*!< adc1 periph clock */ + CRM_ADC2_PERIPH_CLOCK = MAKE_VALUE(0x44, 9), /*!< adc2 periph clock */ + CRM_ADC3_PERIPH_CLOCK = MAKE_VALUE(0x44, 10), /*!< adc3 periph clock */ + CRM_SPI1_PERIPH_CLOCK = MAKE_VALUE(0x44, 12), /*!< spi1 periph clock */ + CRM_SPI4_PERIPH_CLOCK = MAKE_VALUE(0x44, 13), /*!< spi4 periph clock */ + CRM_SCFG_PERIPH_CLOCK = MAKE_VALUE(0x44, 14), /*!< scfg periph clock */ + CRM_TMR9_PERIPH_CLOCK = MAKE_VALUE(0x44, 16), /*!< tmr9 periph clock */ + CRM_TMR10_PERIPH_CLOCK = MAKE_VALUE(0x44, 17), /*!< tmr10 periph clock */ + CRM_TMR11_PERIPH_CLOCK = MAKE_VALUE(0x44, 18), /*!< tmr11 periph clock */ + CRM_TMR20_PERIPH_CLOCK = MAKE_VALUE(0x44, 20), /*!< tmr20 periph clock */ + CRM_ACC_PERIPH_CLOCK = MAKE_VALUE(0x44, 29) /*!< acc periph clock */ #endif } crm_periph_clock_type; @@ -243,139 +242,138 @@ typedef enum /** * @brief crm periph reset */ -typedef enum -{ +typedef enum { #if defined (AT32F435xx) - /* ahb periph1 */ - CRM_GPIOA_PERIPH_RESET = MAKE_VALUE(0x10, 0), /*!< gpioa periph reset */ - CRM_GPIOB_PERIPH_RESET = MAKE_VALUE(0x10, 1), /*!< gpiob periph reset */ - CRM_GPIOC_PERIPH_RESET = MAKE_VALUE(0x10, 2), /*!< gpioc periph reset */ - CRM_GPIOD_PERIPH_RESET = MAKE_VALUE(0x10, 3), /*!< gpiod periph reset */ - CRM_GPIOE_PERIPH_RESET = MAKE_VALUE(0x10, 4), /*!< gpioe periph reset */ - CRM_GPIOF_PERIPH_RESET = MAKE_VALUE(0x10, 5), /*!< gpiof periph reset */ - CRM_GPIOG_PERIPH_RESET = MAKE_VALUE(0x10, 6), /*!< gpiog periph reset */ - CRM_GPIOH_PERIPH_RESET = MAKE_VALUE(0x10, 7), /*!< gpioh periph reset */ - CRM_CRC_PERIPH_RESET = MAKE_VALUE(0x10, 12), /*!< crc periph reset */ - CRM_EDMA_PERIPH_RESET = MAKE_VALUE(0x10, 21), /*!< edma periph reset */ - CRM_DMA1_PERIPH_RESET = MAKE_VALUE(0x10, 22), /*!< dma1 periph reset */ - CRM_DMA2_PERIPH_RESET = MAKE_VALUE(0x10, 24), /*!< dma2 periph reset */ - CRM_OTGFS2_PERIPH_RESET = MAKE_VALUE(0x10, 29), /*!< otgfs2 periph reset */ - /* ahb periph2 */ - CRM_DVP_PERIPH_RESET = MAKE_VALUE(0x14, 0), /*!< dvp periph reset */ - CRM_OTGFS1_PERIPH_RESET = MAKE_VALUE(0x14, 7), /*!< otgfs1 periph reset */ - CRM_SDIO1_PERIPH_RESET = MAKE_VALUE(0x14, 15), /*!< sdio1 periph reset */ - /* ahb periph3 */ - CRM_XMC_PERIPH_RESET = MAKE_VALUE(0x18, 0), /*!< xmc periph reset */ - CRM_QSPI1_PERIPH_RESET = MAKE_VALUE(0x18, 1), /*!< qspi1 periph reset */ - CRM_QSPI2_PERIPH_RESET = MAKE_VALUE(0x18, 14), /*!< qspi2 periph reset */ - CRM_SDIO2_PERIPH_RESET = MAKE_VALUE(0x18, 15), /*!< sdio2 periph reset */ - /* apb1 periph */ - CRM_TMR2_PERIPH_RESET = MAKE_VALUE(0x20, 0), /*!< tmr2 periph reset */ - CRM_TMR3_PERIPH_RESET = MAKE_VALUE(0x20, 1), /*!< tmr3 periph reset */ - CRM_TMR4_PERIPH_RESET = MAKE_VALUE(0x20, 2), /*!< tmr4 periph reset */ - CRM_TMR5_PERIPH_RESET = MAKE_VALUE(0x20, 3), /*!< tmr5 periph reset */ - CRM_TMR6_PERIPH_RESET = MAKE_VALUE(0x20, 4), /*!< tmr6 periph reset */ - CRM_TMR7_PERIPH_RESET = MAKE_VALUE(0x20, 5), /*!< tmr7 periph reset */ - CRM_TMR12_PERIPH_RESET = MAKE_VALUE(0x20, 6), /*!< tmr12 periph reset */ - CRM_TMR13_PERIPH_RESET = MAKE_VALUE(0x20, 7), /*!< tmr13 periph reset */ - CRM_TMR14_PERIPH_RESET = MAKE_VALUE(0x20, 8), /*!< tmr14 periph reset */ - CRM_WWDT_PERIPH_RESET = MAKE_VALUE(0x20, 11), /*!< wwdt periph reset */ - CRM_SPI2_PERIPH_RESET = MAKE_VALUE(0x20, 14), /*!< spi2 periph reset */ - CRM_SPI3_PERIPH_RESET = MAKE_VALUE(0x20, 15), /*!< spi3 periph reset */ - CRM_USART2_PERIPH_RESET = MAKE_VALUE(0x20, 17), /*!< usart2 periph reset */ - CRM_USART3_PERIPH_RESET = MAKE_VALUE(0x20, 18), /*!< usart3 periph reset */ - CRM_UART4_PERIPH_RESET = MAKE_VALUE(0x20, 19), /*!< uart4 periph reset */ - CRM_UART5_PERIPH_RESET = MAKE_VALUE(0x20, 20), /*!< uart5 periph reset */ - CRM_I2C1_PERIPH_RESET = MAKE_VALUE(0x20, 21), /*!< i2c1 periph reset */ - CRM_I2C2_PERIPH_RESET = MAKE_VALUE(0x20, 22), /*!< i2c2 periph reset */ - CRM_I2C3_PERIPH_RESET = MAKE_VALUE(0x20, 23), /*!< i2c3 periph reset */ - CRM_CAN1_PERIPH_RESET = MAKE_VALUE(0x20, 25), /*!< can1 periph reset */ - CRM_CAN2_PERIPH_RESET = MAKE_VALUE(0x20, 26), /*!< can2 periph reset */ - CRM_PWC_PERIPH_RESET = MAKE_VALUE(0x20, 28), /*!< pwc periph reset */ - CRM_DAC_PERIPH_RESET = MAKE_VALUE(0x20, 29), /*!< dac periph reset */ - CRM_UART7_PERIPH_RESET = MAKE_VALUE(0x20, 30), /*!< uart7 periph reset */ - CRM_UART8_PERIPH_RESET = MAKE_VALUE(0x20, 31), /*!< uart8 periph reset */ - /* apb2 periph */ - CRM_TMR1_PERIPH_RESET = MAKE_VALUE(0x24, 0), /*!< tmr1 periph reset */ - CRM_TMR8_PERIPH_RESET = MAKE_VALUE(0x24, 1), /*!< tmr8 periph reset */ - CRM_USART1_PERIPH_RESET = MAKE_VALUE(0x24, 4), /*!< usart1 periph reset */ - CRM_USART6_PERIPH_RESET = MAKE_VALUE(0x24, 5), /*!< usart6 periph reset */ - CRM_ADC_PERIPH_RESET = MAKE_VALUE(0x24, 8), /*!< adc periph reset */ - CRM_SPI1_PERIPH_RESET = MAKE_VALUE(0x24, 12), /*!< spi1 periph reset */ - CRM_SPI4_PERIPH_RESET = MAKE_VALUE(0x24, 13), /*!< spi4 periph reset */ - CRM_SCFG_PERIPH_RESET = MAKE_VALUE(0x24, 14), /*!< scfg periph reset */ - CRM_TMR9_PERIPH_RESET = MAKE_VALUE(0x24, 16), /*!< tmr9 periph reset */ - CRM_TMR10_PERIPH_RESET = MAKE_VALUE(0x24, 17), /*!< tmr10 periph reset */ - CRM_TMR11_PERIPH_RESET = MAKE_VALUE(0x24, 18), /*!< tmr11 periph reset */ - CRM_TMR20_PERIPH_RESET = MAKE_VALUE(0x24, 20), /*!< tmr20 periph reset */ - CRM_ACC_PERIPH_RESET = MAKE_VALUE(0x24, 29) /*!< acc periph reset */ + /* ahb periph1 */ + CRM_GPIOA_PERIPH_RESET = MAKE_VALUE(0x10, 0), /*!< gpioa periph reset */ + CRM_GPIOB_PERIPH_RESET = MAKE_VALUE(0x10, 1), /*!< gpiob periph reset */ + CRM_GPIOC_PERIPH_RESET = MAKE_VALUE(0x10, 2), /*!< gpioc periph reset */ + CRM_GPIOD_PERIPH_RESET = MAKE_VALUE(0x10, 3), /*!< gpiod periph reset */ + CRM_GPIOE_PERIPH_RESET = MAKE_VALUE(0x10, 4), /*!< gpioe periph reset */ + CRM_GPIOF_PERIPH_RESET = MAKE_VALUE(0x10, 5), /*!< gpiof periph reset */ + CRM_GPIOG_PERIPH_RESET = MAKE_VALUE(0x10, 6), /*!< gpiog periph reset */ + CRM_GPIOH_PERIPH_RESET = MAKE_VALUE(0x10, 7), /*!< gpioh periph reset */ + CRM_CRC_PERIPH_RESET = MAKE_VALUE(0x10, 12), /*!< crc periph reset */ + CRM_EDMA_PERIPH_RESET = MAKE_VALUE(0x10, 21), /*!< edma periph reset */ + CRM_DMA1_PERIPH_RESET = MAKE_VALUE(0x10, 22), /*!< dma1 periph reset */ + CRM_DMA2_PERIPH_RESET = MAKE_VALUE(0x10, 24), /*!< dma2 periph reset */ + CRM_OTGFS2_PERIPH_RESET = MAKE_VALUE(0x10, 29), /*!< otgfs2 periph reset */ + /* ahb periph2 */ + CRM_DVP_PERIPH_RESET = MAKE_VALUE(0x14, 0), /*!< dvp periph reset */ + CRM_OTGFS1_PERIPH_RESET = MAKE_VALUE(0x14, 7), /*!< otgfs1 periph reset */ + CRM_SDIO1_PERIPH_RESET = MAKE_VALUE(0x14, 15), /*!< sdio1 periph reset */ + /* ahb periph3 */ + CRM_XMC_PERIPH_RESET = MAKE_VALUE(0x18, 0), /*!< xmc periph reset */ + CRM_QSPI1_PERIPH_RESET = MAKE_VALUE(0x18, 1), /*!< qspi1 periph reset */ + CRM_QSPI2_PERIPH_RESET = MAKE_VALUE(0x18, 14), /*!< qspi2 periph reset */ + CRM_SDIO2_PERIPH_RESET = MAKE_VALUE(0x18, 15), /*!< sdio2 periph reset */ + /* apb1 periph */ + CRM_TMR2_PERIPH_RESET = MAKE_VALUE(0x20, 0), /*!< tmr2 periph reset */ + CRM_TMR3_PERIPH_RESET = MAKE_VALUE(0x20, 1), /*!< tmr3 periph reset */ + CRM_TMR4_PERIPH_RESET = MAKE_VALUE(0x20, 2), /*!< tmr4 periph reset */ + CRM_TMR5_PERIPH_RESET = MAKE_VALUE(0x20, 3), /*!< tmr5 periph reset */ + CRM_TMR6_PERIPH_RESET = MAKE_VALUE(0x20, 4), /*!< tmr6 periph reset */ + CRM_TMR7_PERIPH_RESET = MAKE_VALUE(0x20, 5), /*!< tmr7 periph reset */ + CRM_TMR12_PERIPH_RESET = MAKE_VALUE(0x20, 6), /*!< tmr12 periph reset */ + CRM_TMR13_PERIPH_RESET = MAKE_VALUE(0x20, 7), /*!< tmr13 periph reset */ + CRM_TMR14_PERIPH_RESET = MAKE_VALUE(0x20, 8), /*!< tmr14 periph reset */ + CRM_WWDT_PERIPH_RESET = MAKE_VALUE(0x20, 11), /*!< wwdt periph reset */ + CRM_SPI2_PERIPH_RESET = MAKE_VALUE(0x20, 14), /*!< spi2 periph reset */ + CRM_SPI3_PERIPH_RESET = MAKE_VALUE(0x20, 15), /*!< spi3 periph reset */ + CRM_USART2_PERIPH_RESET = MAKE_VALUE(0x20, 17), /*!< usart2 periph reset */ + CRM_USART3_PERIPH_RESET = MAKE_VALUE(0x20, 18), /*!< usart3 periph reset */ + CRM_UART4_PERIPH_RESET = MAKE_VALUE(0x20, 19), /*!< uart4 periph reset */ + CRM_UART5_PERIPH_RESET = MAKE_VALUE(0x20, 20), /*!< uart5 periph reset */ + CRM_I2C1_PERIPH_RESET = MAKE_VALUE(0x20, 21), /*!< i2c1 periph reset */ + CRM_I2C2_PERIPH_RESET = MAKE_VALUE(0x20, 22), /*!< i2c2 periph reset */ + CRM_I2C3_PERIPH_RESET = MAKE_VALUE(0x20, 23), /*!< i2c3 periph reset */ + CRM_CAN1_PERIPH_RESET = MAKE_VALUE(0x20, 25), /*!< can1 periph reset */ + CRM_CAN2_PERIPH_RESET = MAKE_VALUE(0x20, 26), /*!< can2 periph reset */ + CRM_PWC_PERIPH_RESET = MAKE_VALUE(0x20, 28), /*!< pwc periph reset */ + CRM_DAC_PERIPH_RESET = MAKE_VALUE(0x20, 29), /*!< dac periph reset */ + CRM_UART7_PERIPH_RESET = MAKE_VALUE(0x20, 30), /*!< uart7 periph reset */ + CRM_UART8_PERIPH_RESET = MAKE_VALUE(0x20, 31), /*!< uart8 periph reset */ + /* apb2 periph */ + CRM_TMR1_PERIPH_RESET = MAKE_VALUE(0x24, 0), /*!< tmr1 periph reset */ + CRM_TMR8_PERIPH_RESET = MAKE_VALUE(0x24, 1), /*!< tmr8 periph reset */ + CRM_USART1_PERIPH_RESET = MAKE_VALUE(0x24, 4), /*!< usart1 periph reset */ + CRM_USART6_PERIPH_RESET = MAKE_VALUE(0x24, 5), /*!< usart6 periph reset */ + CRM_ADC_PERIPH_RESET = MAKE_VALUE(0x24, 8), /*!< adc periph reset */ + CRM_SPI1_PERIPH_RESET = MAKE_VALUE(0x24, 12), /*!< spi1 periph reset */ + CRM_SPI4_PERIPH_RESET = MAKE_VALUE(0x24, 13), /*!< spi4 periph reset */ + CRM_SCFG_PERIPH_RESET = MAKE_VALUE(0x24, 14), /*!< scfg periph reset */ + CRM_TMR9_PERIPH_RESET = MAKE_VALUE(0x24, 16), /*!< tmr9 periph reset */ + CRM_TMR10_PERIPH_RESET = MAKE_VALUE(0x24, 17), /*!< tmr10 periph reset */ + CRM_TMR11_PERIPH_RESET = MAKE_VALUE(0x24, 18), /*!< tmr11 periph reset */ + CRM_TMR20_PERIPH_RESET = MAKE_VALUE(0x24, 20), /*!< tmr20 periph reset */ + CRM_ACC_PERIPH_RESET = MAKE_VALUE(0x24, 29) /*!< acc periph reset */ #endif #if defined (AT32F437xx) - /* ahb periph1 */ - CRM_GPIOA_PERIPH_RESET = MAKE_VALUE(0x10, 0), /*!< gpioa periph reset */ - CRM_GPIOB_PERIPH_RESET = MAKE_VALUE(0x10, 1), /*!< gpiob periph reset */ - CRM_GPIOC_PERIPH_RESET = MAKE_VALUE(0x10, 2), /*!< gpioc periph reset */ - CRM_GPIOD_PERIPH_RESET = MAKE_VALUE(0x10, 3), /*!< gpiod periph reset */ - CRM_GPIOE_PERIPH_RESET = MAKE_VALUE(0x10, 4), /*!< gpioe periph reset */ - CRM_GPIOF_PERIPH_RESET = MAKE_VALUE(0x10, 5), /*!< gpiof periph reset */ - CRM_GPIOG_PERIPH_RESET = MAKE_VALUE(0x10, 6), /*!< gpiog periph reset */ - CRM_GPIOH_PERIPH_RESET = MAKE_VALUE(0x10, 7), /*!< gpioh periph reset */ - CRM_CRC_PERIPH_RESET = MAKE_VALUE(0x10, 12), /*!< crc periph reset */ - CRM_EDMA_PERIPH_RESET = MAKE_VALUE(0x10, 21), /*!< edma periph reset */ - CRM_DMA1_PERIPH_RESET = MAKE_VALUE(0x10, 22), /*!< dma1 periph reset */ - CRM_DMA2_PERIPH_RESET = MAKE_VALUE(0x10, 24), /*!< dma2 periph reset */ - CRM_EMAC_PERIPH_RESET = MAKE_VALUE(0x10, 25), /*!< emac periph reset */ - CRM_OTGFS2_PERIPH_RESET = MAKE_VALUE(0x10, 29), /*!< otgfs2 periph reset */ - /* ahb periph2 */ - CRM_DVP_PERIPH_RESET = MAKE_VALUE(0x14, 0), /*!< dvp periph reset */ - CRM_OTGFS1_PERIPH_RESET = MAKE_VALUE(0x14, 7), /*!< otgfs1 periph reset */ - CRM_SDIO1_PERIPH_RESET = MAKE_VALUE(0x14, 15), /*!< sdio1 periph reset */ - /* ahb periph3 */ - CRM_XMC_PERIPH_RESET = MAKE_VALUE(0x18, 0), /*!< xmc periph reset */ - CRM_QSPI1_PERIPH_RESET = MAKE_VALUE(0x18, 1), /*!< qspi1 periph reset */ - CRM_QSPI2_PERIPH_RESET = MAKE_VALUE(0x18, 14), /*!< qspi2 periph reset */ - CRM_SDIO2_PERIPH_RESET = MAKE_VALUE(0x18, 15), /*!< sdio2 periph reset */ - /* apb1 periph */ - CRM_TMR2_PERIPH_RESET = MAKE_VALUE(0x20, 0), /*!< tmr2 periph reset */ - CRM_TMR3_PERIPH_RESET = MAKE_VALUE(0x20, 1), /*!< tmr3 periph reset */ - CRM_TMR4_PERIPH_RESET = MAKE_VALUE(0x20, 2), /*!< tmr4 periph reset */ - CRM_TMR5_PERIPH_RESET = MAKE_VALUE(0x20, 3), /*!< tmr5 periph reset */ - CRM_TMR6_PERIPH_RESET = MAKE_VALUE(0x20, 4), /*!< tmr6 periph reset */ - CRM_TMR7_PERIPH_RESET = MAKE_VALUE(0x20, 5), /*!< tmr7 periph reset */ - CRM_TMR12_PERIPH_RESET = MAKE_VALUE(0x20, 6), /*!< tmr12 periph reset */ - CRM_TMR13_PERIPH_RESET = MAKE_VALUE(0x20, 7), /*!< tmr13 periph reset */ - CRM_TMR14_PERIPH_RESET = MAKE_VALUE(0x20, 8), /*!< tmr14 periph reset */ - CRM_WWDT_PERIPH_RESET = MAKE_VALUE(0x20, 11), /*!< wwdt periph reset */ - CRM_SPI2_PERIPH_RESET = MAKE_VALUE(0x20, 14), /*!< spi2 periph reset */ - CRM_SPI3_PERIPH_RESET = MAKE_VALUE(0x20, 15), /*!< spi3 periph reset */ - CRM_USART2_PERIPH_RESET = MAKE_VALUE(0x20, 17), /*!< usart2 periph reset */ - CRM_USART3_PERIPH_RESET = MAKE_VALUE(0x20, 18), /*!< usart3 periph reset */ - CRM_UART4_PERIPH_RESET = MAKE_VALUE(0x20, 19), /*!< uart4 periph reset */ - CRM_UART5_PERIPH_RESET = MAKE_VALUE(0x20, 20), /*!< uart5 periph reset */ - CRM_I2C1_PERIPH_RESET = MAKE_VALUE(0x20, 21), /*!< i2c1 periph reset */ - CRM_I2C2_PERIPH_RESET = MAKE_VALUE(0x20, 22), /*!< i2c2 periph reset */ - CRM_I2C3_PERIPH_RESET = MAKE_VALUE(0x20, 23), /*!< i2c3 periph reset */ - CRM_CAN1_PERIPH_RESET = MAKE_VALUE(0x20, 25), /*!< can1 periph reset */ - CRM_CAN2_PERIPH_RESET = MAKE_VALUE(0x20, 26), /*!< can2 periph reset */ - CRM_PWC_PERIPH_RESET = MAKE_VALUE(0x20, 28), /*!< pwc periph reset */ - CRM_DAC_PERIPH_RESET = MAKE_VALUE(0x20, 29), /*!< dac periph reset */ - CRM_UART7_PERIPH_RESET = MAKE_VALUE(0x20, 30), /*!< uart7 periph reset */ - CRM_UART8_PERIPH_RESET = MAKE_VALUE(0x20, 31), /*!< uart8 periph reset */ - /* apb2 periph */ - CRM_TMR1_PERIPH_RESET = MAKE_VALUE(0x24, 0), /*!< tmr1 periph reset */ - CRM_TMR8_PERIPH_RESET = MAKE_VALUE(0x24, 1), /*!< tmr8 periph reset */ - CRM_USART1_PERIPH_RESET = MAKE_VALUE(0x24, 4), /*!< usart1 periph reset */ - CRM_USART6_PERIPH_RESET = MAKE_VALUE(0x24, 5), /*!< usart6 periph reset */ - CRM_ADC_PERIPH_RESET = MAKE_VALUE(0x24, 8), /*!< adc periph reset */ - CRM_SPI1_PERIPH_RESET = MAKE_VALUE(0x24, 12), /*!< spi1 periph reset */ - CRM_SPI4_PERIPH_RESET = MAKE_VALUE(0x24, 13), /*!< spi4 periph reset */ - CRM_SCFG_PERIPH_RESET = MAKE_VALUE(0x24, 14), /*!< scfg periph reset */ - CRM_TMR9_PERIPH_RESET = MAKE_VALUE(0x24, 16), /*!< tmr9 periph reset */ - CRM_TMR10_PERIPH_RESET = MAKE_VALUE(0x24, 17), /*!< tmr10 periph reset */ - CRM_TMR11_PERIPH_RESET = MAKE_VALUE(0x24, 18), /*!< tmr11 periph reset */ - CRM_TMR20_PERIPH_RESET = MAKE_VALUE(0x24, 20), /*!< tmr20 periph reset */ - CRM_ACC_PERIPH_RESET = MAKE_VALUE(0x24, 29) /*!< acc periph reset */ + /* ahb periph1 */ + CRM_GPIOA_PERIPH_RESET = MAKE_VALUE(0x10, 0), /*!< gpioa periph reset */ + CRM_GPIOB_PERIPH_RESET = MAKE_VALUE(0x10, 1), /*!< gpiob periph reset */ + CRM_GPIOC_PERIPH_RESET = MAKE_VALUE(0x10, 2), /*!< gpioc periph reset */ + CRM_GPIOD_PERIPH_RESET = MAKE_VALUE(0x10, 3), /*!< gpiod periph reset */ + CRM_GPIOE_PERIPH_RESET = MAKE_VALUE(0x10, 4), /*!< gpioe periph reset */ + CRM_GPIOF_PERIPH_RESET = MAKE_VALUE(0x10, 5), /*!< gpiof periph reset */ + CRM_GPIOG_PERIPH_RESET = MAKE_VALUE(0x10, 6), /*!< gpiog periph reset */ + CRM_GPIOH_PERIPH_RESET = MAKE_VALUE(0x10, 7), /*!< gpioh periph reset */ + CRM_CRC_PERIPH_RESET = MAKE_VALUE(0x10, 12), /*!< crc periph reset */ + CRM_EDMA_PERIPH_RESET = MAKE_VALUE(0x10, 21), /*!< edma periph reset */ + CRM_DMA1_PERIPH_RESET = MAKE_VALUE(0x10, 22), /*!< dma1 periph reset */ + CRM_DMA2_PERIPH_RESET = MAKE_VALUE(0x10, 24), /*!< dma2 periph reset */ + CRM_EMAC_PERIPH_RESET = MAKE_VALUE(0x10, 25), /*!< emac periph reset */ + CRM_OTGFS2_PERIPH_RESET = MAKE_VALUE(0x10, 29), /*!< otgfs2 periph reset */ + /* ahb periph2 */ + CRM_DVP_PERIPH_RESET = MAKE_VALUE(0x14, 0), /*!< dvp periph reset */ + CRM_OTGFS1_PERIPH_RESET = MAKE_VALUE(0x14, 7), /*!< otgfs1 periph reset */ + CRM_SDIO1_PERIPH_RESET = MAKE_VALUE(0x14, 15), /*!< sdio1 periph reset */ + /* ahb periph3 */ + CRM_XMC_PERIPH_RESET = MAKE_VALUE(0x18, 0), /*!< xmc periph reset */ + CRM_QSPI1_PERIPH_RESET = MAKE_VALUE(0x18, 1), /*!< qspi1 periph reset */ + CRM_QSPI2_PERIPH_RESET = MAKE_VALUE(0x18, 14), /*!< qspi2 periph reset */ + CRM_SDIO2_PERIPH_RESET = MAKE_VALUE(0x18, 15), /*!< sdio2 periph reset */ + /* apb1 periph */ + CRM_TMR2_PERIPH_RESET = MAKE_VALUE(0x20, 0), /*!< tmr2 periph reset */ + CRM_TMR3_PERIPH_RESET = MAKE_VALUE(0x20, 1), /*!< tmr3 periph reset */ + CRM_TMR4_PERIPH_RESET = MAKE_VALUE(0x20, 2), /*!< tmr4 periph reset */ + CRM_TMR5_PERIPH_RESET = MAKE_VALUE(0x20, 3), /*!< tmr5 periph reset */ + CRM_TMR6_PERIPH_RESET = MAKE_VALUE(0x20, 4), /*!< tmr6 periph reset */ + CRM_TMR7_PERIPH_RESET = MAKE_VALUE(0x20, 5), /*!< tmr7 periph reset */ + CRM_TMR12_PERIPH_RESET = MAKE_VALUE(0x20, 6), /*!< tmr12 periph reset */ + CRM_TMR13_PERIPH_RESET = MAKE_VALUE(0x20, 7), /*!< tmr13 periph reset */ + CRM_TMR14_PERIPH_RESET = MAKE_VALUE(0x20, 8), /*!< tmr14 periph reset */ + CRM_WWDT_PERIPH_RESET = MAKE_VALUE(0x20, 11), /*!< wwdt periph reset */ + CRM_SPI2_PERIPH_RESET = MAKE_VALUE(0x20, 14), /*!< spi2 periph reset */ + CRM_SPI3_PERIPH_RESET = MAKE_VALUE(0x20, 15), /*!< spi3 periph reset */ + CRM_USART2_PERIPH_RESET = MAKE_VALUE(0x20, 17), /*!< usart2 periph reset */ + CRM_USART3_PERIPH_RESET = MAKE_VALUE(0x20, 18), /*!< usart3 periph reset */ + CRM_UART4_PERIPH_RESET = MAKE_VALUE(0x20, 19), /*!< uart4 periph reset */ + CRM_UART5_PERIPH_RESET = MAKE_VALUE(0x20, 20), /*!< uart5 periph reset */ + CRM_I2C1_PERIPH_RESET = MAKE_VALUE(0x20, 21), /*!< i2c1 periph reset */ + CRM_I2C2_PERIPH_RESET = MAKE_VALUE(0x20, 22), /*!< i2c2 periph reset */ + CRM_I2C3_PERIPH_RESET = MAKE_VALUE(0x20, 23), /*!< i2c3 periph reset */ + CRM_CAN1_PERIPH_RESET = MAKE_VALUE(0x20, 25), /*!< can1 periph reset */ + CRM_CAN2_PERIPH_RESET = MAKE_VALUE(0x20, 26), /*!< can2 periph reset */ + CRM_PWC_PERIPH_RESET = MAKE_VALUE(0x20, 28), /*!< pwc periph reset */ + CRM_DAC_PERIPH_RESET = MAKE_VALUE(0x20, 29), /*!< dac periph reset */ + CRM_UART7_PERIPH_RESET = MAKE_VALUE(0x20, 30), /*!< uart7 periph reset */ + CRM_UART8_PERIPH_RESET = MAKE_VALUE(0x20, 31), /*!< uart8 periph reset */ + /* apb2 periph */ + CRM_TMR1_PERIPH_RESET = MAKE_VALUE(0x24, 0), /*!< tmr1 periph reset */ + CRM_TMR8_PERIPH_RESET = MAKE_VALUE(0x24, 1), /*!< tmr8 periph reset */ + CRM_USART1_PERIPH_RESET = MAKE_VALUE(0x24, 4), /*!< usart1 periph reset */ + CRM_USART6_PERIPH_RESET = MAKE_VALUE(0x24, 5), /*!< usart6 periph reset */ + CRM_ADC_PERIPH_RESET = MAKE_VALUE(0x24, 8), /*!< adc periph reset */ + CRM_SPI1_PERIPH_RESET = MAKE_VALUE(0x24, 12), /*!< spi1 periph reset */ + CRM_SPI4_PERIPH_RESET = MAKE_VALUE(0x24, 13), /*!< spi4 periph reset */ + CRM_SCFG_PERIPH_RESET = MAKE_VALUE(0x24, 14), /*!< scfg periph reset */ + CRM_TMR9_PERIPH_RESET = MAKE_VALUE(0x24, 16), /*!< tmr9 periph reset */ + CRM_TMR10_PERIPH_RESET = MAKE_VALUE(0x24, 17), /*!< tmr10 periph reset */ + CRM_TMR11_PERIPH_RESET = MAKE_VALUE(0x24, 18), /*!< tmr11 periph reset */ + CRM_TMR20_PERIPH_RESET = MAKE_VALUE(0x24, 20), /*!< tmr20 periph reset */ + CRM_ACC_PERIPH_RESET = MAKE_VALUE(0x24, 29) /*!< acc periph reset */ #endif } crm_periph_reset_type; @@ -383,152 +381,151 @@ typedef enum /** * @brief crm periph clock in low power mode */ -typedef enum -{ +typedef enum { #if defined (AT32F435xx) - /* ahb periph1 */ - CRM_GPIOA_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 0), /*!< gpioa sleep mode periph clock */ - CRM_GPIOB_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 1), /*!< gpiob sleep mode periph clock */ - CRM_GPIOC_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 2), /*!< gpioc sleep mode periph clock */ - CRM_GPIOD_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 3), /*!< gpiod sleep mode periph clock */ - CRM_GPIOE_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 4), /*!< gpioe sleep mode periph clock */ - CRM_GPIOF_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 5), /*!< gpiof sleep mode periph clock */ - CRM_GPIOG_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 6), /*!< gpiog sleep mode periph clock */ - CRM_GPIOH_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 7), /*!< gpioh sleep mode periph clock */ - CRM_CRC_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 12), /*!< crc sleep mode periph clock */ - CRM_FLASH_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 15), /*!< flash sleep mode periph clock */ - CRM_SRAM1_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 16), /*!< sram1 sleep mode periph clock */ - CRM_SRAM2_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 17), /*!< sram2 sleep mode periph clock */ - CRM_EDMA_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 21), /*!< edma sleep mode periph clock */ - CRM_DMA1_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 22), /*!< dma1 sleep mode periph clock */ - CRM_DMA2_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 24), /*!< dma2 sleep mode periph clock */ - CRM_OTGFS2_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 29), /*!< otgfs2 sleep mode periph clock */ - /* ahb periph2 */ - CRM_DVP_PERIPH_LOWPOWER = MAKE_VALUE(0x54, 0), /*!< dvp sleep mode periph clock */ - CRM_OTGFS1_PERIPH_LOWPOWER = MAKE_VALUE(0x54, 7), /*!< otgfs1 sleep mode periph clock */ - CRM_SDIO1_PERIPH_LOWPOWER = MAKE_VALUE(0x54, 15), /*!< sdio1 sleep mode periph clock */ - /* ahb periph3 */ - CRM_XMC_PERIPH_LOWPOWER = MAKE_VALUE(0x58, 0), /*!< xmc sleep mode periph clock */ - CRM_QSPI1_PERIPH_LOWPOWER = MAKE_VALUE(0x58, 1), /*!< qspi1 sleep mode periph clock */ - CRM_QSPI2_PERIPH_LOWPOWER = MAKE_VALUE(0x58, 14), /*!< qspi2 sleep mode periph clock */ - CRM_SDIO2_PERIPH_LOWPOWER = MAKE_VALUE(0x58, 15), /*!< sdio2 sleep mode periph clock */ - /* apb1 periph */ - CRM_TMR2_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 0), /*!< tmr2 sleep mode periph clock */ - CRM_TMR3_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 1), /*!< tmr3 sleep mode periph clock */ - CRM_TMR4_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 2), /*!< tmr4 sleep mode periph clock */ - CRM_TMR5_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 3), /*!< tmr5 sleep mode periph clock */ - CRM_TMR6_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 4), /*!< tmr6 sleep mode periph clock */ - CRM_TMR7_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 5), /*!< tmr7 sleep mode periph clock */ - CRM_TMR12_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 6), /*!< tmr12 sleep mode periph clock */ - CRM_TMR13_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 7), /*!< tmr13 sleep mode periph clock */ - CRM_TMR14_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 8), /*!< tmr14 sleep mode periph clock */ - CRM_WWDT_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 11), /*!< wwdt sleep mode periph clock */ - CRM_SPI2_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 14), /*!< spi2 sleep mode periph clock */ - CRM_SPI3_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 15), /*!< spi3 sleep mode periph clock */ - CRM_USART2_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 17), /*!< usart2 sleep mode periph clock */ - CRM_USART3_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 18), /*!< usart3 sleep mode periph clock */ - CRM_UART4_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 19), /*!< uart4 sleep mode periph clock */ - CRM_UART5_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 20), /*!< uart5 sleep mode periph clock */ - CRM_I2C1_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 21), /*!< i2c1 sleep mode periph clock */ - CRM_I2C2_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 22), /*!< i2c2 sleep mode periph clock */ - CRM_I2C3_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 23), /*!< i2c3 sleep mode periph clock */ - CRM_CAN1_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 25), /*!< can1 sleep mode periph clock */ - CRM_CAN2_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 26), /*!< can2 sleep mode periph clock */ - CRM_PWC_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 28), /*!< pwc sleep mode periph clock */ - CRM_DAC_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 29), /*!< dac sleep mode periph clock */ - CRM_UART7_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 30), /*!< uart7 sleep mode periph clock */ - CRM_UART8_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 31), /*!< uart8 sleep mode periph clock */ - /* apb2 periph */ - CRM_TMR1_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 0), /*!< tmr1 sleep mode periph clock */ - CRM_TMR8_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 1), /*!< tmr8 sleep mode periph clock */ - CRM_USART1_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 4), /*!< usart1 sleep mode periph clock */ - CRM_USART6_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 5), /*!< usart6 sleep mode periph clock */ - CRM_ADC1_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 8), /*!< adc1 sleep mode periph clock */ - CRM_ADC2_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 9), /*!< adc2 sleep mode periph clock */ - CRM_ADC3_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 10), /*!< adc3 sleep mode periph clock */ - CRM_SPI1_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 12), /*!< spi1 sleep mode periph clock */ - CRM_SPI4_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 13), /*!< spi4 sleep mode periph clock */ - CRM_SCFG_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 14), /*!< scfg sleep mode periph clock */ - CRM_TMR9_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 16), /*!< tmr9 sleep mode periph clock */ - CRM_TMR10_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 17), /*!< tmr10 sleep mode periph clock */ - CRM_TMR11_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 18), /*!< tmr11 sleep mode periph clock */ - CRM_TMR20_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 20), /*!< tmr20 sleep mode periph clock */ - CRM_ACC_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 29) /*!< acc sleep mode periph clock */ + /* ahb periph1 */ + CRM_GPIOA_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 0), /*!< gpioa sleep mode periph clock */ + CRM_GPIOB_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 1), /*!< gpiob sleep mode periph clock */ + CRM_GPIOC_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 2), /*!< gpioc sleep mode periph clock */ + CRM_GPIOD_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 3), /*!< gpiod sleep mode periph clock */ + CRM_GPIOE_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 4), /*!< gpioe sleep mode periph clock */ + CRM_GPIOF_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 5), /*!< gpiof sleep mode periph clock */ + CRM_GPIOG_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 6), /*!< gpiog sleep mode periph clock */ + CRM_GPIOH_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 7), /*!< gpioh sleep mode periph clock */ + CRM_CRC_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 12), /*!< crc sleep mode periph clock */ + CRM_FLASH_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 15), /*!< flash sleep mode periph clock */ + CRM_SRAM1_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 16), /*!< sram1 sleep mode periph clock */ + CRM_SRAM2_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 17), /*!< sram2 sleep mode periph clock */ + CRM_EDMA_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 21), /*!< edma sleep mode periph clock */ + CRM_DMA1_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 22), /*!< dma1 sleep mode periph clock */ + CRM_DMA2_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 24), /*!< dma2 sleep mode periph clock */ + CRM_OTGFS2_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 29), /*!< otgfs2 sleep mode periph clock */ + /* ahb periph2 */ + CRM_DVP_PERIPH_LOWPOWER = MAKE_VALUE(0x54, 0), /*!< dvp sleep mode periph clock */ + CRM_OTGFS1_PERIPH_LOWPOWER = MAKE_VALUE(0x54, 7), /*!< otgfs1 sleep mode periph clock */ + CRM_SDIO1_PERIPH_LOWPOWER = MAKE_VALUE(0x54, 15), /*!< sdio1 sleep mode periph clock */ + /* ahb periph3 */ + CRM_XMC_PERIPH_LOWPOWER = MAKE_VALUE(0x58, 0), /*!< xmc sleep mode periph clock */ + CRM_QSPI1_PERIPH_LOWPOWER = MAKE_VALUE(0x58, 1), /*!< qspi1 sleep mode periph clock */ + CRM_QSPI2_PERIPH_LOWPOWER = MAKE_VALUE(0x58, 14), /*!< qspi2 sleep mode periph clock */ + CRM_SDIO2_PERIPH_LOWPOWER = MAKE_VALUE(0x58, 15), /*!< sdio2 sleep mode periph clock */ + /* apb1 periph */ + CRM_TMR2_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 0), /*!< tmr2 sleep mode periph clock */ + CRM_TMR3_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 1), /*!< tmr3 sleep mode periph clock */ + CRM_TMR4_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 2), /*!< tmr4 sleep mode periph clock */ + CRM_TMR5_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 3), /*!< tmr5 sleep mode periph clock */ + CRM_TMR6_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 4), /*!< tmr6 sleep mode periph clock */ + CRM_TMR7_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 5), /*!< tmr7 sleep mode periph clock */ + CRM_TMR12_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 6), /*!< tmr12 sleep mode periph clock */ + CRM_TMR13_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 7), /*!< tmr13 sleep mode periph clock */ + CRM_TMR14_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 8), /*!< tmr14 sleep mode periph clock */ + CRM_WWDT_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 11), /*!< wwdt sleep mode periph clock */ + CRM_SPI2_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 14), /*!< spi2 sleep mode periph clock */ + CRM_SPI3_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 15), /*!< spi3 sleep mode periph clock */ + CRM_USART2_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 17), /*!< usart2 sleep mode periph clock */ + CRM_USART3_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 18), /*!< usart3 sleep mode periph clock */ + CRM_UART4_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 19), /*!< uart4 sleep mode periph clock */ + CRM_UART5_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 20), /*!< uart5 sleep mode periph clock */ + CRM_I2C1_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 21), /*!< i2c1 sleep mode periph clock */ + CRM_I2C2_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 22), /*!< i2c2 sleep mode periph clock */ + CRM_I2C3_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 23), /*!< i2c3 sleep mode periph clock */ + CRM_CAN1_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 25), /*!< can1 sleep mode periph clock */ + CRM_CAN2_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 26), /*!< can2 sleep mode periph clock */ + CRM_PWC_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 28), /*!< pwc sleep mode periph clock */ + CRM_DAC_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 29), /*!< dac sleep mode periph clock */ + CRM_UART7_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 30), /*!< uart7 sleep mode periph clock */ + CRM_UART8_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 31), /*!< uart8 sleep mode periph clock */ + /* apb2 periph */ + CRM_TMR1_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 0), /*!< tmr1 sleep mode periph clock */ + CRM_TMR8_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 1), /*!< tmr8 sleep mode periph clock */ + CRM_USART1_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 4), /*!< usart1 sleep mode periph clock */ + CRM_USART6_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 5), /*!< usart6 sleep mode periph clock */ + CRM_ADC1_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 8), /*!< adc1 sleep mode periph clock */ + CRM_ADC2_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 9), /*!< adc2 sleep mode periph clock */ + CRM_ADC3_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 10), /*!< adc3 sleep mode periph clock */ + CRM_SPI1_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 12), /*!< spi1 sleep mode periph clock */ + CRM_SPI4_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 13), /*!< spi4 sleep mode periph clock */ + CRM_SCFG_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 14), /*!< scfg sleep mode periph clock */ + CRM_TMR9_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 16), /*!< tmr9 sleep mode periph clock */ + CRM_TMR10_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 17), /*!< tmr10 sleep mode periph clock */ + CRM_TMR11_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 18), /*!< tmr11 sleep mode periph clock */ + CRM_TMR20_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 20), /*!< tmr20 sleep mode periph clock */ + CRM_ACC_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 29) /*!< acc sleep mode periph clock */ #endif #if defined (AT32F437xx) - /* ahb periph1 */ - CRM_GPIOA_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 0), /*!< gpioa sleep mode periph clock */ - CRM_GPIOB_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 1), /*!< gpiob sleep mode periph clock */ - CRM_GPIOC_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 2), /*!< gpioc sleep mode periph clock */ - CRM_GPIOD_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 3), /*!< gpiod sleep mode periph clock */ - CRM_GPIOE_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 4), /*!< gpioe sleep mode periph clock */ - CRM_GPIOF_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 5), /*!< gpiof sleep mode periph clock */ - CRM_GPIOG_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 6), /*!< gpiog sleep mode periph clock */ - CRM_GPIOH_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 7), /*!< gpioh sleep mode periph clock */ - CRM_CRC_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 12), /*!< crc sleep mode periph clock */ - CRM_FLASH_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 15), /*!< flash sleep mode periph clock */ - CRM_SRAM1_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 16), /*!< sram1 sleep mode periph clock */ - CRM_SRAM2_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 17), /*!< sram2 sleep mode periph clock */ - CRM_EDMA_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 21), /*!< edma sleep mode periph clock */ - CRM_DMA1_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 22), /*!< dma1 sleep mode periph clock */ - CRM_DMA2_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 24), /*!< dma2 sleep mode periph clock */ - CRM_EMAC_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 25), /*!< emac sleep mode periph clock */ - CRM_EMACTX_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 26), /*!< emac tx sleep mode periph clock */ - CRM_EMACRX_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 27), /*!< emac rx sleep mode periph clock */ - CRM_EMACPTP_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 28), /*!< emac ptp sleep mode periph clock */ - CRM_OTGFS2_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 29), /*!< otgfs2 sleep mode periph clock */ - /* ahb periph2 */ - CRM_DVP_PERIPH_LOWPOWER = MAKE_VALUE(0x54, 0), /*!< dvp sleep mode periph clock */ - CRM_OTGFS1_PERIPH_LOWPOWER = MAKE_VALUE(0x54, 7), /*!< otgfs1 sleep mode periph clock */ - CRM_SDIO1_PERIPH_LOWPOWER = MAKE_VALUE(0x54, 15), /*!< sdio1 sleep mode periph clock */ - /* ahb periph3 */ - CRM_XMC_PERIPH_LOWPOWER = MAKE_VALUE(0x58, 0), /*!< xmc sleep mode periph clock */ - CRM_QSPI1_PERIPH_LOWPOWER = MAKE_VALUE(0x58, 1), /*!< qspi1 sleep mode periph clock */ - CRM_QSPI2_PERIPH_LOWPOWER = MAKE_VALUE(0x58, 14), /*!< qspi2 sleep mode periph clock */ - CRM_SDIO2_PERIPH_LOWPOWER = MAKE_VALUE(0x58, 15), /*!< sdio2 sleep mode periph clock */ - /* apb1 periph */ - CRM_TMR2_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 0), /*!< tmr2 sleep mode periph clock */ - CRM_TMR3_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 1), /*!< tmr3 sleep mode periph clock */ - CRM_TMR4_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 2), /*!< tmr4 sleep mode periph clock */ - CRM_TMR5_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 3), /*!< tmr5 sleep mode periph clock */ - CRM_TMR6_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 4), /*!< tmr6 sleep mode periph clock */ - CRM_TMR7_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 5), /*!< tmr7 sleep mode periph clock */ - CRM_TMR12_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 6), /*!< tmr12 sleep mode periph clock */ - CRM_TMR13_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 7), /*!< tmr13 sleep mode periph clock */ - CRM_TMR14_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 8), /*!< tmr14 sleep mode periph clock */ - CRM_WWDT_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 11), /*!< wwdt sleep mode periph clock */ - CRM_SPI2_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 14), /*!< spi2 sleep mode periph clock */ - CRM_SPI3_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 15), /*!< spi3 sleep mode periph clock */ - CRM_USART2_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 17), /*!< usart2 sleep mode periph clock */ - CRM_USART3_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 18), /*!< usart3 sleep mode periph clock */ - CRM_UART4_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 19), /*!< uart4 sleep mode periph clock */ - CRM_UART5_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 20), /*!< uart5 sleep mode periph clock */ - CRM_I2C1_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 21), /*!< i2c1 sleep mode periph clock */ - CRM_I2C2_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 22), /*!< i2c2 sleep mode periph clock */ - CRM_I2C3_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 23), /*!< i2c3 sleep mode periph clock */ - CRM_CAN1_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 25), /*!< can1 sleep mode periph clock */ - CRM_CAN2_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 26), /*!< can2 sleep mode periph clock */ - CRM_PWC_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 28), /*!< pwc sleep mode periph clock */ - CRM_DAC_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 29), /*!< dac sleep mode periph clock */ - CRM_UART7_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 30), /*!< uart7 sleep mode periph clock */ - CRM_UART8_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 31), /*!< uart8 sleep mode periph clock */ - /* apb2 periph */ - CRM_TMR1_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 0), /*!< tmr1 sleep mode periph clock */ - CRM_TMR8_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 1), /*!< tmr8 sleep mode periph clock */ - CRM_USART1_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 4), /*!< usart1 sleep mode periph clock */ - CRM_USART6_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 5), /*!< usart6 sleep mode periph clock */ - CRM_ADC1_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 8), /*!< adc1 sleep mode periph clock */ - CRM_ADC2_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 9), /*!< adc2 sleep mode periph clock */ - CRM_ADC3_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 10), /*!< adc3 sleep mode periph clock */ - CRM_SPI1_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 12), /*!< spi1 sleep mode periph clock */ - CRM_SPI4_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 13), /*!< spi4 sleep mode periph clock */ - CRM_SCFG_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 14), /*!< scfg sleep mode periph clock */ - CRM_TMR9_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 16), /*!< tmr9 sleep mode periph clock */ - CRM_TMR10_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 17), /*!< tmr10 sleep mode periph clock */ - CRM_TMR11_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 18), /*!< tmr11 sleep mode periph clock */ - CRM_TMR20_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 20), /*!< tmr20 sleep mode periph clock */ - CRM_ACC_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 29) /*!< acc sleep mode periph clock */ + /* ahb periph1 */ + CRM_GPIOA_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 0), /*!< gpioa sleep mode periph clock */ + CRM_GPIOB_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 1), /*!< gpiob sleep mode periph clock */ + CRM_GPIOC_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 2), /*!< gpioc sleep mode periph clock */ + CRM_GPIOD_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 3), /*!< gpiod sleep mode periph clock */ + CRM_GPIOE_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 4), /*!< gpioe sleep mode periph clock */ + CRM_GPIOF_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 5), /*!< gpiof sleep mode periph clock */ + CRM_GPIOG_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 6), /*!< gpiog sleep mode periph clock */ + CRM_GPIOH_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 7), /*!< gpioh sleep mode periph clock */ + CRM_CRC_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 12), /*!< crc sleep mode periph clock */ + CRM_FLASH_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 15), /*!< flash sleep mode periph clock */ + CRM_SRAM1_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 16), /*!< sram1 sleep mode periph clock */ + CRM_SRAM2_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 17), /*!< sram2 sleep mode periph clock */ + CRM_EDMA_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 21), /*!< edma sleep mode periph clock */ + CRM_DMA1_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 22), /*!< dma1 sleep mode periph clock */ + CRM_DMA2_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 24), /*!< dma2 sleep mode periph clock */ + CRM_EMAC_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 25), /*!< emac sleep mode periph clock */ + CRM_EMACTX_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 26), /*!< emac tx sleep mode periph clock */ + CRM_EMACRX_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 27), /*!< emac rx sleep mode periph clock */ + CRM_EMACPTP_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 28), /*!< emac ptp sleep mode periph clock */ + CRM_OTGFS2_PERIPH_LOWPOWER = MAKE_VALUE(0x50, 29), /*!< otgfs2 sleep mode periph clock */ + /* ahb periph2 */ + CRM_DVP_PERIPH_LOWPOWER = MAKE_VALUE(0x54, 0), /*!< dvp sleep mode periph clock */ + CRM_OTGFS1_PERIPH_LOWPOWER = MAKE_VALUE(0x54, 7), /*!< otgfs1 sleep mode periph clock */ + CRM_SDIO1_PERIPH_LOWPOWER = MAKE_VALUE(0x54, 15), /*!< sdio1 sleep mode periph clock */ + /* ahb periph3 */ + CRM_XMC_PERIPH_LOWPOWER = MAKE_VALUE(0x58, 0), /*!< xmc sleep mode periph clock */ + CRM_QSPI1_PERIPH_LOWPOWER = MAKE_VALUE(0x58, 1), /*!< qspi1 sleep mode periph clock */ + CRM_QSPI2_PERIPH_LOWPOWER = MAKE_VALUE(0x58, 14), /*!< qspi2 sleep mode periph clock */ + CRM_SDIO2_PERIPH_LOWPOWER = MAKE_VALUE(0x58, 15), /*!< sdio2 sleep mode periph clock */ + /* apb1 periph */ + CRM_TMR2_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 0), /*!< tmr2 sleep mode periph clock */ + CRM_TMR3_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 1), /*!< tmr3 sleep mode periph clock */ + CRM_TMR4_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 2), /*!< tmr4 sleep mode periph clock */ + CRM_TMR5_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 3), /*!< tmr5 sleep mode periph clock */ + CRM_TMR6_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 4), /*!< tmr6 sleep mode periph clock */ + CRM_TMR7_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 5), /*!< tmr7 sleep mode periph clock */ + CRM_TMR12_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 6), /*!< tmr12 sleep mode periph clock */ + CRM_TMR13_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 7), /*!< tmr13 sleep mode periph clock */ + CRM_TMR14_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 8), /*!< tmr14 sleep mode periph clock */ + CRM_WWDT_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 11), /*!< wwdt sleep mode periph clock */ + CRM_SPI2_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 14), /*!< spi2 sleep mode periph clock */ + CRM_SPI3_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 15), /*!< spi3 sleep mode periph clock */ + CRM_USART2_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 17), /*!< usart2 sleep mode periph clock */ + CRM_USART3_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 18), /*!< usart3 sleep mode periph clock */ + CRM_UART4_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 19), /*!< uart4 sleep mode periph clock */ + CRM_UART5_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 20), /*!< uart5 sleep mode periph clock */ + CRM_I2C1_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 21), /*!< i2c1 sleep mode periph clock */ + CRM_I2C2_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 22), /*!< i2c2 sleep mode periph clock */ + CRM_I2C3_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 23), /*!< i2c3 sleep mode periph clock */ + CRM_CAN1_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 25), /*!< can1 sleep mode periph clock */ + CRM_CAN2_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 26), /*!< can2 sleep mode periph clock */ + CRM_PWC_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 28), /*!< pwc sleep mode periph clock */ + CRM_DAC_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 29), /*!< dac sleep mode periph clock */ + CRM_UART7_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 30), /*!< uart7 sleep mode periph clock */ + CRM_UART8_PERIPH_LOWPOWER = MAKE_VALUE(0x60, 31), /*!< uart8 sleep mode periph clock */ + /* apb2 periph */ + CRM_TMR1_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 0), /*!< tmr1 sleep mode periph clock */ + CRM_TMR8_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 1), /*!< tmr8 sleep mode periph clock */ + CRM_USART1_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 4), /*!< usart1 sleep mode periph clock */ + CRM_USART6_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 5), /*!< usart6 sleep mode periph clock */ + CRM_ADC1_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 8), /*!< adc1 sleep mode periph clock */ + CRM_ADC2_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 9), /*!< adc2 sleep mode periph clock */ + CRM_ADC3_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 10), /*!< adc3 sleep mode periph clock */ + CRM_SPI1_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 12), /*!< spi1 sleep mode periph clock */ + CRM_SPI4_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 13), /*!< spi4 sleep mode periph clock */ + CRM_SCFG_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 14), /*!< scfg sleep mode periph clock */ + CRM_TMR9_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 16), /*!< tmr9 sleep mode periph clock */ + CRM_TMR10_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 17), /*!< tmr10 sleep mode periph clock */ + CRM_TMR11_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 18), /*!< tmr11 sleep mode periph clock */ + CRM_TMR20_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 20), /*!< tmr20 sleep mode periph clock */ + CRM_ACC_PERIPH_LOWPOWER = MAKE_VALUE(0x64, 29) /*!< acc sleep mode periph clock */ #endif } crm_periph_clock_lowpower_type; @@ -536,974 +533,904 @@ typedef enum /** * @brief crm pll clock source */ -typedef enum -{ - CRM_PLL_SOURCE_HICK = 0x00, /*!< high speed internal clock as pll reference clock source */ - CRM_PLL_SOURCE_HEXT = 0x01 /*!< high speed external crystal as pll reference clock source */ +typedef enum { + CRM_PLL_SOURCE_HICK = 0x00, /*!< high speed internal clock as pll reference clock source */ + CRM_PLL_SOURCE_HEXT = 0x01 /*!< high speed external crystal as pll reference clock source */ } crm_pll_clock_source_type; /** * @brief crm pll fr */ -typedef enum -{ - CRM_PLL_FR_1 = 0x00, /*!< pll post-division div1 */ - CRM_PLL_FR_2 = 0x01, /*!< pll post-division div2 */ - CRM_PLL_FR_4 = 0x02, /*!< pll post-division div4 */ - CRM_PLL_FR_8 = 0x03, /*!< pll post-division div8 */ - CRM_PLL_FR_16 = 0x04, /*!< pll post-division div16 */ - CRM_PLL_FR_32 = 0x05 /*!< pll post-division div32 */ +typedef enum { + CRM_PLL_FR_1 = 0x00, /*!< pll post-division div1 */ + CRM_PLL_FR_2 = 0x01, /*!< pll post-division div2 */ + CRM_PLL_FR_4 = 0x02, /*!< pll post-division div4 */ + CRM_PLL_FR_8 = 0x03, /*!< pll post-division div8 */ + CRM_PLL_FR_16 = 0x04, /*!< pll post-division div16 */ + CRM_PLL_FR_32 = 0x05 /*!< pll post-division div32 */ } crm_pll_fr_type; /** * @brief crm clock source */ -typedef enum -{ - CRM_CLOCK_SOURCE_HICK = 0x00, /*!< high speed internal clock */ - CRM_CLOCK_SOURCE_HEXT = 0x01, /*!< high speed external crystal */ - CRM_CLOCK_SOURCE_PLL = 0x02, /*!< phase locking loop */ - CRM_CLOCK_SOURCE_LEXT = 0x03, /*!< low speed external crystal */ - CRM_CLOCK_SOURCE_LICK = 0x04 /*!< low speed internal clock */ +typedef enum { + CRM_CLOCK_SOURCE_HICK = 0x00, /*!< high speed internal clock */ + CRM_CLOCK_SOURCE_HEXT = 0x01, /*!< high speed external crystal */ + CRM_CLOCK_SOURCE_PLL = 0x02, /*!< phase locking loop */ + CRM_CLOCK_SOURCE_LEXT = 0x03, /*!< low speed external crystal */ + CRM_CLOCK_SOURCE_LICK = 0x04 /*!< low speed internal clock */ } crm_clock_source_type; /** * @brief crm ahb division */ -typedef enum -{ - CRM_AHB_DIV_1 = 0x00, /*!< sclk div1 to ahbclk */ - CRM_AHB_DIV_2 = 0x08, /*!< sclk div2 to ahbclk */ - CRM_AHB_DIV_4 = 0x09, /*!< sclk div4 to ahbclk */ - CRM_AHB_DIV_8 = 0x0A, /*!< sclk div8 to ahbclk */ - CRM_AHB_DIV_16 = 0x0B, /*!< sclk div16 to ahbclk */ - CRM_AHB_DIV_64 = 0x0C, /*!< sclk div64 to ahbclk */ - CRM_AHB_DIV_128 = 0x0D, /*!< sclk div128 to ahbclk */ - CRM_AHB_DIV_256 = 0x0E, /*!< sclk div256 to ahbclk */ - CRM_AHB_DIV_512 = 0x0F /*!< sclk div512 to ahbclk */ +typedef enum { + CRM_AHB_DIV_1 = 0x00, /*!< sclk div1 to ahbclk */ + CRM_AHB_DIV_2 = 0x08, /*!< sclk div2 to ahbclk */ + CRM_AHB_DIV_4 = 0x09, /*!< sclk div4 to ahbclk */ + CRM_AHB_DIV_8 = 0x0A, /*!< sclk div8 to ahbclk */ + CRM_AHB_DIV_16 = 0x0B, /*!< sclk div16 to ahbclk */ + CRM_AHB_DIV_64 = 0x0C, /*!< sclk div64 to ahbclk */ + CRM_AHB_DIV_128 = 0x0D, /*!< sclk div128 to ahbclk */ + CRM_AHB_DIV_256 = 0x0E, /*!< sclk div256 to ahbclk */ + CRM_AHB_DIV_512 = 0x0F /*!< sclk div512 to ahbclk */ } crm_ahb_div_type; /** * @brief crm apb1 division */ -typedef enum -{ - CRM_APB1_DIV_1 = 0x00, /*!< ahbclk div1 to apb1clk */ - CRM_APB1_DIV_2 = 0x04, /*!< ahbclk div2 to apb1clk */ - CRM_APB1_DIV_4 = 0x05, /*!< ahbclk div4 to apb1clk */ - CRM_APB1_DIV_8 = 0x06, /*!< ahbclk div8 to apb1clk */ - CRM_APB1_DIV_16 = 0x07 /*!< ahbclk div16 to apb1clk */ +typedef enum { + CRM_APB1_DIV_1 = 0x00, /*!< ahbclk div1 to apb1clk */ + CRM_APB1_DIV_2 = 0x04, /*!< ahbclk div2 to apb1clk */ + CRM_APB1_DIV_4 = 0x05, /*!< ahbclk div4 to apb1clk */ + CRM_APB1_DIV_8 = 0x06, /*!< ahbclk div8 to apb1clk */ + CRM_APB1_DIV_16 = 0x07 /*!< ahbclk div16 to apb1clk */ } crm_apb1_div_type; /** * @brief crm apb2 division */ -typedef enum -{ - CRM_APB2_DIV_1 = 0x00, /*!< ahbclk div1 to apb2clk */ - CRM_APB2_DIV_2 = 0x04, /*!< ahbclk div2 to apb2clk */ - CRM_APB2_DIV_4 = 0x05, /*!< ahbclk div4 to apb2clk */ - CRM_APB2_DIV_8 = 0x06, /*!< ahbclk div8 to apb2clk */ - CRM_APB2_DIV_16 = 0x07 /*!< ahbclk div16 to apb2clk */ +typedef enum { + CRM_APB2_DIV_1 = 0x00, /*!< ahbclk div1 to apb2clk */ + CRM_APB2_DIV_2 = 0x04, /*!< ahbclk div2 to apb2clk */ + CRM_APB2_DIV_4 = 0x05, /*!< ahbclk div4 to apb2clk */ + CRM_APB2_DIV_8 = 0x06, /*!< ahbclk div8 to apb2clk */ + CRM_APB2_DIV_16 = 0x07 /*!< ahbclk div16 to apb2clk */ } crm_apb2_div_type; /** * @brief crm usb division */ -typedef enum -{ - CRM_USB_DIV_1_5 = 0x00, /*!< pllclk div1.5 to usbclk */ - CRM_USB_DIV_1 = 0x01, /*!< pllclk div1 to usbclk */ - CRM_USB_DIV_2_5 = 0x02, /*!< pllclk div2.5 to usbclk */ - CRM_USB_DIV_2 = 0x03, /*!< pllclk div2 to usbclk */ - CRM_USB_DIV_3_5 = 0x04, /*!< pllclk div3.5 to usbclk */ - CRM_USB_DIV_3 = 0x05, /*!< pllclk div3 to usbclk */ - CRM_USB_DIV_4_5 = 0x06, /*!< pllclk div4.5 to usbclk */ - CRM_USB_DIV_4 = 0x07, /*!< pllclk div4 to usbclk */ - CRM_USB_DIV_5_5 = 0x08, /*!< pllclk div5.5 to usbclk */ - CRM_USB_DIV_5 = 0x09, /*!< pllclk div5 to usbclk */ - CRM_USB_DIV_6_5 = 0x0A, /*!< pllclk div6.5 to usbclk */ - CRM_USB_DIV_6 = 0x0B, /*!< pllclk div6 to usbclk */ - CRM_USB_DIV_7 = 0x0C /*!< pllclk div7 to usbclk */ +typedef enum { + CRM_USB_DIV_1_5 = 0x00, /*!< pllclk div1.5 to usbclk */ + CRM_USB_DIV_1 = 0x01, /*!< pllclk div1 to usbclk */ + CRM_USB_DIV_2_5 = 0x02, /*!< pllclk div2.5 to usbclk */ + CRM_USB_DIV_2 = 0x03, /*!< pllclk div2 to usbclk */ + CRM_USB_DIV_3_5 = 0x04, /*!< pllclk div3.5 to usbclk */ + CRM_USB_DIV_3 = 0x05, /*!< pllclk div3 to usbclk */ + CRM_USB_DIV_4_5 = 0x06, /*!< pllclk div4.5 to usbclk */ + CRM_USB_DIV_4 = 0x07, /*!< pllclk div4 to usbclk */ + CRM_USB_DIV_5_5 = 0x08, /*!< pllclk div5.5 to usbclk */ + CRM_USB_DIV_5 = 0x09, /*!< pllclk div5 to usbclk */ + CRM_USB_DIV_6_5 = 0x0A, /*!< pllclk div6.5 to usbclk */ + CRM_USB_DIV_6 = 0x0B, /*!< pllclk div6 to usbclk */ + CRM_USB_DIV_7 = 0x0C /*!< pllclk div7 to usbclk */ } crm_usb_div_type; /** * @brief crm ertc clock */ -typedef enum -{ - CRM_ERTC_CLOCK_NOCLK = 0x000, /*!< no clock as ertc clock source */ - CRM_ERTC_CLOCK_LEXT = 0x001, /*!< low speed external crystal as ertc clock source */ - CRM_ERTC_CLOCK_LICK = 0x002, /*!< low speed internal clock as ertc clock source */ - CRM_ERTC_CLOCK_HEXT_DIV_2 = 0x023, /*!< high speed external crystal div2 as ertc clock source */ - CRM_ERTC_CLOCK_HEXT_DIV_3 = 0x033, /*!< high speed external crystal div3 as ertc clock source */ - CRM_ERTC_CLOCK_HEXT_DIV_4 = 0x043, /*!< high speed external crystal div4 as ertc clock source */ - CRM_ERTC_CLOCK_HEXT_DIV_5 = 0x053, /*!< high speed external crystal div5 as ertc clock source */ - CRM_ERTC_CLOCK_HEXT_DIV_6 = 0x063, /*!< high speed external crystal div6 as ertc clock source */ - CRM_ERTC_CLOCK_HEXT_DIV_7 = 0x073, /*!< high speed external crystal div7 as ertc clock source */ - CRM_ERTC_CLOCK_HEXT_DIV_8 = 0x083, /*!< high speed external crystal div8 as ertc clock source */ - CRM_ERTC_CLOCK_HEXT_DIV_9 = 0x093, /*!< high speed external crystal div9 as ertc clock source */ - CRM_ERTC_CLOCK_HEXT_DIV_10 = 0x0A3, /*!< high speed external crystal div10 as ertc clock source */ - CRM_ERTC_CLOCK_HEXT_DIV_11 = 0x0B3, /*!< high speed external crystal div11 as ertc clock source */ - CRM_ERTC_CLOCK_HEXT_DIV_12 = 0x0C3, /*!< high speed external crystal div12 as ertc clock source */ - CRM_ERTC_CLOCK_HEXT_DIV_13 = 0x0D3, /*!< high speed external crystal div13 as ertc clock source */ - CRM_ERTC_CLOCK_HEXT_DIV_14 = 0x0E3, /*!< high speed external crystal div14 as ertc clock source */ - CRM_ERTC_CLOCK_HEXT_DIV_15 = 0x0F3, /*!< high speed external crystal div15 as ertc clock source */ - CRM_ERTC_CLOCK_HEXT_DIV_16 = 0x103, /*!< high speed external crystal div16 as ertc clock source */ - CRM_ERTC_CLOCK_HEXT_DIV_17 = 0x113, /*!< high speed external crystal div17 as ertc clock source */ - CRM_ERTC_CLOCK_HEXT_DIV_18 = 0x123, /*!< high speed external crystal div18 as ertc clock source */ - CRM_ERTC_CLOCK_HEXT_DIV_19 = 0x133, /*!< high speed external crystal div19 as ertc clock source */ - CRM_ERTC_CLOCK_HEXT_DIV_20 = 0x143, /*!< high speed external crystal div20 as ertc clock source */ - CRM_ERTC_CLOCK_HEXT_DIV_21 = 0x153, /*!< high speed external crystal div21 as ertc clock source */ - CRM_ERTC_CLOCK_HEXT_DIV_22 = 0x163, /*!< high speed external crystal div22 as ertc clock source */ - CRM_ERTC_CLOCK_HEXT_DIV_23 = 0x173, /*!< high speed external crystal div23 as ertc clock source */ - CRM_ERTC_CLOCK_HEXT_DIV_24 = 0x183, /*!< high speed external crystal div24 as ertc clock source */ - CRM_ERTC_CLOCK_HEXT_DIV_25 = 0x193, /*!< high speed external crystal div25 as ertc clock source */ - CRM_ERTC_CLOCK_HEXT_DIV_26 = 0x1A3, /*!< high speed external crystal div26 as ertc clock source */ - CRM_ERTC_CLOCK_HEXT_DIV_27 = 0x1B3, /*!< high speed external crystal div27 as ertc clock source */ - CRM_ERTC_CLOCK_HEXT_DIV_28 = 0x1C3, /*!< high speed external crystal div28 as ertc clock source */ - CRM_ERTC_CLOCK_HEXT_DIV_29 = 0x1D3, /*!< high speed external crystal div29 as ertc clock source */ - CRM_ERTC_CLOCK_HEXT_DIV_30 = 0x1E3, /*!< high speed external crystal div30 as ertc clock source */ - CRM_ERTC_CLOCK_HEXT_DIV_31 = 0x1F3 /*!< high speed external crystal div31 as ertc clock source */ +typedef enum { + CRM_ERTC_CLOCK_NOCLK = 0x000, /*!< no clock as ertc clock source */ + CRM_ERTC_CLOCK_LEXT = 0x001, /*!< low speed external crystal as ertc clock source */ + CRM_ERTC_CLOCK_LICK = 0x002, /*!< low speed internal clock as ertc clock source */ + CRM_ERTC_CLOCK_HEXT_DIV_2 = 0x023, /*!< high speed external crystal div2 as ertc clock source */ + CRM_ERTC_CLOCK_HEXT_DIV_3 = 0x033, /*!< high speed external crystal div3 as ertc clock source */ + CRM_ERTC_CLOCK_HEXT_DIV_4 = 0x043, /*!< high speed external crystal div4 as ertc clock source */ + CRM_ERTC_CLOCK_HEXT_DIV_5 = 0x053, /*!< high speed external crystal div5 as ertc clock source */ + CRM_ERTC_CLOCK_HEXT_DIV_6 = 0x063, /*!< high speed external crystal div6 as ertc clock source */ + CRM_ERTC_CLOCK_HEXT_DIV_7 = 0x073, /*!< high speed external crystal div7 as ertc clock source */ + CRM_ERTC_CLOCK_HEXT_DIV_8 = 0x083, /*!< high speed external crystal div8 as ertc clock source */ + CRM_ERTC_CLOCK_HEXT_DIV_9 = 0x093, /*!< high speed external crystal div9 as ertc clock source */ + CRM_ERTC_CLOCK_HEXT_DIV_10 = 0x0A3, /*!< high speed external crystal div10 as ertc clock source */ + CRM_ERTC_CLOCK_HEXT_DIV_11 = 0x0B3, /*!< high speed external crystal div11 as ertc clock source */ + CRM_ERTC_CLOCK_HEXT_DIV_12 = 0x0C3, /*!< high speed external crystal div12 as ertc clock source */ + CRM_ERTC_CLOCK_HEXT_DIV_13 = 0x0D3, /*!< high speed external crystal div13 as ertc clock source */ + CRM_ERTC_CLOCK_HEXT_DIV_14 = 0x0E3, /*!< high speed external crystal div14 as ertc clock source */ + CRM_ERTC_CLOCK_HEXT_DIV_15 = 0x0F3, /*!< high speed external crystal div15 as ertc clock source */ + CRM_ERTC_CLOCK_HEXT_DIV_16 = 0x103, /*!< high speed external crystal div16 as ertc clock source */ + CRM_ERTC_CLOCK_HEXT_DIV_17 = 0x113, /*!< high speed external crystal div17 as ertc clock source */ + CRM_ERTC_CLOCK_HEXT_DIV_18 = 0x123, /*!< high speed external crystal div18 as ertc clock source */ + CRM_ERTC_CLOCK_HEXT_DIV_19 = 0x133, /*!< high speed external crystal div19 as ertc clock source */ + CRM_ERTC_CLOCK_HEXT_DIV_20 = 0x143, /*!< high speed external crystal div20 as ertc clock source */ + CRM_ERTC_CLOCK_HEXT_DIV_21 = 0x153, /*!< high speed external crystal div21 as ertc clock source */ + CRM_ERTC_CLOCK_HEXT_DIV_22 = 0x163, /*!< high speed external crystal div22 as ertc clock source */ + CRM_ERTC_CLOCK_HEXT_DIV_23 = 0x173, /*!< high speed external crystal div23 as ertc clock source */ + CRM_ERTC_CLOCK_HEXT_DIV_24 = 0x183, /*!< high speed external crystal div24 as ertc clock source */ + CRM_ERTC_CLOCK_HEXT_DIV_25 = 0x193, /*!< high speed external crystal div25 as ertc clock source */ + CRM_ERTC_CLOCK_HEXT_DIV_26 = 0x1A3, /*!< high speed external crystal div26 as ertc clock source */ + CRM_ERTC_CLOCK_HEXT_DIV_27 = 0x1B3, /*!< high speed external crystal div27 as ertc clock source */ + CRM_ERTC_CLOCK_HEXT_DIV_28 = 0x1C3, /*!< high speed external crystal div28 as ertc clock source */ + CRM_ERTC_CLOCK_HEXT_DIV_29 = 0x1D3, /*!< high speed external crystal div29 as ertc clock source */ + CRM_ERTC_CLOCK_HEXT_DIV_30 = 0x1E3, /*!< high speed external crystal div30 as ertc clock source */ + CRM_ERTC_CLOCK_HEXT_DIV_31 = 0x1F3 /*!< high speed external crystal div31 as ertc clock source */ } crm_ertc_clock_type; /** * @brief crm hick 48mhz division */ -typedef enum -{ - CRM_HICK48_DIV6 = 0x00, /*!< fixed 8 mhz when hick is selected as sclk */ - CRM_HICK48_NODIV = 0x01 /*!< 8 mhz or 48 mhz depend on hickdiv when hick is selected as sclk */ +typedef enum { + CRM_HICK48_DIV6 = 0x00, /*!< fixed 8 mhz when hick is selected as sclk */ + CRM_HICK48_NODIV = 0x01 /*!< 8 mhz or 48 mhz depend on hickdiv when hick is selected as sclk */ } crm_hick_div_6_type; /** * @brief crm sclk select */ -typedef enum -{ - CRM_SCLK_HICK = 0x00, /*!< select high speed internal clock as sclk */ - CRM_SCLK_HEXT = 0x01, /*!< select high speed external crystal as sclk */ - CRM_SCLK_PLL = 0x02 /*!< select phase locking loop clock as sclk */ +typedef enum { + CRM_SCLK_HICK = 0x00, /*!< select high speed internal clock as sclk */ + CRM_SCLK_HEXT = 0x01, /*!< select high speed external crystal as sclk */ + CRM_SCLK_PLL = 0x02 /*!< select phase locking loop clock as sclk */ } crm_sclk_type; /** * @brief crm clkout index */ -typedef enum -{ - CRM_CLKOUT_INDEX_1 = 0x00, /*!< clkout1 */ - CRM_CLKOUT_INDEX_2 = 0x01 /*!< clkout2 */ +typedef enum { + CRM_CLKOUT_INDEX_1 = 0x00, /*!< clkout1 */ + CRM_CLKOUT_INDEX_2 = 0x01 /*!< clkout2 */ } crm_clkout_index_type; /** * @brief crm clkout1 select */ -typedef enum -{ - CRM_CLKOUT1_HICK = 0x00, /*!< output high speed internal clock to clkout1 pin */ - CRM_CLKOUT1_LEXT = 0x01, /*!< output low speed external crystal to clkout1 pin */ - CRM_CLKOUT1_HEXT = 0x02, /*!< output high speed external crystal to clkout1 pin */ - CRM_CLKOUT1_PLL = 0x03 /*!< output phase locking loop clock to clkout1 pin */ +typedef enum { + CRM_CLKOUT1_HICK = 0x00, /*!< output high speed internal clock to clkout1 pin */ + CRM_CLKOUT1_LEXT = 0x01, /*!< output low speed external crystal to clkout1 pin */ + CRM_CLKOUT1_HEXT = 0x02, /*!< output high speed external crystal to clkout1 pin */ + CRM_CLKOUT1_PLL = 0x03 /*!< output phase locking loop clock to clkout1 pin */ } crm_clkout1_select_type; /** * @brief crm clkout2 select */ -typedef enum -{ - CRM_CLKOUT2_SCLK = 0x00, /*!< output system clock to clkout2 pin */ - CRM_CLKOUT2_HEXT = 0x02, /*!< output high speed external crystal to clkout2 pin */ - CRM_CLKOUT2_PLL = 0x03, /*!< output phase locking loop clock to clkout2 pin */ - CRM_CLKOUT2_USB = 0x10, /*!< output usbclk to clkout2 pin */ - CRM_CLKOUT2_ADC = 0x11, /*!< output adcclk to clkout2 pin */ - CRM_CLKOUT2_HICK = 0x12, /*!< output high speed internal clock to clkout2 pin */ - CRM_CLKOUT2_LICK = 0x13, /*!< output low speed internal clock to clkout2 pin */ - CRM_CLKOUT2_LEXT = 0x14 /*!< output low speed external crystal to clkout2 pin */ +typedef enum { + CRM_CLKOUT2_SCLK = 0x00, /*!< output system clock to clkout2 pin */ + CRM_CLKOUT2_HEXT = 0x02, /*!< output high speed external crystal to clkout2 pin */ + CRM_CLKOUT2_PLL = 0x03, /*!< output phase locking loop clock to clkout2 pin */ + CRM_CLKOUT2_USB = 0x10, /*!< output usbclk to clkout2 pin */ + CRM_CLKOUT2_ADC = 0x11, /*!< output adcclk to clkout2 pin */ + CRM_CLKOUT2_HICK = 0x12, /*!< output high speed internal clock to clkout2 pin */ + CRM_CLKOUT2_LICK = 0x13, /*!< output low speed internal clock to clkout2 pin */ + CRM_CLKOUT2_LEXT = 0x14 /*!< output low speed external crystal to clkout2 pin */ } crm_clkout2_select_type; /** * @brief crm clkout division1 */ -typedef enum -{ - CRM_CLKOUT_DIV1_1 = 0x00, /*!< clkout division1 div1 */ - CRM_CLKOUT_DIV1_2 = 0x04, /*!< clkout division1 div2 */ - CRM_CLKOUT_DIV1_3 = 0x05, /*!< clkout division1 div3 */ - CRM_CLKOUT_DIV1_4 = 0x06, /*!< clkout division1 div4 */ - CRM_CLKOUT_DIV1_5 = 0x07 /*!< clkout division1 div5 */ +typedef enum { + CRM_CLKOUT_DIV1_1 = 0x00, /*!< clkout division1 div1 */ + CRM_CLKOUT_DIV1_2 = 0x04, /*!< clkout division1 div2 */ + CRM_CLKOUT_DIV1_3 = 0x05, /*!< clkout division1 div3 */ + CRM_CLKOUT_DIV1_4 = 0x06, /*!< clkout division1 div4 */ + CRM_CLKOUT_DIV1_5 = 0x07 /*!< clkout division1 div5 */ } crm_clkout_div1_type; /** * @brief crm clkout division2 */ -typedef enum -{ - CRM_CLKOUT_DIV2_1 = 0x00, /*!< clkout division2 div1 */ - CRM_CLKOUT_DIV2_2 = 0x08, /*!< clkout division2 div2 */ - CRM_CLKOUT_DIV2_4 = 0x09, /*!< clkout division2 div4 */ - CRM_CLKOUT_DIV2_8 = 0x0A, /*!< clkout division2 div8 */ - CRM_CLKOUT_DIV2_16 = 0x0B, /*!< clkout division2 div16 */ - CRM_CLKOUT_DIV2_64 = 0x0C, /*!< clkout division2 div64 */ - CRM_CLKOUT_DIV2_128 = 0x0D, /*!< clkout division2 div128 */ - CRM_CLKOUT_DIV2_256 = 0x0E, /*!< clkout division2 div256 */ - CRM_CLKOUT_DIV2_512 = 0x0F /*!< clkout division2 div512 */ +typedef enum { + CRM_CLKOUT_DIV2_1 = 0x00, /*!< clkout division2 div1 */ + CRM_CLKOUT_DIV2_2 = 0x08, /*!< clkout division2 div2 */ + CRM_CLKOUT_DIV2_4 = 0x09, /*!< clkout division2 div4 */ + CRM_CLKOUT_DIV2_8 = 0x0A, /*!< clkout division2 div8 */ + CRM_CLKOUT_DIV2_16 = 0x0B, /*!< clkout division2 div16 */ + CRM_CLKOUT_DIV2_64 = 0x0C, /*!< clkout division2 div64 */ + CRM_CLKOUT_DIV2_128 = 0x0D, /*!< clkout division2 div128 */ + CRM_CLKOUT_DIV2_256 = 0x0E, /*!< clkout division2 div256 */ + CRM_CLKOUT_DIV2_512 = 0x0F /*!< clkout division2 div512 */ } crm_clkout_div2_type; /** * @brief crm auto step mode */ -typedef enum -{ - CRM_AUTO_STEP_MODE_DISABLE = 0x00, /*!< disable auto step mode */ - CRM_AUTO_STEP_MODE_ENABLE = 0x03 /*!< enable auto step mode */ +typedef enum { + CRM_AUTO_STEP_MODE_DISABLE = 0x00, /*!< disable auto step mode */ + CRM_AUTO_STEP_MODE_ENABLE = 0x03 /*!< enable auto step mode */ } crm_auto_step_mode_type; /** * @brief crm usb 48 mhz clock source select */ -typedef enum -{ - CRM_USB_CLOCK_SOURCE_PLL = 0x00, /*!< select phase locking loop clock as usb clock source */ - CRM_USB_CLOCK_SOURCE_HICK = 0x01 /*!< select high speed internal clock as usb clock source */ +typedef enum { + CRM_USB_CLOCK_SOURCE_PLL = 0x00, /*!< select phase locking loop clock as usb clock source */ + CRM_USB_CLOCK_SOURCE_HICK = 0x01 /*!< select high speed internal clock as usb clock source */ } crm_usb_clock_source_type; /** * @brief crm hick as system clock frequency select */ -typedef enum -{ - CRM_HICK_SCLK_8MHZ = 0x00, /*!< fixed 8 mhz when hick is selected as sclk */ - CRM_HICK_SCLK_48MHZ = 0x01 /*!< 8 mhz or 48 mhz depend on hickdiv when hick is selected as sclk */ +typedef enum { + CRM_HICK_SCLK_8MHZ = 0x00, /*!< fixed 8 mhz when hick is selected as sclk */ + CRM_HICK_SCLK_48MHZ = 0x01 /*!< 8 mhz or 48 mhz depend on hickdiv when hick is selected as sclk */ } crm_hick_sclk_frequency_type; /** * @brief crm emac output pulse width */ -typedef enum -{ - CRM_EMAC_PULSE_125MS = 0x00, /*!< emac output pulse width 125ms */ - CRM_EMAC_PULSE_1SCLK = 0x01 /*!< emac output pulse width 1 system clock */ +typedef enum { + CRM_EMAC_PULSE_125MS = 0x00, /*!< emac output pulse width 125ms */ + CRM_EMAC_PULSE_1SCLK = 0x01 /*!< emac output pulse width 1 system clock */ } crm_emac_output_pulse_type; /** * @brief crm clocks freqency structure */ -typedef struct -{ - uint32_t sclk_freq; /*!< system clock frequency */ - uint32_t ahb_freq; /*!< ahb bus clock frequency */ - uint32_t apb2_freq; /*!< apb2 bus clock frequency */ - uint32_t apb1_freq; /*!< apb1 bus clock frequency */ +typedef struct { + uint32_t sclk_freq; /*!< system clock frequency */ + uint32_t ahb_freq; /*!< ahb bus clock frequency */ + uint32_t apb2_freq; /*!< apb2 bus clock frequency */ + uint32_t apb1_freq; /*!< apb1 bus clock frequency */ } crm_clocks_freq_type; /** * @brief type define crm register all */ -typedef struct -{ - /** - * @brief crm ctrl register, offset:0x00 - */ - union - { - __IO uint32_t ctrl; - struct - { - __IO uint32_t hicken : 1; /* [0] */ - __IO uint32_t hickstbl : 1; /* [1] */ - __IO uint32_t hicktrim : 6; /* [7:2] */ - __IO uint32_t hickcal : 8; /* [15:8] */ - __IO uint32_t hexten : 1; /* [16] */ - __IO uint32_t hextstbl : 1; /* [17] */ - __IO uint32_t hextbyps : 1; /* [18] */ - __IO uint32_t cfden : 1; /* [19] */ - __IO uint32_t reserved1 : 4; /* [23:20] */ - __IO uint32_t pllen : 1; /* [24] */ - __IO uint32_t pllstbl : 1; /* [25] */ - __IO uint32_t reserved2 : 6; /* [31:26] */ - } ctrl_bit; - }; +typedef struct { + /** + * @brief crm ctrl register, offset:0x00 + */ + union { + __IO uint32_t ctrl; + struct { + __IO uint32_t hicken : 1; /* [0] */ + __IO uint32_t hickstbl : 1; /* [1] */ + __IO uint32_t hicktrim : 6; /* [7:2] */ + __IO uint32_t hickcal : 8; /* [15:8] */ + __IO uint32_t hexten : 1; /* [16] */ + __IO uint32_t hextstbl : 1; /* [17] */ + __IO uint32_t hextbyps : 1; /* [18] */ + __IO uint32_t cfden : 1; /* [19] */ + __IO uint32_t reserved1 : 4; /* [23:20] */ + __IO uint32_t pllen : 1; /* [24] */ + __IO uint32_t pllstbl : 1; /* [25] */ + __IO uint32_t reserved2 : 6; /* [31:26] */ + } ctrl_bit; + }; - /** - * @brief crm pllcfg register, offset:0x04 - */ - union - { - __IO uint32_t pllcfg; - struct - { - __IO uint32_t pllms : 4; /* [3:0] */ - __IO uint32_t reserved1 : 2; /* [5:4] */ - __IO uint32_t pllns : 9; /* [14:6] */ - __IO uint32_t reserved2 : 1; /* [15] */ - __IO uint32_t pllfr : 3; /* [18:16] */ - __IO uint32_t reserved3 : 3; /* [21:19] */ - __IO uint32_t pllrcs : 1; /* [22] */ - __IO uint32_t reserved4 : 9; /* [31:23] */ - } pllcfg_bit; - }; + /** + * @brief crm pllcfg register, offset:0x04 + */ + union { + __IO uint32_t pllcfg; + struct { + __IO uint32_t pllms : 4; /* [3:0] */ + __IO uint32_t reserved1 : 2; /* [5:4] */ + __IO uint32_t pllns : 9; /* [14:6] */ + __IO uint32_t reserved2 : 1; /* [15] */ + __IO uint32_t pllfr : 3; /* [18:16] */ + __IO uint32_t reserved3 : 3; /* [21:19] */ + __IO uint32_t pllrcs : 1; /* [22] */ + __IO uint32_t reserved4 : 9; /* [31:23] */ + } pllcfg_bit; + }; - /** - * @brief crm cfg register, offset:0x08 - */ - union - { - __IO uint32_t cfg; - struct - { - __IO uint32_t sclksel : 2; /* [1:0] */ - __IO uint32_t sclksts : 2; /* [3:2] */ - __IO uint32_t ahbdiv : 4; /* [7:4] */ - __IO uint32_t reserved1 : 2; /* [9:8] */ - __IO uint32_t apb1div : 3; /* [12:10] */ - __IO uint32_t apb2div : 3; /* [15:13] */ - __IO uint32_t ertcdiv : 5; /* [20:16] */ - __IO uint32_t clkout1_sel : 2; /* [22:21] */ - __IO uint32_t reserved2 : 1; /* [23] */ - __IO uint32_t clkout1div1 : 3; /* [26:24] */ - __IO uint32_t clkout2div1 : 3; /* [29:27] */ - __IO uint32_t clkout2_sel1 : 2; /* [31:30] */ - } cfg_bit; - }; + /** + * @brief crm cfg register, offset:0x08 + */ + union { + __IO uint32_t cfg; + struct { + __IO uint32_t sclksel : 2; /* [1:0] */ + __IO uint32_t sclksts : 2; /* [3:2] */ + __IO uint32_t ahbdiv : 4; /* [7:4] */ + __IO uint32_t reserved1 : 2; /* [9:8] */ + __IO uint32_t apb1div : 3; /* [12:10] */ + __IO uint32_t apb2div : 3; /* [15:13] */ + __IO uint32_t ertcdiv : 5; /* [20:16] */ + __IO uint32_t clkout1_sel : 2; /* [22:21] */ + __IO uint32_t reserved2 : 1; /* [23] */ + __IO uint32_t clkout1div1 : 3; /* [26:24] */ + __IO uint32_t clkout2div1 : 3; /* [29:27] */ + __IO uint32_t clkout2_sel1 : 2; /* [31:30] */ + } cfg_bit; + }; - /** - * @brief crm clkint register, offset:0x0C - */ - union - { - __IO uint32_t clkint; - struct - { - __IO uint32_t lickstblf : 1; /* [0] */ - __IO uint32_t lextstblf : 1; /* [1] */ - __IO uint32_t hickstblf : 1; /* [2] */ - __IO uint32_t hextstblf : 1; /* [3] */ - __IO uint32_t pllstblf : 1; /* [4] */ - __IO uint32_t reserved1 : 2; /* [6:5] */ - __IO uint32_t cfdf : 1; /* [7] */ - __IO uint32_t lickstblien : 1; /* [8] */ - __IO uint32_t lextstblien : 1; /* [9] */ - __IO uint32_t hickstblien : 1; /* [10] */ - __IO uint32_t hextstblien : 1; /* [11] */ - __IO uint32_t pllstblien : 1; /* [12] */ - __IO uint32_t reserved2 : 3; /* [15:13] */ - __IO uint32_t lickstblfc : 1; /* [16] */ - __IO uint32_t lextstblfc : 1; /* [17] */ - __IO uint32_t hickstblfc : 1; /* [18] */ - __IO uint32_t hextstblfc : 1; /* [19] */ - __IO uint32_t pllstblfc : 1; /* [20] */ - __IO uint32_t reserved3 : 2; /* [22:21] */ - __IO uint32_t cfdfc : 1; /* [23] */ - __IO uint32_t reserved4 : 8; /* [31:24] */ - } clkint_bit; - }; + /** + * @brief crm clkint register, offset:0x0C + */ + union { + __IO uint32_t clkint; + struct { + __IO uint32_t lickstblf : 1; /* [0] */ + __IO uint32_t lextstblf : 1; /* [1] */ + __IO uint32_t hickstblf : 1; /* [2] */ + __IO uint32_t hextstblf : 1; /* [3] */ + __IO uint32_t pllstblf : 1; /* [4] */ + __IO uint32_t reserved1 : 2; /* [6:5] */ + __IO uint32_t cfdf : 1; /* [7] */ + __IO uint32_t lickstblien : 1; /* [8] */ + __IO uint32_t lextstblien : 1; /* [9] */ + __IO uint32_t hickstblien : 1; /* [10] */ + __IO uint32_t hextstblien : 1; /* [11] */ + __IO uint32_t pllstblien : 1; /* [12] */ + __IO uint32_t reserved2 : 3; /* [15:13] */ + __IO uint32_t lickstblfc : 1; /* [16] */ + __IO uint32_t lextstblfc : 1; /* [17] */ + __IO uint32_t hickstblfc : 1; /* [18] */ + __IO uint32_t hextstblfc : 1; /* [19] */ + __IO uint32_t pllstblfc : 1; /* [20] */ + __IO uint32_t reserved3 : 2; /* [22:21] */ + __IO uint32_t cfdfc : 1; /* [23] */ + __IO uint32_t reserved4 : 8; /* [31:24] */ + } clkint_bit; + }; - /** - * @brief crm ahbrst1 register, offset:0x10 - */ - union - { - __IO uint32_t ahbrst1; + /** + * @brief crm ahbrst1 register, offset:0x10 + */ + union { + __IO uint32_t ahbrst1; #if defined (AT32F435xx) - struct - { - __IO uint32_t gpioarst : 1; /* [0] */ - __IO uint32_t gpiobrst : 1; /* [1] */ - __IO uint32_t gpiocrst : 1; /* [2] */ - __IO uint32_t gpiodrst : 1; /* [3] */ - __IO uint32_t gpioerst : 1; /* [4] */ - __IO uint32_t gpiofrst : 1; /* [5] */ - __IO uint32_t gpiogrst : 1; /* [6] */ - __IO uint32_t gpiohrst : 1; /* [7] */ - __IO uint32_t reserved1 : 4; /* [11:8] */ - __IO uint32_t crcrst : 1; /* [12] */ - __IO uint32_t reserved2 : 8; /* [20:13] */ - __IO uint32_t edmarst : 1; /* [21] */ - __IO uint32_t dma1rst : 1; /* [22] */ - __IO uint32_t reserved3 : 1; /* [23] */ - __IO uint32_t dma2rst : 1; /* [24] */ - __IO uint32_t reserved4 : 4; /* [28:25] */ - __IO uint32_t otgfs2rst : 1; /* [29] */ - __IO uint32_t reserved5 : 2; /* [31:30] */ - } ahbrst1_bit; + struct { + __IO uint32_t gpioarst : 1; /* [0] */ + __IO uint32_t gpiobrst : 1; /* [1] */ + __IO uint32_t gpiocrst : 1; /* [2] */ + __IO uint32_t gpiodrst : 1; /* [3] */ + __IO uint32_t gpioerst : 1; /* [4] */ + __IO uint32_t gpiofrst : 1; /* [5] */ + __IO uint32_t gpiogrst : 1; /* [6] */ + __IO uint32_t gpiohrst : 1; /* [7] */ + __IO uint32_t reserved1 : 4; /* [11:8] */ + __IO uint32_t crcrst : 1; /* [12] */ + __IO uint32_t reserved2 : 8; /* [20:13] */ + __IO uint32_t edmarst : 1; /* [21] */ + __IO uint32_t dma1rst : 1; /* [22] */ + __IO uint32_t reserved3 : 1; /* [23] */ + __IO uint32_t dma2rst : 1; /* [24] */ + __IO uint32_t reserved4 : 4; /* [28:25] */ + __IO uint32_t otgfs2rst : 1; /* [29] */ + __IO uint32_t reserved5 : 2; /* [31:30] */ + } ahbrst1_bit; #endif #if defined (AT32F437xx) - struct - { - __IO uint32_t gpioarst : 1; /* [0] */ - __IO uint32_t gpiobrst : 1; /* [1] */ - __IO uint32_t gpiocrst : 1; /* [2] */ - __IO uint32_t gpiodrst : 1; /* [3] */ - __IO uint32_t gpioerst : 1; /* [4] */ - __IO uint32_t gpiofrst : 1; /* [5] */ - __IO uint32_t gpiogrst : 1; /* [6] */ - __IO uint32_t gpiohrst : 1; /* [7] */ - __IO uint32_t reserved1 : 4; /* [11:8] */ - __IO uint32_t crcrst : 1; /* [12] */ - __IO uint32_t reserved2 : 8; /* [20:13] */ - __IO uint32_t edmarst : 1; /* [21] */ - __IO uint32_t dma1rst : 1; /* [22] */ - __IO uint32_t reserved3 : 1; /* [23] */ - __IO uint32_t dma2rst : 1; /* [24] */ - __IO uint32_t emacrst : 1; /* [25] */ - __IO uint32_t reserved4 : 3; /* [28:26] */ - __IO uint32_t otgfs2rst : 1; /* [29] */ - __IO uint32_t reserved5 : 2; /* [31:30] */ - } ahbrst1_bit; + struct { + __IO uint32_t gpioarst : 1; /* [0] */ + __IO uint32_t gpiobrst : 1; /* [1] */ + __IO uint32_t gpiocrst : 1; /* [2] */ + __IO uint32_t gpiodrst : 1; /* [3] */ + __IO uint32_t gpioerst : 1; /* [4] */ + __IO uint32_t gpiofrst : 1; /* [5] */ + __IO uint32_t gpiogrst : 1; /* [6] */ + __IO uint32_t gpiohrst : 1; /* [7] */ + __IO uint32_t reserved1 : 4; /* [11:8] */ + __IO uint32_t crcrst : 1; /* [12] */ + __IO uint32_t reserved2 : 8; /* [20:13] */ + __IO uint32_t edmarst : 1; /* [21] */ + __IO uint32_t dma1rst : 1; /* [22] */ + __IO uint32_t reserved3 : 1; /* [23] */ + __IO uint32_t dma2rst : 1; /* [24] */ + __IO uint32_t emacrst : 1; /* [25] */ + __IO uint32_t reserved4 : 3; /* [28:26] */ + __IO uint32_t otgfs2rst : 1; /* [29] */ + __IO uint32_t reserved5 : 2; /* [31:30] */ + } ahbrst1_bit; #endif - }; + }; - /** - * @brief crm ahbrst2 register, offset:0x14 - */ - union - { - __IO uint32_t ahbrst2; - struct - { - __IO uint32_t dvprst : 1; /* [0] */ - __IO uint32_t reserved1 : 6; /* [6:1] */ - __IO uint32_t otgfs1rst : 1; /* [7] */ - __IO uint32_t reserved2 : 7; /* [14:8] */ - __IO uint32_t sdio1rst : 1; /* [15] */ - __IO uint32_t reserved3 : 16;/* [31:16] */ - } ahbrst2_bit; - }; + /** + * @brief crm ahbrst2 register, offset:0x14 + */ + union { + __IO uint32_t ahbrst2; + struct { + __IO uint32_t dvprst : 1; /* [0] */ + __IO uint32_t reserved1 : 6; /* [6:1] */ + __IO uint32_t otgfs1rst : 1; /* [7] */ + __IO uint32_t reserved2 : 7; /* [14:8] */ + __IO uint32_t sdio1rst : 1; /* [15] */ + __IO uint32_t reserved3 : 16;/* [31:16] */ + } ahbrst2_bit; + }; - /** - * @brief crm ahbrst3 register, offset:0x18 - */ - union - { - __IO uint32_t ahbrst3; - struct - { - __IO uint32_t xmcrst : 1; /* [0] */ - __IO uint32_t qspi1rst : 1; /* [1] */ - __IO uint32_t reserved1 : 12;/* [13:2] */ - __IO uint32_t qspi2rst : 1; /* [14] */ - __IO uint32_t sdio2rst : 1; /* [15] */ - __IO uint32_t reserved3 : 16;/* [31:16] */ - } ahbrst3_bit; - }; + /** + * @brief crm ahbrst3 register, offset:0x18 + */ + union { + __IO uint32_t ahbrst3; + struct { + __IO uint32_t xmcrst : 1; /* [0] */ + __IO uint32_t qspi1rst : 1; /* [1] */ + __IO uint32_t reserved1 : 12;/* [13:2] */ + __IO uint32_t qspi2rst : 1; /* [14] */ + __IO uint32_t sdio2rst : 1; /* [15] */ + __IO uint32_t reserved3 : 16;/* [31:16] */ + } ahbrst3_bit; + }; - /** - * @brief crm reserved1 register, offset:0x1C - */ - __IO uint32_t reserved1; + /** + * @brief crm reserved1 register, offset:0x1C + */ + __IO uint32_t reserved1; - /** - * @brief crm apb1rst register, offset:0x20 - */ - union - { - __IO uint32_t apb1rst; - struct - { - __IO uint32_t tmr2rst : 1; /* [0] */ - __IO uint32_t tmr3rst : 1; /* [1] */ - __IO uint32_t tmr4rst : 1; /* [2] */ - __IO uint32_t tmr5rst : 1; /* [3] */ - __IO uint32_t tmr6rst : 1; /* [4] */ - __IO uint32_t tmr7rst : 1; /* [5] */ - __IO uint32_t tmr12rst : 1; /* [6] */ - __IO uint32_t tmr13rst : 1; /* [7] */ - __IO uint32_t adc14rst : 1; /* [8] */ - __IO uint32_t reserved1 : 2; /* [10:9] */ - __IO uint32_t wwdtrst : 1; /* [11] */ - __IO uint32_t reserved2 : 2; /* [13:12] */ - __IO uint32_t spi2rst : 1; /* [14] */ - __IO uint32_t spi3rst : 1; /* [15] */ - __IO uint32_t reserved3 : 1; /* [16] */ - __IO uint32_t usart2rst : 1; /* [17] */ - __IO uint32_t usart3rst : 1; /* [18] */ - __IO uint32_t uart4rst : 1; /* [19] */ - __IO uint32_t uart5rst : 1; /* [20] */ - __IO uint32_t i2c1rst : 1; /* [21] */ - __IO uint32_t i2c2rst : 1; /* [22] */ - __IO uint32_t i2c3rst : 1; /* [23] */ - __IO uint32_t reserved4 : 1; /* [24] */ - __IO uint32_t can1rst : 1; /* [25] */ - __IO uint32_t can2rst : 1; /* [26] */ - __IO uint32_t reserved5 : 1; /* [27] */ - __IO uint32_t pwcrst : 1; /* [28] */ - __IO uint32_t dacrst : 1; /* [29] */ - __IO uint32_t uart7rst : 1; /* [30] */ - __IO uint32_t uart8rst : 1; /* [31] */ - } apb1rst_bit; - }; + /** + * @brief crm apb1rst register, offset:0x20 + */ + union { + __IO uint32_t apb1rst; + struct { + __IO uint32_t tmr2rst : 1; /* [0] */ + __IO uint32_t tmr3rst : 1; /* [1] */ + __IO uint32_t tmr4rst : 1; /* [2] */ + __IO uint32_t tmr5rst : 1; /* [3] */ + __IO uint32_t tmr6rst : 1; /* [4] */ + __IO uint32_t tmr7rst : 1; /* [5] */ + __IO uint32_t tmr12rst : 1; /* [6] */ + __IO uint32_t tmr13rst : 1; /* [7] */ + __IO uint32_t adc14rst : 1; /* [8] */ + __IO uint32_t reserved1 : 2; /* [10:9] */ + __IO uint32_t wwdtrst : 1; /* [11] */ + __IO uint32_t reserved2 : 2; /* [13:12] */ + __IO uint32_t spi2rst : 1; /* [14] */ + __IO uint32_t spi3rst : 1; /* [15] */ + __IO uint32_t reserved3 : 1; /* [16] */ + __IO uint32_t usart2rst : 1; /* [17] */ + __IO uint32_t usart3rst : 1; /* [18] */ + __IO uint32_t uart4rst : 1; /* [19] */ + __IO uint32_t uart5rst : 1; /* [20] */ + __IO uint32_t i2c1rst : 1; /* [21] */ + __IO uint32_t i2c2rst : 1; /* [22] */ + __IO uint32_t i2c3rst : 1; /* [23] */ + __IO uint32_t reserved4 : 1; /* [24] */ + __IO uint32_t can1rst : 1; /* [25] */ + __IO uint32_t can2rst : 1; /* [26] */ + __IO uint32_t reserved5 : 1; /* [27] */ + __IO uint32_t pwcrst : 1; /* [28] */ + __IO uint32_t dacrst : 1; /* [29] */ + __IO uint32_t uart7rst : 1; /* [30] */ + __IO uint32_t uart8rst : 1; /* [31] */ + } apb1rst_bit; + }; - /** - * @brief crm apb2rst register, offset:0x24 - */ - union - { - __IO uint32_t apb2rst; - struct - { - __IO uint32_t tmr1rst : 1; /* [0] */ - __IO uint32_t tmr8rst : 1; /* [1] */ - __IO uint32_t reserved1 : 2; /* [3:2] */ - __IO uint32_t usart1rst : 1; /* [4] */ - __IO uint32_t usart6rst : 1; /* [5] */ - __IO uint32_t reserved2 : 2; /* [7:6] */ - __IO uint32_t adcrst : 1; /* [8] */ - __IO uint32_t reserved3 : 3; /* [11:9] */ - __IO uint32_t spi1rst : 1; /* [12] */ - __IO uint32_t spi4rst : 1; /* [13] */ - __IO uint32_t scfgrst : 1; /* [14] */ - __IO uint32_t reserved4 : 1; /* [15] */ - __IO uint32_t tmr9rst : 1; /* [16] */ - __IO uint32_t tmr10rst : 1; /* [17] */ - __IO uint32_t tmr11rst : 1; /* [18] */ - __IO uint32_t reserved5 : 1; /* [19] */ - __IO uint32_t tmr20rst : 1; /* [20] */ - __IO uint32_t reserved6 : 8; /* [28:21] */ - __IO uint32_t accrst : 1; /* [29] */ - __IO uint32_t reserved7 : 2; /* [31:30] */ - } apb2rst_bit; - }; + /** + * @brief crm apb2rst register, offset:0x24 + */ + union { + __IO uint32_t apb2rst; + struct { + __IO uint32_t tmr1rst : 1; /* [0] */ + __IO uint32_t tmr8rst : 1; /* [1] */ + __IO uint32_t reserved1 : 2; /* [3:2] */ + __IO uint32_t usart1rst : 1; /* [4] */ + __IO uint32_t usart6rst : 1; /* [5] */ + __IO uint32_t reserved2 : 2; /* [7:6] */ + __IO uint32_t adcrst : 1; /* [8] */ + __IO uint32_t reserved3 : 3; /* [11:9] */ + __IO uint32_t spi1rst : 1; /* [12] */ + __IO uint32_t spi4rst : 1; /* [13] */ + __IO uint32_t scfgrst : 1; /* [14] */ + __IO uint32_t reserved4 : 1; /* [15] */ + __IO uint32_t tmr9rst : 1; /* [16] */ + __IO uint32_t tmr10rst : 1; /* [17] */ + __IO uint32_t tmr11rst : 1; /* [18] */ + __IO uint32_t reserved5 : 1; /* [19] */ + __IO uint32_t tmr20rst : 1; /* [20] */ + __IO uint32_t reserved6 : 8; /* [28:21] */ + __IO uint32_t accrst : 1; /* [29] */ + __IO uint32_t reserved7 : 2; /* [31:30] */ + } apb2rst_bit; + }; - /** - * @brief crm reserved2 register, offset:0x28~0x2C - */ - __IO uint32_t reserved2[2]; + /** + * @brief crm reserved2 register, offset:0x28~0x2C + */ + __IO uint32_t reserved2[2]; - /** - * @brief crm ahben1 register, offset:0x30 - */ - union - { - __IO uint32_t ahben1; + /** + * @brief crm ahben1 register, offset:0x30 + */ + union { + __IO uint32_t ahben1; #if defined (AT32F435xx) - struct - { - __IO uint32_t gpioaen : 1; /* [0] */ - __IO uint32_t gpioben : 1; /* [1] */ - __IO uint32_t gpiocen : 1; /* [2] */ - __IO uint32_t gpioden : 1; /* [3] */ - __IO uint32_t gpioeen : 1; /* [4] */ - __IO uint32_t gpiofen : 1; /* [5] */ - __IO uint32_t gpiogen : 1; /* [6] */ - __IO uint32_t gpiohen : 1; /* [7] */ - __IO uint32_t reserved1 : 4; /* [11:8] */ - __IO uint32_t crcen : 1; /* [12] */ - __IO uint32_t reserved2 : 8; /* [20:13] */ - __IO uint32_t edmaen : 1; /* [21] */ - __IO uint32_t dma1en : 1; /* [22] */ - __IO uint32_t reserved3 : 1; /* [23] */ - __IO uint32_t dma2en : 1; /* [24] */ - __IO uint32_t reserved4 : 4; /* [28:25] */ - __IO uint32_t otgfs2en : 1; /* [29] */ - __IO uint32_t reserved5 : 2; /* [31:30] */ - } ahben1_bit; + struct { + __IO uint32_t gpioaen : 1; /* [0] */ + __IO uint32_t gpioben : 1; /* [1] */ + __IO uint32_t gpiocen : 1; /* [2] */ + __IO uint32_t gpioden : 1; /* [3] */ + __IO uint32_t gpioeen : 1; /* [4] */ + __IO uint32_t gpiofen : 1; /* [5] */ + __IO uint32_t gpiogen : 1; /* [6] */ + __IO uint32_t gpiohen : 1; /* [7] */ + __IO uint32_t reserved1 : 4; /* [11:8] */ + __IO uint32_t crcen : 1; /* [12] */ + __IO uint32_t reserved2 : 8; /* [20:13] */ + __IO uint32_t edmaen : 1; /* [21] */ + __IO uint32_t dma1en : 1; /* [22] */ + __IO uint32_t reserved3 : 1; /* [23] */ + __IO uint32_t dma2en : 1; /* [24] */ + __IO uint32_t reserved4 : 4; /* [28:25] */ + __IO uint32_t otgfs2en : 1; /* [29] */ + __IO uint32_t reserved5 : 2; /* [31:30] */ + } ahben1_bit; #endif #if defined (AT32F437xx) - struct - { - __IO uint32_t gpioaen : 1; /* [0] */ - __IO uint32_t gpioben : 1; /* [1] */ - __IO uint32_t gpiocen : 1; /* [2] */ - __IO uint32_t gpioden : 1; /* [3] */ - __IO uint32_t gpioeen : 1; /* [4] */ - __IO uint32_t gpiofen : 1; /* [5] */ - __IO uint32_t gpiogen : 1; /* [6] */ - __IO uint32_t gpiohen : 1; /* [7] */ - __IO uint32_t reserved1 : 4; /* [11:8] */ - __IO uint32_t crcen : 1; /* [12] */ - __IO uint32_t reserved2 : 8; /* [20:13] */ - __IO uint32_t edmaen : 1; /* [21] */ - __IO uint32_t dma1en : 1; /* [22] */ - __IO uint32_t reserved3 : 1; /* [23] */ - __IO uint32_t dma2en : 1; /* [24] */ - __IO uint32_t emacen : 1; /* [25] */ - __IO uint32_t emactxen : 1; /* [26] */ - __IO uint32_t emacrxen : 1; /* [27] */ - __IO uint32_t emacptpen : 1; /* [28] */ - __IO uint32_t otgfs2en : 1; /* [29] */ - __IO uint32_t reserved4 : 2; /* [31:30] */ - } ahben1_bit; + struct { + __IO uint32_t gpioaen : 1; /* [0] */ + __IO uint32_t gpioben : 1; /* [1] */ + __IO uint32_t gpiocen : 1; /* [2] */ + __IO uint32_t gpioden : 1; /* [3] */ + __IO uint32_t gpioeen : 1; /* [4] */ + __IO uint32_t gpiofen : 1; /* [5] */ + __IO uint32_t gpiogen : 1; /* [6] */ + __IO uint32_t gpiohen : 1; /* [7] */ + __IO uint32_t reserved1 : 4; /* [11:8] */ + __IO uint32_t crcen : 1; /* [12] */ + __IO uint32_t reserved2 : 8; /* [20:13] */ + __IO uint32_t edmaen : 1; /* [21] */ + __IO uint32_t dma1en : 1; /* [22] */ + __IO uint32_t reserved3 : 1; /* [23] */ + __IO uint32_t dma2en : 1; /* [24] */ + __IO uint32_t emacen : 1; /* [25] */ + __IO uint32_t emactxen : 1; /* [26] */ + __IO uint32_t emacrxen : 1; /* [27] */ + __IO uint32_t emacptpen : 1; /* [28] */ + __IO uint32_t otgfs2en : 1; /* [29] */ + __IO uint32_t reserved4 : 2; /* [31:30] */ + } ahben1_bit; #endif - }; + }; - /** - * @brief crm ahben2 register, offset:0x34 - */ - union - { - __IO uint32_t ahben2; - struct - { - __IO uint32_t dvpen : 1; /* [0] */ - __IO uint32_t reserved1 : 6; /* [6:1] */ - __IO uint32_t otgfs1en : 1; /* [7] */ - __IO uint32_t reserved2 : 7; /* [14:8] */ - __IO uint32_t sdio1en : 1; /* [15] */ - __IO uint32_t reserved3 : 16;/* [31:16] */ - } ahben2_bit; - }; + /** + * @brief crm ahben2 register, offset:0x34 + */ + union { + __IO uint32_t ahben2; + struct { + __IO uint32_t dvpen : 1; /* [0] */ + __IO uint32_t reserved1 : 6; /* [6:1] */ + __IO uint32_t otgfs1en : 1; /* [7] */ + __IO uint32_t reserved2 : 7; /* [14:8] */ + __IO uint32_t sdio1en : 1; /* [15] */ + __IO uint32_t reserved3 : 16;/* [31:16] */ + } ahben2_bit; + }; - /** - * @brief crm ahben3 register, offset:0x38 - */ - union - { - __IO uint32_t ahben3; - struct - { - __IO uint32_t xmcen : 1; /* [0] */ - __IO uint32_t qspi1en : 1; /* [1] */ - __IO uint32_t reserved1 : 12;/* [13:2] */ - __IO uint32_t qspi2en : 1; /* [14] */ - __IO uint32_t sdio2en : 1; /* [15] */ - __IO uint32_t reserved3 : 16;/* [31:16] */ - } ahben3_bit; - }; + /** + * @brief crm ahben3 register, offset:0x38 + */ + union { + __IO uint32_t ahben3; + struct { + __IO uint32_t xmcen : 1; /* [0] */ + __IO uint32_t qspi1en : 1; /* [1] */ + __IO uint32_t reserved1 : 12;/* [13:2] */ + __IO uint32_t qspi2en : 1; /* [14] */ + __IO uint32_t sdio2en : 1; /* [15] */ + __IO uint32_t reserved3 : 16;/* [31:16] */ + } ahben3_bit; + }; - /** - * @brief crm reserved3 register, offset:0x3C - */ - __IO uint32_t reserved3; + /** + * @brief crm reserved3 register, offset:0x3C + */ + __IO uint32_t reserved3; - /** - * @brief crm apb1en register, offset:0x40 - */ - union - { - __IO uint32_t apb1en; - struct - { - __IO uint32_t tmr2en : 1; /* [0] */ - __IO uint32_t tmr3en : 1; /* [1] */ - __IO uint32_t tmr4en : 1; /* [2] */ - __IO uint32_t tmr5en : 1; /* [3] */ - __IO uint32_t tmr6en : 1; /* [4] */ - __IO uint32_t tmr7en : 1; /* [5] */ - __IO uint32_t tmr12en : 1; /* [6] */ - __IO uint32_t tmr13en : 1; /* [7] */ - __IO uint32_t adc14en : 1; /* [8] */ - __IO uint32_t reserved1 : 2; /* [10:9] */ - __IO uint32_t wwdten : 1; /* [11] */ - __IO uint32_t reserved2 : 2; /* [13:12] */ - __IO uint32_t spi2en : 1; /* [14] */ - __IO uint32_t spi3en : 1; /* [15] */ - __IO uint32_t reserved3 : 1; /* [16] */ - __IO uint32_t usart2en : 1; /* [17] */ - __IO uint32_t usart3en : 1; /* [18] */ - __IO uint32_t uart4en : 1; /* [19] */ - __IO uint32_t uart5en : 1; /* [20] */ - __IO uint32_t i2c1en : 1; /* [21] */ - __IO uint32_t i2c2en : 1; /* [22] */ - __IO uint32_t i2c3en : 1; /* [23] */ - __IO uint32_t reserved4 : 1; /* [24] */ - __IO uint32_t can1en : 1; /* [25] */ - __IO uint32_t can2en : 1; /* [26] */ - __IO uint32_t reserved5 : 1; /* [27] */ - __IO uint32_t pwcen : 1; /* [28] */ - __IO uint32_t dacen : 1; /* [29] */ - __IO uint32_t uart7en : 1; /* [30] */ - __IO uint32_t uart8en : 1; /* [31] */ - } apb1en_bit; - }; + /** + * @brief crm apb1en register, offset:0x40 + */ + union { + __IO uint32_t apb1en; + struct { + __IO uint32_t tmr2en : 1; /* [0] */ + __IO uint32_t tmr3en : 1; /* [1] */ + __IO uint32_t tmr4en : 1; /* [2] */ + __IO uint32_t tmr5en : 1; /* [3] */ + __IO uint32_t tmr6en : 1; /* [4] */ + __IO uint32_t tmr7en : 1; /* [5] */ + __IO uint32_t tmr12en : 1; /* [6] */ + __IO uint32_t tmr13en : 1; /* [7] */ + __IO uint32_t adc14en : 1; /* [8] */ + __IO uint32_t reserved1 : 2; /* [10:9] */ + __IO uint32_t wwdten : 1; /* [11] */ + __IO uint32_t reserved2 : 2; /* [13:12] */ + __IO uint32_t spi2en : 1; /* [14] */ + __IO uint32_t spi3en : 1; /* [15] */ + __IO uint32_t reserved3 : 1; /* [16] */ + __IO uint32_t usart2en : 1; /* [17] */ + __IO uint32_t usart3en : 1; /* [18] */ + __IO uint32_t uart4en : 1; /* [19] */ + __IO uint32_t uart5en : 1; /* [20] */ + __IO uint32_t i2c1en : 1; /* [21] */ + __IO uint32_t i2c2en : 1; /* [22] */ + __IO uint32_t i2c3en : 1; /* [23] */ + __IO uint32_t reserved4 : 1; /* [24] */ + __IO uint32_t can1en : 1; /* [25] */ + __IO uint32_t can2en : 1; /* [26] */ + __IO uint32_t reserved5 : 1; /* [27] */ + __IO uint32_t pwcen : 1; /* [28] */ + __IO uint32_t dacen : 1; /* [29] */ + __IO uint32_t uart7en : 1; /* [30] */ + __IO uint32_t uart8en : 1; /* [31] */ + } apb1en_bit; + }; - /** - * @brief crm apb2en register, offset:0x44 - */ - union - { - __IO uint32_t apb2en; - struct - { - __IO uint32_t tmr1en : 1; /* [0] */ - __IO uint32_t tmr8en : 1; /* [1] */ - __IO uint32_t reserved1 : 2; /* [3:2] */ - __IO uint32_t usart1en : 1; /* [4] */ - __IO uint32_t usart6en : 1; /* [5] */ - __IO uint32_t reserved2 : 2; /* [7:6] */ - __IO uint32_t adcen : 1; /* [8] */ - __IO uint32_t reserved3 : 3; /* [11:9] */ - __IO uint32_t spi1en : 1; /* [12] */ - __IO uint32_t spi4en : 1; /* [13] */ - __IO uint32_t scfgen : 1; /* [14] */ - __IO uint32_t reserved4 : 1; /* [15] */ - __IO uint32_t tmr9en : 1; /* [16] */ - __IO uint32_t tmr10en : 1; /* [17] */ - __IO uint32_t tmr11en : 1; /* [18] */ - __IO uint32_t reserved5 : 1; /* [19] */ - __IO uint32_t tmr20en : 1; /* [20] */ - __IO uint32_t reserved6 : 8; /* [28:21] */ - __IO uint32_t accen : 1; /* [29] */ - __IO uint32_t reserved7 : 2; /* [31:30] */ - } apb2en_bit; - }; + /** + * @brief crm apb2en register, offset:0x44 + */ + union { + __IO uint32_t apb2en; + struct { + __IO uint32_t tmr1en : 1; /* [0] */ + __IO uint32_t tmr8en : 1; /* [1] */ + __IO uint32_t reserved1 : 2; /* [3:2] */ + __IO uint32_t usart1en : 1; /* [4] */ + __IO uint32_t usart6en : 1; /* [5] */ + __IO uint32_t reserved2 : 2; /* [7:6] */ + __IO uint32_t adcen : 1; /* [8] */ + __IO uint32_t reserved3 : 3; /* [11:9] */ + __IO uint32_t spi1en : 1; /* [12] */ + __IO uint32_t spi4en : 1; /* [13] */ + __IO uint32_t scfgen : 1; /* [14] */ + __IO uint32_t reserved4 : 1; /* [15] */ + __IO uint32_t tmr9en : 1; /* [16] */ + __IO uint32_t tmr10en : 1; /* [17] */ + __IO uint32_t tmr11en : 1; /* [18] */ + __IO uint32_t reserved5 : 1; /* [19] */ + __IO uint32_t tmr20en : 1; /* [20] */ + __IO uint32_t reserved6 : 8; /* [28:21] */ + __IO uint32_t accen : 1; /* [29] */ + __IO uint32_t reserved7 : 2; /* [31:30] */ + } apb2en_bit; + }; - /** - * @brief crm reserved4 register, offset:0x48~0x4C - */ - __IO uint32_t reserved4[2]; + /** + * @brief crm reserved4 register, offset:0x48~0x4C + */ + __IO uint32_t reserved4[2]; - /** - * @brief crm ahblpen1 register, offset:0x50 - */ - union - { - __IO uint32_t ahblpen1; + /** + * @brief crm ahblpen1 register, offset:0x50 + */ + union { + __IO uint32_t ahblpen1; #if defined (AT32F435xx) - struct - { - __IO uint32_t gpioalpen : 1; /* [0] */ - __IO uint32_t gpioblpen : 1; /* [1] */ - __IO uint32_t gpioclpen : 1; /* [2] */ - __IO uint32_t gpiodlpen : 1; /* [3] */ - __IO uint32_t gpioelpen : 1; /* [4] */ - __IO uint32_t gpioflpen : 1; /* [5] */ - __IO uint32_t gpioglpen : 1; /* [6] */ - __IO uint32_t gpiohlpen : 1; /* [7] */ - __IO uint32_t reserved1 : 4; /* [11:8] */ - __IO uint32_t crclpen : 1; /* [12] */ - __IO uint32_t reserved2 : 8; /* [20:13] */ - __IO uint32_t edmalpen : 1; /* [21] */ - __IO uint32_t dma1lpen : 1; /* [22] */ - __IO uint32_t reserved3 : 1; /* [23] */ - __IO uint32_t dma2lpen : 1; /* [24] */ - __IO uint32_t reserved4 : 4; /* [28:25] */ - __IO uint32_t otgfs2lpen : 1; /* [29] */ - __IO uint32_t reserved5 : 2; /* [31:30] */ - } ahblpen1_bit; + struct { + __IO uint32_t gpioalpen : 1; /* [0] */ + __IO uint32_t gpioblpen : 1; /* [1] */ + __IO uint32_t gpioclpen : 1; /* [2] */ + __IO uint32_t gpiodlpen : 1; /* [3] */ + __IO uint32_t gpioelpen : 1; /* [4] */ + __IO uint32_t gpioflpen : 1; /* [5] */ + __IO uint32_t gpioglpen : 1; /* [6] */ + __IO uint32_t gpiohlpen : 1; /* [7] */ + __IO uint32_t reserved1 : 4; /* [11:8] */ + __IO uint32_t crclpen : 1; /* [12] */ + __IO uint32_t reserved2 : 8; /* [20:13] */ + __IO uint32_t edmalpen : 1; /* [21] */ + __IO uint32_t dma1lpen : 1; /* [22] */ + __IO uint32_t reserved3 : 1; /* [23] */ + __IO uint32_t dma2lpen : 1; /* [24] */ + __IO uint32_t reserved4 : 4; /* [28:25] */ + __IO uint32_t otgfs2lpen : 1; /* [29] */ + __IO uint32_t reserved5 : 2; /* [31:30] */ + } ahblpen1_bit; #endif #if defined (AT32F437xx) - struct - { - __IO uint32_t gpioalpen : 1; /* [0] */ - __IO uint32_t gpioblpen : 1; /* [1] */ - __IO uint32_t gpioclpen : 1; /* [2] */ - __IO uint32_t gpiodlpen : 1; /* [3] */ - __IO uint32_t gpioelpen : 1; /* [4] */ - __IO uint32_t gpioflpen : 1; /* [5] */ - __IO uint32_t gpioglpen : 1; /* [6] */ - __IO uint32_t gpiohlpen : 1; /* [7] */ - __IO uint32_t reserved1 : 4; /* [11:8] */ - __IO uint32_t crclpen : 1; /* [12] */ - __IO uint32_t reserved2 : 8; /* [20:13] */ - __IO uint32_t edmalpen : 1; /* [21] */ - __IO uint32_t dma1lpen : 1; /* [22] */ - __IO uint32_t reserved3 : 1; /* [23] */ - __IO uint32_t dma2lpen : 1; /* [24] */ - __IO uint32_t emaclpen : 1; /* [25] */ - __IO uint32_t emactxlpen : 1; /* [26] */ - __IO uint32_t emacrxlpen : 1; /* [27] */ - __IO uint32_t emacptplpen : 1; /* [28] */ - __IO uint32_t otgfs2lpen : 1; /* [29] */ - __IO uint32_t reserved4 : 2; /* [31:30] */ - } ahblpen1_bit; + struct { + __IO uint32_t gpioalpen : 1; /* [0] */ + __IO uint32_t gpioblpen : 1; /* [1] */ + __IO uint32_t gpioclpen : 1; /* [2] */ + __IO uint32_t gpiodlpen : 1; /* [3] */ + __IO uint32_t gpioelpen : 1; /* [4] */ + __IO uint32_t gpioflpen : 1; /* [5] */ + __IO uint32_t gpioglpen : 1; /* [6] */ + __IO uint32_t gpiohlpen : 1; /* [7] */ + __IO uint32_t reserved1 : 4; /* [11:8] */ + __IO uint32_t crclpen : 1; /* [12] */ + __IO uint32_t reserved2 : 8; /* [20:13] */ + __IO uint32_t edmalpen : 1; /* [21] */ + __IO uint32_t dma1lpen : 1; /* [22] */ + __IO uint32_t reserved3 : 1; /* [23] */ + __IO uint32_t dma2lpen : 1; /* [24] */ + __IO uint32_t emaclpen : 1; /* [25] */ + __IO uint32_t emactxlpen : 1; /* [26] */ + __IO uint32_t emacrxlpen : 1; /* [27] */ + __IO uint32_t emacptplpen : 1; /* [28] */ + __IO uint32_t otgfs2lpen : 1; /* [29] */ + __IO uint32_t reserved4 : 2; /* [31:30] */ + } ahblpen1_bit; #endif - }; + }; - /** - * @brief crm ahblpen2 register, offset:0x54 - */ - union - { - __IO uint32_t ahblpen2; - struct - { - __IO uint32_t dvplpen : 1; /* [0] */ - __IO uint32_t reserved1 : 6; /* [6:1] */ - __IO uint32_t otgfs1lpen : 1; /* [7] */ - __IO uint32_t reserved2 : 7; /* [14:8] */ - __IO uint32_t sdio1lpen : 1; /* [15] */ - __IO uint32_t reserved3 : 16;/* [31:16] */ - } ahblpen2_bit; - }; + /** + * @brief crm ahblpen2 register, offset:0x54 + */ + union { + __IO uint32_t ahblpen2; + struct { + __IO uint32_t dvplpen : 1; /* [0] */ + __IO uint32_t reserved1 : 6; /* [6:1] */ + __IO uint32_t otgfs1lpen : 1; /* [7] */ + __IO uint32_t reserved2 : 7; /* [14:8] */ + __IO uint32_t sdio1lpen : 1; /* [15] */ + __IO uint32_t reserved3 : 16;/* [31:16] */ + } ahblpen2_bit; + }; - /** - * @brief crm ahblpen3 register, offset:0x58 - */ - union - { - __IO uint32_t ahblpen3; - struct - { - __IO uint32_t xmclpen : 1; /* [0] */ - __IO uint32_t qspi1lpen : 1; /* [1] */ - __IO uint32_t reserved1 : 12;/* [13:2] */ - __IO uint32_t qspi2lpen : 1; /* [14] */ - __IO uint32_t sdio2lpen : 1; /* [15] */ - __IO uint32_t reserved3 : 16;/* [31:16] */ - } ahblpen3_bit; - }; + /** + * @brief crm ahblpen3 register, offset:0x58 + */ + union { + __IO uint32_t ahblpen3; + struct { + __IO uint32_t xmclpen : 1; /* [0] */ + __IO uint32_t qspi1lpen : 1; /* [1] */ + __IO uint32_t reserved1 : 12;/* [13:2] */ + __IO uint32_t qspi2lpen : 1; /* [14] */ + __IO uint32_t sdio2lpen : 1; /* [15] */ + __IO uint32_t reserved3 : 16;/* [31:16] */ + } ahblpen3_bit; + }; - /** - * @brief crm reserved5 register, offset:0x5C - */ - __IO uint32_t reserved5; + /** + * @brief crm reserved5 register, offset:0x5C + */ + __IO uint32_t reserved5; - /** - * @brief crm apb1lpen register, offset:0x60 - */ - union - { - __IO uint32_t apb1lpen; - struct - { - __IO uint32_t tmr2lpen : 1; /* [0] */ - __IO uint32_t tmr3lpen : 1; /* [1] */ - __IO uint32_t tmr4lpen : 1; /* [2] */ - __IO uint32_t tmr5lpen : 1; /* [3] */ - __IO uint32_t tmr6lpen : 1; /* [4] */ - __IO uint32_t tmr7lpen : 1; /* [5] */ - __IO uint32_t tmr12lpen : 1; /* [6] */ - __IO uint32_t tmr13lpen : 1; /* [7] */ - __IO uint32_t adc14lpen : 1; /* [8] */ - __IO uint32_t reserved1 : 2; /* [10:9] */ - __IO uint32_t wwdtlpen : 1; /* [11] */ - __IO uint32_t reserved2 : 2; /* [13:12] */ - __IO uint32_t spi2lpen : 1; /* [14] */ - __IO uint32_t spi3lpen : 1; /* [15] */ - __IO uint32_t reserved3 : 1; /* [16] */ - __IO uint32_t usart2lpen : 1; /* [17] */ - __IO uint32_t usart3lpen : 1; /* [18] */ - __IO uint32_t uart4lpen : 1; /* [19] */ - __IO uint32_t uart5lpen : 1; /* [20] */ - __IO uint32_t i2c1lpen : 1; /* [21] */ - __IO uint32_t i2c2lpen : 1; /* [22] */ - __IO uint32_t i2c3lpen : 1; /* [23] */ - __IO uint32_t reserved4 : 1; /* [24] */ - __IO uint32_t can1lpen : 1; /* [25] */ - __IO uint32_t can2lpen : 1; /* [26] */ - __IO uint32_t reserved5 : 1; /* [27] */ - __IO uint32_t pwclpen : 1; /* [28] */ - __IO uint32_t daclpen : 1; /* [29] */ - __IO uint32_t uart7lpen : 1; /* [30] */ - __IO uint32_t uart8lpen : 1; /* [31] */ - } apb1lpen_bit; - }; + /** + * @brief crm apb1lpen register, offset:0x60 + */ + union { + __IO uint32_t apb1lpen; + struct { + __IO uint32_t tmr2lpen : 1; /* [0] */ + __IO uint32_t tmr3lpen : 1; /* [1] */ + __IO uint32_t tmr4lpen : 1; /* [2] */ + __IO uint32_t tmr5lpen : 1; /* [3] */ + __IO uint32_t tmr6lpen : 1; /* [4] */ + __IO uint32_t tmr7lpen : 1; /* [5] */ + __IO uint32_t tmr12lpen : 1; /* [6] */ + __IO uint32_t tmr13lpen : 1; /* [7] */ + __IO uint32_t adc14lpen : 1; /* [8] */ + __IO uint32_t reserved1 : 2; /* [10:9] */ + __IO uint32_t wwdtlpen : 1; /* [11] */ + __IO uint32_t reserved2 : 2; /* [13:12] */ + __IO uint32_t spi2lpen : 1; /* [14] */ + __IO uint32_t spi3lpen : 1; /* [15] */ + __IO uint32_t reserved3 : 1; /* [16] */ + __IO uint32_t usart2lpen : 1; /* [17] */ + __IO uint32_t usart3lpen : 1; /* [18] */ + __IO uint32_t uart4lpen : 1; /* [19] */ + __IO uint32_t uart5lpen : 1; /* [20] */ + __IO uint32_t i2c1lpen : 1; /* [21] */ + __IO uint32_t i2c2lpen : 1; /* [22] */ + __IO uint32_t i2c3lpen : 1; /* [23] */ + __IO uint32_t reserved4 : 1; /* [24] */ + __IO uint32_t can1lpen : 1; /* [25] */ + __IO uint32_t can2lpen : 1; /* [26] */ + __IO uint32_t reserved5 : 1; /* [27] */ + __IO uint32_t pwclpen : 1; /* [28] */ + __IO uint32_t daclpen : 1; /* [29] */ + __IO uint32_t uart7lpen : 1; /* [30] */ + __IO uint32_t uart8lpen : 1; /* [31] */ + } apb1lpen_bit; + }; - /** - * @brief crm apb2lpen register, offset:0x64 - */ - union - { - __IO uint32_t apb2lpen; - struct - { - __IO uint32_t tmr1lpen : 1; /* [0] */ - __IO uint32_t tmr8lpen : 1; /* [1] */ - __IO uint32_t reserved1 : 2; /* [3:2] */ - __IO uint32_t usart1lpen : 1; /* [4] */ - __IO uint32_t usart6lpen : 1; /* [5] */ - __IO uint32_t reserved2 : 2; /* [7:6] */ - __IO uint32_t adclpen : 1; /* [8] */ - __IO uint32_t reserved3 : 3; /* [11:9] */ - __IO uint32_t spi1lpen : 1; /* [12] */ - __IO uint32_t spi4lpen : 1; /* [13] */ - __IO uint32_t scfglpen : 1; /* [14] */ - __IO uint32_t reserved4 : 1; /* [15] */ - __IO uint32_t tmr9lpen : 1; /* [16] */ - __IO uint32_t tmr10lpen : 1; /* [17] */ - __IO uint32_t tmr11lpen : 1; /* [18] */ - __IO uint32_t reserved5 : 1; /* [19] */ - __IO uint32_t tmr20lpen : 1; /* [20] */ - __IO uint32_t reserved6 : 8; /* [28:21] */ - __IO uint32_t acclpen : 1; /* [29] */ - __IO uint32_t reserved7 : 2; /* [31:30] */ - } apb2lpen_bit; - }; + /** + * @brief crm apb2lpen register, offset:0x64 + */ + union { + __IO uint32_t apb2lpen; + struct { + __IO uint32_t tmr1lpen : 1; /* [0] */ + __IO uint32_t tmr8lpen : 1; /* [1] */ + __IO uint32_t reserved1 : 2; /* [3:2] */ + __IO uint32_t usart1lpen : 1; /* [4] */ + __IO uint32_t usart6lpen : 1; /* [5] */ + __IO uint32_t reserved2 : 2; /* [7:6] */ + __IO uint32_t adclpen : 1; /* [8] */ + __IO uint32_t reserved3 : 3; /* [11:9] */ + __IO uint32_t spi1lpen : 1; /* [12] */ + __IO uint32_t spi4lpen : 1; /* [13] */ + __IO uint32_t scfglpen : 1; /* [14] */ + __IO uint32_t reserved4 : 1; /* [15] */ + __IO uint32_t tmr9lpen : 1; /* [16] */ + __IO uint32_t tmr10lpen : 1; /* [17] */ + __IO uint32_t tmr11lpen : 1; /* [18] */ + __IO uint32_t reserved5 : 1; /* [19] */ + __IO uint32_t tmr20lpen : 1; /* [20] */ + __IO uint32_t reserved6 : 8; /* [28:21] */ + __IO uint32_t acclpen : 1; /* [29] */ + __IO uint32_t reserved7 : 2; /* [31:30] */ + } apb2lpen_bit; + }; - /** - * @brief crm reserved6 register, offset:0x68~0x6C - */ - __IO uint32_t reserved6[2]; + /** + * @brief crm reserved6 register, offset:0x68~0x6C + */ + __IO uint32_t reserved6[2]; - /** - * @brief crm bpdc register, offset:0x70 - */ - union - { - __IO uint32_t bpdc; - struct - { - __IO uint32_t lexten : 1; /* [0] */ - __IO uint32_t lextstbl : 1; /* [1] */ - __IO uint32_t lextbyps : 1; /* [2] */ - __IO uint32_t reserved1 : 5; /* [7:3] */ - __IO uint32_t ertcsel : 2; /* [9:8] */ - __IO uint32_t reserved2 : 5; /* [14:10] */ - __IO uint32_t ertcen : 1; /* [15] */ - __IO uint32_t bpdrst : 1; /* [16] */ - __IO uint32_t reserved3 : 15;/* [31:17] */ - } bpdc_bit; - }; + /** + * @brief crm bpdc register, offset:0x70 + */ + union { + __IO uint32_t bpdc; + struct { + __IO uint32_t lexten : 1; /* [0] */ + __IO uint32_t lextstbl : 1; /* [1] */ + __IO uint32_t lextbyps : 1; /* [2] */ + __IO uint32_t reserved1 : 5; /* [7:3] */ + __IO uint32_t ertcsel : 2; /* [9:8] */ + __IO uint32_t reserved2 : 5; /* [14:10] */ + __IO uint32_t ertcen : 1; /* [15] */ + __IO uint32_t bpdrst : 1; /* [16] */ + __IO uint32_t reserved3 : 15;/* [31:17] */ + } bpdc_bit; + }; - /** - * @brief crm ctrlsts register, offset:0x74 - */ - union - { - __IO uint32_t ctrlsts; - struct - { - __IO uint32_t licken : 1; /* [0] */ - __IO uint32_t lickstbl : 1; /* [1] */ - __IO uint32_t reserved1 : 22;/* [23:2] */ - __IO uint32_t rstfc : 1; /* [24] */ - __IO uint32_t reserved2 : 1; /* [25] */ - __IO uint32_t nrstf : 1; /* [26] */ - __IO uint32_t porrstf : 1; /* [27] */ - __IO uint32_t swrstf : 1; /* [28] */ - __IO uint32_t wdtrstf : 1; /* [29] */ - __IO uint32_t wwdtrstf : 1; /* [30] */ - __IO uint32_t lprstf : 1; /* [31] */ - } ctrlsts_bit; - }; + /** + * @brief crm ctrlsts register, offset:0x74 + */ + union { + __IO uint32_t ctrlsts; + struct { + __IO uint32_t licken : 1; /* [0] */ + __IO uint32_t lickstbl : 1; /* [1] */ + __IO uint32_t reserved1 : 22;/* [23:2] */ + __IO uint32_t rstfc : 1; /* [24] */ + __IO uint32_t reserved2 : 1; /* [25] */ + __IO uint32_t nrstf : 1; /* [26] */ + __IO uint32_t porrstf : 1; /* [27] */ + __IO uint32_t swrstf : 1; /* [28] */ + __IO uint32_t wdtrstf : 1; /* [29] */ + __IO uint32_t wwdtrstf : 1; /* [30] */ + __IO uint32_t lprstf : 1; /* [31] */ + } ctrlsts_bit; + }; - /** - * @brief crm reserved7 register, offset:0x78~0x9C - */ - __IO uint32_t reserved7[10]; + /** + * @brief crm reserved7 register, offset:0x78~0x9C + */ + __IO uint32_t reserved7[10]; - /** - * @brief crm misc1 register, offset:0xA0 - */ - union - { - __IO uint32_t misc1; - struct - { - __IO uint32_t hickcal_key : 8; /* [7:0] */ - __IO uint32_t reserved1 : 4; /* [11:8] */ - __IO uint32_t hickdiv : 1; /* [12] */ - __IO uint32_t hick_to_usb : 1; /* [13] */ - __IO uint32_t hick_to_sclk : 1; /* [14] */ - __IO uint32_t reserved2 : 1; /* [15] */ - __IO uint32_t clkout2_sel2 : 4; /* [19:16] */ - __IO uint32_t reserved3 : 4; /* [23:20] */ - __IO uint32_t clkout1div2 : 4; /* [27:24] */ - __IO uint32_t clkout2div2 : 4; /* [31:28] */ - } misc1_bit; - }; + /** + * @brief crm misc1 register, offset:0xA0 + */ + union { + __IO uint32_t misc1; + struct { + __IO uint32_t hickcal_key : 8; /* [7:0] */ + __IO uint32_t reserved1 : 4; /* [11:8] */ + __IO uint32_t hickdiv : 1; /* [12] */ + __IO uint32_t hick_to_usb : 1; /* [13] */ + __IO uint32_t hick_to_sclk : 1; /* [14] */ + __IO uint32_t reserved2 : 1; /* [15] */ + __IO uint32_t clkout2_sel2 : 4; /* [19:16] */ + __IO uint32_t reserved3 : 4; /* [23:20] */ + __IO uint32_t clkout1div2 : 4; /* [27:24] */ + __IO uint32_t clkout2div2 : 4; /* [31:28] */ + } misc1_bit; + }; - /** - * @brief crm misc2 register, offset:0xA4 - */ - union - { - __IO uint32_t misc2; - struct - { - __IO uint32_t reserved1 : 4; /* [3:0] */ - __IO uint32_t auto_step_en : 2; /* [5:4] */ - __IO uint32_t reserved2 : 2; /* [7:6] */ - __IO uint32_t clk_to_tmr : 1; /* [8] */ - __IO uint32_t emac_pps_sel : 1; /* [9] */ - __IO uint32_t reserved3 : 2; /* [11:10] */ - __IO uint32_t usbdiv : 4; /* [15:12] */ - __IO uint32_t reserved4 : 16;/* [31:16] */ - } misc2_bit; - }; + /** + * @brief crm misc2 register, offset:0xA4 + */ + union { + __IO uint32_t misc2; + struct { + __IO uint32_t reserved1 : 4; /* [3:0] */ + __IO uint32_t auto_step_en : 2; /* [5:4] */ + __IO uint32_t reserved2 : 2; /* [7:6] */ + __IO uint32_t clk_to_tmr : 1; /* [8] */ + __IO uint32_t emac_pps_sel : 1; /* [9] */ + __IO uint32_t reserved3 : 2; /* [11:10] */ + __IO uint32_t usbdiv : 4; /* [15:12] */ + __IO uint32_t reserved4 : 16;/* [31:16] */ + } misc2_bit; + }; } crm_type; diff --git a/armlib/at32_sys/drivers/inc/at32f435_437_dac.h b/armlib/at32_sys/drivers/inc/at32f435_437_dac.h index a09aac851..817d51f17 100644 --- a/armlib/at32_sys/drivers/inc/at32f435_437_dac.h +++ b/armlib/at32_sys/drivers/inc/at32f435_437_dac.h @@ -52,297 +52,261 @@ extern "C" { /** * @brief dac select type */ -typedef enum -{ - DAC1_SELECT = 0x01, /*!< dac1 select */ - DAC2_SELECT = 0x02 /*!< dac2 select */ +typedef enum { + DAC1_SELECT = 0x01, /*!< dac1 select */ + DAC2_SELECT = 0x02 /*!< dac2 select */ } dac_select_type; /** * @brief dac trigger type */ -typedef enum -{ - DAC_TMR6_TRGOUT_EVENT = 0x00, /*!< dac trigger selection:timer6 trgout event */ - DAC_TMR8_TRGOUT_EVENT = 0x01, /*!< dac trigger selection:timer8 trgout event */ - DAC_TMR7_TRGOUT_EVENT = 0x02, /*!< dac trigger selection:timer7 trgout event */ - DAC_TMR5_TRGOUT_EVENT = 0x03, /*!< dac trigger selection:timer5 trgout event */ - DAC_TMR2_TRGOUT_EVENT = 0x04, /*!< dac trigger selection:timer2 trgout event */ - DAC_TMR4_TRGOUT_EVENT = 0x05, /*!< dac trigger selection:timer4 trgout event */ - DAC_EXTERNAL_INTERRUPT_LINE_9 = 0x06, /*!< dac trigger selection:external line9 */ - DAC_SOFTWARE_TRIGGER = 0x07 /*!< dac trigger selection:software trigger */ +typedef enum { + DAC_TMR6_TRGOUT_EVENT = 0x00, /*!< dac trigger selection:timer6 trgout event */ + DAC_TMR8_TRGOUT_EVENT = 0x01, /*!< dac trigger selection:timer8 trgout event */ + DAC_TMR7_TRGOUT_EVENT = 0x02, /*!< dac trigger selection:timer7 trgout event */ + DAC_TMR5_TRGOUT_EVENT = 0x03, /*!< dac trigger selection:timer5 trgout event */ + DAC_TMR2_TRGOUT_EVENT = 0x04, /*!< dac trigger selection:timer2 trgout event */ + DAC_TMR4_TRGOUT_EVENT = 0x05, /*!< dac trigger selection:timer4 trgout event */ + DAC_EXTERNAL_INTERRUPT_LINE_9 = 0x06, /*!< dac trigger selection:external line9 */ + DAC_SOFTWARE_TRIGGER = 0x07 /*!< dac trigger selection:software trigger */ } dac_trigger_type; /** * @brief dac wave type */ -typedef enum -{ - DAC_WAVE_GENERATE_NONE = 0x00, /*!< dac wave generation disabled */ - DAC_WAVE_GENERATE_NOISE = 0x01, /*!< dac noise wave generation enabled */ - DAC_WAVE_GENERATE_TRIANGLE = 0x02 /*!< dac triangle wave generation enabled */ +typedef enum { + DAC_WAVE_GENERATE_NONE = 0x00, /*!< dac wave generation disabled */ + DAC_WAVE_GENERATE_NOISE = 0x01, /*!< dac noise wave generation enabled */ + DAC_WAVE_GENERATE_TRIANGLE = 0x02 /*!< dac triangle wave generation enabled */ } dac_wave_type; /** * @brief dac mask amplitude type */ -typedef enum -{ - DAC_LSFR_BIT0_AMPLITUDE_1 = 0x00, /*!< unmask bit0/ triangle amplitude equal to 1 */ - DAC_LSFR_BIT10_AMPLITUDE_3 = 0x01, /*!< unmask bit[1:0]/ triangle amplitude equal to 3 */ - DAC_LSFR_BIT20_AMPLITUDE_7 = 0x02, /*!< unmask bit[2:0]/ triangle amplitude equal to 7 */ - DAC_LSFR_BIT30_AMPLITUDE_15 = 0x03, /*!< unmask bit[3:0]/ triangle amplitude equal to 15 */ - DAC_LSFR_BIT40_AMPLITUDE_31 = 0x04, /*!< unmask bit[4:0]/ triangle amplitude equal to 31 */ - DAC_LSFR_BIT50_AMPLITUDE_63 = 0x05, /*!< unmask bit[5:0]/ triangle amplitude equal to 63 */ - DAC_LSFR_BIT60_AMPLITUDE_127 = 0x06, /*!< unmask bit[6:0]/ triangle amplitude equal to 127 */ - DAC_LSFR_BIT70_AMPLITUDE_255 = 0x07, /*!< unmask bit[7:0]/ triangle amplitude equal to 255 */ - DAC_LSFR_BIT80_AMPLITUDE_511 = 0x08, /*!< unmask bit[8:0]/ triangle amplitude equal to 511 */ - DAC_LSFR_BIT90_AMPLITUDE_1023 = 0x09, /*!< unmask bit[9:0]/ triangle amplitude equal to 1023 */ - DAC_LSFR_BITA0_AMPLITUDE_2047 = 0x0A, /*!< unmask bit[10:0]/ triangle amplitude equal to 2047 */ - DAC_LSFR_BITB0_AMPLITUDE_4095 = 0x0B /*!< unmask bit[11:0]/ triangle amplitude equal to 4095 */ +typedef enum { + DAC_LSFR_BIT0_AMPLITUDE_1 = 0x00, /*!< unmask bit0/ triangle amplitude equal to 1 */ + DAC_LSFR_BIT10_AMPLITUDE_3 = 0x01, /*!< unmask bit[1:0]/ triangle amplitude equal to 3 */ + DAC_LSFR_BIT20_AMPLITUDE_7 = 0x02, /*!< unmask bit[2:0]/ triangle amplitude equal to 7 */ + DAC_LSFR_BIT30_AMPLITUDE_15 = 0x03, /*!< unmask bit[3:0]/ triangle amplitude equal to 15 */ + DAC_LSFR_BIT40_AMPLITUDE_31 = 0x04, /*!< unmask bit[4:0]/ triangle amplitude equal to 31 */ + DAC_LSFR_BIT50_AMPLITUDE_63 = 0x05, /*!< unmask bit[5:0]/ triangle amplitude equal to 63 */ + DAC_LSFR_BIT60_AMPLITUDE_127 = 0x06, /*!< unmask bit[6:0]/ triangle amplitude equal to 127 */ + DAC_LSFR_BIT70_AMPLITUDE_255 = 0x07, /*!< unmask bit[7:0]/ triangle amplitude equal to 255 */ + DAC_LSFR_BIT80_AMPLITUDE_511 = 0x08, /*!< unmask bit[8:0]/ triangle amplitude equal to 511 */ + DAC_LSFR_BIT90_AMPLITUDE_1023 = 0x09, /*!< unmask bit[9:0]/ triangle amplitude equal to 1023 */ + DAC_LSFR_BITA0_AMPLITUDE_2047 = 0x0A, /*!< unmask bit[10:0]/ triangle amplitude equal to 2047 */ + DAC_LSFR_BITB0_AMPLITUDE_4095 = 0x0B /*!< unmask bit[11:0]/ triangle amplitude equal to 4095 */ } dac_mask_amplitude_type; /** * @brief dac1 aligned data type */ -typedef enum -{ - DAC1_12BIT_RIGHT = 0x40007408, /*!< dac1 12-bit data right-aligned */ - DAC1_12BIT_LEFT = 0x4000740C, /*!< dac1 12-bit data left-aligned */ - DAC1_8BIT_RIGHT = 0x40007410 /*!< dac1 8-bit data right-aligned */ +typedef enum { + DAC1_12BIT_RIGHT = 0x40007408, /*!< dac1 12-bit data right-aligned */ + DAC1_12BIT_LEFT = 0x4000740C, /*!< dac1 12-bit data left-aligned */ + DAC1_8BIT_RIGHT = 0x40007410 /*!< dac1 8-bit data right-aligned */ } dac1_aligned_data_type; /** * @brief dac2 aligned data type */ -typedef enum -{ - DAC2_12BIT_RIGHT = 0x40007414, /*!< dac2 12-bit data right-aligned */ - DAC2_12BIT_LEFT = 0x40007418, /*!< dac2 12-bit data left-aligned */ - DAC2_8BIT_RIGHT = 0x4000741C /*!< dac2 8-bit data right-aligned */ +typedef enum { + DAC2_12BIT_RIGHT = 0x40007414, /*!< dac2 12-bit data right-aligned */ + DAC2_12BIT_LEFT = 0x40007418, /*!< dac2 12-bit data left-aligned */ + DAC2_8BIT_RIGHT = 0x4000741C /*!< dac2 8-bit data right-aligned */ } dac2_aligned_data_type; /** * @brief dac dual data type */ -typedef enum -{ - DAC_DUAL_12BIT_RIGHT = 0x40007420, /*!ctrl1_bit.entrim = FALSE; - } - else - { - ACC->ctrl1_bit.entrim = TRUE; - } - ACC->ctrl1_bit.calon = new_state; +void acc_calibration_mode_enable(uint16_t acc_trim, confirm_state new_state) { + if (acc_trim == ACC_CAL_HICKCAL) { + ACC->ctrl1_bit.entrim = FALSE; + } else { + ACC->ctrl1_bit.entrim = TRUE; + } + ACC->ctrl1_bit.calon = new_state; } /** @@ -67,9 +63,8 @@ void acc_calibration_mode_enable(uint16_t acc_trim, confirm_state new_state) * @param step_value: value to be stored in the acc's ctrl1 register * @retval none */ -void acc_step_set(uint8_t step_value) -{ - ACC->ctrl1_bit.step = step_value; +void acc_step_set(uint8_t step_value) { + ACC->ctrl1_bit.step = step_value; } /** @@ -80,9 +75,8 @@ void acc_step_set(uint8_t step_value) * @arg ACC_SOF_OTG2 * @retval none */ -void acc_sof_select(uint16_t sof_sel) -{ - ACC->ctrl1 |= sof_sel; +void acc_sof_select(uint16_t sof_sel) { + ACC->ctrl1 |= sof_sel; } /** @@ -94,16 +88,12 @@ void acc_sof_select(uint16_t sof_sel) * @param new_state (TRUE or FALSE) * @retval none */ -void acc_interrupt_enable(uint16_t acc_int, confirm_state new_state) -{ - if(acc_int == ACC_CALRDYIEN_INT) - { - ACC->ctrl1_bit.calrdyien = new_state; - } - else - { - ACC->ctrl1_bit.eien = new_state; - } +void acc_interrupt_enable(uint16_t acc_int, confirm_state new_state) { + if (acc_int == ACC_CALRDYIEN_INT) { + ACC->ctrl1_bit.calrdyien = new_state; + } else { + ACC->ctrl1_bit.eien = new_state; + } } /** @@ -111,9 +101,8 @@ void acc_interrupt_enable(uint16_t acc_int, confirm_state new_state) * @param none * @retval 8-bit hicktrim value. */ -uint8_t acc_hicktrim_get(void) -{ - return ((uint8_t)(ACC->ctrl2_bit.hicktrim)); +uint8_t acc_hicktrim_get(void) { + return ((uint8_t)(ACC->ctrl2_bit.hicktrim)); } /** @@ -121,9 +110,8 @@ uint8_t acc_hicktrim_get(void) * @param none * @retval 8-bit hicktrim value. */ -uint8_t acc_hickcal_get(void) -{ - return ((uint8_t)(ACC->ctrl2_bit.hickcal)); +uint8_t acc_hickcal_get(void) { + return ((uint8_t)(ACC->ctrl2_bit.hickcal)); } /** @@ -131,9 +119,8 @@ uint8_t acc_hickcal_get(void) * @param acc_c1_value * @retval none. */ -void acc_write_c1(uint16_t acc_c1_value) -{ - ACC->c1 = acc_c1_value; +void acc_write_c1(uint16_t acc_c1_value) { + ACC->c1 = acc_c1_value; } /** @@ -141,9 +128,8 @@ void acc_write_c1(uint16_t acc_c1_value) * @param acc_c2_value * @retval none. */ -void acc_write_c2(uint16_t acc_c2_value) -{ - ACC->c2 = acc_c2_value; +void acc_write_c2(uint16_t acc_c2_value) { + ACC->c2 = acc_c2_value; } /** @@ -151,9 +137,8 @@ void acc_write_c2(uint16_t acc_c2_value) * @param acc_c3_value * @retval none. */ -void acc_write_c3(uint16_t acc_c3_value) -{ - ACC->c3 = acc_c3_value; +void acc_write_c3(uint16_t acc_c3_value) { + ACC->c3 = acc_c3_value; } /** @@ -161,9 +146,8 @@ void acc_write_c3(uint16_t acc_c3_value) * @param none * @retval 16-bit c1 value. */ -uint16_t acc_read_c1(void) -{ - return ((uint16_t)(ACC->c1)); +uint16_t acc_read_c1(void) { + return ((uint16_t)(ACC->c1)); } /** @@ -171,9 +155,8 @@ uint16_t acc_read_c1(void) * @param none * @retval 16-bit c2 value. */ -uint16_t acc_read_c2(void) -{ - return ((uint16_t)(ACC->c2)); +uint16_t acc_read_c2(void) { + return ((uint16_t)(ACC->c2)); } /** @@ -181,9 +164,8 @@ uint16_t acc_read_c2(void) * @param none * @retval 16-bit c3 value. */ -uint16_t acc_read_c3(void) -{ - return ((uint16_t)(ACC->c3)); +uint16_t acc_read_c3(void) { + return ((uint16_t)(ACC->c3)); } /** @@ -194,12 +176,11 @@ uint16_t acc_read_c3(void) * - ACC_CALRDY_FLAG * @retval flag_status (SET or RESET) */ -flag_status acc_flag_get(uint16_t acc_flag) -{ - if(acc_flag == ACC_CALRDY_FLAG) - return (flag_status)(ACC->sts_bit.calrdy); - else - return (flag_status)(ACC->sts_bit.rslost); +flag_status acc_flag_get(uint16_t acc_flag) { + if (acc_flag == ACC_CALRDY_FLAG) + return (flag_status)(ACC->sts_bit.calrdy); + else + return (flag_status)(ACC->sts_bit.rslost); } /** @@ -210,12 +191,11 @@ flag_status acc_flag_get(uint16_t acc_flag) * - ACC_CALRDY_FLAG * @retval flag_status (SET or RESET) */ -flag_status acc_interrupt_flag_get(uint16_t acc_flag) -{ - if(acc_flag == ACC_CALRDY_FLAG) - return (flag_status)(ACC->sts_bit.calrdy && ACC->ctrl1_bit.calrdyien); - else - return (flag_status)(ACC->sts_bit.rslost && ACC->ctrl1_bit.eien); +flag_status acc_interrupt_flag_get(uint16_t acc_flag) { + if (acc_flag == ACC_CALRDY_FLAG) + return (flag_status)(ACC->sts_bit.calrdy && ACC->ctrl1_bit.calrdyien); + else + return (flag_status)(ACC->sts_bit.rslost && ACC->ctrl1_bit.eien); } @@ -227,9 +207,8 @@ flag_status acc_interrupt_flag_get(uint16_t acc_flag) * - ACC_CALRDY_FLAG * @retval none */ -void acc_flag_clear(uint16_t acc_flag) -{ - ACC->sts = ~acc_flag; +void acc_flag_clear(uint16_t acc_flag) { + ACC->sts = ~acc_flag; } /** diff --git a/armlib/at32_sys/drivers/src/at32f435_437_adc.c b/armlib/at32_sys/drivers/src/at32f435_437_adc.c index 509e90097..39967e3d9 100644 --- a/armlib/at32_sys/drivers/src/at32f435_437_adc.c +++ b/armlib/at32_sys/drivers/src/at32f435_437_adc.c @@ -46,10 +46,9 @@ * @param none * @retval none */ -void adc_reset(void) -{ - crm_periph_reset(CRM_ADC_PERIPH_RESET, TRUE); - crm_periph_reset(CRM_ADC_PERIPH_RESET, FALSE); +void adc_reset(void) { + crm_periph_reset(CRM_ADC_PERIPH_RESET, TRUE); + crm_periph_reset(CRM_ADC_PERIPH_RESET, FALSE); } /** @@ -61,9 +60,8 @@ void adc_reset(void) * this parameter can be: TRUE or FALSE. * @retval none */ -void adc_enable(adc_type *adc_x, confirm_state new_state) -{ - adc_x->ctrl2_bit.adcen = new_state; +void adc_enable(adc_type *adc_x, confirm_state new_state) { + adc_x->ctrl2_bit.adcen = new_state; } /** @@ -81,12 +79,11 @@ void adc_enable(adc_type *adc_x, confirm_state new_state) * - (0x1~0x10) * @retval none */ -void adc_base_default_para_init(adc_base_config_type *adc_base_struct) -{ - adc_base_struct->sequence_mode = FALSE; - adc_base_struct->repeat_mode = FALSE; - adc_base_struct->data_align = ADC_RIGHT_ALIGNMENT; - adc_base_struct->ordinary_channel_length = 1; +void adc_base_default_para_init(adc_base_config_type *adc_base_struct) { + adc_base_struct->sequence_mode = FALSE; + adc_base_struct->repeat_mode = FALSE; + adc_base_struct->data_align = ADC_RIGHT_ALIGNMENT; + adc_base_struct->ordinary_channel_length = 1; } /** @@ -107,12 +104,11 @@ void adc_base_default_para_init(adc_base_config_type *adc_base_struct) * - (0x1~0x10) * @retval none */ -void adc_base_config(adc_type *adc_x, adc_base_config_type *adc_base_struct) -{ - adc_x->ctrl1_bit.sqen = adc_base_struct->sequence_mode; - adc_x->ctrl2_bit.rpen = adc_base_struct->repeat_mode; - adc_x->ctrl2_bit.dtalign = adc_base_struct->data_align; - adc_x->osq1_bit.oclen = adc_base_struct->ordinary_channel_length - 1; +void adc_base_config(adc_type *adc_x, adc_base_config_type *adc_base_struct) { + adc_x->ctrl1_bit.sqen = adc_base_struct->sequence_mode; + adc_x->ctrl2_bit.rpen = adc_base_struct->repeat_mode; + adc_x->ctrl2_bit.dtalign = adc_base_struct->data_align; + adc_x->osq1_bit.oclen = adc_base_struct->ordinary_channel_length - 1; } /** @@ -152,15 +148,14 @@ void adc_base_config(adc_type *adc_x, adc_base_config_type *adc_base_struct) * this parameter can be:TRUE or FALSE * @retval none */ -void adc_common_default_para_init(adc_common_config_type *adc_common_struct) -{ - adc_common_struct->combine_mode = ADC_INDEPENDENT_MODE; - adc_common_struct->div = ADC_HCLK_DIV_2; - adc_common_struct->common_dma_mode = ADC_COMMON_DMAMODE_DISABLE; - adc_common_struct->common_dma_request_repeat_state = FALSE; - adc_common_struct->sampling_interval = ADC_SAMPLING_INTERVAL_5CYCLES; - adc_common_struct->tempervintrv_state = FALSE; - adc_common_struct->vbat_state = FALSE; +void adc_common_default_para_init(adc_common_config_type *adc_common_struct) { + adc_common_struct->combine_mode = ADC_INDEPENDENT_MODE; + adc_common_struct->div = ADC_HCLK_DIV_2; + adc_common_struct->common_dma_mode = ADC_COMMON_DMAMODE_DISABLE; + adc_common_struct->common_dma_request_repeat_state = FALSE; + adc_common_struct->sampling_interval = ADC_SAMPLING_INTERVAL_5CYCLES; + adc_common_struct->tempervintrv_state = FALSE; + adc_common_struct->vbat_state = FALSE; } /** @@ -200,23 +195,19 @@ void adc_common_default_para_init(adc_common_config_type *adc_common_struct) * this parameter can be:TRUE or FALSE * @retval none */ -void adc_common_config(adc_common_config_type *adc_common_struct) -{ - ADCCOM->cctrl_bit.mssel = adc_common_struct->combine_mode; - ADCCOM->cctrl_bit.adcdiv = adc_common_struct->div; - if(adc_common_struct->common_dma_mode & 0x04) - { - ADCCOM->cctrl_bit.msdmasel_h = TRUE; - } - else - { - ADCCOM->cctrl_bit.msdmasel_h = FALSE; - } - ADCCOM->cctrl_bit.msdmasel_l = adc_common_struct->common_dma_mode &0x03; - ADCCOM->cctrl_bit.msdrcen = adc_common_struct->common_dma_request_repeat_state; - ADCCOM->cctrl_bit.asisel = adc_common_struct->sampling_interval; - ADCCOM->cctrl_bit.itsrven = adc_common_struct->tempervintrv_state; - ADCCOM->cctrl_bit.vbaten = adc_common_struct->vbat_state; +void adc_common_config(adc_common_config_type *adc_common_struct) { + ADCCOM->cctrl_bit.mssel = adc_common_struct->combine_mode; + ADCCOM->cctrl_bit.adcdiv = adc_common_struct->div; + if (adc_common_struct->common_dma_mode & 0x04) { + ADCCOM->cctrl_bit.msdmasel_h = TRUE; + } else { + ADCCOM->cctrl_bit.msdmasel_h = FALSE; + } + ADCCOM->cctrl_bit.msdmasel_l = adc_common_struct->common_dma_mode & 0x03; + ADCCOM->cctrl_bit.msdrcen = adc_common_struct->common_dma_request_repeat_state; + ADCCOM->cctrl_bit.asisel = adc_common_struct->sampling_interval; + ADCCOM->cctrl_bit.itsrven = adc_common_struct->tempervintrv_state; + ADCCOM->cctrl_bit.vbaten = adc_common_struct->vbat_state; } /** @@ -232,9 +223,8 @@ void adc_common_config(adc_common_config_type *adc_common_struct) * - ADC_RESOLUTION_6B * @retval none */ -void adc_resolution_set(adc_type *adc_x, adc_resolution_type resolution) -{ - adc_x->ctrl1_bit.crsel = resolution; +void adc_resolution_set(adc_type *adc_x, adc_resolution_type resolution) { + adc_x->ctrl1_bit.crsel = resolution; } /** @@ -243,9 +233,8 @@ void adc_resolution_set(adc_type *adc_x, adc_resolution_type resolution) * this parameter can be: TRUE or FALSE. * @retval none */ -void adc_voltage_battery_enable(confirm_state new_state) -{ - ADCCOM->cctrl_bit.vbaten = new_state; +void adc_voltage_battery_enable(confirm_state new_state) { + ADCCOM->cctrl_bit.vbaten = new_state; } /** @@ -257,9 +246,8 @@ void adc_voltage_battery_enable(confirm_state new_state) * this parameter can be: TRUE or FALSE. * @retval none */ -void adc_dma_mode_enable(adc_type *adc_x, confirm_state new_state) -{ - adc_x->ctrl2_bit.ocdmaen = new_state; +void adc_dma_mode_enable(adc_type *adc_x, confirm_state new_state) { + adc_x->ctrl2_bit.ocdmaen = new_state; } /** @@ -271,9 +259,8 @@ void adc_dma_mode_enable(adc_type *adc_x, confirm_state new_state) * this parameter can be: TRUE or FALSE. * @retval none */ -void adc_dma_request_repeat_enable(adc_type *adc_x, confirm_state new_state) -{ - adc_x->ctrl2_bit.ocdrcen = new_state; +void adc_dma_request_repeat_enable(adc_type *adc_x, confirm_state new_state) { + adc_x->ctrl2_bit.ocdrcen = new_state; } /** @@ -291,16 +278,12 @@ void adc_dma_request_repeat_enable(adc_type *adc_x, confirm_state new_state) * this parameter can be: TRUE or FALSE. * @retval none */ -void adc_interrupt_enable(adc_type *adc_x, uint32_t adc_int, confirm_state new_state) -{ - if(new_state == TRUE) - { - adc_x->ctrl1 |= adc_int; - } - else if(new_state == FALSE) - { - adc_x->ctrl1 &= ~adc_int; - } +void adc_interrupt_enable(adc_type *adc_x, uint32_t adc_int, confirm_state new_state) { + if (new_state == TRUE) { + adc_x->ctrl1 |= adc_int; + } else if (new_state == FALSE) { + adc_x->ctrl1 &= ~adc_int; + } } /** @@ -313,9 +296,8 @@ void adc_interrupt_enable(adc_type *adc_x, uint32_t adc_int, confirm_state new_s * - (0x00~0x7F) * @retval none */ -void adc_calibration_value_set(adc_type *adc_x, uint8_t adc_calibration_value) -{ - adc_x->calval = adc_calibration_value; +void adc_calibration_value_set(adc_type *adc_x, uint8_t adc_calibration_value) { + adc_x->calval = adc_calibration_value; } /** @@ -325,9 +307,8 @@ void adc_calibration_value_set(adc_type *adc_x, uint8_t adc_calibration_value) * - ADC1, ADC2, ADC3. * @retval none */ -void adc_calibration_init(adc_type *adc_x) -{ - adc_x->ctrl2_bit.adcalinit = TRUE; +void adc_calibration_init(adc_type *adc_x) { + adc_x->ctrl2_bit.adcalinit = TRUE; } /** @@ -337,16 +318,12 @@ void adc_calibration_init(adc_type *adc_x) * - ADC1, ADC2, ADC3. * @retval the new state of reset calibration register status(SET or RESET). */ -flag_status adc_calibration_init_status_get(adc_type *adc_x) -{ - if(adc_x->ctrl2_bit.adcalinit) - { - return SET; - } - else - { - return RESET; - } +flag_status adc_calibration_init_status_get(adc_type *adc_x) { + if (adc_x->ctrl2_bit.adcalinit) { + return SET; + } else { + return RESET; + } } /** @@ -356,9 +333,8 @@ flag_status adc_calibration_init_status_get(adc_type *adc_x) * - ADC1, ADC2, ADC3. * @retval none */ -void adc_calibration_start(adc_type *adc_x) -{ - adc_x->ctrl2_bit.adcal = TRUE; +void adc_calibration_start(adc_type *adc_x) { + adc_x->ctrl2_bit.adcal = TRUE; } /** @@ -368,16 +344,12 @@ void adc_calibration_start(adc_type *adc_x) * - ADC1, ADC2, ADC3. * @retval the new state of calibration status(SET or RESET). */ -flag_status adc_calibration_status_get(adc_type *adc_x) -{ - if(adc_x->ctrl2_bit.adcal) - { - return SET; - } - else - { - return RESET; - } +flag_status adc_calibration_status_get(adc_type *adc_x) { + if (adc_x->ctrl2_bit.adcal) { + return SET; + } else { + return RESET; + } } /** @@ -396,12 +368,11 @@ flag_status adc_calibration_status_get(adc_type *adc_x) * - ADC_VMONITOR_NONE * @retval none */ -void adc_voltage_monitor_enable(adc_type *adc_x, adc_voltage_monitoring_type adc_voltage_monitoring) -{ - adc_x->ctrl1_bit.ocvmen = FALSE; - adc_x->ctrl1_bit.pcvmen = FALSE; - adc_x->ctrl1_bit.vmsgen = FALSE; - adc_x->ctrl1 |= adc_voltage_monitoring; +void adc_voltage_monitor_enable(adc_type *adc_x, adc_voltage_monitoring_type adc_voltage_monitoring) { + adc_x->ctrl1_bit.ocvmen = FALSE; + adc_x->ctrl1_bit.pcvmen = FALSE; + adc_x->ctrl1_bit.vmsgen = FALSE; + adc_x->ctrl1 |= adc_voltage_monitoring; } /** @@ -417,10 +388,9 @@ void adc_voltage_monitor_enable(adc_type *adc_x, adc_voltage_monitoring_type adc * - (0x0000~0xFFFF) * @retval none */ -void adc_voltage_monitor_threshold_value_set(adc_type *adc_x, uint16_t adc_high_threshold, uint16_t adc_low_threshold) -{ - adc_x->vmhb_bit.vmhb = adc_high_threshold; - adc_x->vmlb_bit.vmlb = adc_low_threshold; +void adc_voltage_monitor_threshold_value_set(adc_type *adc_x, uint16_t adc_high_threshold, uint16_t adc_low_threshold) { + adc_x->vmhb_bit.vmhb = adc_high_threshold; + adc_x->vmlb_bit.vmlb = adc_low_threshold; } /** @@ -437,9 +407,8 @@ void adc_voltage_monitor_threshold_value_set(adc_type *adc_x, uint16_t adc_high_ * - ADC_CHANNEL_16 - ADC_CHANNEL_17 - ADC_CHANNEL_18 * @retval none */ -void adc_voltage_monitor_single_channel_select(adc_type *adc_x, adc_channel_select_type adc_channel) -{ - adc_x->ctrl1_bit.vmcsel = adc_channel; +void adc_voltage_monitor_single_channel_select(adc_type *adc_x, adc_channel_select_type adc_channel) { + adc_x->ctrl1_bit.vmcsel = adc_channel; } /** @@ -469,45 +438,36 @@ void adc_voltage_monitor_single_channel_select(adc_type *adc_x, adc_channel_sele * - ADC_SAMPLETIME_640_5 * @retval none */ -void adc_ordinary_channel_set(adc_type *adc_x, adc_channel_select_type adc_channel, uint8_t adc_sequence, adc_sampletime_select_type adc_sampletime) -{ - uint32_t tmp_reg; - if(adc_channel < ADC_CHANNEL_10) - { - tmp_reg = adc_x->spt2; - tmp_reg &= ~(0x07 << 3 * adc_channel); - tmp_reg |= adc_sampletime << 3 * adc_channel; - adc_x->spt2 = tmp_reg; - } - else - { - tmp_reg = adc_x->spt1; - tmp_reg &= ~(0x07 << 3 * (adc_channel - ADC_CHANNEL_10)); - tmp_reg |= adc_sampletime << 3 * (adc_channel - ADC_CHANNEL_10); - adc_x->spt1 = tmp_reg; - } - - if(adc_sequence >= 13) - { - tmp_reg = adc_x->osq1; - tmp_reg &= ~(0x01F << 5 * (adc_sequence - 13)); - tmp_reg |= adc_channel << 5 * (adc_sequence - 13); - adc_x->osq1 = tmp_reg; - } - else if(adc_sequence >= 7) - { - tmp_reg = adc_x->osq2; - tmp_reg &= ~(0x01F << 5 * (adc_sequence - 7)); - tmp_reg |= adc_channel << 5 * (adc_sequence - 7); - adc_x->osq2 = tmp_reg; - } - else - { - tmp_reg = adc_x->osq3; - tmp_reg &= ~(0x01F << 5 * (adc_sequence - 1)); - tmp_reg |= adc_channel << 5 * (adc_sequence - 1); - adc_x->osq3 = tmp_reg; - } +void adc_ordinary_channel_set(adc_type *adc_x, adc_channel_select_type adc_channel, uint8_t adc_sequence, adc_sampletime_select_type adc_sampletime) { + uint32_t tmp_reg; + if (adc_channel < ADC_CHANNEL_10) { + tmp_reg = adc_x->spt2; + tmp_reg &= ~(0x07 << 3 * adc_channel); + tmp_reg |= adc_sampletime << 3 * adc_channel; + adc_x->spt2 = tmp_reg; + } else { + tmp_reg = adc_x->spt1; + tmp_reg &= ~(0x07 << 3 * (adc_channel - ADC_CHANNEL_10)); + tmp_reg |= adc_sampletime << 3 * (adc_channel - ADC_CHANNEL_10); + adc_x->spt1 = tmp_reg; + } + + if (adc_sequence >= 13) { + tmp_reg = adc_x->osq1; + tmp_reg &= ~(0x01F << 5 * (adc_sequence - 13)); + tmp_reg |= adc_channel << 5 * (adc_sequence - 13); + adc_x->osq1 = tmp_reg; + } else if (adc_sequence >= 7) { + tmp_reg = adc_x->osq2; + tmp_reg &= ~(0x01F << 5 * (adc_sequence - 7)); + tmp_reg |= adc_channel << 5 * (adc_sequence - 7); + adc_x->osq2 = tmp_reg; + } else { + tmp_reg = adc_x->osq3; + tmp_reg &= ~(0x01F << 5 * (adc_sequence - 1)); + tmp_reg |= adc_channel << 5 * (adc_sequence - 1); + adc_x->osq3 = tmp_reg; + } } /** @@ -520,9 +480,8 @@ void adc_ordinary_channel_set(adc_type *adc_x, adc_channel_select_type adc_chann * - (0x1~0x4) * @retval none */ -void adc_preempt_channel_length_set(adc_type *adc_x, uint8_t adc_channel_lenght) -{ - adc_x->psq_bit.pclen = adc_channel_lenght - 1; +void adc_preempt_channel_length_set(adc_type *adc_x, uint8_t adc_channel_lenght) { + adc_x->psq_bit.pclen = adc_channel_lenght - 1; } /** @@ -552,43 +511,38 @@ void adc_preempt_channel_length_set(adc_type *adc_x, uint8_t adc_channel_lenght) * - ADC_SAMPLETIME_640_5 * @retval none */ -void adc_preempt_channel_set(adc_type *adc_x, adc_channel_select_type adc_channel, uint8_t adc_sequence, adc_sampletime_select_type adc_sampletime) -{ - uint32_t tmp_reg; - uint8_t sequence_index; - if(adc_channel < ADC_CHANNEL_10) - { - tmp_reg = adc_x->spt2; - tmp_reg &= ~(0x07 << 3 * adc_channel); - tmp_reg |= adc_sampletime << 3 * adc_channel; - adc_x->spt2 = tmp_reg; - } - else - { - tmp_reg = adc_x->spt1; - tmp_reg &= ~(0x07 << 3 * (adc_channel - ADC_CHANNEL_10)); - tmp_reg |= adc_sampletime << 3 * (adc_channel - ADC_CHANNEL_10); - adc_x->spt1 = tmp_reg; - } +void adc_preempt_channel_set(adc_type *adc_x, adc_channel_select_type adc_channel, uint8_t adc_sequence, adc_sampletime_select_type adc_sampletime) { + uint32_t tmp_reg; + uint8_t sequence_index; + if (adc_channel < ADC_CHANNEL_10) { + tmp_reg = adc_x->spt2; + tmp_reg &= ~(0x07 << 3 * adc_channel); + tmp_reg |= adc_sampletime << 3 * adc_channel; + adc_x->spt2 = tmp_reg; + } else { + tmp_reg = adc_x->spt1; + tmp_reg &= ~(0x07 << 3 * (adc_channel - ADC_CHANNEL_10)); + tmp_reg |= adc_sampletime << 3 * (adc_channel - ADC_CHANNEL_10); + adc_x->spt1 = tmp_reg; + } - sequence_index = adc_sequence + 3 - adc_x->psq_bit.pclen; - switch(sequence_index) - { - case 1: - adc_x->psq_bit.psn1 = adc_channel; - break; - case 2: - adc_x->psq_bit.psn2 = adc_channel; - break; - case 3: - adc_x->psq_bit.psn3 = adc_channel; - break; - case 4: - adc_x->psq_bit.psn4 = adc_channel; - break; - default: - break; - } + sequence_index = adc_sequence + 3 - adc_x->psq_bit.pclen; + switch (sequence_index) { + case 1: + adc_x->psq_bit.psn1 = adc_channel; + break; + case 2: + adc_x->psq_bit.psn2 = adc_channel; + break; + case 3: + adc_x->psq_bit.psn3 = adc_channel; + break; + case 4: + adc_x->psq_bit.psn4 = adc_channel; + break; + default: + break; + } } /** @@ -615,19 +569,15 @@ void adc_preempt_channel_set(adc_type *adc_x, adc_channel_select_type adc_channe * - ADC_ORDINARY_TRIG_EDGE_RISING_FALLING * @retval none */ -void adc_ordinary_conversion_trigger_set(adc_type *adc_x, adc_ordinary_trig_select_type adc_ordinary_trig, adc_ordinary_trig_edge_type adc_ordinary_trig_edge) -{ - if(adc_ordinary_trig > ADC_ORDINARY_TRIG_EXINT11) - { - adc_x->ctrl2_bit.octesel_h = 1; - adc_x->ctrl2_bit.octesel_l = adc_ordinary_trig & 0x0F; - } - else - { - adc_x->ctrl2_bit.octesel_h = 0; - adc_x->ctrl2_bit.octesel_l = adc_ordinary_trig & 0x0F; - } - adc_x->ctrl2_bit.ocete = adc_ordinary_trig_edge; +void adc_ordinary_conversion_trigger_set(adc_type *adc_x, adc_ordinary_trig_select_type adc_ordinary_trig, adc_ordinary_trig_edge_type adc_ordinary_trig_edge) { + if (adc_ordinary_trig > ADC_ORDINARY_TRIG_EXINT11) { + adc_x->ctrl2_bit.octesel_h = 1; + adc_x->ctrl2_bit.octesel_l = adc_ordinary_trig & 0x0F; + } else { + adc_x->ctrl2_bit.octesel_h = 0; + adc_x->ctrl2_bit.octesel_l = adc_ordinary_trig & 0x0F; + } + adc_x->ctrl2_bit.ocete = adc_ordinary_trig_edge; } /** @@ -654,19 +604,15 @@ void adc_ordinary_conversion_trigger_set(adc_type *adc_x, adc_ordinary_trig_sele * - ADC_PREEMPT_TRIG_EDGE_RISING_FALLING * @retval none */ -void adc_preempt_conversion_trigger_set(adc_type *adc_x, adc_preempt_trig_select_type adc_preempt_trig, adc_preempt_trig_edge_type adc_preempt_trig_edge) -{ - if(adc_preempt_trig > ADC_PREEMPT_TRIG_EXINT15) - { - adc_x->ctrl2_bit.pctesel_h = 1; - adc_x->ctrl2_bit.pctesel_l = adc_preempt_trig & 0x0F; - } - else - { - adc_x->ctrl2_bit.pctesel_h = 0; - adc_x->ctrl2_bit.pctesel_l = adc_preempt_trig & 0x0F; - } - adc_x->ctrl2_bit.pcete = adc_preempt_trig_edge; +void adc_preempt_conversion_trigger_set(adc_type *adc_x, adc_preempt_trig_select_type adc_preempt_trig, adc_preempt_trig_edge_type adc_preempt_trig_edge) { + if (adc_preempt_trig > ADC_PREEMPT_TRIG_EXINT15) { + adc_x->ctrl2_bit.pctesel_h = 1; + adc_x->ctrl2_bit.pctesel_l = adc_preempt_trig & 0x0F; + } else { + adc_x->ctrl2_bit.pctesel_h = 0; + adc_x->ctrl2_bit.pctesel_l = adc_preempt_trig & 0x0F; + } + adc_x->ctrl2_bit.pcete = adc_preempt_trig_edge; } /** @@ -685,25 +631,23 @@ void adc_preempt_conversion_trigger_set(adc_type *adc_x, adc_preempt_trig_select * - (0x000~0xFFF) * @retval none */ -void adc_preempt_offset_value_set(adc_type *adc_x, adc_preempt_channel_type adc_preempt_channel, uint16_t adc_offset_value) -{ - switch(adc_preempt_channel) - { - case ADC_PREEMPT_CHANNEL_1: - adc_x->pcdto1_bit.pcdto1 = adc_offset_value; - break; - case ADC_PREEMPT_CHANNEL_2: - adc_x->pcdto2_bit.pcdto2 = adc_offset_value; - break; - case ADC_PREEMPT_CHANNEL_3: - adc_x->pcdto3_bit.pcdto3 = adc_offset_value; - break; - case ADC_PREEMPT_CHANNEL_4: - adc_x->pcdto4_bit.pcdto4 = adc_offset_value; - break; - default: - break; - } +void adc_preempt_offset_value_set(adc_type *adc_x, adc_preempt_channel_type adc_preempt_channel, uint16_t adc_offset_value) { + switch (adc_preempt_channel) { + case ADC_PREEMPT_CHANNEL_1: + adc_x->pcdto1_bit.pcdto1 = adc_offset_value; + break; + case ADC_PREEMPT_CHANNEL_2: + adc_x->pcdto2_bit.pcdto2 = adc_offset_value; + break; + case ADC_PREEMPT_CHANNEL_3: + adc_x->pcdto3_bit.pcdto3 = adc_offset_value; + break; + case ADC_PREEMPT_CHANNEL_4: + adc_x->pcdto4_bit.pcdto4 = adc_offset_value; + break; + default: + break; + } } /** @@ -716,10 +660,9 @@ void adc_preempt_offset_value_set(adc_type *adc_x, adc_preempt_channel_type adc_ * - (0x1~0x8) * @retval none */ -void adc_ordinary_part_count_set(adc_type *adc_x, uint8_t adc_channel_count) -{ +void adc_ordinary_part_count_set(adc_type *adc_x, uint8_t adc_channel_count) { - adc_x->ctrl1_bit.ocpcnt = adc_channel_count - 1; + adc_x->ctrl1_bit.ocpcnt = adc_channel_count - 1; } /** @@ -731,9 +674,8 @@ void adc_ordinary_part_count_set(adc_type *adc_x, uint8_t adc_channel_count) * this parameter can be: TRUE or FALSE. * @retval none */ -void adc_ordinary_part_mode_enable(adc_type *adc_x, confirm_state new_state) -{ - adc_x->ctrl1_bit.ocpen = new_state; +void adc_ordinary_part_mode_enable(adc_type *adc_x, confirm_state new_state) { + adc_x->ctrl1_bit.ocpen = new_state; } /** @@ -745,9 +687,8 @@ void adc_ordinary_part_mode_enable(adc_type *adc_x, confirm_state new_state) * this parameter can be: TRUE or FALSE. * @retval none */ -void adc_preempt_part_mode_enable(adc_type *adc_x, confirm_state new_state) -{ - adc_x->ctrl1_bit.pcpen = new_state; +void adc_preempt_part_mode_enable(adc_type *adc_x, confirm_state new_state) { + adc_x->ctrl1_bit.pcpen = new_state; } /** @@ -759,9 +700,8 @@ void adc_preempt_part_mode_enable(adc_type *adc_x, confirm_state new_state) * this parameter can be: TRUE or FALSE. * @retval none */ -void adc_preempt_auto_mode_enable(adc_type *adc_x, confirm_state new_state) -{ - adc_x->ctrl1_bit.pcautoen = new_state; +void adc_preempt_auto_mode_enable(adc_type *adc_x, confirm_state new_state) { + adc_x->ctrl1_bit.pcautoen = new_state; } /** @@ -771,9 +711,8 @@ void adc_preempt_auto_mode_enable(adc_type *adc_x, confirm_state new_state) * - ADC1, ADC2, ADC3. * @retval none */ -void adc_conversion_stop(adc_type *adc_x) -{ - adc_x->ctrl2_bit.adabrt = TRUE; +void adc_conversion_stop(adc_type *adc_x) { + adc_x->ctrl2_bit.adabrt = TRUE; } /** @@ -783,16 +722,12 @@ void adc_conversion_stop(adc_type *adc_x) * - ADC1, ADC2, ADC3. * @retval the new state of stop conversion's status(SET or RESET). */ -flag_status adc_conversion_stop_status_get(adc_type *adc_x) -{ - if(adc_x->ctrl2_bit.adabrt) - { - return SET; - } - else - { - return RESET; - } +flag_status adc_conversion_stop_status_get(adc_type *adc_x) { + if (adc_x->ctrl2_bit.adabrt) { + return SET; + } else { + return RESET; + } } /** @@ -804,9 +739,8 @@ flag_status adc_conversion_stop_status_get(adc_type *adc_x) * this parameter can be: TRUE or FALSE. * @retval none */ -void adc_occe_each_conversion_enable(adc_type *adc_x, confirm_state new_state) -{ - adc_x->ctrl2_bit.eocsfen = new_state; +void adc_occe_each_conversion_enable(adc_type *adc_x, confirm_state new_state) { + adc_x->ctrl2_bit.eocsfen = new_state; } /** @@ -818,9 +752,8 @@ void adc_occe_each_conversion_enable(adc_type *adc_x, confirm_state new_state) * this parameter can be: TRUE or FALSE. * @retval none */ -void adc_ordinary_software_trigger_enable(adc_type *adc_x, confirm_state new_state) -{ - adc_x->ctrl2_bit.ocswtrg = new_state; +void adc_ordinary_software_trigger_enable(adc_type *adc_x, confirm_state new_state) { + adc_x->ctrl2_bit.ocswtrg = new_state; } /** @@ -830,16 +763,12 @@ void adc_ordinary_software_trigger_enable(adc_type *adc_x, confirm_state new_sta * - ADC1, ADC2, ADC3. * @retval the new state of ordinary software start conversion status(SET or RESET). */ -flag_status adc_ordinary_software_trigger_status_get(adc_type *adc_x) -{ - if(adc_x->ctrl2_bit.ocswtrg) - { - return SET; - } - else - { - return RESET; - } +flag_status adc_ordinary_software_trigger_status_get(adc_type *adc_x) { + if (adc_x->ctrl2_bit.ocswtrg) { + return SET; + } else { + return RESET; + } } /** @@ -851,10 +780,9 @@ flag_status adc_ordinary_software_trigger_status_get(adc_type *adc_x) * this parameter can be: TRUE or FALSE. * @retval none */ -void adc_preempt_software_trigger_enable(adc_type *adc_x, confirm_state new_state) -{ - adc_x->ctrl2_bit.pcswtrg = new_state; - adc_x->ctrl2_bit.pcswtrg = FALSE; +void adc_preempt_software_trigger_enable(adc_type *adc_x, confirm_state new_state) { + adc_x->ctrl2_bit.pcswtrg = new_state; + adc_x->ctrl2_bit.pcswtrg = FALSE; } /** @@ -864,16 +792,12 @@ void adc_preempt_software_trigger_enable(adc_type *adc_x, confirm_state new_stat * - ADC1, ADC2, ADC3. * @retval the new state of preempt software start conversion status(SET or RESET). */ -flag_status adc_preempt_software_trigger_status_get(adc_type *adc_x) -{ - if(adc_x->ctrl2_bit.pcswtrg) - { - return SET; - } - else - { - return RESET; - } +flag_status adc_preempt_software_trigger_status_get(adc_type *adc_x) { + if (adc_x->ctrl2_bit.pcswtrg) { + return SET; + } else { + return RESET; + } } /** @@ -883,18 +807,16 @@ flag_status adc_preempt_software_trigger_status_get(adc_type *adc_x) * - ADC1, ADC2, ADC3. * @retval the last conversion data for ordinary channel. */ -uint16_t adc_ordinary_conversion_data_get(adc_type *adc_x) -{ - return (uint16_t)(adc_x->odt_bit.odt); +uint16_t adc_ordinary_conversion_data_get(adc_type *adc_x) { + return (uint16_t)(adc_x->odt_bit.odt); } /** * @brief return the last ordinary conversion data of combine adc. * @retval the last conversion data for ordinary channel. */ -uint32_t adc_combine_ordinary_conversion_data_get(void) -{ - return (uint32_t)(ADCCOM->codt); +uint32_t adc_combine_ordinary_conversion_data_get(void) { + return (uint32_t)(ADCCOM->codt); } /** @@ -910,27 +832,25 @@ uint32_t adc_combine_ordinary_conversion_data_get(void) * - ADC_PREEMPT_CHANNEL_4 * @retval the conversion data for selection preempt channel. */ -uint16_t adc_preempt_conversion_data_get(adc_type *adc_x, adc_preempt_channel_type adc_preempt_channel) -{ - uint16_t preempt_conv_data_index = 0; - switch(adc_preempt_channel) - { - case ADC_PREEMPT_CHANNEL_1: - preempt_conv_data_index = (uint16_t)(adc_x->pdt1_bit.pdt1); - break; - case ADC_PREEMPT_CHANNEL_2: - preempt_conv_data_index = (uint16_t)(adc_x->pdt2_bit.pdt2); - break; - case ADC_PREEMPT_CHANNEL_3: - preempt_conv_data_index = (uint16_t)(adc_x->pdt3_bit.pdt3); - break; - case ADC_PREEMPT_CHANNEL_4: - preempt_conv_data_index = (uint16_t)(adc_x->pdt4_bit.pdt4); - break; - default: - break; - } - return preempt_conv_data_index; +uint16_t adc_preempt_conversion_data_get(adc_type *adc_x, adc_preempt_channel_type adc_preempt_channel) { + uint16_t preempt_conv_data_index = 0; + switch (adc_preempt_channel) { + case ADC_PREEMPT_CHANNEL_1: + preempt_conv_data_index = (uint16_t)(adc_x->pdt1_bit.pdt1); + break; + case ADC_PREEMPT_CHANNEL_2: + preempt_conv_data_index = (uint16_t)(adc_x->pdt2_bit.pdt2); + break; + case ADC_PREEMPT_CHANNEL_3: + preempt_conv_data_index = (uint16_t)(adc_x->pdt3_bit.pdt3); + break; + case ADC_PREEMPT_CHANNEL_4: + preempt_conv_data_index = (uint16_t)(adc_x->pdt4_bit.pdt4); + break; + default: + break; + } + return preempt_conv_data_index; } /** @@ -949,19 +869,15 @@ uint16_t adc_preempt_conversion_data_get(adc_type *adc_x, adc_preempt_channel_ty * - ADC_RDY_FLAG(no interrupt associated) * @retval the new state of adc flag status(SET or RESET). */ -flag_status adc_flag_get(adc_type *adc_x, uint8_t adc_flag) -{ - flag_status status = RESET; +flag_status adc_flag_get(adc_type *adc_x, uint8_t adc_flag) { + flag_status status = RESET; - if((adc_x->sts & adc_flag) == RESET) - { - status = RESET; - } - else - { - status = SET; - } - return status; + if ((adc_x->sts & adc_flag) == RESET) { + status = RESET; + } else { + status = SET; + } + return status; } /** @@ -977,39 +893,33 @@ flag_status adc_flag_get(adc_type *adc_x, uint8_t adc_flag) * - ADC_OCCO_FLAG * @retval the new state of adc flag status(SET or RESET). */ -flag_status adc_interrupt_flag_get(adc_type *adc_x, uint8_t adc_flag) -{ - flag_status status = RESET; - switch(adc_flag) - { - case ADC_VMOR_FLAG: - if(adc_x->sts_bit.vmor && adc_x->ctrl1_bit.vmorien) - { - status = SET; - } - break; - case ADC_OCCE_FLAG: - if(adc_x->sts_bit.occe && adc_x->ctrl1_bit.occeien) - { - status = SET; - } - break; - case ADC_PCCE_FLAG: - if(adc_x->sts_bit.pcce && adc_x->ctrl1_bit.pcceien) - { - status = SET; - } - break; - case ADC_OCCO_FLAG: - if(adc_x->sts_bit.occo && adc_x->ctrl1_bit.occoien) - { - status = SET; - } - break; - default: - break; - } - return status; +flag_status adc_interrupt_flag_get(adc_type *adc_x, uint8_t adc_flag) { + flag_status status = RESET; + switch (adc_flag) { + case ADC_VMOR_FLAG: + if (adc_x->sts_bit.vmor && adc_x->ctrl1_bit.vmorien) { + status = SET; + } + break; + case ADC_OCCE_FLAG: + if (adc_x->sts_bit.occe && adc_x->ctrl1_bit.occeien) { + status = SET; + } + break; + case ADC_PCCE_FLAG: + if (adc_x->sts_bit.pcce && adc_x->ctrl1_bit.pcceien) { + status = SET; + } + break; + case ADC_OCCO_FLAG: + if (adc_x->sts_bit.occo && adc_x->ctrl1_bit.occoien) { + status = SET; + } + break; + default: + break; + } + return status; } /** @@ -1028,9 +938,8 @@ flag_status adc_interrupt_flag_get(adc_type *adc_x, uint8_t adc_flag) * - note:"ADC_RDY_FLAG" cannot be choose!rdy bit is readonly bit,it means the adc is ready to accept conversion request * @retval none */ -void adc_flag_clear(adc_type *adc_x, uint32_t adc_flag) -{ - adc_x->sts = ~adc_flag; +void adc_flag_clear(adc_type *adc_x, uint32_t adc_flag) { + adc_x->sts = ~adc_flag; } /** @@ -1042,9 +951,8 @@ void adc_flag_clear(adc_type *adc_x, uint32_t adc_flag) * this parameter can be: TRUE or FALSE. * @retval none */ -void adc_ordinary_oversample_enable(adc_type *adc_x, confirm_state new_state) -{ - adc_x->ovsp_bit.oosen = new_state; +void adc_ordinary_oversample_enable(adc_type *adc_x, confirm_state new_state) { + adc_x->ovsp_bit.oosen = new_state; } /** @@ -1056,9 +964,8 @@ void adc_ordinary_oversample_enable(adc_type *adc_x, confirm_state new_state) * this parameter can be: TRUE or FALSE. * @retval none */ -void adc_preempt_oversample_enable(adc_type *adc_x, confirm_state new_state) -{ - adc_x->ovsp_bit.posen = new_state; +void adc_preempt_oversample_enable(adc_type *adc_x, confirm_state new_state) { + adc_x->ovsp_bit.posen = new_state; } /** @@ -1089,10 +996,9 @@ void adc_preempt_oversample_enable(adc_type *adc_x, confirm_state new_state) * - ADC_OVERSAMPLE_SHIFT_8 * @retval none */ -void adc_oversample_ratio_shift_set(adc_type *adc_x, adc_oversample_ratio_type adc_oversample_ratio, adc_oversample_shift_type adc_oversample_shift) -{ - adc_x->ovsp_bit.osrsel = adc_oversample_ratio; - adc_x->ovsp_bit.osssel = adc_oversample_shift; +void adc_oversample_ratio_shift_set(adc_type *adc_x, adc_oversample_ratio_type adc_oversample_ratio, adc_oversample_shift_type adc_oversample_shift) { + adc_x->ovsp_bit.osrsel = adc_oversample_ratio; + adc_x->ovsp_bit.osssel = adc_oversample_shift; } /** @@ -1104,9 +1010,8 @@ void adc_oversample_ratio_shift_set(adc_type *adc_x, adc_oversample_ratio_type a * this parameter can be: TRUE or FALSE. * @retval none */ -void adc_ordinary_oversample_trig_enable(adc_type *adc_x, confirm_state new_state) -{ - adc_x->ovsp_bit.oostren = new_state; +void adc_ordinary_oversample_trig_enable(adc_type *adc_x, confirm_state new_state) { + adc_x->ovsp_bit.oostren = new_state; } /** @@ -1120,9 +1025,8 @@ void adc_ordinary_oversample_trig_enable(adc_type *adc_x, confirm_state new_stat * - ADC_OVERSAMPLE_RESTART * @retval none */ -void adc_ordinary_oversample_restart_set(adc_type *adc_x, adc_ordinary_oversample_restart_type adc_ordinary_oversample_restart) -{ - adc_x->ovsp_bit.oosrsel = adc_ordinary_oversample_restart; +void adc_ordinary_oversample_restart_set(adc_type *adc_x, adc_ordinary_oversample_restart_type adc_ordinary_oversample_restart) { + adc_x->ovsp_bit.oosrsel = adc_ordinary_oversample_restart; } /** diff --git a/armlib/at32_sys/drivers/src/at32f435_437_can.c b/armlib/at32_sys/drivers/src/at32f435_437_can.c index 41efb9b7e..9cf9e7584 100644 --- a/armlib/at32_sys/drivers/src/at32f435_437_can.c +++ b/armlib/at32_sys/drivers/src/at32f435_437_can.c @@ -48,18 +48,14 @@ * CAN1,CAN2. * @retval none. */ -void can_reset(can_type* can_x) -{ - if(can_x == CAN1) - { - crm_periph_reset(CRM_CAN1_PERIPH_RESET, TRUE); - crm_periph_reset(CRM_CAN1_PERIPH_RESET, FALSE); - } - else if(can_x == CAN2) - { - crm_periph_reset(CRM_CAN2_PERIPH_RESET, TRUE); - crm_periph_reset(CRM_CAN2_PERIPH_RESET, FALSE); - } +void can_reset(can_type *can_x) { + if (can_x == CAN1) { + crm_periph_reset(CRM_CAN1_PERIPH_RESET, TRUE); + crm_periph_reset(CRM_CAN1_PERIPH_RESET, FALSE); + } else if (can_x == CAN2) { + crm_periph_reset(CRM_CAN2_PERIPH_RESET, TRUE); + crm_periph_reset(CRM_CAN2_PERIPH_RESET, FALSE); + } } /** @@ -67,21 +63,20 @@ void can_reset(can_type* can_x) * @param can_baudrate_struct: pointer to a can_baudrate_type structure which will be initialized. * @retval none. */ -void can_baudrate_default_para_init(can_baudrate_type* can_baudrate_struct) -{ - /* reset can baudrate structure parameters values */ +void can_baudrate_default_para_init(can_baudrate_type *can_baudrate_struct) { + /* reset can baudrate structure parameters values */ - /* baud rate division */ - can_baudrate_struct->baudrate_div = 1; + /* baud rate division */ + can_baudrate_struct->baudrate_div = 1; - /* resynchronization adjust width */ - can_baudrate_struct->rsaw_size = CAN_RSAW_2TQ; + /* resynchronization adjust width */ + can_baudrate_struct->rsaw_size = CAN_RSAW_2TQ; - /* bit time segment 1 */ - can_baudrate_struct->bts1_size = CAN_BTS1_4TQ; + /* bit time segment 1 */ + can_baudrate_struct->bts1_size = CAN_BTS1_4TQ; - /* bit time segment 2 */ - can_baudrate_struct->bts2_size = CAN_BTS2_3TQ; + /* bit time segment 2 */ + can_baudrate_struct->bts2_size = CAN_BTS2_3TQ; } /** @@ -96,57 +91,48 @@ void can_baudrate_default_para_init(can_baudrate_type* can_baudrate_struct) * this parameter can be one of the following values: * SUCCESS or ERROR */ -error_status can_baudrate_set(can_type* can_x, can_baudrate_type* can_baudrate_struct) -{ - error_status status_index = ERROR; - uint32_t wait_ack_index = 0x00000000; - /* exit from doze mode */ - can_x->mctrl_bit.dzen = FALSE; +error_status can_baudrate_set(can_type *can_x, can_baudrate_type *can_baudrate_struct) { + error_status status_index = ERROR; + uint32_t wait_ack_index = 0x00000000; + /* exit from doze mode */ + can_x->mctrl_bit.dzen = FALSE; - /* request freeze mode */ - can_x->mctrl_bit.fzen = TRUE; - - /* wait the acknowledge */ - while((!can_x->msts_bit.fzc) && (wait_ack_index != FZC_TIMEOUT)) - { - wait_ack_index++; - } - - /* check acknowledge */ - if(can_x->msts_bit.fzc) - { - can_x->btmg_bit.brdiv = can_baudrate_struct->baudrate_div - 1; - can_x->btmg_bit.rsaw = can_baudrate_struct->rsaw_size; - can_x->btmg_bit.bts1 = can_baudrate_struct->bts1_size; - can_x->btmg_bit.bts2 = can_baudrate_struct->bts2_size; - - /* request leave freeze mode */ - can_x->mctrl_bit.fzen = FALSE; + /* request freeze mode */ + can_x->mctrl_bit.fzen = TRUE; /* wait the acknowledge */ - wait_ack_index = 0; - while((can_x->msts_bit.fzc) && (wait_ack_index != FZC_TIMEOUT)) - { - wait_ack_index++; + while ((!can_x->msts_bit.fzc) && (wait_ack_index != FZC_TIMEOUT)) { + wait_ack_index++; } - /* check acknowledged */ - if(can_x->msts_bit.fzc) - { - status_index = ERROR; - } - else - { - status_index = SUCCESS ; - } - } - else - { - status_index = ERROR; - } + /* check acknowledge */ + if (can_x->msts_bit.fzc) { + can_x->btmg_bit.brdiv = can_baudrate_struct->baudrate_div - 1; + can_x->btmg_bit.rsaw = can_baudrate_struct->rsaw_size; + can_x->btmg_bit.bts1 = can_baudrate_struct->bts1_size; + can_x->btmg_bit.bts2 = can_baudrate_struct->bts2_size; - /* return the status of baudrate set */ - return status_index; + /* request leave freeze mode */ + can_x->mctrl_bit.fzen = FALSE; + + /* wait the acknowledge */ + wait_ack_index = 0; + while ((can_x->msts_bit.fzc) && (wait_ack_index != FZC_TIMEOUT)) { + wait_ack_index++; + } + + /* check acknowledged */ + if (can_x->msts_bit.fzc) { + status_index = ERROR; + } else { + status_index = SUCCESS ; + } + } else { + status_index = ERROR; + } + + /* return the status of baudrate set */ + return status_index; } /** @@ -154,30 +140,29 @@ error_status can_baudrate_set(can_type* can_x, can_baudrate_type* can_baudrate_s * @param can_base_struct: pointer to a can_base_type structure which will be initialized. * @retval none. */ -void can_default_para_init(can_base_type* can_base_struct) -{ - /* reset can init structure parameters values */ +void can_default_para_init(can_base_type *can_base_struct) { + /* reset can init structure parameters values */ - /* initialize the time triggered communication mode */ - can_base_struct->ttc_enable = FALSE; + /* initialize the time triggered communication mode */ + can_base_struct->ttc_enable = FALSE; - /* initialize the automatic exit bus-off management */ - can_base_struct->aebo_enable = FALSE; + /* initialize the automatic exit bus-off management */ + can_base_struct->aebo_enable = FALSE; - /* initialize the automatic exit doze mode */ - can_base_struct->aed_enable = FALSE; + /* initialize the automatic exit doze mode */ + can_base_struct->aed_enable = FALSE; - /* initialize the prohibit retransmission when sending fails */ - can_base_struct->prsf_enable = FALSE; + /* initialize the prohibit retransmission when sending fails */ + can_base_struct->prsf_enable = FALSE; - /* initialize the message discarding rule select when overflow */ - can_base_struct->mdrsel_selection = CAN_DISCARDING_FIRST_RECEIVED; + /* initialize the message discarding rule select when overflow */ + can_base_struct->mdrsel_selection = CAN_DISCARDING_FIRST_RECEIVED; - /* initialize the multiple message sending sequence rule */ - can_base_struct->mmssr_selection = CAN_SENDING_BY_ID; + /* initialize the multiple message sending sequence rule */ + can_base_struct->mmssr_selection = CAN_SENDING_BY_ID; - /* initialize the can_mode */ - can_base_struct->mode_selection = CAN_MODE_COMMUNICATE; + /* initialize the can_mode */ + can_base_struct->mode_selection = CAN_MODE_COMMUNICATE; } /** @@ -191,74 +176,65 @@ void can_default_para_init(can_base_type* can_base_struct) * this parameter can be one of the following values: * SUCCESS or ERROR */ -error_status can_base_init(can_type* can_x, can_base_type* can_base_struct) -{ - error_status init_status_index = ERROR; - uint32_t wait_ack_index = 0x00000000; - /* exit from doze mode */ - can_x->mctrl_bit.dzen = FALSE; +error_status can_base_init(can_type *can_x, can_base_type *can_base_struct) { + error_status init_status_index = ERROR; + uint32_t wait_ack_index = 0x00000000; + /* exit from doze mode */ + can_x->mctrl_bit.dzen = FALSE; - /* request freeze mode */ - can_x->mctrl_bit.fzen = TRUE; - - /* wait the acknowledge */ - while((!can_x->msts_bit.fzc) && (wait_ack_index != FZC_TIMEOUT)) - { - wait_ack_index++; - } - - /* check acknowledge */ - if(can_x->msts_bit.fzc) - { - /* set the time triggered communication mode */ - can_x->mctrl_bit.ttcen = can_base_struct->ttc_enable; - - /* set the automatic exit bus-off management */ - can_x->mctrl_bit.aeboen = can_base_struct->aebo_enable; - - /* set the automatic automatic exit doze mode */ - can_x->mctrl_bit.aeden = can_base_struct->aed_enable; - - /* set the prohibit retransmission when sending fails */ - can_x->mctrl_bit.prsfen = can_base_struct->prsf_enable; - - /* set the message discarding rule select when overflow */ - can_x->mctrl_bit.mdrsel = can_base_struct->mdrsel_selection; - - /* set the multiple message sending sequence rule */ - can_x->mctrl_bit.mmssr = can_base_struct->mmssr_selection; - - /* set the test mode */ - can_x->btmg_bit.lben = can_base_struct->mode_selection & 0x01; - can_x->btmg_bit.loen = (can_base_struct->mode_selection >> 1) & 0x01; - - /* request leave freeze mode */ - can_x->mctrl_bit.fzen = FALSE; + /* request freeze mode */ + can_x->mctrl_bit.fzen = TRUE; /* wait the acknowledge */ - wait_ack_index = 0; - while((can_x->msts_bit.fzc) && (wait_ack_index != FZC_TIMEOUT)) - { - wait_ack_index++; + while ((!can_x->msts_bit.fzc) && (wait_ack_index != FZC_TIMEOUT)) { + wait_ack_index++; } - /* check acknowledged */ - if(can_x->msts_bit.fzc) - { - init_status_index = ERROR; - } - else - { - init_status_index = SUCCESS ; - } - } - else - { - init_status_index = ERROR; - } + /* check acknowledge */ + if (can_x->msts_bit.fzc) { + /* set the time triggered communication mode */ + can_x->mctrl_bit.ttcen = can_base_struct->ttc_enable; - /* return the status of initialization */ - return init_status_index; + /* set the automatic exit bus-off management */ + can_x->mctrl_bit.aeboen = can_base_struct->aebo_enable; + + /* set the automatic automatic exit doze mode */ + can_x->mctrl_bit.aeden = can_base_struct->aed_enable; + + /* set the prohibit retransmission when sending fails */ + can_x->mctrl_bit.prsfen = can_base_struct->prsf_enable; + + /* set the message discarding rule select when overflow */ + can_x->mctrl_bit.mdrsel = can_base_struct->mdrsel_selection; + + /* set the multiple message sending sequence rule */ + can_x->mctrl_bit.mmssr = can_base_struct->mmssr_selection; + + /* set the test mode */ + can_x->btmg_bit.lben = can_base_struct->mode_selection & 0x01; + can_x->btmg_bit.loen = (can_base_struct->mode_selection >> 1) & 0x01; + + /* request leave freeze mode */ + can_x->mctrl_bit.fzen = FALSE; + + /* wait the acknowledge */ + wait_ack_index = 0; + while ((can_x->msts_bit.fzc) && (wait_ack_index != FZC_TIMEOUT)) { + wait_ack_index++; + } + + /* check acknowledged */ + if (can_x->msts_bit.fzc) { + init_status_index = ERROR; + } else { + init_status_index = SUCCESS ; + } + } else { + init_status_index = ERROR; + } + + /* return the status of initialization */ + return init_status_index; } /** @@ -266,30 +242,29 @@ error_status can_base_init(can_type* can_x, can_base_type* can_base_struct) * @param can_filter_init_struct: pointer to a can_filter_init_type structure which will be initialized. * @retval none. */ -void can_filter_default_para_init(can_filter_init_type* can_filter_init_struct) -{ - /* reset can filter init structure parameters values */ +void can_filter_default_para_init(can_filter_init_type *can_filter_init_struct) { + /* reset can filter init structure parameters values */ - /* initialize the filter activate state */ - can_filter_init_struct->filter_activate_enable = FALSE; + /* initialize the filter activate state */ + can_filter_init_struct->filter_activate_enable = FALSE; - /* filter mode */ - can_filter_init_struct->filter_mode = CAN_FILTER_MODE_ID_MASK; + /* filter mode */ + can_filter_init_struct->filter_mode = CAN_FILTER_MODE_ID_MASK; - /* filter relation fifo select */ - can_filter_init_struct->filter_fifo = CAN_FILTER_FIFO0; + /* filter relation fifo select */ + can_filter_init_struct->filter_fifo = CAN_FILTER_FIFO0; - /* filter number select */ - can_filter_init_struct->filter_number = 0; + /* filter number select */ + can_filter_init_struct->filter_number = 0; - /* initialize the filter bit width */ - can_filter_init_struct->filter_bit = CAN_FILTER_16BIT; + /* initialize the filter bit width */ + can_filter_init_struct->filter_bit = CAN_FILTER_16BIT; - /* initialize the filters filter data bit */ - can_filter_init_struct->filter_id_high = 0; - can_filter_init_struct->filter_id_low = 0; - can_filter_init_struct->filter_mask_high = 0; - can_filter_init_struct->filter_mask_low = 0; + /* initialize the filters filter data bit */ + can_filter_init_struct->filter_id_high = 0; + can_filter_init_struct->filter_id_low = 0; + can_filter_init_struct->filter_mask_high = 0; + can_filter_init_struct->filter_mask_low = 0; } /** @@ -301,86 +276,81 @@ void can_filter_default_para_init(can_filter_init_type* can_filter_init_struct) * @param can_filter_init_struct: pointer to a can_filter_init_type structure that contains the configuration information. * @retval none. */ -void can_filter_init(can_type* can_x, can_filter_init_type* can_filter_init_struct) -{ - uint32_t filter_number_bit_pos = 0; - filter_number_bit_pos = ((uint32_t)1) << can_filter_init_struct->filter_number; - /* set the filter turn into configuration condition */ - can_x->fctrl_bit.fcs = TRUE; +void can_filter_init(can_type *can_x, can_filter_init_type *can_filter_init_struct) { + uint32_t filter_number_bit_pos = 0; + filter_number_bit_pos = ((uint32_t)1) << can_filter_init_struct->filter_number; + /* set the filter turn into configuration condition */ + can_x->fctrl_bit.fcs = TRUE; - /* filter activate disable */ - can_x->facfg &= ~(uint32_t)filter_number_bit_pos; + /* filter activate disable */ + can_x->facfg &= ~(uint32_t)filter_number_bit_pos; - /* filter bit width */ - switch(can_filter_init_struct->filter_bit) - { - case CAN_FILTER_16BIT: - can_x->fbwcfg &= ~(uint32_t)filter_number_bit_pos; - /* first 16-bit identifier and first 16-bit mask or first 16-bit identifier and second 16-bit identifier */ - can_x->ffb[can_filter_init_struct->filter_number].ffdb1 = ((0x0000FFFF & (uint32_t)can_filter_init_struct->filter_mask_low) << 16); - can_x->ffb[can_filter_init_struct->filter_number].ffdb1 |= (0x0000FFFF & (uint32_t)can_filter_init_struct->filter_id_low); + /* filter bit width */ + switch (can_filter_init_struct->filter_bit) { + case CAN_FILTER_16BIT: + can_x->fbwcfg &= ~(uint32_t)filter_number_bit_pos; + /* first 16-bit identifier and first 16-bit mask or first 16-bit identifier and second 16-bit identifier */ + can_x->ffb[can_filter_init_struct->filter_number].ffdb1 = ((0x0000FFFF & (uint32_t)can_filter_init_struct->filter_mask_low) << 16); + can_x->ffb[can_filter_init_struct->filter_number].ffdb1 |= (0x0000FFFF & (uint32_t)can_filter_init_struct->filter_id_low); - /* second 16-bit identifier and second 16-bit mask or third 16-bit identifier and fourth 16-bit identifier */ - can_x->ffb[can_filter_init_struct->filter_number].ffdb2 = ((0x0000FFFF & (uint32_t)can_filter_init_struct->filter_mask_high) << 16); - can_x->ffb[can_filter_init_struct->filter_number].ffdb2 |= (0x0000FFFF & (uint32_t)can_filter_init_struct->filter_id_high); + /* second 16-bit identifier and second 16-bit mask or third 16-bit identifier and fourth 16-bit identifier */ + can_x->ffb[can_filter_init_struct->filter_number].ffdb2 = ((0x0000FFFF & (uint32_t)can_filter_init_struct->filter_mask_high) << 16); + can_x->ffb[can_filter_init_struct->filter_number].ffdb2 |= (0x0000FFFF & (uint32_t)can_filter_init_struct->filter_id_high); - break; - case CAN_FILTER_32BIT: - can_x->fbwcfg |= filter_number_bit_pos; - /* 32-bit identifier or first 32-bit identifier */ - can_x->ffb[can_filter_init_struct->filter_number].ffdb1 = ((0x0000FFFF & (uint32_t)can_filter_init_struct->filter_id_high) << 16); - can_x->ffb[can_filter_init_struct->filter_number].ffdb1 |= (0x0000FFFF & (uint32_t)can_filter_init_struct->filter_id_low); + break; + case CAN_FILTER_32BIT: + can_x->fbwcfg |= filter_number_bit_pos; + /* 32-bit identifier or first 32-bit identifier */ + can_x->ffb[can_filter_init_struct->filter_number].ffdb1 = ((0x0000FFFF & (uint32_t)can_filter_init_struct->filter_id_high) << 16); + can_x->ffb[can_filter_init_struct->filter_number].ffdb1 |= (0x0000FFFF & (uint32_t)can_filter_init_struct->filter_id_low); - /* 32-bit mask or second 32-bit identifier */ - can_x->ffb[can_filter_init_struct->filter_number].ffdb2 = ((0x0000FFFF & (uint32_t)can_filter_init_struct->filter_mask_high) << 16); - can_x->ffb[can_filter_init_struct->filter_number].ffdb2 |= (0x0000FFFF & (uint32_t)can_filter_init_struct->filter_mask_low); + /* 32-bit mask or second 32-bit identifier */ + can_x->ffb[can_filter_init_struct->filter_number].ffdb2 = ((0x0000FFFF & (uint32_t)can_filter_init_struct->filter_mask_high) << 16); + can_x->ffb[can_filter_init_struct->filter_number].ffdb2 |= (0x0000FFFF & (uint32_t)can_filter_init_struct->filter_mask_low); - break; - default: - break; - } + break; + default: + break; + } - /* filter mode */ - switch(can_filter_init_struct->filter_mode) - { - case CAN_FILTER_MODE_ID_MASK: - can_x->fmcfg &= ~(uint32_t)filter_number_bit_pos; - break; - case CAN_FILTER_MODE_ID_LIST: - can_x->fmcfg |= (uint32_t)filter_number_bit_pos; - break; - default: - break; - } + /* filter mode */ + switch (can_filter_init_struct->filter_mode) { + case CAN_FILTER_MODE_ID_MASK: + can_x->fmcfg &= ~(uint32_t)filter_number_bit_pos; + break; + case CAN_FILTER_MODE_ID_LIST: + can_x->fmcfg |= (uint32_t)filter_number_bit_pos; + break; + default: + break; + } - /* filter relation fifo select */ - switch(can_filter_init_struct->filter_fifo) - { - case CAN_FILTER_FIFO0: - can_x->frf &= ~(uint32_t)filter_number_bit_pos; - break; - case CAN_FILTER_FIFO1: - can_x->frf |= (uint32_t)filter_number_bit_pos; - break; - default: - break; - } + /* filter relation fifo select */ + switch (can_filter_init_struct->filter_fifo) { + case CAN_FILTER_FIFO0: + can_x->frf &= ~(uint32_t)filter_number_bit_pos; + break; + case CAN_FILTER_FIFO1: + can_x->frf |= (uint32_t)filter_number_bit_pos; + break; + default: + break; + } - /* filter activate enable */ - switch(can_filter_init_struct->filter_activate_enable) - { - case TRUE: - can_x->facfg |= (uint32_t)filter_number_bit_pos; - break; - case FALSE: - can_x->facfg &= ~(uint32_t)filter_number_bit_pos; - break; - default: - break; - } + /* filter activate enable */ + switch (can_filter_init_struct->filter_activate_enable) { + case TRUE: + can_x->facfg |= (uint32_t)filter_number_bit_pos; + break; + case FALSE: + can_x->facfg &= ~(uint32_t)filter_number_bit_pos; + break; + default: + break; + } - /* set the filter turn into working condition */ - can_x->fctrl_bit.fcs = FALSE; + /* set the filter turn into working condition */ + can_x->fctrl_bit.fcs = FALSE; } /** @@ -392,9 +362,8 @@ void can_filter_init(can_type* can_x, can_filter_init_type* can_filter_init_stru * this parameter can be: TRUE or FALSE. * @retval none. */ -void can_debug_transmission_prohibit(can_type* can_x, confirm_state new_state) -{ - can_x->mctrl_bit.ptd = new_state; +void can_debug_transmission_prohibit(can_type *can_x, confirm_state new_state) { + can_x->mctrl_bit.ptd = new_state; } /** @@ -413,15 +382,14 @@ void can_debug_transmission_prohibit(can_type* can_x, confirm_state new_state) * tmdtbl must be programmed as 8 in order time stamp (2 bytes) to be sent over the can bus. * @retval none */ -void can_ttc_mode_enable(can_type* can_x, confirm_state new_state) -{ - /* config the ttc mode new_state */ - can_x->mctrl_bit.ttcen = new_state; +void can_ttc_mode_enable(can_type *can_x, confirm_state new_state) { + /* config the ttc mode new_state */ + can_x->mctrl_bit.ttcen = new_state; - /* config tmtsten bits new_state */ - can_x->tx_mailbox[0].tmc_bit.tmtsten = new_state; - can_x->tx_mailbox[1].tmc_bit.tmtsten = new_state; - can_x->tx_mailbox[2].tmc_bit.tmtsten = new_state; + /* config tmtsten bits new_state */ + can_x->tx_mailbox[0].tmc_bit.tmtsten = new_state; + can_x->tx_mailbox[1].tmc_bit.tmtsten = new_state; + can_x->tx_mailbox[2].tmc_bit.tmtsten = new_state; } /** @@ -437,62 +405,52 @@ void can_ttc_mode_enable(can_type* can_x, confirm_state new_state) * - CAN_TX_MAILBOX2 * - CAN_TX_STATUS_NO_EMPTY */ -uint8_t can_message_transmit(can_type* can_x, can_tx_message_type* tx_message_struct) -{ - uint8_t transmit_mailbox = CAN_TX_STATUS_NO_EMPTY; +uint8_t can_message_transmit(can_type *can_x, can_tx_message_type *tx_message_struct) { + uint8_t transmit_mailbox = CAN_TX_STATUS_NO_EMPTY; - /* select one empty transmit mailbox */ - if(can_x->tsts_bit.tm0ef) - { - transmit_mailbox = CAN_TX_MAILBOX0; - } - else if(can_x->tsts_bit.tm1ef) - { - transmit_mailbox = CAN_TX_MAILBOX1; - } - else if(can_x->tsts_bit.tm2ef) - { - transmit_mailbox = CAN_TX_MAILBOX2; - } - else - { - transmit_mailbox = CAN_TX_STATUS_NO_EMPTY; - } - - if(transmit_mailbox != CAN_TX_STATUS_NO_EMPTY) - { - /* set up the id */ - can_x->tx_mailbox[transmit_mailbox].tmi &= 0x00000001; - can_x->tx_mailbox[transmit_mailbox].tmi_bit.tmidsel = tx_message_struct->id_type; - switch(tx_message_struct->id_type) - { - case CAN_ID_STANDARD: - can_x->tx_mailbox[transmit_mailbox].tmi_bit.tmsid = tx_message_struct->standard_id; - break; - case CAN_ID_EXTENDED: - can_x->tx_mailbox[transmit_mailbox].tmi |= (tx_message_struct->extended_id << 3); - break; - default: - break; + /* select one empty transmit mailbox */ + if (can_x->tsts_bit.tm0ef) { + transmit_mailbox = CAN_TX_MAILBOX0; + } else if (can_x->tsts_bit.tm1ef) { + transmit_mailbox = CAN_TX_MAILBOX1; + } else if (can_x->tsts_bit.tm2ef) { + transmit_mailbox = CAN_TX_MAILBOX2; + } else { + transmit_mailbox = CAN_TX_STATUS_NO_EMPTY; } - can_x->tx_mailbox[transmit_mailbox].tmi_bit.tmfrsel = tx_message_struct->frame_type; - /* set up the dlc */ - can_x->tx_mailbox[transmit_mailbox].tmc_bit.tmdtbl = (tx_message_struct->dlc & ((uint8_t)0x0F)); - /* set up the data field */ - can_x->tx_mailbox[transmit_mailbox].tmdtl = (((uint32_t)tx_message_struct->data[3] << 24) | - ((uint32_t)tx_message_struct->data[2] << 16) | - ((uint32_t)tx_message_struct->data[1] << 8) | - ((uint32_t)tx_message_struct->data[0])); - can_x->tx_mailbox[transmit_mailbox].tmdth = (((uint32_t)tx_message_struct->data[7] << 24) | - ((uint32_t)tx_message_struct->data[6] << 16) | - ((uint32_t)tx_message_struct->data[5] << 8) | - ((uint32_t)tx_message_struct->data[4])); + if (transmit_mailbox != CAN_TX_STATUS_NO_EMPTY) { + /* set up the id */ + can_x->tx_mailbox[transmit_mailbox].tmi &= 0x00000001; + can_x->tx_mailbox[transmit_mailbox].tmi_bit.tmidsel = tx_message_struct->id_type; + switch (tx_message_struct->id_type) { + case CAN_ID_STANDARD: + can_x->tx_mailbox[transmit_mailbox].tmi_bit.tmsid = tx_message_struct->standard_id; + break; + case CAN_ID_EXTENDED: + can_x->tx_mailbox[transmit_mailbox].tmi |= (tx_message_struct->extended_id << 3); + break; + default: + break; + } + can_x->tx_mailbox[transmit_mailbox].tmi_bit.tmfrsel = tx_message_struct->frame_type; + /* set up the dlc */ + can_x->tx_mailbox[transmit_mailbox].tmc_bit.tmdtbl = (tx_message_struct->dlc & ((uint8_t)0x0F)); - /* request transmission */ - can_x->tx_mailbox[transmit_mailbox].tmi_bit.tmsr = TRUE; - } - return transmit_mailbox; + /* set up the data field */ + can_x->tx_mailbox[transmit_mailbox].tmdtl = (((uint32_t)tx_message_struct->data[3] << 24) | + ((uint32_t)tx_message_struct->data[2] << 16) | + ((uint32_t)tx_message_struct->data[1] << 8) | + ((uint32_t)tx_message_struct->data[0])); + can_x->tx_mailbox[transmit_mailbox].tmdth = (((uint32_t)tx_message_struct->data[7] << 24) | + ((uint32_t)tx_message_struct->data[6] << 16) | + ((uint32_t)tx_message_struct->data[5] << 8) | + ((uint32_t)tx_message_struct->data[4])); + + /* request transmission */ + can_x->tx_mailbox[transmit_mailbox].tmi_bit.tmsr = TRUE; + } + return transmit_mailbox; } /** @@ -511,67 +469,47 @@ uint8_t can_message_transmit(can_type* can_x, can_tx_message_type* tx_message_st * - CAN_TX_STATUS_FAILED * - CAN_TX_STATUS_PENDING */ -can_transmit_status_type can_transmit_status_get(can_type* can_x, can_tx_mailbox_num_type transmit_mailbox) -{ - can_transmit_status_type state_index = CAN_TX_STATUS_FAILED; - switch(transmit_mailbox) - { - case CAN_TX_MAILBOX0: - if(can_x->tsts_bit.tm0tcf != RESET) - { - if(can_x->tsts_bit.tm0tsf != RESET) - { - state_index = CAN_TX_STATUS_SUCCESSFUL; - } - else - { - state_index = CAN_TX_STATUS_FAILED; - } - } - else - { - state_index = CAN_TX_STATUS_PENDING; - } - break; - case CAN_TX_MAILBOX1: - if(can_x->tsts_bit.tm1tcf != RESET) - { - if(can_x->tsts_bit.tm1tsf != RESET) - { - state_index = CAN_TX_STATUS_SUCCESSFUL; - } - else - { - state_index = CAN_TX_STATUS_FAILED; - } - } - else - { - state_index = CAN_TX_STATUS_PENDING; - } - break; - case CAN_TX_MAILBOX2: - if(can_x->tsts_bit.tm2tcf != RESET) - { - if(can_x->tsts_bit.tm2tsf != RESET) - { - state_index = CAN_TX_STATUS_SUCCESSFUL; - } - else - { - state_index = CAN_TX_STATUS_FAILED; - } - } - else - { - state_index = CAN_TX_STATUS_PENDING; - } - break; - default: - state_index = CAN_TX_STATUS_FAILED; - break; - } - return state_index; +can_transmit_status_type can_transmit_status_get(can_type *can_x, can_tx_mailbox_num_type transmit_mailbox) { + can_transmit_status_type state_index = CAN_TX_STATUS_FAILED; + switch (transmit_mailbox) { + case CAN_TX_MAILBOX0: + if (can_x->tsts_bit.tm0tcf != RESET) { + if (can_x->tsts_bit.tm0tsf != RESET) { + state_index = CAN_TX_STATUS_SUCCESSFUL; + } else { + state_index = CAN_TX_STATUS_FAILED; + } + } else { + state_index = CAN_TX_STATUS_PENDING; + } + break; + case CAN_TX_MAILBOX1: + if (can_x->tsts_bit.tm1tcf != RESET) { + if (can_x->tsts_bit.tm1tsf != RESET) { + state_index = CAN_TX_STATUS_SUCCESSFUL; + } else { + state_index = CAN_TX_STATUS_FAILED; + } + } else { + state_index = CAN_TX_STATUS_PENDING; + } + break; + case CAN_TX_MAILBOX2: + if (can_x->tsts_bit.tm2tcf != RESET) { + if (can_x->tsts_bit.tm2tsf != RESET) { + state_index = CAN_TX_STATUS_SUCCESSFUL; + } else { + state_index = CAN_TX_STATUS_FAILED; + } + } else { + state_index = CAN_TX_STATUS_PENDING; + } + break; + default: + state_index = CAN_TX_STATUS_FAILED; + break; + } + return state_index; } /** @@ -586,24 +524,22 @@ can_transmit_status_type can_transmit_status_get(can_type* can_x, can_tx_mailbox * - CAN_TX_MAILBOX2 * @retval none. */ -void can_transmit_cancel(can_type* can_x, can_tx_mailbox_num_type transmit_mailbox) -{ - uint32_t transmit_cancel_bit = 0; - transmit_cancel_bit = can_x->tsts & (CAN_TSTS_TM0CT_VAL | CAN_TSTS_TM1CT_VAL | CAN_TSTS_TM2CT_VAL); - switch (transmit_mailbox) - { - case CAN_TX_MAILBOX0: - can_x->tsts = transmit_cancel_bit | CAN_TSTS_TM0CT_VAL; - break; - case CAN_TX_MAILBOX1: - can_x->tsts = transmit_cancel_bit | CAN_TSTS_TM1CT_VAL; - break; - case CAN_TX_MAILBOX2: - can_x->tsts = transmit_cancel_bit | CAN_TSTS_TM2CT_VAL; - break; - default: - break; - } +void can_transmit_cancel(can_type *can_x, can_tx_mailbox_num_type transmit_mailbox) { + uint32_t transmit_cancel_bit = 0; + transmit_cancel_bit = can_x->tsts & (CAN_TSTS_TM0CT_VAL | CAN_TSTS_TM1CT_VAL | CAN_TSTS_TM2CT_VAL); + switch (transmit_mailbox) { + case CAN_TX_MAILBOX0: + can_x->tsts = transmit_cancel_bit | CAN_TSTS_TM0CT_VAL; + break; + case CAN_TX_MAILBOX1: + can_x->tsts = transmit_cancel_bit | CAN_TSTS_TM1CT_VAL; + break; + case CAN_TX_MAILBOX2: + can_x->tsts = transmit_cancel_bit | CAN_TSTS_TM2CT_VAL; + break; + default: + break; + } } /** @@ -618,40 +554,38 @@ void can_transmit_cancel(can_type* can_x, can_tx_mailbox_num_type transmit_mailb * @param rx_message_struct: pointer to a structure which store the receive message. * @retval none. */ -void can_message_receive(can_type* can_x, can_rx_fifo_num_type fifo_number, can_rx_message_type* rx_message_struct) -{ - /* get the id type */ - rx_message_struct->id_type = (can_identifier_type)can_x->fifo_mailbox[fifo_number].rfi_bit.rfidi; - switch (rx_message_struct->id_type) - { - case CAN_ID_STANDARD: - rx_message_struct->standard_id = can_x->fifo_mailbox[fifo_number].rfi_bit.rfsid; - break; - case CAN_ID_EXTENDED: - rx_message_struct->extended_id = 0x1FFFFFFF & (can_x->fifo_mailbox[fifo_number].rfi >> 3); - break; - default: - break; - } - rx_message_struct->frame_type = (can_trans_frame_type)can_x->fifo_mailbox[fifo_number].rfi_bit.rffri; - /* get the dlc */ - rx_message_struct->dlc = can_x->fifo_mailbox[fifo_number].rfc_bit.rfdtl; +void can_message_receive(can_type *can_x, can_rx_fifo_num_type fifo_number, can_rx_message_type *rx_message_struct) { + /* get the id type */ + rx_message_struct->id_type = (can_identifier_type)can_x->fifo_mailbox[fifo_number].rfi_bit.rfidi; + switch (rx_message_struct->id_type) { + case CAN_ID_STANDARD: + rx_message_struct->standard_id = can_x->fifo_mailbox[fifo_number].rfi_bit.rfsid; + break; + case CAN_ID_EXTENDED: + rx_message_struct->extended_id = 0x1FFFFFFF & (can_x->fifo_mailbox[fifo_number].rfi >> 3); + break; + default: + break; + } + rx_message_struct->frame_type = (can_trans_frame_type)can_x->fifo_mailbox[fifo_number].rfi_bit.rffri; + /* get the dlc */ + rx_message_struct->dlc = can_x->fifo_mailbox[fifo_number].rfc_bit.rfdtl; - /* get the filter match number */ - rx_message_struct->filter_index = can_x->fifo_mailbox[fifo_number].rfc_bit.rffmn; + /* get the filter match number */ + rx_message_struct->filter_index = can_x->fifo_mailbox[fifo_number].rfc_bit.rffmn; - /* get the data field */ - rx_message_struct->data[0] = can_x->fifo_mailbox[fifo_number].rfdtl_bit.rfdt0; - rx_message_struct->data[1] = can_x->fifo_mailbox[fifo_number].rfdtl_bit.rfdt1; - rx_message_struct->data[2] = can_x->fifo_mailbox[fifo_number].rfdtl_bit.rfdt2; - rx_message_struct->data[3] = can_x->fifo_mailbox[fifo_number].rfdtl_bit.rfdt3; - rx_message_struct->data[4] = can_x->fifo_mailbox[fifo_number].rfdth_bit.rfdt4; - rx_message_struct->data[5] = can_x->fifo_mailbox[fifo_number].rfdth_bit.rfdt5; - rx_message_struct->data[6] = can_x->fifo_mailbox[fifo_number].rfdth_bit.rfdt6; - rx_message_struct->data[7] = can_x->fifo_mailbox[fifo_number].rfdth_bit.rfdt7; + /* get the data field */ + rx_message_struct->data[0] = can_x->fifo_mailbox[fifo_number].rfdtl_bit.rfdt0; + rx_message_struct->data[1] = can_x->fifo_mailbox[fifo_number].rfdtl_bit.rfdt1; + rx_message_struct->data[2] = can_x->fifo_mailbox[fifo_number].rfdtl_bit.rfdt2; + rx_message_struct->data[3] = can_x->fifo_mailbox[fifo_number].rfdtl_bit.rfdt3; + rx_message_struct->data[4] = can_x->fifo_mailbox[fifo_number].rfdth_bit.rfdt4; + rx_message_struct->data[5] = can_x->fifo_mailbox[fifo_number].rfdth_bit.rfdt5; + rx_message_struct->data[6] = can_x->fifo_mailbox[fifo_number].rfdth_bit.rfdt6; + rx_message_struct->data[7] = can_x->fifo_mailbox[fifo_number].rfdth_bit.rfdt7; - /* release the fifo */ - can_receive_fifo_release(can_x, fifo_number); + /* release the fifo */ + can_receive_fifo_release(can_x, fifo_number); } /** @@ -665,19 +599,17 @@ void can_message_receive(can_type* can_x, can_rx_fifo_num_type fifo_number, can_ * - CAN_RX_FIFO1 * @retval none. */ -void can_receive_fifo_release(can_type* can_x, can_rx_fifo_num_type fifo_number) -{ - switch (fifo_number) - { - case CAN_RX_FIFO0: - can_x->rf0 = CAN_RF0_RF0R_VAL; - break; - case CAN_RX_FIFO1: - can_x->rf1 = CAN_RF1_RF1R_VAL; - break; - default: - break; - } +void can_receive_fifo_release(can_type *can_x, can_rx_fifo_num_type fifo_number) { + switch (fifo_number) { + case CAN_RX_FIFO0: + can_x->rf0 = CAN_RF0_RF0R_VAL; + break; + case CAN_RX_FIFO1: + can_x->rf1 = CAN_RF1_RF1R_VAL; + break; + default: + break; + } } /** @@ -691,21 +623,19 @@ void can_receive_fifo_release(can_type* can_x, can_rx_fifo_num_type fifo_number) * - CAN_RX_FIFO1 * @retval the number of message pending in the receive fifo. */ -uint8_t can_receive_message_pending_get(can_type* can_x, can_rx_fifo_num_type fifo_number) -{ - uint8_t message_pending = 0; - switch (fifo_number) - { - case CAN_RX_FIFO0: - message_pending = can_x->rf0_bit.rf0mn; - break; - case CAN_RX_FIFO1: - message_pending = can_x->rf1_bit.rf1mn; - break; - default: - break; - } - return message_pending; +uint8_t can_receive_message_pending_get(can_type *can_x, can_rx_fifo_num_type fifo_number) { + uint8_t message_pending = 0; + switch (fifo_number) { + case CAN_RX_FIFO0: + message_pending = can_x->rf0_bit.rf0mn; + break; + case CAN_RX_FIFO1: + message_pending = can_x->rf1_bit.rf1mn; + break; + default: + break; + } + return message_pending; } /** @@ -722,73 +652,53 @@ uint8_t can_receive_message_pending_get(can_type* can_x, can_rx_fifo_num_type fi * this parameter can be one of the following values: * SUCCESS or ERROR */ -error_status can_operating_mode_set(can_type* can_x, can_operating_mode_type can_operating_mode) -{ - error_status status = ERROR; - uint32_t time_out_index = FZC_TIMEOUT; +error_status can_operating_mode_set(can_type *can_x, can_operating_mode_type can_operating_mode) { + error_status status = ERROR; + uint32_t time_out_index = FZC_TIMEOUT; - if (can_operating_mode == CAN_OPERATINGMODE_FREEZE) - { - /* request enter freeze mode */ - can_x->mctrl_bit.dzen = FALSE; - can_x->mctrl_bit.fzen = TRUE; + if (can_operating_mode == CAN_OPERATINGMODE_FREEZE) { + /* request enter freeze mode */ + can_x->mctrl_bit.dzen = FALSE; + can_x->mctrl_bit.fzen = TRUE; - while(((can_x->msts_bit.dzc) || (!can_x->msts_bit.fzc)) && (time_out_index != 0)) - { - time_out_index--; - } - if((can_x->msts_bit.dzc) || (!can_x->msts_bit.fzc)) - { - status = ERROR; - } - else - { - status = SUCCESS; - } - } - else if(can_operating_mode == CAN_OPERATINGMODE_DOZE) - { - /* request enter doze mode */ - can_x->mctrl_bit.dzen = TRUE; - can_x->mctrl_bit.fzen = FALSE; + while (((can_x->msts_bit.dzc) || (!can_x->msts_bit.fzc)) && (time_out_index != 0)) { + time_out_index--; + } + if ((can_x->msts_bit.dzc) || (!can_x->msts_bit.fzc)) { + status = ERROR; + } else { + status = SUCCESS; + } + } else if (can_operating_mode == CAN_OPERATINGMODE_DOZE) { + /* request enter doze mode */ + can_x->mctrl_bit.dzen = TRUE; + can_x->mctrl_bit.fzen = FALSE; - while(((!can_x->msts_bit.dzc) || (can_x->msts_bit.fzc)) && (time_out_index != 0)) - { - time_out_index--; - } - if((!can_x->msts_bit.dzc) || (can_x->msts_bit.fzc)) - { - status = ERROR; - } - else - { - status = SUCCESS; - } - } - else if(can_operating_mode == CAN_OPERATINGMODE_COMMUNICATE) - { - /* request enter normal mode */ - can_x->mctrl_bit.dzen = FALSE; - can_x->mctrl_bit.fzen = FALSE; + while (((!can_x->msts_bit.dzc) || (can_x->msts_bit.fzc)) && (time_out_index != 0)) { + time_out_index--; + } + if ((!can_x->msts_bit.dzc) || (can_x->msts_bit.fzc)) { + status = ERROR; + } else { + status = SUCCESS; + } + } else if (can_operating_mode == CAN_OPERATINGMODE_COMMUNICATE) { + /* request enter normal mode */ + can_x->mctrl_bit.dzen = FALSE; + can_x->mctrl_bit.fzen = FALSE; - while(((can_x->msts_bit.dzc) || (can_x->msts_bit.fzc)) && (time_out_index != 0)) - { - time_out_index--; + while (((can_x->msts_bit.dzc) || (can_x->msts_bit.fzc)) && (time_out_index != 0)) { + time_out_index--; + } + if ((can_x->msts_bit.dzc) || (can_x->msts_bit.fzc)) { + status = ERROR; + } else { + status = SUCCESS; + } + } else { + status = ERROR; } - if((can_x->msts_bit.dzc) || (can_x->msts_bit.fzc)) - { - status = ERROR; - } - else - { - status = SUCCESS; - } - } - else - { - status = ERROR; - } - return status; + return status; } /** @@ -800,25 +710,20 @@ error_status can_operating_mode_set(can_type* can_x, can_operating_mode_type can * - CAN_ENTER_DOZE_SUCCESSFUL * - CAN_ENTER_DOZE_FAILED */ -can_enter_doze_status_type can_doze_mode_enter(can_type* can_x) -{ - can_enter_doze_status_type status = CAN_ENTER_DOZE_FAILED; - uint32_t time_out_index = FZC_TIMEOUT; - can_x->mctrl_bit.fzen = FALSE; - can_x->mctrl_bit.dzen = TRUE; - while(((!can_x->msts_bit.dzc) || (can_x->msts_bit.fzc)) && (time_out_index != 0)) - { - time_out_index--; - } - if((!can_x->msts_bit.dzc) || (can_x->msts_bit.fzc)) - { - status = CAN_ENTER_DOZE_FAILED; - } - else - { - status = CAN_ENTER_DOZE_SUCCESSFUL; - } - return status; +can_enter_doze_status_type can_doze_mode_enter(can_type *can_x) { + can_enter_doze_status_type status = CAN_ENTER_DOZE_FAILED; + uint32_t time_out_index = FZC_TIMEOUT; + can_x->mctrl_bit.fzen = FALSE; + can_x->mctrl_bit.dzen = TRUE; + while (((!can_x->msts_bit.dzc) || (can_x->msts_bit.fzc)) && (time_out_index != 0)) { + time_out_index--; + } + if ((!can_x->msts_bit.dzc) || (can_x->msts_bit.fzc)) { + status = CAN_ENTER_DOZE_FAILED; + } else { + status = CAN_ENTER_DOZE_SUCCESSFUL; + } + return status; } /** @@ -830,20 +735,17 @@ can_enter_doze_status_type can_doze_mode_enter(can_type* can_x) * - CAN_QUIT_DOZE_SUCCESSFUL * - CAN_QUIT_DOZE_FAILED */ -can_quit_doze_status_type can_doze_mode_exit(can_type* can_x) -{ - can_quit_doze_status_type status = CAN_QUIT_DOZE_FAILED; - uint32_t time_out_index = DZC_TIMEOUT; - can_x->mctrl_bit.dzen = FALSE; - while((can_x->msts_bit.dzc) && (time_out_index != 0)) - { - time_out_index--; - } - if(!can_x->msts_bit.dzc) - { - status = CAN_QUIT_DOZE_SUCCESSFUL; - } - return status; +can_quit_doze_status_type can_doze_mode_exit(can_type *can_x) { + can_quit_doze_status_type status = CAN_QUIT_DOZE_FAILED; + uint32_t time_out_index = DZC_TIMEOUT; + can_x->mctrl_bit.dzen = FALSE; + while ((can_x->msts_bit.dzc) && (time_out_index != 0)) { + time_out_index--; + } + if (!can_x->msts_bit.dzc) { + status = CAN_QUIT_DOZE_SUCCESSFUL; + } + return status; } /** @@ -862,12 +764,11 @@ can_quit_doze_status_type can_doze_mode_exit(can_type* can_x) * - CAN_ERRORRECORD_CRCERR, * - CAN_ERRORRECORD_SOFTWARESETERR */ -can_error_record_type can_error_type_record_get(can_type* can_x) -{ - can_error_record_type error_code = CAN_ERRORRECORD_NOERR; +can_error_record_type can_error_type_record_get(can_type *can_x) { + can_error_record_type error_code = CAN_ERRORRECORD_NOERR; - error_code = (can_error_record_type)can_x->ests_bit.etr; - return error_code; + error_code = (can_error_record_type)can_x->ests_bit.etr; + return error_code; } /** @@ -877,11 +778,10 @@ can_error_record_type can_error_type_record_get(can_type* can_x) * CAN1,CAN2. * @retval the value of receive error counter. */ -uint8_t can_receive_error_counter_get(can_type* can_x) -{ - uint8_t counter = 0; - counter = can_x->ests_bit.rec; - return counter; +uint8_t can_receive_error_counter_get(can_type *can_x) { + uint8_t counter = 0; + counter = can_x->ests_bit.rec; + return counter; } /** @@ -891,11 +791,10 @@ uint8_t can_receive_error_counter_get(can_type* can_x) * CAN1,CAN2. * @retval the value of transmit error counter. */ -uint8_t can_transmit_error_counter_get(can_type* can_x) -{ - uint8_t counter = 0; - counter = can_x->ests_bit.tec; - return counter; +uint8_t can_transmit_error_counter_get(can_type *can_x) { + uint8_t counter = 0; + counter = can_x->ests_bit.tec; + return counter; } /** @@ -923,16 +822,12 @@ uint8_t can_transmit_error_counter_get(can_type* can_x) * this parameter can be: TRUE or FALSE. * @retval none. */ -void can_interrupt_enable(can_type* can_x, uint32_t can_int, confirm_state new_state) -{ - if (new_state != FALSE) - { - can_x->inten |= can_int; - } - else - { - can_x->inten &= ~can_int; - } +void can_interrupt_enable(can_type *can_x, uint32_t can_int, confirm_state new_state) { + if (new_state != FALSE) { + can_x->inten |= can_int; + } else { + can_x->inten &= ~can_int; + } } /** @@ -963,72 +858,69 @@ void can_interrupt_enable(can_type* can_x, uint32_t can_int, confirm_state new_s * note:the state of CAN_TMEF_FLAG need to check rqc0,rqc1 and rqc2 bit * @retval status of can_flag, the returned value can be:SET or RESET. */ -flag_status can_interrupt_flag_get(can_type* can_x, uint32_t can_flag) -{ - flag_status bit_status = RESET; - flag_status int_status = RESET; +flag_status can_interrupt_flag_get(can_type *can_x, uint32_t can_flag) { + flag_status bit_status = RESET; + flag_status int_status = RESET; - switch(can_flag) - { - case CAN_EAF_FLAG: - int_status = (flag_status)(can_x->inten_bit.eoien && can_x->inten_bit.eaien); - break; - case CAN_EPF_FLAG: - int_status = (flag_status)(can_x->inten_bit.eoien && can_x->inten_bit.epien); - break; - case CAN_BOF_FLAG: - int_status = (flag_status)(can_x->inten_bit.eoien && can_x->inten_bit.boien); - break; - case CAN_ETR_FLAG: - int_status = (flag_status)(can_x->inten_bit.eoien && can_x->inten_bit.etrien); - break; - case CAN_EOIF_FLAG: - int_status = (flag_status)can_x->inten_bit.eoien; - break; - case CAN_TM0TCF_FLAG: - case CAN_TM1TCF_FLAG: - case CAN_TM2TCF_FLAG: - int_status = (flag_status)can_x->inten_bit.tcien; - break; - case CAN_RF0MN_FLAG: - int_status = (flag_status)can_x->inten_bit.rf0mien; - break; - case CAN_RF0FF_FLAG: - int_status = (flag_status)can_x->inten_bit.rf0fien; - break; - case CAN_RF0OF_FLAG: - int_status = (flag_status)can_x->inten_bit.rf0oien; - break; - case CAN_RF1MN_FLAG: - int_status = (flag_status)can_x->inten_bit.rf1mien; - break; - case CAN_RF1FF_FLAG: - int_status = (flag_status)can_x->inten_bit.rf1fien; - break; - case CAN_RF1OF_FLAG: - int_status = (flag_status)can_x->inten_bit.rf1oien; - break; - case CAN_QDZIF_FLAG: - int_status = (flag_status)can_x->inten_bit.qdzien; - break; - case CAN_EDZC_FLAG: - int_status = (flag_status)can_x->inten_bit.edzien; - break; - case CAN_TMEF_FLAG: - int_status = (flag_status)can_x->inten_bit.tcien; - break; - default: - int_status = RESET; - break; - } + switch (can_flag) { + case CAN_EAF_FLAG: + int_status = (flag_status)(can_x->inten_bit.eoien && can_x->inten_bit.eaien); + break; + case CAN_EPF_FLAG: + int_status = (flag_status)(can_x->inten_bit.eoien && can_x->inten_bit.epien); + break; + case CAN_BOF_FLAG: + int_status = (flag_status)(can_x->inten_bit.eoien && can_x->inten_bit.boien); + break; + case CAN_ETR_FLAG: + int_status = (flag_status)(can_x->inten_bit.eoien && can_x->inten_bit.etrien); + break; + case CAN_EOIF_FLAG: + int_status = (flag_status)can_x->inten_bit.eoien; + break; + case CAN_TM0TCF_FLAG: + case CAN_TM1TCF_FLAG: + case CAN_TM2TCF_FLAG: + int_status = (flag_status)can_x->inten_bit.tcien; + break; + case CAN_RF0MN_FLAG: + int_status = (flag_status)can_x->inten_bit.rf0mien; + break; + case CAN_RF0FF_FLAG: + int_status = (flag_status)can_x->inten_bit.rf0fien; + break; + case CAN_RF0OF_FLAG: + int_status = (flag_status)can_x->inten_bit.rf0oien; + break; + case CAN_RF1MN_FLAG: + int_status = (flag_status)can_x->inten_bit.rf1mien; + break; + case CAN_RF1FF_FLAG: + int_status = (flag_status)can_x->inten_bit.rf1fien; + break; + case CAN_RF1OF_FLAG: + int_status = (flag_status)can_x->inten_bit.rf1oien; + break; + case CAN_QDZIF_FLAG: + int_status = (flag_status)can_x->inten_bit.qdzien; + break; + case CAN_EDZC_FLAG: + int_status = (flag_status)can_x->inten_bit.edzien; + break; + case CAN_TMEF_FLAG: + int_status = (flag_status)can_x->inten_bit.tcien; + break; + default: + int_status = RESET; + break; + } - if(int_status != SET) - { - return RESET; - } - bit_status = can_flag_get(can_x, can_flag); + if (int_status != SET) { + return RESET; + } + bit_status = can_flag_get(can_x, can_flag); - return bit_status; + return bit_status; } /** @@ -1059,102 +951,85 @@ flag_status can_interrupt_flag_get(can_type* can_x, uint32_t can_flag) * note:the state of CAN_TMEF_FLAG need to check rqc0,rqc1 and rqc2 bit * @retval status of can_flag, the returned value can be:SET or RESET. */ -flag_status can_flag_get(can_type* can_x, uint32_t can_flag) -{ - flag_status bit_status = RESET; - switch(can_flag) - { - case CAN_EAF_FLAG: - bit_status = (flag_status)can_x->ests_bit.eaf; - break; - case CAN_EPF_FLAG: - bit_status = (flag_status)can_x->ests_bit.epf; - break; - case CAN_BOF_FLAG: - bit_status = (flag_status)can_x->ests_bit.bof; - break; - case CAN_ETR_FLAG: - if(can_x->ests_bit.etr != 0) - { - bit_status = SET; - } - else - { - bit_status = RESET; - } - break; - case CAN_EOIF_FLAG: - bit_status = (flag_status)can_x->msts_bit.eoif; - break; - case CAN_TM0TCF_FLAG: - bit_status = (flag_status)can_x->tsts_bit.tm0tcf; - break; - case CAN_TM1TCF_FLAG: - bit_status = (flag_status)can_x->tsts_bit.tm1tcf; - break; - case CAN_TM2TCF_FLAG: - bit_status = (flag_status)can_x->tsts_bit.tm2tcf; - break; - case CAN_RF0MN_FLAG: - if(can_x->rf0_bit.rf0mn != 0) - { - bit_status = SET; - } - else - { - bit_status = RESET; - } - break; - case CAN_RF0FF_FLAG: - bit_status = (flag_status)can_x->rf0_bit.rf0ff; - break; - case CAN_RF0OF_FLAG: - bit_status = (flag_status)can_x->rf0_bit.rf0of; - break; - case CAN_RF1MN_FLAG: - if(can_x->rf1_bit.rf1mn != 0) - { - bit_status = SET; - } - else - { - bit_status = RESET; - } - break; - case CAN_RF1FF_FLAG: - bit_status = (flag_status)can_x->rf1_bit.rf1ff; - break; - case CAN_RF1OF_FLAG: - bit_status = (flag_status)can_x->rf1_bit.rf1of; - break; - case CAN_QDZIF_FLAG: - bit_status = (flag_status)can_x->msts_bit.qdzif; - break; - case CAN_EDZC_FLAG: - if((can_x->msts_bit.dzc != RESET) ||(can_x->msts_bit.edzif != RESET)) - { - bit_status = SET; - } - else - { - bit_status = RESET; - } - break; - case CAN_TMEF_FLAG: - if((can_x->tsts_bit.tm0ef != RESET) || (can_x->tsts_bit.tm1ef != RESET) || (can_x->tsts_bit.tm2ef != RESET)) - { - bit_status = SET; - } - else - { - bit_status = RESET; - } - break; - default: - bit_status = RESET; - break; - } - return bit_status; +flag_status can_flag_get(can_type *can_x, uint32_t can_flag) { + flag_status bit_status = RESET; + switch (can_flag) { + case CAN_EAF_FLAG: + bit_status = (flag_status)can_x->ests_bit.eaf; + break; + case CAN_EPF_FLAG: + bit_status = (flag_status)can_x->ests_bit.epf; + break; + case CAN_BOF_FLAG: + bit_status = (flag_status)can_x->ests_bit.bof; + break; + case CAN_ETR_FLAG: + if (can_x->ests_bit.etr != 0) { + bit_status = SET; + } else { + bit_status = RESET; + } + break; + case CAN_EOIF_FLAG: + bit_status = (flag_status)can_x->msts_bit.eoif; + break; + case CAN_TM0TCF_FLAG: + bit_status = (flag_status)can_x->tsts_bit.tm0tcf; + break; + case CAN_TM1TCF_FLAG: + bit_status = (flag_status)can_x->tsts_bit.tm1tcf; + break; + case CAN_TM2TCF_FLAG: + bit_status = (flag_status)can_x->tsts_bit.tm2tcf; + break; + case CAN_RF0MN_FLAG: + if (can_x->rf0_bit.rf0mn != 0) { + bit_status = SET; + } else { + bit_status = RESET; + } + break; + case CAN_RF0FF_FLAG: + bit_status = (flag_status)can_x->rf0_bit.rf0ff; + break; + case CAN_RF0OF_FLAG: + bit_status = (flag_status)can_x->rf0_bit.rf0of; + break; + case CAN_RF1MN_FLAG: + if (can_x->rf1_bit.rf1mn != 0) { + bit_status = SET; + } else { + bit_status = RESET; + } + break; + case CAN_RF1FF_FLAG: + bit_status = (flag_status)can_x->rf1_bit.rf1ff; + break; + case CAN_RF1OF_FLAG: + bit_status = (flag_status)can_x->rf1_bit.rf1of; + break; + case CAN_QDZIF_FLAG: + bit_status = (flag_status)can_x->msts_bit.qdzif; + break; + case CAN_EDZC_FLAG: + if ((can_x->msts_bit.dzc != RESET) || (can_x->msts_bit.edzif != RESET)) { + bit_status = SET; + } else { + bit_status = RESET; + } + break; + case CAN_TMEF_FLAG: + if ((can_x->tsts_bit.tm0ef != RESET) || (can_x->tsts_bit.tm1ef != RESET) || (can_x->tsts_bit.tm2ef != RESET)) { + bit_status = SET; + } else { + bit_status = RESET; + } + break; + default: + bit_status = RESET; + break; + } + return bit_status; } /** @@ -1182,53 +1057,51 @@ flag_status can_flag_get(can_type* can_x, uint32_t can_flag) * note:CAN_RF0MN_FLAG and CAN_RF1MN_FLAG can not clear by this function * @retval none. */ -void can_flag_clear(can_type* can_x, uint32_t can_flag) -{ - switch(can_flag) - { - case CAN_EAF_FLAG: - case CAN_EPF_FLAG: - case CAN_BOF_FLAG: - case CAN_EOIF_FLAG: - can_x->msts = CAN_MSTS_EOIF_VAL; - break; - case CAN_ETR_FLAG: - can_x->msts = CAN_MSTS_EOIF_VAL; - can_x->ests = 0; - break; - case CAN_TM0TCF_FLAG: - can_x->tsts = CAN_TSTS_TM0TCF_VAL; - break; - case CAN_TM1TCF_FLAG: - can_x->tsts = CAN_TSTS_TM1TCF_VAL; - break; - case CAN_TM2TCF_FLAG: - can_x->tsts = CAN_TSTS_TM2TCF_VAL; - break; - case CAN_RF0FF_FLAG: - can_x->rf0 = CAN_RF0_RF0FF_VAL; - break; - case CAN_RF0OF_FLAG: - can_x->rf0 = CAN_RF0_RF0OF_VAL; - break; - case CAN_RF1FF_FLAG: - can_x->rf1 = CAN_RF1_RF1FF_VAL; - break; - case CAN_RF1OF_FLAG: - can_x->rf1 = CAN_RF1_RF1OF_VAL; - break; - case CAN_QDZIF_FLAG: - can_x->msts = CAN_MSTS_QDZIF_VAL; - break; - case CAN_EDZC_FLAG: - can_x->msts = CAN_MSTS_EDZIF_VAL; - break; - case CAN_TMEF_FLAG: - can_x->tsts = CAN_TSTS_TM0TCF_VAL | CAN_TSTS_TM1TCF_VAL | CAN_TSTS_TM2TCF_VAL; - break; - default: - break; - } +void can_flag_clear(can_type *can_x, uint32_t can_flag) { + switch (can_flag) { + case CAN_EAF_FLAG: + case CAN_EPF_FLAG: + case CAN_BOF_FLAG: + case CAN_EOIF_FLAG: + can_x->msts = CAN_MSTS_EOIF_VAL; + break; + case CAN_ETR_FLAG: + can_x->msts = CAN_MSTS_EOIF_VAL; + can_x->ests = 0; + break; + case CAN_TM0TCF_FLAG: + can_x->tsts = CAN_TSTS_TM0TCF_VAL; + break; + case CAN_TM1TCF_FLAG: + can_x->tsts = CAN_TSTS_TM1TCF_VAL; + break; + case CAN_TM2TCF_FLAG: + can_x->tsts = CAN_TSTS_TM2TCF_VAL; + break; + case CAN_RF0FF_FLAG: + can_x->rf0 = CAN_RF0_RF0FF_VAL; + break; + case CAN_RF0OF_FLAG: + can_x->rf0 = CAN_RF0_RF0OF_VAL; + break; + case CAN_RF1FF_FLAG: + can_x->rf1 = CAN_RF1_RF1FF_VAL; + break; + case CAN_RF1OF_FLAG: + can_x->rf1 = CAN_RF1_RF1OF_VAL; + break; + case CAN_QDZIF_FLAG: + can_x->msts = CAN_MSTS_QDZIF_VAL; + break; + case CAN_EDZC_FLAG: + can_x->msts = CAN_MSTS_EDZIF_VAL; + break; + case CAN_TMEF_FLAG: + can_x->tsts = CAN_TSTS_TM0TCF_VAL | CAN_TSTS_TM1TCF_VAL | CAN_TSTS_TM2TCF_VAL; + break; + default: + break; + } } /** diff --git a/armlib/at32_sys/drivers/src/at32f435_437_crc.c b/armlib/at32_sys/drivers/src/at32f435_437_crc.c index 1b28f83e5..efa41e311 100644 --- a/armlib/at32_sys/drivers/src/at32f435_437_crc.c +++ b/armlib/at32_sys/drivers/src/at32f435_437_crc.c @@ -45,10 +45,9 @@ * @param none * @retval none */ -void crc_data_reset(void) -{ - /* reset crc generator */ - CRC->ctrl_bit.rst = 0x1; +void crc_data_reset(void) { + /* reset crc generator */ + CRC->ctrl_bit.rst = 0x1; } /** @@ -56,10 +55,9 @@ void crc_data_reset(void) * @param data: data word(32-bit) to compute its crc * @retval 32-bit crc */ -uint32_t crc_one_word_calculate(uint32_t data) -{ - CRC->dt = data; - return (CRC->dt); +uint32_t crc_one_word_calculate(uint32_t data) { + CRC->dt = data; + return (CRC->dt); } /** @@ -68,16 +66,14 @@ uint32_t crc_one_word_calculate(uint32_t data) * @param length: length of the buffer to be computed * @retval 32-bit crc */ -uint32_t crc_block_calculate(uint32_t *pbuffer, uint32_t length) -{ - uint32_t index = 0; +uint32_t crc_block_calculate(uint32_t *pbuffer, uint32_t length) { + uint32_t index = 0; - for(index = 0; index < length; index++) - { - CRC->dt = pbuffer[index]; - } + for (index = 0; index < length; index++) { + CRC->dt = pbuffer[index]; + } - return (CRC->dt); + return (CRC->dt); } /** @@ -85,9 +81,8 @@ uint32_t crc_block_calculate(uint32_t *pbuffer, uint32_t length) * @param none * @retval 32-bit crc */ -uint32_t crc_data_get(void) -{ - return (CRC->dt); +uint32_t crc_data_get(void) { + return (CRC->dt); } /** @@ -95,9 +90,8 @@ uint32_t crc_data_get(void) * @param cdt_value: 8-bit value to be stored in the common data register * @retval none */ -void crc_common_data_set(uint8_t cdt_value) -{ - CRC->cdt_bit.cdt = cdt_value; +void crc_common_data_set(uint8_t cdt_value) { + CRC->cdt_bit.cdt = cdt_value; } /** @@ -105,9 +99,8 @@ void crc_common_data_set(uint8_t cdt_value) * @param none * @retval 8-bit value of the common data register */ -uint8_t crc_common_data_get(void) -{ - return (CRC->cdt_bit.cdt); +uint8_t crc_common_data_get(void) { + return (CRC->cdt_bit.cdt); } /** @@ -115,9 +108,8 @@ uint8_t crc_common_data_get(void) * @param value: initial data * @retval none */ -void crc_init_data_set(uint32_t value) -{ - CRC->idt = value; +void crc_init_data_set(uint32_t value) { + CRC->idt = value; } /** @@ -130,9 +122,8 @@ void crc_init_data_set(uint32_t value) * - CRC_REVERSE_INPUT_BY_WORD * @retval none. */ -void crc_reverse_input_data_set(crc_reverse_input_type value) -{ - CRC->ctrl_bit.revid = value; +void crc_reverse_input_data_set(crc_reverse_input_type value) { + CRC->ctrl_bit.revid = value; } /** @@ -143,9 +134,8 @@ void crc_reverse_input_data_set(crc_reverse_input_type value) * - CRC_REVERSE_OUTPUT_DATA * @retval none. */ -void crc_reverse_output_data_set(crc_reverse_output_type value) -{ - CRC->ctrl_bit.revod = value; +void crc_reverse_output_data_set(crc_reverse_output_type value) { + CRC->ctrl_bit.revod = value; } /** @@ -154,9 +144,8 @@ void crc_reverse_output_data_set(crc_reverse_output_type value) * 32-bit new data of crc poly value * @retval none. */ -void crc_poly_value_set(uint32_t value) -{ - CRC->poly = value; +void crc_poly_value_set(uint32_t value) { + CRC->poly = value; } /** @@ -164,9 +153,8 @@ void crc_poly_value_set(uint32_t value) * @param none * @retval 32-bit value of the polynomial value. */ -uint32_t crc_poly_value_get(void) -{ - return (CRC->poly); +uint32_t crc_poly_value_get(void) { + return (CRC->poly); } /** @@ -179,9 +167,8 @@ uint32_t crc_poly_value_get(void) * - CRC_POLY_SIZE_7B * @retval none. */ -void crc_poly_size_set(crc_poly_size_type size) -{ - CRC->ctrl_bit.poly_size = size; +void crc_poly_size_set(crc_poly_size_type size) { + CRC->ctrl_bit.poly_size = size; } /** @@ -189,9 +176,8 @@ void crc_poly_size_set(crc_poly_size_type size) * @param none * @retval polynomial data size. */ -crc_poly_size_type crc_poly_size_get(void) -{ - return (crc_poly_size_type)(CRC->ctrl_bit.poly_size); +crc_poly_size_type crc_poly_size_get(void) { + return (crc_poly_size_type)(CRC->ctrl_bit.poly_size); } /** diff --git a/armlib/at32_sys/drivers/src/at32f435_437_crm.c b/armlib/at32_sys/drivers/src/at32f435_437_crm.c index e15082163..f05255097 100644 --- a/armlib/at32_sys/drivers/src/at32f435_437_crm.c +++ b/armlib/at32_sys/drivers/src/at32f435_437_crm.c @@ -45,35 +45,34 @@ * @param none * @retval none */ -void crm_reset(void) -{ - /* reset the crm clock configuration to the default reset state(for debug purpose) */ - /* set hicken bit */ - CRM->ctrl_bit.hicken = TRUE; +void crm_reset(void) { + /* reset the crm clock configuration to the default reset state(for debug purpose) */ + /* set hicken bit */ + CRM->ctrl_bit.hicken = TRUE; - /* wait hick stable */ - while(CRM->ctrl_bit.hickstbl != SET); + /* wait hick stable */ + while (CRM->ctrl_bit.hickstbl != SET); - /* hick used as system clock */ - CRM->cfg_bit.sclksel = CRM_SCLK_HICK; + /* hick used as system clock */ + CRM->cfg_bit.sclksel = CRM_SCLK_HICK; - /* wait sclk switch status */ - while(CRM->cfg_bit.sclksts != CRM_SCLK_HICK); + /* wait sclk switch status */ + while (CRM->cfg_bit.sclksts != CRM_SCLK_HICK); - /* reset hexten, hextbyps, cfden and pllen bits */ - CRM->ctrl &= ~(0x010D0000U); + /* reset hexten, hextbyps, cfden and pllen bits */ + CRM->ctrl &= ~(0x010D0000U); - /* reset cfg register, include sclk switch, ahbdiv, apb1div, apb2div, adcdiv, clkout bits */ - CRM->cfg = 0; + /* reset cfg register, include sclk switch, ahbdiv, apb1div, apb2div, adcdiv, clkout bits */ + CRM->cfg = 0; - /* reset pllms pllns pllfr pllrcs bits */ - CRM->pllcfg = 0x00033002U; + /* reset pllms pllns pllfr pllrcs bits */ + CRM->pllcfg = 0x00033002U; - /* reset clkout[3], usbbufs, hickdiv, clkoutdiv */ - CRM->misc1 = 0; + /* reset clkout[3], usbbufs, hickdiv, clkoutdiv */ + CRM->misc1 = 0; - /* disable all interrupts enable and clear pending bits */ - CRM->clkint = 0x009F0000U; + /* disable all interrupts enable and clear pending bits */ + CRM->clkint = 0x009F0000U; } /** @@ -81,9 +80,8 @@ void crm_reset(void) * @param new_state (TRUE or FALSE) * @retval none */ -void crm_lext_bypass(confirm_state new_state) -{ - CRM->bpdc_bit.lextbyps = new_state; +void crm_lext_bypass(confirm_state new_state) { + CRM->bpdc_bit.lextbyps = new_state; } /** @@ -91,9 +89,8 @@ void crm_lext_bypass(confirm_state new_state) * @param new_state (TRUE or FALSE) * @retval none */ -void crm_hext_bypass(confirm_state new_state) -{ - CRM->ctrl_bit.hextbyps = new_state; +void crm_hext_bypass(confirm_state new_state) { + CRM->ctrl_bit.hextbyps = new_state; } /** @@ -120,18 +117,14 @@ void crm_hext_bypass(confirm_state new_state) * - CRM_CLOCK_FAILURE_INT_FLAG * @retval flag_status (SET or RESET) */ -flag_status crm_flag_get(uint32_t flag) -{ - flag_status status = RESET; - if((CRM_REG(flag) & CRM_REG_BIT(flag)) != CRM_REG_BIT(flag)) - { - status = RESET; - } - else - { - status = SET; - } - return status; +flag_status crm_flag_get(uint32_t flag) { + flag_status status = RESET; + if ((CRM_REG(flag) & CRM_REG_BIT(flag)) != CRM_REG_BIT(flag)) { + status = RESET; + } else { + status = SET; + } + return status; } /** @@ -146,50 +139,42 @@ flag_status crm_flag_get(uint32_t flag) * - CRM_CLOCK_FAILURE_INT_FLAG * @retval flag_status (SET or RESET) */ -flag_status crm_interrupt_flag_get(uint32_t flag) -{ - flag_status status = RESET; - switch(flag) - { - case CRM_LICK_READY_INT_FLAG: - if(CRM->clkint_bit.lickstblf && CRM->clkint_bit.lickstblien) - { - status = SET; - } - break; - case CRM_LEXT_READY_INT_FLAG: - if(CRM->clkint_bit.lextstblf && CRM->clkint_bit.lextstblien) - { - status = SET; - } - break; - case CRM_HICK_READY_INT_FLAG: - if(CRM->clkint_bit.hickstblf && CRM->clkint_bit.hickstblien) - { - status = SET; - } - break; - case CRM_HEXT_READY_INT_FLAG: - if(CRM->clkint_bit.hextstblf && CRM->clkint_bit.hextstblien) - { - status = SET; - } - break; - case CRM_PLL_READY_INT_FLAG: - if(CRM->clkint_bit.pllstblf && CRM->clkint_bit.pllstblien) - { - status = SET; - } - break; - case CRM_CLOCK_FAILURE_INT_FLAG: - if(CRM->clkint_bit.cfdf && CRM->ctrl_bit.cfden) - { - status = SET; - } - break; - } +flag_status crm_interrupt_flag_get(uint32_t flag) { + flag_status status = RESET; + switch (flag) { + case CRM_LICK_READY_INT_FLAG: + if (CRM->clkint_bit.lickstblf && CRM->clkint_bit.lickstblien) { + status = SET; + } + break; + case CRM_LEXT_READY_INT_FLAG: + if (CRM->clkint_bit.lextstblf && CRM->clkint_bit.lextstblien) { + status = SET; + } + break; + case CRM_HICK_READY_INT_FLAG: + if (CRM->clkint_bit.hickstblf && CRM->clkint_bit.hickstblien) { + status = SET; + } + break; + case CRM_HEXT_READY_INT_FLAG: + if (CRM->clkint_bit.hextstblf && CRM->clkint_bit.hextstblien) { + status = SET; + } + break; + case CRM_PLL_READY_INT_FLAG: + if (CRM->clkint_bit.pllstblf && CRM->clkint_bit.pllstblien) { + status = SET; + } + break; + case CRM_CLOCK_FAILURE_INT_FLAG: + if (CRM->clkint_bit.cfdf && CRM->ctrl_bit.cfden) { + status = SET; + } + break; + } - return status; + return status; } /** @@ -197,26 +182,21 @@ flag_status crm_interrupt_flag_get(uint32_t flag) * @param none * @retval error_status (ERROR or SUCCESS) */ -error_status crm_hext_stable_wait(void) -{ - uint32_t stable_cnt = 0; - error_status status = ERROR; +error_status crm_hext_stable_wait(void) { + uint32_t stable_cnt = 0; + error_status status = ERROR; - while((crm_flag_get(CRM_HEXT_STABLE_FLAG) != SET) && (stable_cnt < HEXT_STARTUP_TIMEOUT)) - { - stable_cnt ++; - } + while ((crm_flag_get(CRM_HEXT_STABLE_FLAG) != SET) && (stable_cnt < HEXT_STARTUP_TIMEOUT)) { + stable_cnt ++; + } - if(crm_flag_get(CRM_HEXT_STABLE_FLAG) != SET) - { - status = ERROR; - } - else - { - status = SUCCESS; - } + if (crm_flag_get(CRM_HEXT_STABLE_FLAG) != SET) { + status = ERROR; + } else { + status = SUCCESS; + } - return status; + return status; } /** @@ -224,9 +204,8 @@ error_status crm_hext_stable_wait(void) * @param trim_value (0x00~0x3F) * @retval none */ -void crm_hick_clock_trimming_set(uint8_t trim_value) -{ - CRM->ctrl_bit.hicktrim = trim_value; +void crm_hick_clock_trimming_set(uint8_t trim_value) { + CRM->ctrl_bit.hicktrim = trim_value; } /** @@ -234,16 +213,15 @@ void crm_hick_clock_trimming_set(uint8_t trim_value) * @param cali_value (0x00~0xFF) * @retval none */ -void crm_hick_clock_calibration_set(uint8_t cali_value) -{ - /* enable write hick calibration */ - CRM->misc1_bit.hickcal_key = 0x5A; +void crm_hick_clock_calibration_set(uint8_t cali_value) { + /* enable write hick calibration */ + CRM->misc1_bit.hickcal_key = 0x5A; - /* write hick calibration value */ - CRM->ctrl_bit.hickcal = cali_value; + /* write hick calibration value */ + CRM->ctrl_bit.hickcal = cali_value; - /* disable write hick calibration */ - CRM->misc1_bit.hickcal_key = 0x0; + /* disable write hick calibration */ + CRM->misc1_bit.hickcal_key = 0x0; } /** @@ -269,18 +247,15 @@ void crm_hick_clock_calibration_set(uint8_t cali_value) * @param new_state (TRUE or FALSE) * @retval none */ -void crm_periph_clock_enable(crm_periph_clock_type value, confirm_state new_state) -{ - /* enable periph clock */ - if(TRUE == new_state) - { - CRM_REG(value) |= CRM_REG_BIT(value); - } - /* disable periph clock */ - else - { - CRM_REG(value) &= ~(CRM_REG_BIT(value)); - } +void crm_periph_clock_enable(crm_periph_clock_type value, confirm_state new_state) { + /* enable periph clock */ + if (TRUE == new_state) { + CRM_REG(value) |= CRM_REG_BIT(value); + } + /* disable periph clock */ + else { + CRM_REG(value) &= ~(CRM_REG_BIT(value)); + } } /** @@ -305,18 +280,15 @@ void crm_periph_clock_enable(crm_periph_clock_type value, confirm_state new_stat * @param new_state (TRUE or FALSE) * @retval none */ -void crm_periph_reset(crm_periph_reset_type value, confirm_state new_state) -{ - /* enable periph reset */ - if(new_state == TRUE) - { - CRM_REG(value) |= (CRM_REG_BIT(value)); - } - /* disable periph reset */ - else - { - CRM_REG(value) &= ~(CRM_REG_BIT(value)); - } +void crm_periph_reset(crm_periph_reset_type value, confirm_state new_state) { + /* enable periph reset */ + if (new_state == TRUE) { + CRM_REG(value) |= (CRM_REG_BIT(value)); + } + /* disable periph reset */ + else { + CRM_REG(value) &= ~(CRM_REG_BIT(value)); + } } /** @@ -343,18 +315,15 @@ void crm_periph_reset(crm_periph_reset_type value, confirm_state new_state) * @param new_state (TRUE or FALSE) * @retval none */ -void crm_periph_lowpower_mode_enable(crm_periph_clock_lowpower_type value, confirm_state new_state) -{ - /* enable periph clock in lowpower mode */ - if(new_state == TRUE) - { - CRM_REG(value) |= (CRM_REG_BIT(value)); - } - /* disable periph clock in lowpower mode */ - else - { - CRM_REG(value) &= ~(CRM_REG_BIT(value)); - } +void crm_periph_lowpower_mode_enable(crm_periph_clock_lowpower_type value, confirm_state new_state) { + /* enable periph clock in lowpower mode */ + if (new_state == TRUE) { + CRM_REG(value) |= (CRM_REG_BIT(value)); + } + /* disable periph clock in lowpower mode */ + else { + CRM_REG(value) &= ~(CRM_REG_BIT(value)); + } } /** @@ -369,27 +338,26 @@ void crm_periph_lowpower_mode_enable(crm_periph_clock_lowpower_type value, confi * @param new_state (TRUE or FALSE) * @retval none */ -void crm_clock_source_enable(crm_clock_source_type source, confirm_state new_state) -{ - switch(source) - { - case CRM_CLOCK_SOURCE_HICK: - CRM->ctrl_bit.hicken = new_state; - break; - case CRM_CLOCK_SOURCE_HEXT: - CRM->ctrl_bit.hexten = new_state; - break; - case CRM_CLOCK_SOURCE_PLL: - CRM->ctrl_bit.pllen = new_state; - break; - case CRM_CLOCK_SOURCE_LEXT: - CRM->bpdc_bit.lexten = new_state; - break; - case CRM_CLOCK_SOURCE_LICK: - CRM->ctrlsts_bit.licken = new_state; - break; - default: break; - } +void crm_clock_source_enable(crm_clock_source_type source, confirm_state new_state) { + switch (source) { + case CRM_CLOCK_SOURCE_HICK: + CRM->ctrl_bit.hicken = new_state; + break; + case CRM_CLOCK_SOURCE_HEXT: + CRM->ctrl_bit.hexten = new_state; + break; + case CRM_CLOCK_SOURCE_PLL: + CRM->ctrl_bit.pllen = new_state; + break; + case CRM_CLOCK_SOURCE_LEXT: + CRM->bpdc_bit.lexten = new_state; + break; + case CRM_CLOCK_SOURCE_LICK: + CRM->ctrlsts_bit.licken = new_state; + break; + default: + break; + } } /** @@ -413,41 +381,39 @@ void crm_clock_source_enable(crm_clock_source_type source, confirm_state new_sta * - CRM_CLOCK_FAILURE_INT_FLAG * @retval none */ -void crm_flag_clear(uint32_t flag) -{ - switch(flag) - { - case CRM_NRST_RESET_FLAG: - case CRM_POR_RESET_FLAG: - case CRM_SW_RESET_FLAG: - case CRM_WDT_RESET_FLAG: - case CRM_WWDT_RESET_FLAG: - case CRM_LOWPOWER_RESET_FLAG: - case CRM_ALL_RESET_FLAG: - CRM->ctrlsts_bit.rstfc = TRUE; - while(CRM->ctrlsts_bit.rstfc == TRUE); - break; - case CRM_LICK_READY_INT_FLAG: - CRM->clkint_bit.lickstblfc = TRUE; - break; - case CRM_LEXT_READY_INT_FLAG: - CRM->clkint_bit.lextstblfc = TRUE; - break; - case CRM_HICK_READY_INT_FLAG: - CRM->clkint_bit.hickstblfc = TRUE; - break; - case CRM_HEXT_READY_INT_FLAG: - CRM->clkint_bit.hextstblfc = TRUE; - break; - case CRM_PLL_READY_INT_FLAG: - CRM->clkint_bit.pllstblfc = TRUE; - break; - case CRM_CLOCK_FAILURE_INT_FLAG: - CRM->clkint_bit.cfdfc = TRUE; - break; - default: - break; - } +void crm_flag_clear(uint32_t flag) { + switch (flag) { + case CRM_NRST_RESET_FLAG: + case CRM_POR_RESET_FLAG: + case CRM_SW_RESET_FLAG: + case CRM_WDT_RESET_FLAG: + case CRM_WWDT_RESET_FLAG: + case CRM_LOWPOWER_RESET_FLAG: + case CRM_ALL_RESET_FLAG: + CRM->ctrlsts_bit.rstfc = TRUE; + while (CRM->ctrlsts_bit.rstfc == TRUE); + break; + case CRM_LICK_READY_INT_FLAG: + CRM->clkint_bit.lickstblfc = TRUE; + break; + case CRM_LEXT_READY_INT_FLAG: + CRM->clkint_bit.lextstblfc = TRUE; + break; + case CRM_HICK_READY_INT_FLAG: + CRM->clkint_bit.hickstblfc = TRUE; + break; + case CRM_HEXT_READY_INT_FLAG: + CRM->clkint_bit.hextstblfc = TRUE; + break; + case CRM_PLL_READY_INT_FLAG: + CRM->clkint_bit.pllstblfc = TRUE; + break; + case CRM_CLOCK_FAILURE_INT_FLAG: + CRM->clkint_bit.cfdfc = TRUE; + break; + default: + break; + } } /** @@ -489,10 +455,9 @@ void crm_flag_clear(uint32_t flag) * - CRM_ERTC_CLOCK_HEXT_DIV_31 * @retval none */ -void crm_ertc_clock_select(crm_ertc_clock_type value) -{ - CRM->cfg_bit.ertcdiv = ((value & 0x1F0) >> 4); - CRM->bpdc_bit.ertcsel = (value & 0xF); +void crm_ertc_clock_select(crm_ertc_clock_type value) { + CRM->cfg_bit.ertcdiv = ((value & 0x1F0) >> 4); + CRM->bpdc_bit.ertcsel = (value & 0xF); } /** @@ -500,9 +465,8 @@ void crm_ertc_clock_select(crm_ertc_clock_type value) * @param new_state (TRUE or FALSE) * @retval none */ -void crm_ertc_clock_enable(confirm_state new_state) -{ - CRM->bpdc_bit.ertcen = new_state; +void crm_ertc_clock_enable(confirm_state new_state) { + CRM->bpdc_bit.ertcen = new_state; } /** @@ -520,9 +484,8 @@ void crm_ertc_clock_enable(confirm_state new_state) * - CRM_AHB_DIV_512 * @retval none */ -void crm_ahb_div_set(crm_ahb_div_type value) -{ - CRM->cfg_bit.ahbdiv = value; +void crm_ahb_div_set(crm_ahb_div_type value) { + CRM->cfg_bit.ahbdiv = value; } /** @@ -537,9 +500,8 @@ void crm_ahb_div_set(crm_ahb_div_type value) * - CRM_APB1_DIV_16 * @retval none */ -void crm_apb1_div_set(crm_apb1_div_type value) -{ - CRM->cfg_bit.apb1div = value; +void crm_apb1_div_set(crm_apb1_div_type value) { + CRM->cfg_bit.apb1div = value; } /** @@ -554,9 +516,8 @@ void crm_apb1_div_set(crm_apb1_div_type value) * - CRM_APB2_DIV_16 * @retval none */ -void crm_apb2_div_set(crm_apb2_div_type value) -{ - CRM->cfg_bit.apb2div = value; +void crm_apb2_div_set(crm_apb2_div_type value) { + CRM->cfg_bit.apb2div = value; } /** @@ -578,8 +539,7 @@ void crm_apb2_div_set(crm_apb2_div_type value) * - CRM_USB_DIV_7 * @retval none */ -void crm_usb_clock_div_set(crm_usb_div_type value) -{ +void crm_usb_clock_div_set(crm_usb_div_type value) { CRM->misc2_bit.usbdiv = value; } @@ -588,9 +548,8 @@ void crm_usb_clock_div_set(crm_usb_div_type value) * @param new_state (TRUE or FALSE) * @retval none */ -void crm_clock_failure_detection_enable(confirm_state new_state) -{ - CRM->ctrl_bit.cfden = new_state; +void crm_clock_failure_detection_enable(confirm_state new_state) { + CRM->ctrl_bit.cfden = new_state; } /** @@ -598,9 +557,8 @@ void crm_clock_failure_detection_enable(confirm_state new_state) * @param new_state (TRUE or FALSE) * @retval none */ -void crm_battery_powered_domain_reset(confirm_state new_state) -{ - CRM->bpdc_bit.bpdrst = new_state; +void crm_battery_powered_domain_reset(confirm_state new_state) { + CRM->bpdc_bit.bpdrst = new_state; } /** @@ -608,12 +566,11 @@ void crm_battery_powered_domain_reset(confirm_state new_state) * @param new_state (TRUE or FALSE) * @retval none */ -void crm_auto_step_mode_enable(confirm_state new_state) -{ - if(new_state == TRUE) - CRM->misc2_bit.auto_step_en = CRM_AUTO_STEP_MODE_ENABLE; - else - CRM->misc2_bit.auto_step_en = CRM_AUTO_STEP_MODE_DISABLE; +void crm_auto_step_mode_enable(confirm_state new_state) { + if (new_state == TRUE) + CRM->misc2_bit.auto_step_en = CRM_AUTO_STEP_MODE_ENABLE; + else + CRM->misc2_bit.auto_step_en = CRM_AUTO_STEP_MODE_DISABLE; } /** @@ -624,9 +581,8 @@ void crm_auto_step_mode_enable(confirm_state new_state) * - CRM_HICK48_NODIV * @retval none */ -void crm_hick_divider_select(crm_hick_div_6_type value) -{ - CRM->misc1_bit.hickdiv = value; +void crm_hick_divider_select(crm_hick_div_6_type value) { + CRM->misc1_bit.hickdiv = value; } /** @@ -637,10 +593,9 @@ void crm_hick_divider_select(crm_hick_div_6_type value) * - CRM_HICK_SCLK_48MHZ * @retval none */ -void crm_hick_sclk_frequency_select(crm_hick_sclk_frequency_type value) -{ - crm_hick_divider_select(CRM_HICK48_NODIV); - CRM->misc1_bit.hick_to_sclk = value; +void crm_hick_sclk_frequency_select(crm_hick_sclk_frequency_type value) { + crm_hick_divider_select(CRM_HICK48_NODIV); + CRM->misc1_bit.hick_to_sclk = value; } /** @@ -651,13 +606,11 @@ void crm_hick_sclk_frequency_select(crm_hick_sclk_frequency_type value) * - CRM_USB_CLOCK_SOURCE_HICK * @retval none */ -void crm_usb_clock_source_select(crm_usb_clock_source_type value) -{ - if(value == CRM_USB_CLOCK_SOURCE_HICK) - { - crm_hick_sclk_frequency_select(CRM_HICK_SCLK_48MHZ); - } - CRM->misc1_bit.hick_to_usb = value; +void crm_usb_clock_source_select(crm_usb_clock_source_type value) { + if (value == CRM_USB_CLOCK_SOURCE_HICK) { + crm_hick_sclk_frequency_select(CRM_HICK_SCLK_48MHZ); + } + CRM->misc1_bit.hick_to_usb = value; } /** @@ -665,9 +618,8 @@ void crm_usb_clock_source_select(crm_usb_clock_source_type value) * @param new_state (TRUE or FALSE) * @retval none */ -void crm_clkout_to_tmr10_enable(confirm_state new_state) -{ - CRM->misc2_bit.clk_to_tmr = new_state; +void crm_clkout_to_tmr10_enable(confirm_state new_state) { + CRM->misc2_bit.clk_to_tmr = new_state; } /** @@ -703,19 +655,17 @@ void crm_clkout_to_tmr10_enable(confirm_state new_state) * @retval none */ void crm_pll_config(crm_pll_clock_source_type clock_source, uint16_t pll_ns, \ - uint16_t pll_ms, crm_pll_fr_type pll_fr) -{ - /* config pll clock source */ - if(clock_source == CRM_PLL_SOURCE_HICK) - { - CRM->misc1_bit.hickdiv = CRM_HICK48_NODIV; - } - CRM->pllcfg_bit.pllrcs = clock_source; + uint16_t pll_ms, crm_pll_fr_type pll_fr) { + /* config pll clock source */ + if (clock_source == CRM_PLL_SOURCE_HICK) { + CRM->misc1_bit.hickdiv = CRM_HICK48_NODIV; + } + CRM->pllcfg_bit.pllrcs = clock_source; - /* config pll multiplication factor */ - CRM->pllcfg_bit.pllns = pll_ns; - CRM->pllcfg_bit.pllms = pll_ms; - CRM->pllcfg_bit.pllfr = pll_fr; + /* config pll multiplication factor */ + CRM->pllcfg_bit.pllns = pll_ns; + CRM->pllcfg_bit.pllms = pll_ms; + CRM->pllcfg_bit.pllfr = pll_fr; } /** @@ -727,10 +677,9 @@ void crm_pll_config(crm_pll_clock_source_type clock_source, uint16_t pll_ns, \ * - CRM_SCLK_PLL * @retval none */ -void crm_sysclk_switch(crm_sclk_type value) -{ - CRM->cfg_bit.sclksel = value; - DUMMY_NOP(); +void crm_sysclk_switch(crm_sclk_type value) { + CRM->cfg_bit.sclksel = value; + DUMMY_NOP(); } /** @@ -742,9 +691,8 @@ void crm_sysclk_switch(crm_sclk_type value) * - CRM_SCLK_HEXT * - CRM_SCLK_PLL */ -crm_sclk_type crm_sysclk_switch_status_get(void) -{ - return (crm_sclk_type)CRM->cfg_bit.sclksts; +crm_sclk_type crm_sysclk_switch_status_get(void) { + return (crm_sclk_type)CRM->cfg_bit.sclksts; } /** @@ -753,86 +701,81 @@ crm_sclk_type crm_sysclk_switch_status_get(void) * - pointer to the crm_clocks_freq_type structure * @retval none */ -void crm_clocks_freq_get(crm_clocks_freq_type *clocks_struct) -{ - uint32_t pll_ns = 0, pll_ms = 0, pll_fr = 0, pll_clock_source = 0, pllrcsfreq = 0; - uint32_t temp = 0, div_value = 0; - crm_sclk_type sclk_source; +void crm_clocks_freq_get(crm_clocks_freq_type *clocks_struct) { + uint32_t pll_ns = 0, pll_ms = 0, pll_fr = 0, pll_clock_source = 0, pllrcsfreq = 0; + uint32_t temp = 0, div_value = 0; + crm_sclk_type sclk_source; - static const uint8_t sclk_ahb_div_table[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9}; - static const uint8_t ahb_apb1_div_table[8] = {0, 0, 0, 0, 1, 2, 3, 4}; - static const uint8_t ahb_apb2_div_table[8] = {0, 0, 0, 0, 1, 2, 3, 4}; - static const uint8_t pll_fr_table[6] = {1, 2, 4, 8, 16, 32}; + static const uint8_t sclk_ahb_div_table[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9}; + static const uint8_t ahb_apb1_div_table[8] = {0, 0, 0, 0, 1, 2, 3, 4}; + static const uint8_t ahb_apb2_div_table[8] = {0, 0, 0, 0, 1, 2, 3, 4}; + static const uint8_t pll_fr_table[6] = {1, 2, 4, 8, 16, 32}; - /* get sclk source */ - sclk_source = crm_sysclk_switch_status_get(); + /* get sclk source */ + sclk_source = crm_sysclk_switch_status_get(); - switch(sclk_source) - { - case CRM_SCLK_HICK: - if(((CRM->misc1_bit.hick_to_sclk) != RESET) && ((CRM->misc1_bit.hickdiv) != RESET)) - clocks_struct->sclk_freq = HICK_VALUE * 6; - else - clocks_struct->sclk_freq = HICK_VALUE; - break; - case CRM_SCLK_HEXT: - clocks_struct->sclk_freq = HEXT_VALUE; - break; - case CRM_SCLK_PLL: - /* get pll clock source */ - pll_clock_source = CRM->pllcfg_bit.pllrcs; + switch (sclk_source) { + case CRM_SCLK_HICK: + if (((CRM->misc1_bit.hick_to_sclk) != RESET) && ((CRM->misc1_bit.hickdiv) != RESET)) + clocks_struct->sclk_freq = HICK_VALUE * 6; + else + clocks_struct->sclk_freq = HICK_VALUE; + break; + case CRM_SCLK_HEXT: + clocks_struct->sclk_freq = HEXT_VALUE; + break; + case CRM_SCLK_PLL: + /* get pll clock source */ + pll_clock_source = CRM->pllcfg_bit.pllrcs; - /* get multiplication factor */ - pll_ns = CRM->pllcfg_bit.pllns; - pll_ms = CRM->pllcfg_bit.pllms; - pll_fr = pll_fr_table[CRM->pllcfg_bit.pllfr]; + /* get multiplication factor */ + pll_ns = CRM->pllcfg_bit.pllns; + pll_ms = CRM->pllcfg_bit.pllms; + pll_fr = pll_fr_table[CRM->pllcfg_bit.pllfr]; - if (pll_clock_source == CRM_PLL_SOURCE_HICK) - { - /* hick selected as pll clock entry */ - pllrcsfreq = HICK_VALUE; - } - else - { - /* hext selected as pll clock entry */ - pllrcsfreq = HEXT_VALUE; - } + if (pll_clock_source == CRM_PLL_SOURCE_HICK) { + /* hick selected as pll clock entry */ + pllrcsfreq = HICK_VALUE; + } else { + /* hext selected as pll clock entry */ + pllrcsfreq = HEXT_VALUE; + } - // TODO DXL For fix error: undefined reference to `__aeabi_uldivmod' - // 1. After code review, I found that pll_ns generally does not exceed 144, that is, it can be treated as u32. - // However, for the robustness of firmware, we still need to make error judgments. - if (pllrcsfreq * pll_ns > UINT32_MAX) { - while (1) { - __NOP(); // !!! Fix me !!! - } - } - clocks_struct->sclk_freq = pllrcsfreq * pll_ns / (pll_ms * pll_fr); - // 2. If u64 division is necessary, it is better to link to gcc(-lgcc), but the firmware size will increase. - // clocks_struct->sclk_freq = (uint32_t)(((uint64_t)pllrcsfreq * pll_ns) / (pll_ms * pll_fr)); - break; - default: - clocks_struct->sclk_freq = HICK_VALUE; - break; - } + // TODO DXL For fix error: undefined reference to `__aeabi_uldivmod' + // 1. After code review, I found that pll_ns generally does not exceed 144, that is, it can be treated as u32. + // However, for the robustness of firmware, we still need to make error judgments. + if (pllrcsfreq * pll_ns > UINT32_MAX) { + while (1) { + __NOP(); // !!! Fix me !!! + } + } + clocks_struct->sclk_freq = pllrcsfreq * pll_ns / (pll_ms * pll_fr); + // 2. If u64 division is necessary, it is better to link to gcc(-lgcc), but the firmware size will increase. + // clocks_struct->sclk_freq = (uint32_t)(((uint64_t)pllrcsfreq * pll_ns) / (pll_ms * pll_fr)); + break; + default: + clocks_struct->sclk_freq = HICK_VALUE; + break; + } - /* compute sclk, ahbclk, abp1clk and apb2clk frequencies */ - /* get ahb division */ - temp = CRM->cfg_bit.ahbdiv; - div_value = sclk_ahb_div_table[temp]; - /* ahbclk frequency */ - clocks_struct->ahb_freq = clocks_struct->sclk_freq >> div_value; + /* compute sclk, ahbclk, abp1clk and apb2clk frequencies */ + /* get ahb division */ + temp = CRM->cfg_bit.ahbdiv; + div_value = sclk_ahb_div_table[temp]; + /* ahbclk frequency */ + clocks_struct->ahb_freq = clocks_struct->sclk_freq >> div_value; - /* get apb1 division */ - temp = CRM->cfg_bit.apb1div; - div_value = ahb_apb1_div_table[temp]; - /* apb1clk frequency */ - clocks_struct->apb1_freq = clocks_struct->ahb_freq >> div_value; + /* get apb1 division */ + temp = CRM->cfg_bit.apb1div; + div_value = ahb_apb1_div_table[temp]; + /* apb1clk frequency */ + clocks_struct->apb1_freq = clocks_struct->ahb_freq >> div_value; - /* get apb2 division */ - temp = CRM->cfg_bit.apb2div; - div_value = ahb_apb2_div_table[temp]; - /* apb2clk frequency */ - clocks_struct->apb2_freq = clocks_struct->ahb_freq >> div_value; + /* get apb2 division */ + temp = CRM->cfg_bit.apb2div; + div_value = ahb_apb2_div_table[temp]; + /* apb2clk frequency */ + clocks_struct->apb2_freq = clocks_struct->ahb_freq >> div_value; } /** @@ -845,8 +788,7 @@ void crm_clocks_freq_get(crm_clocks_freq_type *clocks_struct) * - CRM_CLKOUT1_PLL * @retval none */ -void crm_clock_out1_set(crm_clkout1_select_type clkout) -{ +void crm_clock_out1_set(crm_clkout1_select_type clkout) { CRM->cfg_bit.clkout1_sel = clkout; } @@ -864,17 +806,13 @@ void crm_clock_out1_set(crm_clkout1_select_type clkout) * - CRM_CLKOUT2_LEXT * @retval none */ -void crm_clock_out2_set(crm_clkout2_select_type clkout) -{ - if(clkout < 0x10) - { - CRM->cfg_bit.clkout2_sel1 = (clkout & 0x3); - } - else - { - CRM->cfg_bit.clkout2_sel1 = 0x1; - CRM->misc1_bit.clkout2_sel2 = (clkout & 0xF); - } +void crm_clock_out2_set(crm_clkout2_select_type clkout) { + if (clkout < 0x10) { + CRM->cfg_bit.clkout2_sel1 = (clkout & 0x3); + } else { + CRM->cfg_bit.clkout2_sel1 = 0x1; + CRM->misc1_bit.clkout2_sel2 = (clkout & 0xF); + } } /** @@ -903,18 +841,14 @@ void crm_clock_out2_set(crm_clkout2_select_type clkout) * - CRM_CLKOUT_DIV2_512 * @retval none */ -void crm_clkout_div_set(crm_clkout_index_type index, crm_clkout_div1_type div1, crm_clkout_div2_type div2) -{ - if(index == CRM_CLKOUT_INDEX_1) - { - CRM->cfg_bit.clkout1div1 = div1; - CRM->misc1_bit.clkout1div2 = div2; - } - else - { - CRM->cfg_bit.clkout2div1 = div1; - CRM->misc1_bit.clkout2div2 = div2; - } +void crm_clkout_div_set(crm_clkout_index_type index, crm_clkout_div1_type div1, crm_clkout_div2_type div2) { + if (index == CRM_CLKOUT_INDEX_1) { + CRM->cfg_bit.clkout1div1 = div1; + CRM->misc1_bit.clkout1div2 = div2; + } else { + CRM->cfg_bit.clkout2div1 = div1; + CRM->misc1_bit.clkout2div2 = div2; + } } /** @@ -925,9 +859,8 @@ void crm_clkout_div_set(crm_clkout_index_type index, crm_clkout_div1_type div1, * - CRM_EMAC_PULSE_1SCLK * @retval none */ -void crm_emac_output_pulse_set(crm_emac_output_pulse_type width) -{ - CRM->misc2_bit.emac_pps_sel = width; +void crm_emac_output_pulse_set(crm_emac_output_pulse_type width) { + CRM->misc2_bit.emac_pps_sel = width; } /** @@ -942,12 +875,11 @@ void crm_emac_output_pulse_set(crm_emac_output_pulse_type width) * @param new_state (TRUE or FALSE) * @retval none */ -void crm_interrupt_enable(uint32_t crm_int, confirm_state new_state) -{ - if(TRUE == new_state) - CRM->clkint |= crm_int; - else - CRM->clkint &= ~crm_int; +void crm_interrupt_enable(uint32_t crm_int, confirm_state new_state) { + if (TRUE == new_state) + CRM->clkint |= crm_int; + else + CRM->clkint &= ~crm_int; } /** @@ -977,73 +909,64 @@ void crm_interrupt_enable(uint32_t crm_int, confirm_state new_state) * @retval error_status (SUCCESS or ERROR) */ error_status crm_pll_parameter_calculate(crm_pll_clock_source_type pll_rcs, uint32_t target_sclk_freq, \ - uint16_t *ret_ms, uint16_t *ret_ns, uint16_t *ret_fr) -{ - uint32_t error_min = 0xFFFFFFFF; - uint32_t pll_rcs_freq = 0, result = 0, absolute_value = 0; - uint16_t ns = 0, ms = 0, ms_min = 0, ms_max = 0; - int16_t fr = 0; + uint16_t *ret_ms, uint16_t *ret_ns, uint16_t *ret_fr) { + uint32_t error_min = 0xFFFFFFFF; + uint32_t pll_rcs_freq = 0, result = 0, absolute_value = 0; + uint16_t ns = 0, ms = 0, ms_min = 0, ms_max = 0; + int16_t fr = 0; - /* reduce calculate accuracy, target_sclk_freq accuracy with khz */ - target_sclk_freq = target_sclk_freq / 1000; + /* reduce calculate accuracy, target_sclk_freq accuracy with khz */ + target_sclk_freq = target_sclk_freq / 1000; - /* get pll reference clock frequency, accuracy with khz */ - if(pll_rcs == CRM_PLL_SOURCE_HICK) - pll_rcs_freq = HICK_VALUE / 1000; - else - pll_rcs_freq = HEXT_VALUE / 1000; + /* get pll reference clock frequency, accuracy with khz */ + if (pll_rcs == CRM_PLL_SOURCE_HICK) + pll_rcs_freq = HICK_VALUE / 1000; + else + pll_rcs_freq = HEXT_VALUE / 1000; - /* polling ms range, accuracy with khz */ - for(ms = 1; ms <= 15; ms ++) - { - result = pll_rcs_freq / ms; - if((result >= 2000U) && (result <= 16000U)) - { - if(ms_min == 0) - ms_min = ms; + /* polling ms range, accuracy with khz */ + for (ms = 1; ms <= 15; ms ++) { + result = pll_rcs_freq / ms; + if ((result >= 2000U) && (result <= 16000U)) { + if (ms_min == 0) + ms_min = ms; - ms_max = ms; + ms_max = ms; + } } - } - /* polling pll parameters */ - for(ms = ms_min; ms <= ms_max; ms ++) - { - for(fr = 5; fr >= 0; fr --) - { - for(ns = 31; ns <= 500; ns ++) - { - result = (pll_rcs_freq * ns) / (ms); - /* check vco frequency range, accuracy with khz */ - if((result < 500000U) || (result > 1200000U)) - { - continue; + /* polling pll parameters */ + for (ms = ms_min; ms <= ms_max; ms ++) { + for (fr = 5; fr >= 0; fr --) { + for (ns = 31; ns <= 500; ns ++) { + result = (pll_rcs_freq * ns) / (ms); + /* check vco frequency range, accuracy with khz */ + if ((result < 500000U) || (result > 1200000U)) { + continue; + } + /* calculate pll output frequency */ + result = result / (0x1 << fr); + /* check frequency */ + if (target_sclk_freq == result) { + *ret_ms = ms; + *ret_ns = ns; + *ret_fr = (uint16_t)fr; + /* the pll parameters that is equal to target_sclk_freq */ + return SUCCESS; + } + /* calculate error range, accuracy with khz */ + absolute_value = (result > target_sclk_freq) ? (result - target_sclk_freq) : (target_sclk_freq - result); + if (absolute_value < error_min) { + error_min = absolute_value; + *ret_ms = ms; + *ret_ns = ns; + *ret_fr = (uint16_t)fr; + } + } } - /* calculate pll output frequency */ - result = result / (0x1 << fr); - /* check frequency */ - if(target_sclk_freq == result) - { - *ret_ms = ms; - *ret_ns = ns; - *ret_fr = (uint16_t)fr; - /* the pll parameters that is equal to target_sclk_freq */ - return SUCCESS; - } - /* calculate error range, accuracy with khz */ - absolute_value = (result > target_sclk_freq) ? (result - target_sclk_freq) : (target_sclk_freq - result); - if(absolute_value < error_min) - { - error_min = absolute_value; - *ret_ms = ms; - *ret_ns = ns; - *ret_fr = (uint16_t)fr; - } - } } - } - /* the pll parameters that is the closest approach to target_sclk_freq */ - return ERROR; + /* the pll parameters that is the closest approach to target_sclk_freq */ + return ERROR; } /** diff --git a/armlib/at32_sys/drivers/src/at32f435_437_dac.c b/armlib/at32_sys/drivers/src/at32f435_437_dac.c index 7609200ef..f8eef6ab5 100644 --- a/armlib/at32_sys/drivers/src/at32f435_437_dac.c +++ b/armlib/at32_sys/drivers/src/at32f435_437_dac.c @@ -46,10 +46,9 @@ * @param none * @retval none */ -void dac_reset(void) -{ - crm_periph_reset(CRM_DAC_PERIPH_RESET, TRUE); - crm_periph_reset(CRM_DAC_PERIPH_RESET, FALSE); +void dac_reset(void) { + crm_periph_reset(CRM_DAC_PERIPH_RESET, TRUE); + crm_periph_reset(CRM_DAC_PERIPH_RESET, FALSE); } /** @@ -61,19 +60,17 @@ void dac_reset(void) * @param new_state (TRUE or FALSE) * @retval none */ -void dac_enable(dac_select_type dac_select, confirm_state new_state) -{ - switch(dac_select) - { - case DAC1_SELECT: - DAC->ctrl_bit.d1en = new_state; - break; - case DAC2_SELECT: - DAC->ctrl_bit.d2en = new_state; - break; - default: - break; - } +void dac_enable(dac_select_type dac_select, confirm_state new_state) { + switch (dac_select) { + case DAC1_SELECT: + DAC->ctrl_bit.d1en = new_state; + break; + case DAC2_SELECT: + DAC->ctrl_bit.d2en = new_state; + break; + default: + break; + } } /** @@ -85,20 +82,18 @@ void dac_enable(dac_select_type dac_select, confirm_state new_state) * @param new_state (TRUE or FALSE) * @retval none */ -void dac_output_buffer_enable(dac_select_type dac_select, confirm_state new_state) -{ - new_state = (confirm_state)!new_state; - switch(dac_select) - { - case DAC1_SELECT: - DAC->ctrl_bit.d1obdis = new_state; - break; - case DAC2_SELECT: - DAC->ctrl_bit.d2obdis = new_state; - break; - default: - break; - } +void dac_output_buffer_enable(dac_select_type dac_select, confirm_state new_state) { + new_state = (confirm_state)!new_state; + switch (dac_select) { + case DAC1_SELECT: + DAC->ctrl_bit.d1obdis = new_state; + break; + case DAC2_SELECT: + DAC->ctrl_bit.d2obdis = new_state; + break; + default: + break; + } } /** @@ -110,19 +105,17 @@ void dac_output_buffer_enable(dac_select_type dac_select, confirm_state new_stat * @param new_state (TRUE or FALSE) * @retval none */ -void dac_trigger_enable(dac_select_type dac_select, confirm_state new_state) -{ - switch(dac_select) - { - case DAC1_SELECT: - DAC->ctrl_bit.d1trgen = new_state; - break; - case DAC2_SELECT: - DAC->ctrl_bit.d2trgen = new_state; - break; - default: - break; - } +void dac_trigger_enable(dac_select_type dac_select, confirm_state new_state) { + switch (dac_select) { + case DAC1_SELECT: + DAC->ctrl_bit.d1trgen = new_state; + break; + case DAC2_SELECT: + DAC->ctrl_bit.d2trgen = new_state; + break; + default: + break; + } } /** @@ -143,19 +136,17 @@ void dac_trigger_enable(dac_select_type dac_select, confirm_state new_state) * - DAC_SOFTWARE_TRIGGER * @retval none */ -void dac_trigger_select(dac_select_type dac_select, dac_trigger_type dac_trigger_source) -{ - switch(dac_select) - { - case DAC1_SELECT: - DAC->ctrl_bit.d1trgsel = dac_trigger_source; - break; - case DAC2_SELECT: - DAC->ctrl_bit.d2trgsel = dac_trigger_source; - break; - default: - break; - } +void dac_trigger_select(dac_select_type dac_select, dac_trigger_type dac_trigger_source) { + switch (dac_select) { + case DAC1_SELECT: + DAC->ctrl_bit.d1trgsel = dac_trigger_source; + break; + case DAC2_SELECT: + DAC->ctrl_bit.d2trgsel = dac_trigger_source; + break; + default: + break; + } } /** @@ -166,19 +157,17 @@ void dac_trigger_select(dac_select_type dac_select, dac_trigger_type dac_trigger * - DAC2_SELECT * @retval none */ -void dac_software_trigger_generate(dac_select_type dac_select) -{ - switch(dac_select) - { - case DAC1_SELECT: - DAC->swtrg_bit.d1swtrg = TRUE; - break; - case DAC2_SELECT: - DAC->swtrg_bit.d2swtrg = TRUE; - break; - default: - break; - } +void dac_software_trigger_generate(dac_select_type dac_select) { + switch (dac_select) { + case DAC1_SELECT: + DAC->swtrg_bit.d1swtrg = TRUE; + break; + case DAC2_SELECT: + DAC->swtrg_bit.d2swtrg = TRUE; + break; + default: + break; + } } /** @@ -186,9 +175,8 @@ void dac_software_trigger_generate(dac_select_type dac_select) * @param none * @retval none */ -void dac_dual_software_trigger_generate(void) -{ - DAC->swtrg |= 0x03; +void dac_dual_software_trigger_generate(void) { + DAC->swtrg |= 0x03; } /** @@ -204,19 +192,17 @@ void dac_dual_software_trigger_generate(void) * - DAC_WAVE_GENERATE_TRIANGLE * @retval none */ -void dac_wave_generate(dac_select_type dac_select, dac_wave_type dac_wave) -{ - switch(dac_select) - { - case DAC1_SELECT: - DAC->ctrl_bit.d1nm = dac_wave; - break; - case DAC2_SELECT: - DAC->ctrl_bit.d2nm = dac_wave; - break; - default: - break; - } +void dac_wave_generate(dac_select_type dac_select, dac_wave_type dac_wave) { + switch (dac_select) { + case DAC1_SELECT: + DAC->ctrl_bit.d1nm = dac_wave; + break; + case DAC2_SELECT: + DAC->ctrl_bit.d2nm = dac_wave; + break; + default: + break; + } } /** @@ -241,19 +227,17 @@ void dac_wave_generate(dac_select_type dac_select, dac_wave_type dac_wave) * - DAC_LSFR_BITB0_AMPLITUDE_4095 * @retval none */ -void dac_mask_amplitude_select(dac_select_type dac_select, dac_mask_amplitude_type dac_mask_amplitude) -{ - switch(dac_select) - { - case DAC1_SELECT: - DAC->ctrl_bit.d1nbsel = dac_mask_amplitude; - break; - case DAC2_SELECT: - DAC->ctrl_bit.d2nbsel = dac_mask_amplitude; - break; - default: - break; - } +void dac_mask_amplitude_select(dac_select_type dac_select, dac_mask_amplitude_type dac_mask_amplitude) { + switch (dac_select) { + case DAC1_SELECT: + DAC->ctrl_bit.d1nbsel = dac_mask_amplitude; + break; + case DAC2_SELECT: + DAC->ctrl_bit.d2nbsel = dac_mask_amplitude; + break; + default: + break; + } } /** @@ -265,19 +249,17 @@ void dac_mask_amplitude_select(dac_select_type dac_select, dac_mask_amplitude_ty * @param new_state (TRUE or FALSE) * @retval none */ -void dac_dma_enable(dac_select_type dac_select, confirm_state new_state) -{ - switch(dac_select) - { - case DAC1_SELECT: - DAC->ctrl_bit.d1dmaen = new_state; - break; - case DAC2_SELECT: - DAC->ctrl_bit.d2dmaen = new_state; - break; - default: - break; - } +void dac_dma_enable(dac_select_type dac_select, confirm_state new_state) { + switch (dac_select) { + case DAC1_SELECT: + DAC->ctrl_bit.d1dmaen = new_state; + break; + case DAC2_SELECT: + DAC->ctrl_bit.d2dmaen = new_state; + break; + default: + break; + } } /** @@ -288,21 +270,19 @@ void dac_dma_enable(dac_select_type dac_select, confirm_state new_state) * - DAC2_SELECT * @retval dac channel data output */ -uint16_t dac_data_output_get(dac_select_type dac_select) -{ - uint16_t data_output =0; - switch(dac_select) - { - case DAC1_SELECT: - data_output = DAC->d1odt_bit.d1odt; - break; - case DAC2_SELECT: - data_output = DAC->d2odt_bit.d2odt; - break; - default: - break; - } - return data_output; +uint16_t dac_data_output_get(dac_select_type dac_select) { + uint16_t data_output = 0; + switch (dac_select) { + case DAC1_SELECT: + data_output = DAC->d1odt_bit.d1odt; + break; + case DAC2_SELECT: + data_output = DAC->d2odt_bit.d2odt; + break; + default: + break; + } + return data_output; } /** @@ -315,9 +295,8 @@ uint16_t dac_data_output_get(dac_select_type dac_select) * @param dac1_data :indecate from selected data holding register * @retval none */ -void dac_1_data_set(dac1_aligned_data_type dac1_aligned, uint16_t dac1_data) -{ - *(__IO uint32_t *) dac1_aligned = dac1_data; +void dac_1_data_set(dac1_aligned_data_type dac1_aligned, uint16_t dac1_data) { + *(__IO uint32_t *) dac1_aligned = dac1_data; } /** @@ -330,9 +309,8 @@ void dac_1_data_set(dac1_aligned_data_type dac1_aligned, uint16_t dac1_data) * @param dac2_data :indecate from selected data holding register * @retval none */ -void dac_2_data_set(dac2_aligned_data_type dac2_aligned, uint16_t dac2_data) -{ - *(__IO uint32_t *) dac2_aligned = dac2_data; +void dac_2_data_set(dac2_aligned_data_type dac2_aligned, uint16_t dac2_data) { + *(__IO uint32_t *) dac2_aligned = dac2_data; } /** @@ -346,22 +324,20 @@ void dac_2_data_set(dac2_aligned_data_type dac2_aligned, uint16_t dac2_data) * @param data2 :dac1 channel indecate from selected data holding register * @retval none */ -void dac_dual_data_set(dac_dual_data_type dac_dual, uint16_t data1, uint16_t data2) -{ - switch(dac_dual) - { - case DAC_DUAL_12BIT_RIGHT: - *(__IO uint32_t *) dac_dual = (uint32_t)(data1 | (data2 << 16)); - break; - case DAC_DUAL_12BIT_LEFT: - *(__IO uint32_t *) dac_dual = (uint32_t)(data1 | (data2 << 16)); - break; - case DAC_DUAL_8BIT_RIGHT: - *(__IO uint32_t *) dac_dual = (uint32_t)(data1 | (data2 << 8)); - break; - default: - break; - } +void dac_dual_data_set(dac_dual_data_type dac_dual, uint16_t data1, uint16_t data2) { + switch (dac_dual) { + case DAC_DUAL_12BIT_RIGHT: + *(__IO uint32_t *) dac_dual = (uint32_t)(data1 | (data2 << 16)); + break; + case DAC_DUAL_12BIT_LEFT: + *(__IO uint32_t *) dac_dual = (uint32_t)(data1 | (data2 << 16)); + break; + case DAC_DUAL_8BIT_RIGHT: + *(__IO uint32_t *) dac_dual = (uint32_t)(data1 | (data2 << 8)); + break; + default: + break; + } } /** @@ -373,19 +349,17 @@ void dac_dual_data_set(dac_dual_data_type dac_dual, uint16_t data1, uint16_t dat * @param new_state (TRUE or FALSE) * @retval none */ -void dac_udr_enable(dac_select_type dac_select, confirm_state new_state) -{ - switch(dac_select) - { - case DAC1_SELECT: - DAC->ctrl_bit.d1dmaudrien = new_state; - break; - case DAC2_SELECT: - DAC->ctrl_bit.d2dmaudrien = new_state; - break; - default: - break; - } +void dac_udr_enable(dac_select_type dac_select, confirm_state new_state) { + switch (dac_select) { + case DAC1_SELECT: + DAC->ctrl_bit.d1dmaudrien = new_state; + break; + case DAC2_SELECT: + DAC->ctrl_bit.d2dmaudrien = new_state; + break; + default: + break; + } } /** @@ -396,24 +370,22 @@ void dac_udr_enable(dac_select_type dac_select, confirm_state new_state) * - DAC2_SELECT * @retval the new state of dac udr flag status(SET or RESET). */ -flag_status dac_udr_flag_get(dac_select_type dac_select) -{ - flag_status status = RESET; +flag_status dac_udr_flag_get(dac_select_type dac_select) { + flag_status status = RESET; - switch(dac_select) - { - case DAC1_SELECT: - if(DAC->sts_bit.d1dmaudrf != 0) - status = SET; - break; - case DAC2_SELECT: - if(DAC->sts_bit.d2dmaudrf != 0) - status = SET; - break; - default: - break; - } - return status; + switch (dac_select) { + case DAC1_SELECT: + if (DAC->sts_bit.d1dmaudrf != 0) + status = SET; + break; + case DAC2_SELECT: + if (DAC->sts_bit.d2dmaudrf != 0) + status = SET; + break; + default: + break; + } + return status; } /** @@ -424,24 +396,22 @@ flag_status dac_udr_flag_get(dac_select_type dac_select) * - DAC2_SELECT * @retval the new state of dac udr flag status(SET or RESET). */ -flag_status dac_udr_interrupt_flag_get(dac_select_type dac_select) -{ - flag_status status = RESET; +flag_status dac_udr_interrupt_flag_get(dac_select_type dac_select) { + flag_status status = RESET; - switch(dac_select) - { - case DAC1_SELECT: - if((DAC->sts_bit.d1dmaudrf && DAC->ctrl_bit.d1dmaudrien) != 0) - status = SET; - break; - case DAC2_SELECT: - if((DAC->sts_bit.d2dmaudrf && DAC->ctrl_bit.d2dmaudrien) != 0) - status = SET; - break; - default: - break; - } - return status; + switch (dac_select) { + case DAC1_SELECT: + if ((DAC->sts_bit.d1dmaudrf && DAC->ctrl_bit.d1dmaudrien) != 0) + status = SET; + break; + case DAC2_SELECT: + if ((DAC->sts_bit.d2dmaudrf && DAC->ctrl_bit.d2dmaudrien) != 0) + status = SET; + break; + default: + break; + } + return status; } /** @@ -452,19 +422,17 @@ flag_status dac_udr_interrupt_flag_get(dac_select_type dac_select) * - DAC2_SELECT * @retval none */ -void dac_udr_flag_clear(dac_select_type dac_select) -{ - switch(dac_select) - { - case DAC1_SELECT: - DAC->sts = DAC1_D1DMAUDRF; - break; - case DAC2_SELECT: - DAC->sts = DAC2_D2DMAUDRF; - break; - default: - break; - } +void dac_udr_flag_clear(dac_select_type dac_select) { + switch (dac_select) { + case DAC1_SELECT: + DAC->sts = DAC1_D1DMAUDRF; + break; + case DAC2_SELECT: + DAC->sts = DAC2_D2DMAUDRF; + break; + default: + break; + } } /** diff --git a/armlib/at32_sys/drivers/src/at32f435_437_debug.c b/armlib/at32_sys/drivers/src/at32f435_437_debug.c index ec7b3202f..eb33b1cb5 100644 --- a/armlib/at32_sys/drivers/src/at32f435_437_debug.c +++ b/armlib/at32_sys/drivers/src/at32f435_437_debug.c @@ -45,9 +45,8 @@ * @param none * @retval the debug device id */ -uint32_t debug_device_id_get(void) -{ - return DEBUGMCU->pid; +uint32_t debug_device_id_get(void) { + return DEBUGMCU->pid; } /** * @brief set periph debug mode @@ -59,16 +58,12 @@ uint32_t debug_device_id_get(void) * @param new_state (TRUE or FALSE) * @retval none */ -void debug_low_power_mode_set(uint32_t low_power_mode, confirm_state new_state) -{ - if(new_state != FALSE) - { - DEBUGMCU->ctrl |= low_power_mode; - } - else - { - DEBUGMCU->ctrl &= ~low_power_mode; - } +void debug_low_power_mode_set(uint32_t low_power_mode, confirm_state new_state) { + if (new_state != FALSE) { + DEBUGMCU->ctrl |= low_power_mode; + } else { + DEBUGMCU->ctrl &= ~low_power_mode; + } } /** * @brief set apb1 periph debug mode @@ -86,16 +81,12 @@ void debug_low_power_mode_set(uint32_t low_power_mode, confirm_state new_state) * @param new_state (TRUE or FALSE) * @retval none */ -void debug_apb1_periph_mode_set(uint32_t apb1_periph, confirm_state new_state) -{ - if(new_state != FALSE) - { - DEBUGMCU->apb1_frz |= apb1_periph; - } - else - { - DEBUGMCU->apb1_frz &= ~apb1_periph; - } +void debug_apb1_periph_mode_set(uint32_t apb1_periph, confirm_state new_state) { + if (new_state != FALSE) { + DEBUGMCU->apb1_frz |= apb1_periph; + } else { + DEBUGMCU->apb1_frz &= ~apb1_periph; + } } /** * @brief set apb2 periph debug mode @@ -107,16 +98,12 @@ void debug_apb1_periph_mode_set(uint32_t apb1_periph, confirm_state new_state) * @param new_state (TRUE or FALSE) * @retval none */ -void debug_apb2_periph_mode_set(uint32_t apb2_periph, confirm_state new_state) -{ - if(new_state != FALSE) - { - DEBUGMCU->apb2_frz |= apb2_periph; - } - else - { - DEBUGMCU->apb2_frz &= ~apb2_periph; - } +void debug_apb2_periph_mode_set(uint32_t apb2_periph, confirm_state new_state) { + if (new_state != FALSE) { + DEBUGMCU->apb2_frz |= apb2_periph; + } else { + DEBUGMCU->apb2_frz &= ~apb2_periph; + } } /** diff --git a/armlib/at32_sys/drivers/src/at32f435_437_dma.c b/armlib/at32_sys/drivers/src/at32f435_437_dma.c index 191fe2804..3694e1e7d 100644 --- a/armlib/at32_sys/drivers/src/at32f435_437_dma.c +++ b/armlib/at32_sys/drivers/src/at32f435_437_dma.c @@ -60,27 +60,23 @@ * - DMA2_CHANNEL7 * @retval none. */ -void dma_reset(dma_channel_type *dmax_channely) -{ - uint32_t temp = 0; - dmax_channely->ctrl_bit.chen = FALSE; - dmax_channely->ctrl = 0; - dmax_channely->dtcnt = 0; - dmax_channely->paddr = 0; - dmax_channely->maddr = 0; +void dma_reset(dma_channel_type *dmax_channely) { + uint32_t temp = 0; + dmax_channely->ctrl_bit.chen = FALSE; + dmax_channely->ctrl = 0; + dmax_channely->dtcnt = 0; + dmax_channely->paddr = 0; + dmax_channely->maddr = 0; - temp = (uint32_t)dmax_channely; + temp = (uint32_t)dmax_channely; - if((temp & 0x6FF) < 0x608) - { - /* dma1 channel */ - DMA1->clr |= (uint32_t)(0x0F << ((((temp & 0xFF) - 0x08) / 0x14) * 4)); - } - else if((temp & 0x6FF) < 0x688) - { - /* dma2 channel */ - DMA2->clr |= (uint32_t)(0x0F << ((((temp & 0xFF) - 0x08) / 0x14) * 4)); - } + if ((temp & 0x6FF) < 0x608) { + /* dma1 channel */ + DMA1->clr |= (uint32_t)(0x0F << ((((temp & 0xFF) - 0x08) / 0x14) * 4)); + } else if ((temp & 0x6FF) < 0x688) { + /* dma2 channel */ + DMA2->clr |= (uint32_t)(0x0F << ((((temp & 0xFF) - 0x08) / 0x14) * 4)); + } } /** @@ -104,9 +100,8 @@ void dma_reset(dma_channel_type *dmax_channely) * @param data_number: the number of data to be transferred (0x0000~0xFFFF). * @retval none. */ -void dma_data_number_set(dma_channel_type *dmax_channely, uint16_t data_number) -{ - dmax_channely->dtcnt = data_number; +void dma_data_number_set(dma_channel_type *dmax_channely, uint16_t data_number) { + dmax_channely->dtcnt = data_number; } /** @@ -129,9 +124,8 @@ void dma_data_number_set(dma_channel_type *dmax_channely, uint16_t data_number) * - DMA2_CHANNEL7 * @retval the number value. */ -uint16_t dma_data_number_get(dma_channel_type *dmax_channely) -{ - return (uint16_t)dmax_channely->dtcnt; +uint16_t dma_data_number_get(dma_channel_type *dmax_channely) { + return (uint16_t)dmax_channely->dtcnt; } /** @@ -160,16 +154,12 @@ uint16_t dma_data_number_get(dma_channel_type *dmax_channely) * @param new_state (TRUE or FALSE) * @retval none. */ -void dma_interrupt_enable(dma_channel_type *dmax_channely, uint32_t dma_int, confirm_state new_state) -{ - if(new_state != FALSE) - { - dmax_channely->ctrl |= dma_int; - } - else - { - dmax_channely->ctrl &= ~dma_int; - } +void dma_interrupt_enable(dma_channel_type *dmax_channely, uint32_t dma_int, confirm_state new_state) { + if (new_state != FALSE) { + dmax_channely->ctrl |= dma_int; + } else { + dmax_channely->ctrl &= ~dma_int; + } } /** @@ -193,9 +183,8 @@ void dma_interrupt_enable(dma_channel_type *dmax_channely, uint32_t dma_int, con * @param new_state (TRUE or FALSE). * @retval none. */ -void dma_channel_enable(dma_channel_type *dmax_channely, confirm_state new_state) -{ - dmax_channely->ctrl_bit.chen = new_state; +void dma_channel_enable(dma_channel_type *dmax_channely, confirm_state new_state) { + dmax_channely->ctrl_bit.chen = new_state; } /** @@ -217,27 +206,20 @@ void dma_channel_enable(dma_channel_type *dmax_channely, confirm_state new_state * - DMA2_GL7_FLAG - DMA2_FDT7_FLAG - DMA2_HDT7_FLAG - DMA2_DTERR7_FLAG * @retval state of dma flag. */ -flag_status dma_flag_get(uint32_t dmax_flag) -{ - uint32_t temp = 0; +flag_status dma_flag_get(uint32_t dmax_flag) { + uint32_t temp = 0; - if(dmax_flag > 0x10000000) - { - temp = DMA2->sts; - } - else - { - temp = DMA1->sts; - } + if (dmax_flag > 0x10000000) { + temp = DMA2->sts; + } else { + temp = DMA1->sts; + } - if((temp & dmax_flag) != RESET) - { - return SET; - } - else - { - return RESET; - } + if ((temp & dmax_flag) != RESET) { + return SET; + } else { + return RESET; + } } /** @@ -259,27 +241,20 @@ flag_status dma_flag_get(uint32_t dmax_flag) * - DMA2_FDT7_FLAG - DMA2_HDT7_FLAG - DMA2_DTERR7_FLAG * @retval state of dma flag. */ -flag_status dma_interrupt_flag_get(uint32_t dmax_flag) -{ - uint32_t temp = 0; +flag_status dma_interrupt_flag_get(uint32_t dmax_flag) { + uint32_t temp = 0; - if(dmax_flag > 0x10000000) - { - temp = DMA2->sts; - } - else - { - temp = DMA1->sts; - } + if (dmax_flag > 0x10000000) { + temp = DMA2->sts; + } else { + temp = DMA1->sts; + } - if((temp & dmax_flag) != RESET) - { - return SET; - } - else - { - return RESET; - } + if ((temp & dmax_flag) != RESET) { + return SET; + } else { + return RESET; + } } /** @@ -302,16 +277,12 @@ flag_status dma_interrupt_flag_get(uint32_t dmax_flag) * - DMA2_GL7_FLAG - DMA2_FDT7_FLAG - DMA2_HDT7_FLAG - DMA2_DTERR7_FLAG * @retval none. */ -void dma_flag_clear(uint32_t dmax_flag) -{ - if(dmax_flag > ((uint32_t)0x10000000)) - { - DMA2->clr = (uint32_t)(dmax_flag & 0x0FFFFFFF); - } - else - { - DMA1->clr = dmax_flag; - } +void dma_flag_clear(uint32_t dmax_flag) { + if (dmax_flag > ((uint32_t)0x10000000)) { + DMA2->clr = (uint32_t)(dmax_flag & 0x0FFFFFFF); + } else { + DMA1->clr = dmax_flag; + } } /** @@ -319,18 +290,17 @@ void dma_flag_clear(uint32_t dmax_flag) * @param dma_init_struct: pointer to a dma_init_type structure which will be initialized. * @retval none. */ -void dma_default_para_init(dma_init_type *dma_init_struct) -{ - dma_init_struct->peripheral_base_addr = 0; - dma_init_struct->memory_base_addr = 0; - dma_init_struct->direction = DMA_DIR_PERIPHERAL_TO_MEMORY; - dma_init_struct->buffer_size = 0; - dma_init_struct->peripheral_inc_enable = FALSE; - dma_init_struct->memory_inc_enable = FALSE; - dma_init_struct->peripheral_data_width = DMA_PERIPHERAL_DATA_WIDTH_BYTE; - dma_init_struct->memory_data_width = DMA_MEMORY_DATA_WIDTH_BYTE; - dma_init_struct->loop_mode_enable = FALSE; - dma_init_struct->priority = DMA_PRIORITY_LOW; +void dma_default_para_init(dma_init_type *dma_init_struct) { + dma_init_struct->peripheral_base_addr = 0; + dma_init_struct->memory_base_addr = 0; + dma_init_struct->direction = DMA_DIR_PERIPHERAL_TO_MEMORY; + dma_init_struct->buffer_size = 0; + dma_init_struct->peripheral_inc_enable = FALSE; + dma_init_struct->memory_inc_enable = FALSE; + dma_init_struct->peripheral_data_width = DMA_PERIPHERAL_DATA_WIDTH_BYTE; + dma_init_struct->memory_data_width = DMA_MEMORY_DATA_WIDTH_BYTE; + dma_init_struct->loop_mode_enable = FALSE; + dma_init_struct->priority = DMA_PRIORITY_LOW; } /** @@ -354,21 +324,20 @@ void dma_default_para_init(dma_init_type *dma_init_struct) * @param dma_init_struct: pointer to a dma_init_type structure. * @retval none. */ -void dma_init(dma_channel_type *dmax_channely, dma_init_type *dma_init_struct) -{ - /* clear ctrl register dtd bit and m2m bit */ - dmax_channely->ctrl &= 0xbfef; - dmax_channely->ctrl |= dma_init_struct->direction; +void dma_init(dma_channel_type *dmax_channely, dma_init_type *dma_init_struct) { + /* clear ctrl register dtd bit and m2m bit */ + dmax_channely->ctrl &= 0xbfef; + dmax_channely->ctrl |= dma_init_struct->direction; - dmax_channely->ctrl_bit.chpl = dma_init_struct->priority; - dmax_channely->ctrl_bit.mwidth = dma_init_struct->memory_data_width; - dmax_channely->ctrl_bit.pwidth = dma_init_struct->peripheral_data_width; - dmax_channely->ctrl_bit.mincm = dma_init_struct->memory_inc_enable; - dmax_channely->ctrl_bit.pincm = dma_init_struct->peripheral_inc_enable; - dmax_channely->ctrl_bit.lm = dma_init_struct->loop_mode_enable; - dmax_channely->dtcnt_bit.cnt = dma_init_struct->buffer_size; - dmax_channely->paddr = dma_init_struct->peripheral_base_addr; - dmax_channely->maddr = dma_init_struct->memory_base_addr; + dmax_channely->ctrl_bit.chpl = dma_init_struct->priority; + dmax_channely->ctrl_bit.mwidth = dma_init_struct->memory_data_width; + dmax_channely->ctrl_bit.pwidth = dma_init_struct->peripheral_data_width; + dmax_channely->ctrl_bit.mincm = dma_init_struct->memory_inc_enable; + dmax_channely->ctrl_bit.pincm = dma_init_struct->peripheral_inc_enable; + dmax_channely->ctrl_bit.lm = dma_init_struct->loop_mode_enable; + dmax_channely->dtcnt_bit.cnt = dma_init_struct->buffer_size; + dmax_channely->paddr = dma_init_struct->peripheral_base_addr; + dmax_channely->maddr = dma_init_struct->memory_base_addr; } /** * @brief dmamux init. @@ -417,10 +386,9 @@ void dma_init(dma_channel_type *dmax_channely, dma_init_type *dma_init_struct) * - DMAMUX_DMAREQ_ID_TMR20_TRIG - DMAMUX_DMAREQ_ID_TMR20_HALL - DMAMUX_DMAREQ_ID_DVP * @retval none. */ -void dma_flexible_config(dma_type* dma_x, dmamux_channel_type *dmamux_channelx, dmamux_requst_id_sel_type dmamux_req_sel) -{ - dma_x->muxsel_bit.tblsel = TRUE; - dmamux_channelx->muxctrl_bit.reqsel = dmamux_req_sel; +void dma_flexible_config(dma_type *dma_x, dmamux_channel_type *dmamux_channelx, dmamux_requst_id_sel_type dmamux_req_sel) { + dma_x->muxsel_bit.tblsel = TRUE; + dmamux_channelx->muxctrl_bit.reqsel = dmamux_req_sel; } /** @@ -429,9 +397,8 @@ void dma_flexible_config(dma_type* dma_x, dmamux_channel_type *dmamux_channelx, * @param new_state (TRUE or FALSE) . * @retval none. */ -void dmamux_enable(dma_type *dma_x, confirm_state new_state) -{ - dma_x->muxsel_bit.tblsel = new_state; +void dmamux_enable(dma_type *dma_x, confirm_state new_state) { + dma_x->muxsel_bit.tblsel = new_state; } /** @@ -480,9 +447,8 @@ void dmamux_enable(dma_type *dma_x, confirm_state new_state) * - DMAMUX_DMAREQ_ID_TMR20_TRIG - DMAMUX_DMAREQ_ID_TMR20_HALL - DMAMUX_DMAREQ_ID_DVP * @retval none. */ -void dmamux_init(dmamux_channel_type *dmamux_channelx, dmamux_requst_id_sel_type dmamux_req_sel) -{ - dmamux_channelx->muxctrl_bit.reqsel = dmamux_req_sel; +void dmamux_init(dmamux_channel_type *dmamux_channelx, dmamux_requst_id_sel_type dmamux_req_sel) { + dmamux_channelx->muxctrl_bit.reqsel = dmamux_req_sel; } /** @@ -490,13 +456,12 @@ void dmamux_init(dmamux_channel_type *dmamux_channelx, dmamux_requst_id_sel_type * @param dmamux_sync_init_struct: pointer to a dmamux_sync_init_type structure which will be initialized. * @retval none. */ -void dmamux_sync_default_para_init(dmamux_sync_init_type *dmamux_sync_init_struct) -{ - dmamux_sync_init_struct->sync_enable = FALSE; - dmamux_sync_init_struct->sync_event_enable = FALSE; - dmamux_sync_init_struct->sync_polarity = DMAMUX_SYNC_POLARITY_DISABLE; - dmamux_sync_init_struct->sync_request_number = 0x0; - dmamux_sync_init_struct->sync_signal_sel = (dmamux_sync_id_sel_type)0; +void dmamux_sync_default_para_init(dmamux_sync_init_type *dmamux_sync_init_struct) { + dmamux_sync_init_struct->sync_enable = FALSE; + dmamux_sync_init_struct->sync_event_enable = FALSE; + dmamux_sync_init_struct->sync_polarity = DMAMUX_SYNC_POLARITY_DISABLE; + dmamux_sync_init_struct->sync_request_number = 0x0; + dmamux_sync_init_struct->sync_signal_sel = (dmamux_sync_id_sel_type)0; } /** @@ -520,13 +485,12 @@ void dmamux_sync_default_para_init(dmamux_sync_init_type *dmamux_sync_init_struc * @param dmamux_sync_init_struct: ointer to a dmamux_sync_init_type structure. * @retval none. */ -void dmamux_sync_config(dmamux_channel_type *dmamux_channelx, dmamux_sync_init_type *dmamux_sync_init_struct) -{ - dmamux_channelx->muxctrl_bit.syncsel = dmamux_sync_init_struct->sync_signal_sel; - dmamux_channelx->muxctrl_bit.syncpol = dmamux_sync_init_struct->sync_polarity; - dmamux_channelx->muxctrl_bit.reqcnt = dmamux_sync_init_struct->sync_request_number - 1; - dmamux_channelx->muxctrl_bit.evtgen = dmamux_sync_init_struct->sync_event_enable; - dmamux_channelx->muxctrl_bit.syncen = dmamux_sync_init_struct->sync_enable; +void dmamux_sync_config(dmamux_channel_type *dmamux_channelx, dmamux_sync_init_type *dmamux_sync_init_struct) { + dmamux_channelx->muxctrl_bit.syncsel = dmamux_sync_init_struct->sync_signal_sel; + dmamux_channelx->muxctrl_bit.syncpol = dmamux_sync_init_struct->sync_polarity; + dmamux_channelx->muxctrl_bit.reqcnt = dmamux_sync_init_struct->sync_request_number - 1; + dmamux_channelx->muxctrl_bit.evtgen = dmamux_sync_init_struct->sync_event_enable; + dmamux_channelx->muxctrl_bit.syncen = dmamux_sync_init_struct->sync_enable; } /** @@ -534,12 +498,11 @@ void dmamux_sync_config(dmamux_channel_type *dmamux_channelx, dmamux_sync_init_t * @param dmamux_gen_init_struct: pointer to a dmamux_gen_init_type structure which will be initialized. * @retval none. */ -void dmamux_generator_default_para_init(dmamux_gen_init_type *dmamux_gen_init_struct) -{ - dmamux_gen_init_struct->gen_enable = FALSE; - dmamux_gen_init_struct->gen_polarity = DMAMUX_GEN_POLARITY_DISABLE; - dmamux_gen_init_struct->gen_request_number = 0x0; - dmamux_gen_init_struct->gen_signal_sel = (dmamux_gen_id_sel_type)0x0; +void dmamux_generator_default_para_init(dmamux_gen_init_type *dmamux_gen_init_struct) { + dmamux_gen_init_struct->gen_enable = FALSE; + dmamux_gen_init_struct->gen_polarity = DMAMUX_GEN_POLARITY_DISABLE; + dmamux_gen_init_struct->gen_request_number = 0x0; + dmamux_gen_init_struct->gen_signal_sel = (dmamux_gen_id_sel_type)0x0; } /** @@ -557,12 +520,11 @@ void dmamux_generator_default_para_init(dmamux_gen_init_type *dmamux_gen_init_st * @param dmamux_gen_init_struct: pointer to a dmamux_gen_init_type structure which will be initialized. * @retval none. */ -void dmamux_generator_config(dmamux_generator_type *dmamux_gen_x, dmamux_gen_init_type *dmamux_gen_init_struct) -{ - dmamux_gen_x->gctrl_bit.sigsel = dmamux_gen_init_struct->gen_signal_sel; - dmamux_gen_x->gctrl_bit.gpol = dmamux_gen_init_struct->gen_polarity; - dmamux_gen_x->gctrl_bit.greqcnt = dmamux_gen_init_struct->gen_request_number - 1; - dmamux_gen_x->gctrl_bit.gen = dmamux_gen_init_struct->gen_enable; +void dmamux_generator_config(dmamux_generator_type *dmamux_gen_x, dmamux_gen_init_type *dmamux_gen_init_struct) { + dmamux_gen_x->gctrl_bit.sigsel = dmamux_gen_init_struct->gen_signal_sel; + dmamux_gen_x->gctrl_bit.gpol = dmamux_gen_init_struct->gen_polarity; + dmamux_gen_x->gctrl_bit.greqcnt = dmamux_gen_init_struct->gen_request_number - 1; + dmamux_gen_x->gctrl_bit.gen = dmamux_gen_init_struct->gen_enable; } /** @@ -586,16 +548,12 @@ void dmamux_generator_config(dmamux_generator_type *dmamux_gen_x, dmamux_gen_ini * @param new_state (TRUE or FALSE). * @retval none. */ -void dmamux_sync_interrupt_enable(dmamux_channel_type *dmamux_channelx, confirm_state new_state) -{ - if(new_state != FALSE) - { - dmamux_channelx->muxctrl_bit.syncovien = TRUE; - } - else - { - dmamux_channelx->muxctrl_bit.syncovien = FALSE; - } +void dmamux_sync_interrupt_enable(dmamux_channel_type *dmamux_channelx, confirm_state new_state) { + if (new_state != FALSE) { + dmamux_channelx->muxctrl_bit.syncovien = TRUE; + } else { + dmamux_channelx->muxctrl_bit.syncovien = FALSE; + } } /** @@ -613,16 +571,12 @@ void dmamux_sync_interrupt_enable(dmamux_channel_type *dmamux_channelx, confirm_ * @param new_state (TRUE or FALSE). * @retval none. */ -void dmamux_generator_interrupt_enable(dmamux_generator_type *dmamux_gen_x, confirm_state new_state) -{ - if(new_state != FALSE) - { - dmamux_gen_x->gctrl_bit.trgovien = TRUE; - } - else - { - dmamux_gen_x->gctrl_bit.trgovien = FALSE; - } +void dmamux_generator_interrupt_enable(dmamux_generator_type *dmamux_gen_x, confirm_state new_state) { + if (new_state != FALSE) { + dmamux_gen_x->gctrl_bit.trgovien = TRUE; + } else { + dmamux_gen_x->gctrl_bit.trgovien = FALSE; + } } /** @@ -639,16 +593,12 @@ void dmamux_generator_interrupt_enable(dmamux_generator_type *dmamux_gen_x, conf * - DMAMUX_SYNC_OV7_FLAG * @retval state of dmamux sync flag. */ -flag_status dmamux_sync_flag_get(dma_type *dma_x, uint32_t flag) -{ - if((dma_x->muxsyncsts & flag) != RESET) - { - return SET; - } - else - { - return RESET; - } +flag_status dmamux_sync_flag_get(dma_type *dma_x, uint32_t flag) { + if ((dma_x->muxsyncsts & flag) != RESET) { + return SET; + } else { + return RESET; + } } /** @@ -665,62 +615,45 @@ flag_status dmamux_sync_flag_get(dma_type *dma_x, uint32_t flag) * - DMAMUX_SYNC_OV7_FLAG * @retval state of dmamux sync flag. */ -flag_status dmamux_sync_interrupt_flag_get(dma_type *dma_x, uint32_t flag) -{ +flag_status dmamux_sync_interrupt_flag_get(dma_type *dma_x, uint32_t flag) { - flag_status bitstatus = RESET; - uint32_t sync_int_temp = flag; - uint32_t index = 0; - uint32_t tmpreg = 0, enablestatus = 0; - uint32_t regoffset = 0x4; - - while((sync_int_temp & 0x00000001) == RESET) - { - sync_int_temp = sync_int_temp >> 1; - index++; - } - - if(dma_x == DMA1) - { - tmpreg = *(uint32_t*)(DMA1MUX_BASE + (index * regoffset)); - } - else - { - tmpreg = *(uint32_t*)(DMA2MUX_BASE + (index * regoffset)); - } - - if((tmpreg & (uint32_t)0x00000100) != (uint32_t)RESET) - { - enablestatus = SET; - } - else - { - enablestatus = RESET; - } - - if(dma_x == DMA1) - { - if(((DMA1->muxsyncsts & flag) != (uint32_t)RESET) && (enablestatus != RESET)) - { - bitstatus = SET; + flag_status bitstatus = RESET; + uint32_t sync_int_temp = flag; + uint32_t index = 0; + uint32_t tmpreg = 0, enablestatus = 0; + uint32_t regoffset = 0x4; + + while ((sync_int_temp & 0x00000001) == RESET) { + sync_int_temp = sync_int_temp >> 1; + index++; } - else - { - bitstatus = RESET; + + if (dma_x == DMA1) { + tmpreg = *(uint32_t *)(DMA1MUX_BASE + (index * regoffset)); + } else { + tmpreg = *(uint32_t *)(DMA2MUX_BASE + (index * regoffset)); } - } - else - { - if(((DMA2->muxsyncsts & flag) != (uint32_t)RESET) && (enablestatus != RESET)) - { - bitstatus = SET; + + if ((tmpreg & (uint32_t)0x00000100) != (uint32_t)RESET) { + enablestatus = SET; + } else { + enablestatus = RESET; } - else - { - bitstatus = RESET; + + if (dma_x == DMA1) { + if (((DMA1->muxsyncsts & flag) != (uint32_t)RESET) && (enablestatus != RESET)) { + bitstatus = SET; + } else { + bitstatus = RESET; + } + } else { + if (((DMA2->muxsyncsts & flag) != (uint32_t)RESET) && (enablestatus != RESET)) { + bitstatus = SET; + } else { + bitstatus = RESET; + } } - } - return bitstatus; + return bitstatus; } /** @@ -737,9 +670,8 @@ flag_status dmamux_sync_interrupt_flag_get(dma_type *dma_x, uint32_t flag) * - DMAMUX_SYNC_OV7_FLAG * @retval none. */ -void dmamux_sync_flag_clear(dma_type *dma_x, uint32_t flag) -{ - dma_x->muxsyncclr = flag; +void dmamux_sync_flag_clear(dma_type *dma_x, uint32_t flag) { + dma_x->muxsyncclr = flag; } /** @@ -753,16 +685,12 @@ void dmamux_sync_flag_clear(dma_type *dma_x, uint32_t flag) * - DMAMUX_GEN_TRIG_OV4_FLAG * @retval state of dmamux sync flag. */ -flag_status dmamux_generator_flag_get(dma_type *dma_x, uint32_t flag) -{ - if((dma_x->muxgsts & flag) != RESET) - { - return SET; - } - else - { - return RESET; - } +flag_status dmamux_generator_flag_get(dma_type *dma_x, uint32_t flag) { + if ((dma_x->muxgsts & flag) != RESET) { + return SET; + } else { + return RESET; + } } /** @@ -776,57 +704,43 @@ flag_status dmamux_generator_flag_get(dma_type *dma_x, uint32_t flag) * - DMAMUX_GEN_TRIG_OV4_FLAG * @retval state of dmamux sync flag. */ -flag_status dmamux_generator_interrupt_flag_get(dma_type *dma_x, uint32_t flag) -{ - flag_status bitstatus = RESET; - uint32_t sync_int_temp = flag; - uint32_t index = 0; - uint32_t tmpreg = 0, enablestatus = 0; - uint32_t regoffset = 0x4; - - while((sync_int_temp & 0x00000001) == RESET) - { - sync_int_temp = sync_int_temp >> 1; - index++; - } - - if(dma_x == DMA1) - tmpreg = *(uint32_t*)(DMA1MUX_GENERATOR1_BASE + (index * regoffset)); - else - tmpreg = *(uint32_t*)(DMA2MUX_GENERATOR1_BASE + (index * regoffset)); - - if((tmpreg & (uint32_t)0x00000100) != (uint32_t)RESET) - { - enablestatus = SET; - } - else - { - enablestatus = RESET; - } - if(dma_x == DMA1) - { - if(((DMA1->muxgsts & flag) != (uint32_t)RESET) && (enablestatus != RESET)) - { - bitstatus = SET; +flag_status dmamux_generator_interrupt_flag_get(dma_type *dma_x, uint32_t flag) { + flag_status bitstatus = RESET; + uint32_t sync_int_temp = flag; + uint32_t index = 0; + uint32_t tmpreg = 0, enablestatus = 0; + uint32_t regoffset = 0x4; + + while ((sync_int_temp & 0x00000001) == RESET) { + sync_int_temp = sync_int_temp >> 1; + index++; } + + if (dma_x == DMA1) + tmpreg = *(uint32_t *)(DMA1MUX_GENERATOR1_BASE + (index * regoffset)); else - { - bitstatus = RESET; + tmpreg = *(uint32_t *)(DMA2MUX_GENERATOR1_BASE + (index * regoffset)); + + if ((tmpreg & (uint32_t)0x00000100) != (uint32_t)RESET) { + enablestatus = SET; + } else { + enablestatus = RESET; } - } - else - { - if(((DMA2->muxgsts & flag) != (uint32_t)RESET) && (enablestatus != RESET)) - { - bitstatus = SET; + if (dma_x == DMA1) { + if (((DMA1->muxgsts & flag) != (uint32_t)RESET) && (enablestatus != RESET)) { + bitstatus = SET; + } else { + bitstatus = RESET; + } + } else { + if (((DMA2->muxgsts & flag) != (uint32_t)RESET) && (enablestatus != RESET)) { + bitstatus = SET; + } else { + bitstatus = RESET; + } } - else - { - bitstatus = RESET; - } - } - - return bitstatus; + + return bitstatus; } /** @@ -840,9 +754,8 @@ flag_status dmamux_generator_interrupt_flag_get(dma_type *dma_x, uint32_t flag) * - DMAMUX_GEN_TRIG_OV4_FLAG * @retval none. */ -void dmamux_generator_flag_clear(dma_type *dma_x, uint32_t flag) -{ - dma_x->muxgclr = flag; +void dmamux_generator_flag_clear(dma_type *dma_x, uint32_t flag) { + dma_x->muxgclr = flag; } /** diff --git a/armlib/at32_sys/drivers/src/at32f435_437_dvp.c b/armlib/at32_sys/drivers/src/at32f435_437_dvp.c index 0a5bd65fe..c2e1ecf1a 100644 --- a/armlib/at32_sys/drivers/src/at32f435_437_dvp.c +++ b/armlib/at32_sys/drivers/src/at32f435_437_dvp.c @@ -46,10 +46,9 @@ * @param none * @retval none */ -void dvp_reset(void) -{ - crm_periph_reset(CRM_DVP_PERIPH_RESET, TRUE); - crm_periph_reset(CRM_DVP_PERIPH_RESET, FALSE); +void dvp_reset(void) { + crm_periph_reset(CRM_DVP_PERIPH_RESET, TRUE); + crm_periph_reset(CRM_DVP_PERIPH_RESET, FALSE); } /** @@ -57,9 +56,8 @@ void dvp_reset(void) * @param new_state (TRUE or FALSE) * @retval none */ -void dvp_capture_enable(confirm_state new_state) -{ - DVP->ctrl_bit.cap = new_state; +void dvp_capture_enable(confirm_state new_state) { + DVP->ctrl_bit.cap = new_state; } /** @@ -70,9 +68,8 @@ void dvp_capture_enable(confirm_state new_state) * - DVP_CAP_FUNC_MODE_SINGLE * @retval none */ -void dvp_capture_mode_set(dvp_cfm_type cap_mode) -{ - DVP->ctrl_bit.cfm = cap_mode; +void dvp_capture_mode_set(dvp_cfm_type cap_mode) { + DVP->ctrl_bit.cfm = cap_mode; } /** @@ -80,9 +77,8 @@ void dvp_capture_mode_set(dvp_cfm_type cap_mode) * @param new_state (TRUE or FALSE) * @retval none */ -void dvp_window_crop_enable(confirm_state new_state) -{ - DVP->ctrl_bit.crp = new_state; +void dvp_window_crop_enable(confirm_state new_state) { + DVP->ctrl_bit.crp = new_state; } /** @@ -95,10 +91,9 @@ void dvp_window_crop_enable(confirm_state new_state) * eg. y8:bytes = 1, rgb565:bytes = 2 * @retval none */ -void dvp_window_crop_set(uint16_t crop_x, uint16_t crop_y, uint16_t crop_w, uint16_t crop_h, uint8_t bytes) -{ - DVP->cwst = ((crop_x * bytes) | (crop_y << 16)); - DVP->cwsz = ((crop_w * bytes - 1) | ((crop_h - 1) << 16)); +void dvp_window_crop_set(uint16_t crop_x, uint16_t crop_y, uint16_t crop_w, uint16_t crop_h, uint8_t bytes) { + DVP->cwst = ((crop_x * bytes) | (crop_y << 16)); + DVP->cwsz = ((crop_w * bytes - 1) | ((crop_h - 1) << 16)); } /** @@ -106,9 +101,8 @@ void dvp_window_crop_set(uint16_t crop_x, uint16_t crop_y, uint16_t crop_w, uint * @param new_state (TRUE or FALSE) * @retval none */ -void dvp_jpeg_enable(confirm_state new_state) -{ - DVP->ctrl_bit.jpeg = new_state; +void dvp_jpeg_enable(confirm_state new_state) { + DVP->ctrl_bit.jpeg = new_state; } /** @@ -119,9 +113,8 @@ void dvp_jpeg_enable(confirm_state new_state) * - DVP_SYNC_MODE_EMBEDDED * @retval none */ -void dvp_sync_mode_set(dvp_sm_type sync_mode) -{ - DVP->ctrl_bit.sm = sync_mode; +void dvp_sync_mode_set(dvp_sm_type sync_mode) { + DVP->ctrl_bit.sm = sync_mode; } /** @@ -132,9 +125,8 @@ void dvp_sync_mode_set(dvp_sm_type sync_mode) * @param lnec(0x00~0xFF): line end code * @retval none */ -void dvp_sync_code_set(uint8_t fmsc, uint8_t fmec, uint8_t lnsc, uint8_t lnec) -{ - DVP->scr = (fmsc | (lnsc << 8) | (lnec << 16) | (fmec << 24)); +void dvp_sync_code_set(uint8_t fmsc, uint8_t fmec, uint8_t lnsc, uint8_t lnec) { + DVP->scr = (fmsc | (lnsc << 8) | (lnec << 16) | (fmec << 24)); } /** @@ -145,9 +137,8 @@ void dvp_sync_code_set(uint8_t fmsc, uint8_t fmec, uint8_t lnsc, uint8_t lnec) * @param lneu(0x00~0xFF): line end unmask * @retval none */ -void dvp_sync_unmask_set(uint8_t fmsu, uint8_t fmeu, uint8_t lnsu, uint8_t lneu) -{ - DVP->sur = (fmsu | (lnsu << 8) | (lneu << 16) | (fmeu << 24)); +void dvp_sync_unmask_set(uint8_t fmsu, uint8_t fmeu, uint8_t lnsu, uint8_t lneu) { + DVP->sur = (fmsu | (lnsu << 8) | (lneu << 16) | (fmeu << 24)); } /** @@ -158,9 +149,8 @@ void dvp_sync_unmask_set(uint8_t fmsu, uint8_t fmeu, uint8_t lnsu, uint8_t lneu) * - DVP_CLK_POLARITY_FALLING * @retval none */ -void dvp_pclk_polarity_set(dvp_ckp_type edge) -{ - DVP->ctrl_bit.ckp = edge; +void dvp_pclk_polarity_set(dvp_ckp_type edge) { + DVP->ctrl_bit.ckp = edge; } /** @@ -171,9 +161,8 @@ void dvp_pclk_polarity_set(dvp_ckp_type edge) * - DVP_HSYNC_POLARITY_LOW * @retval none */ -void dvp_hsync_polarity_set(dvp_hsp_type hsync_pol) -{ - DVP->ctrl_bit.hsp = hsync_pol; +void dvp_hsync_polarity_set(dvp_hsp_type hsync_pol) { + DVP->ctrl_bit.hsp = hsync_pol; } /** @@ -184,9 +173,8 @@ void dvp_hsync_polarity_set(dvp_hsp_type hsync_pol) * - DVP_VSYNC_POLARITY_HIGH * @retval none */ -void dvp_vsync_polarity_set(dvp_vsp_type vsync_pol) -{ - DVP->ctrl_bit.vsp = vsync_pol; +void dvp_vsync_polarity_set(dvp_vsp_type vsync_pol) { + DVP->ctrl_bit.vsp = vsync_pol; } /** @@ -199,9 +187,8 @@ void dvp_vsync_polarity_set(dvp_vsp_type vsync_pol) * - DVP_BFRC_QUARTER * @retval none */ -void dvp_basic_frame_rate_control_set(dvp_bfrc_type dvp_bfrc) -{ - DVP->ctrl_bit.bfrc = dvp_bfrc; +void dvp_basic_frame_rate_control_set(dvp_bfrc_type dvp_bfrc) { + DVP->ctrl_bit.bfrc = dvp_bfrc; } /** @@ -214,9 +201,8 @@ void dvp_basic_frame_rate_control_set(dvp_bfrc_type dvp_bfrc) * - DVP_PIXEL_DATA_LENGTH_14 * @retval none */ -void dvp_pixel_data_length_set(dvp_pdl_type dvp_pdl) -{ - DVP->ctrl_bit.pdl = dvp_pdl; +void dvp_pixel_data_length_set(dvp_pdl_type dvp_pdl) { + DVP->ctrl_bit.pdl = dvp_pdl; } /** @@ -224,9 +210,8 @@ void dvp_pixel_data_length_set(dvp_pdl_type dvp_pdl) * @param new_state (TRUE or FALSE) * @retval none */ -void dvp_enable(confirm_state new_state) -{ - DVP->ctrl_bit.ena = new_state; +void dvp_enable(confirm_state new_state) { + DVP->ctrl_bit.ena = new_state; } /** @@ -237,9 +222,8 @@ void dvp_enable(confirm_state new_state) * - DVP_PCDES_DROP_FIRST * @retval none */ -void dvp_zoomout_select(dvp_pcdes_type dvp_pcdes) -{ - DVP->actrl_bit.pcdes = dvp_pcdes; +void dvp_zoomout_select(dvp_pcdes_type dvp_pcdes) { + DVP->actrl_bit.pcdes = dvp_pcdes; } /** @@ -264,12 +248,11 @@ void dvp_zoomout_select(dvp_pcdes_type dvp_pcdes) * - DVP_LCDS_DROP_FIRST * @retval none */ -void dvp_zoomout_set(dvp_pcdc_type dvp_pcdc, dvp_pcds_type dvp_pcds, dvp_lcdc_type dvp_lcdc, dvp_lcds_type dvp_lcds) -{ - DVP->ctrl_bit.pcdc = dvp_pcdc; - DVP->ctrl_bit.pcds = dvp_pcds; - DVP->ctrl_bit.lcdc = dvp_lcdc; - DVP->ctrl_bit.lcds = dvp_lcds; +void dvp_zoomout_set(dvp_pcdc_type dvp_pcdc, dvp_pcds_type dvp_pcds, dvp_lcdc_type dvp_lcdc, dvp_lcds_type dvp_lcds) { + DVP->ctrl_bit.pcdc = dvp_pcdc; + DVP->ctrl_bit.pcds = dvp_pcds; + DVP->ctrl_bit.lcdc = dvp_lcdc; + DVP->ctrl_bit.lcds = dvp_lcds; } /** @@ -281,20 +264,16 @@ void dvp_zoomout_set(dvp_pcdc_type dvp_pcdc, dvp_pcds_type dvp_pcds, dvp_lcdc_ty * - DVP_STATUS_OFNE * @retval flag_status (SET or RESET) */ -flag_status dvp_basic_status_get(dvp_status_basic_type dvp_status_basic) -{ - flag_status status = RESET; +flag_status dvp_basic_status_get(dvp_status_basic_type dvp_status_basic) { + flag_status status = RESET; - if ((DVP->sts & (0x1 << dvp_status_basic)) != (uint16_t)RESET) - { - status = SET; - } - else - { - status = RESET; - } + if ((DVP->sts & (0x1 << dvp_status_basic)) != (uint16_t)RESET) { + status = SET; + } else { + status = RESET; + } - return status; + return status; } /** @@ -309,16 +288,12 @@ flag_status dvp_basic_status_get(dvp_status_basic_type dvp_status_basic) * @param new_state (TRUE or FALSE) * @retval none */ -void dvp_interrupt_enable(uint32_t dvp_int, confirm_state new_state) -{ - if(new_state == TRUE) - { - DVP->ier |= dvp_int; - } - else - { - DVP->ier &= ~dvp_int; - } +void dvp_interrupt_enable(uint32_t dvp_int, confirm_state new_state) { + if (new_state == TRUE) { + DVP->ier |= dvp_int; + } else { + DVP->ier &= ~dvp_int; + } } /** @@ -332,20 +307,16 @@ void dvp_interrupt_enable(uint32_t dvp_int, confirm_state new_state) * - DVP_HS_INT_FLAG * @retval flag_status (SET or RESET) */ -flag_status dvp_interrupt_flag_get(uint32_t flag) -{ - flag_status status = RESET; +flag_status dvp_interrupt_flag_get(uint32_t flag) { + flag_status status = RESET; - if((DVP->ists & flag) != RESET) - { - status = SET; - } - else - { - status = RESET; - } + if ((DVP->ists & flag) != RESET) { + status = SET; + } else { + status = RESET; + } - return status; + return status; } /** @@ -359,21 +330,17 @@ flag_status dvp_interrupt_flag_get(uint32_t flag) * - DVP_HS_EVT_FLAG * @retval flag_status (SET or RESET) */ -flag_status dvp_flag_get(uint32_t flag) -{ - flag_status status = RESET; - flag &= ~0x80000000; - - if((DVP->ests & flag) != RESET) - { - status = SET; - } - else - { - status = RESET; - } - - return status; +flag_status dvp_flag_get(uint32_t flag) { + flag_status status = RESET; + flag &= ~0x80000000; + + if ((DVP->ests & flag) != RESET) { + status = SET; + } else { + status = RESET; + } + + return status; } /** @@ -394,10 +361,9 @@ flag_status dvp_flag_get(uint32_t flag) * - DVP_HS_INT_FLAG * @retval none */ -void dvp_flag_clear(uint32_t flag) -{ - flag &= ~0x80000000; - DVP->iclr = flag; +void dvp_flag_clear(uint32_t flag) { + flag &= ~0x80000000; + DVP->iclr = flag; } /** @@ -405,9 +371,8 @@ void dvp_flag_clear(uint32_t flag) * @param new_state (TRUE or FALSE) * @retval none */ -void dvp_enhanced_scaling_resize_enable(confirm_state new_state) -{ - DVP->actrl_bit.eisre = new_state; +void dvp_enhanced_scaling_resize_enable(confirm_state new_state) { + DVP->actrl_bit.eisre = new_state; } /** * @brief set dvp enhanced image scaling resize configuration @@ -417,13 +382,11 @@ void dvp_enhanced_scaling_resize_enable(confirm_state new_state) * @param des_h(0x0001~0x1FFF): vertical scaling resize target size (target image height) * @retval none */ -void dvp_enhanced_scaling_resize_set(uint16_t src_w, uint16_t des_w, uint16_t src_h, uint16_t des_h) -{ - if((!DVP->ctrl_bit.pcdc) && (!DVP->ctrl_bit.lcdc) && DVP->actrl_bit.efdf) - { - DVP->hscf = (src_w | (des_w << 16)); - DVP->vscf = (src_h | (des_h << 16)); - } +void dvp_enhanced_scaling_resize_set(uint16_t src_w, uint16_t des_w, uint16_t src_h, uint16_t des_h) { + if ((!DVP->ctrl_bit.pcdc) && (!DVP->ctrl_bit.lcdc) && DVP->actrl_bit.efdf) { + DVP->hscf = (src_w | (des_w << 16)); + DVP->vscf = (src_h | (des_h << 16)); + } } /** @@ -433,14 +396,12 @@ void dvp_enhanced_scaling_resize_set(uint16_t src_w, uint16_t des_w, uint16_t sr * @param new_state (TRUE or FALSE) * @retval none */ -void dvp_enhanced_framerate_set(uint16_t efrcsf, uint16_t efrctf, confirm_state new_state) -{ - if((!DVP->ctrl_bit.cfm) && (!DVP->ctrl_bit.bfrc) && (efrctf <= efrcsf)) - { - DVP->frf = (efrcsf | (efrctf << 8)); - } +void dvp_enhanced_framerate_set(uint16_t efrcsf, uint16_t efrctf, confirm_state new_state) { + if ((!DVP->ctrl_bit.cfm) && (!DVP->ctrl_bit.bfrc) && (efrctf <= efrcsf)) { + DVP->frf = (efrcsf | (efrctf << 8)); + } - DVP->actrl_bit.efrce = new_state; + DVP->actrl_bit.efrce = new_state; } /** @@ -449,10 +410,9 @@ void dvp_enhanced_framerate_set(uint16_t efrcsf, uint16_t efrctf, confirm_state * @param new_state: (TRUE or FALSE) * @retval none */ -void dvp_monochrome_image_binarization_set(uint8_t mibthd, confirm_state new_state) -{ - DVP->bth_bit.mibthd = mibthd; - DVP->actrl_bit.mibe = new_state; +void dvp_monochrome_image_binarization_set(uint8_t mibthd, confirm_state new_state) { + DVP->bth_bit.mibthd = mibthd; + DVP->actrl_bit.mibe = new_state; } /** @@ -466,9 +426,8 @@ void dvp_monochrome_image_binarization_set(uint8_t mibthd, confirm_state new_sta * - DVP_EFDF_Y8 * @retval none */ -void dvp_enhanced_data_format_set(dvp_efdf_type dvp_efdf) -{ - DVP->actrl_bit.efdf = dvp_efdf; +void dvp_enhanced_data_format_set(dvp_efdf_type dvp_efdf) { + DVP->actrl_bit.efdf = dvp_efdf; } /** @@ -485,10 +444,9 @@ void dvp_enhanced_data_format_set(dvp_efdf_type dvp_efdf) * - DVP_IDUN_6 * @retval none */ -void dvp_input_data_unused_set(dvp_idus_type dvp_idus, dvp_idun_type dvp_idun) -{ - DVP->actrl_bit.idus = dvp_idus; - DVP->actrl_bit.idun = dvp_idun; +void dvp_input_data_unused_set(dvp_idus_type dvp_idus, dvp_idun_type dvp_idun) { + DVP->actrl_bit.idus = dvp_idus; + DVP->actrl_bit.idun = dvp_idun; } /** @@ -499,9 +457,8 @@ void dvp_input_data_unused_set(dvp_idus_type dvp_idus, dvp_idun_type dvp_idun) * - DVP_DMABT_BURST * @retval none */ -void dvp_dma_burst_set(dvp_dmabt_type dvp_dmabt) -{ - DVP->actrl_bit.dmabt = dvp_dmabt; +void dvp_dma_burst_set(dvp_dmabt_type dvp_dmabt) { + DVP->actrl_bit.dmabt = dvp_dmabt; } /** @@ -516,10 +473,9 @@ void dvp_dma_burst_set(dvp_dmabt_type dvp_dmabt) * - DVP_VSEID_FRMAE_START * @retval none */ -void dvp_sync_event_interrupt_set(dvp_hseid_type dvp_hseid, dvp_vseid_type dvp_vseid) -{ - DVP->actrl_bit.hseid = dvp_hseid; - DVP->actrl_bit.vseid = dvp_vseid; +void dvp_sync_event_interrupt_set(dvp_hseid_type dvp_hseid, dvp_vseid_type dvp_vseid) { + DVP->actrl_bit.hseid = dvp_hseid; + DVP->actrl_bit.vseid = dvp_vseid; } /** diff --git a/armlib/at32_sys/drivers/src/at32f435_437_edma.c b/armlib/at32_sys/drivers/src/at32f435_437_edma.c index 2a593908d..ba10c41d2 100644 --- a/armlib/at32_sys/drivers/src/at32f435_437_edma.c +++ b/armlib/at32_sys/drivers/src/at32f435_437_edma.c @@ -55,46 +55,45 @@ * - EDMA_STREAM8 * @retval none. */ -void edma_reset(edma_stream_type *edma_streamx) -{ - /* reset registers for the selected stream */ - edma_streamx->ctrl_bit.sen = FALSE; - edma_streamx->ctrl = 0x0; - edma_streamx->dtcnt = 0x0; - edma_streamx->paddr = 0x0; - edma_streamx->m0addr = 0x0; - edma_streamx->m1addr = 0x0; - edma_streamx->fctrl = (uint32_t)0x00000021; +void edma_reset(edma_stream_type *edma_streamx) { + /* reset registers for the selected stream */ + edma_streamx->ctrl_bit.sen = FALSE; + edma_streamx->ctrl = 0x0; + edma_streamx->dtcnt = 0x0; + edma_streamx->paddr = 0x0; + edma_streamx->m0addr = 0x0; + edma_streamx->m1addr = 0x0; + edma_streamx->fctrl = (uint32_t)0x00000021; - /* reset interrupt pending bits for the selected stream */ - switch((uint32_t)edma_streamx) - { - case EDMA_STREAM1_BASE: - EDMA->clr1 = EDMA_STREAM1_INT_MASK; - break; - case EDMA_STREAM2_BASE: - EDMA->clr1 = EDMA_STREAM2_INT_MASK; - break; - case EDMA_STREAM3_BASE: - EDMA->clr1 = EDMA_STREAM3_INT_MASK; - break; - case EDMA_STREAM4_BASE: - EDMA->clr1 = EDMA_STREAM4_INT_MASK; - break; - case EDMA_STREAM5_BASE: - EDMA->clr2 = EDMA_STREAM5_INT_MASK; - break; - case EDMA_STREAM6_BASE: - EDMA->clr2 = EDMA_STREAM6_INT_MASK; - break; - case EDMA_STREAM7_BASE: - EDMA->clr2 = EDMA_STREAM7_INT_MASK; - break; - case EDMA_STREAM8_BASE: - EDMA->clr2 = EDMA_STREAM8_INT_MASK; - break; - default: break; - } + /* reset interrupt pending bits for the selected stream */ + switch ((uint32_t)edma_streamx) { + case EDMA_STREAM1_BASE: + EDMA->clr1 = EDMA_STREAM1_INT_MASK; + break; + case EDMA_STREAM2_BASE: + EDMA->clr1 = EDMA_STREAM2_INT_MASK; + break; + case EDMA_STREAM3_BASE: + EDMA->clr1 = EDMA_STREAM3_INT_MASK; + break; + case EDMA_STREAM4_BASE: + EDMA->clr1 = EDMA_STREAM4_INT_MASK; + break; + case EDMA_STREAM5_BASE: + EDMA->clr2 = EDMA_STREAM5_INT_MASK; + break; + case EDMA_STREAM6_BASE: + EDMA->clr2 = EDMA_STREAM6_INT_MASK; + break; + case EDMA_STREAM7_BASE: + EDMA->clr2 = EDMA_STREAM7_INT_MASK; + break; + case EDMA_STREAM8_BASE: + EDMA->clr2 = EDMA_STREAM8_INT_MASK; + break; + default: + break; + } } /** @@ -112,49 +111,48 @@ void edma_reset(edma_stream_type *edma_streamx) * @param edma_init_struct: pointer to a edma_init_type structure. * @retval none. */ -void edma_init(edma_stream_type *edma_streamx, edma_init_type *edma_init_struct) -{ - /* config dtd bits */ - edma_streamx->ctrl_bit.dtd = edma_init_struct->direction; +void edma_init(edma_stream_type *edma_streamx, edma_init_type *edma_init_struct) { + /* config dtd bits */ + edma_streamx->ctrl_bit.dtd = edma_init_struct->direction; - /* config pincm bit */ - edma_streamx->ctrl_bit.pincm = edma_init_struct->peripheral_inc_enable; + /* config pincm bit */ + edma_streamx->ctrl_bit.pincm = edma_init_struct->peripheral_inc_enable; - /* config mincm bit*/ - edma_streamx->ctrl_bit.mincm = edma_init_struct->memory_inc_enable; + /* config mincm bit*/ + edma_streamx->ctrl_bit.mincm = edma_init_struct->memory_inc_enable; - /* config pwidth bits */ - edma_streamx->ctrl_bit.pwidth = edma_init_struct->peripheral_data_width; + /* config pwidth bits */ + edma_streamx->ctrl_bit.pwidth = edma_init_struct->peripheral_data_width; - /* config mwidth bits */ - edma_streamx->ctrl_bit.mwidth = edma_init_struct->memory_data_width; + /* config mwidth bits */ + edma_streamx->ctrl_bit.mwidth = edma_init_struct->memory_data_width; - /* config lm bit */ - edma_streamx->ctrl_bit.lm = edma_init_struct->loop_mode_enable; + /* config lm bit */ + edma_streamx->ctrl_bit.lm = edma_init_struct->loop_mode_enable; - /* config spl bits */ - edma_streamx->ctrl_bit.spl = edma_init_struct->priority; + /* config spl bits */ + edma_streamx->ctrl_bit.spl = edma_init_struct->priority; - /* config mct bits */ - edma_streamx->ctrl_bit.mct = edma_init_struct->memory_burst_mode; + /* config mct bits */ + edma_streamx->ctrl_bit.mct = edma_init_struct->memory_burst_mode; - /* config pct bits */ - edma_streamx->ctrl_bit.pct = edma_init_struct->peripheral_burst_mode; + /* config pct bits */ + edma_streamx->ctrl_bit.pct = edma_init_struct->peripheral_burst_mode; - /* config fen bits */ - edma_streamx->fctrl_bit.fen = edma_init_struct->fifo_mode_enable; + /* config fen bits */ + edma_streamx->fctrl_bit.fen = edma_init_struct->fifo_mode_enable; - /* config fthsel bits*/ - edma_streamx->fctrl_bit.fthsel = edma_init_struct->fifo_threshold; + /* config fthsel bits*/ + edma_streamx->fctrl_bit.fthsel = edma_init_struct->fifo_threshold; - /* config dtcnt */ - edma_streamx->dtcnt = edma_init_struct->buffer_size; + /* config dtcnt */ + edma_streamx->dtcnt = edma_init_struct->buffer_size; - /* config paddr */ - edma_streamx->paddr = edma_init_struct->peripheral_base_addr; + /* config paddr */ + edma_streamx->paddr = edma_init_struct->peripheral_base_addr; - /* config m0addr */ - edma_streamx->m0addr = edma_init_struct->memory0_base_addr; + /* config m0addr */ + edma_streamx->m0addr = edma_init_struct->memory0_base_addr; } /** @@ -162,22 +160,21 @@ void edma_init(edma_stream_type *edma_streamx, edma_init_type *edma_init_struct) * @param edma_init_struct: pointer to a edma_init_type structure which will be initialized. * @retval none. */ -void edma_default_para_init(edma_init_type *edma_init_struct) -{ - edma_init_struct->buffer_size = 0; - edma_init_struct->loop_mode_enable = FALSE; - edma_init_struct->direction = EDMA_DIR_PERIPHERAL_TO_MEMORY; - edma_init_struct->fifo_threshold = EDMA_FIFO_THRESHOLD_1QUARTER; - edma_init_struct->fifo_mode_enable = FALSE; - edma_init_struct->memory0_base_addr = 0; - edma_init_struct->memory_burst_mode = EDMA_MEMORY_SINGLE; - edma_init_struct->memory_data_width = EDMA_MEMORY_DATA_WIDTH_BYTE; - edma_init_struct->memory_inc_enable = FALSE; - edma_init_struct->peripheral_base_addr = 0; - edma_init_struct->peripheral_burst_mode = EDMA_PERIPHERAL_SINGLE; - edma_init_struct->peripheral_data_width = EDMA_PERIPHERAL_DATA_WIDTH_BYTE; - edma_init_struct->peripheral_inc_enable = FALSE; - edma_init_struct->priority = EDMA_PRIORITY_LOW; +void edma_default_para_init(edma_init_type *edma_init_struct) { + edma_init_struct->buffer_size = 0; + edma_init_struct->loop_mode_enable = FALSE; + edma_init_struct->direction = EDMA_DIR_PERIPHERAL_TO_MEMORY; + edma_init_struct->fifo_threshold = EDMA_FIFO_THRESHOLD_1QUARTER; + edma_init_struct->fifo_mode_enable = FALSE; + edma_init_struct->memory0_base_addr = 0; + edma_init_struct->memory_burst_mode = EDMA_MEMORY_SINGLE; + edma_init_struct->memory_data_width = EDMA_MEMORY_DATA_WIDTH_BYTE; + edma_init_struct->memory_inc_enable = FALSE; + edma_init_struct->peripheral_base_addr = 0; + edma_init_struct->peripheral_burst_mode = EDMA_PERIPHERAL_SINGLE; + edma_init_struct->peripheral_data_width = EDMA_PERIPHERAL_DATA_WIDTH_BYTE; + edma_init_struct->peripheral_inc_enable = FALSE; + edma_init_struct->priority = EDMA_PRIORITY_LOW; } /** @@ -195,9 +192,8 @@ void edma_default_para_init(edma_init_type *edma_init_struct) * @param new_state (TRUE or FALSE). * @retval none. */ -void edma_stream_enable(edma_stream_type *edma_streamx, confirm_state new_state) -{ - edma_streamx->ctrl_bit.sen = new_state; +void edma_stream_enable(edma_stream_type *edma_streamx, confirm_state new_state) { + edma_streamx->ctrl_bit.sen = new_state; } /** @@ -222,31 +218,22 @@ void edma_stream_enable(edma_stream_type *edma_streamx, confirm_state new_state) * @param new_state (TRUE or FALSE). * @retval none. */ -void edma_interrupt_enable(edma_stream_type *edma_streamx, uint32_t edma_int, confirm_state new_state) -{ - if((edma_int & EDMA_FERR_INT) != 0) - { - if(new_state != FALSE) - { - edma_streamx->fctrl |= (uint32_t)EDMA_FERR_INT; +void edma_interrupt_enable(edma_stream_type *edma_streamx, uint32_t edma_int, confirm_state new_state) { + if ((edma_int & EDMA_FERR_INT) != 0) { + if (new_state != FALSE) { + edma_streamx->fctrl |= (uint32_t)EDMA_FERR_INT; + } else { + edma_streamx->fctrl &= ~(uint32_t)EDMA_FERR_INT; + } } - else - { - edma_streamx->fctrl &= ~(uint32_t)EDMA_FERR_INT; - } - } - if(edma_int != EDMA_FERR_INT) - { - if(new_state != FALSE) - { - edma_streamx->ctrl |= (uint32_t)edma_int; + if (edma_int != EDMA_FERR_INT) { + if (new_state != FALSE) { + edma_streamx->ctrl |= (uint32_t)edma_int; + } else { + edma_streamx->ctrl &= ~(uint32_t)edma_int; + } } - else - { - edma_streamx->ctrl &= ~(uint32_t)edma_int; - } - } } /** @@ -267,9 +254,8 @@ void edma_interrupt_enable(edma_stream_type *edma_streamx, uint32_t edma_int, co * - EDMA_PERIPHERAL_INC_4_BYTE * @retval none. */ -void edma_peripheral_inc_offset_set(edma_stream_type *edma_streamx, edma_peripheral_inc_offset_type offset) -{ - edma_streamx->ctrl_bit.pincos = offset; +void edma_peripheral_inc_offset_set(edma_stream_type *edma_streamx, edma_peripheral_inc_offset_type offset) { + edma_streamx->ctrl_bit.pincos = offset; } /** @@ -287,9 +273,8 @@ void edma_peripheral_inc_offset_set(edma_stream_type *edma_streamx, edma_periphe * @param new_state (TRUE or FALSE). * @retval none. */ -void edma_flow_controller_enable(edma_stream_type *edma_streamx, confirm_state new_state) -{ - edma_streamx->ctrl_bit.pfctrl = new_state; +void edma_flow_controller_enable(edma_stream_type *edma_streamx, confirm_state new_state) { + edma_streamx->ctrl_bit.pfctrl = new_state; } /** @@ -307,10 +292,9 @@ void edma_flow_controller_enable(edma_stream_type *edma_streamx, confirm_state n * @param data_number: the number of data to be transferred (0x0000~0xFFFF). * @retval none. */ -void edma_data_number_set(edma_stream_type *edma_streamx, uint16_t data_number) -{ - /* write the number of data units to be transferred */ - edma_streamx->dtcnt = data_number; +void edma_data_number_set(edma_stream_type *edma_streamx, uint16_t data_number) { + /* write the number of data units to be transferred */ + edma_streamx->dtcnt = data_number; } /** @@ -327,9 +311,8 @@ void edma_data_number_set(edma_stream_type *edma_streamx, uint16_t data_number) * - EDMA_STREAM8 * @retval the number value. */ -uint16_t edma_data_number_get(edma_stream_type *edma_streamx) -{ - return ((uint16_t)(edma_streamx->dtcnt)); +uint16_t edma_data_number_get(edma_stream_type *edma_streamx) { + return ((uint16_t)(edma_streamx->dtcnt)); } /** @@ -351,18 +334,14 @@ uint16_t edma_data_number_get(edma_stream_type *edma_streamx) * - EDMA_MEMORY_1 * @retval none. */ -void edma_double_buffer_mode_init(edma_stream_type *edma_streamx, uint32_t memory1_addr, edma_memory_type current_memory) -{ - if(current_memory != EDMA_MEMORY_0) - { - edma_streamx->ctrl_bit.cm = 1; - } - else - { - edma_streamx->ctrl_bit.cm = 0; - } +void edma_double_buffer_mode_init(edma_stream_type *edma_streamx, uint32_t memory1_addr, edma_memory_type current_memory) { + if (current_memory != EDMA_MEMORY_0) { + edma_streamx->ctrl_bit.cm = 1; + } else { + edma_streamx->ctrl_bit.cm = 0; + } - edma_streamx->m1addr = memory1_addr; + edma_streamx->m1addr = memory1_addr; } /** @@ -380,16 +359,12 @@ void edma_double_buffer_mode_init(edma_stream_type *edma_streamx, uint32_t memor * @param new_state (TRUE or FALSE). * @retval none. */ -void edma_double_buffer_mode_enable(edma_stream_type *edma_streamx, confirm_state new_state) -{ - if(new_state != FALSE) - { - edma_streamx->ctrl_bit.dmm = 1; - } - else - { - edma_streamx->ctrl_bit.dmm = 0; - } +void edma_double_buffer_mode_enable(edma_stream_type *edma_streamx, confirm_state new_state) { + if (new_state != FALSE) { + edma_streamx->ctrl_bit.dmm = 1; + } else { + edma_streamx->ctrl_bit.dmm = 0; + } } /** @@ -411,16 +386,12 @@ void edma_double_buffer_mode_enable(edma_stream_type *edma_streamx, confirm_stat * - EDMA_MEMORY_1 * @retval none. */ -void edma_memory_addr_set(edma_stream_type *edma_streamx, uint32_t memory_addr, uint32_t memory_target) -{ - if(memory_target != EDMA_MEMORY_0) - { - edma_streamx->m1addr = memory_addr; - } - else - { - edma_streamx->m0addr = memory_addr; - } +void edma_memory_addr_set(edma_stream_type *edma_streamx, uint32_t memory_addr, uint32_t memory_target) { + if (memory_target != EDMA_MEMORY_0) { + edma_streamx->m1addr = memory_addr; + } else { + edma_streamx->m0addr = memory_addr; + } } /** @@ -439,9 +410,8 @@ void edma_memory_addr_set(edma_stream_type *edma_streamx, uint32_t memory_addr, * - EDMA_MEMORY_0 * - EDMA_MEMORY_1 */ -edma_memory_type edma_memory_target_get(edma_stream_type *edma_streamx) -{ - return (edma_memory_type)(edma_streamx->ctrl_bit.cm); +edma_memory_type edma_memory_target_get(edma_stream_type *edma_streamx) { + return (edma_memory_type)(edma_streamx->ctrl_bit.cm); } /** @@ -458,16 +428,12 @@ edma_memory_type edma_memory_target_get(edma_stream_type *edma_streamx) * - EDMA_STREAM8 * @retval current state of the edma streamx (SET or RESET). */ -flag_status edma_stream_status_get(edma_stream_type *edma_streamx) -{ - if((edma_streamx->ctrl_bit.sen) != RESET) - { - return SET; - } - else - { - return RESET; - } +flag_status edma_stream_status_get(edma_stream_type *edma_streamx) { + if ((edma_streamx->ctrl_bit.sen) != RESET) { + return SET; + } else { + return RESET; + } } /** @@ -490,9 +456,8 @@ flag_status edma_stream_status_get(edma_stream_type *edma_streamx) * - EDMA_FIFO_STATUS_EMPTY: fifo is empty. * - EDMA_FIFO_STATUS_FULL: fifo is full. */ -uint8_t edma_fifo_status_get(edma_stream_type *edma_streamx) -{ - return (uint8_t)(edma_streamx->fctrl_bit.fsts); +uint8_t edma_fifo_status_get(edma_stream_type *edma_streamx) { + return (uint8_t)(edma_streamx->fctrl_bit.fsts); } /** @@ -509,27 +474,20 @@ uint8_t edma_fifo_status_get(edma_stream_type *edma_streamx) * - EDMA_FERR8_FLAG - EDMA_DMERR8_FLAG - EDMA_DTERR8_FLAG - EDMA_HDT8_FLAG - EDMA_FDT8_FLAG * @retval the new state of edma flag (SET or RESET). */ -flag_status edma_flag_get(uint32_t edma_flag) -{ - uint32_t status; +flag_status edma_flag_get(uint32_t edma_flag) { + uint32_t status; - if(edma_flag > ((uint32_t)0x20000000)) - { - status = EDMA->sts2; - } - else - { - status = EDMA->sts1; - } + if (edma_flag > ((uint32_t)0x20000000)) { + status = EDMA->sts2; + } else { + status = EDMA->sts1; + } - if((status & edma_flag) != ((uint32_t)RESET)) - { - return SET; - } - else - { - return RESET; - } + if ((status & edma_flag) != ((uint32_t)RESET)) { + return SET; + } else { + return RESET; + } } /** @@ -546,27 +504,20 @@ flag_status edma_flag_get(uint32_t edma_flag) * - EDMA_FERR8_FLAG - EDMA_DMERR8_FLAG - EDMA_DTERR8_FLAG - EDMA_HDT8_FLAG - EDMA_FDT8_FLAG * @retval the new state of edma flag (SET or RESET). */ -flag_status edma_interrupt_flag_get(uint32_t edma_flag) -{ - uint32_t status; +flag_status edma_interrupt_flag_get(uint32_t edma_flag) { + uint32_t status; - if(edma_flag > ((uint32_t)0x20000000)) - { - status = EDMA->sts2; - } - else - { - status = EDMA->sts1; - } + if (edma_flag > ((uint32_t)0x20000000)) { + status = EDMA->sts2; + } else { + status = EDMA->sts1; + } - if((status & edma_flag) != ((uint32_t)RESET)) - { - return SET; - } - else - { - return RESET; - } + if ((status & edma_flag) != ((uint32_t)RESET)) { + return SET; + } else { + return RESET; + } } /** @@ -583,16 +534,12 @@ flag_status edma_interrupt_flag_get(uint32_t edma_flag) * - EDMA_FERR8_FLAG - EDMA_DMERR8_FLAG - EDMA_DTERR8_FLAG - EDMA_HDT8_FLAG - EDMA_FDT8_FLAG * @retval none. */ -void edma_flag_clear(uint32_t edma_flag) -{ - if(edma_flag > ((uint32_t)0x20000000)) - { - EDMA->clr2 = (uint32_t)(edma_flag & 0x0FFFFFFF); - } - else - { - EDMA->clr1 = edma_flag; - } +void edma_flag_clear(uint32_t edma_flag) { + if (edma_flag > ((uint32_t)0x20000000)) { + EDMA->clr2 = (uint32_t)(edma_flag & 0x0FFFFFFF); + } else { + EDMA->clr1 = edma_flag; + } } /** @@ -613,11 +560,10 @@ void edma_flag_clear(uint32_t edma_flag) * @param ycnt: y dimension transfer count(0x0000~ 0xFFFF). * @retval none. */ -void edma_2d_init(edma_stream_2d_type *edma_streamx_2d, int16_t src_stride, int16_t dst_stride, uint16_t xcnt, uint16_t ycnt) -{ - edma_streamx_2d->s2dcnt = (uint32_t)((ycnt << 16) | (xcnt)); +void edma_2d_init(edma_stream_2d_type *edma_streamx_2d, int16_t src_stride, int16_t dst_stride, uint16_t xcnt, uint16_t ycnt) { + edma_streamx_2d->s2dcnt = (uint32_t)((ycnt << 16) | (xcnt)); - edma_streamx_2d->stride = (uint32_t)((dst_stride << 16) | (src_stride)); + edma_streamx_2d->stride = (uint32_t)((dst_stride << 16) | (src_stride)); } /** @@ -635,20 +581,16 @@ void edma_2d_init(edma_stream_2d_type *edma_streamx_2d, int16_t src_stride, int1 * @param new_state (TRUE or FALSE). * @retval none. */ -void edma_2d_enable(edma_stream_2d_type *edma_streamx_2d, confirm_state new_state) -{ - uint32_t offset; +void edma_2d_enable(edma_stream_2d_type *edma_streamx_2d, confirm_state new_state) { + uint32_t offset; - offset = ((uint32_t)edma_streamx_2d - EDMA_STREAM1_2D_BASE) / 4; + offset = ((uint32_t)edma_streamx_2d - EDMA_STREAM1_2D_BASE) / 4; - if(new_state != FALSE) - { - EDMA->s2dctrl |= (uint16_t)0x0001 << offset; - } - else - { - EDMA->s2dctrl &= ~((uint16_t)0x0001 << offset); - } + if (new_state != FALSE) { + EDMA->s2dctrl |= (uint16_t)0x0001 << offset; + } else { + EDMA->s2dctrl &= ~((uint16_t)0x0001 << offset); + } } /** @@ -666,9 +608,8 @@ void edma_2d_enable(edma_stream_2d_type *edma_streamx_2d, confirm_state new_stat * @param pointer: link list pointer. * @retval none. */ -void edma_link_list_init(edma_stream_link_list_type *edma_streamx_ll, uint32_t pointer) -{ - edma_streamx_ll->llp = pointer; +void edma_link_list_init(edma_stream_link_list_type *edma_streamx_ll, uint32_t pointer) { + edma_streamx_ll->llp = pointer; } /** @@ -686,20 +627,16 @@ void edma_link_list_init(edma_stream_link_list_type *edma_streamx_ll, uint32_t p * @param new_state (TRUE or FALSE). * @retval none. */ -void edma_link_list_enable(edma_stream_link_list_type *edma_streamx_ll, confirm_state new_state) -{ - uint32_t offset; +void edma_link_list_enable(edma_stream_link_list_type *edma_streamx_ll, confirm_state new_state) { + uint32_t offset; - offset = ((uint32_t)edma_streamx_ll - EDMA_STREAM1_LL_BASE) / 4; + offset = ((uint32_t)edma_streamx_ll - EDMA_STREAM1_LL_BASE) / 4; - if(new_state != FALSE) - { - EDMA->llctrl |= (uint16_t)0x0001 << offset; - } - else - { - EDMA->llctrl &= ~((uint16_t)0x0001 << offset); - } + if (new_state != FALSE) { + EDMA->llctrl |= (uint16_t)0x0001 << offset; + } else { + EDMA->llctrl &= ~((uint16_t)0x0001 << offset); + } } /** @@ -707,9 +644,8 @@ void edma_link_list_enable(edma_stream_link_list_type *edma_streamx_ll, confirm_ * @param new_state (TRUE or FALSE). * @retval none. */ -void edmamux_enable(confirm_state new_state) -{ - EDMA->muxsel_bit.tblsel = new_state; +void edmamux_enable(confirm_state new_state) { + EDMA->muxsel_bit.tblsel = new_state; } /** @@ -752,9 +688,8 @@ void edmamux_enable(confirm_state new_state) * - EDMAMUX_DMAREQ_ID_TMR20_TRIG - EDMAMUX_DMAREQ_ID_TMR20_HALL - EDMAMUX_DMAREQ_ID_DVP * @retval none. */ -void edmamux_init(edmamux_channel_type *edmamux_channelx, edmamux_requst_id_sel_type edmamux_req_id) -{ - edmamux_channelx->muxctrl_bit.reqsel = edmamux_req_id; +void edmamux_init(edmamux_channel_type *edmamux_channelx, edmamux_requst_id_sel_type edmamux_req_id) { + edmamux_channelx->muxctrl_bit.reqsel = edmamux_req_id; } /** @@ -762,13 +697,12 @@ void edmamux_init(edmamux_channel_type *edmamux_channelx, edmamux_requst_id_sel_ * @param edmamux_sync_init_struct: pointer to a edmamux_sync_init_type structure which will be initialized. * @retval none. */ -void edmamux_sync_default_para_init(edmamux_sync_init_type *edmamux_sync_init_struct) -{ - edmamux_sync_init_struct->sync_enable = FALSE; - edmamux_sync_init_struct->sync_event_enable = FALSE; - edmamux_sync_init_struct->sync_polarity = EDMAMUX_SYNC_POLARITY_DISABLE; - edmamux_sync_init_struct->sync_request_number = 0x0; - edmamux_sync_init_struct->sync_signal_sel = EDMAMUX_SYNC_ID_EXINT0; +void edmamux_sync_default_para_init(edmamux_sync_init_type *edmamux_sync_init_struct) { + edmamux_sync_init_struct->sync_enable = FALSE; + edmamux_sync_init_struct->sync_event_enable = FALSE; + edmamux_sync_init_struct->sync_polarity = EDMAMUX_SYNC_POLARITY_DISABLE; + edmamux_sync_init_struct->sync_request_number = 0x0; + edmamux_sync_init_struct->sync_signal_sel = EDMAMUX_SYNC_ID_EXINT0; } /** @@ -786,13 +720,12 @@ void edmamux_sync_default_para_init(edmamux_sync_init_type *edmamux_sync_init_st * @param edmamux_sync_init_struct: ointer to a edmamux_sync_init_type structure. * @retval none. */ -void edmamux_sync_config(edmamux_channel_type *edmamux_channelx, edmamux_sync_init_type *edmamux_sync_init_struct) -{ - edmamux_channelx->muxctrl_bit.syncsel = edmamux_sync_init_struct->sync_signal_sel; - edmamux_channelx->muxctrl_bit.syncpol = edmamux_sync_init_struct->sync_polarity; - edmamux_channelx->muxctrl_bit.reqcnt = edmamux_sync_init_struct->sync_request_number - 1; - edmamux_channelx->muxctrl_bit.evtgen = edmamux_sync_init_struct->sync_event_enable; - edmamux_channelx->muxctrl_bit.syncen = edmamux_sync_init_struct->sync_enable; +void edmamux_sync_config(edmamux_channel_type *edmamux_channelx, edmamux_sync_init_type *edmamux_sync_init_struct) { + edmamux_channelx->muxctrl_bit.syncsel = edmamux_sync_init_struct->sync_signal_sel; + edmamux_channelx->muxctrl_bit.syncpol = edmamux_sync_init_struct->sync_polarity; + edmamux_channelx->muxctrl_bit.reqcnt = edmamux_sync_init_struct->sync_request_number - 1; + edmamux_channelx->muxctrl_bit.evtgen = edmamux_sync_init_struct->sync_event_enable; + edmamux_channelx->muxctrl_bit.syncen = edmamux_sync_init_struct->sync_enable; } /** @@ -800,12 +733,11 @@ void edmamux_sync_config(edmamux_channel_type *edmamux_channelx, edmamux_sync_in * @param edmamux_gen_init_struct: pointer to a edmamux_gen_init_type structure which will be initialized. * @retval none. */ -void edmamux_generator_default_para_init(edmamux_gen_init_type *edmamux_gen_init_struct) -{ - edmamux_gen_init_struct->gen_enable = FALSE; - edmamux_gen_init_struct->gen_polarity = EDMAMUX_GEN_POLARITY_DISABLE; - edmamux_gen_init_struct->gen_request_number = 0x0; - edmamux_gen_init_struct->gen_signal_sel = EDMAMUX_GEN_ID_EXINT0; +void edmamux_generator_default_para_init(edmamux_gen_init_type *edmamux_gen_init_struct) { + edmamux_gen_init_struct->gen_enable = FALSE; + edmamux_gen_init_struct->gen_polarity = EDMAMUX_GEN_POLARITY_DISABLE; + edmamux_gen_init_struct->gen_request_number = 0x0; + edmamux_gen_init_struct->gen_signal_sel = EDMAMUX_GEN_ID_EXINT0; } /** @@ -813,12 +745,11 @@ void edmamux_generator_default_para_init(edmamux_gen_init_type *edmamux_gen_init * @param edmamux_gen_init_struct: pointer to a edmamux_gen_init_type structure which will be initialized. * @retval none. */ -void edmamux_generator_config(edmamux_generator_type *edmamux_gen_x, edmamux_gen_init_type *edmamux_gen_init_struct) -{ - edmamux_gen_x->gctrl_bit.sigsel = edmamux_gen_init_struct->gen_signal_sel; - edmamux_gen_x->gctrl_bit.gpol = edmamux_gen_init_struct->gen_polarity; - edmamux_gen_x->gctrl_bit.greqcnt = edmamux_gen_init_struct->gen_request_number - 1; - edmamux_gen_x->gctrl_bit.gen = edmamux_gen_init_struct->gen_enable; +void edmamux_generator_config(edmamux_generator_type *edmamux_gen_x, edmamux_gen_init_type *edmamux_gen_init_struct) { + edmamux_gen_x->gctrl_bit.sigsel = edmamux_gen_init_struct->gen_signal_sel; + edmamux_gen_x->gctrl_bit.gpol = edmamux_gen_init_struct->gen_polarity; + edmamux_gen_x->gctrl_bit.greqcnt = edmamux_gen_init_struct->gen_request_number - 1; + edmamux_gen_x->gctrl_bit.gen = edmamux_gen_init_struct->gen_enable; } /** @@ -836,16 +767,12 @@ void edmamux_generator_config(edmamux_generator_type *edmamux_gen_x, edmamux_gen * @param new_state (TRUE or FALSE). * @retval none. */ -void edmamux_sync_interrupt_enable(edmamux_channel_type *edmamux_channelx, confirm_state new_state) -{ - if(new_state != FALSE) - { - edmamux_channelx->muxctrl_bit.syncovien = TRUE; - } - else - { - edmamux_channelx->muxctrl_bit.syncovien = FALSE; - } +void edmamux_sync_interrupt_enable(edmamux_channel_type *edmamux_channelx, confirm_state new_state) { + if (new_state != FALSE) { + edmamux_channelx->muxctrl_bit.syncovien = TRUE; + } else { + edmamux_channelx->muxctrl_bit.syncovien = FALSE; + } } /** @@ -859,16 +786,12 @@ void edmamux_sync_interrupt_enable(edmamux_channel_type *edmamux_channelx, confi * @param new_state (TRUE or FALSE). * @retval none. */ -void edmamux_generator_interrupt_enable(edmamux_generator_type *edmamux_gen_x, confirm_state new_state) -{ - if(new_state != FALSE) - { - edmamux_gen_x->gctrl_bit.trgovien = TRUE; - } - else - { - edmamux_gen_x->gctrl_bit.trgovien = FALSE; - } +void edmamux_generator_interrupt_enable(edmamux_generator_type *edmamux_gen_x, confirm_state new_state) { + if (new_state != FALSE) { + edmamux_gen_x->gctrl_bit.trgovien = TRUE; + } else { + edmamux_gen_x->gctrl_bit.trgovien = FALSE; + } } /** @@ -885,16 +808,12 @@ void edmamux_generator_interrupt_enable(edmamux_generator_type *edmamux_gen_x, c * - EDMAMUX_SYNC_OV8_FLAG * @retval state of edmamux sync flag. */ -flag_status edmamux_sync_flag_get(uint32_t flag) -{ - if((EDMA->muxsyncsts & flag) != RESET) - { - return SET; - } - else - { - return RESET; - } +flag_status edmamux_sync_flag_get(uint32_t flag) { + if ((EDMA->muxsyncsts & flag) != RESET) { + return SET; + } else { + return RESET; + } } /** @@ -911,47 +830,31 @@ flag_status edmamux_sync_flag_get(uint32_t flag) * - EDMAMUX_SYNC_OV8_FLAG * @retval state of edmamux sync flag. */ -flag_status edmamux_sync_interrupt_flag_get(uint32_t flag) -{ - uint32_t int_stat = 0; - - if(flag == EDMAMUX_SYNC_OV1_FLAG) - { - int_stat = (uint32_t)EDMAMUX_CHANNEL1->muxctrl_bit.syncovien; - } - else if(flag == EDMAMUX_SYNC_OV2_FLAG) - { - int_stat = (uint32_t)EDMAMUX_CHANNEL2->muxctrl_bit.syncovien; - } - else if(flag == EDMAMUX_SYNC_OV3_FLAG) - { - int_stat = (uint32_t)EDMAMUX_CHANNEL3->muxctrl_bit.syncovien; - } - else if(flag == EDMAMUX_SYNC_OV4_FLAG) - { - int_stat = (uint32_t)EDMAMUX_CHANNEL4->muxctrl_bit.syncovien; - } - else if(flag == EDMAMUX_SYNC_OV5_FLAG) - { - int_stat = (uint32_t)EDMAMUX_CHANNEL5->muxctrl_bit.syncovien; - } - else if(flag == EDMAMUX_SYNC_OV6_FLAG) - { - int_stat = (uint32_t)EDMAMUX_CHANNEL6->muxctrl_bit.syncovien; - } - else if(flag == EDMAMUX_SYNC_OV7_FLAG) - { - int_stat = (uint32_t)EDMAMUX_CHANNEL7->muxctrl_bit.syncovien; - } - else - { - int_stat = (uint32_t)EDMAMUX_CHANNEL8->muxctrl_bit.syncovien; - } - - if((int_stat != RESET) && ((EDMA->muxsyncsts & flag) != RESET)) - return SET; - else - return RESET; +flag_status edmamux_sync_interrupt_flag_get(uint32_t flag) { + uint32_t int_stat = 0; + + if (flag == EDMAMUX_SYNC_OV1_FLAG) { + int_stat = (uint32_t)EDMAMUX_CHANNEL1->muxctrl_bit.syncovien; + } else if (flag == EDMAMUX_SYNC_OV2_FLAG) { + int_stat = (uint32_t)EDMAMUX_CHANNEL2->muxctrl_bit.syncovien; + } else if (flag == EDMAMUX_SYNC_OV3_FLAG) { + int_stat = (uint32_t)EDMAMUX_CHANNEL3->muxctrl_bit.syncovien; + } else if (flag == EDMAMUX_SYNC_OV4_FLAG) { + int_stat = (uint32_t)EDMAMUX_CHANNEL4->muxctrl_bit.syncovien; + } else if (flag == EDMAMUX_SYNC_OV5_FLAG) { + int_stat = (uint32_t)EDMAMUX_CHANNEL5->muxctrl_bit.syncovien; + } else if (flag == EDMAMUX_SYNC_OV6_FLAG) { + int_stat = (uint32_t)EDMAMUX_CHANNEL6->muxctrl_bit.syncovien; + } else if (flag == EDMAMUX_SYNC_OV7_FLAG) { + int_stat = (uint32_t)EDMAMUX_CHANNEL7->muxctrl_bit.syncovien; + } else { + int_stat = (uint32_t)EDMAMUX_CHANNEL8->muxctrl_bit.syncovien; + } + + if ((int_stat != RESET) && ((EDMA->muxsyncsts & flag) != RESET)) + return SET; + else + return RESET; } /** @@ -968,9 +871,8 @@ flag_status edmamux_sync_interrupt_flag_get(uint32_t flag) * - EDMAMUX_SYNC_OV8_FLAG * @retval none. */ -void edmamux_sync_flag_clear(uint32_t flag) -{ - EDMA->muxsyncclr = flag; +void edmamux_sync_flag_clear(uint32_t flag) { + EDMA->muxsyncclr = flag; } /** @@ -983,16 +885,12 @@ void edmamux_sync_flag_clear(uint32_t flag) * - EDMAMUX_GEN_TRIG_OV4_FLAG * @retval state of edmamux sync flag. */ -flag_status edmamux_generator_flag_get(uint32_t flag) -{ - if((EDMA->muxgsts & flag) != RESET) - { - return SET; - } - else - { - return RESET; - } +flag_status edmamux_generator_flag_get(uint32_t flag) { + if ((EDMA->muxgsts & flag) != RESET) { + return SET; + } else { + return RESET; + } } /** @@ -1005,31 +903,23 @@ flag_status edmamux_generator_flag_get(uint32_t flag) * - EDMAMUX_GEN_TRIG_OV4_FLAG * @retval state of edmamux sync flag. */ -flag_status edmamux_generator_interrupt_flag_get(uint32_t flag) -{ - uint32_t int_stat = 0; - - if(flag == EDMAMUX_GEN_TRIG_OV1_FLAG) - { - int_stat = EDMAMUX_GENERATOR1->gctrl_bit.trgovien; - } - else if(flag == EDMAMUX_GEN_TRIG_OV2_FLAG) - { - int_stat = EDMAMUX_GENERATOR2->gctrl_bit.trgovien; - } - else if(flag == EDMAMUX_GEN_TRIG_OV3_FLAG) - { - int_stat = EDMAMUX_GENERATOR3->gctrl_bit.trgovien; - } - else - { - int_stat = EDMAMUX_GENERATOR4->gctrl_bit.trgovien; - } - - if((int_stat != RESET) && ((EDMA->muxgsts & flag) != RESET)) - return SET; - else - return RESET; +flag_status edmamux_generator_interrupt_flag_get(uint32_t flag) { + uint32_t int_stat = 0; + + if (flag == EDMAMUX_GEN_TRIG_OV1_FLAG) { + int_stat = EDMAMUX_GENERATOR1->gctrl_bit.trgovien; + } else if (flag == EDMAMUX_GEN_TRIG_OV2_FLAG) { + int_stat = EDMAMUX_GENERATOR2->gctrl_bit.trgovien; + } else if (flag == EDMAMUX_GEN_TRIG_OV3_FLAG) { + int_stat = EDMAMUX_GENERATOR3->gctrl_bit.trgovien; + } else { + int_stat = EDMAMUX_GENERATOR4->gctrl_bit.trgovien; + } + + if ((int_stat != RESET) && ((EDMA->muxgsts & flag) != RESET)) + return SET; + else + return RESET; } /** @@ -1042,9 +932,8 @@ flag_status edmamux_generator_interrupt_flag_get(uint32_t flag) * - EDMAMUX_GEN_TRIG_OV4_FLAG * @retval none. */ -void edmamux_generator_flag_clear(uint32_t flag) -{ - EDMA->muxgclr = flag; +void edmamux_generator_flag_clear(uint32_t flag) { + EDMA->muxgclr = flag; } /** diff --git a/armlib/at32_sys/drivers/src/at32f435_437_emac.c b/armlib/at32_sys/drivers/src/at32f435_437_emac.c index 3685ca2b2..5ba666e55 100644 --- a/armlib/at32_sys/drivers/src/at32f435_437_emac.c +++ b/armlib/at32_sys/drivers/src/at32f435_437_emac.c @@ -56,10 +56,9 @@ static void emac_delay(uint32_t delay); * @param none * @retval none */ -void emac_reset(void) -{ - crm_periph_reset(CRM_EMAC_PERIPH_RESET, TRUE); - crm_periph_reset(CRM_EMAC_PERIPH_RESET, FALSE); +void emac_reset(void) { + crm_periph_reset(CRM_EMAC_PERIPH_RESET, TRUE); + crm_periph_reset(CRM_EMAC_PERIPH_RESET, FALSE); } /** @@ -67,22 +66,21 @@ void emac_reset(void) * @param emac_control_config_type * @retval none */ -void emac_control_para_init(emac_control_config_type *control_para) -{ - control_para->auto_nego = EMAC_AUTO_NEGOTIATION_OFF; - control_para->auto_pad_crc_strip = FALSE; - control_para->back_off_limit = EMAC_BACKOFF_LIMIT_0; - control_para->carrier_sense_disable = FALSE; - control_para->deferral_check = FALSE; - control_para->duplex_mode = EMAC_HALF_DUPLEX; - control_para->fast_ethernet_speed = EMAC_SPEED_10MBPS; - control_para->interframe_gap = EMAC_INTERFRAME_GAP_96BIT; - control_para->ipv4_checksum_offload = FALSE; - control_para->jabber_disable = FALSE; - control_para->loopback_mode = FALSE; - control_para->receive_own_disable = FALSE; - control_para->retry_disable = FALSE; - control_para->watchdog_disable = FALSE; +void emac_control_para_init(emac_control_config_type *control_para) { + control_para->auto_nego = EMAC_AUTO_NEGOTIATION_OFF; + control_para->auto_pad_crc_strip = FALSE; + control_para->back_off_limit = EMAC_BACKOFF_LIMIT_0; + control_para->carrier_sense_disable = FALSE; + control_para->deferral_check = FALSE; + control_para->duplex_mode = EMAC_HALF_DUPLEX; + control_para->fast_ethernet_speed = EMAC_SPEED_10MBPS; + control_para->interframe_gap = EMAC_INTERFRAME_GAP_96BIT; + control_para->ipv4_checksum_offload = FALSE; + control_para->jabber_disable = FALSE; + control_para->loopback_mode = FALSE; + control_para->receive_own_disable = FALSE; + control_para->retry_disable = FALSE; + control_para->watchdog_disable = FALSE; } /** @@ -90,42 +88,30 @@ void emac_control_para_init(emac_control_config_type *control_para) * @param none * @retval none */ -void emac_clock_range_set(void) -{ - uint8_t bits_value = 0; - crm_clocks_freq_type clocks_freq = {0}; +void emac_clock_range_set(void) { + uint8_t bits_value = 0; + crm_clocks_freq_type clocks_freq = {0}; - /* clear clock range bits */ - EMAC->miiaddr_bit.cr = bits_value; + /* clear clock range bits */ + EMAC->miiaddr_bit.cr = bits_value; - crm_clocks_freq_get(&clocks_freq); + crm_clocks_freq_get(&clocks_freq); - if((clocks_freq.ahb_freq >= EMAC_HCLK_BORDER_20MHZ) && (clocks_freq.ahb_freq < EMAC_HCLK_BORDER_35MHZ)) - { - bits_value = EMAC_CLOCK_RANGE_20_TO_35; - } - else if((clocks_freq.ahb_freq >= EMAC_HCLK_BORDER_35MHZ) && (clocks_freq.ahb_freq < EMAC_HCLK_BORDER_60MHZ)) - { - bits_value = EMAC_CLOCK_RANGE_35_TO_60; - } - else if((clocks_freq.ahb_freq >= EMAC_HCLK_BORDER_60MHZ) && (clocks_freq.ahb_freq < EMAC_HCLK_BORDER_100MHZ)) - { - bits_value = EMAC_CLOCK_RANGE_60_TO_100; - } - else if((clocks_freq.ahb_freq >= EMAC_HCLK_BORDER_100MHZ) && (clocks_freq.ahb_freq < EMAC_HCLK_BORDER_150MHZ)) - { - bits_value = EMAC_CLOCK_RANGE_100_TO_150; - } - else if((clocks_freq.ahb_freq >= EMAC_HCLK_BORDER_150MHZ) && (clocks_freq.ahb_freq < EMAC_HCLK_BORDER_250MHZ)) - { - bits_value = EMAC_CLOCK_RANGE_150_TO_250; - } - else if((clocks_freq.ahb_freq >= EMAC_HCLK_BORDER_250MHZ) && (clocks_freq.ahb_freq <= EMAC_HCLK_BORDER_288MHZ)) - { - bits_value = EMAC_CLOCK_RANGE_250_TO_288; - } + if ((clocks_freq.ahb_freq >= EMAC_HCLK_BORDER_20MHZ) && (clocks_freq.ahb_freq < EMAC_HCLK_BORDER_35MHZ)) { + bits_value = EMAC_CLOCK_RANGE_20_TO_35; + } else if ((clocks_freq.ahb_freq >= EMAC_HCLK_BORDER_35MHZ) && (clocks_freq.ahb_freq < EMAC_HCLK_BORDER_60MHZ)) { + bits_value = EMAC_CLOCK_RANGE_35_TO_60; + } else if ((clocks_freq.ahb_freq >= EMAC_HCLK_BORDER_60MHZ) && (clocks_freq.ahb_freq < EMAC_HCLK_BORDER_100MHZ)) { + bits_value = EMAC_CLOCK_RANGE_60_TO_100; + } else if ((clocks_freq.ahb_freq >= EMAC_HCLK_BORDER_100MHZ) && (clocks_freq.ahb_freq < EMAC_HCLK_BORDER_150MHZ)) { + bits_value = EMAC_CLOCK_RANGE_100_TO_150; + } else if ((clocks_freq.ahb_freq >= EMAC_HCLK_BORDER_150MHZ) && (clocks_freq.ahb_freq < EMAC_HCLK_BORDER_250MHZ)) { + bits_value = EMAC_CLOCK_RANGE_150_TO_250; + } else if ((clocks_freq.ahb_freq >= EMAC_HCLK_BORDER_250MHZ) && (clocks_freq.ahb_freq <= EMAC_HCLK_BORDER_288MHZ)) { + bits_value = EMAC_CLOCK_RANGE_250_TO_288; + } - EMAC->miiaddr_bit.cr = bits_value; + EMAC->miiaddr_bit.cr = bits_value; } /** @@ -133,19 +119,18 @@ void emac_clock_range_set(void) * @param control_struct: control setting of mac control register. * @retval none */ -void emac_control_config(emac_control_config_type *control_struct) -{ - emac_deferral_check_set(control_struct->deferral_check); - emac_backoff_limit_set(control_struct->back_off_limit); - emac_auto_pad_crc_stripping_set(control_struct->auto_pad_crc_strip); - emac_retry_disable(control_struct->retry_disable); - emac_ipv4_checksum_offload_set(control_struct->ipv4_checksum_offload); - emac_loopback_mode_enable(control_struct->loopback_mode); - emac_receive_own_disable(control_struct->receive_own_disable); - emac_carrier_sense_disable(control_struct->carrier_sense_disable); - emac_interframe_gap_set(control_struct->interframe_gap); - emac_jabber_disable(control_struct->jabber_disable); - emac_watchdog_disable(control_struct->watchdog_disable); +void emac_control_config(emac_control_config_type *control_struct) { + emac_deferral_check_set(control_struct->deferral_check); + emac_backoff_limit_set(control_struct->back_off_limit); + emac_auto_pad_crc_stripping_set(control_struct->auto_pad_crc_strip); + emac_retry_disable(control_struct->retry_disable); + emac_ipv4_checksum_offload_set(control_struct->ipv4_checksum_offload); + emac_loopback_mode_enable(control_struct->loopback_mode); + emac_receive_own_disable(control_struct->receive_own_disable); + emac_carrier_sense_disable(control_struct->carrier_sense_disable); + emac_interframe_gap_set(control_struct->interframe_gap); + emac_jabber_disable(control_struct->jabber_disable); + emac_watchdog_disable(control_struct->watchdog_disable); } /** @@ -153,9 +138,8 @@ void emac_control_config(emac_control_config_type *control_struct) * @param none * @retval none */ -void emac_dma_software_reset_set(void) -{ - EMAC_DMA->bm_bit.swr = 1; +void emac_dma_software_reset_set(void) { + EMAC_DMA->bm_bit.swr = 1; } /** @@ -163,16 +147,12 @@ void emac_dma_software_reset_set(void) * @param none * @retval TRUE of FALSE */ -flag_status emac_dma_software_reset_get(void) -{ - if(EMAC_DMA->bm_bit.swr) - { - return SET; - } - else - { - return RESET; - } +flag_status emac_dma_software_reset_get(void) { + if (EMAC_DMA->bm_bit.swr) { + return SET; + } else { + return RESET; + } } /** @@ -180,22 +160,21 @@ flag_status emac_dma_software_reset_get(void) * @param none * @retval none */ -void emac_start(void) -{ - /* enable transmit state machine of the mac for transmission on the mii */ - emac_trasmitter_enable(TRUE); +void emac_start(void) { + /* enable transmit state machine of the mac for transmission on the mii */ + emac_trasmitter_enable(TRUE); - /* flush transmit fifo */ - emac_dma_operations_set(EMAC_DMA_OPS_FLUSH_TRANSMIT_FIFO, TRUE); + /* flush transmit fifo */ + emac_dma_operations_set(EMAC_DMA_OPS_FLUSH_TRANSMIT_FIFO, TRUE); - /* enable receive state machine of the mac for reception from the mii */ - emac_receiver_enable(TRUE); + /* enable receive state machine of the mac for reception from the mii */ + emac_receiver_enable(TRUE); - /* start dma transmission */ - emac_dma_operations_set(EMAC_DMA_OPS_START_STOP_TRANSMIT, TRUE); + /* start dma transmission */ + emac_dma_operations_set(EMAC_DMA_OPS_START_STOP_TRANSMIT, TRUE); - /* start dma reception */ - emac_dma_operations_set(EMAC_DMA_OPS_START_STOP_RECEIVE, TRUE); + /* start dma reception */ + emac_dma_operations_set(EMAC_DMA_OPS_START_STOP_RECEIVE, TRUE); } /** @@ -203,22 +182,21 @@ void emac_start(void) * @param none * @retval none */ -void emac_stop(void) -{ - /* stop dma transmission */ - emac_dma_operations_set(EMAC_DMA_OPS_START_STOP_TRANSMIT, FALSE); +void emac_stop(void) { + /* stop dma transmission */ + emac_dma_operations_set(EMAC_DMA_OPS_START_STOP_TRANSMIT, FALSE); - /* stop dma reception */ - emac_dma_operations_set(EMAC_DMA_OPS_START_STOP_RECEIVE, FALSE); + /* stop dma reception */ + emac_dma_operations_set(EMAC_DMA_OPS_START_STOP_RECEIVE, FALSE); - /* stop receive state machine of the mac for reception from the mii */ - emac_receiver_enable(FALSE); + /* stop receive state machine of the mac for reception from the mii */ + emac_receiver_enable(FALSE); - /* flush transmit fifo */ - emac_dma_operations_set(EMAC_DMA_OPS_FLUSH_TRANSMIT_FIFO, TRUE); + /* flush transmit fifo */ + emac_dma_operations_set(EMAC_DMA_OPS_FLUSH_TRANSMIT_FIFO, TRUE); - /* stop transmit state machine of the mac for transmission on the mii */ - emac_trasmitter_enable(FALSE); + /* stop transmit state machine of the mac for transmission on the mii */ + emac_trasmitter_enable(FALSE); } /** @@ -228,27 +206,24 @@ void emac_stop(void) * @param data: value that wants to write to phy. * @retval SUCCESS or ERROR */ -error_status emac_phy_register_write(uint8_t address, uint8_t reg, uint16_t data) -{ - uint32_t timeout = 0; +error_status emac_phy_register_write(uint8_t address, uint8_t reg, uint16_t data) { + uint32_t timeout = 0; - EMAC->miidt_bit.md = data; + EMAC->miidt_bit.md = data; - EMAC->miiaddr_bit.pa = address; - EMAC->miiaddr_bit.mii = reg; - EMAC->miiaddr_bit.mw = 1; - EMAC->miiaddr_bit.mb = 1; + EMAC->miiaddr_bit.pa = address; + EMAC->miiaddr_bit.mii = reg; + EMAC->miiaddr_bit.mw = 1; + EMAC->miiaddr_bit.mb = 1; - do - { - timeout++; - } while((EMAC->miiaddr_bit.mb) && (timeout < PHY_TIMEOUT)); + do { + timeout++; + } while ((EMAC->miiaddr_bit.mb) && (timeout < PHY_TIMEOUT)); - if(timeout == PHY_TIMEOUT) - { - return ERROR; - } - return SUCCESS; + if (timeout == PHY_TIMEOUT) { + return ERROR; + } + return SUCCESS; } /** @@ -258,28 +233,25 @@ error_status emac_phy_register_write(uint8_t address, uint8_t reg, uint16_t data * @param data: value that is read from phy. * @retval SUCCESS or ERROR */ -error_status emac_phy_register_read(uint8_t address, uint8_t reg, uint16_t *data) -{ - uint32_t timeout = 0; +error_status emac_phy_register_read(uint8_t address, uint8_t reg, uint16_t *data) { + uint32_t timeout = 0; - EMAC->miiaddr_bit.pa = address; - EMAC->miiaddr_bit.mii = reg; - EMAC->miiaddr_bit.mw = 0; - EMAC->miiaddr_bit.mb = 1; + EMAC->miiaddr_bit.pa = address; + EMAC->miiaddr_bit.mii = reg; + EMAC->miiaddr_bit.mw = 0; + EMAC->miiaddr_bit.mb = 1; + + do { + timeout++; + *data = EMAC->miidt_bit.md; + } while ((EMAC->miiaddr_bit.mb) && (timeout < PHY_TIMEOUT)); + + if (timeout == PHY_TIMEOUT) { + return ERROR; + } - do - { - timeout++; *data = EMAC->miidt_bit.md; - } while((EMAC->miiaddr_bit.mb) && (timeout < PHY_TIMEOUT)); - - if(timeout == PHY_TIMEOUT) - { - return ERROR; - } - - *data = EMAC->miidt_bit.md; - return SUCCESS; + return SUCCESS; } /** @@ -287,15 +259,14 @@ error_status emac_phy_register_read(uint8_t address, uint8_t reg, uint16_t *data * @param new_state: TRUE or FALSE. * @retval none */ -void emac_receiver_enable(confirm_state new_state) -{ - __IO uint32_t temp = 0; +void emac_receiver_enable(confirm_state new_state) { + __IO uint32_t temp = 0; - EMAC->ctrl_bit.re = new_state; + EMAC->ctrl_bit.re = new_state; - temp = EMAC->ctrl; - emac_delay(1); - EMAC->ctrl = temp; + temp = EMAC->ctrl; + emac_delay(1); + EMAC->ctrl = temp; } /** @@ -303,15 +274,14 @@ void emac_receiver_enable(confirm_state new_state) * @param new_state: TRUE or FALSE. * @retval none */ -void emac_trasmitter_enable(confirm_state new_state) -{ - __IO uint32_t temp = 0; +void emac_trasmitter_enable(confirm_state new_state) { + __IO uint32_t temp = 0; - EMAC->ctrl_bit.te = new_state; + EMAC->ctrl_bit.te = new_state; - temp = EMAC->ctrl; - emac_delay(1); - EMAC->ctrl = temp; + temp = EMAC->ctrl; + emac_delay(1); + EMAC->ctrl = temp; } /** @@ -319,9 +289,8 @@ void emac_trasmitter_enable(confirm_state new_state) * @param new_state: TRUE or FALSE. * @retval none */ -void emac_deferral_check_set(confirm_state new_state) -{ - EMAC->ctrl_bit.dc = new_state; +void emac_deferral_check_set(confirm_state new_state) { + EMAC->ctrl_bit.dc = new_state; } /** @@ -334,9 +303,8 @@ void emac_deferral_check_set(confirm_state new_state) * - EMAC_BACKOFF_LIMIT_3 * @retval none */ -void emac_backoff_limit_set(emac_bol_type slot_time) -{ - EMAC->ctrl_bit.bl = slot_time; +void emac_backoff_limit_set(emac_bol_type slot_time) { + EMAC->ctrl_bit.bl = slot_time; } /** @@ -344,9 +312,8 @@ void emac_backoff_limit_set(emac_bol_type slot_time) * @param new_state: TRUE or FALSE. * @retval none */ -void emac_auto_pad_crc_stripping_set(confirm_state new_state) -{ - EMAC->ctrl_bit.acs = new_state; +void emac_auto_pad_crc_stripping_set(confirm_state new_state) { + EMAC->ctrl_bit.acs = new_state; } /** @@ -354,9 +321,8 @@ void emac_auto_pad_crc_stripping_set(confirm_state new_state) * @param new_state: TRUE or FALSE. * @retval none */ -void emac_retry_disable(confirm_state new_state) -{ - EMAC->ctrl_bit.dr = new_state; +void emac_retry_disable(confirm_state new_state) { + EMAC->ctrl_bit.dr = new_state; } /** @@ -364,9 +330,8 @@ void emac_retry_disable(confirm_state new_state) * @param new_state: TRUE or FALSE. * @retval none */ -void emac_ipv4_checksum_offload_set(confirm_state new_state) -{ - EMAC->ctrl_bit.ipc = new_state; +void emac_ipv4_checksum_offload_set(confirm_state new_state) { + EMAC->ctrl_bit.ipc = new_state; } /** @@ -374,9 +339,8 @@ void emac_ipv4_checksum_offload_set(confirm_state new_state) * @param new_state: TRUE or FALSE. * @retval none */ -void emac_loopback_mode_enable(confirm_state new_state) -{ - EMAC->ctrl_bit.lm = new_state; +void emac_loopback_mode_enable(confirm_state new_state) { + EMAC->ctrl_bit.lm = new_state; } /** @@ -384,9 +348,8 @@ void emac_loopback_mode_enable(confirm_state new_state) * @param new_state: TRUE or FALSE. * @retval none */ -void emac_receive_own_disable(confirm_state new_state) -{ - EMAC->ctrl_bit.dro = new_state; +void emac_receive_own_disable(confirm_state new_state) { + EMAC->ctrl_bit.dro = new_state; } /** @@ -394,9 +357,8 @@ void emac_receive_own_disable(confirm_state new_state) * @param new_state: TRUE or FALSE. * @retval none */ -void emac_carrier_sense_disable(confirm_state new_state) -{ - EMAC->ctrl_bit.dcs = new_state; +void emac_carrier_sense_disable(confirm_state new_state) { + EMAC->ctrl_bit.dcs = new_state; } /** @@ -413,9 +375,8 @@ void emac_carrier_sense_disable(confirm_state new_state) * - EMAC_FRAME_GAP_40BIT * @retval none */ -void emac_interframe_gap_set(emac_intergrame_gap_type number) -{ - EMAC->ctrl_bit.ifg = number; +void emac_interframe_gap_set(emac_intergrame_gap_type number) { + EMAC->ctrl_bit.ifg = number; } /** @@ -423,9 +384,8 @@ void emac_interframe_gap_set(emac_intergrame_gap_type number) * @param new_state: TRUE or FALSE. * @retval none */ -void emac_jabber_disable(confirm_state new_state) -{ - EMAC->ctrl_bit.jd = new_state; +void emac_jabber_disable(confirm_state new_state) { + EMAC->ctrl_bit.jd = new_state; } /** @@ -433,9 +393,8 @@ void emac_jabber_disable(confirm_state new_state) * @param new_state: TRUE or FALSE. * @retval none */ -void emac_watchdog_disable(confirm_state new_state) -{ - EMAC->ctrl_bit.wd = new_state; +void emac_watchdog_disable(confirm_state new_state) { + EMAC->ctrl_bit.wd = new_state; } /** @@ -446,9 +405,8 @@ void emac_watchdog_disable(confirm_state new_state) * - EMAC_SPEED_100MBPS * @retval none */ -void emac_fast_speed_set(emac_speed_type speed) -{ - EMAC->ctrl_bit.fes = speed; +void emac_fast_speed_set(emac_speed_type speed) { + EMAC->ctrl_bit.fes = speed; } /** @@ -459,9 +417,8 @@ void emac_fast_speed_set(emac_speed_type speed) * - EMAC_FULL_DUPLEX * @retval none */ -void emac_duplex_mode_set(emac_duplex_type duplex_mode) -{ - EMAC->ctrl_bit.dm = duplex_mode; +void emac_duplex_mode_set(emac_duplex_type duplex_mode) { + EMAC->ctrl_bit.dm = duplex_mode; } /** @@ -469,9 +426,8 @@ void emac_duplex_mode_set(emac_duplex_type duplex_mode) * @param new_state: TRUE or FALSE. * @retval none */ -void emac_promiscuous_mode_set(confirm_state new_state) -{ - EMAC->frmf_bit.pr = new_state; +void emac_promiscuous_mode_set(confirm_state new_state) { + EMAC->frmf_bit.pr = new_state; } /** @@ -479,9 +435,8 @@ void emac_promiscuous_mode_set(confirm_state new_state) * @param new_state: TRUE or FALSE. * @retval none */ -void emac_hash_unicast_set(confirm_state new_state) -{ - EMAC->frmf_bit.huc = new_state; +void emac_hash_unicast_set(confirm_state new_state) { + EMAC->frmf_bit.huc = new_state; } /** @@ -489,9 +444,8 @@ void emac_hash_unicast_set(confirm_state new_state) * @param new_state: TRUE or FALSE. * @retval none */ -void emac_hash_multicast_set(confirm_state new_state) -{ - EMAC->frmf_bit.hmc = new_state; +void emac_hash_multicast_set(confirm_state new_state) { + EMAC->frmf_bit.hmc = new_state; } /** @@ -499,9 +453,8 @@ void emac_hash_multicast_set(confirm_state new_state) * @param new_state: TRUE or FALSE. * @retval none */ -void emac_dstaddr_inverse_filter_set(confirm_state new_state) -{ - EMAC->frmf_bit.daif = new_state; +void emac_dstaddr_inverse_filter_set(confirm_state new_state) { + EMAC->frmf_bit.daif = new_state; } /** @@ -509,9 +462,8 @@ void emac_dstaddr_inverse_filter_set(confirm_state new_state) * @param new_state: TRUE or FALSE. * @retval none */ -void emac_pass_all_multicasting_set(confirm_state new_state) -{ - EMAC->frmf_bit.pmc = new_state; +void emac_pass_all_multicasting_set(confirm_state new_state) { + EMAC->frmf_bit.pmc = new_state; } /** @@ -519,9 +471,8 @@ void emac_pass_all_multicasting_set(confirm_state new_state) * @param new_state: TRUE or FALSE. * @retval none */ -void emac_broadcast_frames_disable(confirm_state new_state) -{ - EMAC->frmf_bit.dbf = new_state; +void emac_broadcast_frames_disable(confirm_state new_state) { + EMAC->frmf_bit.dbf = new_state; } /** @@ -534,9 +485,8 @@ void emac_broadcast_frames_disable(confirm_state new_state) * - EMAC_CONTROL_FRAME_PASSING_MATCH * @retval none */ -void emac_pass_control_frames_set(emac_control_frames_filter_type condition) -{ - EMAC->frmf_bit.pcf = condition; +void emac_pass_control_frames_set(emac_control_frames_filter_type condition) { + EMAC->frmf_bit.pcf = condition; } /** @@ -544,9 +494,8 @@ void emac_pass_control_frames_set(emac_control_frames_filter_type condition) * @param new_state: TRUE or FALSE. * @retval none */ -void emac_srcaddr_inverse_filter_set(confirm_state new_state) -{ - EMAC->frmf_bit.saif = new_state; +void emac_srcaddr_inverse_filter_set(confirm_state new_state) { + EMAC->frmf_bit.saif = new_state; } /** @@ -554,9 +503,8 @@ void emac_srcaddr_inverse_filter_set(confirm_state new_state) * @param new_state: TRUE or FALSE. * @retval none */ -void emac_srcaddr_filter_set(confirm_state new_state) -{ - EMAC->frmf_bit.saf = new_state; +void emac_srcaddr_filter_set(confirm_state new_state) { + EMAC->frmf_bit.saf = new_state; } /** @@ -564,9 +512,8 @@ void emac_srcaddr_filter_set(confirm_state new_state) * @param new_state: TRUE or FALSE. * @retval none */ -void emac_hash_perfect_filter_set(confirm_state new_state) -{ - EMAC->frmf_bit.hpf = new_state; +void emac_hash_perfect_filter_set(confirm_state new_state) { + EMAC->frmf_bit.hpf = new_state; } /** @@ -574,9 +521,8 @@ void emac_hash_perfect_filter_set(confirm_state new_state) * @param new_state: TRUE or FALSE. * @retval none */ -void emac_receive_all_set(confirm_state new_state) -{ - EMAC->frmf_bit.ra = new_state; +void emac_receive_all_set(confirm_state new_state) { + EMAC->frmf_bit.ra = new_state; } /** @@ -584,9 +530,8 @@ void emac_receive_all_set(confirm_state new_state) * @param high32bits: the highest 32-bit of hash table. * @retval none */ -void emac_hash_table_high32bits_set(uint32_t high32bits) -{ - EMAC->hth_bit.hth = high32bits; +void emac_hash_table_high32bits_set(uint32_t high32bits) { + EMAC->hth_bit.hth = high32bits; } /** @@ -594,9 +539,8 @@ void emac_hash_table_high32bits_set(uint32_t high32bits) * @param low32bits: the lowest 32-bit of hash table. * @retval none */ -void emac_hash_table_low32bits_set(uint32_t low32bits) -{ - EMAC->htl_bit.htl = low32bits; +void emac_hash_table_low32bits_set(uint32_t low32bits) { + EMAC->htl_bit.htl = low32bits; } /** @@ -604,14 +548,12 @@ void emac_hash_table_low32bits_set(uint32_t low32bits) * @param none * @retval SET or RESET */ -flag_status emac_mii_busy_get(void) -{ - if(EMAC->miiaddr_bit.mb) { - return SET; - } - else { - return RESET; - } +flag_status emac_mii_busy_get(void) { + if (EMAC->miiaddr_bit.mb) { + return SET; + } else { + return RESET; + } } /** @@ -619,9 +561,8 @@ flag_status emac_mii_busy_get(void) * @param new_state: TRUE or FALSE. * @retval none */ -void emac_mii_write(confirm_state new_state) -{ - EMAC->miiaddr_bit.mw = new_state; +void emac_mii_write(confirm_state new_state) { + EMAC->miiaddr_bit.mw = new_state; } /** @@ -629,9 +570,8 @@ void emac_mii_write(confirm_state new_state) * @param new_state: TRUE or FALSE. * @retval none */ -void emac_fcb_bpa_set(confirm_state new_state) -{ - EMAC->fctrl_bit.fcbbpa = new_state; +void emac_fcb_bpa_set(confirm_state new_state) { + EMAC->fctrl_bit.fcbbpa = new_state; } /** @@ -639,9 +579,8 @@ void emac_fcb_bpa_set(confirm_state new_state) * @param new_state: TRUE or FALSE. * @retval none */ -void emac_transmit_flow_control_enable(confirm_state new_state) -{ - EMAC->fctrl_bit.etf = new_state; +void emac_transmit_flow_control_enable(confirm_state new_state) { + EMAC->fctrl_bit.etf = new_state; } /** @@ -649,9 +588,8 @@ void emac_transmit_flow_control_enable(confirm_state new_state) * @param new_state: TRUE or FALSE. * @retval none */ -void emac_receive_flow_control_enable(confirm_state new_state) -{ - EMAC->fctrl_bit.erf = new_state; +void emac_receive_flow_control_enable(confirm_state new_state) { + EMAC->fctrl_bit.erf = new_state; } /** @@ -659,9 +597,8 @@ void emac_receive_flow_control_enable(confirm_state new_state) * @param new_state: TRUE or FALSE. * @retval none */ -void emac_unicast_pause_frame_detect(confirm_state new_state) -{ - EMAC->fctrl_bit.dup = new_state; +void emac_unicast_pause_frame_detect(confirm_state new_state) { + EMAC->fctrl_bit.dup = new_state; } /** @@ -674,9 +611,8 @@ void emac_unicast_pause_frame_detect(confirm_state new_state) * - EMAC_PAUSE_256_SLOT_TIME * @retval none */ -void emac_pause_low_threshold_set(emac_pause_slot_threshold_type pasue_threshold) -{ - EMAC->fctrl_bit.plt = pasue_threshold; +void emac_pause_low_threshold_set(emac_pause_slot_threshold_type pasue_threshold) { + EMAC->fctrl_bit.plt = pasue_threshold; } /** @@ -684,9 +620,8 @@ void emac_pause_low_threshold_set(emac_pause_slot_threshold_type pasue_threshold * @param new_state: TRUE or FALSE. * @retval none */ -void emac_zero_quanta_pause_disable(confirm_state new_state) -{ - EMAC->fctrl_bit.dzqp = new_state; +void emac_zero_quanta_pause_disable(confirm_state new_state) { + EMAC->fctrl_bit.dzqp = new_state; } /** @@ -694,9 +629,8 @@ void emac_zero_quanta_pause_disable(confirm_state new_state) * @param pause_time: time slots to pause transmit frame. * @retval none */ -void emac_pause_time_set(uint16_t pause_time) -{ - EMAC->fctrl_bit.pt = pause_time; +void emac_pause_time_set(uint16_t pause_time) { + EMAC->fctrl_bit.pt = pause_time; } /** @@ -704,9 +638,8 @@ void emac_pause_time_set(uint16_t pause_time) * @param identifier: it will be compared with coming frame. * @retval none */ -void emac_vlan_tag_identifier_set(uint16_t identifier) -{ - EMAC->vlt_bit.vti = identifier; +void emac_vlan_tag_identifier_set(uint16_t identifier) { + EMAC->vlt_bit.vti = identifier; } /** @@ -714,9 +647,8 @@ void emac_vlan_tag_identifier_set(uint16_t identifier) * @param new_state: TRUE or FALSE. * @retval none */ -void emac_vlan_tag_comparison_set(confirm_state new_state) -{ - EMAC->vlt_bit.etv = new_state; +void emac_vlan_tag_comparison_set(confirm_state new_state) { + EMAC->vlt_bit.etv = new_state; } /** @@ -724,9 +656,8 @@ void emac_vlan_tag_comparison_set(confirm_state new_state) * @param value: it will be written to eight non transparent registers. * @retval none */ -void emac_wakeup_frame_set(uint32_t value) -{ - EMAC->rwff = value; +void emac_wakeup_frame_set(uint32_t value) { + EMAC->rwff = value; } /** @@ -734,9 +665,8 @@ void emac_wakeup_frame_set(uint32_t value) * @param none * @retval get value from eight non transparent registers. */ -uint32_t emac_wakeup_frame_get(void) -{ - return (EMAC->rwff); +uint32_t emac_wakeup_frame_get(void) { + return (EMAC->rwff); } /** @@ -744,9 +674,8 @@ uint32_t emac_wakeup_frame_get(void) * @param new_state: TRUE or FALSE. * @retval none */ -void emac_power_down_set(confirm_state new_state) -{ - EMAC->pmtctrlsts_bit.pd = new_state; +void emac_power_down_set(confirm_state new_state) { + EMAC->pmtctrlsts_bit.pd = new_state; } /** @@ -754,9 +683,8 @@ void emac_power_down_set(confirm_state new_state) * @param new_state: TRUE or FALSE. * @retval none */ -void emac_magic_packet_enable(confirm_state new_state) -{ - EMAC->pmtctrlsts_bit.emp = new_state; +void emac_magic_packet_enable(confirm_state new_state) { + EMAC->pmtctrlsts_bit.emp = new_state; } /** @@ -764,9 +692,8 @@ void emac_magic_packet_enable(confirm_state new_state) * @param new_state: TRUE or FALSE. * @retval none */ -void emac_wakeup_frame_enable(confirm_state new_state) -{ - EMAC->pmtctrlsts_bit.erwf = new_state; +void emac_wakeup_frame_enable(confirm_state new_state) { + EMAC->pmtctrlsts_bit.erwf = new_state; } /** @@ -774,16 +701,12 @@ void emac_wakeup_frame_enable(confirm_state new_state) * @param none * @retval the new state of usart_flag (SET or RESET). */ -flag_status emac_received_magic_packet_get(void) -{ - if(EMAC->pmtctrlsts_bit.rmp) - { - return SET; - } - else - { - return RESET; - } +flag_status emac_received_magic_packet_get(void) { + if (EMAC->pmtctrlsts_bit.rmp) { + return SET; + } else { + return RESET; + } } /** @@ -791,16 +714,12 @@ flag_status emac_received_magic_packet_get(void) * @param none * @retval the new state of usart_flag (SET or RESET). */ -flag_status emac_received_wakeup_frame_get(void) -{ - if(EMAC->pmtctrlsts_bit.rrwf) - { - return SET; - } - else - { - return RESET; - } +flag_status emac_received_wakeup_frame_get(void) { + if (EMAC->pmtctrlsts_bit.rrwf) { + return SET; + } else { + return RESET; + } } /** @@ -808,9 +727,8 @@ flag_status emac_received_wakeup_frame_get(void) * @param new_state: TRUE or FALSE. * @retval none */ -void emac_global_unicast_set(confirm_state new_state) -{ - EMAC->pmtctrlsts_bit.guc = new_state; +void emac_global_unicast_set(confirm_state new_state) { + EMAC->pmtctrlsts_bit.guc = new_state; } /** @@ -818,9 +736,8 @@ void emac_global_unicast_set(confirm_state new_state) * @param new_state: TRUE or FALSE. * @retval none */ -void emac_wakeup_frame_filter_reset(confirm_state new_state) -{ - EMAC->pmtctrlsts_bit.rwffpr = new_state; +void emac_wakeup_frame_filter_reset(confirm_state new_state) { + EMAC->pmtctrlsts_bit.rwffpr = new_state; } /** @@ -834,16 +751,12 @@ void emac_wakeup_frame_filter_reset(confirm_state new_state) * - EMAC_TST_FLAG * @retval the new state of usart_flag (SET or RESET). */ -flag_status emac_interrupt_status_read(uint32_t flag) -{ - if(EMAC->ists & flag) - { - return SET; - } - else - { - return RESET; - } +flag_status emac_interrupt_status_read(uint32_t flag) { + if (EMAC->ists & flag) { + return SET; + } else { + return RESET; + } } /** @@ -855,21 +768,17 @@ flag_status emac_interrupt_status_read(uint32_t flag) * @param new_state: TRUE or FALSE. * @retval none */ -void emac_interrupt_mask_set(emac_interrupt_mask_type mask_type, confirm_state new_state) -{ - switch(mask_type) - { - case EMAC_INTERRUPT_PMT_MASK: - { - EMAC->imr_bit.pim = new_state; - break; +void emac_interrupt_mask_set(emac_interrupt_mask_type mask_type, confirm_state new_state) { + switch (mask_type) { + case EMAC_INTERRUPT_PMT_MASK: { + EMAC->imr_bit.pim = new_state; + break; + } + case EMAC_INTERRUPT_TST_MASK: { + EMAC->imr_bit.tim = new_state; + break; + } } - case EMAC_INTERRUPT_TST_MASK: - { - EMAC->imr_bit.tim = new_state; - break; - } - } } /** @@ -877,10 +786,9 @@ void emac_interrupt_mask_set(emac_interrupt_mask_type mask_type, confirm_state n * @param address: local address for mac0 * @retval none */ -void emac_local_address_set(uint8_t *address) -{ - EMAC->a0h_bit.ma0h = (uint32_t)(address[5] << 8 | address[4]); - EMAC->a0l_bit.ma0l = (uint32_t)(address[3] << 24 | address[2] << 16 | address[1] << 8 | address[0]); +void emac_local_address_set(uint8_t *address) { + EMAC->a0h_bit.ma0h = (uint32_t)(address[5] << 8 | address[4]); + EMAC->a0l_bit.ma0l = (uint32_t)(address[3] << 24 | address[2] << 16 | address[1] << 8 | address[0]); } /** @@ -892,32 +800,27 @@ void emac_local_address_set(uint8_t *address) * - EMAC_ADDRESS_FILTER_3 * @retval none */ -void emac_address_filter_set(emac_address_type mac, emac_address_filter_type filter, emac_address_mask_type mask_bit, confirm_state new_state) -{ - switch(mac) - { - case EMAC_ADDRESS_FILTER_1: - { - EMAC->a1h_bit.sa = filter; - EMAC->a1h_bit.mbc = mask_bit; - EMAC->a1h_bit.ae = new_state; - break; +void emac_address_filter_set(emac_address_type mac, emac_address_filter_type filter, emac_address_mask_type mask_bit, confirm_state new_state) { + switch (mac) { + case EMAC_ADDRESS_FILTER_1: { + EMAC->a1h_bit.sa = filter; + EMAC->a1h_bit.mbc = mask_bit; + EMAC->a1h_bit.ae = new_state; + break; + } + case EMAC_ADDRESS_FILTER_2: { + EMAC->a2h_bit.sa = filter; + EMAC->a2h_bit.mbc = mask_bit; + EMAC->a2h_bit.ae = new_state; + break; + } + case EMAC_ADDRESS_FILTER_3: { + EMAC->a3h_bit.sa = filter; + EMAC->a3h_bit.mbc = mask_bit; + EMAC->a3h_bit.ae = new_state; + break; + } } - case EMAC_ADDRESS_FILTER_2: - { - EMAC->a2h_bit.sa = filter; - EMAC->a2h_bit.mbc = mask_bit; - EMAC->a2h_bit.ae = new_state; - break; - } - case EMAC_ADDRESS_FILTER_3: - { - EMAC->a3h_bit.sa = filter; - EMAC->a3h_bit.mbc = mask_bit; - EMAC->a3h_bit.ae = new_state; - break; - } - } } /** @@ -931,62 +834,50 @@ void emac_address_filter_set(emac_address_type mac, emac_address_filter_type fil * @param buffer_count: number of the used Tx desc in the list * @retval none */ -void emac_dma_descriptor_list_address_set(emac_dma_tx_rx_type transfer_type, emac_dma_desc_type *dma_desc_tab, uint8_t *buff, uint32_t buffer_count) -{ - uint32_t i = 0; - emac_dma_desc_type *dma_descriptor; +void emac_dma_descriptor_list_address_set(emac_dma_tx_rx_type transfer_type, emac_dma_desc_type *dma_desc_tab, uint8_t *buff, uint32_t buffer_count) { + uint32_t i = 0; + emac_dma_desc_type *dma_descriptor; - switch(transfer_type) - { - case EMAC_DMA_TRANSMIT: - { - dma_tx_desc_to_set = dma_desc_tab; - for(i = 0; i < buffer_count; i++) - { - dma_descriptor = dma_desc_tab + i; + switch (transfer_type) { + case EMAC_DMA_TRANSMIT: { + dma_tx_desc_to_set = dma_desc_tab; + for (i = 0; i < buffer_count; i++) { + dma_descriptor = dma_desc_tab + i; - dma_descriptor->status = EMAC_DMATXDESC_TCH; + dma_descriptor->status = EMAC_DMATXDESC_TCH; - dma_descriptor->buf1addr = (uint32_t)(&buff[i * EMAC_MAX_PACKET_LENGTH]); + dma_descriptor->buf1addr = (uint32_t)(&buff[i * EMAC_MAX_PACKET_LENGTH]); - if(i < (buffer_count - 1)) - { - dma_descriptor->buf2nextdescaddr = (uint32_t)(dma_desc_tab + i + 1); + if (i < (buffer_count - 1)) { + dma_descriptor->buf2nextdescaddr = (uint32_t)(dma_desc_tab + i + 1); + } else { + dma_descriptor->buf2nextdescaddr = (uint32_t) dma_desc_tab; + } + } + EMAC_DMA->tdladdr_bit.stl = (uint32_t) dma_desc_tab; + break; } - else - { - dma_descriptor->buf2nextdescaddr = (uint32_t) dma_desc_tab; + case EMAC_DMA_RECEIVE: { + dma_rx_desc_to_get = dma_desc_tab; + for (i = 0; i < buffer_count; i++) { + dma_descriptor = dma_desc_tab + i; + + dma_descriptor->status = EMAC_DMARXDESC_OWN; + + dma_descriptor->controlsize = EMAC_DMARXDESC_RCH | (uint32_t)EMAC_MAX_PACKET_LENGTH; + + dma_descriptor->buf1addr = (uint32_t)(&buff[i * EMAC_MAX_PACKET_LENGTH]); + + if (i < (buffer_count - 1)) { + dma_descriptor->buf2nextdescaddr = (uint32_t)(dma_desc_tab + i + 1); + } else { + dma_descriptor->buf2nextdescaddr = (uint32_t) dma_desc_tab; + } + } + EMAC_DMA->rdladdr_bit.srl = (uint32_t) dma_desc_tab; + break; } - } - EMAC_DMA->tdladdr_bit.stl = (uint32_t) dma_desc_tab; - break; } - case EMAC_DMA_RECEIVE: - { - dma_rx_desc_to_get = dma_desc_tab; - for(i = 0; i < buffer_count; i++) - { - dma_descriptor = dma_desc_tab + i; - - dma_descriptor->status = EMAC_DMARXDESC_OWN; - - dma_descriptor->controlsize = EMAC_DMARXDESC_RCH | (uint32_t)EMAC_MAX_PACKET_LENGTH; - - dma_descriptor->buf1addr = (uint32_t)(&buff[i * EMAC_MAX_PACKET_LENGTH]); - - if(i < (buffer_count - 1)) - { - dma_descriptor->buf2nextdescaddr = (uint32_t)(dma_desc_tab + i + 1); - } - else - { - dma_descriptor->buf2nextdescaddr = (uint32_t) dma_desc_tab; - } - } - EMAC_DMA->rdladdr_bit.srl = (uint32_t) dma_desc_tab; - break; - } - } } /** @@ -1000,78 +891,66 @@ void emac_dma_descriptor_list_address_set(emac_dma_tx_rx_type transfer_type, ema * @param buffer_count: number of the used Tx desc in the list * @retval none */ -void emac_ptp_dma_descriptor_list_address_set(emac_dma_tx_rx_type transfer_type, emac_dma_desc_type *dma_desc_tab, emac_dma_desc_type *ptp_dma_desc_tab, uint8_t *buff, uint32_t buffer_count) -{ - uint32_t i = 0; - emac_dma_desc_type *dma_descriptor; +void emac_ptp_dma_descriptor_list_address_set(emac_dma_tx_rx_type transfer_type, emac_dma_desc_type *dma_desc_tab, emac_dma_desc_type *ptp_dma_desc_tab, uint8_t *buff, uint32_t buffer_count) { + uint32_t i = 0; + emac_dma_desc_type *dma_descriptor; - switch(transfer_type) - { - case EMAC_DMA_TRANSMIT: - { - dma_tx_desc_to_set = dma_desc_tab; - ptp_dma_tx_desc_to_set = ptp_dma_desc_tab; - - for(i = 0; i < buffer_count; i++) - { - dma_descriptor = dma_desc_tab + i; + switch (transfer_type) { + case EMAC_DMA_TRANSMIT: { + dma_tx_desc_to_set = dma_desc_tab; + ptp_dma_tx_desc_to_set = ptp_dma_desc_tab; - dma_descriptor->status = EMAC_DMATXDESC_TCH | EMAC_DMATXDESC_TTSE; + for (i = 0; i < buffer_count; i++) { + dma_descriptor = dma_desc_tab + i; - dma_descriptor->buf1addr = (uint32_t)(&buff[i * EMAC_MAX_PACKET_LENGTH]); + dma_descriptor->status = EMAC_DMATXDESC_TCH | EMAC_DMATXDESC_TTSE; - if(i < (buffer_count - 1)) - { - dma_descriptor->buf2nextdescaddr = (uint32_t)(dma_desc_tab + i + 1); + dma_descriptor->buf1addr = (uint32_t)(&buff[i * EMAC_MAX_PACKET_LENGTH]); + + if (i < (buffer_count - 1)) { + dma_descriptor->buf2nextdescaddr = (uint32_t)(dma_desc_tab + i + 1); + } else { + dma_descriptor->buf2nextdescaddr = (uint32_t) dma_desc_tab; + } + + (&ptp_dma_desc_tab[i])->buf1addr = dma_descriptor->buf1addr; + (&ptp_dma_desc_tab[i])->buf2nextdescaddr = dma_descriptor->buf2nextdescaddr; + } + + (&ptp_dma_desc_tab[i - 1])->status = (uint32_t) ptp_dma_desc_tab; + + EMAC_DMA->tdladdr_bit.stl = (uint32_t) dma_desc_tab; + break; } - else - { - dma_descriptor->buf2nextdescaddr = (uint32_t) dma_desc_tab; + case EMAC_DMA_RECEIVE: { + dma_rx_desc_to_get = dma_desc_tab; + ptp_dma_rx_desc_to_get = ptp_dma_desc_tab; + + for (i = 0; i < buffer_count; i++) { + dma_descriptor = dma_desc_tab + i; + + dma_descriptor->status = EMAC_DMARXDESC_OWN; + + dma_descriptor->controlsize = EMAC_DMARXDESC_RCH | (uint32_t)EMAC_MAX_PACKET_LENGTH; + + dma_descriptor->buf1addr = (uint32_t)(&buff[i * EMAC_MAX_PACKET_LENGTH]); + + if (i < (buffer_count - 1)) { + dma_descriptor->buf2nextdescaddr = (uint32_t)(dma_desc_tab + i + 1); + } else { + dma_descriptor->buf2nextdescaddr = (uint32_t) dma_desc_tab; + } + + (&ptp_dma_desc_tab[i])->buf1addr = dma_descriptor->buf1addr; + (&ptp_dma_desc_tab[i])->buf2nextdescaddr = dma_descriptor->buf2nextdescaddr; + } + + (&ptp_dma_desc_tab[i - 1])->status = (uint32_t) ptp_dma_desc_tab; + + EMAC_DMA->rdladdr_bit.srl = (uint32_t) dma_desc_tab; + break; } - - (&ptp_dma_desc_tab[i])->buf1addr = dma_descriptor->buf1addr; - (&ptp_dma_desc_tab[i])->buf2nextdescaddr = dma_descriptor->buf2nextdescaddr; - } - - (&ptp_dma_desc_tab[i-1])->status = (uint32_t) ptp_dma_desc_tab; - - EMAC_DMA->tdladdr_bit.stl = (uint32_t) dma_desc_tab; - break; } - case EMAC_DMA_RECEIVE: - { - dma_rx_desc_to_get = dma_desc_tab; - ptp_dma_rx_desc_to_get = ptp_dma_desc_tab; - - for(i = 0; i < buffer_count; i++) - { - dma_descriptor = dma_desc_tab + i; - - dma_descriptor->status = EMAC_DMARXDESC_OWN; - - dma_descriptor->controlsize = EMAC_DMARXDESC_RCH | (uint32_t)EMAC_MAX_PACKET_LENGTH; - - dma_descriptor->buf1addr = (uint32_t)(&buff[i * EMAC_MAX_PACKET_LENGTH]); - - if(i < (buffer_count - 1)) - { - dma_descriptor->buf2nextdescaddr = (uint32_t)(dma_desc_tab + i + 1); - } - else - { - dma_descriptor->buf2nextdescaddr = (uint32_t) dma_desc_tab; - } - - (&ptp_dma_desc_tab[i])->buf1addr = dma_descriptor->buf1addr; - (&ptp_dma_desc_tab[i])->buf2nextdescaddr = dma_descriptor->buf2nextdescaddr; - } - - (&ptp_dma_desc_tab[i-1])->status = (uint32_t) ptp_dma_desc_tab; - - EMAC_DMA->rdladdr_bit.srl = (uint32_t) dma_desc_tab; - break; - } - } } /** * @brief enable or disable the specified dma rx descriptor receive interrupt @@ -1082,18 +961,14 @@ void emac_ptp_dma_descriptor_list_address_set(emac_dma_tx_rx_type transfer_type, * - FALSE. * @retval none */ -void emac_dma_rx_desc_interrupt_config(emac_dma_desc_type *dma_rx_desc, confirm_state new_state) -{ - if (new_state != FALSE) - { - /* enable the dma rx desc receive interrupt */ - dma_rx_desc->controlsize &= (~(uint32_t)EMAC_DMARXDESC_DIC); - } - else - { - /* disable the dma rx desc receive interrupt */ - dma_rx_desc->controlsize |= EMAC_DMARXDESC_DIC; - } +void emac_dma_rx_desc_interrupt_config(emac_dma_desc_type *dma_rx_desc, confirm_state new_state) { + if (new_state != FALSE) { + /* enable the dma rx desc receive interrupt */ + dma_rx_desc->controlsize &= (~(uint32_t)EMAC_DMARXDESC_DIC); + } else { + /* disable the dma rx desc receive interrupt */ + dma_rx_desc->controlsize |= EMAC_DMARXDESC_DIC; + } } /** @@ -1104,20 +979,16 @@ void emac_dma_rx_desc_interrupt_config(emac_dma_desc_type *dma_rx_desc, confirm_ * - EMAC_DMA_RECEIVE * @retval transmit/receive descriptor list address */ -uint32_t emac_dma_descriptor_list_address_get(emac_dma_tx_rx_type transfer_type) -{ - switch(transfer_type) - { - case EMAC_DMA_TRANSMIT: - { - return (EMAC_DMA->tdladdr_bit.stl); +uint32_t emac_dma_descriptor_list_address_get(emac_dma_tx_rx_type transfer_type) { + switch (transfer_type) { + case EMAC_DMA_TRANSMIT: { + return (EMAC_DMA->tdladdr_bit.stl); + } + case EMAC_DMA_RECEIVE: { + return (EMAC_DMA->rdladdr_bit.srl); + } } - case EMAC_DMA_RECEIVE: - { - return (EMAC_DMA->rdladdr_bit.srl); - } - } - return 0; + return 0; } /** @@ -1125,18 +996,16 @@ uint32_t emac_dma_descriptor_list_address_get(emac_dma_tx_rx_type transfer_type) * @param none * @retval received packet size */ -uint32_t emac_received_packet_size_get(void) -{ - uint32_t frame_length = 0; - if(((dma_rx_desc_to_get->status & EMAC_DMARXDESC_OWN) == (uint32_t)RESET) && - ((dma_rx_desc_to_get->status & EMAC_DMATXDESC_ES) == (uint32_t)RESET) && - ((dma_rx_desc_to_get->status & EMAC_DMARXDESC_LS) != (uint32_t)RESET) && - ((dma_rx_desc_to_get->status & EMAC_DMARXDESC_FS) != (uint32_t)RESET)) - { - frame_length = emac_dmarxdesc_frame_length_get((emac_dma_desc_type*) dma_rx_desc_to_get); - } +uint32_t emac_received_packet_size_get(void) { + uint32_t frame_length = 0; + if (((dma_rx_desc_to_get->status & EMAC_DMARXDESC_OWN) == (uint32_t)RESET) && + ((dma_rx_desc_to_get->status & EMAC_DMATXDESC_ES) == (uint32_t)RESET) && + ((dma_rx_desc_to_get->status & EMAC_DMARXDESC_LS) != (uint32_t)RESET) && + ((dma_rx_desc_to_get->status & EMAC_DMARXDESC_FS) != (uint32_t)RESET)) { + frame_length = emac_dmarxdesc_frame_length_get((emac_dma_desc_type *) dma_rx_desc_to_get); + } - return frame_length; + return frame_length; } /** @@ -1144,9 +1013,8 @@ uint32_t emac_received_packet_size_get(void) * @param dma_rx_desc: pointer on a dma rx descriptor * @retval the rx descriptor received frame length. */ -uint32_t emac_dmarxdesc_frame_length_get(emac_dma_desc_type *dma_rx_desc) -{ - return ((dma_rx_desc->status & EMAC_DMARXDESC_FL) >> EMAC_DMARXDESC_FRAME_LENGTHSHIFT); +uint32_t emac_dmarxdesc_frame_length_get(emac_dma_desc_type *dma_rx_desc) { + return ((dma_rx_desc->status & EMAC_DMARXDESC_FL) >> EMAC_DMARXDESC_FRAME_LENGTHSHIFT); } /** @@ -1154,25 +1022,24 @@ uint32_t emac_dmarxdesc_frame_length_get(emac_dma_desc_type *dma_rx_desc) * @param emac_dma_config_type * @retval none */ -void emac_dma_para_init(emac_dma_config_type *control_para) -{ - control_para->aab_enable = FALSE; - control_para->da_enable = FALSE; - control_para->desc_skip_length = 0; - control_para->dt_disable = FALSE; - control_para->fb_enable = FALSE; - control_para->fef_enable = FALSE; - control_para->flush_rx_disable = FALSE; - control_para->fugf_enable = FALSE; - control_para->osf_enable = FALSE; - control_para->priority_ratio = EMAC_DMA_1_RX_1_TX; - control_para->rsf_enable = FALSE; - control_para->rx_dma_pal = EMAC_DMA_PBL_1; - control_para->rx_threshold = EMAC_DMA_RX_THRESHOLD_64_BYTES; - control_para->tsf_enable = FALSE; - control_para->tx_dma_pal = EMAC_DMA_PBL_1; - control_para->tx_threshold = EMAC_DMA_TX_THRESHOLD_64_BYTES; - control_para->usp_enable = FALSE; +void emac_dma_para_init(emac_dma_config_type *control_para) { + control_para->aab_enable = FALSE; + control_para->da_enable = FALSE; + control_para->desc_skip_length = 0; + control_para->dt_disable = FALSE; + control_para->fb_enable = FALSE; + control_para->fef_enable = FALSE; + control_para->flush_rx_disable = FALSE; + control_para->fugf_enable = FALSE; + control_para->osf_enable = FALSE; + control_para->priority_ratio = EMAC_DMA_1_RX_1_TX; + control_para->rsf_enable = FALSE; + control_para->rx_dma_pal = EMAC_DMA_PBL_1; + control_para->rx_threshold = EMAC_DMA_RX_THRESHOLD_64_BYTES; + control_para->tsf_enable = FALSE; + control_para->tx_dma_pal = EMAC_DMA_PBL_1; + control_para->tx_threshold = EMAC_DMA_TX_THRESHOLD_64_BYTES; + control_para->usp_enable = FALSE; } /** @@ -1180,26 +1047,25 @@ void emac_dma_para_init(emac_dma_config_type *control_para) * @param emac_dma_config_type * @retval none */ -void emac_dma_config(emac_dma_config_type *control_para) -{ - EMAC_DMA->bm_bit.aab = control_para->aab_enable; - EMAC_DMA->bm_bit.dsl = control_para->desc_skip_length; - EMAC_DMA->bm_bit.rdp = control_para->rx_dma_pal; - EMAC_DMA->bm_bit.pbl = control_para->tx_dma_pal; - EMAC_DMA->bm_bit.fb = control_para->fb_enable; - EMAC_DMA->bm_bit.usp = control_para->usp_enable; - EMAC_DMA->bm_bit.da = control_para->da_enable; - EMAC_DMA->bm_bit.pr = control_para->priority_ratio; +void emac_dma_config(emac_dma_config_type *control_para) { + EMAC_DMA->bm_bit.aab = control_para->aab_enable; + EMAC_DMA->bm_bit.dsl = control_para->desc_skip_length; + EMAC_DMA->bm_bit.rdp = control_para->rx_dma_pal; + EMAC_DMA->bm_bit.pbl = control_para->tx_dma_pal; + EMAC_DMA->bm_bit.fb = control_para->fb_enable; + EMAC_DMA->bm_bit.usp = control_para->usp_enable; + EMAC_DMA->bm_bit.da = control_para->da_enable; + EMAC_DMA->bm_bit.pr = control_para->priority_ratio; - EMAC_DMA->opm_bit.dt = control_para->dt_disable; - EMAC_DMA->opm_bit.rsf = control_para->rsf_enable; - EMAC_DMA->opm_bit.dfrf = control_para->flush_rx_disable; - EMAC_DMA->opm_bit.tsf = control_para->tsf_enable; - EMAC_DMA->opm_bit.ttc = control_para->tx_threshold; - EMAC_DMA->opm_bit.fef = control_para->fef_enable; - EMAC_DMA->opm_bit.fugf = control_para->fugf_enable; - EMAC_DMA->opm_bit.rtc = control_para->rx_threshold; - EMAC_DMA->opm_bit.osf = control_para->osf_enable; + EMAC_DMA->opm_bit.dt = control_para->dt_disable; + EMAC_DMA->opm_bit.rsf = control_para->rsf_enable; + EMAC_DMA->opm_bit.dfrf = control_para->flush_rx_disable; + EMAC_DMA->opm_bit.tsf = control_para->tsf_enable; + EMAC_DMA->opm_bit.ttc = control_para->tx_threshold; + EMAC_DMA->opm_bit.fef = control_para->fef_enable; + EMAC_DMA->opm_bit.fugf = control_para->fugf_enable; + EMAC_DMA->opm_bit.rtc = control_para->rx_threshold; + EMAC_DMA->opm_bit.osf = control_para->osf_enable; } /** @@ -1213,14 +1079,12 @@ void emac_dma_config(emac_dma_config_type *control_para) * @param new_state: TRUE or FALSE * @retval none */ -void emac_dma_arbitation_set(emac_dma_rx_tx_ratio_type ratio, confirm_state new_state) -{ - EMAC_DMA->bm_bit.da = new_state; +void emac_dma_arbitation_set(emac_dma_rx_tx_ratio_type ratio, confirm_state new_state) { + EMAC_DMA->bm_bit.da = new_state; - if(new_state) - { - EMAC_DMA->bm_bit.pr = ratio; - } + if (new_state) { + EMAC_DMA->bm_bit.pr = ratio; + } } /** @@ -1228,9 +1092,8 @@ void emac_dma_arbitation_set(emac_dma_rx_tx_ratio_type ratio, confirm_state new_ * @param length: descriptor skip length * @retval none */ -void emac_dma_descriptor_skip_length_set(uint8_t length) -{ - EMAC_DMA->bm_bit.dsl = length; +void emac_dma_descriptor_skip_length_set(uint8_t length) { + EMAC_DMA->bm_bit.dsl = length; } /** @@ -1254,15 +1117,13 @@ void emac_dma_descriptor_skip_length_set(uint8_t length) * @param new_state: TRUE or FALSE * @retval none */ -void emac_dma_separate_pbl_set(emac_dma_pbl_type tx_length, emac_dma_pbl_type rx_length, confirm_state new_state) -{ - EMAC_DMA->bm_bit.usp = new_state; - EMAC_DMA->bm_bit.pbl = tx_length; +void emac_dma_separate_pbl_set(emac_dma_pbl_type tx_length, emac_dma_pbl_type rx_length, confirm_state new_state) { + EMAC_DMA->bm_bit.usp = new_state; + EMAC_DMA->bm_bit.pbl = tx_length; - if(new_state) - { - EMAC_DMA->bm_bit.pbl = rx_length; - } + if (new_state) { + EMAC_DMA->bm_bit.pbl = rx_length; + } } /** @@ -1270,9 +1131,8 @@ void emac_dma_separate_pbl_set(emac_dma_pbl_type tx_length, emac_dma_pbl_type rx * @param new_state: TRUE or FALSE * @retval none */ -void emac_dma_eight_pbl_mode_set(confirm_state new_state) -{ - EMAC_DMA->bm_bit.pblx8 = new_state; +void emac_dma_eight_pbl_mode_set(confirm_state new_state) { + EMAC_DMA->bm_bit.pblx8 = new_state; } /** @@ -1280,9 +1140,8 @@ void emac_dma_eight_pbl_mode_set(confirm_state new_state) * @param new_state: TRUE or FALSE * @retval none */ -void emac_dma_address_aligned_beats_set(confirm_state new_state) -{ - EMAC_DMA->bm_bit.aab = new_state; +void emac_dma_address_aligned_beats_set(confirm_state new_state) { + EMAC_DMA->bm_bit.aab = new_state; } /** @@ -1294,21 +1153,17 @@ void emac_dma_address_aligned_beats_set(confirm_state new_state) * @param value: it can be any number * @retval none */ -void emac_dma_poll_demand_set(emac_dma_tx_rx_type transfer_type, uint32_t value) -{ - switch(transfer_type) - { - case EMAC_DMA_TRANSMIT: - { - EMAC_DMA->tpd_bit.tpd = value; - break; +void emac_dma_poll_demand_set(emac_dma_tx_rx_type transfer_type, uint32_t value) { + switch (transfer_type) { + case EMAC_DMA_TRANSMIT: { + EMAC_DMA->tpd_bit.tpd = value; + break; + } + case EMAC_DMA_RECEIVE: { + EMAC_DMA->rpd_bit.rpd = value; + break; + } } - case EMAC_DMA_RECEIVE: - { - EMAC_DMA->rpd_bit.rpd = value; - break; - } - } } /** @@ -1319,20 +1174,16 @@ void emac_dma_poll_demand_set(emac_dma_tx_rx_type transfer_type, uint32_t value) * - EMAC_DMA_RECEIVE * @retval current transmit descriptor */ -uint32_t emac_dma_poll_demand_get(emac_dma_tx_rx_type transfer_type) -{ - switch(transfer_type) - { - case EMAC_DMA_TRANSMIT: - { - return (EMAC_DMA->tpd_bit.tpd); +uint32_t emac_dma_poll_demand_get(emac_dma_tx_rx_type transfer_type) { + switch (transfer_type) { + case EMAC_DMA_TRANSMIT: { + return (EMAC_DMA->tpd_bit.tpd); + } + case EMAC_DMA_RECEIVE: { + return (EMAC_DMA->rpd_bit.rpd); + } } - case EMAC_DMA_RECEIVE: - { - return (EMAC_DMA->rpd_bit.rpd); - } - } - return 0; + return 0; } /** @@ -1347,42 +1198,34 @@ uint32_t emac_dma_poll_demand_get(emac_dma_tx_rx_type transfer_type) * - EMAC_DMA_RX_CLOSE_DESCRIPTOR * - EMAC_DMA_RX_FIFO_TO_HOST */ -emac_dma_receive_process_status_type emac_dma_receive_status_get(void) -{ - switch(EMAC_DMA->sts_bit.rs) - { - case EMAC_DMA_RX_RESET_STOP_COMMAND: - { - return EMAC_DMA_RX_RESET_STOP_COMMAND; +emac_dma_receive_process_status_type emac_dma_receive_status_get(void) { + switch (EMAC_DMA->sts_bit.rs) { + case EMAC_DMA_RX_RESET_STOP_COMMAND: { + return EMAC_DMA_RX_RESET_STOP_COMMAND; + } + + case EMAC_DMA_RX_FETCH_DESCRIPTOR: { + return EMAC_DMA_RX_FETCH_DESCRIPTOR; + } + + case EMAC_DMA_RX_WAITING_PACKET: { + return EMAC_DMA_RX_WAITING_PACKET; + } + + case EMAC_DMA_RX_DESCRIPTOR_UNAVAILABLE: { + return EMAC_DMA_RX_DESCRIPTOR_UNAVAILABLE; + } + + case EMAC_DMA_RX_CLOSE_DESCRIPTOR: { + return EMAC_DMA_RX_CLOSE_DESCRIPTOR; + } + + case EMAC_DMA_RX_FIFO_TO_HOST: { + return EMAC_DMA_RX_FIFO_TO_HOST; + } } - case EMAC_DMA_RX_FETCH_DESCRIPTOR: - { - return EMAC_DMA_RX_FETCH_DESCRIPTOR; - } - - case EMAC_DMA_RX_WAITING_PACKET: - { - return EMAC_DMA_RX_WAITING_PACKET; - } - - case EMAC_DMA_RX_DESCRIPTOR_UNAVAILABLE: - { - return EMAC_DMA_RX_DESCRIPTOR_UNAVAILABLE; - } - - case EMAC_DMA_RX_CLOSE_DESCRIPTOR: - { - return EMAC_DMA_RX_CLOSE_DESCRIPTOR; - } - - case EMAC_DMA_RX_FIFO_TO_HOST: - { - return EMAC_DMA_RX_FIFO_TO_HOST; - } - } - - return EMAC_DMA_RX_RESET_STOP_COMMAND; + return EMAC_DMA_RX_RESET_STOP_COMMAND; } /** @@ -1397,42 +1240,34 @@ emac_dma_receive_process_status_type emac_dma_receive_status_get(void) * - EMAC_DMA_TX_DESCRIPTOR_UNAVAILABLE * - EMAC_DMA_TX_CLOSE_DESCRIPTOR */ -emac_dma_transmit_process_status_type emac_dma_transmit_status_get(void) -{ - switch(EMAC_DMA->sts_bit.ts) - { - case EMAC_DMA_TX_RESET_STOP_COMMAND: - { - return EMAC_DMA_TX_RESET_STOP_COMMAND; +emac_dma_transmit_process_status_type emac_dma_transmit_status_get(void) { + switch (EMAC_DMA->sts_bit.ts) { + case EMAC_DMA_TX_RESET_STOP_COMMAND: { + return EMAC_DMA_TX_RESET_STOP_COMMAND; + } + + case EMAC_DMA_TX_FETCH_DESCRIPTOR: { + return EMAC_DMA_TX_FETCH_DESCRIPTOR; + } + + case EMAC_DMA_TX_WAITING_FOR_STATUS: { + return EMAC_DMA_TX_WAITING_FOR_STATUS; + } + + case EMAC_DMA_TX_HOST_TO_FIFO: { + return EMAC_DMA_TX_HOST_TO_FIFO; + } + + case EMAC_DMA_TX_DESCRIPTOR_UNAVAILABLE: { + return EMAC_DMA_TX_DESCRIPTOR_UNAVAILABLE; + } + + case EMAC_DMA_TX_CLOSE_DESCRIPTOR: { + return EMAC_DMA_TX_CLOSE_DESCRIPTOR; + } } - case EMAC_DMA_TX_FETCH_DESCRIPTOR: - { - return EMAC_DMA_TX_FETCH_DESCRIPTOR; - } - - case EMAC_DMA_TX_WAITING_FOR_STATUS: - { - return EMAC_DMA_TX_WAITING_FOR_STATUS; - } - - case EMAC_DMA_TX_HOST_TO_FIFO: - { - return EMAC_DMA_TX_HOST_TO_FIFO; - } - - case EMAC_DMA_TX_DESCRIPTOR_UNAVAILABLE: - { - return EMAC_DMA_TX_DESCRIPTOR_UNAVAILABLE; - } - - case EMAC_DMA_TX_CLOSE_DESCRIPTOR: - { - return EMAC_DMA_TX_CLOSE_DESCRIPTOR; - } - } - - return EMAC_DMA_TX_RESET_STOP_COMMAND; + return EMAC_DMA_TX_RESET_STOP_COMMAND; } /** @@ -1452,74 +1287,62 @@ emac_dma_transmit_process_status_type emac_dma_transmit_status_get(void) * @param new_state: TRUE or FALSE * @retval none */ -void emac_dma_operations_set(emac_dma_operations_type ops, confirm_state new_state) -{ - __IO uint32_t temp = 0; - switch(ops) - { - case EMAC_DMA_OPS_START_STOP_RECEIVE: - { - EMAC_DMA->opm_bit.ssr = new_state; - break; - } +void emac_dma_operations_set(emac_dma_operations_type ops, confirm_state new_state) { + __IO uint32_t temp = 0; + switch (ops) { + case EMAC_DMA_OPS_START_STOP_RECEIVE: { + EMAC_DMA->opm_bit.ssr = new_state; + break; + } - case EMAC_DMA_OPS_SECOND_FRAME: - { - EMAC_DMA->opm_bit.osf = new_state; - break; - } + case EMAC_DMA_OPS_SECOND_FRAME: { + EMAC_DMA->opm_bit.osf = new_state; + break; + } - case EMAC_DMA_OPS_FORWARD_UNDERSIZED: - { - EMAC_DMA->opm_bit.fugf = new_state; - break; - } + case EMAC_DMA_OPS_FORWARD_UNDERSIZED: { + EMAC_DMA->opm_bit.fugf = new_state; + break; + } - case EMAC_DMA_OPS_FORWARD_ERROR: - { - EMAC_DMA->opm_bit.fef = new_state; - break; - } + case EMAC_DMA_OPS_FORWARD_ERROR: { + EMAC_DMA->opm_bit.fef = new_state; + break; + } - case EMAC_DMA_OPS_START_STOP_TRANSMIT: - { - EMAC_DMA->opm_bit.sstc = new_state; - break; - } + case EMAC_DMA_OPS_START_STOP_TRANSMIT: { + EMAC_DMA->opm_bit.sstc = new_state; + break; + } - case EMAC_DMA_OPS_FLUSH_TRANSMIT_FIFO: - { - EMAC_DMA->opm_bit.ftf = new_state; - temp = EMAC_DMA->opm; - emac_delay(1); - EMAC_DMA->opm = temp; - break; - } + case EMAC_DMA_OPS_FLUSH_TRANSMIT_FIFO: { + EMAC_DMA->opm_bit.ftf = new_state; + temp = EMAC_DMA->opm; + emac_delay(1); + EMAC_DMA->opm = temp; + break; + } - case EMAC_DMA_OPS_TRANSMIT_STORE_FORWARD: - { - EMAC_DMA->opm_bit.tsf = new_state; - break; - } + case EMAC_DMA_OPS_TRANSMIT_STORE_FORWARD: { + EMAC_DMA->opm_bit.tsf = new_state; + break; + } - case EMAC_DMA_OPS_RECEIVE_FLUSH_DISABLE: - { - EMAC_DMA->opm_bit.dfrf = new_state; - break; - } + case EMAC_DMA_OPS_RECEIVE_FLUSH_DISABLE: { + EMAC_DMA->opm_bit.dfrf = new_state; + break; + } - case EMAC_DMA_OPS_RECEIVE_STORE_FORWARD: - { - EMAC_DMA->opm_bit.rsf = new_state; - break; - } + case EMAC_DMA_OPS_RECEIVE_STORE_FORWARD: { + EMAC_DMA->opm_bit.rsf = new_state; + break; + } - case EMAC_DMA_OPS_DROP_ERROR_DISABLE: - { - EMAC_DMA->opm_bit.dt = new_state; - break; + case EMAC_DMA_OPS_DROP_ERROR_DISABLE: { + EMAC_DMA->opm_bit.dt = new_state; + break; + } } - } } /** @@ -1532,9 +1355,8 @@ void emac_dma_operations_set(emac_dma_operations_type ops, confirm_state new_sta * - EMAC_DMA_RX_THRESHOLD_128_BYTES * @retval none */ -void emac_dma_receive_threshold_set(emac_dma_receive_threshold_type value) -{ - EMAC_DMA->opm_bit.rtc = value; +void emac_dma_receive_threshold_set(emac_dma_receive_threshold_type value) { + EMAC_DMA->opm_bit.rtc = value; } /** @@ -1551,9 +1373,8 @@ void emac_dma_receive_threshold_set(emac_dma_receive_threshold_type value) * - EMAC_DMA_TX_THRESHOLD_16_BYTES * @retval none */ -void emac_dma_transmit_threshold_set(emac_dma_transmit_threshold_type value) -{ - EMAC_DMA->opm_bit.ttc = value; +void emac_dma_transmit_threshold_set(emac_dma_transmit_threshold_type value) { + EMAC_DMA->opm_bit.ttc = value; } /** @@ -1578,86 +1399,69 @@ void emac_dma_transmit_threshold_set(emac_dma_transmit_threshold_type value) * @param new_state: TRUE or FALSE * @retval none */ -void emac_dma_interrupt_enable(emac_dma_interrupt_type it, confirm_state new_state) -{ - switch(it) - { - case EMAC_DMA_INTERRUPT_TX: - { - EMAC_DMA->ie_bit.tie = new_state; - break; +void emac_dma_interrupt_enable(emac_dma_interrupt_type it, confirm_state new_state) { + switch (it) { + case EMAC_DMA_INTERRUPT_TX: { + EMAC_DMA->ie_bit.tie = new_state; + break; + } + case EMAC_DMA_INTERRUPT_TX_STOP: { + EMAC_DMA->ie_bit.tse = new_state; + break; + } + case EMAC_DMA_INTERRUPT_TX_UNAVAILABLE: { + EMAC_DMA->ie_bit.tue = new_state; + break; + } + case EMAC_DMA_INTERRUPT_TX_JABBER: { + EMAC_DMA->ie_bit.tje = new_state; + break; + } + case EMAC_DMA_INTERRUPT_RX_OVERFLOW: { + EMAC_DMA->ie_bit.ove = new_state; + break; + } + case EMAC_DMA_INTERRUPT_TX_UNDERFLOW: { + EMAC_DMA->ie_bit.une = new_state; + break; + } + case EMAC_DMA_INTERRUPT_RX: { + EMAC_DMA->ie_bit.rie = new_state; + break; + } + case EMAC_DMA_INTERRUPT_RX_UNAVAILABLE: { + EMAC_DMA->ie_bit.rbue = new_state; + break; + } + case EMAC_DMA_INTERRUPT_RX_STOP: { + EMAC_DMA->ie_bit.rse = new_state; + break; + } + case EMAC_DMA_INTERRUPT_RX_TIMEOUT: { + EMAC_DMA->ie_bit.rwte = new_state; + break; + } + case EMAC_DMA_INTERRUPT_TX_EARLY: { + EMAC_DMA->ie_bit.eie = new_state; + break; + } + case EMAC_DMA_INTERRUPT_FATAL_BUS_ERROR: { + EMAC_DMA->ie_bit.fbee = new_state; + break; + } + case EMAC_DMA_INTERRUPT_RX_EARLY: { + EMAC_DMA->ie_bit.ere = new_state; + break; + } + case EMAC_DMA_INTERRUPT_ABNORMAL_SUMMARY: { + EMAC_DMA->ie_bit.aie = new_state; + break; + } + case EMAC_DMA_INTERRUPT_NORMAL_SUMMARY: { + EMAC_DMA->ie_bit.nie = new_state; + break; + } } - case EMAC_DMA_INTERRUPT_TX_STOP: - { - EMAC_DMA->ie_bit.tse = new_state; - break; - } - case EMAC_DMA_INTERRUPT_TX_UNAVAILABLE: - { - EMAC_DMA->ie_bit.tue = new_state; - break; - } - case EMAC_DMA_INTERRUPT_TX_JABBER: - { - EMAC_DMA->ie_bit.tje = new_state; - break; - } - case EMAC_DMA_INTERRUPT_RX_OVERFLOW: - { - EMAC_DMA->ie_bit.ove = new_state; - break; - } - case EMAC_DMA_INTERRUPT_TX_UNDERFLOW: - { - EMAC_DMA->ie_bit.une = new_state; - break; - } - case EMAC_DMA_INTERRUPT_RX: - { - EMAC_DMA->ie_bit.rie = new_state; - break; - } - case EMAC_DMA_INTERRUPT_RX_UNAVAILABLE: - { - EMAC_DMA->ie_bit.rbue = new_state; - break; - } - case EMAC_DMA_INTERRUPT_RX_STOP: - { - EMAC_DMA->ie_bit.rse = new_state; - break; - } - case EMAC_DMA_INTERRUPT_RX_TIMEOUT: - { - EMAC_DMA->ie_bit.rwte = new_state; - break; - } - case EMAC_DMA_INTERRUPT_TX_EARLY: - { - EMAC_DMA->ie_bit.eie = new_state; - break; - } - case EMAC_DMA_INTERRUPT_FATAL_BUS_ERROR: - { - EMAC_DMA->ie_bit.fbee = new_state; - break; - } - case EMAC_DMA_INTERRUPT_RX_EARLY: - { - EMAC_DMA->ie_bit.ere = new_state; - break; - } - case EMAC_DMA_INTERRUPT_ABNORMAL_SUMMARY: - { - EMAC_DMA->ie_bit.aie = new_state; - break; - } - case EMAC_DMA_INTERRUPT_NORMAL_SUMMARY: - { - EMAC_DMA->ie_bit.nie = new_state; - break; - } - } } /** @@ -1665,10 +1469,9 @@ void emac_dma_interrupt_enable(emac_dma_interrupt_type it, confirm_state new_sta * @param none * @retval missed frames by the controller */ -uint16_t emac_dma_controller_missing_frame_get(void) -{ - uint16_t number = EMAC_DMA->mfbocnt_bit.mfc; - return number; +uint16_t emac_dma_controller_missing_frame_get(void) { + uint16_t number = EMAC_DMA->mfbocnt_bit.mfc; + return number; } /** @@ -1676,10 +1479,9 @@ uint16_t emac_dma_controller_missing_frame_get(void) * @param none * @retval overflow bit for missed frame counter */ -uint8_t emac_dma_missing_overflow_bit_get(void) -{ - uint8_t number = EMAC_DMA->mfbocnt_bit.obmfc; - return number; +uint8_t emac_dma_missing_overflow_bit_get(void) { + uint8_t number = EMAC_DMA->mfbocnt_bit.obmfc; + return number; } /** @@ -1687,10 +1489,9 @@ uint8_t emac_dma_missing_overflow_bit_get(void) * @param none * @retval missed frames by the application */ -uint16_t emac_dma_application_missing_frame_get(void) -{ - uint16_t number = EMAC_DMA->mfbocnt_bit.ofc; - return number; +uint16_t emac_dma_application_missing_frame_get(void) { + uint16_t number = EMAC_DMA->mfbocnt_bit.ofc; + return number; } /** @@ -1698,10 +1499,9 @@ uint16_t emac_dma_application_missing_frame_get(void) * @param none * @retval overflow bit for FIFO overflow counter */ -uint8_t emac_dma_fifo_overflow_bit_get(void) -{ - uint8_t number = EMAC_DMA->mfbocnt_bit.obfoc; - return number; +uint8_t emac_dma_fifo_overflow_bit_get(void) { + uint8_t number = EMAC_DMA->mfbocnt_bit.obfoc; + return number; } /** @@ -1714,34 +1514,28 @@ uint8_t emac_dma_fifo_overflow_bit_get(void) * - EMAC_DMA_RX_BUFFER * @retval memory address */ -uint32_t emac_dma_tansfer_address_get(emac_dma_transfer_address_type transfer_type) -{ - uint32_t address = 0; +uint32_t emac_dma_tansfer_address_get(emac_dma_transfer_address_type transfer_type) { + uint32_t address = 0; - switch(transfer_type) - { - case EMAC_DMA_TX_DESCRIPTOR: - { - address = EMAC_DMA->ctd_bit.htdap; - break; + switch (transfer_type) { + case EMAC_DMA_TX_DESCRIPTOR: { + address = EMAC_DMA->ctd_bit.htdap; + break; + } + case EMAC_DMA_RX_DESCRIPTOR: { + address = EMAC_DMA->crd_bit.hrdap; + break; + } + case EMAC_DMA_TX_BUFFER: { + address = EMAC_DMA->ctbaddr_bit.htbap; + break; + } + case EMAC_DMA_RX_BUFFER: { + address = EMAC_DMA->crbaddr_bit.hrbap; + break; + } } - case EMAC_DMA_RX_DESCRIPTOR: - { - address = EMAC_DMA->crd_bit.hrdap; - break; - } - case EMAC_DMA_TX_BUFFER: - { - address = EMAC_DMA->ctbaddr_bit.htbap; - break; - } - case EMAC_DMA_RX_BUFFER: - { - address = EMAC_DMA->crbaddr_bit.hrbap; - break; - } - } - return address; + return address; } /** @@ -1749,9 +1543,8 @@ uint32_t emac_dma_tansfer_address_get(emac_dma_transfer_address_type transfer_ty * @param new_state: TRUE or FALSE * @retval none */ -void emac_dma_alternate_desc_size(confirm_state new_state) -{ - EMAC_DMA->bm_bit.atds = new_state; +void emac_dma_alternate_desc_size(confirm_state new_state) { + EMAC_DMA->bm_bit.atds = new_state; } /** @@ -1759,9 +1552,8 @@ void emac_dma_alternate_desc_size(confirm_state new_state) * @param none * @retval none */ -void emac_mmc_counter_reset(void) -{ - EMAC_MMC->ctrl_bit.rc = TRUE; +void emac_mmc_counter_reset(void) { + EMAC_MMC->ctrl_bit.rc = TRUE; } /** @@ -1769,9 +1561,8 @@ void emac_mmc_counter_reset(void) * @param new_state: TRUE or FALSE. * @retval none */ -void emac_mmc_rollover_stop(confirm_state new_state) -{ - EMAC_MMC->ctrl_bit.scr = new_state; +void emac_mmc_rollover_stop(confirm_state new_state) { + EMAC_MMC->ctrl_bit.scr = new_state; } /** @@ -1779,9 +1570,8 @@ void emac_mmc_rollover_stop(confirm_state new_state) * @param new_state: TRUE or FALSE. * @retval none */ -void emac_mmc_reset_on_read_enable(confirm_state new_state) -{ - EMAC_MMC->ctrl_bit.rr = new_state; +void emac_mmc_reset_on_read_enable(confirm_state new_state) { + EMAC_MMC->ctrl_bit.rr = new_state; } /** @@ -1789,9 +1579,8 @@ void emac_mmc_reset_on_read_enable(confirm_state new_state) * @param new_state: TRUE or FALSE. * @retval none */ -void emac_mmc_counter_freeze(confirm_state new_state) -{ - EMAC_MMC->ctrl_bit.fmc = new_state; +void emac_mmc_counter_freeze(confirm_state new_state) { + EMAC_MMC->ctrl_bit.fmc = new_state; } /** @@ -1803,16 +1592,12 @@ void emac_mmc_counter_freeze(confirm_state new_state) * - MMC_RX_GOOD_UNICAST * @retval the new state of usart_flag (SET or RESET). */ -flag_status emac_mmc_received_status_get(uint32_t flag) -{ - if(EMAC_MMC->ri & flag) - { - return SET; - } - else - { - return RESET; - } +flag_status emac_mmc_received_status_get(uint32_t flag) { + if (EMAC_MMC->ri & flag) { + return SET; + } else { + return RESET; + } } /** @@ -1824,16 +1609,12 @@ flag_status emac_mmc_received_status_get(uint32_t flag) * - MMC_TX_GOOD_FRAMES * @retval the new state of usart_flag (SET or RESET). */ -flag_status emac_mmc_transmit_status_get(uint32_t flag) -{ - if(EMAC_MMC->ti & flag) - { - return SET; - } - else - { - return RESET; - } +flag_status emac_mmc_transmit_status_get(uint32_t flag) { + if (EMAC_MMC->ti & flag) { + return SET; + } else { + return RESET; + } } /** @@ -1846,26 +1627,21 @@ flag_status emac_mmc_transmit_status_get(uint32_t flag) * @param new_state: TRUE or FALSE. * @retval none */ -void emac_mmc_received_interrupt_mask_set(uint32_t flag, confirm_state new_state) -{ - switch(flag) - { - case MMC_RX_CRC_ERROR: - { - EMAC_MMC->rim_bit.rcefcim = new_state; - break; +void emac_mmc_received_interrupt_mask_set(uint32_t flag, confirm_state new_state) { + switch (flag) { + case MMC_RX_CRC_ERROR: { + EMAC_MMC->rim_bit.rcefcim = new_state; + break; + } + case MMC_RX_ALIGN_ERROR: { + EMAC_MMC->rim_bit.raefacim = new_state; + break; + } + case MMC_RX_GOOD_UNICAST: { + EMAC_MMC->rim_bit.rugfcim = new_state; + break; + } } - case MMC_RX_ALIGN_ERROR: - { - EMAC_MMC->rim_bit.raefacim = new_state; - break; - } - case MMC_RX_GOOD_UNICAST: - { - EMAC_MMC->rim_bit.rugfcim = new_state; - break; - } - } } /** @@ -1878,26 +1654,21 @@ void emac_mmc_received_interrupt_mask_set(uint32_t flag, confirm_state new_state * @param new_state: TRUE or FALSE. * @retval none */ -void emac_mmc_transmit_interrupt_mask_set(uint32_t flag, confirm_state new_state) -{ - switch(flag) - { - case MMC_TX_SINGLE_COL: - { - EMAC_MMC->tim_bit.tscgfcim = new_state; - break; +void emac_mmc_transmit_interrupt_mask_set(uint32_t flag, confirm_state new_state) { + switch (flag) { + case MMC_TX_SINGLE_COL: { + EMAC_MMC->tim_bit.tscgfcim = new_state; + break; + } + case MMC_TX_MULTIPLE_COL: { + EMAC_MMC->tim_bit.tmcgfcim = new_state; + break; + } + case MMC_TX_GOOD_FRAMES: { + EMAC_MMC->tim_bit.tgfcim = new_state; + break; + } } - case MMC_TX_MULTIPLE_COL: - { - EMAC_MMC->tim_bit.tmcgfcim = new_state; - break; - } - case MMC_TX_GOOD_FRAMES: - { - EMAC_MMC->tim_bit.tgfcim = new_state; - break; - } - } } /** @@ -1909,29 +1680,24 @@ void emac_mmc_transmit_interrupt_mask_set(uint32_t flag, confirm_state new_state * - MMC_TX_GOOD_FRAMES * @retval good frames */ -uint32_t emac_mmc_transmit_good_frames_get(uint32_t flag) -{ - uint32_t good_frames = MMC_TX_GOOD_FRAMES; +uint32_t emac_mmc_transmit_good_frames_get(uint32_t flag) { + uint32_t good_frames = MMC_TX_GOOD_FRAMES; - switch(flag) - { - case MMC_TX_SINGLE_COL: - { - good_frames = EMAC_MMC->tfscc_bit.tgfscc; - break; + switch (flag) { + case MMC_TX_SINGLE_COL: { + good_frames = EMAC_MMC->tfscc_bit.tgfscc; + break; + } + case MMC_TX_MULTIPLE_COL: { + good_frames = EMAC_MMC->tfmscc_bit.tgfmscc; + break; + } + case MMC_TX_GOOD_FRAMES: { + good_frames = EMAC_MMC->tfcnt_bit.tgfc; + break; + } } - case MMC_TX_MULTIPLE_COL: - { - good_frames = EMAC_MMC->tfmscc_bit.tgfmscc; - break; - } - case MMC_TX_GOOD_FRAMES: - { - good_frames = EMAC_MMC->tfcnt_bit.tgfc; - break; - } - } - return good_frames; + return good_frames; } /** @@ -1943,29 +1709,24 @@ uint32_t emac_mmc_transmit_good_frames_get(uint32_t flag) * - MMC_RX_GOOD_UNICAST * @retval good frames */ -uint32_t emac_mmc_received_error_frames_get(uint32_t flag) -{ - uint32_t error_frames = MMC_RX_GOOD_UNICAST; +uint32_t emac_mmc_received_error_frames_get(uint32_t flag) { + uint32_t error_frames = MMC_RX_GOOD_UNICAST; - switch(flag) - { - case MMC_RX_CRC_ERROR: - { - error_frames = EMAC_MMC->rfcecnt_bit.rfcec; - break; + switch (flag) { + case MMC_RX_CRC_ERROR: { + error_frames = EMAC_MMC->rfcecnt_bit.rfcec; + break; + } + case MMC_RX_ALIGN_ERROR: { + error_frames = EMAC_MMC->rfaecnt_bit.rfaec; + break; + } + case MMC_RX_GOOD_UNICAST: { + error_frames = EMAC_MMC->rgufcnt_bit.rgufc; + break; + } } - case MMC_RX_ALIGN_ERROR: - { - error_frames = EMAC_MMC->rfaecnt_bit.rfaec; - break; - } - case MMC_RX_GOOD_UNICAST: - { - error_frames = EMAC_MMC->rgufcnt_bit.rgufc; - break; - } - } - return error_frames; + return error_frames; } /** @@ -1973,9 +1734,8 @@ uint32_t emac_mmc_received_error_frames_get(uint32_t flag) * @param new_state: TRUE or FALSE. * @retval none */ -void emac_ptp_timestamp_enable(confirm_state new_state) -{ - EMAC_PTP->tsctrl_bit.te = new_state; +void emac_ptp_timestamp_enable(confirm_state new_state) { + EMAC_PTP->tsctrl_bit.te = new_state; } /** @@ -1983,9 +1743,8 @@ void emac_ptp_timestamp_enable(confirm_state new_state) * @param new_state: TRUE or FALSE. * @retval none */ -void emac_ptp_timestamp_fine_update_enable(confirm_state new_state) -{ - EMAC_PTP->tsctrl_bit.tfcu = new_state; +void emac_ptp_timestamp_fine_update_enable(confirm_state new_state) { + EMAC_PTP->tsctrl_bit.tfcu = new_state; } /** @@ -1993,9 +1752,8 @@ void emac_ptp_timestamp_fine_update_enable(confirm_state new_state) * @param new_state: TRUE or FALSE. * @retval none */ -void emac_ptp_timestamp_system_time_init(confirm_state new_state) -{ - EMAC_PTP->tsctrl_bit.ti = new_state; +void emac_ptp_timestamp_system_time_init(confirm_state new_state) { + EMAC_PTP->tsctrl_bit.ti = new_state; } /** @@ -2003,9 +1761,8 @@ void emac_ptp_timestamp_system_time_init(confirm_state new_state) * @param new_state: TRUE or FALSE. * @retval none */ -void emac_ptp_timestamp_system_time_update(confirm_state new_state) -{ - EMAC_PTP->tsctrl_bit.tu = new_state; +void emac_ptp_timestamp_system_time_update(confirm_state new_state) { + EMAC_PTP->tsctrl_bit.tu = new_state; } /** @@ -2013,9 +1770,8 @@ void emac_ptp_timestamp_system_time_update(confirm_state new_state) * @param new_state: TRUE or FALSE. * @retval none */ -void emac_ptp_interrupt_trigger_enable(confirm_state new_state) -{ - EMAC_PTP->tsctrl_bit.tite = new_state; +void emac_ptp_interrupt_trigger_enable(confirm_state new_state) { + EMAC_PTP->tsctrl_bit.tite = new_state; } /** @@ -2023,9 +1779,8 @@ void emac_ptp_interrupt_trigger_enable(confirm_state new_state) * @param new_state: TRUE or FALSE. * @retval none */ -void emac_ptp_addend_register_update(confirm_state new_state) -{ - EMAC_PTP->tsctrl_bit.aru = new_state; +void emac_ptp_addend_register_update(confirm_state new_state) { + EMAC_PTP->tsctrl_bit.aru = new_state; } /** @@ -2033,9 +1788,8 @@ void emac_ptp_addend_register_update(confirm_state new_state) * @param new_state: TRUE or FALSE. * @retval none */ -void emac_ptp_snapshot_received_frames_enable(confirm_state new_state) -{ - EMAC_PTP->tsctrl_bit.etaf = new_state; +void emac_ptp_snapshot_received_frames_enable(confirm_state new_state) { + EMAC_PTP->tsctrl_bit.etaf = new_state; } /** @@ -2043,9 +1797,8 @@ void emac_ptp_snapshot_received_frames_enable(confirm_state new_state) * @param new_state: TRUE or FALSE. * @retval none */ -void emac_ptp_subsecond_rollover_enable(confirm_state new_state) -{ - EMAC_PTP->tsctrl_bit.tdbrc = new_state; +void emac_ptp_subsecond_rollover_enable(confirm_state new_state) { + EMAC_PTP->tsctrl_bit.tdbrc = new_state; } /** @@ -2053,9 +1806,8 @@ void emac_ptp_subsecond_rollover_enable(confirm_state new_state) * @param new_state: TRUE or FALSE. * @retval none */ -void emac_ptp_psv2_enable(confirm_state new_state) -{ - EMAC_PTP->tsctrl_bit.eppv2f = new_state; +void emac_ptp_psv2_enable(confirm_state new_state) { + EMAC_PTP->tsctrl_bit.eppv2f = new_state; } /** @@ -2063,9 +1815,8 @@ void emac_ptp_psv2_enable(confirm_state new_state) * @param new_state: TRUE or FALSE. * @retval none */ -void emac_ptp_snapshot_emac_frames_enable(confirm_state new_state) -{ - EMAC_PTP->tsctrl_bit.eppef = new_state; +void emac_ptp_snapshot_emac_frames_enable(confirm_state new_state) { + EMAC_PTP->tsctrl_bit.eppef = new_state; } /** @@ -2073,9 +1824,8 @@ void emac_ptp_snapshot_emac_frames_enable(confirm_state new_state) * @param new_state: TRUE or FALSE. * @retval none */ -void emac_ptp_snapshot_ipv6_frames_enable(confirm_state new_state) -{ - EMAC_PTP->tsctrl_bit.eppfsip6u = new_state; +void emac_ptp_snapshot_ipv6_frames_enable(confirm_state new_state) { + EMAC_PTP->tsctrl_bit.eppfsip6u = new_state; } /** @@ -2083,9 +1833,8 @@ void emac_ptp_snapshot_ipv6_frames_enable(confirm_state new_state) * @param new_state: TRUE or FALSE. * @retval none */ -void emac_ptp_snapshot_ipv4_frames_enable(confirm_state new_state) -{ - EMAC_PTP->tsctrl_bit.eppfsip4u = new_state; +void emac_ptp_snapshot_ipv4_frames_enable(confirm_state new_state) { + EMAC_PTP->tsctrl_bit.eppfsip4u = new_state; } /** @@ -2093,9 +1842,8 @@ void emac_ptp_snapshot_ipv4_frames_enable(confirm_state new_state) * @param new_state: TRUE or FALSE. * @retval none */ -void emac_ptp_snapshot_event_message_enable(confirm_state new_state) -{ - EMAC_PTP->tsctrl_bit.etsfem = new_state; +void emac_ptp_snapshot_event_message_enable(confirm_state new_state) { + EMAC_PTP->tsctrl_bit.etsfem = new_state; } /** @@ -2103,9 +1851,8 @@ void emac_ptp_snapshot_event_message_enable(confirm_state new_state) * @param new_state: TRUE or FALSE. * @retval none */ -void emac_ptp_snapshot_master_event_enable(confirm_state new_state) -{ - EMAC_PTP->tsctrl_bit.esfmrtm = new_state; +void emac_ptp_snapshot_master_event_enable(confirm_state new_state) { + EMAC_PTP->tsctrl_bit.esfmrtm = new_state; } /** @@ -2118,9 +1865,8 @@ void emac_ptp_snapshot_master_event_enable(confirm_state new_state) * - EMAC_PTP_PEER_TO_PEER_CLOCK * @retval none */ -void emac_ptp_clock_node_set(emac_ptp_clock_node_type node) -{ - EMAC_PTP->tsctrl_bit.sppfts = node; +void emac_ptp_clock_node_set(emac_ptp_clock_node_type node) { + EMAC_PTP->tsctrl_bit.sppfts = node; } /** @@ -2128,9 +1874,8 @@ void emac_ptp_clock_node_set(emac_ptp_clock_node_type node) * @param new_state: TRUE or FALSE. * @retval none */ -void emac_ptp_mac_address_filter_enable(confirm_state new_state) -{ - EMAC_PTP->tsctrl_bit.emafpff = new_state; +void emac_ptp_mac_address_filter_enable(confirm_state new_state) { + EMAC_PTP->tsctrl_bit.emafpff = new_state; } /** @@ -2142,16 +1887,12 @@ void emac_ptp_mac_address_filter_enable(confirm_state new_state) * - EMAC_PTP_ARU_FLAG: transmit data buffer empty flag * @retval the new state of usart_flag (SET or RESET). */ -flag_status emac_ptp_flag_get(uint32_t flag) -{ - if(EMAC_PTP->tsctrl & flag) - { - return SET; - } - else - { - return RESET; - } +flag_status emac_ptp_flag_get(uint32_t flag) { + if (EMAC_PTP->tsctrl & flag) { + return SET; + } else { + return RESET; + } } /** @@ -2159,9 +1900,8 @@ flag_status emac_ptp_flag_get(uint32_t flag) * @param value: add to subsecond value for every update * @retval none */ -void emac_ptp_subsecond_increment_set(uint8_t value) -{ - EMAC_PTP->ssinc_bit.ssiv = value; +void emac_ptp_subsecond_increment_set(uint8_t value) { + EMAC_PTP->ssinc_bit.ssiv = value; } /** @@ -2169,10 +1909,9 @@ void emac_ptp_subsecond_increment_set(uint8_t value) * @param none * @retval system time second */ -uint32_t emac_ptp_system_second_get(void) -{ - uint32_t second = EMAC_PTP->tsh_bit.ts; - return second; +uint32_t emac_ptp_system_second_get(void) { + uint32_t second = EMAC_PTP->tsh_bit.ts; + return second; } /** @@ -2180,10 +1919,9 @@ uint32_t emac_ptp_system_second_get(void) * @param none * @retval system time subsecond */ -uint32_t emac_ptp_system_subsecond_get(void) -{ - uint32_t subsecond = EMAC_PTP->tsl_bit.tss; - return subsecond; +uint32_t emac_ptp_system_subsecond_get(void) { + uint32_t subsecond = EMAC_PTP->tsl_bit.tss; + return subsecond; } /** @@ -2191,16 +1929,12 @@ uint32_t emac_ptp_system_subsecond_get(void) * @param none * @retval TRUE or FALSE */ -confirm_state emac_ptp_system_time_sign_get(void) -{ - if(EMAC_PTP->tsl_bit.ast) - { - return TRUE; - } - else - { - return FALSE; - } +confirm_state emac_ptp_system_time_sign_get(void) { + if (EMAC_PTP->tsl_bit.ast) { + return TRUE; + } else { + return FALSE; + } } /** @@ -2210,11 +1944,10 @@ confirm_state emac_ptp_system_time_sign_get(void) * @param subsecond: system time subsecond * @retval none */ -void emac_ptp_system_time_set(uint32_t sign, uint32_t second, uint32_t subsecond) -{ - EMAC_PTP->tslud_bit.ast = sign ? 1 : 0; - EMAC_PTP->tshud_bit.ts = second; - EMAC_PTP->tslud_bit.tss = subsecond; +void emac_ptp_system_time_set(uint32_t sign, uint32_t second, uint32_t subsecond) { + EMAC_PTP->tslud_bit.ast = sign ? 1 : 0; + EMAC_PTP->tshud_bit.ts = second; + EMAC_PTP->tslud_bit.tss = subsecond; } /** @@ -2222,9 +1955,8 @@ void emac_ptp_system_time_set(uint32_t sign, uint32_t second, uint32_t subsecond * @param value: to achieve time synchronization * @retval none */ -void emac_ptp_timestamp_addend_set(uint32_t value) -{ - EMAC_PTP->tsad_bit.tar = value; +void emac_ptp_timestamp_addend_set(uint32_t value) { + EMAC_PTP->tsad_bit.tar = value; } /** @@ -2232,9 +1964,8 @@ void emac_ptp_timestamp_addend_set(uint32_t value) * @param value: to set target time second * @retval none */ -void emac_ptp_target_second_set(uint32_t value) -{ - EMAC_PTP->tth_bit.ttsr = value; +void emac_ptp_target_second_set(uint32_t value) { + EMAC_PTP->tth_bit.ttsr = value; } /** @@ -2242,9 +1973,8 @@ void emac_ptp_target_second_set(uint32_t value) * @param value: to set target time nanosecond * @retval none */ -void emac_ptp_target_nanosecond_set(uint32_t value) -{ - EMAC_PTP->ttl_bit.ttlr = value; +void emac_ptp_target_nanosecond_set(uint32_t value) { + EMAC_PTP->ttl_bit.ttlr = value; } /** @@ -2255,34 +1985,24 @@ void emac_ptp_target_nanosecond_set(uint32_t value) * - EMAC_PTP_TARGET_TIME_REACH * @retval TRUE or FALSE */ -confirm_state emac_ptp_timestamp_status_get(emac_ptp_timestamp_status_type status) -{ - switch(status) - { - case EMAC_PTP_SECOND_OVERFLOW: - { - if(EMAC_PTP->tssr_bit.tso) - { - return TRUE; - } - else - { - return FALSE; - } +confirm_state emac_ptp_timestamp_status_get(emac_ptp_timestamp_status_type status) { + switch (status) { + case EMAC_PTP_SECOND_OVERFLOW: { + if (EMAC_PTP->tssr_bit.tso) { + return TRUE; + } else { + return FALSE; + } + } + case EMAC_PTP_TARGET_TIME_REACH: { + if (EMAC_PTP->tssr_bit.tttr) { + return TRUE; + } else { + return FALSE; + } + } } - case EMAC_PTP_TARGET_TIME_REACH: - { - if(EMAC_PTP->tssr_bit.tttr) - { - return TRUE; - } - else - { - return FALSE; - } - } - } - return FALSE; + return FALSE; } /** @@ -2307,9 +2027,8 @@ confirm_state emac_ptp_timestamp_status_get(emac_ptp_timestamp_status_type statu * - EMAC_PTP_PPS_32768HZ * @retval none */ -void emac_ptp_pps_frequency_set(emac_ptp_pps_control_type freq) -{ - EMAC_PTP->ppscr_bit.pofc = freq; +void emac_ptp_pps_frequency_set(emac_ptp_pps_control_type freq) { + EMAC_PTP->ppscr_bit.pofc = freq; } /** @@ -2317,14 +2036,11 @@ void emac_ptp_pps_frequency_set(emac_ptp_pps_control_type freq) * @param delay: delay time * @retval none */ -static void emac_delay(uint32_t delay) -{ - __IO uint32_t delay_time = delay * (system_core_clock / 8 / 1000); - do - { - __NOP(); - } - while(delay_time --); +static void emac_delay(uint32_t delay) { + __IO uint32_t delay_time = delay * (system_core_clock / 8 / 1000); + do { + __NOP(); + } while (delay_time --); } /** @@ -2348,14 +2064,13 @@ static void emac_delay(uint32_t delay) * - EMAC_DMA_NIS_FLAG * @retval the new state of dma_flag (SET or RESET). */ -flag_status emac_dma_flag_get(uint32_t dma_flag) -{ - flag_status status = RESET; +flag_status emac_dma_flag_get(uint32_t dma_flag) { + flag_status status = RESET; - if(EMAC_DMA->sts & dma_flag) - status = SET; - /* return the new state (SET or RESET) */ - return status; + if (EMAC_DMA->sts & dma_flag) + status = SET; + /* return the new state (SET or RESET) */ + return status; } /** @@ -2379,39 +2094,37 @@ flag_status emac_dma_flag_get(uint32_t dma_flag) * - EMAC_DMA_NIS_FLAG * @retval the new state of dma_flag (SET or RESET). */ -flag_status emac_dma_interrupt_flag_get(uint32_t dma_flag) -{ - flag_status status = RESET; - switch(dma_flag) - { - case EMAC_DMA_TI_FLAG: - case EMAC_DMA_TBU_FLAG: - case EMAC_DMA_RI_FLAG: - case EMAC_DMA_ERI_FLAG: - if((EMAC_DMA->sts & dma_flag) && - (EMAC_DMA->ie & dma_flag) && - (EMAC_DMA->sts & EMAC_DMA_NIS_FLAG)) - status = SET; - break; - case EMAC_DMA_TPS_FLAG: - case EMAC_DMA_TJT_FLAG: - case EMAC_DMA_OVF_FLAG: - case EMAC_DMA_UNF_FLAG: - case EMAC_DMA_RBU_FLAG: - case EMAC_DMA_RPS_FLAG: - case EMAC_DMA_RWT_FLAG: - case EMAC_DMA_ETI_FLAG: - case EMAC_DMA_FBEI_FLAG: - if((EMAC_DMA->sts & dma_flag) && - (EMAC_DMA->ie & dma_flag) && - (EMAC_DMA->sts & EMAC_DMA_AIS_FLAG)) - status = SET; - break; - default: - break; - } - /* return the new state (SET or RESET) */ - return status; +flag_status emac_dma_interrupt_flag_get(uint32_t dma_flag) { + flag_status status = RESET; + switch (dma_flag) { + case EMAC_DMA_TI_FLAG: + case EMAC_DMA_TBU_FLAG: + case EMAC_DMA_RI_FLAG: + case EMAC_DMA_ERI_FLAG: + if ((EMAC_DMA->sts & dma_flag) && + (EMAC_DMA->ie & dma_flag) && + (EMAC_DMA->sts & EMAC_DMA_NIS_FLAG)) + status = SET; + break; + case EMAC_DMA_TPS_FLAG: + case EMAC_DMA_TJT_FLAG: + case EMAC_DMA_OVF_FLAG: + case EMAC_DMA_UNF_FLAG: + case EMAC_DMA_RBU_FLAG: + case EMAC_DMA_RPS_FLAG: + case EMAC_DMA_RWT_FLAG: + case EMAC_DMA_ETI_FLAG: + case EMAC_DMA_FBEI_FLAG: + if ((EMAC_DMA->sts & dma_flag) && + (EMAC_DMA->ie & dma_flag) && + (EMAC_DMA->sts & EMAC_DMA_AIS_FLAG)) + status = SET; + break; + default: + break; + } + /* return the new state (SET or RESET) */ + return status; } /** @@ -2435,9 +2148,8 @@ flag_status emac_dma_interrupt_flag_get(uint32_t dma_flag) * - EMAC_DMA_NIS_FLAG * @retval none */ -void emac_dma_flag_clear(uint32_t dma_flag) -{ - EMAC_DMA->sts = dma_flag; +void emac_dma_flag_clear(uint32_t dma_flag) { + EMAC_DMA->sts = dma_flag; } /** diff --git a/armlib/at32_sys/drivers/src/at32f435_437_ertc.c b/armlib/at32_sys/drivers/src/at32f435_437_ertc.c index 535ef581c..0ccaf4e79 100644 --- a/armlib/at32_sys/drivers/src/at32f435_437_ertc.c +++ b/armlib/at32_sys/drivers/src/at32f435_437_ertc.c @@ -47,14 +47,13 @@ * @param num: number(0~99) * @retval bcd code. */ -uint8_t ertc_num_to_bcd(uint8_t num) -{ - uint8_t bcd_h = 0, bcd_l = 0; +uint8_t ertc_num_to_bcd(uint8_t num) { + uint8_t bcd_h = 0, bcd_l = 0; - bcd_h = num / 10; - bcd_l = num % 10; + bcd_h = num / 10; + bcd_l = num % 10; - return ((uint8_t)(bcd_h << 4) | bcd_l); + return ((uint8_t)(bcd_h << 4) | bcd_l); } /** @@ -62,9 +61,8 @@ uint8_t ertc_num_to_bcd(uint8_t num) * @param bcd: bcd code(0~99). * @retval number. */ -uint8_t ertc_bcd_to_num(uint8_t bcd) -{ - return ((((uint8_t)(bcd & (uint8_t)0xF0) >> 4) * 10) + (bcd & (uint8_t)0x0F)); +uint8_t ertc_bcd_to_num(uint8_t bcd) { + return ((((uint8_t)(bcd & (uint8_t)0xF0) >> 4) * 10) + (bcd & (uint8_t)0x0F)); } /** @@ -72,9 +70,8 @@ uint8_t ertc_bcd_to_num(uint8_t bcd) * @param none. * @retval none */ -void ertc_write_protect_enable(void) -{ - ERTC->wp = 0xFF; +void ertc_write_protect_enable(void) { + ERTC->wp = 0xFF; } /** @@ -82,10 +79,9 @@ void ertc_write_protect_enable(void) * @param none. * @retval none */ -void ertc_write_protect_disable(void) -{ - ERTC->wp = 0xCA; - ERTC->wp = 0x53; +void ertc_write_protect_disable(void) { + ERTC->wp = 0xCA; + ERTC->wp = 0x53; } /** @@ -93,24 +89,21 @@ void ertc_write_protect_disable(void) * @param none. * @retval error_status (ERROR or SUCCESS). */ -error_status ertc_wait_update(void) -{ - uint32_t timeout = ERTC_TIMEOUT * 2; +error_status ertc_wait_update(void) { + uint32_t timeout = ERTC_TIMEOUT * 2; - /* clear updf flag */ - ERTC->sts = ~(ERTC_UPDF_FLAG | 0x00000080) | (ERTC->sts_bit.imen << 7); + /* clear updf flag */ + ERTC->sts = ~(ERTC_UPDF_FLAG | 0x00000080) | (ERTC->sts_bit.imen << 7); - while(ERTC->sts_bit.updf == 0) - { - if(timeout == 0) - { - return ERROR; + while (ERTC->sts_bit.updf == 0) { + if (timeout == 0) { + return ERROR; + } + + timeout--; } - timeout--; - } - - return SUCCESS; + return SUCCESS; } /** @@ -128,24 +121,21 @@ error_status ertc_wait_update(void) * - RESET. * @retval error_status (ERROR or SUCCESS). */ -error_status ertc_wait_flag(uint32_t flag, flag_status status) -{ - uint32_t timeout = ERTC_TIMEOUT; +error_status ertc_wait_flag(uint32_t flag, flag_status status) { + uint32_t timeout = ERTC_TIMEOUT; - while(ertc_flag_get(flag) == status) - { - if(timeout == 0) - { - /* enable write protection */ - ertc_write_protect_enable(); + while (ertc_flag_get(flag) == status) { + if (timeout == 0) { + /* enable write protection */ + ertc_write_protect_enable(); - return ERROR; + return ERROR; + } + + timeout--; } - timeout--; - } - - return SUCCESS; + return SUCCESS; } /** @@ -153,30 +143,26 @@ error_status ertc_wait_flag(uint32_t flag, flag_status status) * @param none. * @retval error_status (ERROR or SUCCESS). */ -error_status ertc_init_mode_enter(void) -{ - uint32_t timeout = ERTC_TIMEOUT * 2; +error_status ertc_init_mode_enter(void) { + uint32_t timeout = ERTC_TIMEOUT * 2; - if(ERTC->sts_bit.imf == 0) - { - /* enter init mode */ - ERTC->sts = 0xFFFFFFFF; + if (ERTC->sts_bit.imf == 0) { + /* enter init mode */ + ERTC->sts = 0xFFFFFFFF; - while(ERTC->sts_bit.imf == 0) - { - if(timeout == 0) - { - /* enable write protection */ - ertc_write_protect_enable(); + while (ERTC->sts_bit.imf == 0) { + if (timeout == 0) { + /* enable write protection */ + ertc_write_protect_enable(); - return ERROR; - } + return ERROR; + } - timeout--; + timeout--; + } } - } - return SUCCESS; + return SUCCESS; } /** @@ -184,9 +170,8 @@ error_status ertc_init_mode_enter(void) * @param none. * @retval none. */ -void ertc_init_mode_exit(void) -{ - ERTC->sts = 0xFFFFFF7F; +void ertc_init_mode_exit(void) { + ERTC->sts = 0xFFFFFF7F; } /** @@ -194,42 +179,40 @@ void ertc_init_mode_exit(void) * @param none. * @retval error_status (ERROR or SUCCESS). */ -error_status ertc_reset(void) -{ - /* disable write protection */ - ertc_write_protect_disable(); +error_status ertc_reset(void) { + /* disable write protection */ + ertc_write_protect_disable(); - ERTC->ctrl = (uint32_t)0x00000000; + ERTC->ctrl = (uint32_t)0x00000000; - /* enter init mode */ - if(ertc_init_mode_enter() != SUCCESS) - { - return ERROR; - } + /* enter init mode */ + if (ertc_init_mode_enter() != SUCCESS) { + return ERROR; + } - /* reset register */ - ERTC->time = (uint32_t)0x00000000; - ERTC->date = (uint32_t)0x00002101; - ERTC->ctrl = (uint32_t)0x00000000; - ERTC->div = (uint32_t)0x007F00FF; - ERTC->wat = (uint32_t)0x0000FFFF; - ERTC->ccal = (uint32_t)0x00000000; - ERTC->ala = (uint32_t)0x00000000; - ERTC->alb = (uint32_t)0x00000000; - ERTC->tadj = (uint32_t)0x00000000; - ERTC->scal = (uint32_t)0x00000000; - ERTC->tamp = (uint32_t)0x00000000; - ERTC->alasbs = (uint32_t)0x00000000; - ERTC->albsbs = (uint32_t)0x00000000; - ERTC->sts = (uint32_t)0x00000000; + /* reset register */ + ERTC->time = (uint32_t)0x00000000; + ERTC->date = (uint32_t)0x00002101; + ERTC->ctrl = (uint32_t)0x00000000; + ERTC->div = (uint32_t)0x007F00FF; + ERTC->wat = (uint32_t)0x0000FFFF; + ERTC->ccal = (uint32_t)0x00000000; + ERTC->ala = (uint32_t)0x00000000; + ERTC->alb = (uint32_t)0x00000000; + ERTC->tadj = (uint32_t)0x00000000; + ERTC->scal = (uint32_t)0x00000000; + ERTC->tamp = (uint32_t)0x00000000; + ERTC->alasbs = (uint32_t)0x00000000; + ERTC->albsbs = (uint32_t)0x00000000; + ERTC->sts = (uint32_t)0x00000000; - /* wait calendar update */ - ertc_wait_update(); + /* wait calendar update */ + ertc_wait_update(); - /* enable write protection */ - ertc_write_protect_enable(); + /* enable write protection */ + ertc_write_protect_enable(); - return SUCCESS; + return SUCCESS; } /** @@ -238,28 +221,26 @@ error_status ertc_reset(void) * @param div_b: division b (0~0x7FFF). * @retval error_status (ERROR or SUCCESS). */ -error_status ertc_divider_set(uint16_t div_a, uint16_t div_b) -{ - /* disable write protection */ - ertc_write_protect_disable(); +error_status ertc_divider_set(uint16_t div_a, uint16_t div_b) { + /* disable write protection */ + ertc_write_protect_disable(); - /* enter init mode */ - if(ertc_init_mode_enter() != SUCCESS) - { - return ERROR; - } + /* enter init mode */ + if (ertc_init_mode_enter() != SUCCESS) { + return ERROR; + } - /* config the ertc divider */ - ERTC->div_bit.diva = div_a; - ERTC->div_bit.divb = div_b; + /* config the ertc divider */ + ERTC->div_bit.diva = div_a; + ERTC->div_bit.divb = div_b; - /* exit init mode */ - ertc_init_mode_exit(); + /* exit init mode */ + ertc_init_mode_exit(); - /* enable write protection */ - ertc_write_protect_enable(); + /* enable write protection */ + ertc_write_protect_enable(); - return SUCCESS; + return SUCCESS; } /** @@ -270,27 +251,25 @@ error_status ertc_divider_set(uint16_t div_a, uint16_t div_b) * - ERTC_HOUR_MODE_12: 12-hour format. * @retval error_status (ERROR or SUCCESS). */ -error_status ertc_hour_mode_set(ertc_hour_mode_set_type mode) -{ - /* disable write protection */ - ertc_write_protect_disable(); +error_status ertc_hour_mode_set(ertc_hour_mode_set_type mode) { + /* disable write protection */ + ertc_write_protect_disable(); - /* enter init mode */ - if(ertc_init_mode_enter() != SUCCESS) - { - return ERROR; - } + /* enter init mode */ + if (ertc_init_mode_enter() != SUCCESS) { + return ERROR; + } - /* write register */ - ERTC->ctrl_bit.hm = mode; + /* write register */ + ERTC->ctrl_bit.hm = mode; - /* exit init mode */ - ertc_init_mode_exit(); + /* exit init mode */ + ertc_init_mode_exit(); - /* enable write protection */ - ertc_write_protect_enable(); + /* enable write protection */ + ertc_write_protect_enable(); - return SUCCESS; + return SUCCESS; } /** @@ -301,41 +280,38 @@ error_status ertc_hour_mode_set(ertc_hour_mode_set_type mode) * @param week: week (1~7). * @retval error_status (ERROR or SUCCESS). */ -error_status ertc_date_set(uint8_t year, uint8_t month, uint8_t date, uint8_t week) -{ - ertc_reg_date_type reg; +error_status ertc_date_set(uint8_t year, uint8_t month, uint8_t date, uint8_t week) { + ertc_reg_date_type reg; - reg.date = 0; + reg.date = 0; - reg.date_bit.y = ertc_num_to_bcd(year); - reg.date_bit.m = ertc_num_to_bcd(month); - reg.date_bit.d = ertc_num_to_bcd(date); - reg.date_bit.wk = week; + reg.date_bit.y = ertc_num_to_bcd(year); + reg.date_bit.m = ertc_num_to_bcd(month); + reg.date_bit.d = ertc_num_to_bcd(date); + reg.date_bit.wk = week; - /* disable write protection */ - ertc_write_protect_disable(); + /* disable write protection */ + ertc_write_protect_disable(); - /* enter init mode */ - if(ertc_init_mode_enter() != SUCCESS) - { - return ERROR; - } + /* enter init mode */ + if (ertc_init_mode_enter() != SUCCESS) { + return ERROR; + } - /* set the ertc_date register */ - ERTC->date = reg.date; + /* set the ertc_date register */ + ERTC->date = reg.date; - /* exit init mode */ - ertc_init_mode_exit(); + /* exit init mode */ + ertc_init_mode_exit(); - if(ERTC->ctrl_bit.dren == 0) - { - ertc_wait_update(); - } + if (ERTC->ctrl_bit.dren == 0) { + ertc_wait_update(); + } - /* enable write protection */ - ertc_write_protect_enable(); + /* enable write protection */ + ertc_write_protect_enable(); - return SUCCESS; + return SUCCESS; } /** @@ -350,40 +326,37 @@ error_status ertc_date_set(uint8_t year, uint8_t month, uint8_t date, uint8_t we * - ERTC_PM: 12-hour format, post meridiem. * @retval error_status (ERROR or SUCCESS). */ -error_status ertc_time_set(uint8_t hour, uint8_t min, uint8_t sec, ertc_am_pm_type ampm) -{ - ertc_reg_time_type reg; +error_status ertc_time_set(uint8_t hour, uint8_t min, uint8_t sec, ertc_am_pm_type ampm) { + ertc_reg_time_type reg; - reg.time = 0; + reg.time = 0; - reg.time_bit.h = ertc_num_to_bcd(hour); - reg.time_bit.m = ertc_num_to_bcd(min); - reg.time_bit.s = ertc_num_to_bcd(sec); - reg.time_bit.ampm = ampm; + reg.time_bit.h = ertc_num_to_bcd(hour); + reg.time_bit.m = ertc_num_to_bcd(min); + reg.time_bit.s = ertc_num_to_bcd(sec); + reg.time_bit.ampm = ampm; - /* disable write protection */ - ertc_write_protect_disable(); + /* disable write protection */ + ertc_write_protect_disable(); - /* enter init mode */ - if(ertc_init_mode_enter() != SUCCESS) - { - return ERROR; - } + /* enter init mode */ + if (ertc_init_mode_enter() != SUCCESS) { + return ERROR; + } - ERTC->time = reg.time; + ERTC->time = reg.time; - /* exit init mode */ - ertc_init_mode_exit(); + /* exit init mode */ + ertc_init_mode_exit(); - if(ERTC->ctrl_bit.dren == 0) - { - ertc_wait_update(); - } + if (ERTC->ctrl_bit.dren == 0) { + ertc_wait_update(); + } - /* enable write protection */ - ertc_write_protect_enable(); + /* enable write protection */ + ertc_write_protect_enable(); - return SUCCESS; + return SUCCESS; } /** @@ -391,23 +364,22 @@ error_status ertc_time_set(uint8_t hour, uint8_t min, uint8_t sec, ertc_am_pm_ty * @param time: ertc time. * @retval none. */ -void ertc_calendar_get(ertc_time_type* time) -{ - ertc_reg_time_type reg_tm; - ertc_reg_date_type reg_dt; +void ertc_calendar_get(ertc_time_type *time) { + ertc_reg_time_type reg_tm; + ertc_reg_date_type reg_dt; - reg_tm.time = ERTC->time; - reg_dt.date = ERTC->date; + reg_tm.time = ERTC->time; + reg_dt.date = ERTC->date; - time->hour = ertc_bcd_to_num(reg_tm.time_bit.h); - time->min = ertc_bcd_to_num(reg_tm.time_bit.m); - time->sec = ertc_bcd_to_num(reg_tm.time_bit.s); - time->ampm = (ertc_am_pm_type)reg_tm.time_bit.ampm; + time->hour = ertc_bcd_to_num(reg_tm.time_bit.h); + time->min = ertc_bcd_to_num(reg_tm.time_bit.m); + time->sec = ertc_bcd_to_num(reg_tm.time_bit.s); + time->ampm = (ertc_am_pm_type)reg_tm.time_bit.ampm; - time->year = ertc_bcd_to_num(reg_dt.date_bit.y); - time->month = ertc_bcd_to_num(reg_dt.date_bit.m); - time->day = ertc_bcd_to_num(reg_dt.date_bit.d); - time->week = reg_dt.date_bit.wk; + time->year = ertc_bcd_to_num(reg_dt.date_bit.y); + time->month = ertc_bcd_to_num(reg_dt.date_bit.m); + time->day = ertc_bcd_to_num(reg_dt.date_bit.d); + time->week = reg_dt.date_bit.wk; } /** @@ -415,15 +387,14 @@ void ertc_calendar_get(ertc_time_type* time) * @param none. * @retval sub second. */ -uint32_t ertc_sub_second_get(void) -{ - uint32_t reg = 0; +uint32_t ertc_sub_second_get(void) { + uint32_t reg = 0; - reg = ERTC->sbs; + reg = ERTC->sbs; - (void) (ERTC->date); + (void)(ERTC->date); - return (reg); + return (reg); } /** @@ -443,34 +414,30 @@ uint32_t ertc_sub_second_get(void) * @param alarm: alarm para. * @retval none. */ -void ertc_alarm_mask_set(ertc_alarm_type alarm_x, uint32_t mask) -{ - uint32_t reg; +void ertc_alarm_mask_set(ertc_alarm_type alarm_x, uint32_t mask) { + uint32_t reg; - /* disable write protection */ - ertc_write_protect_disable(); + /* disable write protection */ + ertc_write_protect_disable(); - if(alarm_x == ERTC_ALA) - { - reg = ERTC->ala; + if (alarm_x == ERTC_ALA) { + reg = ERTC->ala; - reg &= ~ERTC_ALARM_MASK_ALL; - reg |= mask; + reg &= ~ERTC_ALARM_MASK_ALL; + reg |= mask; - ERTC->ala= reg; - } - else - { - reg = ERTC->alb; + ERTC->ala = reg; + } else { + reg = ERTC->alb; - reg &= ~ERTC_ALARM_MASK_ALL; - reg |= mask; + reg &= ~ERTC_ALARM_MASK_ALL; + reg |= mask; - ERTC->alb= reg; - } + ERTC->alb = reg; + } - /* enable write protection */ - ertc_write_protect_enable(); + /* enable write protection */ + ertc_write_protect_enable(); } /** @@ -485,22 +452,18 @@ void ertc_alarm_mask_set(ertc_alarm_type alarm_x, uint32_t mask) * - ERTC_SLECT_WEEK: slect week mode. * @retval none. */ -void ertc_alarm_week_date_select(ertc_alarm_type alarm_x, ertc_week_date_select_type wk) -{ - /* disable write protection */ - ertc_write_protect_disable(); +void ertc_alarm_week_date_select(ertc_alarm_type alarm_x, ertc_week_date_select_type wk) { + /* disable write protection */ + ertc_write_protect_disable(); - if(alarm_x == ERTC_ALA) - { - ERTC->ala_bit.wksel = wk; - } - else - { - ERTC->alb_bit.wksel = wk; - } + if (alarm_x == ERTC_ALA) { + ERTC->ala_bit.wksel = wk; + } else { + ERTC->alb_bit.wksel = wk; + } - /* enable write protection */ - ertc_write_protect_enable(); + /* enable write protection */ + ertc_write_protect_enable(); } /** @@ -523,39 +486,32 @@ void ertc_alarm_week_date_select(ertc_alarm_type alarm_x, ertc_week_date_select_ * @param alarm: alarm para. * @retval none. */ -void ertc_alarm_set(ertc_alarm_type alarm_x, uint8_t week_date, uint8_t hour, uint8_t min, uint8_t sec, ertc_am_pm_type ampm) -{ - ertc_reg_alarm_type reg; +void ertc_alarm_set(ertc_alarm_type alarm_x, uint8_t week_date, uint8_t hour, uint8_t min, uint8_t sec, ertc_am_pm_type ampm) { + ertc_reg_alarm_type reg; - if(alarm_x == ERTC_ALA) - { - reg.ala = ERTC->ala; - } - else - { - reg.ala = ERTC->alb; - } + if (alarm_x == ERTC_ALA) { + reg.ala = ERTC->ala; + } else { + reg.ala = ERTC->alb; + } - reg.ala_bit.d = ertc_num_to_bcd(week_date); - reg.ala_bit.h = ertc_num_to_bcd(hour); - reg.ala_bit.m = ertc_num_to_bcd(min); - reg.ala_bit.s = ertc_num_to_bcd(sec); - reg.ala_bit.ampm = ampm; + reg.ala_bit.d = ertc_num_to_bcd(week_date); + reg.ala_bit.h = ertc_num_to_bcd(hour); + reg.ala_bit.m = ertc_num_to_bcd(min); + reg.ala_bit.s = ertc_num_to_bcd(sec); + reg.ala_bit.ampm = ampm; - /* disable write protection */ - ertc_write_protect_disable(); + /* disable write protection */ + ertc_write_protect_disable(); - if(alarm_x == ERTC_ALA) - { - ERTC->ala= reg.ala; - } - else - { - ERTC->alb = reg.ala; - } + if (alarm_x == ERTC_ALA) { + ERTC->ala = reg.ala; + } else { + ERTC->alb = reg.ala; + } - /* enable write protection */ - ertc_write_protect_enable(); + /* enable write protection */ + ertc_write_protect_enable(); } /** @@ -585,24 +541,20 @@ void ertc_alarm_set(ertc_alarm_type alarm_x, uint8_t week_date, uint8_t hour, ui * - ERTC_ALARM_SBS_MASK_NONE: compare bit [14:0]. * @retval none. */ -void ertc_alarm_sub_second_set(ertc_alarm_type alarm_x, uint32_t value, ertc_alarm_sbs_mask_type mask) -{ - /* disable write protection */ - ertc_write_protect_disable(); +void ertc_alarm_sub_second_set(ertc_alarm_type alarm_x, uint32_t value, ertc_alarm_sbs_mask_type mask) { + /* disable write protection */ + ertc_write_protect_disable(); - if(alarm_x == ERTC_ALA) - { - ERTC->alasbs_bit.sbsmsk = mask; - ERTC->alasbs_bit.sbs = value; - } - else - { - ERTC->albsbs_bit.sbsmsk = mask; - ERTC->albsbs_bit.sbs = value; - } + if (alarm_x == ERTC_ALA) { + ERTC->alasbs_bit.sbsmsk = mask; + ERTC->alasbs_bit.sbs = value; + } else { + ERTC->albsbs_bit.sbsmsk = mask; + ERTC->albsbs_bit.sbs = value; + } - /* enable write protection */ - ertc_write_protect_enable(); + /* enable write protection */ + ertc_write_protect_enable(); } /** @@ -614,40 +566,32 @@ void ertc_alarm_sub_second_set(ertc_alarm_type alarm_x, uint32_t value, ertc_ala * @param new_state (TRUE or FALSE). * @retval error_status (ERROR or SUCCESS). */ -error_status ertc_alarm_enable(ertc_alarm_type alarm_x, confirm_state new_state) -{ - /* disable write protection */ - ertc_write_protect_disable(); +error_status ertc_alarm_enable(ertc_alarm_type alarm_x, confirm_state new_state) { + /* disable write protection */ + ertc_write_protect_disable(); - if(alarm_x == ERTC_ALA) - { - ERTC->ctrl_bit.alaen = new_state; + if (alarm_x == ERTC_ALA) { + ERTC->ctrl_bit.alaen = new_state; - if(new_state == FALSE) - { - if(ertc_wait_flag(ERTC_ALAWF_FLAG, RESET) != SUCCESS) - { - return ERROR; - } + if (new_state == FALSE) { + if (ertc_wait_flag(ERTC_ALAWF_FLAG, RESET) != SUCCESS) { + return ERROR; + } + } + } else { + ERTC->ctrl_bit.alben = new_state; + + if (new_state == FALSE) { + if (ertc_wait_flag(ERTC_ALBWF_FLAG, RESET) != SUCCESS) { + return ERROR; + } + } } - } - else - { - ERTC->ctrl_bit.alben = new_state; - if(new_state == FALSE) - { - if(ertc_wait_flag(ERTC_ALBWF_FLAG, RESET) != SUCCESS) - { - return ERROR; - } - } - } + /* enable write protection */ + ertc_write_protect_enable(); - /* enable write protection */ - ertc_write_protect_enable(); - - return SUCCESS; + return SUCCESS; } /** @@ -659,29 +603,25 @@ error_status ertc_alarm_enable(ertc_alarm_type alarm_x, confirm_state new_state) * @param alarm: alarm para. * @retval none. */ -void ertc_alarm_get(ertc_alarm_type alarm_x, ertc_alarm_value_type* alarm) -{ - ertc_reg_alarm_type reg; +void ertc_alarm_get(ertc_alarm_type alarm_x, ertc_alarm_value_type *alarm) { + ertc_reg_alarm_type reg; - reg.ala = 0; + reg.ala = 0; - if(alarm_x == ERTC_ALA) - { - reg.ala = ERTC->ala; - } - else - { - reg.ala = ERTC->alb; - } + if (alarm_x == ERTC_ALA) { + reg.ala = ERTC->ala; + } else { + reg.ala = ERTC->alb; + } - alarm->day = ertc_bcd_to_num(reg.ala_bit.d); - alarm->week = ertc_bcd_to_num(reg.ala_bit.d); - alarm->hour = ertc_bcd_to_num(reg.ala_bit.h); - alarm->min = ertc_bcd_to_num(reg.ala_bit.m); - alarm->sec = ertc_bcd_to_num(reg.ala_bit.s); - alarm->ampm = (ertc_am_pm_type)reg.ala_bit.ampm; - alarm->week_date_sel = reg.ala_bit.wksel; - alarm->mask = reg.ala & ERTC_ALARM_MASK_ALL; + alarm->day = ertc_bcd_to_num(reg.ala_bit.d); + alarm->week = ertc_bcd_to_num(reg.ala_bit.d); + alarm->hour = ertc_bcd_to_num(reg.ala_bit.h); + alarm->min = ertc_bcd_to_num(reg.ala_bit.m); + alarm->sec = ertc_bcd_to_num(reg.ala_bit.s); + alarm->ampm = (ertc_am_pm_type)reg.ala_bit.ampm; + alarm->week_date_sel = reg.ala_bit.wksel; + alarm->mask = reg.ala & ERTC_ALARM_MASK_ALL; } /** @@ -692,16 +632,12 @@ void ertc_alarm_get(ertc_alarm_type alarm_x, ertc_alarm_value_type* alarm) * - ERTC_ALB: alarm b. * @retval sub second. */ -uint32_t ertc_alarm_sub_second_get(ertc_alarm_type alarm_x) -{ - if(alarm_x == ERTC_ALA) - { - return (ERTC->alasbs_bit.sbs); - } - else - { - return (ERTC->albsbs_bit.sbs); - } +uint32_t ertc_alarm_sub_second_get(ertc_alarm_type alarm_x) { + if (alarm_x == ERTC_ALA) { + return (ERTC->alasbs_bit.sbs); + } else { + return (ERTC->albsbs_bit.sbs); + } } /** @@ -716,15 +652,14 @@ uint32_t ertc_alarm_sub_second_get(ertc_alarm_type alarm_x) * - ERTC_WAT_CLK_CK_B_17BITS: CK_B, wakeup counter = ERTC_WAT + 65535. * @retval none. */ -void ertc_wakeup_clock_set(ertc_wakeup_clock_type clock) -{ - /* disable write protection */ - ertc_write_protect_disable(); +void ertc_wakeup_clock_set(ertc_wakeup_clock_type clock) { + /* disable write protection */ + ertc_write_protect_disable(); - ERTC->ctrl_bit.watclk = clock; + ERTC->ctrl_bit.watclk = clock; - /* enable write protection */ - ertc_write_protect_enable(); + /* enable write protection */ + ertc_write_protect_enable(); } /** @@ -732,15 +667,14 @@ void ertc_wakeup_clock_set(ertc_wakeup_clock_type clock) * @param counter: wakeup counter(0~65535). * @retval none. */ -void ertc_wakeup_counter_set(uint32_t counter) -{ - /* disable write protection */ - ertc_write_protect_disable(); +void ertc_wakeup_counter_set(uint32_t counter) { + /* disable write protection */ + ertc_write_protect_disable(); - ERTC->wat_bit.val = counter; + ERTC->wat_bit.val = counter; - /* enable write protection */ - ertc_write_protect_enable(); + /* enable write protection */ + ertc_write_protect_enable(); } /** @@ -748,9 +682,8 @@ void ertc_wakeup_counter_set(uint32_t counter) * @param none. * @retval wakeup counter. */ -uint16_t ertc_wakeup_counter_get(void) -{ - return ERTC->wat_bit.val; +uint16_t ertc_wakeup_counter_get(void) { + return ERTC->wat_bit.val; } /** @@ -758,25 +691,22 @@ uint16_t ertc_wakeup_counter_get(void) * @param new_state (TRUE or FALSE). * @retval error_status (ERROR or SUCCESS). */ -error_status ertc_wakeup_enable(confirm_state new_state) -{ - /* disable write protection */ - ertc_write_protect_disable(); +error_status ertc_wakeup_enable(confirm_state new_state) { + /* disable write protection */ + ertc_write_protect_disable(); - ERTC->ctrl_bit.waten = new_state; + ERTC->ctrl_bit.waten = new_state; - if(new_state == FALSE) - { - if(ertc_wait_flag(ERTC_WATWF_FLAG, RESET) != SUCCESS) - { - return ERROR; + if (new_state == FALSE) { + if (ertc_wait_flag(ERTC_WATWF_FLAG, RESET) != SUCCESS) { + return ERROR; + } } - } - /* enable write protection */ - ertc_write_protect_enable(); + /* enable write protection */ + ertc_write_protect_enable(); - return SUCCESS; + return SUCCESS; } /** @@ -793,43 +723,40 @@ error_status ertc_wakeup_enable(confirm_state new_state) * @param clk_dec: decrease clock(0~511). * @retval error_status (ERROR or SUCCESS). */ -error_status ertc_smooth_calibration_config(ertc_smooth_cal_period_type period, ertc_smooth_cal_clk_add_type clk_add, uint32_t clk_dec) -{ - ertc_reg_scal_type reg; +error_status ertc_smooth_calibration_config(ertc_smooth_cal_period_type period, ertc_smooth_cal_clk_add_type clk_add, uint32_t clk_dec) { + ertc_reg_scal_type reg; - /* disable write protection */ - ertc_write_protect_disable(); + /* disable write protection */ + ertc_write_protect_disable(); - if(ertc_wait_flag(ERTC_CALUPDF_FLAG, SET) != SUCCESS) - { - return ERROR; - } + if (ertc_wait_flag(ERTC_CALUPDF_FLAG, SET) != SUCCESS) { + return ERROR; + } - reg.scal = 0; + reg.scal = 0; - switch (period) - { - case ERTC_SMOOTH_CAL_PERIOD_32: - break; - case ERTC_SMOOTH_CAL_PERIOD_16: - reg.scal_bit.cal16 = 1; - break; - case ERTC_SMOOTH_CAL_PERIOD_8: - reg.scal_bit.cal8 = 1; - break; - default: - break; - } + switch (period) { + case ERTC_SMOOTH_CAL_PERIOD_32: + break; + case ERTC_SMOOTH_CAL_PERIOD_16: + reg.scal_bit.cal16 = 1; + break; + case ERTC_SMOOTH_CAL_PERIOD_8: + reg.scal_bit.cal8 = 1; + break; + default: + break; + } - reg.scal_bit.add = clk_add; - reg.scal_bit.dec = clk_dec; + reg.scal_bit.add = clk_add; + reg.scal_bit.dec = clk_dec; - ERTC->scal = reg.scal; + ERTC->scal = reg.scal; - /* enable write protection */ - ertc_write_protect_enable(); + /* enable write protection */ + ertc_write_protect_enable(); - return SUCCESS; + return SUCCESS; } /** @@ -841,28 +768,26 @@ error_status ertc_smooth_calibration_config(ertc_smooth_cal_period_type period, * @param value: calibration value(0~31). * @retval error_status (ERROR or SUCCESS). */ -error_status ertc_coarse_calibration_set(ertc_cal_direction_type dir, uint32_t value) -{ - /* disable write protection */ - ertc_write_protect_disable(); +error_status ertc_coarse_calibration_set(ertc_cal_direction_type dir, uint32_t value) { + /* disable write protection */ + ertc_write_protect_disable(); - /* enter init mode */ - if(ertc_init_mode_enter() == ERROR) - { - return ERROR; - } + /* enter init mode */ + if (ertc_init_mode_enter() == ERROR) { + return ERROR; + } - ERTC->ccal_bit.caldir = dir; + ERTC->ccal_bit.caldir = dir; - ERTC->ccal_bit.calval = value; + ERTC->ccal_bit.calval = value; - /* exit init mode */ - ertc_init_mode_exit(); + /* exit init mode */ + ertc_init_mode_exit(); - /* enable write protection */ - ertc_write_protect_enable(); + /* enable write protection */ + ertc_write_protect_enable(); - return SUCCESS; + return SUCCESS; } /** @@ -870,26 +795,24 @@ error_status ertc_coarse_calibration_set(ertc_cal_direction_type dir, uint32_t v * @param new_state (TRUE or FALSE). * @retval error_status (ERROR or SUCCESS). */ -error_status ertc_coarse_calibration_enable(confirm_state new_state) -{ - /* disable write protection */ - ertc_write_protect_disable(); +error_status ertc_coarse_calibration_enable(confirm_state new_state) { + /* disable write protection */ + ertc_write_protect_disable(); - /* enter init mode */ - if(ertc_init_mode_enter() == ERROR) - { - return ERROR; - } + /* enter init mode */ + if (ertc_init_mode_enter() == ERROR) { + return ERROR; + } - ERTC->ctrl_bit.ccalen = new_state; + ERTC->ctrl_bit.ccalen = new_state; - /* exit init mode */ - ertc_init_mode_exit(); + /* exit init mode */ + ertc_init_mode_exit(); - /* enable write protection */ - ertc_write_protect_enable(); + /* enable write protection */ + ertc_write_protect_enable(); - return SUCCESS; + return SUCCESS; } /** @@ -900,15 +823,14 @@ error_status ertc_coarse_calibration_enable(confirm_state new_state) * - ERTC_CAL_OUTPUT_1HZ: output 1 hz. * @retval none. */ -void ertc_cal_output_select(ertc_cal_output_select_type output) -{ - /* disable write protection */ - ertc_write_protect_disable(); +void ertc_cal_output_select(ertc_cal_output_select_type output) { + /* disable write protection */ + ertc_write_protect_disable(); - ERTC->ctrl_bit.calosel = output; + ERTC->ctrl_bit.calosel = output; - /* enable write protection */ - ertc_write_protect_enable(); + /* enable write protection */ + ertc_write_protect_enable(); } /** @@ -916,15 +838,14 @@ void ertc_cal_output_select(ertc_cal_output_select_type output) * @param new_state (TRUE or FALSE). * @retval none. */ -void ertc_cal_output_enable(confirm_state new_state) -{ - /* disable write protection */ - ertc_write_protect_disable(); +void ertc_cal_output_enable(confirm_state new_state) { + /* disable write protection */ + ertc_write_protect_disable(); - ERTC->ctrl_bit.caloen = new_state; + ERTC->ctrl_bit.caloen = new_state; - /* enable write protection */ - ertc_write_protect_enable(); + /* enable write protection */ + ertc_write_protect_enable(); } /** @@ -936,42 +857,36 @@ void ertc_cal_output_enable(confirm_state new_state) * @param decsbs: decrease sub second(0~0x7FFF). * @retval error_status (ERROR or SUCCESS). */ -error_status ertc_time_adjust(ertc_time_adjust_type add1s, uint32_t decsbs) -{ - ertc_reg_tadj_type reg; +error_status ertc_time_adjust(ertc_time_adjust_type add1s, uint32_t decsbs) { + ertc_reg_tadj_type reg; - reg.tadj = 0; + reg.tadj = 0; - /* disable write protection */ - ertc_write_protect_disable(); + /* disable write protection */ + ertc_write_protect_disable(); - if(ertc_wait_flag(ERTC_TADJF_FLAG, SET) != SUCCESS) - { - return ERROR; - } - - /* check if the reference clock detection is disabled */ - if(ERTC->ctrl_bit.rcden == 0) - { - reg.tadj_bit.add1s = add1s; - reg.tadj_bit.decsbs = decsbs; - - ERTC->tadj = reg.tadj; - - if(ertc_wait_update() == ERROR) - { - return ERROR; + if (ertc_wait_flag(ERTC_TADJF_FLAG, SET) != SUCCESS) { + return ERROR; } - } - else - { - return ERROR; - } - /* enable write protection */ - ertc_write_protect_enable(); + /* check if the reference clock detection is disabled */ + if (ERTC->ctrl_bit.rcden == 0) { + reg.tadj_bit.add1s = add1s; + reg.tadj_bit.decsbs = decsbs; - return SUCCESS; + ERTC->tadj = reg.tadj; + + if (ertc_wait_update() == ERROR) { + return ERROR; + } + } else { + return ERROR; + } + + /* enable write protection */ + ertc_write_protect_enable(); + + return SUCCESS; } /** @@ -986,24 +901,20 @@ error_status ertc_time_adjust(ertc_time_adjust_type add1s, uint32_t decsbs) * - ERTC_DST_SAVE_1: set the bpr register value to 1. * @retval none. */ -void ertc_daylight_set(ertc_dst_operation_type operation, ertc_dst_save_type save) -{ - /* disable write protection */ - ertc_write_protect_disable(); +void ertc_daylight_set(ertc_dst_operation_type operation, ertc_dst_save_type save) { + /* disable write protection */ + ertc_write_protect_disable(); - if(operation == ERTC_DST_ADD_1H) - { - ERTC->ctrl_bit.add1h = 1; - } - else - { - ERTC->ctrl_bit.dec1h = 1; - } + if (operation == ERTC_DST_ADD_1H) { + ERTC->ctrl_bit.add1h = 1; + } else { + ERTC->ctrl_bit.dec1h = 1; + } - ERTC->ctrl_bit.bpr = save; + ERTC->ctrl_bit.bpr = save; - /* enable write protection */ - ertc_write_protect_enable(); + /* enable write protection */ + ertc_write_protect_enable(); } /** @@ -1011,9 +922,8 @@ void ertc_daylight_set(ertc_dst_operation_type operation, ertc_dst_save_type sav * @param none. * @retval bpr value. */ -uint8_t ertc_daylight_bpr_get(void) -{ - return ERTC->ctrl_bit.bpr; +uint8_t ertc_daylight_bpr_get(void) { + return ERTC->ctrl_bit.bpr; } /** @@ -1021,27 +931,25 @@ uint8_t ertc_daylight_bpr_get(void) * @param new_state (TRUE or FALSE). * @retval error_status (ERROR or SUCCESS). */ -error_status ertc_refer_clock_detect_enable(confirm_state new_state) -{ - /* disable write protection */ - ertc_write_protect_disable(); +error_status ertc_refer_clock_detect_enable(confirm_state new_state) { + /* disable write protection */ + ertc_write_protect_disable(); - /* enter init mode */ - if(ertc_init_mode_enter() != SUCCESS) - { - return ERROR; - } + /* enter init mode */ + if (ertc_init_mode_enter() != SUCCESS) { + return ERROR; + } - /* write register */ - ERTC->ctrl_bit.rcden = new_state; + /* write register */ + ERTC->ctrl_bit.rcden = new_state; - /* exit init mode */ - ertc_init_mode_exit(); + /* exit init mode */ + ertc_init_mode_exit(); - /* enable write protection */ - ertc_write_protect_enable(); + /* enable write protection */ + ertc_write_protect_enable(); - return SUCCESS; + return SUCCESS; } /** @@ -1049,15 +957,14 @@ error_status ertc_refer_clock_detect_enable(confirm_state new_state) * @param new_state (TRUE or FALSE). * @retval none. */ -void ertc_direct_read_enable(confirm_state new_state) -{ - /* disable write protection */ - ertc_write_protect_disable(); +void ertc_direct_read_enable(confirm_state new_state) { + /* disable write protection */ + ertc_write_protect_disable(); - ERTC->ctrl_bit.dren = new_state; + ERTC->ctrl_bit.dren = new_state; - /* enable write protection */ - ertc_write_protect_enable(); + /* enable write protection */ + ertc_write_protect_enable(); } /** @@ -1078,19 +985,18 @@ void ertc_direct_read_enable(confirm_state new_state) * - ERTC_OUTPUT_TYPE_PUSH_PULL: push pull output. * @retval none. */ -void ertc_output_set(ertc_output_source_type source, ertc_output_polarity_type polarity, ertc_output_type type) -{ - /* disable write protection */ - ertc_write_protect_disable(); +void ertc_output_set(ertc_output_source_type source, ertc_output_polarity_type polarity, ertc_output_type type) { + /* disable write protection */ + ertc_write_protect_disable(); - ERTC->ctrl_bit.outp = polarity; + ERTC->ctrl_bit.outp = polarity; - ERTC->tamp_bit.outtype = type; + ERTC->tamp_bit.outtype = type; - ERTC->ctrl_bit.outsel = source; + ERTC->ctrl_bit.outsel = source; - /* enable write protection */ - ertc_write_protect_enable(); + /* enable write protection */ + ertc_write_protect_enable(); } /** @@ -1101,15 +1007,14 @@ void ertc_output_set(ertc_output_source_type source, ertc_output_polarity_type p * - ERTC_PIN_PA0: pa0 is used as timestamp detection pin. * @retval data value. */ -void ertc_timestamp_pin_select(ertc_pin_select_type pin) -{ - /* disable write protection */ - ertc_write_protect_disable(); +void ertc_timestamp_pin_select(ertc_pin_select_type pin) { + /* disable write protection */ + ertc_write_protect_disable(); - ERTC->tamp_bit.tspin = pin; + ERTC->tamp_bit.tspin = pin; - /* enable write protection */ - ertc_write_protect_enable(); + /* enable write protection */ + ertc_write_protect_enable(); } /** @@ -1120,15 +1025,14 @@ void ertc_timestamp_pin_select(ertc_pin_select_type pin) * - ERTC_TIMESTAMP_EDGE_FALLING: falling edge trigger. * @retval none. */ -void ertc_timestamp_valid_edge_set(ertc_timestamp_valid_edge_type edge) -{ - /* disable write protection */ - ertc_write_protect_disable(); +void ertc_timestamp_valid_edge_set(ertc_timestamp_valid_edge_type edge) { + /* disable write protection */ + ertc_write_protect_disable(); - ERTC->ctrl_bit.tsedg = edge; + ERTC->ctrl_bit.tsedg = edge; - /* enable write protection */ - ertc_write_protect_enable(); + /* enable write protection */ + ertc_write_protect_enable(); } /** @@ -1136,15 +1040,14 @@ void ertc_timestamp_valid_edge_set(ertc_timestamp_valid_edge_type edge) * @param new_state (TRUE or FALSE). * @retval none. */ -void ertc_timestamp_enable(confirm_state new_state) -{ - /* disable write protection */ - ertc_write_protect_disable(); +void ertc_timestamp_enable(confirm_state new_state) { + /* disable write protection */ + ertc_write_protect_disable(); - ERTC->ctrl_bit.tsen = new_state; + ERTC->ctrl_bit.tsen = new_state; - /* enable write protection */ - ertc_write_protect_enable(); + /* enable write protection */ + ertc_write_protect_enable(); } /** @@ -1153,22 +1056,21 @@ void ertc_timestamp_enable(confirm_state new_state) * @param date: date. * @retval none. */ -void ertc_timestamp_get(ertc_time_type* time) -{ - ertc_reg_tstm_type tmtime; - ertc_reg_tsdt_type tmdate; +void ertc_timestamp_get(ertc_time_type *time) { + ertc_reg_tstm_type tmtime; + ertc_reg_tsdt_type tmdate; - tmtime.tstm = ERTC->tstm; - tmdate.tsdt = ERTC->tsdt; + tmtime.tstm = ERTC->tstm; + tmdate.tsdt = ERTC->tsdt; - time->year = 0; - time->month = ertc_bcd_to_num(tmdate.tsdt_bit.m); - time->day = ertc_bcd_to_num(tmdate.tsdt_bit.d); - time->week = ertc_bcd_to_num(tmdate.tsdt_bit.wk); - time->hour = ertc_bcd_to_num(tmtime.tstm_bit.h); - time->min = ertc_bcd_to_num(tmtime.tstm_bit.m); - time->sec = ertc_bcd_to_num(tmtime.tstm_bit.s); - time->ampm = (ertc_am_pm_type)tmtime.tstm_bit.ampm; + time->year = 0; + time->month = ertc_bcd_to_num(tmdate.tsdt_bit.m); + time->day = ertc_bcd_to_num(tmdate.tsdt_bit.d); + time->week = ertc_bcd_to_num(tmdate.tsdt_bit.wk); + time->hour = ertc_bcd_to_num(tmtime.tstm_bit.h); + time->min = ertc_bcd_to_num(tmtime.tstm_bit.m); + time->sec = ertc_bcd_to_num(tmtime.tstm_bit.s); + time->ampm = (ertc_am_pm_type)tmtime.tstm_bit.ampm; } /** @@ -1176,9 +1078,8 @@ void ertc_timestamp_get(ertc_time_type* time) * @param none. * @retval timestamp sub second. */ -uint32_t ertc_timestamp_sub_second_get(void) -{ - return ERTC->tssbs_bit.sbs; +uint32_t ertc_timestamp_sub_second_get(void) { + return ERTC->tssbs_bit.sbs; } /** @@ -1189,15 +1090,14 @@ uint32_t ertc_timestamp_sub_second_get(void) * - ERTC_PIN_PA0: pa0 is used as tamper 1 detection pin. * @retval data value. */ -void ertc_tamper_1_pin_select(ertc_pin_select_type pin) -{ - /* disable write protection */ - ertc_write_protect_disable(); +void ertc_tamper_1_pin_select(ertc_pin_select_type pin) { + /* disable write protection */ + ertc_write_protect_disable(); - ERTC->tamp_bit.tp1pin = pin; + ERTC->tamp_bit.tp1pin = pin; - /* enable write protection */ - ertc_write_protect_enable(); + /* enable write protection */ + ertc_write_protect_enable(); } /** @@ -1205,15 +1105,14 @@ void ertc_tamper_1_pin_select(ertc_pin_select_type pin) * @param new_state (TRUE or FALSE). * @retval none. */ -void ertc_tamper_pull_up_enable(confirm_state new_state) -{ - /* disable write protection */ - ertc_write_protect_disable(); +void ertc_tamper_pull_up_enable(confirm_state new_state) { + /* disable write protection */ + ertc_write_protect_disable(); - ERTC->tamp_bit.tppu = !new_state; + ERTC->tamp_bit.tppu = !new_state; - /* enable write protection */ - ertc_write_protect_enable(); + /* enable write protection */ + ertc_write_protect_enable(); } /** @@ -1226,15 +1125,14 @@ void ertc_tamper_pull_up_enable(confirm_state new_state) * - ERTC_TAMPER_PR_8_ERTCCLK: pre-charge time is 8 ERTC_CLK. * @retval none. */ -void ertc_tamper_precharge_set(ertc_tamper_precharge_type precharge) -{ - /* disable write protection */ - ertc_write_protect_disable(); +void ertc_tamper_precharge_set(ertc_tamper_precharge_type precharge) { + /* disable write protection */ + ertc_write_protect_disable(); - ERTC->tamp_bit.tppr = precharge; + ERTC->tamp_bit.tppr = precharge; - /* enable write protection */ - ertc_write_protect_enable(); + /* enable write protection */ + ertc_write_protect_enable(); } /** @@ -1247,15 +1145,14 @@ void ertc_tamper_precharge_set(ertc_tamper_precharge_type precharge) * - ERTC_TAMPER_FILTER_8: 8 consecutive samples arw valid, effective tamper event. * @retval none. */ -void ertc_tamper_filter_set(ertc_tamper_filter_type filter) -{ - /* disable write protection */ - ertc_write_protect_disable(); +void ertc_tamper_filter_set(ertc_tamper_filter_type filter) { + /* disable write protection */ + ertc_write_protect_disable(); - ERTC->tamp_bit.tpflt = filter; + ERTC->tamp_bit.tpflt = filter; - /* enable write protection */ - ertc_write_protect_enable(); + /* enable write protection */ + ertc_write_protect_enable(); } /** @@ -1272,15 +1169,14 @@ void ertc_tamper_filter_set(ertc_tamper_filter_type filter) * - ERTC_TAMPER_FREQ_DIV_256: ERTC_CLK / 256. * @retval none. */ -void ertc_tamper_detect_freq_set(ertc_tamper_detect_freq_type freq) -{ - /* disable write protection */ - ertc_write_protect_disable(); +void ertc_tamper_detect_freq_set(ertc_tamper_detect_freq_type freq) { + /* disable write protection */ + ertc_write_protect_disable(); - ERTC->tamp_bit.tpfreq = freq; + ERTC->tamp_bit.tpfreq = freq; - /* enable write protection */ - ertc_write_protect_enable(); + /* enable write protection */ + ertc_write_protect_enable(); } /** @@ -1298,22 +1194,18 @@ void ertc_tamper_detect_freq_set(ertc_tamper_detect_freq_type freq) * @param alarm: alarm para. * @retval none. */ -void ertc_tamper_valid_edge_set(ertc_tamper_select_type tamper_x, ertc_tamper_valid_edge_type trigger) -{ - /* disable write protection */ - ertc_write_protect_disable(); +void ertc_tamper_valid_edge_set(ertc_tamper_select_type tamper_x, ertc_tamper_valid_edge_type trigger) { + /* disable write protection */ + ertc_write_protect_disable(); - if(tamper_x == ERTC_TAMPER_1) - { - ERTC->tamp_bit.tp1edg = trigger; - } - else - { - ERTC->tamp_bit.tp2edg = trigger; - } + if (tamper_x == ERTC_TAMPER_1) { + ERTC->tamp_bit.tp1edg = trigger; + } else { + ERTC->tamp_bit.tp2edg = trigger; + } - /* enable write protection */ - ertc_write_protect_enable(); + /* enable write protection */ + ertc_write_protect_enable(); } /** @@ -1321,15 +1213,14 @@ void ertc_tamper_valid_edge_set(ertc_tamper_select_type tamper_x, ertc_tamper_va * @param new_state (TRUE or FALSE). * @retval none. */ -void ertc_tamper_timestamp_enable(confirm_state new_state) -{ - /* disable write protection */ - ertc_write_protect_disable(); +void ertc_tamper_timestamp_enable(confirm_state new_state) { + /* disable write protection */ + ertc_write_protect_disable(); - ERTC->tamp_bit.tptsen = new_state; + ERTC->tamp_bit.tptsen = new_state; - /* enable write protection */ - ertc_write_protect_enable(); + /* enable write protection */ + ertc_write_protect_enable(); } /** @@ -1341,22 +1232,18 @@ void ertc_tamper_timestamp_enable(confirm_state new_state) * @param new_state (TRUE or FALSE). * @retval none. */ -void ertc_tamper_enable(ertc_tamper_select_type tamper_x, confirm_state new_state) -{ - /* disable write protection */ - ertc_write_protect_disable(); +void ertc_tamper_enable(ertc_tamper_select_type tamper_x, confirm_state new_state) { + /* disable write protection */ + ertc_write_protect_disable(); - if(tamper_x == ERTC_TAMPER_1) - { - ERTC->tamp_bit.tp1en = new_state; - } - else - { - ERTC->tamp_bit.tp2en = new_state; - } + if (tamper_x == ERTC_TAMPER_1) { + ERTC->tamp_bit.tp1en = new_state; + } else { + ERTC->tamp_bit.tp2en = new_state; + } - /* enable write protection */ - ertc_write_protect_enable(); + /* enable write protection */ + ertc_write_protect_enable(); } /** @@ -1371,36 +1258,28 @@ void ertc_tamper_enable(ertc_tamper_select_type tamper_x, confirm_state new_stat * @param new_state (TRUE or FALSE). * @retval none. */ -void ertc_interrupt_enable(uint32_t source, confirm_state new_state) -{ - /* disable write protection */ - ertc_write_protect_disable(); +void ertc_interrupt_enable(uint32_t source, confirm_state new_state) { + /* disable write protection */ + ertc_write_protect_disable(); - if(source & ERTC_TP_INT) - { - if(new_state != FALSE) - { - ERTC->tamp |= ERTC_TP_INT; - } - else - { - ERTC->tamp &= ~ERTC_TP_INT; + if (source & ERTC_TP_INT) { + if (new_state != FALSE) { + ERTC->tamp |= ERTC_TP_INT; + } else { + ERTC->tamp &= ~ERTC_TP_INT; + } + + source &= ~ERTC_TP_INT; } - source &= ~ERTC_TP_INT; - } + if (new_state != FALSE) { + ERTC->ctrl |= source; + } else { + ERTC->ctrl &= ~source; + } - if(new_state != FALSE) - { - ERTC->ctrl |= source; - } - else - { - ERTC->ctrl &= ~source; - } - - /* enable write protection */ - ertc_write_protect_enable(); + /* enable write protection */ + ertc_write_protect_enable(); } /** @@ -1414,28 +1293,20 @@ void ertc_interrupt_enable(uint32_t source, confirm_state new_state) * - ERTC_TS_INT: timestamp interrupt. * @retval flag_status (SET or RESET) */ -flag_status ertc_interrupt_get(uint32_t source) -{ - if(source & ERTC_TP_INT) - { - if((ERTC->tamp & ERTC_TP_INT) != RESET) - { - return SET; +flag_status ertc_interrupt_get(uint32_t source) { + if (source & ERTC_TP_INT) { + if ((ERTC->tamp & ERTC_TP_INT) != RESET) { + return SET; + } else { + return RESET; + } } - else - { - return RESET; - } - } - if((ERTC->ctrl & source) != RESET) - { - return SET; - } - else - { - return RESET; - } + if ((ERTC->ctrl & source) != RESET) { + return SET; + } else { + return RESET; + } } /** @@ -1459,16 +1330,12 @@ flag_status ertc_interrupt_get(uint32_t source) * - ERTC_CALUPDF_FLAG: calibration value update completed flag. * @retval the new state of flag (SET or RESET). */ -flag_status ertc_flag_get(uint32_t flag) -{ - if((ERTC->sts & flag) != (uint32_t)RESET) - { - return SET; - } - else - { - return RESET; - } +flag_status ertc_flag_get(uint32_t flag) { + if ((ERTC->sts & flag) != (uint32_t)RESET) { + return SET; + } else { + return RESET; + } } /** @@ -1483,41 +1350,36 @@ flag_status ertc_flag_get(uint32_t flag) * - ERTC_TP2F_FLAG: tamper detection 2 flag. * @retval the new state of flag (SET or RESET). */ -flag_status ertc_interrupt_flag_get(uint32_t flag) -{ - __IO uint32_t iten = 0; +flag_status ertc_interrupt_flag_get(uint32_t flag) { + __IO uint32_t iten = 0; - switch(flag) - { - case ERTC_ALAF_FLAG: - iten = ERTC->ctrl_bit.alaien; - break; - case ERTC_ALBF_FLAG: - iten = ERTC->ctrl_bit.albien; - break; - case ERTC_WATF_FLAG: - iten = ERTC->ctrl_bit.watien; - break; - case ERTC_TSF_FLAG: - iten = ERTC->ctrl_bit.tsien; - break; - case ERTC_TP1F_FLAG: - case ERTC_TP2F_FLAG: - iten = ERTC->tamp_bit.tpien; - break; + switch (flag) { + case ERTC_ALAF_FLAG: + iten = ERTC->ctrl_bit.alaien; + break; + case ERTC_ALBF_FLAG: + iten = ERTC->ctrl_bit.albien; + break; + case ERTC_WATF_FLAG: + iten = ERTC->ctrl_bit.watien; + break; + case ERTC_TSF_FLAG: + iten = ERTC->ctrl_bit.tsien; + break; + case ERTC_TP1F_FLAG: + case ERTC_TP2F_FLAG: + iten = ERTC->tamp_bit.tpien; + break; - default: - break; - } + default: + break; + } - if(((ERTC->sts & flag) != (uint32_t)RESET) && (iten)) - { - return SET; - } - else - { - return RESET; - } + if (((ERTC->sts & flag) != (uint32_t)RESET) && (iten)) { + return SET; + } else { + return RESET; + } } /** @@ -1541,9 +1403,8 @@ flag_status ertc_interrupt_flag_get(uint32_t flag) * - ERTC_CALUPDF_FLAG: calibration value update completed flag. * @retval none */ -void ertc_flag_clear(uint32_t flag) -{ - ERTC->sts = ~(flag | 0x00000080) | (ERTC->sts_bit.imen << 7); +void ertc_flag_clear(uint32_t flag) { + ERTC->sts = ~(flag | 0x00000080) | (ERTC->sts_bit.imen << 7); } /** @@ -1558,13 +1419,12 @@ void ertc_flag_clear(uint32_t flag) * @param data: data to be write. * @retval none. */ -void ertc_bpr_data_write(ertc_dt_type dt, uint32_t data) -{ - __IO uint32_t reg = 0; +void ertc_bpr_data_write(ertc_dt_type dt, uint32_t data) { + __IO uint32_t reg = 0; - reg = ERTC_BASE + 0x50 + (dt * 4); + reg = ERTC_BASE + 0x50 + (dt * 4); - *(__IO uint32_t *)reg = data; + *(__IO uint32_t *)reg = data; } /** @@ -1578,13 +1438,12 @@ void ertc_bpr_data_write(ertc_dt_type dt, uint32_t data) * - ERTC_DT20 * @retval data value. */ -uint32_t ertc_bpr_data_read(ertc_dt_type dt) -{ - __IO uint32_t reg = 0; +uint32_t ertc_bpr_data_read(ertc_dt_type dt) { + __IO uint32_t reg = 0; - reg = ERTC_BASE + 0x50 + (dt * 4); + reg = ERTC_BASE + 0x50 + (dt * 4); - return (*(__IO uint32_t *)reg); + return (*(__IO uint32_t *)reg); } /** diff --git a/armlib/at32_sys/drivers/src/at32f435_437_exint.c b/armlib/at32_sys/drivers/src/at32f435_437_exint.c index 047297421..da81a5e0a 100644 --- a/armlib/at32_sys/drivers/src/at32f435_437_exint.c +++ b/armlib/at32_sys/drivers/src/at32f435_437_exint.c @@ -45,13 +45,12 @@ * @param none * @retval none */ -void exint_reset(void) -{ - EXINT->inten = 0x00000000; - EXINT->polcfg1 = 0x00000000; - EXINT->polcfg2 = 0x00000000; - EXINT->evten = 0x00000000; - EXINT->intsts = 0x007FFFFF; +void exint_reset(void) { + EXINT->inten = 0x00000000; + EXINT->polcfg1 = 0x00000000; + EXINT->polcfg2 = 0x00000000; + EXINT->evten = 0x00000000; + EXINT->intsts = 0x007FFFFF; } /** @@ -60,12 +59,11 @@ void exint_reset(void) * - to the structure of exint_init_type * @retval none */ -void exint_default_para_init(exint_init_type *exint_struct) -{ - exint_struct->line_enable = FALSE; - exint_struct->line_select = EXINT_LINE_NONE; - exint_struct->line_polarity = EXINT_TRIGGER_FALLING_EDGE; - exint_struct->line_mode = EXINT_LINE_EVENT; +void exint_default_para_init(exint_init_type *exint_struct) { + exint_struct->line_enable = FALSE; + exint_struct->line_select = EXINT_LINE_NONE; + exint_struct->line_polarity = EXINT_TRIGGER_FALLING_EDGE; + exint_struct->line_mode = EXINT_LINE_EVENT; } /** @@ -74,41 +72,31 @@ void exint_default_para_init(exint_init_type *exint_struct) * - to the structure of exint_init_type * @retval none */ -void exint_init(exint_init_type *exint_struct) -{ - uint32_t line_index = 0; - line_index = exint_struct->line_select; +void exint_init(exint_init_type *exint_struct) { + uint32_t line_index = 0; + line_index = exint_struct->line_select; - EXINT->inten &= ~line_index; - EXINT->evten &= ~line_index; + EXINT->inten &= ~line_index; + EXINT->evten &= ~line_index; - if(exint_struct->line_enable != FALSE) - { - if(exint_struct->line_mode == EXINT_LINE_INTERRUPT) - { - EXINT->inten |= line_index; - } - else - { - EXINT->evten |= line_index; - } + if (exint_struct->line_enable != FALSE) { + if (exint_struct->line_mode == EXINT_LINE_INTERRUPT) { + EXINT->inten |= line_index; + } else { + EXINT->evten |= line_index; + } - EXINT->polcfg1 &= ~line_index; - EXINT->polcfg2 &= ~line_index; - if(exint_struct->line_polarity == EXINT_TRIGGER_RISING_EDGE) - { - EXINT->polcfg1 |= line_index; + EXINT->polcfg1 &= ~line_index; + EXINT->polcfg2 &= ~line_index; + if (exint_struct->line_polarity == EXINT_TRIGGER_RISING_EDGE) { + EXINT->polcfg1 |= line_index; + } else if (exint_struct->line_polarity == EXINT_TRIGGER_FALLING_EDGE) { + EXINT->polcfg2 |= line_index; + } else { + EXINT->polcfg1 |= line_index; + EXINT->polcfg2 |= line_index; + } } - else if(exint_struct->line_polarity == EXINT_TRIGGER_FALLING_EDGE) - { - EXINT->polcfg2 |= line_index; - } - else - { - EXINT->polcfg1 |= line_index; - EXINT->polcfg2 |= line_index; - } - } } /** @@ -122,9 +110,8 @@ void exint_init(exint_init_type *exint_struct) * - EXINT_LINE_22 * @retval none */ -void exint_flag_clear(uint32_t exint_line) -{ - EXINT->intsts = exint_line; +void exint_flag_clear(uint32_t exint_line) { + EXINT->intsts = exint_line; } /** @@ -138,20 +125,16 @@ void exint_flag_clear(uint32_t exint_line) * - EXINT_LINE_22 * @retval the new state of exint flag(SET or RESET). */ -flag_status exint_flag_get(uint32_t exint_line) -{ - flag_status status = RESET; - uint32_t exint_flag =0; - exint_flag = EXINT->intsts & exint_line; - if((exint_flag != (uint16_t)RESET)) - { - status = SET; - } - else - { - status = RESET; - } - return status; +flag_status exint_flag_get(uint32_t exint_line) { + flag_status status = RESET; + uint32_t exint_flag = 0; + exint_flag = EXINT->intsts & exint_line; + if ((exint_flag != (uint16_t)RESET)) { + status = SET; + } else { + status = RESET; + } + return status; } /** @@ -165,22 +148,18 @@ flag_status exint_flag_get(uint32_t exint_line) * - EXINT_LINE_22 * @retval the new state of exint flag(SET or RESET). */ -flag_status exint_interrupt_flag_get(uint32_t exint_line) -{ - flag_status status = RESET; - uint32_t exint_flag = 0; - exint_flag = EXINT->intsts & exint_line; - exint_flag = exint_flag & EXINT->inten; +flag_status exint_interrupt_flag_get(uint32_t exint_line) { + flag_status status = RESET; + uint32_t exint_flag = 0; + exint_flag = EXINT->intsts & exint_line; + exint_flag = exint_flag & EXINT->inten; - if((exint_flag != (uint16_t)RESET)) - { - status = SET; - } - else - { - status = RESET; - } - return status; + if ((exint_flag != (uint16_t)RESET)) { + status = SET; + } else { + status = RESET; + } + return status; } /** @@ -194,9 +173,8 @@ flag_status exint_interrupt_flag_get(uint32_t exint_line) * - EXINT_LINE_22 * @retval none */ -void exint_software_interrupt_event_generate(uint32_t exint_line) -{ - EXINT->swtrg |= exint_line; +void exint_software_interrupt_event_generate(uint32_t exint_line) { + EXINT->swtrg |= exint_line; } /** @@ -212,16 +190,12 @@ void exint_software_interrupt_event_generate(uint32_t exint_line) * this parameter can be: TRUE or FALSE. * @retval none */ -void exint_interrupt_enable(uint32_t exint_line, confirm_state new_state) -{ - if(new_state == TRUE) - { - EXINT->inten |= exint_line; - } - else - { - EXINT->inten &= ~exint_line; - } +void exint_interrupt_enable(uint32_t exint_line, confirm_state new_state) { + if (new_state == TRUE) { + EXINT->inten |= exint_line; + } else { + EXINT->inten &= ~exint_line; + } } /** @@ -237,16 +211,12 @@ void exint_interrupt_enable(uint32_t exint_line, confirm_state new_state) * this parameter can be: TRUE or FALSE. * @retval none */ -void exint_event_enable(uint32_t exint_line, confirm_state new_state) -{ - if(new_state == TRUE) - { - EXINT->evten |= exint_line; - } - else - { - EXINT->evten &= ~exint_line; - } +void exint_event_enable(uint32_t exint_line, confirm_state new_state) { + if (new_state == TRUE) { + EXINT->evten |= exint_line; + } else { + EXINT->evten &= ~exint_line; + } } /** diff --git a/armlib/at32_sys/drivers/src/at32f435_437_flash.c b/armlib/at32_sys/drivers/src/at32f435_437_flash.c index 3bd8770ae..8ea7965e1 100644 --- a/armlib/at32_sys/drivers/src/at32f435_437_flash.c +++ b/armlib/at32_sys/drivers/src/at32f435_437_flash.c @@ -59,31 +59,29 @@ * - FLASH_USDERR_FLAG * @retval the new state of flash_flag (SET or RESET). */ -flag_status flash_flag_get(uint32_t flash_flag) -{ - flag_status status = RESET; - uint32_t flag_position; - flag_position = flash_flag & 0x70000000; - flash_flag &= 0x8FFFFFFF; - switch(flag_position) - { - case 0x00000000: - if(FLASH->sts & flash_flag) - status = SET; - break; - case 0x10000000: - if(FLASH->sts2 & flash_flag) - status = SET; - break; - case 0x40000000: - if(FLASH->usd & flash_flag) - status = SET; - break; - default: - break; - } - /* return the new state of flash_flag (SET or RESET) */ - return status; +flag_status flash_flag_get(uint32_t flash_flag) { + flag_status status = RESET; + uint32_t flag_position; + flag_position = flash_flag & 0x70000000; + flash_flag &= 0x8FFFFFFF; + switch (flag_position) { + case 0x00000000: + if (FLASH->sts & flash_flag) + status = SET; + break; + case 0x10000000: + if (FLASH->sts2 & flash_flag) + status = SET; + break; + case 0x40000000: + if (FLASH->usd & flash_flag) + status = SET; + break; + default: + break; + } + /* return the new state of flash_flag (SET or RESET) */ + return status; } /** @@ -101,22 +99,20 @@ flag_status flash_flag_get(uint32_t flash_flag) * - FLASH_BANK2_EPPERR_FLAG * @retval none */ -void flash_flag_clear(uint32_t flash_flag) -{ - uint32_t flag_position; - flag_position = flash_flag & 0x70000000; - flash_flag &= 0x8FFFFFFF; - switch(flag_position) - { - case 0x00000000: - FLASH->sts = flash_flag; - break; - case 0x10000000: - FLASH->sts2 = flash_flag; - break; - default: - break; - } +void flash_flag_clear(uint32_t flash_flag) { + uint32_t flag_position; + flag_position = flash_flag & 0x70000000; + flash_flag &= 0x8FFFFFFF; + switch (flag_position) { + case 0x00000000: + FLASH->sts = flash_flag; + break; + case 0x10000000: + FLASH->sts2 = flash_flag; + break; + default: + break; + } } /** @@ -125,27 +121,19 @@ void flash_flag_clear(uint32_t flash_flag) * @retval status: the returned value can be: FLASH_OPERATE_BUSY, * FLASH_PROGRAM_ERROR, FLASH_EPP_ERROR or FLASH_OPERATE_DONE. */ -flash_status_type flash_operation_status_get(void) -{ - flash_status_type flash_status = FLASH_OPERATE_DONE; - if(FLASH->sts_bit.obf != RESET) - { - flash_status = FLASH_OPERATE_BUSY; - } - else if(FLASH->sts_bit.prgmerr != RESET) - { - flash_status = FLASH_PROGRAM_ERROR; - } - else if(FLASH->sts_bit.epperr != RESET) - { - flash_status = FLASH_EPP_ERROR; - } - else - { - flash_status = FLASH_OPERATE_DONE; - } - /* return the flash status */ - return flash_status; +flash_status_type flash_operation_status_get(void) { + flash_status_type flash_status = FLASH_OPERATE_DONE; + if (FLASH->sts_bit.obf != RESET) { + flash_status = FLASH_OPERATE_BUSY; + } else if (FLASH->sts_bit.prgmerr != RESET) { + flash_status = FLASH_PROGRAM_ERROR; + } else if (FLASH->sts_bit.epperr != RESET) { + flash_status = FLASH_EPP_ERROR; + } else { + flash_status = FLASH_OPERATE_DONE; + } + /* return the flash status */ + return flash_status; } /** @@ -154,27 +142,19 @@ flash_status_type flash_operation_status_get(void) * @retval status: the returned value can be: FLASH_OPERATE_BUSY, * FLASH_PROGRAM_ERROR, FLASH_EPP_ERROR or FLASH_OPERATE_DONE. */ -flash_status_type flash_bank1_operation_status_get(void) -{ - flash_status_type flash_status = FLASH_OPERATE_DONE; - if(FLASH->sts_bit.obf != RESET) - { - flash_status = FLASH_OPERATE_BUSY; - } - else if(FLASH->sts_bit.prgmerr != RESET) - { - flash_status = FLASH_PROGRAM_ERROR; - } - else if(FLASH->sts_bit.epperr != RESET) - { - flash_status = FLASH_EPP_ERROR; - } - else - { - flash_status = FLASH_OPERATE_DONE; - } - /* return the flash status */ - return flash_status; +flash_status_type flash_bank1_operation_status_get(void) { + flash_status_type flash_status = FLASH_OPERATE_DONE; + if (FLASH->sts_bit.obf != RESET) { + flash_status = FLASH_OPERATE_BUSY; + } else if (FLASH->sts_bit.prgmerr != RESET) { + flash_status = FLASH_PROGRAM_ERROR; + } else if (FLASH->sts_bit.epperr != RESET) { + flash_status = FLASH_EPP_ERROR; + } else { + flash_status = FLASH_OPERATE_DONE; + } + /* return the flash status */ + return flash_status; } /** @@ -183,27 +163,19 @@ flash_status_type flash_bank1_operation_status_get(void) * @retval status: the returned value can be: FLASH_OPERATE_BUSY, * FLASH_PROGRAM_ERROR, FLASH_EPP_ERROR or FLASH_OPERATE_DONE. */ -flash_status_type flash_bank2_operation_status_get(void) -{ - flash_status_type flash_status = FLASH_OPERATE_DONE; - if(FLASH->sts2_bit.obf != RESET) - { - flash_status = FLASH_OPERATE_BUSY; - } - else if(FLASH->sts2_bit.prgmerr != RESET) - { - flash_status = FLASH_PROGRAM_ERROR; - } - else if(FLASH->sts2_bit.epperr != RESET) - { - flash_status = FLASH_EPP_ERROR; - } - else - { - flash_status = FLASH_OPERATE_DONE; - } - /* return the flash status */ - return flash_status; +flash_status_type flash_bank2_operation_status_get(void) { + flash_status_type flash_status = FLASH_OPERATE_DONE; + if (FLASH->sts2_bit.obf != RESET) { + flash_status = FLASH_OPERATE_BUSY; + } else if (FLASH->sts2_bit.prgmerr != RESET) { + flash_status = FLASH_PROGRAM_ERROR; + } else if (FLASH->sts2_bit.epperr != RESET) { + flash_status = FLASH_EPP_ERROR; + } else { + flash_status = FLASH_OPERATE_DONE; + } + /* return the flash status */ + return flash_status; } /** @@ -212,23 +184,20 @@ flash_status_type flash_bank2_operation_status_get(void) * @retval status: the returned value can be: FLASH_PROGRAM_ERROR, * FLASH_EPP_ERROR, FLASH_OPERATE_DONE or FLASH_OPERATE_TIMEOUT. */ -flash_status_type flash_operation_wait_for(uint32_t time_out) -{ - flash_status_type status = FLASH_OPERATE_DONE; - /* check for the flash status */ - status = flash_operation_status_get(); - - while((status == FLASH_OPERATE_BUSY) && (time_out != 0x00)) - { +flash_status_type flash_operation_wait_for(uint32_t time_out) { + flash_status_type status = FLASH_OPERATE_DONE; + /* check for the flash status */ status = flash_operation_status_get(); - time_out--; - } - if(time_out == 0x00) - { - status = FLASH_OPERATE_TIMEOUT; - } - /* return the status */ - return status; + + while ((status == FLASH_OPERATE_BUSY) && (time_out != 0x00)) { + status = flash_operation_status_get(); + time_out--; + } + if (time_out == 0x00) { + status = FLASH_OPERATE_TIMEOUT; + } + /* return the status */ + return status; } /** @@ -237,23 +206,20 @@ flash_status_type flash_operation_wait_for(uint32_t time_out) * @retval status: the returned value can be: FLASH_PROGRAM_ERROR, * FLASH_EPP_ERROR, FLASH_OPERATE_DONE or FLASH_OPERATE_TIMEOUT. */ -flash_status_type flash_bank1_operation_wait_for(uint32_t time_out) -{ - flash_status_type status = FLASH_OPERATE_DONE; - /* check for the flash status */ - status = flash_bank1_operation_status_get(); - - while((status == FLASH_OPERATE_BUSY) && (time_out != 0x00)) - { +flash_status_type flash_bank1_operation_wait_for(uint32_t time_out) { + flash_status_type status = FLASH_OPERATE_DONE; + /* check for the flash status */ status = flash_bank1_operation_status_get(); - time_out--; - } - if(time_out == 0x00) - { - status = FLASH_OPERATE_TIMEOUT; - } - /* return the operation status */ - return status; + + while ((status == FLASH_OPERATE_BUSY) && (time_out != 0x00)) { + status = flash_bank1_operation_status_get(); + time_out--; + } + if (time_out == 0x00) { + status = FLASH_OPERATE_TIMEOUT; + } + /* return the operation status */ + return status; } /** @@ -262,23 +228,20 @@ flash_status_type flash_bank1_operation_wait_for(uint32_t time_out) * @retval status: the returned value can be: FLASH_PROGRAM_ERROR, * FLASH_EPP_ERROR, FLASH_OPERATE_DONE or FLASH_OPERATE_TIMEOUT. */ -flash_status_type flash_bank2_operation_wait_for(uint32_t time_out) -{ - flash_status_type status = FLASH_OPERATE_DONE; - /* check for the flash status */ - status = flash_bank2_operation_status_get(); - - while((status == FLASH_OPERATE_BUSY) && (time_out != 0x00)) - { +flash_status_type flash_bank2_operation_wait_for(uint32_t time_out) { + flash_status_type status = FLASH_OPERATE_DONE; + /* check for the flash status */ status = flash_bank2_operation_status_get(); - time_out--; - } - if(time_out == 0x00) - { - status = FLASH_OPERATE_TIMEOUT; - } - /* return the operation status */ - return status; + + while ((status == FLASH_OPERATE_BUSY) && (time_out != 0x00)) { + status = flash_bank2_operation_status_get(); + time_out--; + } + if (time_out == 0x00) { + status = FLASH_OPERATE_TIMEOUT; + } + /* return the operation status */ + return status; } /** @@ -286,12 +249,11 @@ flash_status_type flash_bank2_operation_wait_for(uint32_t time_out) * @param none * @retval none */ -void flash_unlock(void) -{ - FLASH->unlock = FLASH_UNLOCK_KEY1; - FLASH->unlock = FLASH_UNLOCK_KEY2; - FLASH->unlock2 = FLASH_UNLOCK_KEY1; - FLASH->unlock2 = FLASH_UNLOCK_KEY2; +void flash_unlock(void) { + FLASH->unlock = FLASH_UNLOCK_KEY1; + FLASH->unlock = FLASH_UNLOCK_KEY2; + FLASH->unlock2 = FLASH_UNLOCK_KEY1; + FLASH->unlock2 = FLASH_UNLOCK_KEY2; } /** @@ -299,10 +261,9 @@ void flash_unlock(void) * @param none * @retval none */ -void flash_bank1_unlock(void) -{ - FLASH->unlock = FLASH_UNLOCK_KEY1; - FLASH->unlock = FLASH_UNLOCK_KEY2; +void flash_bank1_unlock(void) { + FLASH->unlock = FLASH_UNLOCK_KEY1; + FLASH->unlock = FLASH_UNLOCK_KEY2; } /** @@ -310,10 +271,9 @@ void flash_bank1_unlock(void) * @param none * @retval none */ -void flash_bank2_unlock(void) -{ - FLASH->unlock2 = FLASH_UNLOCK_KEY1; - FLASH->unlock2 = FLASH_UNLOCK_KEY2; +void flash_bank2_unlock(void) { + FLASH->unlock2 = FLASH_UNLOCK_KEY1; + FLASH->unlock2 = FLASH_UNLOCK_KEY2; } /** @@ -321,10 +281,9 @@ void flash_bank2_unlock(void) * @param none * @retval none */ -void flash_lock(void) -{ - FLASH->ctrl_bit.oplk = TRUE; - FLASH->ctrl2_bit.oplk = TRUE; +void flash_lock(void) { + FLASH->ctrl_bit.oplk = TRUE; + FLASH->ctrl2_bit.oplk = TRUE; } /** @@ -332,9 +291,8 @@ void flash_lock(void) * @param none * @retval none */ -void flash_bank1_lock(void) -{ - FLASH->ctrl_bit.oplk = TRUE; +void flash_bank1_lock(void) { + FLASH->ctrl_bit.oplk = TRUE; } /** @@ -342,9 +300,8 @@ void flash_bank1_lock(void) * @param none * @retval none */ -void flash_bank2_lock(void) -{ - FLASH->ctrl2_bit.oplk = TRUE; +void flash_bank2_lock(void) { + FLASH->ctrl2_bit.oplk = TRUE; } /** @@ -353,36 +310,32 @@ void flash_bank2_lock(void) * @retval status: the returned value can be: FLASH_PROGRAM_ERROR, * FLASH_EPP_ERROR, FLASH_OPERATE_DONE or FLASH_OPERATE_TIMEOUT. */ -flash_status_type flash_sector_erase(uint32_t sector_address) -{ - flash_status_type status = FLASH_OPERATE_DONE; - if((sector_address >= FLASH_BANK1_START_ADDR) && (sector_address <= FLASH_BANK1_END_ADDR)) - { - FLASH->ctrl_bit.secers = TRUE; - FLASH->addr = sector_address; - FLASH->ctrl_bit.erstr = TRUE; +flash_status_type flash_sector_erase(uint32_t sector_address) { + flash_status_type status = FLASH_OPERATE_DONE; + if ((sector_address >= FLASH_BANK1_START_ADDR) && (sector_address <= FLASH_BANK1_END_ADDR)) { + FLASH->ctrl_bit.secers = TRUE; + FLASH->addr = sector_address; + FLASH->ctrl_bit.erstr = TRUE; - /* wait for operation to be completed */ - status = flash_bank1_operation_wait_for(ERASE_TIMEOUT); + /* wait for operation to be completed */ + status = flash_bank1_operation_wait_for(ERASE_TIMEOUT); - /* disable the secers bit */ - FLASH->ctrl_bit.secers = FALSE; - } - else if((sector_address >= FLASH_BANK2_START_ADDR) && (sector_address <= FLASH_BANK2_END_ADDR)) - { - FLASH->ctrl2_bit.secers = TRUE; - FLASH->addr2 = sector_address; - FLASH->ctrl2_bit.erstr = TRUE; + /* disable the secers bit */ + FLASH->ctrl_bit.secers = FALSE; + } else if ((sector_address >= FLASH_BANK2_START_ADDR) && (sector_address <= FLASH_BANK2_END_ADDR)) { + FLASH->ctrl2_bit.secers = TRUE; + FLASH->addr2 = sector_address; + FLASH->ctrl2_bit.erstr = TRUE; - /* wait for operation to be completed */ - status = flash_bank2_operation_wait_for(ERASE_TIMEOUT); + /* wait for operation to be completed */ + status = flash_bank2_operation_wait_for(ERASE_TIMEOUT); - /* disable the secers bit */ - FLASH->ctrl2_bit.secers = FALSE; - } + /* disable the secers bit */ + FLASH->ctrl2_bit.secers = FALSE; + } - /* return the erase status */ - return status; + /* return the erase status */ + return status; } /** @@ -391,36 +344,32 @@ flash_status_type flash_sector_erase(uint32_t sector_address) * @retval status: the returned value can be: FLASH_PROGRAM_ERROR, * FLASH_EPP_ERROR, FLASH_OPERATE_DONE or FLASH_OPERATE_TIMEOUT. */ -flash_status_type flash_block_erase(uint32_t block_address) -{ - flash_status_type status = FLASH_OPERATE_DONE; - if((block_address >= FLASH_BANK1_START_ADDR) && (block_address <= FLASH_BANK1_END_ADDR)) - { - FLASH->ctrl_bit.blkers = TRUE; - FLASH->addr = block_address; - FLASH->ctrl_bit.erstr = TRUE; +flash_status_type flash_block_erase(uint32_t block_address) { + flash_status_type status = FLASH_OPERATE_DONE; + if ((block_address >= FLASH_BANK1_START_ADDR) && (block_address <= FLASH_BANK1_END_ADDR)) { + FLASH->ctrl_bit.blkers = TRUE; + FLASH->addr = block_address; + FLASH->ctrl_bit.erstr = TRUE; - /* wait for operation to be completed */ - status = flash_bank1_operation_wait_for(ERASE_TIMEOUT); + /* wait for operation to be completed */ + status = flash_bank1_operation_wait_for(ERASE_TIMEOUT); - /* disable the blkers bit */ - FLASH->ctrl_bit.blkers = FALSE; - } - else if((block_address >= FLASH_BANK2_START_ADDR) && (block_address <= FLASH_BANK2_END_ADDR)) - { - FLASH->ctrl2_bit.blkers = TRUE; - FLASH->addr2 = block_address; - FLASH->ctrl2_bit.erstr = TRUE; + /* disable the blkers bit */ + FLASH->ctrl_bit.blkers = FALSE; + } else if ((block_address >= FLASH_BANK2_START_ADDR) && (block_address <= FLASH_BANK2_END_ADDR)) { + FLASH->ctrl2_bit.blkers = TRUE; + FLASH->addr2 = block_address; + FLASH->ctrl2_bit.erstr = TRUE; - /* wait for operation to be completed */ - status = flash_bank2_operation_wait_for(ERASE_TIMEOUT); + /* wait for operation to be completed */ + status = flash_bank2_operation_wait_for(ERASE_TIMEOUT); - /* disable the blkers bit */ - FLASH->ctrl2_bit.blkers = FALSE; - } + /* disable the blkers bit */ + FLASH->ctrl2_bit.blkers = FALSE; + } - /* return the erase status */ - return status; + /* return the erase status */ + return status; } /** @@ -429,33 +378,31 @@ flash_status_type flash_block_erase(uint32_t block_address) * @retval status: the returned value can be: FLASH_PROGRAM_ERROR, * FLASH_EPP_ERROR, FLASH_OPERATE_DONE or FLASH_OPERATE_TIMEOUT. */ -flash_status_type flash_internal_all_erase(void) -{ - flash_status_type status = FLASH_OPERATE_DONE; +flash_status_type flash_internal_all_erase(void) { + flash_status_type status = FLASH_OPERATE_DONE; - FLASH->ctrl_bit.bankers = TRUE; - FLASH->ctrl_bit.erstr = TRUE; - - /* wait for operation to be completed */ - status = flash_bank1_operation_wait_for(ERASE_TIMEOUT); - - /* disable the bankers bit */ - FLASH->ctrl_bit.bankers = FALSE; - - if(status == FLASH_OPERATE_DONE) - { - /* if the previous operation is completed, continue to erase bank2 */ - FLASH->ctrl2_bit.bankers = TRUE; - FLASH->ctrl2_bit.erstr = TRUE; + FLASH->ctrl_bit.bankers = TRUE; + FLASH->ctrl_bit.erstr = TRUE; /* wait for operation to be completed */ - status = flash_bank2_operation_wait_for(ERASE_TIMEOUT); + status = flash_bank1_operation_wait_for(ERASE_TIMEOUT); /* disable the bankers bit */ - FLASH->ctrl2_bit.bankers = FALSE; - } - /* return the erase status */ - return status; + FLASH->ctrl_bit.bankers = FALSE; + + if (status == FLASH_OPERATE_DONE) { + /* if the previous operation is completed, continue to erase bank2 */ + FLASH->ctrl2_bit.bankers = TRUE; + FLASH->ctrl2_bit.erstr = TRUE; + + /* wait for operation to be completed */ + status = flash_bank2_operation_wait_for(ERASE_TIMEOUT); + + /* disable the bankers bit */ + FLASH->ctrl2_bit.bankers = FALSE; + } + /* return the erase status */ + return status; } /** @@ -464,21 +411,20 @@ flash_status_type flash_internal_all_erase(void) * @retval status: the returned value can be: FLASH_PROGRAM_ERROR, * FLASH_EPP_ERROR, FLASH_OPERATE_DONE or FLASH_OPERATE_TIMEOUT. */ -flash_status_type flash_bank1_erase(void) -{ - flash_status_type status = FLASH_OPERATE_DONE; +flash_status_type flash_bank1_erase(void) { + flash_status_type status = FLASH_OPERATE_DONE; - FLASH->ctrl_bit.bankers = TRUE; - FLASH->ctrl_bit.erstr = TRUE; + FLASH->ctrl_bit.bankers = TRUE; + FLASH->ctrl_bit.erstr = TRUE; - /* wait for operation to be completed */ - status = flash_bank1_operation_wait_for(ERASE_TIMEOUT); + /* wait for operation to be completed */ + status = flash_bank1_operation_wait_for(ERASE_TIMEOUT); - /* disable the bankers bit */ - FLASH->ctrl_bit.bankers = FALSE; + /* disable the bankers bit */ + FLASH->ctrl_bit.bankers = FALSE; - /* return the erase status */ - return status; + /* return the erase status */ + return status; } /** @@ -487,21 +433,20 @@ flash_status_type flash_bank1_erase(void) * @retval status: the returned value can be: FLASH_PROGRAM_ERROR, * FLASH_EPP_ERROR, FLASH_OPERATE_DONE or FLASH_OPERATE_TIMEOUT. */ -flash_status_type flash_bank2_erase(void) -{ - flash_status_type status = FLASH_OPERATE_DONE; +flash_status_type flash_bank2_erase(void) { + flash_status_type status = FLASH_OPERATE_DONE; - FLASH->ctrl2_bit.bankers = TRUE; - FLASH->ctrl2_bit.erstr = TRUE; + FLASH->ctrl2_bit.bankers = TRUE; + FLASH->ctrl2_bit.erstr = TRUE; - /* wait for operation to be completed */ - status = flash_bank2_operation_wait_for(ERASE_TIMEOUT); + /* wait for operation to be completed */ + status = flash_bank2_operation_wait_for(ERASE_TIMEOUT); - /* disable the bankers bit */ - FLASH->ctrl2_bit.bankers = FALSE; + /* disable the bankers bit */ + FLASH->ctrl2_bit.bankers = FALSE; - /* return the erase status */ - return status; + /* return the erase status */ + return status; } /** @@ -512,48 +457,45 @@ flash_status_type flash_bank2_erase(void) * @retval status: the returned value can be: FLASH_PROGRAM_ERROR, * FLASH_EPP_ERROR, FLASH_OPERATE_DONE or FLASH_OPERATE_TIMEOUT. */ -flash_status_type flash_user_system_data_erase(void) -{ - flash_status_type status = FLASH_OPERATE_DONE; - uint16_t fap_val = FAP_RELIEVE_KEY; - /* get the flash access protection status */ - if(flash_fap_status_get() != RESET) - { - fap_val = 0x0000; - } +flash_status_type flash_user_system_data_erase(void) { + flash_status_type status = FLASH_OPERATE_DONE; + uint16_t fap_val = FAP_RELIEVE_KEY; + /* get the flash access protection status */ + if (flash_fap_status_get() != RESET) { + fap_val = 0x0000; + } - /* unlock the user system data */ - FLASH->usd_unlock = FLASH_UNLOCK_KEY1; - FLASH->usd_unlock = FLASH_UNLOCK_KEY2; - while(FLASH->ctrl_bit.usdulks==RESET); + /* unlock the user system data */ + FLASH->usd_unlock = FLASH_UNLOCK_KEY1; + FLASH->usd_unlock = FLASH_UNLOCK_KEY2; + while (FLASH->ctrl_bit.usdulks == RESET); - /* erase the user system data */ - FLASH->ctrl_bit.usders = TRUE; - FLASH->ctrl_bit.erstr = TRUE; - - /* wait for operation to be completed */ - status = flash_operation_wait_for(ERASE_TIMEOUT); - - /* disable the usders bit */ - FLASH->ctrl_bit.usders = FALSE; - - if((status == FLASH_OPERATE_DONE) && (fap_val == FAP_RELIEVE_KEY)) - { - /* enable the user system data programming operation */ - FLASH->ctrl_bit.usdprgm = TRUE; - - /* restore the last flash access protection value */ - USD->fap = (uint16_t)fap_val; + /* erase the user system data */ + FLASH->ctrl_bit.usders = TRUE; + FLASH->ctrl_bit.erstr = TRUE; /* wait for operation to be completed */ - status = flash_operation_wait_for(PROGRAMMING_TIMEOUT); + status = flash_operation_wait_for(ERASE_TIMEOUT); - /*disable the usdprgm bit */ - FLASH->ctrl_bit.usdprgm = FALSE; - } + /* disable the usders bit */ + FLASH->ctrl_bit.usders = FALSE; - /* return the status */ - return status; + if ((status == FLASH_OPERATE_DONE) && (fap_val == FAP_RELIEVE_KEY)) { + /* enable the user system data programming operation */ + FLASH->ctrl_bit.usdprgm = TRUE; + + /* restore the last flash access protection value */ + USD->fap = (uint16_t)fap_val; + + /* wait for operation to be completed */ + status = flash_operation_wait_for(PROGRAMMING_TIMEOUT); + + /*disable the usdprgm bit */ + FLASH->ctrl_bit.usdprgm = FALSE; + } + + /* return the status */ + return status; } /** @@ -572,29 +514,28 @@ flash_status_type flash_user_system_data_erase(void) * @retval status: the returned value can be: FLASH_PROGRAM_ERROR, * FLASH_EPP_ERROR, FLASH_OPERATE_DONE or FLASH_OPERATE_TIMEOUT. */ -flash_status_type flash_eopb0_config(flash_usd_eopb0_type data) -{ - flash_status_type status = FLASH_OPERATE_DONE; +flash_status_type flash_eopb0_config(flash_usd_eopb0_type data) { + flash_status_type status = FLASH_OPERATE_DONE; - /* unlock the user system data */ - FLASH->usd_unlock = FLASH_UNLOCK_KEY1; - FLASH->usd_unlock = FLASH_UNLOCK_KEY2; - while(FLASH->ctrl_bit.usdulks==RESET); + /* unlock the user system data */ + FLASH->usd_unlock = FLASH_UNLOCK_KEY1; + FLASH->usd_unlock = FLASH_UNLOCK_KEY2; + while (FLASH->ctrl_bit.usdulks == RESET); - /* enable the user system data programming operation */ - FLASH->ctrl_bit.usdprgm = TRUE; + /* enable the user system data programming operation */ + FLASH->ctrl_bit.usdprgm = TRUE; - /* restore the default eopb0 value */ - USD->eopb0 = (uint16_t)data; + /* restore the default eopb0 value */ + USD->eopb0 = (uint16_t)data; - /* wait for operation to be completed */ - status = flash_operation_wait_for(PROGRAMMING_TIMEOUT); + /* wait for operation to be completed */ + status = flash_operation_wait_for(PROGRAMMING_TIMEOUT); - /*disable the usdprgm bit */ - FLASH->ctrl_bit.usdprgm = FALSE; + /*disable the usdprgm bit */ + FLASH->ctrl_bit.usdprgm = FALSE; - /* return the status */ - return status; + /* return the status */ + return status; } /** @@ -604,32 +545,28 @@ flash_status_type flash_eopb0_config(flash_usd_eopb0_type data) * @retval status: the returned value can be: FLASH_PROGRAM_ERROR, * FLASH_EPP_ERROR, FLASH_OPERATE_DONE or FLASH_OPERATE_TIMEOUT. */ -flash_status_type flash_word_program(uint32_t address, uint32_t data) -{ - flash_status_type status = FLASH_OPERATE_DONE; - if((address >= FLASH_BANK1_START_ADDR) && (address <= FLASH_BANK1_END_ADDR)) - { - FLASH->ctrl_bit.fprgm = TRUE; - *(__IO uint32_t*)address = data; - /* wait for operation to be completed */ - status = flash_bank1_operation_wait_for(PROGRAMMING_TIMEOUT); +flash_status_type flash_word_program(uint32_t address, uint32_t data) { + flash_status_type status = FLASH_OPERATE_DONE; + if ((address >= FLASH_BANK1_START_ADDR) && (address <= FLASH_BANK1_END_ADDR)) { + FLASH->ctrl_bit.fprgm = TRUE; + *(__IO uint32_t *)address = data; + /* wait for operation to be completed */ + status = flash_bank1_operation_wait_for(PROGRAMMING_TIMEOUT); - /* disable the fprgm bit */ - FLASH->ctrl_bit.fprgm = FALSE; - } - else if((address >= FLASH_BANK2_START_ADDR) && (address <= FLASH_BANK2_END_ADDR)) - { - FLASH->ctrl2_bit.fprgm = TRUE; - *(__IO uint32_t*)address = data; - /* wait for operation to be completed */ - status = flash_bank2_operation_wait_for(PROGRAMMING_TIMEOUT); + /* disable the fprgm bit */ + FLASH->ctrl_bit.fprgm = FALSE; + } else if ((address >= FLASH_BANK2_START_ADDR) && (address <= FLASH_BANK2_END_ADDR)) { + FLASH->ctrl2_bit.fprgm = TRUE; + *(__IO uint32_t *)address = data; + /* wait for operation to be completed */ + status = flash_bank2_operation_wait_for(PROGRAMMING_TIMEOUT); - /* disable the fprgm bit */ - FLASH->ctrl2_bit.fprgm = FALSE; - } + /* disable the fprgm bit */ + FLASH->ctrl2_bit.fprgm = FALSE; + } - /* return the program status */ - return status; + /* return the program status */ + return status; } /** @@ -639,32 +576,28 @@ flash_status_type flash_word_program(uint32_t address, uint32_t data) * @retval status: the returned value can be: FLASH_PROGRAM_ERROR, * FLASH_EPP_ERROR, FLASH_OPERATE_DONE or FLASH_OPERATE_TIMEOUT. */ -flash_status_type flash_halfword_program(uint32_t address, uint16_t data) -{ - flash_status_type status = FLASH_OPERATE_DONE; - if((address >= FLASH_BANK1_START_ADDR) && (address <= FLASH_BANK1_END_ADDR)) - { - FLASH->ctrl_bit.fprgm = TRUE; - *(__IO uint16_t*)address = data; - /* wait for operation to be completed */ - status = flash_bank1_operation_wait_for(PROGRAMMING_TIMEOUT); +flash_status_type flash_halfword_program(uint32_t address, uint16_t data) { + flash_status_type status = FLASH_OPERATE_DONE; + if ((address >= FLASH_BANK1_START_ADDR) && (address <= FLASH_BANK1_END_ADDR)) { + FLASH->ctrl_bit.fprgm = TRUE; + *(__IO uint16_t *)address = data; + /* wait for operation to be completed */ + status = flash_bank1_operation_wait_for(PROGRAMMING_TIMEOUT); - /* disable the fprgm bit */ - FLASH->ctrl_bit.fprgm = FALSE; - } - else if((address >= FLASH_BANK2_START_ADDR) && (address <= FLASH_BANK2_END_ADDR)) - { - FLASH->ctrl2_bit.fprgm = TRUE; - *(__IO uint16_t*)address = data; - /* wait for operation to be completed */ - status = flash_bank2_operation_wait_for(PROGRAMMING_TIMEOUT); + /* disable the fprgm bit */ + FLASH->ctrl_bit.fprgm = FALSE; + } else if ((address >= FLASH_BANK2_START_ADDR) && (address <= FLASH_BANK2_END_ADDR)) { + FLASH->ctrl2_bit.fprgm = TRUE; + *(__IO uint16_t *)address = data; + /* wait for operation to be completed */ + status = flash_bank2_operation_wait_for(PROGRAMMING_TIMEOUT); - /* disable the fprgm bit */ - FLASH->ctrl2_bit.fprgm = FALSE; - } + /* disable the fprgm bit */ + FLASH->ctrl2_bit.fprgm = FALSE; + } - /* return the program status */ - return status; + /* return the program status */ + return status; } /** @@ -675,31 +608,27 @@ flash_status_type flash_halfword_program(uint32_t address, uint16_t data) * @retval status: the returned value can be: FLASH_PROGRAM_ERROR, * FLASH_EPP_ERROR, FLASH_OPERATE_DONE or FLASH_OPERATE_TIMEOUT. */ -flash_status_type flash_byte_program(uint32_t address, uint8_t data) -{ - flash_status_type status = FLASH_OPERATE_DONE; - if((address >= FLASH_BANK1_START_ADDR) && (address <= FLASH_BANK1_END_ADDR)) - { - FLASH->ctrl_bit.fprgm = TRUE; - *(__IO uint8_t*)address = data; - /* wait for operation to be completed */ - status = flash_bank1_operation_wait_for(PROGRAMMING_TIMEOUT); +flash_status_type flash_byte_program(uint32_t address, uint8_t data) { + flash_status_type status = FLASH_OPERATE_DONE; + if ((address >= FLASH_BANK1_START_ADDR) && (address <= FLASH_BANK1_END_ADDR)) { + FLASH->ctrl_bit.fprgm = TRUE; + *(__IO uint8_t *)address = data; + /* wait for operation to be completed */ + status = flash_bank1_operation_wait_for(PROGRAMMING_TIMEOUT); - /* disable the fprgm bit */ - FLASH->ctrl_bit.fprgm = FALSE; - } - else if((address >= FLASH_BANK2_START_ADDR) && (address <= FLASH_BANK2_END_ADDR)) - { - FLASH->ctrl2_bit.fprgm = TRUE; - *(__IO uint8_t*)address = data; - /* wait for operation to be completed */ - status = flash_bank2_operation_wait_for(PROGRAMMING_TIMEOUT); + /* disable the fprgm bit */ + FLASH->ctrl_bit.fprgm = FALSE; + } else if ((address >= FLASH_BANK2_START_ADDR) && (address <= FLASH_BANK2_END_ADDR)) { + FLASH->ctrl2_bit.fprgm = TRUE; + *(__IO uint8_t *)address = data; + /* wait for operation to be completed */ + status = flash_bank2_operation_wait_for(PROGRAMMING_TIMEOUT); - /* disable the fprgm bit */ - FLASH->ctrl2_bit.fprgm = FALSE; - } - /* return the program status */ - return status; + /* disable the fprgm bit */ + FLASH->ctrl2_bit.fprgm = FALSE; + } + /* return the program status */ + return status; } /** @@ -709,33 +638,31 @@ flash_status_type flash_byte_program(uint32_t address, uint8_t data) * @retval status: the returned value can be: FLASH_PROGRAM_ERROR, * FLASH_EPP_ERROR, FLASH_OPERATE_DONE or FLASH_OPERATE_TIMEOUT. */ -flash_status_type flash_user_system_data_program(uint32_t address, uint8_t data) -{ - flash_status_type status = FLASH_OPERATE_DONE; +flash_status_type flash_user_system_data_program(uint32_t address, uint8_t data) { + flash_status_type status = FLASH_OPERATE_DONE; - if(address == USD_BASE) - { - if(data != 0xA5) - return FLASH_OPERATE_DONE; - } - - /* unlock the user system data */ - FLASH->usd_unlock = FLASH_UNLOCK_KEY1; - FLASH->usd_unlock = FLASH_UNLOCK_KEY2; - while(FLASH->ctrl_bit.usdulks==RESET); + if (address == USD_BASE) { + if (data != 0xA5) + return FLASH_OPERATE_DONE; + } - /* enable the user system data programming operation */ - FLASH->ctrl_bit.usdprgm = TRUE; - *(__IO uint16_t*)address = data; + /* unlock the user system data */ + FLASH->usd_unlock = FLASH_UNLOCK_KEY1; + FLASH->usd_unlock = FLASH_UNLOCK_KEY2; + while (FLASH->ctrl_bit.usdulks == RESET); - /* wait for operation to be completed */ - status = flash_operation_wait_for(PROGRAMMING_TIMEOUT); + /* enable the user system data programming operation */ + FLASH->ctrl_bit.usdprgm = TRUE; + *(__IO uint16_t *)address = data; - /* disable the usdprgm bit */ - FLASH->ctrl_bit.usdprgm = FALSE; + /* wait for operation to be completed */ + status = flash_operation_wait_for(PROGRAMMING_TIMEOUT); - /* return the user system data program status */ - return status; + /* disable the usdprgm bit */ + FLASH->ctrl_bit.usdprgm = FALSE; + + /* return the user system data program status */ + return status; } /** @@ -747,80 +674,72 @@ flash_status_type flash_user_system_data_program(uint32_t address, uint8_t data) * @retval status: the returned value can be: FLASH_PROGRAM_ERROR, * FLASH_EPP_ERROR, FLASH_OPERATE_DONE or FLASH_OPERATE_TIMEOUT. */ -flash_status_type flash_epp_set(uint32_t *sector_bits) -{ - uint16_t epp_data[4] = {0xFFFF,0xFFFF,0xFFFF,0xFFFF}; - flash_status_type status = FLASH_OPERATE_DONE; - sector_bits[0] = (uint32_t)(~sector_bits[0]); - epp_data[0] = (uint16_t)((sector_bits[0] >> 0) & 0xFF); - epp_data[1] = (uint16_t)((sector_bits[0] >> 8) & 0xFF); - epp_data[2] = (uint16_t)((sector_bits[0] >> 16) & 0xFF); - epp_data[3] = (uint16_t)((sector_bits[0] >> 24) & 0xFF); +flash_status_type flash_epp_set(uint32_t *sector_bits) { + uint16_t epp_data[4] = {0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF}; + flash_status_type status = FLASH_OPERATE_DONE; + sector_bits[0] = (uint32_t)(~sector_bits[0]); + epp_data[0] = (uint16_t)((sector_bits[0] >> 0) & 0xFF); + epp_data[1] = (uint16_t)((sector_bits[0] >> 8) & 0xFF); + epp_data[2] = (uint16_t)((sector_bits[0] >> 16) & 0xFF); + epp_data[3] = (uint16_t)((sector_bits[0] >> 24) & 0xFF); - /* unlock the user system data */ - FLASH->usd_unlock = FLASH_UNLOCK_KEY1; - FLASH->usd_unlock = FLASH_UNLOCK_KEY2; - while(FLASH->ctrl_bit.usdulks==RESET); + /* unlock the user system data */ + FLASH->usd_unlock = FLASH_UNLOCK_KEY1; + FLASH->usd_unlock = FLASH_UNLOCK_KEY2; + while (FLASH->ctrl_bit.usdulks == RESET); - FLASH->ctrl_bit.usdprgm = TRUE; - USD->epp0 = epp_data[0]; - /* wait for operation to be completed */ - status = flash_operation_wait_for(PROGRAMMING_TIMEOUT); + FLASH->ctrl_bit.usdprgm = TRUE; + USD->epp0 = epp_data[0]; + /* wait for operation to be completed */ + status = flash_operation_wait_for(PROGRAMMING_TIMEOUT); - if(status == FLASH_OPERATE_DONE) - { - USD->epp1 = epp_data[1]; - /* wait for operation to be completed */ - status = flash_operation_wait_for(PROGRAMMING_TIMEOUT); - } - if(status == FLASH_OPERATE_DONE) - { - USD->epp2 = epp_data[2]; - /* wait for operation to be completed */ - status = flash_operation_wait_for(PROGRAMMING_TIMEOUT); - } - if(status == FLASH_OPERATE_DONE) - { - USD->epp3 = epp_data[3]; - /* wait for operation to be completed */ - status = flash_operation_wait_for(PROGRAMMING_TIMEOUT); - } + if (status == FLASH_OPERATE_DONE) { + USD->epp1 = epp_data[1]; + /* wait for operation to be completed */ + status = flash_operation_wait_for(PROGRAMMING_TIMEOUT); + } + if (status == FLASH_OPERATE_DONE) { + USD->epp2 = epp_data[2]; + /* wait for operation to be completed */ + status = flash_operation_wait_for(PROGRAMMING_TIMEOUT); + } + if (status == FLASH_OPERATE_DONE) { + USD->epp3 = epp_data[3]; + /* wait for operation to be completed */ + status = flash_operation_wait_for(PROGRAMMING_TIMEOUT); + } - sector_bits[1] = (uint32_t)(~sector_bits[1]); - epp_data[0] = (uint16_t)((sector_bits[1] >> 0) & 0xFF); - epp_data[1] = (uint16_t)((sector_bits[1] >> 8) & 0xFF); - epp_data[2] = (uint16_t)((sector_bits[1] >> 16) & 0xFF); - epp_data[3] = (uint16_t)((sector_bits[1] >> 24) & 0xFF); - if(status == FLASH_OPERATE_DONE) - { - USD->epp4 = epp_data[0]; - /* wait for operation to be completed */ - status = flash_operation_wait_for(PROGRAMMING_TIMEOUT); - } - if(status == FLASH_OPERATE_DONE) - { - USD->epp5 = epp_data[1]; - /* wait for operation to be completed */ - status = flash_operation_wait_for(PROGRAMMING_TIMEOUT); - } - if(status == FLASH_OPERATE_DONE) - { - USD->epp6 = epp_data[2]; - /* wait for operation to be completed */ - status = flash_operation_wait_for(PROGRAMMING_TIMEOUT); - } - if(status == FLASH_OPERATE_DONE) - { - USD->epp7 = epp_data[3]; - /* wait for operation to be completed */ - status = flash_operation_wait_for(PROGRAMMING_TIMEOUT); - } + sector_bits[1] = (uint32_t)(~sector_bits[1]); + epp_data[0] = (uint16_t)((sector_bits[1] >> 0) & 0xFF); + epp_data[1] = (uint16_t)((sector_bits[1] >> 8) & 0xFF); + epp_data[2] = (uint16_t)((sector_bits[1] >> 16) & 0xFF); + epp_data[3] = (uint16_t)((sector_bits[1] >> 24) & 0xFF); + if (status == FLASH_OPERATE_DONE) { + USD->epp4 = epp_data[0]; + /* wait for operation to be completed */ + status = flash_operation_wait_for(PROGRAMMING_TIMEOUT); + } + if (status == FLASH_OPERATE_DONE) { + USD->epp5 = epp_data[1]; + /* wait for operation to be completed */ + status = flash_operation_wait_for(PROGRAMMING_TIMEOUT); + } + if (status == FLASH_OPERATE_DONE) { + USD->epp6 = epp_data[2]; + /* wait for operation to be completed */ + status = flash_operation_wait_for(PROGRAMMING_TIMEOUT); + } + if (status == FLASH_OPERATE_DONE) { + USD->epp7 = epp_data[3]; + /* wait for operation to be completed */ + status = flash_operation_wait_for(PROGRAMMING_TIMEOUT); + } - /* disable the usdprgm bit */ - FLASH->ctrl_bit.usdprgm = FALSE; + /* disable the usdprgm bit */ + FLASH->ctrl_bit.usdprgm = FALSE; - /* return the erase/program protection operation status */ - return status; + /* return the erase/program protection operation status */ + return status; } /** @@ -828,11 +747,10 @@ flash_status_type flash_epp_set(uint32_t *sector_bits) * @param sector_bits: pointer to get the epps register. * @retval none */ -void flash_epp_status_get(uint32_t *sector_bits) -{ - /* return the flash erase/program protection register value */ - sector_bits[0] = (uint32_t)(FLASH->epps0); - sector_bits[1] = (uint32_t)(FLASH->epps1); +void flash_epp_status_get(uint32_t *sector_bits) { + /* return the flash erase/program protection register value */ + sector_bits[0] = (uint32_t)(FLASH->epps0); + sector_bits[1] = (uint32_t)(FLASH->epps1); } /** @@ -844,46 +762,43 @@ void flash_epp_status_get(uint32_t *sector_bits) * @retval status: the returned value can be: FLASH_PROGRAM_ERROR, * FLASH_EPP_ERROR, FLASH_OPERATE_DONE or FLASH_OPERATE_TIMEOUT. */ -flash_status_type flash_fap_enable(confirm_state new_state) -{ - flash_status_type status = FLASH_OPERATE_DONE; +flash_status_type flash_fap_enable(confirm_state new_state) { + flash_status_type status = FLASH_OPERATE_DONE; - /* unlock the user system data */ - FLASH->usd_unlock = FLASH_UNLOCK_KEY1; - FLASH->usd_unlock = FLASH_UNLOCK_KEY2; - while(FLASH->ctrl_bit.usdulks==RESET); + /* unlock the user system data */ + FLASH->usd_unlock = FLASH_UNLOCK_KEY1; + FLASH->usd_unlock = FLASH_UNLOCK_KEY2; + while (FLASH->ctrl_bit.usdulks == RESET); - FLASH->ctrl_bit.usders = TRUE; - FLASH->ctrl_bit.erstr = TRUE; - /* wait for operation to be completed */ - status = flash_operation_wait_for(ERASE_TIMEOUT); - - /* disable the usders bit */ - FLASH->ctrl_bit.usders = FALSE; - - if(status == FLASH_OPERATE_DONE) - { - /* enable the user system data programming operation */ - FLASH->ctrl_bit.usdprgm = TRUE; - - /* restore the default eopb0 value */ - USD->eopb0 = (uint16_t)0x0002; - - /* Wait for operation to be completed */ + FLASH->ctrl_bit.usders = TRUE; + FLASH->ctrl_bit.erstr = TRUE; + /* wait for operation to be completed */ status = flash_operation_wait_for(ERASE_TIMEOUT); - if(new_state == FALSE) - { - USD->fap = FAP_RELIEVE_KEY; - /* Wait for operation to be completed */ - status = flash_operation_wait_for(ERASE_TIMEOUT); - } - /* disable the usdprgm bit */ - FLASH->ctrl_bit.usdprgm = FALSE; - } + /* disable the usders bit */ + FLASH->ctrl_bit.usders = FALSE; - /* return the flash access protection operation status */ - return status; + if (status == FLASH_OPERATE_DONE) { + /* enable the user system data programming operation */ + FLASH->ctrl_bit.usdprgm = TRUE; + + /* restore the default eopb0 value */ + USD->eopb0 = (uint16_t)0x0002; + + /* Wait for operation to be completed */ + status = flash_operation_wait_for(ERASE_TIMEOUT); + + if (new_state == FALSE) { + USD->fap = FAP_RELIEVE_KEY; + /* Wait for operation to be completed */ + status = flash_operation_wait_for(ERASE_TIMEOUT); + } + /* disable the usdprgm bit */ + FLASH->ctrl_bit.usdprgm = FALSE; + } + + /* return the flash access protection operation status */ + return status; } /** @@ -891,9 +806,8 @@ flash_status_type flash_fap_enable(confirm_state new_state) * @param none * @retval flash access protection status(SET or RESET) */ -flag_status flash_fap_status_get(void) -{ - return (flag_status)FLASH->usd_bit.fap; +flag_status flash_fap_status_get(void) { + return (flag_status)FLASH->usd_bit.fap; } /** @@ -927,27 +841,26 @@ flag_status flash_fap_status_get(void) * @retval status: the returned value can be: FLASH_PROGRAM_ERROR, * FLASH_EPP_ERROR, FLASH_OPERATE_DONE or FLASH_OPERATE_TIMEOUT. */ -flash_status_type flash_ssb_set(uint8_t usd_ssb) -{ - flash_status_type status = FLASH_OPERATE_DONE; +flash_status_type flash_ssb_set(uint8_t usd_ssb) { + flash_status_type status = FLASH_OPERATE_DONE; - /* unlock the user system data */ - FLASH->usd_unlock = FLASH_UNLOCK_KEY1; - FLASH->usd_unlock = FLASH_UNLOCK_KEY2; - while(FLASH->ctrl_bit.usdulks==RESET); + /* unlock the user system data */ + FLASH->usd_unlock = FLASH_UNLOCK_KEY1; + FLASH->usd_unlock = FLASH_UNLOCK_KEY2; + while (FLASH->ctrl_bit.usdulks == RESET); - /* enable the user system data programming operation */ - FLASH->ctrl_bit.usdprgm = TRUE; + /* enable the user system data programming operation */ + FLASH->ctrl_bit.usdprgm = TRUE; - USD->ssb = usd_ssb; - /* wait for operation to be completed */ - status = flash_operation_wait_for(PROGRAMMING_TIMEOUT); + USD->ssb = usd_ssb; + /* wait for operation to be completed */ + status = flash_operation_wait_for(PROGRAMMING_TIMEOUT); - /* disable the usdprgm bit */ - FLASH->ctrl_bit.usdprgm = FALSE; + /* disable the usdprgm bit */ + FLASH->ctrl_bit.usdprgm = FALSE; - /* return the user system data program status */ - return status; + /* return the user system data program status */ + return status; } /** @@ -956,10 +869,9 @@ flash_status_type flash_ssb_set(uint8_t usd_ssb) * @retval values from flash_usd register: wdt_ato_en(bit0), depslp_rst(bit1), * stdby_rst(bit2) and btopt(bit3). */ -uint8_t flash_ssb_status_get(void) -{ - /* return the system setting byte status */ - return (uint8_t)(FLASH->usd >> 2); +uint8_t flash_ssb_status_get(void) { + /* return the system setting byte status */ + return (uint8_t)(FLASH->usd >> 2); } /** @@ -976,16 +888,15 @@ uint8_t flash_ssb_status_get(void) * this parameter can be: TRUE or FALSE. * @retval none */ -void flash_interrupt_enable(uint32_t flash_int, confirm_state new_state) -{ - if(flash_int & FLASH_BANK1_ERR_INT) - FLASH->ctrl_bit.errie = new_state; - if(flash_int & FLASH_BANK1_ODF_INT) - FLASH->ctrl_bit.odfie = new_state; - if(flash_int & FLASH_BANK2_ERR_INT) - FLASH->ctrl2_bit.errie = new_state; - if(flash_int & FLASH_BANK2_ODF_INT) - FLASH->ctrl2_bit.odfie = new_state; +void flash_interrupt_enable(uint32_t flash_int, confirm_state new_state) { + if (flash_int & FLASH_BANK1_ERR_INT) + FLASH->ctrl_bit.errie = new_state; + if (flash_int & FLASH_BANK1_ODF_INT) + FLASH->ctrl_bit.odfie = new_state; + if (flash_int & FLASH_BANK2_ERR_INT) + FLASH->ctrl2_bit.errie = new_state; + if (flash_int & FLASH_BANK2_ODF_INT) + FLASH->ctrl2_bit.odfie = new_state; } /** @@ -997,37 +908,34 @@ void flash_interrupt_enable(uint32_t flash_int, confirm_state new_state) * @retval status: the returned value can be: FLASH_PROGRAM_ERROR, * FLASH_EPP_ERROR, FLASH_OPERATE_DONE or FLASH_OPERATE_TIMEOUT. */ -flash_status_type flash_slib_enable(uint32_t pwd, uint16_t start_sector, uint16_t inst_start_sector, uint16_t end_sector) -{ - uint32_t slib_range; - flash_status_type status = FLASH_OPERATE_DONE; +flash_status_type flash_slib_enable(uint32_t pwd, uint16_t start_sector, uint16_t inst_start_sector, uint16_t end_sector) { + uint32_t slib_range; + flash_status_type status = FLASH_OPERATE_DONE; - /*check range param limits*/ - if((start_sector > inst_start_sector) || ((inst_start_sector > end_sector) && \ - (inst_start_sector != 0xFFFF)) || (start_sector > end_sector)) - return FLASH_PROGRAM_ERROR; + /*check range param limits*/ + if ((start_sector > inst_start_sector) || ((inst_start_sector > end_sector) && \ + (inst_start_sector != 0xFFFF)) || (start_sector > end_sector)) + return FLASH_PROGRAM_ERROR; - /* unlock slib cfg register */ - FLASH->slib_unlock = SLIB_UNLOCK_KEY; - while(FLASH->slib_misc_sts_bit.slib_ulkf==RESET); + /* unlock slib cfg register */ + FLASH->slib_unlock = SLIB_UNLOCK_KEY; + while (FLASH->slib_misc_sts_bit.slib_ulkf == RESET); - /* configure slib, set pwd and range */ - FLASH->slib_set_pwd = pwd; - status = flash_operation_wait_for(PROGRAMMING_TIMEOUT); - if(status == FLASH_OPERATE_DONE) - { - slib_range = ((uint32_t)(end_sector << 16) & FLASH_SLIB_END_SECTOR) | (start_sector & FLASH_SLIB_START_SECTOR); - FLASH->slib_set_range0 = slib_range; + /* configure slib, set pwd and range */ + FLASH->slib_set_pwd = pwd; status = flash_operation_wait_for(PROGRAMMING_TIMEOUT); - if(status == FLASH_OPERATE_DONE) - { - slib_range = (inst_start_sector & FLASH_SLIB_INST_START_SECTOR) | 0x80000000; - FLASH->slib_set_range1 = slib_range; - status = flash_operation_wait_for(PROGRAMMING_TIMEOUT); + if (status == FLASH_OPERATE_DONE) { + slib_range = ((uint32_t)(end_sector << 16) & FLASH_SLIB_END_SECTOR) | (start_sector & FLASH_SLIB_START_SECTOR); + FLASH->slib_set_range0 = slib_range; + status = flash_operation_wait_for(PROGRAMMING_TIMEOUT); + if (status == FLASH_OPERATE_DONE) { + slib_range = (inst_start_sector & FLASH_SLIB_INST_START_SECTOR) | 0x80000000; + FLASH->slib_set_range1 = slib_range; + status = flash_operation_wait_for(PROGRAMMING_TIMEOUT); + } } - } - return status; + return status; } /** @@ -1035,21 +943,19 @@ flash_status_type flash_slib_enable(uint32_t pwd, uint16_t start_sector, uint16_ * @param pwd: slib password * @retval success or error */ -error_status flash_slib_disable(uint32_t pwd) -{ - flash_status_type status = FLASH_OPERATE_DONE; - /* write password to disable slib */ - FLASH->slib_pwd_clr = pwd; +error_status flash_slib_disable(uint32_t pwd) { + flash_status_type status = FLASH_OPERATE_DONE; + /* write password to disable slib */ + FLASH->slib_pwd_clr = pwd; - status = flash_operation_wait_for(ERASE_TIMEOUT); - if(status == FLASH_OPERATE_DONE) - { - if(FLASH->slib_misc_sts_bit.slib_pwd_ok) - return SUCCESS; - else - return ERROR; - } - return ERROR; + status = flash_operation_wait_for(ERASE_TIMEOUT); + if (status == FLASH_OPERATE_DONE) { + if (FLASH->slib_misc_sts_bit.slib_pwd_ok) + return SUCCESS; + else + return ERROR; + } + return ERROR; } /** @@ -1057,9 +963,8 @@ error_status flash_slib_disable(uint32_t pwd) * @param none * @retval uint32_t */ -uint32_t flash_slib_remaining_count_get(void) -{ - return (uint32_t)FLASH->slib_misc_sts_bit.slib_rcnt; +uint32_t flash_slib_remaining_count_get(void) { + return (uint32_t)FLASH->slib_misc_sts_bit.slib_rcnt; } /** @@ -1067,12 +972,11 @@ uint32_t flash_slib_remaining_count_get(void) * @param none * @retval SET or RESET */ -flag_status flash_slib_state_get(void) -{ - if(FLASH->slib_sts0_bit.slib_enf) - return SET; - else - return RESET; +flag_status flash_slib_state_get(void) { + if (FLASH->slib_sts0_bit.slib_enf) + return SET; + else + return RESET; } /** @@ -1080,9 +984,8 @@ flag_status flash_slib_state_get(void) * @param none * @retval uint16_t */ -uint16_t flash_slib_start_sector_get(void) -{ - return (uint16_t)FLASH->slib_sts1_bit.slib_ss; +uint16_t flash_slib_start_sector_get(void) { + return (uint16_t)FLASH->slib_sts1_bit.slib_ss; } /** @@ -1090,9 +993,8 @@ uint16_t flash_slib_start_sector_get(void) * @param none * @retval uint16_t */ -uint16_t flash_slib_inststart_sector_get(void) -{ - return (uint16_t)FLASH->slib_sts2_bit.slib_inst_ss; +uint16_t flash_slib_inststart_sector_get(void) { + return (uint16_t)FLASH->slib_sts2_bit.slib_inst_ss; } /** @@ -1100,9 +1002,8 @@ uint16_t flash_slib_inststart_sector_get(void) * @param none * @retval uint16_t */ -uint16_t flash_slib_end_sector_get(void) -{ - return (uint16_t)FLASH->slib_sts1_bit.slib_es; +uint16_t flash_slib_end_sector_get(void) { + return (uint16_t)FLASH->slib_sts1_bit.slib_es; } /** @@ -1111,13 +1012,12 @@ uint16_t flash_slib_end_sector_get(void) * sector_cnt: crc calibration sector count * @retval uint32: crc calibration result */ -uint32_t flash_crc_calibrate(uint32_t start_sector, uint32_t sector_cnt) -{ - FLASH->crc_ctrl_bit.crc_ss = start_sector; - FLASH->crc_ctrl_bit.crc_sn = sector_cnt; - FLASH->crc_ctrl_bit.crc_strt = TRUE; - flash_operation_wait_for(OPERATION_TIMEOUT); - return FLASH->crc_chkr; +uint32_t flash_crc_calibrate(uint32_t start_sector, uint32_t sector_cnt) { + FLASH->crc_ctrl_bit.crc_ss = start_sector; + FLASH->crc_ctrl_bit.crc_sn = sector_cnt; + FLASH->crc_ctrl_bit.crc_strt = TRUE; + flash_operation_wait_for(OPERATION_TIMEOUT); + return FLASH->crc_chkr; } /** @@ -1126,9 +1026,8 @@ uint32_t flash_crc_calibrate(uint32_t start_sector, uint32_t sector_cnt) * this parameter can be: TRUE or FALSE. * @retval none */ -void flash_nzw_boost_enable(confirm_state new_state) -{ - FLASH->psr_bit.nzw_bst = new_state; +void flash_nzw_boost_enable(confirm_state new_state) { + FLASH->psr_bit.nzw_bst = new_state; } /** @@ -1137,9 +1036,8 @@ void flash_nzw_boost_enable(confirm_state new_state) * this parameter can be: TRUE or FALSE. * @retval none */ -void flash_continue_read_enable(confirm_state new_state) -{ - FLASH->contr_bit.fcontr_en = new_state; +void flash_continue_read_enable(confirm_state new_state) { + FLASH->contr_bit.fcontr_en = new_state; } /** diff --git a/armlib/at32_sys/drivers/src/at32f435_437_gpio.c b/armlib/at32_sys/drivers/src/at32f435_437_gpio.c index 1c88b8798..b114719c4 100644 --- a/armlib/at32_sys/drivers/src/at32f435_437_gpio.c +++ b/armlib/at32_sys/drivers/src/at32f435_437_gpio.c @@ -48,48 +48,32 @@ * GPIOA, GPIOB, GPIOC, GPIOD, GPIOE, GPIOF, GPIOG, GPIOH. * @retval none */ -void gpio_reset(gpio_type *gpio_x) -{ - if(gpio_x == GPIOA) - { - crm_periph_reset(CRM_GPIOA_PERIPH_RESET, TRUE); - crm_periph_reset(CRM_GPIOA_PERIPH_RESET, FALSE); - } - else if(gpio_x == GPIOB) - { - crm_periph_reset(CRM_GPIOB_PERIPH_RESET, TRUE); - crm_periph_reset(CRM_GPIOB_PERIPH_RESET, FALSE); - } - else if(gpio_x == GPIOC) - { - crm_periph_reset(CRM_GPIOC_PERIPH_RESET, TRUE); - crm_periph_reset(CRM_GPIOC_PERIPH_RESET, FALSE); - } - else if(gpio_x == GPIOD) - { - crm_periph_reset(CRM_GPIOD_PERIPH_RESET, TRUE); - crm_periph_reset(CRM_GPIOD_PERIPH_RESET, FALSE); - } - else if(gpio_x == GPIOE) - { - crm_periph_reset(CRM_GPIOE_PERIPH_RESET, TRUE); - crm_periph_reset(CRM_GPIOE_PERIPH_RESET, FALSE); - } - else if(gpio_x == GPIOF) - { - crm_periph_reset(CRM_GPIOF_PERIPH_RESET, TRUE); - crm_periph_reset(CRM_GPIOF_PERIPH_RESET, FALSE); - } - else if(gpio_x == GPIOG) - { - crm_periph_reset(CRM_GPIOG_PERIPH_RESET, TRUE); - crm_periph_reset(CRM_GPIOG_PERIPH_RESET, FALSE); - } - else if(gpio_x == GPIOH) - { - crm_periph_reset(CRM_GPIOH_PERIPH_RESET, TRUE); - crm_periph_reset(CRM_GPIOH_PERIPH_RESET, FALSE); - } +void gpio_reset(gpio_type *gpio_x) { + if (gpio_x == GPIOA) { + crm_periph_reset(CRM_GPIOA_PERIPH_RESET, TRUE); + crm_periph_reset(CRM_GPIOA_PERIPH_RESET, FALSE); + } else if (gpio_x == GPIOB) { + crm_periph_reset(CRM_GPIOB_PERIPH_RESET, TRUE); + crm_periph_reset(CRM_GPIOB_PERIPH_RESET, FALSE); + } else if (gpio_x == GPIOC) { + crm_periph_reset(CRM_GPIOC_PERIPH_RESET, TRUE); + crm_periph_reset(CRM_GPIOC_PERIPH_RESET, FALSE); + } else if (gpio_x == GPIOD) { + crm_periph_reset(CRM_GPIOD_PERIPH_RESET, TRUE); + crm_periph_reset(CRM_GPIOD_PERIPH_RESET, FALSE); + } else if (gpio_x == GPIOE) { + crm_periph_reset(CRM_GPIOE_PERIPH_RESET, TRUE); + crm_periph_reset(CRM_GPIOE_PERIPH_RESET, FALSE); + } else if (gpio_x == GPIOF) { + crm_periph_reset(CRM_GPIOF_PERIPH_RESET, TRUE); + crm_periph_reset(CRM_GPIOF_PERIPH_RESET, FALSE); + } else if (gpio_x == GPIOG) { + crm_periph_reset(CRM_GPIOG_PERIPH_RESET, TRUE); + crm_periph_reset(CRM_GPIOG_PERIPH_RESET, FALSE); + } else if (gpio_x == GPIOH) { + crm_periph_reset(CRM_GPIOH_PERIPH_RESET, TRUE); + crm_periph_reset(CRM_GPIOH_PERIPH_RESET, FALSE); + } } /** @@ -100,31 +84,28 @@ void gpio_reset(gpio_type *gpio_x) * @param gpio_init_struct: pointer to gpio init structure. * @retval none */ -void gpio_init(gpio_type *gpio_x, gpio_init_type *gpio_init_struct) -{ - uint16_t pinx_value, pin_index = 0; +void gpio_init(gpio_type *gpio_x, gpio_init_type *gpio_init_struct) { + uint16_t pinx_value, pin_index = 0; - pinx_value = (uint16_t)gpio_init_struct->gpio_pins; + pinx_value = (uint16_t)gpio_init_struct->gpio_pins; - while(pinx_value > 0) - { - if(pinx_value & 0x01) - { - gpio_x->cfgr &= (uint32_t)~(0x03 << (pin_index * 2)); - gpio_x->cfgr |= (uint32_t)(gpio_init_struct->gpio_mode << (pin_index * 2)); + while (pinx_value > 0) { + if (pinx_value & 0x01) { + gpio_x->cfgr &= (uint32_t)~(0x03 << (pin_index * 2)); + gpio_x->cfgr |= (uint32_t)(gpio_init_struct->gpio_mode << (pin_index * 2)); - gpio_x->omode &= (uint32_t)~(0x01 << (pin_index)); - gpio_x->omode |= (uint32_t)(gpio_init_struct->gpio_out_type << (pin_index)); + gpio_x->omode &= (uint32_t)~(0x01 << (pin_index)); + gpio_x->omode |= (uint32_t)(gpio_init_struct->gpio_out_type << (pin_index)); - gpio_x->odrvr &= (uint32_t)~(0x03 << (pin_index * 2)); - gpio_x->odrvr |= (uint32_t)(gpio_init_struct->gpio_drive_strength << (pin_index * 2)); + gpio_x->odrvr &= (uint32_t)~(0x03 << (pin_index * 2)); + gpio_x->odrvr |= (uint32_t)(gpio_init_struct->gpio_drive_strength << (pin_index * 2)); - gpio_x->pull &= (uint32_t)~(0x03 << (pin_index * 2)); - gpio_x->pull |= (uint32_t)(gpio_init_struct->gpio_pull << (pin_index * 2)); + gpio_x->pull &= (uint32_t)~(0x03 << (pin_index * 2)); + gpio_x->pull |= (uint32_t)(gpio_init_struct->gpio_pull << (pin_index * 2)); + } + pinx_value >>= 1; + pin_index++; } - pinx_value >>= 1; - pin_index++; - } } /** @@ -132,14 +113,13 @@ void gpio_init(gpio_type *gpio_x, gpio_init_type *gpio_init_struct) * @param gpio_init_struct : pointer to a gpio_init_type structure which will be initialized. * @retval none */ -void gpio_default_para_init(gpio_init_type *gpio_init_struct) -{ - /* reset gpio init structure parameters values */ - gpio_init_struct->gpio_pins = GPIO_PINS_ALL; - gpio_init_struct->gpio_mode = GPIO_MODE_INPUT; - gpio_init_struct->gpio_out_type = GPIO_OUTPUT_PUSH_PULL; - gpio_init_struct->gpio_pull = GPIO_PULL_NONE; - gpio_init_struct->gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER; +void gpio_default_para_init(gpio_init_type *gpio_init_struct) { + /* reset gpio init structure parameters values */ + gpio_init_struct->gpio_pins = GPIO_PINS_ALL; + gpio_init_struct->gpio_mode = GPIO_MODE_INPUT; + gpio_init_struct->gpio_out_type = GPIO_OUTPUT_PUSH_PULL; + gpio_init_struct->gpio_pull = GPIO_PULL_NONE; + gpio_init_struct->gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER; } /** @@ -167,20 +147,16 @@ void gpio_default_para_init(gpio_init_type *gpio_init_struct) * - GPIO_PINS_15 * @retval flag_status (SET or RESET) */ -flag_status gpio_input_data_bit_read(gpio_type *gpio_x, uint16_t pins) -{ - flag_status status = RESET; +flag_status gpio_input_data_bit_read(gpio_type *gpio_x, uint16_t pins) { + flag_status status = RESET; - if(pins != (pins & gpio_x->idt)) - { - status = RESET; - } - else - { - status = SET; - } + if (pins != (pins & gpio_x->idt)) { + status = RESET; + } else { + status = SET; + } - return status; + return status; } /** @@ -190,9 +166,8 @@ flag_status gpio_input_data_bit_read(gpio_type *gpio_x, uint16_t pins) * GPIOA, GPIOB, GPIOC, GPIOD, GPIOE, GPIOF, GPIOG, GPIOH. * @retval gpio input data port value. */ -uint16_t gpio_input_data_read(gpio_type *gpio_x) -{ - return ((uint16_t)(gpio_x->idt)); +uint16_t gpio_input_data_read(gpio_type *gpio_x) { + return ((uint16_t)(gpio_x->idt)); } /** @@ -220,20 +195,16 @@ uint16_t gpio_input_data_read(gpio_type *gpio_x) * - GPIO_PINS_15 * @retval flag_status (SET or RESET) */ -flag_status gpio_output_data_bit_read(gpio_type *gpio_x, uint16_t pins) -{ - flag_status status = RESET; +flag_status gpio_output_data_bit_read(gpio_type *gpio_x, uint16_t pins) { + flag_status status = RESET; - if((gpio_x->odt & pins) != RESET) - { - status = SET; - } - else - { - status = RESET; - } + if ((gpio_x->odt & pins) != RESET) { + status = SET; + } else { + status = RESET; + } - return status; + return status; } /** @@ -243,9 +214,8 @@ flag_status gpio_output_data_bit_read(gpio_type *gpio_x, uint16_t pins) * GPIOA, GPIOB, GPIOC, GPIOD, GPIOE, GPIOF, GPIOG, GPIOH. * @retval gpio input data port value. */ -uint16_t gpio_output_data_read(gpio_type *gpio_x) -{ - return ((uint16_t)(gpio_x->odt)); +uint16_t gpio_output_data_read(gpio_type *gpio_x) { + return ((uint16_t)(gpio_x->odt)); } /** @@ -274,9 +244,8 @@ uint16_t gpio_output_data_read(gpio_type *gpio_x) * - GPIO_PINS_ALL * @retval none */ -void gpio_bits_set(gpio_type *gpio_x, uint16_t pins) -{ - gpio_x->scr = pins; +void gpio_bits_set(gpio_type *gpio_x, uint16_t pins) { + gpio_x->scr = pins; } /** @@ -305,9 +274,8 @@ void gpio_bits_set(gpio_type *gpio_x, uint16_t pins) * - GPIO_PINS_ALL * @retval none */ -void gpio_bits_reset(gpio_type *gpio_x, uint16_t pins) -{ - gpio_x->clr = pins; +void gpio_bits_reset(gpio_type *gpio_x, uint16_t pins) { + gpio_x->clr = pins; } /** @@ -337,16 +305,12 @@ void gpio_bits_reset(gpio_type *gpio_x, uint16_t pins) * @param bit_state: specifies the value to be written to the selected bit (TRUE or FALSE). * @retval none */ -void gpio_bits_write(gpio_type *gpio_x, uint16_t pins, confirm_state bit_state) -{ - if(bit_state != FALSE) - { - gpio_x->scr = pins; - } - else - { - gpio_x->clr = pins; - } +void gpio_bits_write(gpio_type *gpio_x, uint16_t pins, confirm_state bit_state) { + if (bit_state != FALSE) { + gpio_x->scr = pins; + } else { + gpio_x->clr = pins; + } } /** @@ -357,9 +321,8 @@ void gpio_bits_write(gpio_type *gpio_x, uint16_t pins, confirm_state bit_state) * @param port_value: specifies the value to be written to the port output data register. * @retval none */ -void gpio_port_write(gpio_type *gpio_x, uint16_t port_value) -{ - gpio_x->odt = port_value; +void gpio_port_write(gpio_type *gpio_x, uint16_t port_value) { + gpio_x->odt = port_value; } /** @@ -388,21 +351,20 @@ void gpio_port_write(gpio_type *gpio_x, uint16_t port_value) * - GPIO_PINS_ALL * @retval none */ -void gpio_pin_wp_config(gpio_type *gpio_x, uint16_t pins) -{ - uint32_t temp = 0x00010000; +void gpio_pin_wp_config(gpio_type *gpio_x, uint16_t pins) { + uint32_t temp = 0x00010000; - temp |= pins; - /* set wpen bit */ - gpio_x->wpr = temp; - /* reset wpen bit */ - gpio_x->wpr = pins; - /* set wpen bit */ - gpio_x->wpr = temp; - /* read wpen bit*/ - temp = gpio_x->wpr; - /* read wpen bit*/ - temp = gpio_x->wpr; + temp |= pins; + /* set wpen bit */ + gpio_x->wpr = temp; + /* reset wpen bit */ + gpio_x->wpr = pins; + /* set wpen bit */ + gpio_x->wpr = temp; + /* read wpen bit*/ + temp = gpio_x->wpr; + /* read wpen bit*/ + temp = gpio_x->wpr; } /** @@ -433,16 +395,12 @@ void gpio_pin_wp_config(gpio_type *gpio_x, uint16_t pins) * this parameter can be: true or false. * @retval none */ -void gpio_pins_huge_driven_config(gpio_type *gpio_x, uint16_t pins, confirm_state new_state) -{ - if(new_state != FALSE) - { - gpio_x->hdrv |= pins; - } - else - { - gpio_x->hdrv &= ~pins; - } +void gpio_pins_huge_driven_config(gpio_type *gpio_x, uint16_t pins, confirm_state new_state) { + if (new_state != FALSE) { + gpio_x->hdrv |= pins; + } else { + gpio_x->hdrv &= ~pins; + } } /** @@ -488,24 +446,20 @@ void gpio_pins_huge_driven_config(gpio_type *gpio_x, uint16_t pins, confirm_stat * - GPIO_MUX_15 * @retval none */ -void gpio_pin_mux_config(gpio_type *gpio_x, gpio_pins_source_type gpio_pin_source, gpio_mux_sel_type gpio_mux) -{ - uint32_t temp = 0x00; - uint32_t temp_2 = 0x00; +void gpio_pin_mux_config(gpio_type *gpio_x, gpio_pins_source_type gpio_pin_source, gpio_mux_sel_type gpio_mux) { + uint32_t temp = 0x00; + uint32_t temp_2 = 0x00; - temp = ((uint32_t)(gpio_mux) << ((uint32_t)((uint32_t)gpio_pin_source & (uint32_t)0x07) * 4)); - if(gpio_pin_source >> 0x03) - { - gpio_x->muxh &= ~((uint32_t)0xF << ((uint32_t)((uint32_t)gpio_pin_source & (uint32_t)0x07) * 4)); - temp_2 = gpio_x->muxh | temp; - gpio_x->muxh = temp_2; - } - else - { - gpio_x->muxl &= ~((uint32_t)0xF << ((uint32_t)((uint32_t)gpio_pin_source & (uint32_t)0x07) * 4)); - temp_2 = gpio_x->muxl | temp; - gpio_x->muxl = temp_2; - } + temp = ((uint32_t)(gpio_mux) << ((uint32_t)((uint32_t)gpio_pin_source & (uint32_t)0x07) * 4)); + if (gpio_pin_source >> 0x03) { + gpio_x->muxh &= ~((uint32_t)0xF << ((uint32_t)((uint32_t)gpio_pin_source & (uint32_t)0x07) * 4)); + temp_2 = gpio_x->muxh | temp; + gpio_x->muxh = temp_2; + } else { + gpio_x->muxl &= ~((uint32_t)0xF << ((uint32_t)((uint32_t)gpio_pin_source & (uint32_t)0x07) * 4)); + temp_2 = gpio_x->muxl | temp; + gpio_x->muxl = temp_2; + } } /** diff --git a/armlib/at32_sys/drivers/src/at32f435_437_i2c.c b/armlib/at32_sys/drivers/src/at32f435_437_i2c.c index 434494a38..ba614aff1 100644 --- a/armlib/at32_sys/drivers/src/at32f435_437_i2c.c +++ b/armlib/at32_sys/drivers/src/at32f435_437_i2c.c @@ -48,23 +48,17 @@ * I2C1, I2C2, I2C3. * @retval none */ -void i2c_reset(i2c_type *i2c_x) -{ - if(i2c_x == I2C1) - { - crm_periph_reset(CRM_I2C1_PERIPH_RESET, TRUE); - crm_periph_reset(CRM_I2C1_PERIPH_RESET, FALSE); - } - else if(i2c_x == I2C2) - { - crm_periph_reset(CRM_I2C2_PERIPH_RESET, TRUE); - crm_periph_reset(CRM_I2C2_PERIPH_RESET, FALSE); - } - else if(i2c_x == I2C3) - { - crm_periph_reset(CRM_I2C3_PERIPH_RESET, TRUE); - crm_periph_reset(CRM_I2C3_PERIPH_RESET, FALSE); - } +void i2c_reset(i2c_type *i2c_x) { + if (i2c_x == I2C1) { + crm_periph_reset(CRM_I2C1_PERIPH_RESET, TRUE); + crm_periph_reset(CRM_I2C1_PERIPH_RESET, FALSE); + } else if (i2c_x == I2C2) { + crm_periph_reset(CRM_I2C2_PERIPH_RESET, TRUE); + crm_periph_reset(CRM_I2C2_PERIPH_RESET, FALSE); + } else if (i2c_x == I2C3) { + crm_periph_reset(CRM_I2C3_PERIPH_RESET, TRUE); + crm_periph_reset(CRM_I2C3_PERIPH_RESET, FALSE); + } } /** @@ -76,16 +70,15 @@ void i2c_reset(i2c_type *i2c_x) * @param clk: i2c clock control register (0x00000000~0xFFFFFFFF). * @retval none */ -void i2c_init(i2c_type *i2c_x, uint8_t dfilters, uint32_t clk) -{ - /* disable i2c peripheral */ - i2c_x->ctrl1_bit.i2cen = FALSE; +void i2c_init(i2c_type *i2c_x, uint8_t dfilters, uint32_t clk) { + /* disable i2c peripheral */ + i2c_x->ctrl1_bit.i2cen = FALSE; - /* write clkctrl register*/ - i2c_x->clkctrl = clk; + /* write clkctrl register*/ + i2c_x->clkctrl = clk; - /* write digital filter register*/ - i2c_x->ctrl1_bit.dflt = dfilters; + /* write digital filter register*/ + i2c_x->ctrl1_bit.dflt = dfilters; } /** @@ -100,16 +93,15 @@ void i2c_init(i2c_type *i2c_x, uint8_t dfilters, uint32_t clk) * @param address: own address 1, such as 0xB0. * @retval none */ -void i2c_own_address1_set(i2c_type *i2c_x, i2c_address_mode_type mode, uint16_t address) -{ - /* config address mode */ - i2c_x->oaddr1_bit.addr1mode = mode; +void i2c_own_address1_set(i2c_type *i2c_x, i2c_address_mode_type mode, uint16_t address) { + /* config address mode */ + i2c_x->oaddr1_bit.addr1mode = mode; - /* config address */ - i2c_x->oaddr1_bit.addr1 = address & 0x03FF; + /* config address */ + i2c_x->oaddr1_bit.addr1 = address & 0x03FF; - /* enable address */ - i2c_x->oaddr1_bit.addr1en = TRUE; + /* enable address */ + i2c_x->oaddr1_bit.addr1en = TRUE; } /** @@ -130,11 +122,10 @@ void i2c_own_address1_set(i2c_type *i2c_x, i2c_address_mode_type mode, uint16_t * - I2C_ADDR2_MASK07: response all addresses other than those reserved for i2c. * @retval none */ -void i2c_own_address2_set(i2c_type *i2c_x, uint8_t address, i2c_addr2_mask_type mask) -{ - i2c_x->oaddr2_bit.addr2mask = mask; +void i2c_own_address2_set(i2c_type *i2c_x, uint8_t address, i2c_addr2_mask_type mask) { + i2c_x->oaddr2_bit.addr2mask = mask; - i2c_x->oaddr2_bit.addr2 = (address >> 1) & 0x7F; + i2c_x->oaddr2_bit.addr2 = (address >> 1) & 0x7F; } /** @@ -145,9 +136,8 @@ void i2c_own_address2_set(i2c_type *i2c_x, uint8_t address, i2c_addr2_mask_type * @param new_state (TRUE or FALSE). * @retval none */ -void i2c_own_address2_enable(i2c_type *i2c_x, confirm_state new_state) -{ - i2c_x->oaddr2_bit.addr2en = new_state; +void i2c_own_address2_enable(i2c_type *i2c_x, confirm_state new_state) { + i2c_x->oaddr2_bit.addr2en = new_state; } /** @@ -162,19 +152,17 @@ void i2c_own_address2_enable(i2c_type *i2c_x, confirm_state new_state) * @param new_state (TRUE or FALSE). * @retval none */ -void i2c_smbus_enable(i2c_type *i2c_x, i2c_smbus_mode_type mode, confirm_state new_state) -{ - switch (mode) - { - case I2C_SMBUS_MODE_DEVICE: - i2c_x->ctrl1_bit.devaddren = new_state; - break; - case I2C_SMBUS_MODE_HOST: - i2c_x->ctrl1_bit.haddren = new_state; - break; - default: - break; - } +void i2c_smbus_enable(i2c_type *i2c_x, i2c_smbus_mode_type mode, confirm_state new_state) { + switch (mode) { + case I2C_SMBUS_MODE_DEVICE: + i2c_x->ctrl1_bit.devaddren = new_state; + break; + case I2C_SMBUS_MODE_HOST: + i2c_x->ctrl1_bit.haddren = new_state; + break; + default: + break; + } } /** @@ -185,9 +173,8 @@ void i2c_smbus_enable(i2c_type *i2c_x, i2c_smbus_mode_type mode, confirm_state n * @param new_state (TRUE or FALSE). * @retval none */ -void i2c_enable(i2c_type *i2c_x, confirm_state new_state) -{ - i2c_x->ctrl1_bit.i2cen = new_state; +void i2c_enable(i2c_type *i2c_x, confirm_state new_state) { + i2c_x->ctrl1_bit.i2cen = new_state; } /** @@ -198,9 +185,8 @@ void i2c_enable(i2c_type *i2c_x, confirm_state new_state) * @param new_state (TRUE or FALSE). * @retval none */ -void i2c_clock_stretch_enable(i2c_type *i2c_x, confirm_state new_state) -{ - i2c_x->ctrl1_bit.stretch = (!new_state); +void i2c_clock_stretch_enable(i2c_type *i2c_x, confirm_state new_state) { + i2c_x->ctrl1_bit.stretch = (!new_state); } /** @@ -211,9 +197,8 @@ void i2c_clock_stretch_enable(i2c_type *i2c_x, confirm_state new_state) * @param new_state (TRUE or FALSE). * @retval none. */ -void i2c_ack_enable(i2c_type *i2c_x, confirm_state new_state) -{ - i2c_x->ctrl2_bit.nacken = (!new_state); +void i2c_ack_enable(i2c_type *i2c_x, confirm_state new_state) { + i2c_x->ctrl2_bit.nacken = (!new_state); } /** @@ -224,9 +209,8 @@ void i2c_ack_enable(i2c_type *i2c_x, confirm_state new_state) * @param new_state (TRUE or FALSE). * @retval none */ -void i2c_addr10_mode_enable(i2c_type *i2c_x, confirm_state new_state) -{ - i2c_x->ctrl2_bit.addr10 = new_state; +void i2c_addr10_mode_enable(i2c_type *i2c_x, confirm_state new_state) { + i2c_x->ctrl2_bit.addr10 = new_state; } /** @@ -237,9 +221,8 @@ void i2c_addr10_mode_enable(i2c_type *i2c_x, confirm_state new_state) * @param address: slave address. * @retval none */ -void i2c_transfer_addr_set(i2c_type *i2c_x, uint16_t address) -{ - i2c_x->ctrl2_bit.saddr = address & 0x03FF; +void i2c_transfer_addr_set(i2c_type *i2c_x, uint16_t address) { + i2c_x->ctrl2_bit.saddr = address & 0x03FF; } /** @@ -249,9 +232,8 @@ void i2c_transfer_addr_set(i2c_type *i2c_x, uint16_t address) * I2C1, I2C2, I2C3. * @retval slave address */ -uint16_t i2c_transfer_addr_get(i2c_type *i2c_x) -{ - return i2c_x->ctrl2_bit.saddr; +uint16_t i2c_transfer_addr_get(i2c_type *i2c_x) { + return i2c_x->ctrl2_bit.saddr; } /** @@ -265,9 +247,8 @@ uint16_t i2c_transfer_addr_get(i2c_type *i2c_x) * - I2C_DIR_RECEIVE: master request a read transfer. * @retval none */ -void i2c_transfer_dir_set(i2c_type *i2c_x, i2c_transfer_dir_type i2c_direction) -{ - i2c_x->ctrl2_bit.dir = i2c_direction; +void i2c_transfer_dir_set(i2c_type *i2c_x, i2c_transfer_dir_type i2c_direction) { + i2c_x->ctrl2_bit.dir = i2c_direction; } /** @@ -279,16 +260,12 @@ void i2c_transfer_dir_set(i2c_type *i2c_x, i2c_transfer_dir_type i2c_direction) * - I2C_DIR_TRANSMIT: master request a write transfer, slave enters receiver mode. * - I2C_DIR_RECEIVE: master request a read transfer, slave enters transmitter mode. */ -i2c_transfer_dir_type i2c_transfer_dir_get(i2c_type *i2c_x) -{ - if (i2c_x->sts_bit.sdir == 0) - { - return I2C_DIR_TRANSMIT; - } - else - { - return I2C_DIR_RECEIVE; - } +i2c_transfer_dir_type i2c_transfer_dir_get(i2c_type *i2c_x) { + if (i2c_x->sts_bit.sdir == 0) { + return I2C_DIR_TRANSMIT; + } else { + return I2C_DIR_RECEIVE; + } } /** @@ -298,9 +275,8 @@ i2c_transfer_dir_type i2c_transfer_dir_get(i2c_type *i2c_x) * I2C1, I2C2, I2C3. * @retval slave matched address. */ -uint8_t i2c_matched_addr_get(i2c_type *i2c_x) -{ - return (i2c_x->sts_bit.addr << 1); +uint8_t i2c_matched_addr_get(i2c_type *i2c_x) { + return (i2c_x->sts_bit.addr << 1); } /** @@ -311,9 +287,8 @@ uint8_t i2c_matched_addr_get(i2c_type *i2c_x) * @param new_state (TRUE or FALSE). * @retval none */ -void i2c_auto_stop_enable(i2c_type *i2c_x, confirm_state new_state) -{ - i2c_x->ctrl2_bit.astopen = new_state; +void i2c_auto_stop_enable(i2c_type *i2c_x, confirm_state new_state) { + i2c_x->ctrl2_bit.astopen = new_state; } /** @@ -324,9 +299,8 @@ void i2c_auto_stop_enable(i2c_type *i2c_x, confirm_state new_state) * @param new_state (TRUE or FALSE). * @retval none */ -void i2c_reload_enable(i2c_type *i2c_x, confirm_state new_state) -{ - i2c_x->ctrl2_bit.rlden = new_state; +void i2c_reload_enable(i2c_type *i2c_x, confirm_state new_state) { + i2c_x->ctrl2_bit.rlden = new_state; } /** @@ -337,9 +311,8 @@ void i2c_reload_enable(i2c_type *i2c_x, confirm_state new_state) * @param cnt: transfer cnt. * @retval none */ -void i2c_cnt_set(i2c_type *i2c_x, uint8_t cnt) -{ - i2c_x->ctrl2_bit.cnt = cnt; +void i2c_cnt_set(i2c_type *i2c_x, uint8_t cnt) { + i2c_x->ctrl2_bit.cnt = cnt; } /** @@ -351,9 +324,8 @@ void i2c_cnt_set(i2c_type *i2c_x, uint8_t cnt) * @param new_state (TRUE or FALSE). * @retval none */ -void i2c_addr10_header_enable(i2c_type *i2c_x, confirm_state new_state) -{ - i2c_x->ctrl2_bit.readh10 = new_state; +void i2c_addr10_header_enable(i2c_type *i2c_x, confirm_state new_state) { + i2c_x->ctrl2_bit.readh10 = new_state; } /** @@ -364,9 +336,8 @@ void i2c_addr10_header_enable(i2c_type *i2c_x, confirm_state new_state) * @param new_state (TRUE or FALSE). * @retval none */ -void i2c_general_call_enable(i2c_type *i2c_x, confirm_state new_state) -{ - i2c_x->ctrl1_bit.gcaen = new_state; +void i2c_general_call_enable(i2c_type *i2c_x, confirm_state new_state) { + i2c_x->ctrl1_bit.gcaen = new_state; } /** @@ -380,9 +351,8 @@ void i2c_general_call_enable(i2c_type *i2c_x, confirm_state new_state) * - I2C_SMBUS_ALERT_HIGH: smbus alert set high. * @retval none */ -void i2c_smbus_alert_set(i2c_type *i2c_x, i2c_smbus_alert_set_type level) -{ - i2c_x->ctrl1_bit.smbalert = level; +void i2c_smbus_alert_set(i2c_type *i2c_x, i2c_smbus_alert_set_type level) { + i2c_x->ctrl1_bit.smbalert = level; } /** @@ -393,9 +363,8 @@ void i2c_smbus_alert_set(i2c_type *i2c_x, i2c_smbus_alert_set_type level) * @param new_state (TRUE or FALSE). * @retval none */ -void i2c_slave_data_ctrl_enable(i2c_type *i2c_x, confirm_state new_state) -{ - i2c_x->ctrl1_bit.sctrl = new_state; +void i2c_slave_data_ctrl_enable(i2c_type *i2c_x, confirm_state new_state) { + i2c_x->ctrl1_bit.sctrl = new_state; } /** @@ -406,9 +375,8 @@ void i2c_slave_data_ctrl_enable(i2c_type *i2c_x, confirm_state new_state) * @param new_state (TRUE or FALSE). * @retval none */ -void i2c_pec_calculate_enable(i2c_type *i2c_x, confirm_state new_state) -{ - i2c_x->ctrl1_bit.pecen = new_state; +void i2c_pec_calculate_enable(i2c_type *i2c_x, confirm_state new_state) { + i2c_x->ctrl1_bit.pecen = new_state; } /** @@ -419,9 +387,8 @@ void i2c_pec_calculate_enable(i2c_type *i2c_x, confirm_state new_state) * @param new_state (TRUE or FALSE). * @retval none */ -void i2c_pec_transmit_enable(i2c_type *i2c_x, confirm_state new_state) -{ - i2c_x->ctrl2_bit.pecten = new_state; +void i2c_pec_transmit_enable(i2c_type *i2c_x, confirm_state new_state) { + i2c_x->ctrl2_bit.pecten = new_state; } /** @@ -431,9 +398,8 @@ void i2c_pec_transmit_enable(i2c_type *i2c_x, confirm_state new_state) * I2C1, I2C2, I2C3. * @retval the value of the pec. */ -uint8_t i2c_pec_value_get(i2c_type *i2c_x) -{ - return (uint8_t)(i2c_x->pec_bit.pecval); +uint8_t i2c_pec_value_get(i2c_type *i2c_x) { + return (uint8_t)(i2c_x->pec_bit.pecval); } /** @@ -444,9 +410,8 @@ uint8_t i2c_pec_value_get(i2c_type *i2c_x) * @param timeout: timeout (0x0000~0x0FFF). * @retval none */ -void i2c_timeout_set(i2c_type *i2c_x, uint16_t timeout) -{ - i2c_x->timeout_bit.totime = timeout; +void i2c_timeout_set(i2c_type *i2c_x, uint16_t timeout) { + i2c_x->timeout_bit.totime = timeout; } /** @@ -460,9 +425,8 @@ void i2c_timeout_set(i2c_type *i2c_x, uint16_t timeout) * - I2C_TIMEOUT_DETCET_LOW: detect low level timeout. * @retval none */ -void i2c_timeout_detcet_set(i2c_type *i2c_x, i2c_timeout_detcet_type mode) -{ - i2c_x->timeout_bit.tomode = mode; +void i2c_timeout_detcet_set(i2c_type *i2c_x, i2c_timeout_detcet_type mode) { + i2c_x->timeout_bit.tomode = mode; } /** @@ -473,9 +437,8 @@ void i2c_timeout_detcet_set(i2c_type *i2c_x, i2c_timeout_detcet_type mode) * @param new_state (TRUE or FALSE). * @retval none */ -void i2c_timeout_enable(i2c_type *i2c_x, confirm_state new_state) -{ - i2c_x->timeout_bit.toen = new_state; +void i2c_timeout_enable(i2c_type *i2c_x, confirm_state new_state) { + i2c_x->timeout_bit.toen = new_state; } /** @@ -486,9 +449,8 @@ void i2c_timeout_enable(i2c_type *i2c_x, confirm_state new_state) * @param timeout: extend timeout (0x0000~0x0FFF). * @retval none */ -void i2c_ext_timeout_set(i2c_type *i2c_x, uint16_t timeout) -{ - i2c_x->timeout_bit.exttime = timeout; +void i2c_ext_timeout_set(i2c_type *i2c_x, uint16_t timeout) { + i2c_x->timeout_bit.exttime = timeout; } /** @@ -499,9 +461,8 @@ void i2c_ext_timeout_set(i2c_type *i2c_x, uint16_t timeout) * @param new_state (TRUE or FALSE). * @retval none */ -void i2c_ext_timeout_enable(i2c_type *i2c_x, confirm_state new_state) -{ - i2c_x->timeout_bit.exten = new_state; +void i2c_ext_timeout_enable(i2c_type *i2c_x, confirm_state new_state) { + i2c_x->timeout_bit.exten = new_state; } /** @@ -521,16 +482,12 @@ void i2c_ext_timeout_enable(i2c_type *i2c_x, confirm_state new_state) * @param new_state (TRUE or FALSE). * @retval none */ -void i2c_interrupt_enable(i2c_type *i2c_x, uint32_t source, confirm_state new_state) -{ - if (new_state != FALSE) - { - i2c_x->ctrl1 |= source; - } - else - { - i2c_x->ctrl1 &= (uint32_t)~source; - } +void i2c_interrupt_enable(i2c_type *i2c_x, uint32_t source, confirm_state new_state) { + if (new_state != FALSE) { + i2c_x->ctrl1 |= source; + } else { + i2c_x->ctrl1 &= (uint32_t)~source; + } } /** @@ -549,16 +506,12 @@ void i2c_interrupt_enable(i2c_type *i2c_x, uint32_t source, confirm_state new_st * - I2C_ERR_INT: bus error interrupt. * @retval flag_status (SET or RESET) */ -flag_status i2c_interrupt_get(i2c_type *i2c_x, uint16_t source) -{ - if((i2c_x->ctrl1 & source) != RESET) - { - return SET; - } - else - { - return RESET; - } +flag_status i2c_interrupt_get(i2c_type *i2c_x, uint16_t source) { + if ((i2c_x->ctrl1 & source) != RESET) { + return SET; + } else { + return RESET; + } } /** @@ -573,16 +526,12 @@ flag_status i2c_interrupt_get(i2c_type *i2c_x, uint16_t source) * @param new_state (TRUE or FALSE). * @retval none */ -void i2c_dma_enable(i2c_type *i2c_x, i2c_dma_request_type dma_req, confirm_state new_state) -{ - if(dma_req == I2C_DMA_REQUEST_TX) - { - i2c_x->ctrl1_bit.dmaten = new_state; - } - else - { - i2c_x->ctrl1_bit.dmaren = new_state; - } +void i2c_dma_enable(i2c_type *i2c_x, i2c_dma_request_type dma_req, confirm_state new_state) { + if (dma_req == I2C_DMA_REQUEST_TX) { + i2c_x->ctrl1_bit.dmaten = new_state; + } else { + i2c_x->ctrl1_bit.dmaren = new_state; + } } /** @@ -604,24 +553,23 @@ void i2c_dma_enable(i2c_type *i2c_x, i2c_dma_request_type dma_req, confirm_state * - I2C_GEN_START_WRITE: send data and generate start. * @retval none */ -void i2c_transmit_set(i2c_type *i2c_x, uint16_t address, uint8_t cnt, i2c_reload_stop_mode_type rld_stop, i2c_start_mode_type start) -{ - uint32_t temp; +void i2c_transmit_set(i2c_type *i2c_x, uint16_t address, uint8_t cnt, i2c_reload_stop_mode_type rld_stop, i2c_start_mode_type start) { + uint32_t temp; - /* copy ctrl2 value to temp */ - temp = i2c_x->ctrl2; + /* copy ctrl2 value to temp */ + temp = i2c_x->ctrl2; - /* clear ctrl2_bit specific bits */ - temp &= ~0x03FF67FF; + /* clear ctrl2_bit specific bits */ + temp &= ~0x03FF67FF; - /* transfer mode and address set */ - temp |= address | rld_stop | start; + /* transfer mode and address set */ + temp |= address | rld_stop | start; - /* transfer counter set */ - temp |= (uint32_t)cnt << 16; + /* transfer counter set */ + temp |= (uint32_t)cnt << 16; - /* update ctrl2 value */ - i2c_x->ctrl2 = temp; + /* update ctrl2 value */ + i2c_x->ctrl2 = temp; } /** @@ -631,9 +579,8 @@ void i2c_transmit_set(i2c_type *i2c_x, uint16_t address, uint8_t cnt, i2c_reload * I2C1, I2C2, I2C3. * @retval none */ -void i2c_start_generate(i2c_type *i2c_x) -{ - i2c_x->ctrl2_bit.genstart = TRUE; +void i2c_start_generate(i2c_type *i2c_x) { + i2c_x->ctrl2_bit.genstart = TRUE; } /** @@ -643,9 +590,8 @@ void i2c_start_generate(i2c_type *i2c_x) * I2C1, I2C2, I2C3. * @retval none */ -void i2c_stop_generate(i2c_type *i2c_x) -{ - i2c_x->ctrl2_bit.genstop = TRUE; +void i2c_stop_generate(i2c_type *i2c_x) { + i2c_x->ctrl2_bit.genstop = TRUE; } /** @@ -656,9 +602,8 @@ void i2c_stop_generate(i2c_type *i2c_x) * @param data: byte to be transmitted. * @retval none */ -void i2c_data_send(i2c_type *i2c_x, uint8_t data) -{ - i2c_x->txdt = data; +void i2c_data_send(i2c_type *i2c_x, uint8_t data) { + i2c_x->txdt = data; } /** @@ -668,9 +613,8 @@ void i2c_data_send(i2c_type *i2c_x, uint8_t data) * I2C1, I2C2, I2C3. * @retval the value of the received data. */ -uint8_t i2c_data_receive(i2c_type *i2c_x) -{ - return (uint8_t)i2c_x->rxdt; +uint8_t i2c_data_receive(i2c_type *i2c_x) { + return (uint8_t)i2c_x->rxdt; } /** @@ -698,16 +642,12 @@ uint8_t i2c_data_receive(i2c_type *i2c_x) * - I2C_SDIR_FLAG: slave data transmit direction. * @retval the new state of flag (SET or RESET). */ -flag_status i2c_flag_get(i2c_type *i2c_x, uint32_t flag) -{ - if((i2c_x->sts & flag) != RESET) - { - return SET; - } - else - { - return RESET; - } +flag_status i2c_flag_get(i2c_type *i2c_x, uint32_t flag) { + if ((i2c_x->sts & flag) != RESET) { + return SET; + } else { + return RESET; + } } /** @@ -733,52 +673,47 @@ flag_status i2c_flag_get(i2c_type *i2c_x, uint32_t flag) * - I2C_ALERTF_FLAG: smbus alert flag. * @retval the new state of flag (SET or RESET). */ -flag_status i2c_interrupt_flag_get(i2c_type *i2c_x, uint32_t flag) -{ - __IO uint32_t iten = 0; +flag_status i2c_interrupt_flag_get(i2c_type *i2c_x, uint32_t flag) { + __IO uint32_t iten = 0; - switch(flag) - { - case I2C_TDIS_FLAG: - iten = i2c_x->ctrl1_bit.tdien; - break; - case I2C_RDBF_FLAG: - iten = i2c_x->ctrl1_bit.rdien; - break; - case I2C_ADDRF_FLAG: - iten = i2c_x->ctrl1_bit.addrien; - break; - case I2C_ACKFAIL_FLAG: - iten = i2c_x->ctrl1_bit.ackfailien; - break; - case I2C_STOPF_FLAG: - iten = i2c_x->ctrl1_bit.stopien; - break; - case I2C_TDC_FLAG: - case I2C_TCRLD_FLAG: - iten = i2c_x->ctrl1_bit.tdcien; - break; - case I2C_BUSERR_FLAG: - case I2C_ARLOST_FLAG: - case I2C_OUF_FLAG: - case I2C_PECERR_FLAG: - case I2C_TMOUT_FLAG: - case I2C_ALERTF_FLAG: - iten = i2c_x->ctrl1_bit.errien; - break; + switch (flag) { + case I2C_TDIS_FLAG: + iten = i2c_x->ctrl1_bit.tdien; + break; + case I2C_RDBF_FLAG: + iten = i2c_x->ctrl1_bit.rdien; + break; + case I2C_ADDRF_FLAG: + iten = i2c_x->ctrl1_bit.addrien; + break; + case I2C_ACKFAIL_FLAG: + iten = i2c_x->ctrl1_bit.ackfailien; + break; + case I2C_STOPF_FLAG: + iten = i2c_x->ctrl1_bit.stopien; + break; + case I2C_TDC_FLAG: + case I2C_TCRLD_FLAG: + iten = i2c_x->ctrl1_bit.tdcien; + break; + case I2C_BUSERR_FLAG: + case I2C_ARLOST_FLAG: + case I2C_OUF_FLAG: + case I2C_PECERR_FLAG: + case I2C_TMOUT_FLAG: + case I2C_ALERTF_FLAG: + iten = i2c_x->ctrl1_bit.errien; + break; - default: - break; - } + default: + break; + } - if(((i2c_x->sts & flag) != RESET) && (iten)) - { - return SET; - } - else - { - return RESET; - } + if (((i2c_x->sts & flag) != RESET) && (iten)) { + return SET; + } else { + return RESET; + } } /** @@ -799,9 +734,8 @@ flag_status i2c_interrupt_flag_get(i2c_type *i2c_x, uint32_t flag) * - I2C_ALERTF_FLAG: smbus alert flag. * @retval none */ -void i2c_flag_clear(i2c_type *i2c_x, uint32_t flag) -{ - i2c_x->clr = flag; +void i2c_flag_clear(i2c_type *i2c_x, uint32_t flag) { + i2c_x->clr = flag; } /** diff --git a/armlib/at32_sys/drivers/src/at32f435_437_misc.c b/armlib/at32_sys/drivers/src/at32f435_437_misc.c index 686ec9b92..f694f958b 100644 --- a/armlib/at32_sys/drivers/src/at32f435_437_misc.c +++ b/armlib/at32_sys/drivers/src/at32f435_437_misc.c @@ -48,9 +48,8 @@ * @param none * @retval none */ -void nvic_system_reset(void) -{ - NVIC_SystemReset(); +void nvic_system_reset(void) { + NVIC_SystemReset(); } /** @@ -60,16 +59,15 @@ void nvic_system_reset(void) * @param sub_priority: subpriority value (starting from 0) * @retval none */ -void nvic_irq_enable(IRQn_Type irqn, uint32_t preempt_priority, uint32_t sub_priority) -{ - uint32_t temp_priority = 0; +void nvic_irq_enable(IRQn_Type irqn, uint32_t preempt_priority, uint32_t sub_priority) { + uint32_t temp_priority = 0; - /* encode priority */ - temp_priority = NVIC_EncodePriority(NVIC_GetPriorityGrouping(), preempt_priority, sub_priority); - /* set priority */ - NVIC_SetPriority(irqn, temp_priority); - /* enable irqn */ - NVIC_EnableIRQ(irqn); + /* encode priority */ + temp_priority = NVIC_EncodePriority(NVIC_GetPriorityGrouping(), preempt_priority, sub_priority); + /* set priority */ + NVIC_SetPriority(irqn, temp_priority); + /* enable irqn */ + NVIC_EnableIRQ(irqn); } /** @@ -77,9 +75,8 @@ void nvic_irq_enable(IRQn_Type irqn, uint32_t preempt_priority, uint32_t sub_pri * @param irqn (IRQn_Type number) * @retval none */ -void nvic_irq_disable(IRQn_Type irqn) -{ - NVIC_DisableIRQ(irqn); +void nvic_irq_disable(IRQn_Type irqn) { + NVIC_DisableIRQ(irqn); } /** @@ -93,10 +90,9 @@ void nvic_irq_disable(IRQn_Type irqn) * - NVIC_PRIORITY_GROUP_4 * @retval none */ -void nvic_priority_group_config(nvic_priority_group_type priority_group) -{ - /* set the prigroup[10:8] bits according to nvic_prioritygroup value */ - NVIC_SetPriorityGrouping(priority_group); +void nvic_priority_group_config(nvic_priority_group_type priority_group) { + /* set the prigroup[10:8] bits according to nvic_prioritygroup value */ + NVIC_SetPriorityGrouping(priority_group); } /** @@ -108,9 +104,8 @@ void nvic_priority_group_config(nvic_priority_group_type priority_group) * @param offset (vector table base offset field. this value must be a multiple of 0x200) * @retval none */ -void nvic_vector_table_set(uint32_t base, uint32_t offset) -{ - SCB->VTOR = base | (offset & (uint32_t)0x1FFFFF80); +void nvic_vector_table_set(uint32_t base, uint32_t offset) { + SCB->VTOR = base | (offset & (uint32_t)0x1FFFFF80); } /** @@ -123,16 +118,12 @@ void nvic_vector_table_set(uint32_t base, uint32_t offset) * @param new_state (new state of lp condition. ENABLE or DISABLE) * @retval none */ -void nvic_lowpower_mode_config(nvic_lowpower_mode_type lp_mode, confirm_state new_state) -{ - if(new_state != FALSE) - { - SCB->SCR |= lp_mode; - } - else - { - SCB->SCR &= (uint32_t)(~(uint32_t)lp_mode); - } +void nvic_lowpower_mode_config(nvic_lowpower_mode_type lp_mode, confirm_state new_state) { + if (new_state != FALSE) { + SCB->SCR |= lp_mode; + } else { + SCB->SCR &= (uint32_t)(~(uint32_t)lp_mode); + } } /** @@ -143,16 +134,12 @@ void nvic_lowpower_mode_config(nvic_lowpower_mode_type lp_mode, confirm_state ne * - SYSTICK_CLOCK_SOURCE_AHBCLK_NODIV * @retval none */ -void systick_clock_source_config(systick_clock_source_type source) -{ - if(source == SYSTICK_CLOCK_SOURCE_AHBCLK_NODIV) - { - SysTick->CTRL |= SYSTICK_CLOCK_SOURCE_AHBCLK_NODIV; - } - else - { - SysTick->CTRL &= ~(uint32_t)SYSTICK_CLOCK_SOURCE_AHBCLK_NODIV; - } +void systick_clock_source_config(systick_clock_source_type source) { + if (source == SYSTICK_CLOCK_SOURCE_AHBCLK_NODIV) { + SysTick->CTRL |= SYSTICK_CLOCK_SOURCE_AHBCLK_NODIV; + } else { + SysTick->CTRL &= ~(uint32_t)SYSTICK_CLOCK_SOURCE_AHBCLK_NODIV; + } } /** diff --git a/armlib/at32_sys/drivers/src/at32f435_437_pwc.c b/armlib/at32_sys/drivers/src/at32f435_437_pwc.c index ebbf421fb..535a02b83 100644 --- a/armlib/at32_sys/drivers/src/at32f435_437_pwc.c +++ b/armlib/at32_sys/drivers/src/at32f435_437_pwc.c @@ -46,10 +46,9 @@ * @param none * @retval none */ -void pwc_reset(void) -{ - crm_periph_reset(CRM_PWC_PERIPH_RESET, TRUE); - crm_periph_reset(CRM_PWC_PERIPH_RESET, FALSE); +void pwc_reset(void) { + crm_periph_reset(CRM_PWC_PERIPH_RESET, TRUE); + crm_periph_reset(CRM_PWC_PERIPH_RESET, FALSE); } /** @@ -58,9 +57,8 @@ void pwc_reset(void) * this parameter can be: TRUE or FALSE. * @retval none */ -void pwc_battery_powered_domain_access(confirm_state new_state) -{ - PWC->ctrl_bit.bpwen= new_state; +void pwc_battery_powered_domain_access(confirm_state new_state) { + PWC->ctrl_bit.bpwen = new_state; } /** @@ -76,9 +74,8 @@ void pwc_battery_powered_domain_access(confirm_state new_state) * - PWC_PVM_VOLTAGE_2V9 * @retval none */ -void pwc_pvm_level_select(pwc_pvm_voltage_type pvm_voltage) -{ - PWC->ctrl_bit.pvmsel= pvm_voltage; +void pwc_pvm_level_select(pwc_pvm_voltage_type pvm_voltage) { + PWC->ctrl_bit.pvmsel = pvm_voltage; } /** @@ -87,9 +84,8 @@ void pwc_pvm_level_select(pwc_pvm_voltage_type pvm_voltage) * this parameter can be: TRUE or FALSE. * @retval none */ -void pwc_power_voltage_monitor_enable(confirm_state new_state) -{ - PWC->ctrl_bit.pvmen= new_state; +void pwc_power_voltage_monitor_enable(confirm_state new_state) { + PWC->ctrl_bit.pvmen = new_state; } /** @@ -104,16 +100,12 @@ void pwc_power_voltage_monitor_enable(confirm_state new_state) * - FALSE * @retval none */ -void pwc_wakeup_pin_enable(uint32_t pin_num, confirm_state new_state) -{ - if(new_state == TRUE) - { - PWC->ctrlsts |= pin_num; - } - else - { - PWC->ctrlsts &= ~pin_num; - } +void pwc_wakeup_pin_enable(uint32_t pin_num, confirm_state new_state) { + if (new_state == TRUE) { + PWC->ctrlsts |= pin_num; + } else { + PWC->ctrlsts &= ~pin_num; + } } /** @@ -125,12 +117,11 @@ void pwc_wakeup_pin_enable(uint32_t pin_num, confirm_state new_state) * - note:"PWC_PVM_OUTPUT_FLAG" cannot be choose!this bit is readonly bit,it means the voltage monitoring output state * @retval none */ -void pwc_flag_clear(uint32_t pwc_flag) -{ - if(pwc_flag & PWC_STANDBY_FLAG) - PWC->ctrl_bit.clsef = TRUE; - if(pwc_flag & PWC_WAKEUP_FLAG) - PWC->ctrl_bit.clswef = TRUE; +void pwc_flag_clear(uint32_t pwc_flag) { + if (pwc_flag & PWC_STANDBY_FLAG) + PWC->ctrl_bit.clsef = TRUE; + if (pwc_flag & PWC_WAKEUP_FLAG) + PWC->ctrl_bit.clswef = TRUE; } /** @@ -142,18 +133,14 @@ void pwc_flag_clear(uint32_t pwc_flag) * - PWC_PVM_OUTPUT_FLAG * @retval state of select flag(SET or RESET). */ -flag_status pwc_flag_get(uint32_t pwc_flag) -{ - flag_status status = RESET; - if ((PWC->ctrlsts & pwc_flag) == RESET) - { - status = RESET; - } - else - { - status = SET; - } - return status; +flag_status pwc_flag_get(uint32_t pwc_flag) { + flag_status status = RESET; + if ((PWC->ctrlsts & pwc_flag) == RESET) { + status = RESET; + } else { + status = SET; + } + return status; } /** @@ -164,19 +151,15 @@ flag_status pwc_flag_get(uint32_t pwc_flag) * - PWC_SLEEP_ENTER_WFE * @retval none */ -void pwc_sleep_mode_enter(pwc_sleep_enter_type pwc_sleep_enter) -{ - SCB->SCR &= (uint32_t)~0x4; - if(pwc_sleep_enter == PWC_SLEEP_ENTER_WFE) - { - __SEV(); - __WFE(); - __WFE(); - } - else if(pwc_sleep_enter == PWC_SLEEP_ENTER_WFI) - { - __WFI(); - } +void pwc_sleep_mode_enter(pwc_sleep_enter_type pwc_sleep_enter) { + SCB->SCR &= (uint32_t)~0x4; + if (pwc_sleep_enter == PWC_SLEEP_ENTER_WFE) { + __SEV(); + __WFE(); + __WFE(); + } else if (pwc_sleep_enter == PWC_SLEEP_ENTER_WFI) { + __WFI(); + } } /** @@ -187,20 +170,16 @@ void pwc_sleep_mode_enter(pwc_sleep_enter_type pwc_sleep_enter) * - PWC_DEEP_SLEEP_ENTER_WFE * @retval none */ -void pwc_deep_sleep_mode_enter(pwc_deep_sleep_enter_type pwc_deep_sleep_enter) -{ - SCB->SCR |= 0x04; - if(pwc_deep_sleep_enter == PWC_DEEP_SLEEP_ENTER_WFE) - { - __SEV(); - __WFE(); - __WFE(); - } - else if(pwc_deep_sleep_enter == PWC_DEEP_SLEEP_ENTER_WFI) - { - __WFI(); - } - SCB->SCR &= (uint32_t)~0x4; +void pwc_deep_sleep_mode_enter(pwc_deep_sleep_enter_type pwc_deep_sleep_enter) { + SCB->SCR |= 0x04; + if (pwc_deep_sleep_enter == PWC_DEEP_SLEEP_ENTER_WFE) { + __SEV(); + __WFE(); + __WFE(); + } else if (pwc_deep_sleep_enter == PWC_DEEP_SLEEP_ENTER_WFI) { + __WFI(); + } + SCB->SCR &= (uint32_t)~0x4; } /** @@ -211,9 +190,8 @@ void pwc_deep_sleep_mode_enter(pwc_deep_sleep_enter_type pwc_deep_sleep_enter) * - PWC_REGULATOR_LOW_POWER * @retval none */ -void pwc_voltage_regulate_set(pwc_regulator_type pwc_regulator) -{ - PWC->ctrl_bit.vrsel = pwc_regulator; +void pwc_voltage_regulate_set(pwc_regulator_type pwc_regulator) { + PWC->ctrl_bit.vrsel = pwc_regulator; } /** @@ -221,18 +199,16 @@ void pwc_voltage_regulate_set(pwc_regulator_type pwc_regulator) * @param none * @retval none */ -void pwc_standby_mode_enter(void) -{ - PWC->ctrl_bit.clswef = TRUE; - PWC->ctrl_bit.lpsel = TRUE; - SCB->SCR |= 0x04; +void pwc_standby_mode_enter(void) { + PWC->ctrl_bit.clswef = TRUE; + PWC->ctrl_bit.lpsel = TRUE; + SCB->SCR |= 0x04; #if defined (__CC_ARM) - __force_stores(); + __force_stores(); #endif - while(1) - { - __WFI(); - } + while (1) { + __WFI(); + } } /** diff --git a/armlib/at32_sys/drivers/src/at32f435_437_qspi.c b/armlib/at32_sys/drivers/src/at32f435_437_qspi.c index d7efa567f..9f71a1cb2 100644 --- a/armlib/at32_sys/drivers/src/at32f435_437_qspi.c +++ b/armlib/at32_sys/drivers/src/at32f435_437_qspi.c @@ -48,18 +48,14 @@ * QSPI1,QSPI2. * @retval none */ -void qspi_reset(qspi_type* qspi_x) -{ - if(qspi_x == QSPI1) - { - crm_periph_reset(CRM_QSPI1_PERIPH_RESET, TRUE); - crm_periph_reset(CRM_QSPI1_PERIPH_RESET, FALSE); - } - else if(qspi_x == QSPI2) - { - crm_periph_reset(CRM_QSPI2_PERIPH_RESET, TRUE); - crm_periph_reset(CRM_QSPI2_PERIPH_RESET, FALSE); - } +void qspi_reset(qspi_type *qspi_x) { + if (qspi_x == QSPI1) { + crm_periph_reset(CRM_QSPI1_PERIPH_RESET, TRUE); + crm_periph_reset(CRM_QSPI1_PERIPH_RESET, FALSE); + } else if (qspi_x == QSPI2) { + crm_periph_reset(CRM_QSPI2_PERIPH_RESET, TRUE); + crm_periph_reset(CRM_QSPI2_PERIPH_RESET, FALSE); + } } /** @@ -71,9 +67,8 @@ void qspi_reset(qspi_type* qspi_x) * @param new_state (TRUE or FALSE) * @retval none */ -void qspi_encryption_enable(qspi_type* qspi_x, confirm_state new_state) -{ - qspi_x->ctrl_bit.keyen = new_state; +void qspi_encryption_enable(qspi_type *qspi_x, confirm_state new_state) { + qspi_x->ctrl_bit.keyen = new_state; } /** @@ -88,9 +83,8 @@ void qspi_encryption_enable(qspi_type* qspi_x, confirm_state new_state) * - QSPI_SCK_MODE_3 * @retval none */ -void qspi_sck_mode_set(qspi_type* qspi_x, qspi_clk_mode_type new_mode) -{ - qspi_x->ctrl_bit.sckmode = new_mode; +void qspi_sck_mode_set(qspi_type *qspi_x, qspi_clk_mode_type new_mode) { + qspi_x->ctrl_bit.sckmode = new_mode; } /** @@ -111,9 +105,8 @@ void qspi_sck_mode_set(qspi_type* qspi_x, qspi_clk_mode_type new_mode) * - QSPI_CLK_DIV_12 * @retval none */ -void qspi_clk_division_set(qspi_type* qspi_x, qspi_clk_div_type new_clkdiv) -{ - qspi_x->ctrl_bit.clkdiv = new_clkdiv; +void qspi_clk_division_set(qspi_type *qspi_x, qspi_clk_div_type new_clkdiv) { + qspi_x->ctrl_bit.clkdiv = new_clkdiv; } /** @@ -128,9 +121,8 @@ void qspi_clk_division_set(qspi_type* qspi_x, qspi_clk_div_type new_clkdiv) * FALSE: enable cache * @retval none */ -void qspi_xip_cache_bypass_set(qspi_type* qspi_x, confirm_state new_state) -{ - qspi_x->xip_cmd_w3_bit.bypassc = new_state; +void qspi_xip_cache_bypass_set(qspi_type *qspi_x, confirm_state new_state) { + qspi_x->xip_cmd_w3_bit.bypassc = new_state; } /** @@ -142,9 +134,8 @@ void qspi_xip_cache_bypass_set(qspi_type* qspi_x, confirm_state new_state) * @param new_state (TRUE or FALSE) * @retval none */ -void qspi_interrupt_enable(qspi_type* qspi_x, confirm_state new_state) -{ - qspi_x->ctrl2_bit.cmdie = new_state; +void qspi_interrupt_enable(qspi_type *qspi_x, confirm_state new_state) { + qspi_x->ctrl2_bit.cmdie = new_state; } /** @@ -159,24 +150,22 @@ void qspi_interrupt_enable(qspi_type* qspi_x, confirm_state new_state) * - QSPI_CMDSTS_FLAG * @retval the new state of the flag (SET or RESET). */ -flag_status qspi_flag_get(qspi_type* qspi_x, uint32_t flag) -{ - flag_status bit_status = RESET; - switch(flag) - { - case QSPI_RXFIFORDY_FLAG: - bit_status = (flag_status)qspi_x->fifosts_bit.rxfifordy; - break; - case QSPI_TXFIFORDY_FLAG: - bit_status = (flag_status)qspi_x->fifosts_bit.txfifordy; - break; - case QSPI_CMDSTS_FLAG: - bit_status = (flag_status)qspi_x->cmdsts_bit.cmdsts; - break; - default: - break; - } - return bit_status; +flag_status qspi_flag_get(qspi_type *qspi_x, uint32_t flag) { + flag_status bit_status = RESET; + switch (flag) { + case QSPI_RXFIFORDY_FLAG: + bit_status = (flag_status)qspi_x->fifosts_bit.rxfifordy; + break; + case QSPI_TXFIFORDY_FLAG: + bit_status = (flag_status)qspi_x->fifosts_bit.txfifordy; + break; + case QSPI_CMDSTS_FLAG: + bit_status = (flag_status)qspi_x->cmdsts_bit.cmdsts; + break; + default: + break; + } + return bit_status; } /** @@ -187,14 +176,13 @@ flag_status qspi_flag_get(qspi_type* qspi_x, uint32_t flag) * @param flag: only QSPI_CMDSTS_FLAG valid. * @retval the new state of the flag (SET or RESET). */ -flag_status qspi_interrupt_flag_get(qspi_type* qspi_x, uint32_t flag) -{ - if(QSPI_CMDSTS_FLAG != flag) - return RESET; - if(qspi_x->cmdsts_bit.cmdsts && qspi_x->ctrl2_bit.cmdie) - return SET; - else - return RESET; +flag_status qspi_interrupt_flag_get(qspi_type *qspi_x, uint32_t flag) { + if (QSPI_CMDSTS_FLAG != flag) + return RESET; + if (qspi_x->cmdsts_bit.cmdsts && qspi_x->ctrl2_bit.cmdie) + return SET; + else + return RESET; } /** @@ -207,9 +195,8 @@ flag_status qspi_interrupt_flag_get(qspi_type* qspi_x, uint32_t flag) * - QSPI_CMDSTS_FLAG * @retval none */ -void qspi_flag_clear(qspi_type* qspi_x, uint32_t flag) -{ - qspi_x->cmdsts = flag; +void qspi_flag_clear(qspi_type *qspi_x, uint32_t flag) { + qspi_x->cmdsts = flag; } /** @@ -225,9 +212,8 @@ void qspi_flag_clear(qspi_type* qspi_x, uint32_t flag) * - QSPI_DMA_FIFO_THOD_WORD24 * @retval none */ -void qspi_dma_rx_threshold_set(qspi_type* qspi_x, qspi_dma_fifo_thod_type new_threshold) -{ - qspi_x->ctrl2_bit.rxfifo_thod = new_threshold; +void qspi_dma_rx_threshold_set(qspi_type *qspi_x, qspi_dma_fifo_thod_type new_threshold) { + qspi_x->ctrl2_bit.rxfifo_thod = new_threshold; } /** @@ -243,9 +229,8 @@ void qspi_dma_rx_threshold_set(qspi_type* qspi_x, qspi_dma_fifo_thod_type new_th * - QSPI_DMA_FIFO_THOD_WORD24 * @retval none */ -void qspi_dma_tx_threshold_set(qspi_type* qspi_x, qspi_dma_fifo_thod_type new_threshold) -{ - qspi_x->ctrl2_bit.txfifo_thod = new_threshold; +void qspi_dma_tx_threshold_set(qspi_type *qspi_x, qspi_dma_fifo_thod_type new_threshold) { + qspi_x->ctrl2_bit.txfifo_thod = new_threshold; } /** @@ -257,9 +242,8 @@ void qspi_dma_tx_threshold_set(qspi_type* qspi_x, qspi_dma_fifo_thod_type new_th * @param new_state (TRUE or FALSE) * @retval none */ -void qspi_dma_enable(qspi_type* qspi_x, confirm_state new_state) -{ - qspi_x->ctrl2_bit.dmaen = new_state; +void qspi_dma_enable(qspi_type *qspi_x, confirm_state new_state) { + qspi_x->ctrl2_bit.dmaen = new_state; } /** @@ -280,9 +264,8 @@ void qspi_dma_enable(qspi_type* qspi_x, confirm_state new_state) * - QSPI_BUSY_OFFSET_7 * @retval none */ -void qspi_busy_config(qspi_type* qspi_x, qspi_busy_pos_type busy_pos) -{ - qspi_x->ctrl_bit.busy = busy_pos; +void qspi_busy_config(qspi_type *qspi_x, qspi_busy_pos_type busy_pos) { + qspi_x->ctrl_bit.busy = busy_pos; } /** @@ -293,48 +276,43 @@ void qspi_busy_config(qspi_type* qspi_x, qspi_busy_pos_type busy_pos) * @param new_state (TRUE or FALSE) * @retval none */ -void qspi_xip_enable(qspi_type* qspi_x, confirm_state new_state) -{ - register uint16_t dly=0; - /* skip if state is no change */ - if(new_state == (confirm_state)(qspi_x->ctrl_bit.xipsel)) - { - return; - } +void qspi_xip_enable(qspi_type *qspi_x, confirm_state new_state) { + register uint16_t dly = 0; + /* skip if state is no change */ + if (new_state == (confirm_state)(qspi_x->ctrl_bit.xipsel)) { + return; + } - /* wait until tx fifo is empty*/ - while(qspi_x->fifosts_bit.txfifordy == 0); + /* wait until tx fifo is empty*/ + while (qspi_x->fifosts_bit.txfifordy == 0); - /* make sure IO is transmitted */ - dly = 64; - while(dly--) - { - __NOP(); - } - - /* flush and reset qspi state */ - qspi_x->ctrl_bit.xiprcmdf = 1; + /* make sure IO is transmitted */ + dly = 64; + while (dly--) { + __NOP(); + } - /* wait until action is finished */ - while(qspi_x->ctrl_bit.abort); + /* flush and reset qspi state */ + qspi_x->ctrl_bit.xiprcmdf = 1; - /* make sure IO is transmitted */ - dly = 64; - while(dly--) - { - __NOP(); - } - /* set xip mode to new state */ - qspi_x->ctrl_bit.xipsel = new_state; + /* wait until action is finished */ + while (qspi_x->ctrl_bit.abort); - /* wait until abort is not set */ - while(qspi_x->ctrl_bit.abort); + /* make sure IO is transmitted */ + dly = 64; + while (dly--) { + __NOP(); + } + /* set xip mode to new state */ + qspi_x->ctrl_bit.xipsel = new_state; - /* wait until cache status valid*/ - if(new_state == TRUE) - { - while( qspi_x->xip_cmd_w3_bit.csts ); - } + /* wait until abort is not set */ + while (qspi_x->ctrl_bit.abort); + + /* wait until cache status valid*/ + if (new_state == TRUE) { + while (qspi_x->xip_cmd_w3_bit.csts); + } } /** @@ -345,31 +323,30 @@ void qspi_xip_enable(qspi_type* qspi_x, confirm_state new_state) * @param qspi_cmd_struct: pointer to qspi cmd structure * @retval none */ -void qspi_cmd_operation_kick(qspi_type* qspi_x, qspi_cmd_type* qspi_cmd_struct) -{ - uint32_t w1_val = 0, w3_val = 0; +void qspi_cmd_operation_kick(qspi_type *qspi_x, qspi_cmd_type *qspi_cmd_struct) { + uint32_t w1_val = 0, w3_val = 0; - /* config analyse cmd_w0 register */ - qspi_x->cmd_w0 = (uint32_t)qspi_cmd_struct->address_code; + /* config analyse cmd_w0 register */ + qspi_x->cmd_w0 = (uint32_t)qspi_cmd_struct->address_code; - /* config analyse cmd_w1 register */ - w1_val = (uint32_t)qspi_cmd_struct->address_length; - w1_val |= (uint32_t)(qspi_cmd_struct->second_dummy_cycle_num << 16); - w1_val |= (uint32_t)(qspi_cmd_struct->instruction_length << 24); - w1_val |= (uint32_t)(qspi_cmd_struct->pe_mode_enable << 28); - qspi_x->cmd_w1 = w1_val; + /* config analyse cmd_w1 register */ + w1_val = (uint32_t)qspi_cmd_struct->address_length; + w1_val |= (uint32_t)(qspi_cmd_struct->second_dummy_cycle_num << 16); + w1_val |= (uint32_t)(qspi_cmd_struct->instruction_length << 24); + w1_val |= (uint32_t)(qspi_cmd_struct->pe_mode_enable << 28); + qspi_x->cmd_w1 = w1_val; - /* config analyse cmd_w2 register */ - qspi_x->cmd_w2 = (uint32_t)qspi_cmd_struct->data_counter; + /* config analyse cmd_w2 register */ + qspi_x->cmd_w2 = (uint32_t)qspi_cmd_struct->data_counter; - /* config analyse cmd_w3 register */ - w3_val = (uint32_t)(qspi_cmd_struct->write_data_enable << 1); - w3_val |= (uint32_t)(qspi_cmd_struct->read_status_enable << 2); - w3_val |= (uint32_t)(qspi_cmd_struct->read_status_config << 3); - w3_val |= (uint32_t)(qspi_cmd_struct->operation_mode << 5); - w3_val |= (uint32_t)(qspi_cmd_struct->pe_mode_operate_code << 16); - w3_val |= (uint32_t)(qspi_cmd_struct->instruction_code << 24); - qspi_x->cmd_w3 = w3_val; + /* config analyse cmd_w3 register */ + w3_val = (uint32_t)(qspi_cmd_struct->write_data_enable << 1); + w3_val |= (uint32_t)(qspi_cmd_struct->read_status_enable << 2); + w3_val |= (uint32_t)(qspi_cmd_struct->read_status_config << 3); + w3_val |= (uint32_t)(qspi_cmd_struct->operation_mode << 5); + w3_val |= (uint32_t)(qspi_cmd_struct->pe_mode_operate_code << 16); + w3_val |= (uint32_t)(qspi_cmd_struct->instruction_code << 24); + qspi_x->cmd_w3 = w3_val; } /** @@ -380,31 +357,30 @@ void qspi_cmd_operation_kick(qspi_type* qspi_x, qspi_cmd_type* qspi_cmd_struct) * @param xip_init_struct: pointer to xip init structure. * @retval none. */ -void qspi_xip_init(qspi_type* qspi_x, qspi_xip_type* xip_init_struct) -{ - uint32_t xc0_val = 0, xc1_val = 0, xc2_val = 0; - /* config analyse xip_cmd_w0 register */ - xc0_val = (uint32_t)xip_init_struct->read_second_dummy_cycle_num; - xc0_val |= (uint32_t)(xip_init_struct->read_operation_mode << 8); - xc0_val |= (uint32_t)(xip_init_struct->read_address_length << 11); - xc0_val |= (uint32_t)(xip_init_struct->read_instruction_code << 12); - qspi_x->xip_cmd_w0 = xc0_val; +void qspi_xip_init(qspi_type *qspi_x, qspi_xip_type *xip_init_struct) { + uint32_t xc0_val = 0, xc1_val = 0, xc2_val = 0; + /* config analyse xip_cmd_w0 register */ + xc0_val = (uint32_t)xip_init_struct->read_second_dummy_cycle_num; + xc0_val |= (uint32_t)(xip_init_struct->read_operation_mode << 8); + xc0_val |= (uint32_t)(xip_init_struct->read_address_length << 11); + xc0_val |= (uint32_t)(xip_init_struct->read_instruction_code << 12); + qspi_x->xip_cmd_w0 = xc0_val; - /* config analyse xip_cmd_w1 register */ - xc1_val = (uint32_t)xip_init_struct->write_second_dummy_cycle_num; - xc1_val |= (uint32_t)(xip_init_struct->write_operation_mode << 8); - xc1_val |= (uint32_t)(xip_init_struct->write_address_length << 11); - xc1_val |= (uint32_t)(xip_init_struct->write_instruction_code << 12); - qspi_x->xip_cmd_w1 = xc1_val; + /* config analyse xip_cmd_w1 register */ + xc1_val = (uint32_t)xip_init_struct->write_second_dummy_cycle_num; + xc1_val |= (uint32_t)(xip_init_struct->write_operation_mode << 8); + xc1_val |= (uint32_t)(xip_init_struct->write_address_length << 11); + xc1_val |= (uint32_t)(xip_init_struct->write_instruction_code << 12); + qspi_x->xip_cmd_w1 = xc1_val; - /* config analyse xip_cmd_w2 register */ - xc2_val = (uint32_t)xip_init_struct->read_data_counter; - xc2_val |= (uint32_t)(xip_init_struct->read_time_counter << 8); - xc2_val |= (uint32_t)(xip_init_struct->read_select_mode << 15); - xc2_val |= (uint32_t)(xip_init_struct->write_data_counter << 16); - xc2_val |= (uint32_t)(xip_init_struct->write_time_counter << 24); - xc2_val |= (uint32_t)(xip_init_struct->write_select_mode << 31); - qspi_x->xip_cmd_w2 = xc2_val; + /* config analyse xip_cmd_w2 register */ + xc2_val = (uint32_t)xip_init_struct->read_data_counter; + xc2_val |= (uint32_t)(xip_init_struct->read_time_counter << 8); + xc2_val |= (uint32_t)(xip_init_struct->read_select_mode << 15); + xc2_val |= (uint32_t)(xip_init_struct->write_data_counter << 16); + xc2_val |= (uint32_t)(xip_init_struct->write_time_counter << 24); + xc2_val |= (uint32_t)(xip_init_struct->write_select_mode << 31); + qspi_x->xip_cmd_w2 = xc2_val; } /** @@ -412,9 +388,8 @@ void qspi_xip_init(qspi_type* qspi_x, qspi_xip_type* xip_init_struct) * @param qspi_x: select the qspi peripheral. * @retval 8-bit data. */ -uint8_t qspi_byte_read(qspi_type* qspi_x) -{ - return qspi_x->dt_u8; +uint8_t qspi_byte_read(qspi_type *qspi_x) { + return qspi_x->dt_u8; } /** @@ -422,9 +397,8 @@ uint8_t qspi_byte_read(qspi_type* qspi_x) * @param qspi_x: select the qspi peripheral. * @retval 16-bit data. */ -uint16_t qspi_half_word_read(qspi_type* qspi_x) -{ - return qspi_x->dt_u16; +uint16_t qspi_half_word_read(qspi_type *qspi_x) { + return qspi_x->dt_u16; } /** @@ -432,9 +406,8 @@ uint16_t qspi_half_word_read(qspi_type* qspi_x) * @param qspi_x: select the qspi peripheral. * @retval 32-bit data. */ -uint32_t qspi_word_read(qspi_type* qspi_x) -{ - return qspi_x->dt; +uint32_t qspi_word_read(qspi_type *qspi_x) { + return qspi_x->dt; } /** @@ -443,9 +416,8 @@ uint32_t qspi_word_read(qspi_type* qspi_x) * @param value: 8-bit data. * @retval none. */ -void qspi_byte_write(qspi_type* qspi_x, uint8_t value) -{ - qspi_x->dt_u8 = value; +void qspi_byte_write(qspi_type *qspi_x, uint8_t value) { + qspi_x->dt_u8 = value; } /** @@ -454,9 +426,8 @@ void qspi_byte_write(qspi_type* qspi_x, uint8_t value) * @param value: 16-bit data. * @retval none. */ -void qspi_half_word_write(qspi_type* qspi_x, uint16_t value) -{ - qspi_x->dt_u16 = value; +void qspi_half_word_write(qspi_type *qspi_x, uint16_t value) { + qspi_x->dt_u16 = value; } /** @@ -465,9 +436,8 @@ void qspi_half_word_write(qspi_type* qspi_x, uint16_t value) * @param value: 32-bit data. * @retval none. */ -void qspi_word_write(qspi_type* qspi_x, uint32_t value) -{ - qspi_x->dt = value; +void qspi_word_write(qspi_type *qspi_x, uint32_t value) { + qspi_x->dt = value; } /** @@ -475,13 +445,12 @@ void qspi_word_write(qspi_type* qspi_x, uint32_t value) * @param qspi_x: select the qspi peripheral. * @retval none. */ -void qspi_auto_ispc_enable(qspi_type* qspi_x) -{ - qspi_x->ctrl3_bit.ispc = TRUE; - if(qspi_x == QSPI1) - qspi_x->ctrl3_bit.ispd = 56; - else if(qspi_x == QSPI2) - qspi_x->ctrl3_bit.ispd = 50; +void qspi_auto_ispc_enable(qspi_type *qspi_x) { + qspi_x->ctrl3_bit.ispc = TRUE; + if (qspi_x == QSPI1) + qspi_x->ctrl3_bit.ispd = 56; + else if (qspi_x == QSPI2) + qspi_x->ctrl3_bit.ispd = 50; } /** diff --git a/armlib/at32_sys/drivers/src/at32f435_437_scfg.c b/armlib/at32_sys/drivers/src/at32f435_437_scfg.c index dab20b40c..816ada74d 100644 --- a/armlib/at32_sys/drivers/src/at32f435_437_scfg.c +++ b/armlib/at32_sys/drivers/src/at32f435_437_scfg.c @@ -46,10 +46,9 @@ * @param none * @retval none */ -void scfg_reset(void) -{ - crm_periph_reset(CRM_SCFG_PERIPH_RESET, TRUE); - crm_periph_reset(CRM_SCFG_PERIPH_RESET, FALSE); +void scfg_reset(void) { + crm_periph_reset(CRM_SCFG_PERIPH_RESET, TRUE); + crm_periph_reset(CRM_SCFG_PERIPH_RESET, FALSE); } /** @@ -62,9 +61,8 @@ void scfg_reset(void) * - SCFG_XMC_SWAP_MODE3 * @retval none */ -void scfg_xmc_mapping_swap_set(scfg_xmc_swap_type xmc_swap) -{ - SCFG->cfg1_bit.swap_xmc = xmc_swap; +void scfg_xmc_mapping_swap_set(scfg_xmc_swap_type xmc_swap) { + SCFG->cfg1_bit.swap_xmc = xmc_swap; } /** @@ -78,10 +76,9 @@ void scfg_xmc_mapping_swap_set(scfg_xmc_swap_type xmc_swap) * - SCFG_IR_POLARITY_REVERSE * @retval none */ -void scfg_infrared_config(scfg_ir_source_type source, scfg_ir_polarity_type polarity) -{ - SCFG->cfg1_bit.ir_src_sel = source; - SCFG->cfg1_bit.ir_pol = polarity; +void scfg_infrared_config(scfg_ir_source_type source, scfg_ir_polarity_type polarity) { + SCFG->cfg1_bit.ir_src_sel = source; + SCFG->cfg1_bit.ir_pol = polarity; } /** @@ -95,9 +92,8 @@ void scfg_infrared_config(scfg_ir_source_type source, scfg_ir_polarity_type pola * - SCFG_MEM_MAP_XMC_SDRAM_BANK1 * @retval none */ -void scfg_mem_map_set(scfg_mem_map_type mem_map) -{ - SCFG->cfg1_bit.mem_map_sel = mem_map; +void scfg_mem_map_set(scfg_mem_map_type mem_map) { + SCFG->cfg1_bit.mem_map_sel = mem_map; } /** @@ -108,9 +104,8 @@ void scfg_mem_map_set(scfg_mem_map_type mem_map) * - SCFG_EMAC_SELECT_RMII * @retval none */ -void scfg_emac_interface_set(scfg_emac_interface_type mode) -{ - SCFG->cfg2_bit.mii_rmii_sel = mode; +void scfg_emac_interface_set(scfg_emac_interface_type mode) { + SCFG->cfg2_bit.mii_rmii_sel = mode; } /** @@ -147,32 +142,30 @@ void scfg_emac_interface_set(scfg_emac_interface_type mode) * - SCFG_PINS_SOURCE15 * @retval none */ -void scfg_exint_line_config(scfg_port_source_type port_source, scfg_pins_source_type pin_source) -{ - uint32_t tmp = 0x00; - tmp = ((uint32_t)0x0F) << (0x04 * (pin_source & (uint8_t)0x03)); +void scfg_exint_line_config(scfg_port_source_type port_source, scfg_pins_source_type pin_source) { + uint32_t tmp = 0x00; + tmp = ((uint32_t)0x0F) << (0x04 * (pin_source & (uint8_t)0x03)); - switch (pin_source >> 0x02) - { - case 0: - SCFG->exintc1 &= ~tmp; - SCFG->exintc1 |= (((uint32_t)port_source) << (0x04 * (pin_source & (uint8_t)0x03))); - break; - case 1: - SCFG->exintc2 &= ~tmp; - SCFG->exintc2 |= (((uint32_t)port_source) << (0x04 * (pin_source & (uint8_t)0x03))); - break; - case 2: - SCFG->exintc3 &= ~tmp; - SCFG->exintc3 |= (((uint32_t)port_source) << (0x04 * (pin_source & (uint8_t)0x03))); - break; - case 3: - SCFG->exintc4 &= ~tmp; - SCFG->exintc4 |= (((uint32_t)port_source) << (0x04 * (pin_source & (uint8_t)0x03))); - break; - default: - break; - } + switch (pin_source >> 0x02) { + case 0: + SCFG->exintc1 &= ~tmp; + SCFG->exintc1 |= (((uint32_t)port_source) << (0x04 * (pin_source & (uint8_t)0x03))); + break; + case 1: + SCFG->exintc2 &= ~tmp; + SCFG->exintc2 |= (((uint32_t)port_source) << (0x04 * (pin_source & (uint8_t)0x03))); + break; + case 2: + SCFG->exintc3 &= ~tmp; + SCFG->exintc3 |= (((uint32_t)port_source) << (0x04 * (pin_source & (uint8_t)0x03))); + break; + case 3: + SCFG->exintc4 &= ~tmp; + SCFG->exintc4 |= (((uint32_t)port_source) << (0x04 * (pin_source & (uint8_t)0x03))); + break; + default: + break; + } } /** @@ -191,16 +184,12 @@ void scfg_exint_line_config(scfg_port_source_type port_source, scfg_pins_source_ * @param new_state (TRUE or FALSE) * @retval none */ -void scfg_pins_ultra_driven_enable(scfg_ultra_driven_pins_type value, confirm_state new_state) -{ - if(TRUE == new_state) - { - SCFG_REG(value) |= SCFG_REG_BIT(value); - } - else - { - SCFG_REG(value) &= ~(SCFG_REG_BIT(value)); - } +void scfg_pins_ultra_driven_enable(scfg_ultra_driven_pins_type value, confirm_state new_state) { + if (TRUE == new_state) { + SCFG_REG(value) |= SCFG_REG_BIT(value); + } else { + SCFG_REG(value) &= ~(SCFG_REG_BIT(value)); + } } /** diff --git a/armlib/at32_sys/drivers/src/at32f435_437_sdio.c b/armlib/at32_sys/drivers/src/at32f435_437_sdio.c index 24f622e83..58b4cda1d 100644 --- a/armlib/at32_sys/drivers/src/at32f435_437_sdio.c +++ b/armlib/at32_sys/drivers/src/at32f435_437_sdio.c @@ -47,17 +47,16 @@ * SDIO1, SDIO2. * @retval none */ -void sdio_reset(sdio_type *sdio_x) -{ - sdio_x->pwrctrl = 0x0; - sdio_x->clkctrl = 0x0; - sdio_x->argu = 0x0; - sdio_x->cmdctrl = 0x0; - sdio_x->dttmr = 0x0; - sdio_x->dtlen = 0x0; - sdio_x->dtctrl = 0x0; - sdio_x->inten = 0x0; - sdio_x->intclr = 0x004007FF; +void sdio_reset(sdio_type *sdio_x) { + sdio_x->pwrctrl = 0x0; + sdio_x->clkctrl = 0x0; + sdio_x->argu = 0x0; + sdio_x->cmdctrl = 0x0; + sdio_x->dttmr = 0x0; + sdio_x->dtlen = 0x0; + sdio_x->dtctrl = 0x0; + sdio_x->inten = 0x0; + sdio_x->intclr = 0x004007FF; } /** @@ -71,9 +70,8 @@ void sdio_reset(sdio_type *sdio_x) * - SDIO_POWER_ON * @retval none */ -void sdio_power_set(sdio_type *sdio_x, sdio_power_state_type power_state) -{ - sdio_x->pwrctrl_bit.ps = power_state; +void sdio_power_set(sdio_type *sdio_x, sdio_power_state_type power_state) { + sdio_x->pwrctrl_bit.ps = power_state; } /** @@ -83,9 +81,8 @@ void sdio_power_set(sdio_type *sdio_x, sdio_power_state_type power_state) * SDIO1, SDIO2. * @retval sdio_power_state_type (SDIO_POWER_ON or SDIO_POWER_OFF) */ -sdio_power_state_type sdio_power_status_get(sdio_type *sdio_x) -{ - return (sdio_power_state_type)(sdio_x->pwrctrl_bit.ps); +sdio_power_state_type sdio_power_status_get(sdio_type *sdio_x) { + return (sdio_power_state_type)(sdio_x->pwrctrl_bit.ps); } /** @@ -100,16 +97,15 @@ sdio_power_state_type sdio_power_status_get(sdio_type *sdio_x) * - SDIO_CLOCK_EDGE_FALLING * @retval none */ -void sdio_clock_config(sdio_type *sdio_x, uint16_t clk_div, sdio_edge_phase_type clk_edg) -{ - /* config clock edge */ - sdio_x->clkctrl_bit.clkegs = clk_edg; +void sdio_clock_config(sdio_type *sdio_x, uint16_t clk_div, sdio_edge_phase_type clk_edg) { + /* config clock edge */ + sdio_x->clkctrl_bit.clkegs = clk_edg; - /* config clock divide [7:0] */ - sdio_x->clkctrl_bit.clkdiv_l = (clk_div & 0xFF); + /* config clock divide [7:0] */ + sdio_x->clkctrl_bit.clkdiv_l = (clk_div & 0xFF); - /* config clock divide [9:8] */ - sdio_x->clkctrl_bit.clkdiv_h = ((clk_div & 0x300) >> 8); + /* config clock divide [9:8] */ + sdio_x->clkctrl_bit.clkdiv_h = ((clk_div & 0x300) >> 8); } /** @@ -124,9 +120,8 @@ void sdio_clock_config(sdio_type *sdio_x, uint16_t clk_div, sdio_edge_phase_type * - SDIO_BUS_WIDTH_D8 * @retval none */ -void sdio_bus_width_config(sdio_type *sdio_x, sdio_bus_width_type width) -{ - sdio_x->clkctrl_bit.busws = width; +void sdio_bus_width_config(sdio_type *sdio_x, sdio_bus_width_type width) { + sdio_x->clkctrl_bit.busws = width; } /** @@ -137,9 +132,8 @@ void sdio_bus_width_config(sdio_type *sdio_x, sdio_bus_width_type width) * @param new_state (TRUE or FALSE) * @retval none */ -void sdio_clock_bypass(sdio_type *sdio_x, confirm_state new_state) -{ - sdio_x->clkctrl_bit.bypsen = new_state; +void sdio_clock_bypass(sdio_type *sdio_x, confirm_state new_state) { + sdio_x->clkctrl_bit.bypsen = new_state; } /** @@ -151,9 +145,8 @@ void sdio_clock_bypass(sdio_type *sdio_x, confirm_state new_state) * @param new_state (TRUE or FALSE) * @retval none */ -void sdio_power_saving_mode_enable(sdio_type *sdio_x, confirm_state new_state) -{ - sdio_x->clkctrl_bit.pwrsven = new_state; +void sdio_power_saving_mode_enable(sdio_type *sdio_x, confirm_state new_state) { + sdio_x->clkctrl_bit.pwrsven = new_state; } /** @@ -164,9 +157,8 @@ void sdio_power_saving_mode_enable(sdio_type *sdio_x, confirm_state new_state) * @param new_state (TRUE or FALSE) * @retval none */ -void sdio_flow_control_enable(sdio_type *sdio_x, confirm_state new_state) -{ - sdio_x->clkctrl_bit.hfcen = new_state; +void sdio_flow_control_enable(sdio_type *sdio_x, confirm_state new_state) { + sdio_x->clkctrl_bit.hfcen = new_state; } /** @@ -177,9 +169,8 @@ void sdio_flow_control_enable(sdio_type *sdio_x, confirm_state new_state) * @param new_state (TRUE or FALSE) * @retval none */ -void sdio_clock_enable(sdio_type *sdio_x, confirm_state new_state) -{ - sdio_x->clkctrl_bit.clkoen = new_state; +void sdio_clock_enable(sdio_type *sdio_x, confirm_state new_state) { + sdio_x->clkctrl_bit.clkoen = new_state; } /** @@ -190,9 +181,8 @@ void sdio_clock_enable(sdio_type *sdio_x, confirm_state new_state) * @param new_state (TRUE or FALSE) * @retval none */ -void sdio_dma_enable(sdio_type *sdio_x, confirm_state new_state) -{ - sdio_x->dtctrl_bit.dmaen = new_state; +void sdio_dma_enable(sdio_type *sdio_x, confirm_state new_state) { + sdio_x->dtctrl_bit.dmaen = new_state; } /** @@ -228,18 +218,15 @@ void sdio_dma_enable(sdio_type *sdio_x, confirm_state new_state) * @param new_state (TRUE or FALSE) * @retval none */ -void sdio_interrupt_enable(sdio_type *sdio_x, uint32_t int_opt, confirm_state new_state) -{ - /* enable interrupt */ - if(TRUE == new_state) - { - sdio_x->inten |= int_opt; - } - /* disable interrupt */ - else - { - sdio_x->inten &= ~(int_opt); - } +void sdio_interrupt_enable(sdio_type *sdio_x, uint32_t int_opt, confirm_state new_state) { + /* enable interrupt */ + if (TRUE == new_state) { + sdio_x->inten |= int_opt; + } + /* disable interrupt */ + else { + sdio_x->inten &= ~(int_opt); + } } /** @@ -274,16 +261,14 @@ void sdio_interrupt_enable(sdio_type *sdio_x, uint32_t int_opt, confirm_state n * - SDIO_SDIOIF_FLAG * @retval flag_status (SET or RESET) */ -flag_status sdio_interrupt_flag_get(sdio_type *sdio_x, uint32_t flag) -{ - flag_status status = RESET; +flag_status sdio_interrupt_flag_get(sdio_type *sdio_x, uint32_t flag) { + flag_status status = RESET; - if((sdio_x->inten & flag) && (sdio_x->sts & flag)) - { - status = SET; - } + if ((sdio_x->inten & flag) && (sdio_x->sts & flag)) { + status = SET; + } - return status; + return status; } /** @@ -318,20 +303,16 @@ flag_status sdio_interrupt_flag_get(sdio_type *sdio_x, uint32_t flag) * - SDIO_SDIOIF_FLAG * @retval flag_status (SET or RESET) */ -flag_status sdio_flag_get(sdio_type *sdio_x, uint32_t flag) -{ - flag_status status = RESET; +flag_status sdio_flag_get(sdio_type *sdio_x, uint32_t flag) { + flag_status status = RESET; - if((sdio_x->sts & flag) == flag) - { - status = SET; - } - else - { - status = RESET; - } + if ((sdio_x->sts & flag) == flag) { + status = SET; + } else { + status = RESET; + } - return status; + return status; } /** @@ -355,9 +336,8 @@ flag_status sdio_flag_get(sdio_type *sdio_x, uint32_t flag) * - SDIO_SDIOIF_FLAG * @retval none */ -void sdio_flag_clear(sdio_type *sdio_x, uint32_t flag) -{ - sdio_x->intclr = flag; +void sdio_flag_clear(sdio_type *sdio_x, uint32_t flag) { + sdio_x->intclr = flag; } /** @@ -369,19 +349,18 @@ void sdio_flag_clear(sdio_type *sdio_x, uint32_t flag) * that contains the configuration information for the sdio command. * @retval none */ -void sdio_command_config(sdio_type *sdio_x, sdio_command_struct_type *command_struct) -{ - /* disable command path state machine */ - sdio_x->cmdctrl_bit.ccsmen = FALSE; +void sdio_command_config(sdio_type *sdio_x, sdio_command_struct_type *command_struct) { + /* disable command path state machine */ + sdio_x->cmdctrl_bit.ccsmen = FALSE; - /* config command argument */ - sdio_x->argu = command_struct->argument; + /* config command argument */ + sdio_x->argu = command_struct->argument; - /* config command register */ - sdio_x->cmdctrl_bit.cmdidx = command_struct->cmd_index; - sdio_x->cmdctrl_bit.rspwt = command_struct->rsp_type; - sdio_x->cmdctrl_bit.intwt = (command_struct->wait_type & 0x1); /* [1:0] -> [0] */ - sdio_x->cmdctrl_bit.pndwt = (command_struct->wait_type & 0x2)>>1; /* [1:0] -> [1] */ + /* config command register */ + sdio_x->cmdctrl_bit.cmdidx = command_struct->cmd_index; + sdio_x->cmdctrl_bit.rspwt = command_struct->rsp_type; + sdio_x->cmdctrl_bit.intwt = (command_struct->wait_type & 0x1); /* [1:0] -> [0] */ + sdio_x->cmdctrl_bit.pndwt = (command_struct->wait_type & 0x2) >> 1; /* [1:0] -> [1] */ } /** @@ -392,9 +371,8 @@ void sdio_command_config(sdio_type *sdio_x, sdio_command_struct_type *command_st * @param new_state (TRUE or FALSE) * @retval none */ -void sdio_command_state_machine_enable(sdio_type *sdio_x, confirm_state new_state) -{ - sdio_x->cmdctrl_bit.ccsmen = new_state; +void sdio_command_state_machine_enable(sdio_type *sdio_x, confirm_state new_state) { + sdio_x->cmdctrl_bit.ccsmen = new_state; } /** @@ -405,9 +383,8 @@ void sdio_command_state_machine_enable(sdio_type *sdio_x, confirm_state new_stat * @param new_state (TRUE or FALSE) * @retval uint8_t: command index */ -uint8_t sdio_command_response_get(sdio_type *sdio_x) -{ - return sdio_x->rspcmd_bit.rspcmd; +uint8_t sdio_command_response_get(sdio_type *sdio_x) { + return sdio_x->rspcmd_bit.rspcmd; } /** @@ -423,28 +400,27 @@ uint8_t sdio_command_response_get(sdio_type *sdio_x) * - SDIO_RSP4_INDEX * @retval uint32_t: response register value */ -uint32_t sdio_response_get(sdio_type *sdio_x, sdio_rsp_index_type reg_index) -{ - uint32_t response_value = 0; +uint32_t sdio_response_get(sdio_type *sdio_x, sdio_rsp_index_type reg_index) { + uint32_t response_value = 0; - switch(reg_index) - { - case SDIO_RSP1_INDEX: - response_value = sdio_x->rsp1; - break; - case SDIO_RSP2_INDEX: - response_value = sdio_x->rsp2; - break; - case SDIO_RSP3_INDEX: - response_value = sdio_x->rsp3; - break; - case SDIO_RSP4_INDEX: - response_value = sdio_x->rsp4; - break; - default: break; - } + switch (reg_index) { + case SDIO_RSP1_INDEX: + response_value = sdio_x->rsp1; + break; + case SDIO_RSP2_INDEX: + response_value = sdio_x->rsp2; + break; + case SDIO_RSP3_INDEX: + response_value = sdio_x->rsp3; + break; + case SDIO_RSP4_INDEX: + response_value = sdio_x->rsp4; + break; + default: + break; + } - return response_value; + return response_value; } /** @@ -456,21 +432,20 @@ uint32_t sdio_response_get(sdio_type *sdio_x, sdio_rsp_index_type reg_index) * that contains the configuration information for the sdio data. * @retval none */ -void sdio_data_config(sdio_type *sdio_x, sdio_data_struct_type *data_struct) -{ - /* disable data path state machine */ - sdio_x->dtctrl_bit.tfren = FALSE; +void sdio_data_config(sdio_type *sdio_x, sdio_data_struct_type *data_struct) { + /* disable data path state machine */ + sdio_x->dtctrl_bit.tfren = FALSE; - /* config data block, transfer mode and transfer direction */ - sdio_x->dtctrl_bit.blksize = data_struct->block_size; - sdio_x->dtctrl_bit.tfrdir = data_struct->transfer_direction; - sdio_x->dtctrl_bit.tfrmode = data_struct->transfer_mode; + /* config data block, transfer mode and transfer direction */ + sdio_x->dtctrl_bit.blksize = data_struct->block_size; + sdio_x->dtctrl_bit.tfrdir = data_struct->transfer_direction; + sdio_x->dtctrl_bit.tfrmode = data_struct->transfer_mode; - /* config data length */ - sdio_x->dtlen_bit.dtlen = data_struct->data_length; + /* config data length */ + sdio_x->dtlen_bit.dtlen = data_struct->data_length; - /* config data transfer timeout */ - sdio_x->dttmr_bit.timeout = data_struct->timeout; + /* config data transfer timeout */ + sdio_x->dttmr_bit.timeout = data_struct->timeout; } /** @@ -481,9 +456,8 @@ void sdio_data_config(sdio_type *sdio_x, sdio_data_struct_type *data_struct) * @param new_state (TRUE or FALSE) * @retval none */ -void sdio_data_state_machine_enable(sdio_type *sdio_x, confirm_state new_state) -{ - sdio_x->dtctrl_bit.tfren = new_state; +void sdio_data_state_machine_enable(sdio_type *sdio_x, confirm_state new_state) { + sdio_x->dtctrl_bit.tfren = new_state; } /** @@ -493,9 +467,8 @@ void sdio_data_state_machine_enable(sdio_type *sdio_x, confirm_state new_state) * SDIO1, SDIO2. * @retval uint32_t: number of bytes */ -uint32_t sdio_data_counter_get(sdio_type *sdio_x) -{ - return sdio_x->dtcnt; +uint32_t sdio_data_counter_get(sdio_type *sdio_x) { + return sdio_x->dtcnt; } /** @@ -505,9 +478,8 @@ uint32_t sdio_data_counter_get(sdio_type *sdio_x) * SDIO1, SDIO2. * @retval uint32_t: data received */ -uint32_t sdio_data_read(sdio_type *sdio_x) -{ - return sdio_x->buf; +uint32_t sdio_data_read(sdio_type *sdio_x) { + return sdio_x->buf; } /** @@ -517,9 +489,8 @@ uint32_t sdio_data_read(sdio_type *sdio_x) * SDIO1, SDIO2. * @retval uint32_t: number of words */ -uint32_t sdio_buffer_counter_get(sdio_type *sdio_x) -{ - return sdio_x->bufcnt; +uint32_t sdio_buffer_counter_get(sdio_type *sdio_x) { + return sdio_x->bufcnt; } /** @@ -530,9 +501,8 @@ uint32_t sdio_buffer_counter_get(sdio_type *sdio_x) * @param data: data to be transferred. * @retval none */ -void sdio_data_write(sdio_type *sdio_x, uint32_t data) -{ - sdio_x->buf = data; +void sdio_data_write(sdio_type *sdio_x, uint32_t data) { + sdio_x->buf = data; } /** @@ -546,9 +516,8 @@ void sdio_data_write(sdio_type *sdio_x, uint32_t data) * - SDIO_READ_WAIT_CONTROLLED_BY_CK * @retval none */ -void sdio_read_wait_mode_set(sdio_type *sdio_x, sdio_read_wait_mode_type mode) -{ - sdio_x->dtctrl_bit.rdwtmode = mode; +void sdio_read_wait_mode_set(sdio_type *sdio_x, sdio_read_wait_mode_type mode) { + sdio_x->dtctrl_bit.rdwtmode = mode; } /** @@ -559,9 +528,8 @@ void sdio_read_wait_mode_set(sdio_type *sdio_x, sdio_read_wait_mode_type mode) * @param new_state (TRUE or FALSE) * @retval none */ -void sdio_read_wait_start(sdio_type *sdio_x, confirm_state new_state) -{ - sdio_x->dtctrl_bit.rdwtstart = new_state; +void sdio_read_wait_start(sdio_type *sdio_x, confirm_state new_state) { + sdio_x->dtctrl_bit.rdwtstart = new_state; } /** @@ -572,9 +540,8 @@ void sdio_read_wait_start(sdio_type *sdio_x, confirm_state new_state) * @param new_state (TRUE or FALSE) * @retval none */ -void sdio_read_wait_stop(sdio_type *sdio_x, confirm_state new_state) -{ - sdio_x->dtctrl_bit.rdwtstop = new_state; +void sdio_read_wait_stop(sdio_type *sdio_x, confirm_state new_state) { + sdio_x->dtctrl_bit.rdwtstop = new_state; } /** @@ -585,9 +552,8 @@ void sdio_read_wait_stop(sdio_type *sdio_x, confirm_state new_state) * @param new_state (TRUE or FALSE) * @retval none */ -void sdio_io_function_enable(sdio_type *sdio_x, confirm_state new_state) -{ - sdio_x->dtctrl_bit.ioen = new_state; +void sdio_io_function_enable(sdio_type *sdio_x, confirm_state new_state) { + sdio_x->dtctrl_bit.ioen = new_state; } /** @@ -598,9 +564,8 @@ void sdio_io_function_enable(sdio_type *sdio_x, confirm_state new_state) * @param new_state (TRUE or FALSE) * @retval none */ -void sdio_io_suspend_command_set(sdio_type *sdio_x, confirm_state new_state) -{ - sdio_x->cmdctrl_bit.iosusp = new_state; +void sdio_io_suspend_command_set(sdio_type *sdio_x, confirm_state new_state) { + sdio_x->cmdctrl_bit.iosusp = new_state; } /** diff --git a/armlib/at32_sys/drivers/src/at32f435_437_spi.c b/armlib/at32_sys/drivers/src/at32f435_437_spi.c index d3f70458f..a24940daa 100644 --- a/armlib/at32_sys/drivers/src/at32f435_437_spi.c +++ b/armlib/at32_sys/drivers/src/at32f435_437_spi.c @@ -48,28 +48,20 @@ * SPI1, SPI2, SPI3 ,SPI4 * @retval none */ -void spi_i2s_reset(spi_type *spi_x) -{ - if(spi_x == SPI1) - { - crm_periph_reset(CRM_SPI1_PERIPH_RESET, TRUE); - crm_periph_reset(CRM_SPI1_PERIPH_RESET, FALSE); - } - else if(spi_x == SPI2) - { - crm_periph_reset(CRM_SPI2_PERIPH_RESET, TRUE); - crm_periph_reset(CRM_SPI2_PERIPH_RESET, FALSE); - } - else if(spi_x == SPI3) - { - crm_periph_reset(CRM_SPI3_PERIPH_RESET, TRUE); - crm_periph_reset(CRM_SPI3_PERIPH_RESET, FALSE); - } - else if(spi_x == SPI4) - { - crm_periph_reset(CRM_SPI4_PERIPH_RESET, TRUE); - crm_periph_reset(CRM_SPI4_PERIPH_RESET, FALSE); - } +void spi_i2s_reset(spi_type *spi_x) { + if (spi_x == SPI1) { + crm_periph_reset(CRM_SPI1_PERIPH_RESET, TRUE); + crm_periph_reset(CRM_SPI1_PERIPH_RESET, FALSE); + } else if (spi_x == SPI2) { + crm_periph_reset(CRM_SPI2_PERIPH_RESET, TRUE); + crm_periph_reset(CRM_SPI2_PERIPH_RESET, FALSE); + } else if (spi_x == SPI3) { + crm_periph_reset(CRM_SPI3_PERIPH_RESET, TRUE); + crm_periph_reset(CRM_SPI3_PERIPH_RESET, FALSE); + } else if (spi_x == SPI4) { + crm_periph_reset(CRM_SPI4_PERIPH_RESET, TRUE); + crm_periph_reset(CRM_SPI4_PERIPH_RESET, FALSE); + } } /** @@ -78,16 +70,15 @@ void spi_i2s_reset(spi_type *spi_x) * be initialized. * @retval none */ -void spi_default_para_init(spi_init_type* spi_init_struct) -{ - spi_init_struct->transmission_mode = SPI_TRANSMIT_FULL_DUPLEX; - spi_init_struct->master_slave_mode = SPI_MODE_SLAVE; - spi_init_struct->mclk_freq_division = SPI_MCLK_DIV_2; - spi_init_struct->first_bit_transmission = SPI_FIRST_BIT_MSB; - spi_init_struct->frame_bit_num = SPI_FRAME_8BIT; - spi_init_struct->clock_polarity = SPI_CLOCK_POLARITY_LOW; - spi_init_struct->clock_phase = SPI_CLOCK_PHASE_1EDGE; - spi_init_struct->cs_mode_selection = SPI_CS_SOFTWARE_MODE; +void spi_default_para_init(spi_init_type *spi_init_struct) { + spi_init_struct->transmission_mode = SPI_TRANSMIT_FULL_DUPLEX; + spi_init_struct->master_slave_mode = SPI_MODE_SLAVE; + spi_init_struct->mclk_freq_division = SPI_MCLK_DIV_2; + spi_init_struct->first_bit_transmission = SPI_FIRST_BIT_MSB; + spi_init_struct->frame_bit_num = SPI_FRAME_8BIT; + spi_init_struct->clock_polarity = SPI_CLOCK_POLARITY_LOW; + spi_init_struct->clock_phase = SPI_CLOCK_PHASE_1EDGE; + spi_init_struct->cs_mode_selection = SPI_CS_SOFTWARE_MODE; } /** @@ -98,68 +89,52 @@ void spi_default_para_init(spi_init_type* spi_init_struct) * @param spi_init_struct : pointer to a spi_init_type structure which will be initialized. * @retval none */ -void spi_init(spi_type* spi_x, spi_init_type* spi_init_struct) -{ - spi_x->i2sctrl_bit.i2smsel = FALSE; - if(spi_init_struct->transmission_mode == SPI_TRANSMIT_FULL_DUPLEX) - { - spi_x->ctrl1_bit.slben = FALSE; - spi_x->ctrl1_bit.slbtd = FALSE; - spi_x->ctrl1_bit.ora = FALSE; - } - else if(spi_init_struct->transmission_mode == SPI_TRANSMIT_SIMPLEX_RX) - { - spi_x->ctrl1_bit.slben = FALSE; - spi_x->ctrl1_bit.slbtd = FALSE; - spi_x->ctrl1_bit.ora = TRUE; - } - else if(spi_init_struct->transmission_mode == SPI_TRANSMIT_HALF_DUPLEX_RX) - { - spi_x->ctrl1_bit.slben = TRUE; - spi_x->ctrl1_bit.slbtd = FALSE; - spi_x->ctrl1_bit.ora = FALSE; - } - else if(spi_init_struct->transmission_mode == SPI_TRANSMIT_HALF_DUPLEX_TX) - { - spi_x->ctrl1_bit.slben = TRUE; - spi_x->ctrl1_bit.slbtd = TRUE; - spi_x->ctrl1_bit.ora = FALSE; - } +void spi_init(spi_type *spi_x, spi_init_type *spi_init_struct) { + spi_x->i2sctrl_bit.i2smsel = FALSE; + if (spi_init_struct->transmission_mode == SPI_TRANSMIT_FULL_DUPLEX) { + spi_x->ctrl1_bit.slben = FALSE; + spi_x->ctrl1_bit.slbtd = FALSE; + spi_x->ctrl1_bit.ora = FALSE; + } else if (spi_init_struct->transmission_mode == SPI_TRANSMIT_SIMPLEX_RX) { + spi_x->ctrl1_bit.slben = FALSE; + spi_x->ctrl1_bit.slbtd = FALSE; + spi_x->ctrl1_bit.ora = TRUE; + } else if (spi_init_struct->transmission_mode == SPI_TRANSMIT_HALF_DUPLEX_RX) { + spi_x->ctrl1_bit.slben = TRUE; + spi_x->ctrl1_bit.slbtd = FALSE; + spi_x->ctrl1_bit.ora = FALSE; + } else if (spi_init_struct->transmission_mode == SPI_TRANSMIT_HALF_DUPLEX_TX) { + spi_x->ctrl1_bit.slben = TRUE; + spi_x->ctrl1_bit.slbtd = TRUE; + spi_x->ctrl1_bit.ora = FALSE; + } - spi_x->ctrl1_bit.swcsen = spi_init_struct->cs_mode_selection; - if((spi_init_struct->master_slave_mode == SPI_MODE_MASTER) && (spi_init_struct->cs_mode_selection == SPI_CS_SOFTWARE_MODE)) - { - spi_x->ctrl1_bit.swcsil = TRUE; - } - else - { - spi_x->ctrl1_bit.swcsil = FALSE; - } - spi_x->ctrl1_bit.msten = spi_init_struct->master_slave_mode; + spi_x->ctrl1_bit.swcsen = spi_init_struct->cs_mode_selection; + if ((spi_init_struct->master_slave_mode == SPI_MODE_MASTER) && (spi_init_struct->cs_mode_selection == SPI_CS_SOFTWARE_MODE)) { + spi_x->ctrl1_bit.swcsil = TRUE; + } else { + spi_x->ctrl1_bit.swcsil = FALSE; + } + spi_x->ctrl1_bit.msten = spi_init_struct->master_slave_mode; - if(spi_init_struct->mclk_freq_division <= SPI_MCLK_DIV_256) - { - spi_x->ctrl2_bit.mdiv3en = FALSE; - spi_x->ctrl2_bit.mdiv_h = FALSE; - spi_x->ctrl1_bit.mdiv_l = spi_init_struct->mclk_freq_division; - } - else if(spi_init_struct->mclk_freq_division == SPI_MCLK_DIV_3) - { - spi_x->ctrl2_bit.mdiv3en = TRUE; - spi_x->ctrl2_bit.mdiv_h = FALSE; - spi_x->ctrl1_bit.mdiv_l = 0; - } - else - { - spi_x->ctrl2_bit.mdiv3en = FALSE; - spi_x->ctrl2_bit.mdiv_h = TRUE; - spi_x->ctrl1_bit.mdiv_l = spi_init_struct->mclk_freq_division & 0x7; - } + if (spi_init_struct->mclk_freq_division <= SPI_MCLK_DIV_256) { + spi_x->ctrl2_bit.mdiv3en = FALSE; + spi_x->ctrl2_bit.mdiv_h = FALSE; + spi_x->ctrl1_bit.mdiv_l = spi_init_struct->mclk_freq_division; + } else if (spi_init_struct->mclk_freq_division == SPI_MCLK_DIV_3) { + spi_x->ctrl2_bit.mdiv3en = TRUE; + spi_x->ctrl2_bit.mdiv_h = FALSE; + spi_x->ctrl1_bit.mdiv_l = 0; + } else { + spi_x->ctrl2_bit.mdiv3en = FALSE; + spi_x->ctrl2_bit.mdiv_h = TRUE; + spi_x->ctrl1_bit.mdiv_l = spi_init_struct->mclk_freq_division & 0x7; + } - spi_x->ctrl1_bit.ltf = spi_init_struct->first_bit_transmission; - spi_x->ctrl1_bit.fbn = spi_init_struct->frame_bit_num; - spi_x->ctrl1_bit.clkpol = spi_init_struct->clock_polarity; - spi_x->ctrl1_bit.clkpha = spi_init_struct->clock_phase; + spi_x->ctrl1_bit.ltf = spi_init_struct->first_bit_transmission; + spi_x->ctrl1_bit.fbn = spi_init_struct->frame_bit_num; + spi_x->ctrl1_bit.clkpol = spi_init_struct->clock_polarity; + spi_x->ctrl1_bit.clkpha = spi_init_struct->clock_phase; } /** @@ -171,9 +146,8 @@ void spi_init(spi_type* spi_x, spi_init_type* spi_init_struct) * this parameter can be: TRUE or FALSE. * @retval none */ -void spi_ti_mode_enable(spi_type* spi_x, confirm_state new_state) -{ - spi_x->ctrl2_bit.tien = new_state; +void spi_ti_mode_enable(spi_type *spi_x, confirm_state new_state) { + spi_x->ctrl2_bit.tien = new_state; } /** @@ -183,9 +157,8 @@ void spi_ti_mode_enable(spi_type* spi_x, confirm_state new_state) * SPI1, SPI2, SPI3 ,SPI4 * @retval none */ -void spi_crc_next_transmit(spi_type* spi_x) -{ - spi_x->ctrl1_bit.ntc = TRUE; +void spi_crc_next_transmit(spi_type *spi_x) { + spi_x->ctrl1_bit.ntc = TRUE; } /** @@ -196,9 +169,8 @@ void spi_crc_next_transmit(spi_type* spi_x) * @param crc_poly: crc polynomial value. * @retval none */ -void spi_crc_polynomial_set(spi_type* spi_x, uint16_t crc_poly) -{ - spi_x->cpoly_bit.cpoly = crc_poly; +void spi_crc_polynomial_set(spi_type *spi_x, uint16_t crc_poly) { + spi_x->cpoly_bit.cpoly = crc_poly; } /** @@ -208,9 +180,8 @@ void spi_crc_polynomial_set(spi_type* spi_x, uint16_t crc_poly) * SPI1, SPI2, SPI3 ,SPI4 * @retval the select crc polynomial register value */ -uint16_t spi_crc_polynomial_get(spi_type* spi_x) -{ - return spi_x->cpoly_bit.cpoly; +uint16_t spi_crc_polynomial_get(spi_type *spi_x) { + return spi_x->cpoly_bit.cpoly; } /** @@ -222,9 +193,8 @@ uint16_t spi_crc_polynomial_get(spi_type* spi_x) * this parameter can be: TRUE or FALSE. * @retval none */ -void spi_crc_enable(spi_type* spi_x, confirm_state new_state) -{ - spi_x->ctrl1_bit.ccen = new_state; +void spi_crc_enable(spi_type *spi_x, confirm_state new_state) { + spi_x->ctrl1_bit.ccen = new_state; } /** @@ -237,12 +207,11 @@ void spi_crc_enable(spi_type* spi_x, confirm_state new_state) * - SPI_CRC_TX * @retval the select crc register value */ -uint16_t spi_crc_value_get(spi_type* spi_x, spi_crc_direction_type crc_direction) -{ - if(crc_direction == SPI_CRC_RX) - return spi_x->rcrc_bit.rcrc; - else - return spi_x->tcrc_bit.tcrc; +uint16_t spi_crc_value_get(spi_type *spi_x, spi_crc_direction_type crc_direction) { + if (crc_direction == SPI_CRC_RX) + return spi_x->rcrc_bit.rcrc; + else + return spi_x->tcrc_bit.tcrc; } /** @@ -255,9 +224,8 @@ uint16_t spi_crc_value_get(spi_type* spi_x, spi_crc_direction_type crc_direction * note:the bit only use in spi master mode * @retval none */ -void spi_hardware_cs_output_enable(spi_type* spi_x, confirm_state new_state) -{ - spi_x->ctrl2_bit.hwcsoe = new_state; +void spi_hardware_cs_output_enable(spi_type *spi_x, confirm_state new_state) { + spi_x->ctrl2_bit.hwcsoe = new_state; } /** @@ -273,9 +241,8 @@ void spi_hardware_cs_output_enable(spi_type* spi_x, confirm_state new_state) * note:when use this bit,io operation on the cs pin are invalid. * @retval none */ -void spi_software_cs_internal_level_set(spi_type* spi_x, spi_software_cs_level_type level) -{ - spi_x->ctrl1_bit.swcsil = level; +void spi_software_cs_internal_level_set(spi_type *spi_x, spi_software_cs_level_type level) { + spi_x->ctrl1_bit.swcsil = level; } /** @@ -288,9 +255,8 @@ void spi_software_cs_internal_level_set(spi_type* spi_x, spi_software_cs_level_t * - SPI_FRAME_16BIT * @retval none */ -void spi_frame_bit_num_set(spi_type* spi_x, spi_frame_bit_num_type bit_num) -{ - spi_x->ctrl1_bit.fbn = bit_num; +void spi_frame_bit_num_set(spi_type *spi_x, spi_frame_bit_num_type bit_num) { + spi_x->ctrl1_bit.fbn = bit_num; } /** @@ -304,8 +270,7 @@ void spi_frame_bit_num_set(spi_type* spi_x, spi_frame_bit_num_type bit_num) * - SPI_HALF_DUPLEX_DIRECTION_TX * @retval none */ -void spi_half_duplex_direction_set(spi_type* spi_x, spi_half_duplex_direction_type direction) -{ +void spi_half_duplex_direction_set(spi_type *spi_x, spi_half_duplex_direction_type direction) { spi_x->ctrl1_bit.slbtd = direction; } @@ -318,9 +283,8 @@ void spi_half_duplex_direction_set(spi_type* spi_x, spi_half_duplex_direction_ty * this parameter can be: TRUE or FALSE. * @retval none */ -void spi_enable(spi_type* spi_x, confirm_state new_state) -{ - spi_x->ctrl1_bit.spien = new_state; +void spi_enable(spi_type *spi_x, confirm_state new_state) { + spi_x->ctrl1_bit.spien = new_state; } /** @@ -329,14 +293,13 @@ void spi_enable(spi_type* spi_x, confirm_state new_state) * be initialized. * @retval none */ -void i2s_default_para_init(i2s_init_type* i2s_init_struct) -{ - i2s_init_struct->operation_mode = I2S_MODE_SLAVE_TX; - i2s_init_struct->audio_protocol = I2S_AUDIO_PROTOCOL_PHILLIPS; - i2s_init_struct->audio_sampling_freq = I2S_AUDIO_FREQUENCY_DEFAULT; - i2s_init_struct->data_channel_format = I2S_DATA_16BIT_CHANNEL_16BIT; - i2s_init_struct->clock_polarity = I2S_CLOCK_POLARITY_LOW; - i2s_init_struct->mclk_output_enable = FALSE; +void i2s_default_para_init(i2s_init_type *i2s_init_struct) { + i2s_init_struct->operation_mode = I2S_MODE_SLAVE_TX; + i2s_init_struct->audio_protocol = I2S_AUDIO_PROTOCOL_PHILLIPS; + i2s_init_struct->audio_sampling_freq = I2S_AUDIO_FREQUENCY_DEFAULT; + i2s_init_struct->data_channel_format = I2S_DATA_16BIT_CHANNEL_16BIT; + i2s_init_struct->clock_polarity = I2S_CLOCK_POLARITY_LOW; + i2s_init_struct->mclk_output_enable = FALSE; } /** @@ -347,124 +310,91 @@ void i2s_default_para_init(i2s_init_type* i2s_init_struct) * @param i2s_init_struct : pointer to a i2s_init_type structure which will be initialized. * @retval none */ -void i2s_init(spi_type* spi_x, i2s_init_type* i2s_init_struct) -{ - crm_clocks_freq_type clocks_freq; - uint32_t i2s_sclk_index = 0; - uint32_t i2sdiv_index = 2, i2sodd_index = 0, frequency_index = 0; +void i2s_init(spi_type *spi_x, i2s_init_type *i2s_init_struct) { + crm_clocks_freq_type clocks_freq; + uint32_t i2s_sclk_index = 0; + uint32_t i2sdiv_index = 2, i2sodd_index = 0, frequency_index = 0; - /* i2s audio frequency config */ - if(i2s_init_struct->audio_sampling_freq == I2S_AUDIO_FREQUENCY_DEFAULT) - { - i2sodd_index = 0; - i2sdiv_index = 2; - } - else - { - crm_clocks_freq_get(&clocks_freq); - i2s_sclk_index = clocks_freq.sclk_freq; - if((i2s_init_struct->audio_protocol == I2S_AUDIO_PROTOCOL_PCM_SHORT) || (i2s_init_struct->audio_protocol == I2S_AUDIO_PROTOCOL_PCM_LONG)) - { - if(i2s_init_struct->mclk_output_enable == TRUE) - { - frequency_index = (((i2s_sclk_index / 128) * 10) / i2s_init_struct->audio_sampling_freq) + 5; - } - else - { - if(i2s_init_struct->data_channel_format == I2S_DATA_16BIT_CHANNEL_16BIT) - frequency_index = (((i2s_sclk_index / 16) * 10) / i2s_init_struct->audio_sampling_freq) + 5; - else - frequency_index = (((i2s_sclk_index / 32) * 10) / i2s_init_struct->audio_sampling_freq) + 5; - } + /* i2s audio frequency config */ + if (i2s_init_struct->audio_sampling_freq == I2S_AUDIO_FREQUENCY_DEFAULT) { + i2sodd_index = 0; + i2sdiv_index = 2; + } else { + crm_clocks_freq_get(&clocks_freq); + i2s_sclk_index = clocks_freq.sclk_freq; + if ((i2s_init_struct->audio_protocol == I2S_AUDIO_PROTOCOL_PCM_SHORT) || (i2s_init_struct->audio_protocol == I2S_AUDIO_PROTOCOL_PCM_LONG)) { + if (i2s_init_struct->mclk_output_enable == TRUE) { + frequency_index = (((i2s_sclk_index / 128) * 10) / i2s_init_struct->audio_sampling_freq) + 5; + } else { + if (i2s_init_struct->data_channel_format == I2S_DATA_16BIT_CHANNEL_16BIT) + frequency_index = (((i2s_sclk_index / 16) * 10) / i2s_init_struct->audio_sampling_freq) + 5; + else + frequency_index = (((i2s_sclk_index / 32) * 10) / i2s_init_struct->audio_sampling_freq) + 5; + } + } else { + if (i2s_init_struct->mclk_output_enable == TRUE) { + frequency_index = (((i2s_sclk_index / 256) * 10) / i2s_init_struct->audio_sampling_freq) + 5; + } else { + if (i2s_init_struct->data_channel_format == I2S_DATA_16BIT_CHANNEL_16BIT) + frequency_index = (((i2s_sclk_index / 32) * 10) / i2s_init_struct->audio_sampling_freq) + 5; + else + frequency_index = (((i2s_sclk_index / 64) * 10) / i2s_init_struct->audio_sampling_freq) + 5; + } + } } - else - { - if(i2s_init_struct->mclk_output_enable == TRUE) - { - frequency_index = (((i2s_sclk_index / 256) * 10) / i2s_init_struct->audio_sampling_freq) + 5; - } - else - { - if(i2s_init_struct->data_channel_format == I2S_DATA_16BIT_CHANNEL_16BIT) - frequency_index = (((i2s_sclk_index / 32) * 10) / i2s_init_struct->audio_sampling_freq) + 5; - else - frequency_index = (((i2s_sclk_index / 64) * 10) / i2s_init_struct->audio_sampling_freq) + 5; - } + frequency_index = frequency_index / 10; + i2sodd_index = frequency_index & (uint16_t)0x0001; + i2sdiv_index = (frequency_index - i2sodd_index) / 2; + if ((i2sdiv_index < 2) || (i2sdiv_index > 0x03FF)) { + i2sodd_index = 0; + i2sdiv_index = 2; + } + spi_x->i2sclk_bit.i2sodd = i2sodd_index; + if (i2sdiv_index > 0x00FF) { + spi_x->i2sclk_bit.i2sdiv_h = (i2sdiv_index >> 8) & 0x0003; + spi_x->i2sclk_bit.i2sdiv_l = i2sdiv_index & 0x00FF; + } else { + spi_x->i2sclk_bit.i2sdiv_h = 0; + spi_x->i2sclk_bit.i2sdiv_l = i2sdiv_index; } - } - frequency_index = frequency_index / 10; - i2sodd_index = frequency_index & (uint16_t)0x0001; - i2sdiv_index = (frequency_index - i2sodd_index) / 2; - if((i2sdiv_index < 2) || (i2sdiv_index > 0x03FF)) - { - i2sodd_index = 0; - i2sdiv_index = 2; - } - spi_x->i2sclk_bit.i2sodd = i2sodd_index; - if(i2sdiv_index > 0x00FF) - { - spi_x->i2sclk_bit.i2sdiv_h = (i2sdiv_index >> 8) & 0x0003; - spi_x->i2sclk_bit.i2sdiv_l = i2sdiv_index & 0x00FF; - } - else - { - spi_x->i2sclk_bit.i2sdiv_h = 0; - spi_x->i2sclk_bit.i2sdiv_l = i2sdiv_index; - } - /* i2s audio_protocol set*/ - if(i2s_init_struct->audio_protocol == I2S_AUDIO_PROTOCOL_PCM_LONG) - { - spi_x->i2sctrl_bit.pcmfssel = 1; - spi_x->i2sctrl_bit.stdsel = 3; - } - else if(i2s_init_struct->audio_protocol == I2S_AUDIO_PROTOCOL_PCM_SHORT) - { - spi_x->i2sctrl_bit.pcmfssel = 0; - spi_x->i2sctrl_bit.stdsel = 3; - } - else if(i2s_init_struct->audio_protocol == I2S_AUDIO_PROTOCOL_LSB) - { - spi_x->i2sctrl_bit.pcmfssel = 0; - spi_x->i2sctrl_bit.stdsel = 2; - } - else if(i2s_init_struct->audio_protocol == I2S_AUDIO_PROTOCOL_MSB) - { - spi_x->i2sctrl_bit.pcmfssel = 0; - spi_x->i2sctrl_bit.stdsel = 1; - } - else if(i2s_init_struct->audio_protocol == I2S_AUDIO_PROTOCOL_PHILLIPS) - { - spi_x->i2sctrl_bit.pcmfssel = 0; - spi_x->i2sctrl_bit.stdsel = 0; - } + /* i2s audio_protocol set*/ + if (i2s_init_struct->audio_protocol == I2S_AUDIO_PROTOCOL_PCM_LONG) { + spi_x->i2sctrl_bit.pcmfssel = 1; + spi_x->i2sctrl_bit.stdsel = 3; + } else if (i2s_init_struct->audio_protocol == I2S_AUDIO_PROTOCOL_PCM_SHORT) { + spi_x->i2sctrl_bit.pcmfssel = 0; + spi_x->i2sctrl_bit.stdsel = 3; + } else if (i2s_init_struct->audio_protocol == I2S_AUDIO_PROTOCOL_LSB) { + spi_x->i2sctrl_bit.pcmfssel = 0; + spi_x->i2sctrl_bit.stdsel = 2; + } else if (i2s_init_struct->audio_protocol == I2S_AUDIO_PROTOCOL_MSB) { + spi_x->i2sctrl_bit.pcmfssel = 0; + spi_x->i2sctrl_bit.stdsel = 1; + } else if (i2s_init_struct->audio_protocol == I2S_AUDIO_PROTOCOL_PHILLIPS) { + spi_x->i2sctrl_bit.pcmfssel = 0; + spi_x->i2sctrl_bit.stdsel = 0; + } - /* i2s data_channel_format set*/ - if(i2s_init_struct->data_channel_format == I2S_DATA_16BIT_CHANNEL_16BIT) - { - spi_x->i2sctrl_bit.i2scbn = 0; - spi_x->i2sctrl_bit.i2sdbn = 0; - } - else if(i2s_init_struct->data_channel_format == I2S_DATA_16BIT_CHANNEL_32BIT) - { - spi_x->i2sctrl_bit.i2scbn = 1; - spi_x->i2sctrl_bit.i2sdbn = 0; - } - else if(i2s_init_struct->data_channel_format == I2S_DATA_24BIT_CHANNEL_32BIT) - { - spi_x->i2sctrl_bit.i2scbn = 1; - spi_x->i2sctrl_bit.i2sdbn = 1; - } - else if(i2s_init_struct->data_channel_format == I2S_DATA_32BIT_CHANNEL_32BIT) - { - spi_x->i2sctrl_bit.i2scbn = 1; - spi_x->i2sctrl_bit.i2sdbn = 2; - } + /* i2s data_channel_format set*/ + if (i2s_init_struct->data_channel_format == I2S_DATA_16BIT_CHANNEL_16BIT) { + spi_x->i2sctrl_bit.i2scbn = 0; + spi_x->i2sctrl_bit.i2sdbn = 0; + } else if (i2s_init_struct->data_channel_format == I2S_DATA_16BIT_CHANNEL_32BIT) { + spi_x->i2sctrl_bit.i2scbn = 1; + spi_x->i2sctrl_bit.i2sdbn = 0; + } else if (i2s_init_struct->data_channel_format == I2S_DATA_24BIT_CHANNEL_32BIT) { + spi_x->i2sctrl_bit.i2scbn = 1; + spi_x->i2sctrl_bit.i2sdbn = 1; + } else if (i2s_init_struct->data_channel_format == I2S_DATA_32BIT_CHANNEL_32BIT) { + spi_x->i2sctrl_bit.i2scbn = 1; + spi_x->i2sctrl_bit.i2sdbn = 2; + } - spi_x->i2sctrl_bit.i2sclkpol = i2s_init_struct->clock_polarity; - spi_x->i2sclk_bit.i2smclkoe = i2s_init_struct->mclk_output_enable; - spi_x->i2sctrl_bit.opersel = i2s_init_struct->operation_mode; - spi_x->i2sctrl_bit.i2smsel = TRUE; + spi_x->i2sctrl_bit.i2sclkpol = i2s_init_struct->clock_polarity; + spi_x->i2sclk_bit.i2smclkoe = i2s_init_struct->mclk_output_enable; + spi_x->i2sctrl_bit.opersel = i2s_init_struct->operation_mode; + spi_x->i2sctrl_bit.i2smsel = TRUE; } /** @@ -476,9 +406,8 @@ void i2s_init(spi_type* spi_x, i2s_init_type* i2s_init_struct) * this parameter can be: TRUE or FALSE. * @retval none */ -void i2s_enable(spi_type* spi_x, confirm_state new_state) -{ - spi_x->i2sctrl_bit.i2sen = new_state; +void i2s_enable(spi_type *spi_x, confirm_state new_state) { + spi_x->i2sctrl_bit.i2sen = new_state; } /** @@ -495,16 +424,12 @@ void i2s_enable(spi_type* spi_x, confirm_state new_state) * this parameter can be: TRUE or FALSE. * @retval none */ -void spi_i2s_interrupt_enable(spi_type* spi_x, uint32_t spi_i2s_int, confirm_state new_state) -{ - if(new_state != FALSE) - { - spi_x->ctrl2 |= spi_i2s_int; - } - else - { - spi_x->ctrl2 &= ~spi_i2s_int; - } +void spi_i2s_interrupt_enable(spi_type *spi_x, uint32_t spi_i2s_int, confirm_state new_state) { + if (new_state != FALSE) { + spi_x->ctrl2 |= spi_i2s_int; + } else { + spi_x->ctrl2 &= ~spi_i2s_int; + } } /** @@ -516,9 +441,8 @@ void spi_i2s_interrupt_enable(spi_type* spi_x, uint32_t spi_i2s_int, confirm_sta * this parameter can be: TRUE or FALSE. * @retval none */ -void spi_i2s_dma_transmitter_enable(spi_type* spi_x, confirm_state new_state) -{ - spi_x->ctrl2_bit.dmaten = new_state; +void spi_i2s_dma_transmitter_enable(spi_type *spi_x, confirm_state new_state) { + spi_x->ctrl2_bit.dmaten = new_state; } /** @@ -530,9 +454,8 @@ void spi_i2s_dma_transmitter_enable(spi_type* spi_x, confirm_state new_state) * this parameter can be: TRUE or FALSE. * @retval none */ -void spi_i2s_dma_receiver_enable(spi_type* spi_x, confirm_state new_state) -{ - spi_x->ctrl2_bit.dmaren = new_state; +void spi_i2s_dma_receiver_enable(spi_type *spi_x, confirm_state new_state) { + spi_x->ctrl2_bit.dmaren = new_state; } /** @@ -545,9 +468,8 @@ void spi_i2s_dma_receiver_enable(spi_type* spi_x, confirm_state new_state) * - (0x0000~0xFFFF) * @retval none */ -void spi_i2s_data_transmit(spi_type* spi_x, uint16_t tx_data) -{ - spi_x->dt = tx_data; +void spi_i2s_data_transmit(spi_type *spi_x, uint16_t tx_data) { + spi_x->dt = tx_data; } /** @@ -557,9 +479,8 @@ void spi_i2s_data_transmit(spi_type* spi_x, uint16_t tx_data) * SPI1, SPI2, SPI3 ,SPI4 , I2S2EXT, I2S3EXT * @retval the received data value */ -uint16_t spi_i2s_data_receive(spi_type* spi_x) -{ - return (uint16_t)spi_x->dt; +uint16_t spi_i2s_data_receive(spi_type *spi_x) { + return (uint16_t)spi_x->dt; } /** @@ -580,18 +501,14 @@ uint16_t spi_i2s_data_receive(spi_type* spi_x) * - SPI_CSPAS_FLAG * @retval the new state of spi/i2s flag */ -flag_status spi_i2s_flag_get(spi_type* spi_x, uint32_t spi_i2s_flag) -{ - flag_status status = RESET; - if ((spi_x->sts & spi_i2s_flag) == RESET) - { - status = RESET; - } - else - { - status = SET; - } - return status; +flag_status spi_i2s_flag_get(spi_type *spi_x, uint32_t spi_i2s_flag) { + flag_status status = RESET; + if ((spi_x->sts & spi_i2s_flag) == RESET) { + status = RESET; + } else { + status = SET; + } + return status; } /** @@ -610,58 +527,49 @@ flag_status spi_i2s_flag_get(spi_type* spi_x, uint32_t spi_i2s_flag) * - SPI_CSPAS_FLAG * @retval the new state of spi/i2s flag */ -flag_status spi_i2s_interrupt_flag_get(spi_type* spi_x, uint32_t spi_i2s_flag) -{ - flag_status status = RESET; - - switch(spi_i2s_flag) - { - case SPI_I2S_RDBF_FLAG: - if(spi_x->sts_bit.rdbf && spi_x->ctrl2_bit.rdbfie) - { - status = SET; - } - break; - case SPI_I2S_TDBE_FLAG: - if(spi_x->sts_bit.tdbe && spi_x->ctrl2_bit.tdbeie) - { - status = SET; - } - break; - case I2S_TUERR_FLAG: - if(spi_x->sts_bit.tuerr && spi_x->ctrl2_bit.errie) - { - status = SET; - } - break; - case SPI_CCERR_FLAG: - if(spi_x->sts_bit.ccerr && spi_x->ctrl2_bit.errie) - { - status = SET; - } - break; - case SPI_MMERR_FLAG: - if(spi_x->sts_bit.mmerr && spi_x->ctrl2_bit.errie) - { - status = SET; - } - break; - case SPI_I2S_ROERR_FLAG: - if(spi_x->sts_bit.roerr && spi_x->ctrl2_bit.errie) - { - status = SET; - } - break; - case SPI_CSPAS_FLAG: - if(spi_x->sts_bit.cspas && spi_x->ctrl2_bit.errie) - { - status = SET; - } - break; - default: - break; - }; - return status; +flag_status spi_i2s_interrupt_flag_get(spi_type *spi_x, uint32_t spi_i2s_flag) { + flag_status status = RESET; + + switch (spi_i2s_flag) { + case SPI_I2S_RDBF_FLAG: + if (spi_x->sts_bit.rdbf && spi_x->ctrl2_bit.rdbfie) { + status = SET; + } + break; + case SPI_I2S_TDBE_FLAG: + if (spi_x->sts_bit.tdbe && spi_x->ctrl2_bit.tdbeie) { + status = SET; + } + break; + case I2S_TUERR_FLAG: + if (spi_x->sts_bit.tuerr && spi_x->ctrl2_bit.errie) { + status = SET; + } + break; + case SPI_CCERR_FLAG: + if (spi_x->sts_bit.ccerr && spi_x->ctrl2_bit.errie) { + status = SET; + } + break; + case SPI_MMERR_FLAG: + if (spi_x->sts_bit.mmerr && spi_x->ctrl2_bit.errie) { + status = SET; + } + break; + case SPI_I2S_ROERR_FLAG: + if (spi_x->sts_bit.roerr && spi_x->ctrl2_bit.errie) { + status = SET; + } + break; + case SPI_CSPAS_FLAG: + if (spi_x->sts_bit.cspas && spi_x->ctrl2_bit.errie) { + status = SET; + } + break; + default: + break; + }; + return status; } /** @@ -683,26 +591,22 @@ flag_status spi_i2s_interrupt_flag_get(spi_type* spi_x, uint32_t spi_i2s_flag) * SPI_I2S_BF_FLAG this flag cann't cleared by software, it's set and cleared by hardware. * @retval none */ -void spi_i2s_flag_clear(spi_type* spi_x, uint32_t spi_i2s_flag) -{ - if(spi_i2s_flag == SPI_CCERR_FLAG) - spi_x->sts = ~SPI_CCERR_FLAG; - else if(spi_i2s_flag == SPI_I2S_RDBF_FLAG) - UNUSED(spi_x->dt); - else if(spi_i2s_flag == I2S_TUERR_FLAG) - UNUSED(spi_x->sts); - else if(spi_i2s_flag == SPI_CSPAS_FLAG) - UNUSED(spi_x->sts); - else if(spi_i2s_flag == SPI_MMERR_FLAG) - { - UNUSED(spi_x->sts); - spi_x->ctrl1 = spi_x->ctrl1; - } - else if(spi_i2s_flag == SPI_I2S_ROERR_FLAG) - { - UNUSED(spi_x->dt); - UNUSED(spi_x->sts); - } +void spi_i2s_flag_clear(spi_type *spi_x, uint32_t spi_i2s_flag) { + if (spi_i2s_flag == SPI_CCERR_FLAG) + spi_x->sts = ~SPI_CCERR_FLAG; + else if (spi_i2s_flag == SPI_I2S_RDBF_FLAG) + UNUSED(spi_x->dt); + else if (spi_i2s_flag == I2S_TUERR_FLAG) + UNUSED(spi_x->sts); + else if (spi_i2s_flag == SPI_CSPAS_FLAG) + UNUSED(spi_x->sts); + else if (spi_i2s_flag == SPI_MMERR_FLAG) { + UNUSED(spi_x->sts); + spi_x->ctrl1 = spi_x->ctrl1; + } else if (spi_i2s_flag == SPI_I2S_ROERR_FLAG) { + UNUSED(spi_x->dt); + UNUSED(spi_x->sts); + } } /** diff --git a/armlib/at32_sys/drivers/src/at32f435_437_tmr.c b/armlib/at32_sys/drivers/src/at32f435_437_tmr.c index 55569e020..47ffc9e95 100644 --- a/armlib/at32_sys/drivers/src/at32f435_437_tmr.c +++ b/armlib/at32_sys/drivers/src/at32f435_437_tmr.c @@ -49,83 +49,53 @@ * TMR9, TMR10, TMR11, TMR12, TMR13, TMR14, TMR20 * @retval none */ -void tmr_reset(tmr_type *tmr_x) -{ - if(tmr_x == TMR1) - { - crm_periph_reset(CRM_TMR1_PERIPH_RESET, TRUE); - crm_periph_reset(CRM_TMR1_PERIPH_RESET, FALSE); - } - else if(tmr_x == TMR2) - { - crm_periph_reset(CRM_TMR2_PERIPH_RESET, TRUE); - crm_periph_reset(CRM_TMR2_PERIPH_RESET, FALSE); - } - else if(tmr_x == TMR3) - { - crm_periph_reset(CRM_TMR3_PERIPH_RESET, TRUE); - crm_periph_reset(CRM_TMR3_PERIPH_RESET, FALSE); - } - else if(tmr_x == TMR4) - { - crm_periph_reset(CRM_TMR4_PERIPH_RESET, TRUE); - crm_periph_reset(CRM_TMR4_PERIPH_RESET, FALSE); - } - else if(tmr_x == TMR5) - { - crm_periph_reset(CRM_TMR5_PERIPH_RESET, TRUE); - crm_periph_reset(CRM_TMR5_PERIPH_RESET, FALSE); - } - else if(tmr_x == TMR6) - { - crm_periph_reset(CRM_TMR6_PERIPH_RESET, TRUE); - crm_periph_reset(CRM_TMR6_PERIPH_RESET, FALSE); - } - else if(tmr_x == TMR7) - { - crm_periph_reset(CRM_TMR7_PERIPH_RESET, TRUE); - crm_periph_reset(CRM_TMR7_PERIPH_RESET, FALSE); - } - else if(tmr_x == TMR8) - { - crm_periph_reset(CRM_TMR8_PERIPH_RESET, TRUE); - crm_periph_reset(CRM_TMR8_PERIPH_RESET, FALSE); - } - else if(tmr_x == TMR9) - { - crm_periph_reset(CRM_TMR9_PERIPH_RESET, TRUE); - crm_periph_reset(CRM_TMR9_PERIPH_RESET, FALSE); - } - else if(tmr_x == TMR10) - { - crm_periph_reset(CRM_TMR10_PERIPH_RESET, TRUE); - crm_periph_reset(CRM_TMR10_PERIPH_RESET, FALSE); - } - else if(tmr_x == TMR11) - { - crm_periph_reset(CRM_TMR11_PERIPH_RESET, TRUE); - crm_periph_reset(CRM_TMR11_PERIPH_RESET, FALSE); - } - else if(tmr_x == TMR12) - { - crm_periph_reset(CRM_TMR12_PERIPH_RESET, TRUE); - crm_periph_reset(CRM_TMR12_PERIPH_RESET, FALSE); - } - else if(tmr_x == TMR13) - { - crm_periph_reset(CRM_TMR13_PERIPH_RESET, TRUE); - crm_periph_reset(CRM_TMR13_PERIPH_RESET, FALSE); - } - else if(tmr_x == TMR14) - { - crm_periph_reset(CRM_TMR14_PERIPH_RESET, TRUE); - crm_periph_reset(CRM_TMR14_PERIPH_RESET, FALSE); - } - else if(tmr_x == TMR20) - { - crm_periph_reset(CRM_TMR20_PERIPH_RESET, TRUE); - crm_periph_reset(CRM_TMR20_PERIPH_RESET, FALSE); - } +void tmr_reset(tmr_type *tmr_x) { + if (tmr_x == TMR1) { + crm_periph_reset(CRM_TMR1_PERIPH_RESET, TRUE); + crm_periph_reset(CRM_TMR1_PERIPH_RESET, FALSE); + } else if (tmr_x == TMR2) { + crm_periph_reset(CRM_TMR2_PERIPH_RESET, TRUE); + crm_periph_reset(CRM_TMR2_PERIPH_RESET, FALSE); + } else if (tmr_x == TMR3) { + crm_periph_reset(CRM_TMR3_PERIPH_RESET, TRUE); + crm_periph_reset(CRM_TMR3_PERIPH_RESET, FALSE); + } else if (tmr_x == TMR4) { + crm_periph_reset(CRM_TMR4_PERIPH_RESET, TRUE); + crm_periph_reset(CRM_TMR4_PERIPH_RESET, FALSE); + } else if (tmr_x == TMR5) { + crm_periph_reset(CRM_TMR5_PERIPH_RESET, TRUE); + crm_periph_reset(CRM_TMR5_PERIPH_RESET, FALSE); + } else if (tmr_x == TMR6) { + crm_periph_reset(CRM_TMR6_PERIPH_RESET, TRUE); + crm_periph_reset(CRM_TMR6_PERIPH_RESET, FALSE); + } else if (tmr_x == TMR7) { + crm_periph_reset(CRM_TMR7_PERIPH_RESET, TRUE); + crm_periph_reset(CRM_TMR7_PERIPH_RESET, FALSE); + } else if (tmr_x == TMR8) { + crm_periph_reset(CRM_TMR8_PERIPH_RESET, TRUE); + crm_periph_reset(CRM_TMR8_PERIPH_RESET, FALSE); + } else if (tmr_x == TMR9) { + crm_periph_reset(CRM_TMR9_PERIPH_RESET, TRUE); + crm_periph_reset(CRM_TMR9_PERIPH_RESET, FALSE); + } else if (tmr_x == TMR10) { + crm_periph_reset(CRM_TMR10_PERIPH_RESET, TRUE); + crm_periph_reset(CRM_TMR10_PERIPH_RESET, FALSE); + } else if (tmr_x == TMR11) { + crm_periph_reset(CRM_TMR11_PERIPH_RESET, TRUE); + crm_periph_reset(CRM_TMR11_PERIPH_RESET, FALSE); + } else if (tmr_x == TMR12) { + crm_periph_reset(CRM_TMR12_PERIPH_RESET, TRUE); + crm_periph_reset(CRM_TMR12_PERIPH_RESET, FALSE); + } else if (tmr_x == TMR13) { + crm_periph_reset(CRM_TMR13_PERIPH_RESET, TRUE); + crm_periph_reset(CRM_TMR13_PERIPH_RESET, FALSE); + } else if (tmr_x == TMR14) { + crm_periph_reset(CRM_TMR14_PERIPH_RESET, TRUE); + crm_periph_reset(CRM_TMR14_PERIPH_RESET, FALSE); + } else if (tmr_x == TMR20) { + crm_periph_reset(CRM_TMR20_PERIPH_RESET, TRUE); + crm_periph_reset(CRM_TMR20_PERIPH_RESET, FALSE); + } } /** @@ -137,10 +107,9 @@ void tmr_reset(tmr_type *tmr_x) * @param new_state (TRUE or FALSE) * @retval none */ -void tmr_counter_enable(tmr_type *tmr_x, confirm_state new_state) -{ - /* tmr counter enable */ - tmr_x->ctrl1_bit.tmren = new_state; +void tmr_counter_enable(tmr_type *tmr_x, confirm_state new_state) { + /* tmr counter enable */ + tmr_x->ctrl1_bit.tmren = new_state; } /** @@ -149,15 +118,14 @@ void tmr_counter_enable(tmr_type *tmr_x, confirm_state new_state) * - to the structure of tmr_output_config_type * @retval none */ -void tmr_output_default_para_init(tmr_output_config_type *tmr_output_struct) -{ - tmr_output_struct->oc_mode = TMR_OUTPUT_CONTROL_OFF; - tmr_output_struct->oc_idle_state = FALSE; - tmr_output_struct->occ_idle_state = FALSE; - tmr_output_struct->oc_polarity = TMR_OUTPUT_ACTIVE_HIGH; - tmr_output_struct->occ_polarity = TMR_OUTPUT_ACTIVE_HIGH; - tmr_output_struct->oc_output_state = FALSE; - tmr_output_struct->occ_output_state = FALSE; +void tmr_output_default_para_init(tmr_output_config_type *tmr_output_struct) { + tmr_output_struct->oc_mode = TMR_OUTPUT_CONTROL_OFF; + tmr_output_struct->oc_idle_state = FALSE; + tmr_output_struct->occ_idle_state = FALSE; + tmr_output_struct->oc_polarity = TMR_OUTPUT_ACTIVE_HIGH; + tmr_output_struct->occ_polarity = TMR_OUTPUT_ACTIVE_HIGH; + tmr_output_struct->oc_output_state = FALSE; + tmr_output_struct->occ_output_state = FALSE; } /** @@ -166,12 +134,11 @@ void tmr_output_default_para_init(tmr_output_config_type *tmr_output_struct) * - to the structure of tmr_input_config_type * @retval none */ -void tmr_input_default_para_init(tmr_input_config_type *tmr_input_struct) -{ - tmr_input_struct->input_channel_select = TMR_SELECT_CHANNEL_1; - tmr_input_struct->input_polarity_select = TMR_INPUT_RISING_EDGE; - tmr_input_struct->input_mapped_select = TMR_CC_CHANNEL_MAPPED_DIRECT; - tmr_input_struct->input_filter_value = 0x0; +void tmr_input_default_para_init(tmr_input_config_type *tmr_input_struct) { + tmr_input_struct->input_channel_select = TMR_SELECT_CHANNEL_1; + tmr_input_struct->input_polarity_select = TMR_INPUT_RISING_EDGE; + tmr_input_struct->input_mapped_select = TMR_CC_CHANNEL_MAPPED_DIRECT; + tmr_input_struct->input_filter_value = 0x0; } /** @@ -180,15 +147,14 @@ void tmr_input_default_para_init(tmr_input_config_type *tmr_input_struct) * - to the structure of tmr_brkdt_config_type * @retval none */ -void tmr_brkdt_default_para_init(tmr_brkdt_config_type *tmr_brkdt_struct) -{ - tmr_brkdt_struct->deadtime = 0x0; - tmr_brkdt_struct->brk_polarity = TMR_BRK_INPUT_ACTIVE_LOW; - tmr_brkdt_struct->wp_level = TMR_WP_OFF; - tmr_brkdt_struct->auto_output_enable = FALSE ; - tmr_brkdt_struct->fcsoen_state = FALSE ; - tmr_brkdt_struct->fcsodis_state = FALSE ; - tmr_brkdt_struct->brk_enable = FALSE ; +void tmr_brkdt_default_para_init(tmr_brkdt_config_type *tmr_brkdt_struct) { + tmr_brkdt_struct->deadtime = 0x0; + tmr_brkdt_struct->brk_polarity = TMR_BRK_INPUT_ACTIVE_LOW; + tmr_brkdt_struct->wp_level = TMR_WP_OFF; + tmr_brkdt_struct->auto_output_enable = FALSE ; + tmr_brkdt_struct->fcsoen_state = FALSE ; + tmr_brkdt_struct->fcsodis_state = FALSE ; + tmr_brkdt_struct->brk_enable = FALSE ; } /** @@ -202,16 +168,15 @@ void tmr_brkdt_default_para_init(tmr_brkdt_config_type *tmr_brkdt_struct) * @param tmr_div (timer div value:0x0000~0xFFFF) * @retval none */ -void tmr_base_init(tmr_type* tmr_x, uint32_t tmr_pr, uint32_t tmr_div) -{ - /* set the pr value */ - tmr_x->pr = tmr_pr; +void tmr_base_init(tmr_type *tmr_x, uint32_t tmr_pr, uint32_t tmr_div) { + /* set the pr value */ + tmr_x->pr = tmr_pr; - /* set the div value */ - tmr_x->div = tmr_div; + /* set the div value */ + tmr_x->div = tmr_div; - /* trigger the overflow event to immediately reload pr value and div value */ - tmr_x->swevt_bit.ovfswtr = TRUE; + /* trigger the overflow event to immediately reload pr value and div value */ + tmr_x->swevt_bit.ovfswtr = TRUE; } /** @@ -227,10 +192,9 @@ void tmr_base_init(tmr_type* tmr_x, uint32_t tmr_pr, uint32_t tmr_div) * - TMR_CLOCK_DIV4 * @retval none */ -void tmr_clock_source_div_set(tmr_type *tmr_x, tmr_clock_division_type tmr_clock_div) -{ - /* set tmr clock source division */ - tmr_x->ctrl1_bit.clkdiv = tmr_clock_div; +void tmr_clock_source_div_set(tmr_type *tmr_x, tmr_clock_division_type tmr_clock_div) { + /* set tmr clock source division */ + tmr_x->ctrl1_bit.clkdiv = tmr_clock_div; } /** @@ -248,10 +212,9 @@ void tmr_clock_source_div_set(tmr_type *tmr_x, tmr_clock_division_type tmr_clock * - TMR_COUNT_TWO_WAY_3 * @retval none */ -void tmr_cnt_dir_set(tmr_type *tmr_x, tmr_count_mode_type tmr_cnt_dir) -{ - /* set the cnt direct */ - tmr_x->ctrl1_bit.cnt_dir = tmr_cnt_dir; +void tmr_cnt_dir_set(tmr_type *tmr_x, tmr_count_mode_type tmr_cnt_dir) { + /* set the cnt direct */ + tmr_x->ctrl1_bit.cnt_dir = tmr_cnt_dir; } /** @@ -262,10 +225,9 @@ void tmr_cnt_dir_set(tmr_type *tmr_x, tmr_count_mode_type tmr_cnt_dir) * @param tmr_rpr_value (0x0000~0xFFFF) * @retval none */ -void tmr_repetition_counter_set(tmr_type *tmr_x, uint16_t tmr_rpr_value) -{ - /* set the repetition counter value */ - tmr_x->rpr_bit.rpr = tmr_rpr_value; +void tmr_repetition_counter_set(tmr_type *tmr_x, uint16_t tmr_rpr_value) { + /* set the repetition counter value */ + tmr_x->rpr_bit.rpr = tmr_rpr_value; } /** @@ -278,10 +240,9 @@ void tmr_repetition_counter_set(tmr_type *tmr_x, uint16_t tmr_rpr_value) * for 32 bit tmr 0x0000_0000~0xFFFF_FFFF) * @retval none */ -void tmr_counter_value_set(tmr_type *tmr_x, uint32_t tmr_cnt_value) -{ - /* set the tmr counter value */ - tmr_x->cval = tmr_cnt_value; +void tmr_counter_value_set(tmr_type *tmr_x, uint32_t tmr_cnt_value) { + /* set the tmr counter value */ + tmr_x->cval = tmr_cnt_value; } /** @@ -292,9 +253,8 @@ void tmr_counter_value_set(tmr_type *tmr_x, uint32_t tmr_cnt_value) * TMR9, TMR10, TMR11, TMR12, TMR13, TMR14, TMR20 * @retval tmr counter value */ -uint32_t tmr_counter_value_get(tmr_type *tmr_x) -{ - return tmr_x->cval; +uint32_t tmr_counter_value_get(tmr_type *tmr_x) { + return tmr_x->cval; } /** @@ -306,10 +266,9 @@ uint32_t tmr_counter_value_get(tmr_type *tmr_x) * @param tmr_div_value (0x0000~0xFFFF) * @retval none */ -void tmr_div_value_set(tmr_type *tmr_x, uint32_t tmr_div_value) -{ - /* set the tmr div value */ - tmr_x->div = tmr_div_value; +void tmr_div_value_set(tmr_type *tmr_x, uint32_t tmr_div_value) { + /* set the tmr div value */ + tmr_x->div = tmr_div_value; } /** @@ -320,9 +279,8 @@ void tmr_div_value_set(tmr_type *tmr_x, uint32_t tmr_div_value) * TMR9, TMR10, TMR11, TMR12, TMR13, TMR14, TMR20 * @retval tmr div value */ -uint32_t tmr_div_value_get(tmr_type *tmr_x) -{ - return tmr_x->div; +uint32_t tmr_div_value_get(tmr_type *tmr_x) { + return tmr_x->div; } /** @@ -343,89 +301,87 @@ uint32_t tmr_div_value_get(tmr_type *tmr_x) * @retval none */ void tmr_output_channel_config(tmr_type *tmr_x, tmr_channel_select_type tmr_channel, \ - tmr_output_config_type *tmr_output_struct) -{ - uint16_t channel_index = 0, channel_c_index = 0, channel = 0, chx_offset, chcx_offset; + tmr_output_config_type *tmr_output_struct) { + uint16_t channel_index = 0, channel_c_index = 0, channel = 0, chx_offset, chcx_offset; - chx_offset = (8 + tmr_channel); - chcx_offset = (9 + tmr_channel); - - /* get channel idle state bit position in ctrl2 register */ - channel_index = (uint16_t)(tmr_output_struct->oc_idle_state << chx_offset); + chx_offset = (8 + tmr_channel); + chcx_offset = (9 + tmr_channel); - /* get channel complementary idle state bit position in ctrl2 register */ - channel_c_index = (uint16_t)(tmr_output_struct->occ_idle_state << chcx_offset); + /* get channel idle state bit position in ctrl2 register */ + channel_index = (uint16_t)(tmr_output_struct->oc_idle_state << chx_offset); - /* set output channel complementary idle state */ - tmr_x->ctrl2 &= ~(1<ctrl2 |= channel_c_index; + /* get channel complementary idle state bit position in ctrl2 register */ + channel_c_index = (uint16_t)(tmr_output_struct->occ_idle_state << chcx_offset); - /* set output channel idle state */ - tmr_x->ctrl2 &= ~(1<ctrl2 |= channel_index; + /* set output channel complementary idle state */ + tmr_x->ctrl2 &= ~(1 << chcx_offset); + tmr_x->ctrl2 |= channel_c_index; - /* set channel output mode */ - channel = tmr_channel; + /* set output channel idle state */ + tmr_x->ctrl2 &= ~(1 << chx_offset); + tmr_x->ctrl2 |= channel_index; - switch(channel) - { - case TMR_SELECT_CHANNEL_1: - tmr_x->cm1_output_bit.c1octrl = tmr_output_struct->oc_mode; - break; + /* set channel output mode */ + channel = tmr_channel; - case TMR_SELECT_CHANNEL_2: - tmr_x->cm1_output_bit.c2octrl = tmr_output_struct->oc_mode; - break; + switch (channel) { + case TMR_SELECT_CHANNEL_1: + tmr_x->cm1_output_bit.c1octrl = tmr_output_struct->oc_mode; + break; - case TMR_SELECT_CHANNEL_3: - tmr_x->cm2_output_bit.c3octrl = tmr_output_struct->oc_mode; - break; + case TMR_SELECT_CHANNEL_2: + tmr_x->cm1_output_bit.c2octrl = tmr_output_struct->oc_mode; + break; - case TMR_SELECT_CHANNEL_4: - tmr_x->cm2_output_bit.c4octrl = tmr_output_struct->oc_mode; - break; + case TMR_SELECT_CHANNEL_3: + tmr_x->cm2_output_bit.c3octrl = tmr_output_struct->oc_mode; + break; - case TMR_SELECT_CHANNEL_5: - tmr_x->cm3_output_bit.c5octrl = tmr_output_struct->oc_mode; - break; + case TMR_SELECT_CHANNEL_4: + tmr_x->cm2_output_bit.c4octrl = tmr_output_struct->oc_mode; + break; - default: - break; - } + case TMR_SELECT_CHANNEL_5: + tmr_x->cm3_output_bit.c5octrl = tmr_output_struct->oc_mode; + break; - chx_offset = ((tmr_channel * 2) + 1); - chcx_offset = ((tmr_channel * 2) + 3); + default: + break; + } - /* get channel polarity bit position in cctrl register */ - channel_index = (uint16_t)(tmr_output_struct->oc_polarity << chx_offset); + chx_offset = ((tmr_channel * 2) + 1); + chcx_offset = ((tmr_channel * 2) + 3); - /* get channel complementary polarity bit position in cctrl register */ - channel_c_index = (uint16_t)(tmr_output_struct->occ_polarity << chcx_offset); + /* get channel polarity bit position in cctrl register */ + channel_index = (uint16_t)(tmr_output_struct->oc_polarity << chx_offset); - /* set output channel complementary polarity */ - tmr_x->cctrl &= ~(1<cctrl |= channel_c_index; + /* get channel complementary polarity bit position in cctrl register */ + channel_c_index = (uint16_t)(tmr_output_struct->occ_polarity << chcx_offset); - /* set output channel polarity */ - tmr_x->cctrl &= ~(1<cctrl |= channel_index; + /* set output channel complementary polarity */ + tmr_x->cctrl &= ~(1 << chcx_offset); + tmr_x->cctrl |= channel_c_index; - chx_offset = (tmr_channel * 2); - chcx_offset = ((tmr_channel * 2) + 2); + /* set output channel polarity */ + tmr_x->cctrl &= ~(1 << chx_offset); + tmr_x->cctrl |= channel_index; - /* get channel enable bit position in cctrl register */ - channel_index = (uint16_t)(tmr_output_struct->oc_output_state << (tmr_channel * 2)); + chx_offset = (tmr_channel * 2); + chcx_offset = ((tmr_channel * 2) + 2); - /* get channel complementary enable bit position in cctrl register */ - channel_c_index = (uint16_t)(tmr_output_struct->occ_output_state << ((tmr_channel * 2) + 2)); + /* get channel enable bit position in cctrl register */ + channel_index = (uint16_t)(tmr_output_struct->oc_output_state << (tmr_channel * 2)); - /* set output channel complementary enable bit */ - tmr_x->cctrl &= ~(1<cctrl |= channel_c_index; + /* get channel complementary enable bit position in cctrl register */ + channel_c_index = (uint16_t)(tmr_output_struct->occ_output_state << ((tmr_channel * 2) + 2)); - /* set output channel enable bit */ - tmr_x->cctrl &= ~(1<cctrl |= channel_index; + /* set output channel complementary enable bit */ + tmr_x->cctrl &= ~(1 << chcx_offset); + tmr_x->cctrl |= channel_c_index; + + /* set output channel enable bit */ + tmr_x->cctrl &= ~(1 << chx_offset); + tmr_x->cctrl |= channel_index; } /** @@ -454,37 +410,35 @@ void tmr_output_channel_config(tmr_type *tmr_x, tmr_channel_select_type tmr_chan * @retval none */ void tmr_output_channel_mode_select(tmr_type *tmr_x, tmr_channel_select_type tmr_channel, \ - tmr_output_control_mode_type oc_mode) -{ - uint16_t channel; + tmr_output_control_mode_type oc_mode) { + uint16_t channel; - channel = tmr_channel; + channel = tmr_channel; - switch(channel) - { - case TMR_SELECT_CHANNEL_1: - tmr_x->cm1_output_bit.c1octrl = oc_mode; - break; + switch (channel) { + case TMR_SELECT_CHANNEL_1: + tmr_x->cm1_output_bit.c1octrl = oc_mode; + break; - case TMR_SELECT_CHANNEL_2: - tmr_x->cm1_output_bit.c2octrl = oc_mode; - break; + case TMR_SELECT_CHANNEL_2: + tmr_x->cm1_output_bit.c2octrl = oc_mode; + break; - case TMR_SELECT_CHANNEL_3: - tmr_x->cm2_output_bit.c3octrl = oc_mode; - break; + case TMR_SELECT_CHANNEL_3: + tmr_x->cm2_output_bit.c3octrl = oc_mode; + break; - case TMR_SELECT_CHANNEL_4: - tmr_x->cm2_output_bit.c4octrl = oc_mode; - break; + case TMR_SELECT_CHANNEL_4: + tmr_x->cm2_output_bit.c4octrl = oc_mode; + break; - case TMR_SELECT_CHANNEL_5: - tmr_x->cm3_output_bit.c5octrl = oc_mode; - break; + case TMR_SELECT_CHANNEL_5: + tmr_x->cm3_output_bit.c5octrl = oc_mode; + break; - default: - break; - } + default: + break; + } } /** * @brief set tmr period value @@ -497,10 +451,9 @@ void tmr_output_channel_mode_select(tmr_type *tmr_x, tmr_channel_select_type tmr * for 32 bit tmr 0x0000_0000~0xFFFF_FFFF) * @retval none */ -void tmr_period_value_set(tmr_type *tmr_x, uint32_t tmr_pr_value) -{ - /* set tmr period value */ - tmr_x->pr = tmr_pr_value; +void tmr_period_value_set(tmr_type *tmr_x, uint32_t tmr_pr_value) { + /* set tmr period value */ + tmr_x->pr = tmr_pr_value; } /** @@ -513,9 +466,8 @@ void tmr_period_value_set(tmr_type *tmr_x, uint32_t tmr_pr_value) * (for 16 bit tmr 0x0000~0xFFFF, for 32 bit tmr * 0x0000_0000~0xFFFF_FFFF) */ -uint32_t tmr_period_value_get(tmr_type *tmr_x) -{ - return tmr_x->pr; +uint32_t tmr_period_value_get(tmr_type *tmr_x) { + return tmr_x->pr; } /** @@ -536,38 +488,36 @@ uint32_t tmr_period_value_get(tmr_type *tmr_x) * @retval none */ void tmr_channel_value_set(tmr_type *tmr_x, tmr_channel_select_type tmr_channel, \ - uint32_t tmr_channel_value) -{ - uint16_t channel; + uint32_t tmr_channel_value) { + uint16_t channel; - channel = tmr_channel; + channel = tmr_channel; - /* set tmr channel value */ - switch(channel) - { - case TMR_SELECT_CHANNEL_1: - tmr_x->c1dt = tmr_channel_value; - break; + /* set tmr channel value */ + switch (channel) { + case TMR_SELECT_CHANNEL_1: + tmr_x->c1dt = tmr_channel_value; + break; - case TMR_SELECT_CHANNEL_2: - tmr_x->c2dt = tmr_channel_value; - break; + case TMR_SELECT_CHANNEL_2: + tmr_x->c2dt = tmr_channel_value; + break; - case TMR_SELECT_CHANNEL_3: - tmr_x->c3dt = tmr_channel_value; - break; + case TMR_SELECT_CHANNEL_3: + tmr_x->c3dt = tmr_channel_value; + break; - case TMR_SELECT_CHANNEL_4: - tmr_x->c4dt = tmr_channel_value; - break; + case TMR_SELECT_CHANNEL_4: + tmr_x->c4dt = tmr_channel_value; + break; - case TMR_SELECT_CHANNEL_5: - tmr_x->c5dt = tmr_channel_value; - break; + case TMR_SELECT_CHANNEL_5: + tmr_x->c5dt = tmr_channel_value; + break; - default: - break; - } + default: + break; + } } /** @@ -585,41 +535,39 @@ void tmr_channel_value_set(tmr_type *tmr_x, tmr_channel_select_type tmr_channel, * - TMR_SELECT_CHANNEL_5 * @retval tmr channel value */ -uint32_t tmr_channel_value_get(tmr_type *tmr_x, tmr_channel_select_type tmr_channel) -{ - uint32_t cc_value_get = 0; - uint16_t channel; +uint32_t tmr_channel_value_get(tmr_type *tmr_x, tmr_channel_select_type tmr_channel) { + uint32_t cc_value_get = 0; + uint16_t channel; - channel = tmr_channel; + channel = tmr_channel; - /* get tmr channel value */ - switch(channel) - { - case TMR_SELECT_CHANNEL_1: - cc_value_get = tmr_x->c1dt; - break; + /* get tmr channel value */ + switch (channel) { + case TMR_SELECT_CHANNEL_1: + cc_value_get = tmr_x->c1dt; + break; - case TMR_SELECT_CHANNEL_2: - cc_value_get = tmr_x->c2dt; - break; + case TMR_SELECT_CHANNEL_2: + cc_value_get = tmr_x->c2dt; + break; - case TMR_SELECT_CHANNEL_3: - cc_value_get = tmr_x->c3dt; - break; + case TMR_SELECT_CHANNEL_3: + cc_value_get = tmr_x->c3dt; + break; - case TMR_SELECT_CHANNEL_4: - cc_value_get = tmr_x->c4dt; - break; + case TMR_SELECT_CHANNEL_4: + cc_value_get = tmr_x->c4dt; + break; - case TMR_SELECT_CHANNEL_5: - cc_value_get = tmr_x->c5dt; - break; + case TMR_SELECT_CHANNEL_5: + cc_value_get = tmr_x->c5dt; + break; - default: - break; - } + default: + break; + } - return cc_value_get; + return cc_value_get; } /** * @brief set tmr period buffer @@ -630,10 +578,9 @@ uint32_t tmr_channel_value_get(tmr_type *tmr_x, tmr_channel_select_type tmr_chan * @param new_state (TRUE or FALSE) * @retval none */ -void tmr_period_buffer_enable(tmr_type *tmr_x, confirm_state new_state) -{ - /* tmr period buffer set */ - tmr_x->ctrl1_bit.prben = new_state; +void tmr_period_buffer_enable(tmr_type *tmr_x, confirm_state new_state) { + /* tmr period buffer set */ + tmr_x->ctrl1_bit.prben = new_state; } /** @@ -653,38 +600,36 @@ void tmr_period_buffer_enable(tmr_type *tmr_x, confirm_state new_state) * @retval none */ void tmr_output_channel_buffer_enable(tmr_type *tmr_x, tmr_channel_select_type tmr_channel, \ - confirm_state new_state) -{ - uint16_t channel; + confirm_state new_state) { + uint16_t channel; - channel = tmr_channel; + channel = tmr_channel; - /* get tmr channel value */ - switch(channel) - { - case TMR_SELECT_CHANNEL_1: - tmr_x->cm1_output_bit.c1oben = new_state; - break; + /* get tmr channel value */ + switch (channel) { + case TMR_SELECT_CHANNEL_1: + tmr_x->cm1_output_bit.c1oben = new_state; + break; - case TMR_SELECT_CHANNEL_2: - tmr_x->cm1_output_bit.c2oben = new_state; - break; + case TMR_SELECT_CHANNEL_2: + tmr_x->cm1_output_bit.c2oben = new_state; + break; - case TMR_SELECT_CHANNEL_3: - tmr_x->cm2_output_bit.c3oben = new_state; - break; + case TMR_SELECT_CHANNEL_3: + tmr_x->cm2_output_bit.c3oben = new_state; + break; - case TMR_SELECT_CHANNEL_4: - tmr_x->cm2_output_bit.c4oben = new_state; - break; + case TMR_SELECT_CHANNEL_4: + tmr_x->cm2_output_bit.c4oben = new_state; + break; - case TMR_SELECT_CHANNEL_5: - tmr_x->cm3_output_bit.c5oben = new_state; - break; + case TMR_SELECT_CHANNEL_5: + tmr_x->cm3_output_bit.c5oben = new_state; + break; - default: - break; - } + default: + break; + } } /** @@ -704,38 +649,36 @@ void tmr_output_channel_buffer_enable(tmr_type *tmr_x, tmr_channel_select_type t * @retval none */ void tmr_output_channel_immediately_set(tmr_type *tmr_x, tmr_channel_select_type tmr_channel, \ - confirm_state new_state) -{ - uint16_t channel; + confirm_state new_state) { + uint16_t channel; - channel = tmr_channel; + channel = tmr_channel; - /* get tmr channel value */ - switch(channel) - { - case TMR_SELECT_CHANNEL_1: - tmr_x->cm1_output_bit.c1oien = new_state; - break; + /* get tmr channel value */ + switch (channel) { + case TMR_SELECT_CHANNEL_1: + tmr_x->cm1_output_bit.c1oien = new_state; + break; - case TMR_SELECT_CHANNEL_2: - tmr_x->cm1_output_bit.c2oien = new_state; - break; + case TMR_SELECT_CHANNEL_2: + tmr_x->cm1_output_bit.c2oien = new_state; + break; - case TMR_SELECT_CHANNEL_3: - tmr_x->cm2_output_bit.c3oien = new_state; - break; + case TMR_SELECT_CHANNEL_3: + tmr_x->cm2_output_bit.c3oien = new_state; + break; - case TMR_SELECT_CHANNEL_4: - tmr_x->cm2_output_bit.c4oien = new_state; - break; + case TMR_SELECT_CHANNEL_4: + tmr_x->cm2_output_bit.c4oien = new_state; + break; - case TMR_SELECT_CHANNEL_5: - tmr_x->cm3_output_bit.c5oien = new_state; - break; + case TMR_SELECT_CHANNEL_5: + tmr_x->cm3_output_bit.c5oien = new_state; + break; - default: - break; - } + default: + break; + } } /** @@ -755,38 +698,36 @@ void tmr_output_channel_immediately_set(tmr_type *tmr_x, tmr_channel_select_type * @retval none */ void tmr_output_channel_switch_set(tmr_type *tmr_x, tmr_channel_select_type tmr_channel, \ - confirm_state new_state) -{ - uint16_t channel; + confirm_state new_state) { + uint16_t channel; - channel = tmr_channel; + channel = tmr_channel; - /* get tmr channel value */ - switch(channel) - { - case TMR_SELECT_CHANNEL_1: - tmr_x->cm1_output_bit.c1osen = new_state; - break; + /* get tmr channel value */ + switch (channel) { + case TMR_SELECT_CHANNEL_1: + tmr_x->cm1_output_bit.c1osen = new_state; + break; - case TMR_SELECT_CHANNEL_2: - tmr_x->cm1_output_bit.c2osen = new_state; - break; + case TMR_SELECT_CHANNEL_2: + tmr_x->cm1_output_bit.c2osen = new_state; + break; - case TMR_SELECT_CHANNEL_3: - tmr_x->cm2_output_bit.c3osen = new_state; - break; + case TMR_SELECT_CHANNEL_3: + tmr_x->cm2_output_bit.c3osen = new_state; + break; - case TMR_SELECT_CHANNEL_4: - tmr_x->cm2_output_bit.c4osen = new_state; - break; + case TMR_SELECT_CHANNEL_4: + tmr_x->cm2_output_bit.c4osen = new_state; + break; - case TMR_SELECT_CHANNEL_5: - tmr_x->cm3_output_bit.c5osen = new_state; - break; + case TMR_SELECT_CHANNEL_5: + tmr_x->cm3_output_bit.c5osen = new_state; + break; - default: - break; - } + default: + break; + } } /** @@ -797,10 +738,9 @@ void tmr_output_channel_switch_set(tmr_type *tmr_x, tmr_channel_select_type tmr_ * @param new_state (TRUE or FALSE) * @retval none */ -void tmr_one_cycle_mode_enable(tmr_type *tmr_x, confirm_state new_state) -{ - /* tmr one cycle mode enable */ - tmr_x->ctrl1_bit.ocmen = new_state; +void tmr_one_cycle_mode_enable(tmr_type *tmr_x, confirm_state new_state) { + /* tmr one cycle mode enable */ + tmr_x->ctrl1_bit.ocmen = new_state; } /** @@ -811,13 +751,11 @@ void tmr_one_cycle_mode_enable(tmr_type *tmr_x, confirm_state new_state) * @param new_state (TRUE or FALSE) * @retval none */ -void tmr_32_bit_function_enable (tmr_type *tmr_x, confirm_state new_state) -{ - /* tmr 32 bit function(plus mode) enable,only for TMR2/TMR5 */ - if((tmr_x == TMR2) || (tmr_x == TMR5)) - { - tmr_x->ctrl1_bit.pmen = new_state; - } +void tmr_32_bit_function_enable(tmr_type *tmr_x, confirm_state new_state) { + /* tmr 32 bit function(plus mode) enable,only for TMR2/TMR5 */ + if ((tmr_x == TMR2) || (tmr_x == TMR5)) { + tmr_x->ctrl1_bit.pmen = new_state; + } } /** @@ -829,9 +767,8 @@ void tmr_32_bit_function_enable (tmr_type *tmr_x, confirm_state new_state) * @param new_state (TRUE or FALSE) * @retval none */ -void tmr_overflow_request_source_set(tmr_type *tmr_x, confirm_state new_state) -{ - tmr_x->ctrl1_bit.ovfs = new_state; +void tmr_overflow_request_source_set(tmr_type *tmr_x, confirm_state new_state) { + tmr_x->ctrl1_bit.ovfs = new_state; } /** @@ -843,9 +780,8 @@ void tmr_overflow_request_source_set(tmr_type *tmr_x, confirm_state new_state) * @param new_state (TRUE or FALSE) * @retval none */ -void tmr_overflow_event_disable(tmr_type *tmr_x, confirm_state new_state) -{ - tmr_x->ctrl1_bit.ovfen = new_state; +void tmr_overflow_event_disable(tmr_type *tmr_x, confirm_state new_state) { + tmr_x->ctrl1_bit.ovfen = new_state; } /** @@ -865,57 +801,55 @@ void tmr_overflow_event_disable(tmr_type *tmr_x, confirm_state new_state) * @retval none */ void tmr_input_channel_init(tmr_type *tmr_x, tmr_input_config_type *input_struct, \ - tmr_channel_input_divider_type divider_factor) -{ - uint16_t channel = 0; + tmr_channel_input_divider_type divider_factor) { + uint16_t channel = 0; - /* get channel selected */ - channel = input_struct->input_channel_select; + /* get channel selected */ + channel = input_struct->input_channel_select; - switch(channel) - { - case TMR_SELECT_CHANNEL_1: - tmr_x->cctrl_bit.c1en = FALSE; - tmr_x->cctrl_bit.c1p = (uint32_t)input_struct->input_polarity_select; - tmr_x->cctrl_bit.c1cp = (input_struct->input_polarity_select & 0x2) >> 1; - tmr_x->cm1_input_bit.c1c = input_struct->input_mapped_select; - tmr_x->cm1_input_bit.c1df = input_struct->input_filter_value; - tmr_x->cm1_input_bit.c1idiv = divider_factor; - tmr_x->cctrl_bit.c1en = TRUE; - break; + switch (channel) { + case TMR_SELECT_CHANNEL_1: + tmr_x->cctrl_bit.c1en = FALSE; + tmr_x->cctrl_bit.c1p = (uint32_t)input_struct->input_polarity_select; + tmr_x->cctrl_bit.c1cp = (input_struct->input_polarity_select & 0x2) >> 1; + tmr_x->cm1_input_bit.c1c = input_struct->input_mapped_select; + tmr_x->cm1_input_bit.c1df = input_struct->input_filter_value; + tmr_x->cm1_input_bit.c1idiv = divider_factor; + tmr_x->cctrl_bit.c1en = TRUE; + break; - case TMR_SELECT_CHANNEL_2: - tmr_x->cctrl_bit.c2en = FALSE; - tmr_x->cctrl_bit.c2p = (uint32_t)input_struct->input_polarity_select; - tmr_x->cctrl_bit.c2cp = (input_struct->input_polarity_select & 0x2) >> 1; - tmr_x->cm1_input_bit.c2c = input_struct->input_mapped_select; - tmr_x->cm1_input_bit.c2df = input_struct->input_filter_value; - tmr_x->cm1_input_bit.c2idiv = divider_factor; - tmr_x->cctrl_bit.c2en = TRUE; - break; + case TMR_SELECT_CHANNEL_2: + tmr_x->cctrl_bit.c2en = FALSE; + tmr_x->cctrl_bit.c2p = (uint32_t)input_struct->input_polarity_select; + tmr_x->cctrl_bit.c2cp = (input_struct->input_polarity_select & 0x2) >> 1; + tmr_x->cm1_input_bit.c2c = input_struct->input_mapped_select; + tmr_x->cm1_input_bit.c2df = input_struct->input_filter_value; + tmr_x->cm1_input_bit.c2idiv = divider_factor; + tmr_x->cctrl_bit.c2en = TRUE; + break; - case TMR_SELECT_CHANNEL_3: - tmr_x->cctrl_bit.c3en = FALSE; - tmr_x->cctrl_bit.c3p = (uint32_t)input_struct->input_polarity_select; - tmr_x->cctrl_bit.c3cp = (input_struct->input_polarity_select & 0x2) >> 1; - tmr_x->cm2_input_bit.c3c = input_struct->input_mapped_select; - tmr_x->cm2_input_bit.c3df = input_struct->input_filter_value; - tmr_x->cm2_input_bit.c3idiv = divider_factor; - tmr_x->cctrl_bit.c3en = TRUE; - break; + case TMR_SELECT_CHANNEL_3: + tmr_x->cctrl_bit.c3en = FALSE; + tmr_x->cctrl_bit.c3p = (uint32_t)input_struct->input_polarity_select; + tmr_x->cctrl_bit.c3cp = (input_struct->input_polarity_select & 0x2) >> 1; + tmr_x->cm2_input_bit.c3c = input_struct->input_mapped_select; + tmr_x->cm2_input_bit.c3df = input_struct->input_filter_value; + tmr_x->cm2_input_bit.c3idiv = divider_factor; + tmr_x->cctrl_bit.c3en = TRUE; + break; - case TMR_SELECT_CHANNEL_4: - tmr_x->cctrl_bit.c4en = FALSE; - tmr_x->cctrl_bit.c4p = (uint32_t)input_struct->input_polarity_select; - tmr_x->cm2_input_bit.c4c = input_struct->input_mapped_select; - tmr_x->cm2_input_bit.c4df = input_struct->input_filter_value; - tmr_x->cm2_input_bit.c4idiv = divider_factor; - tmr_x->cctrl_bit.c4en = TRUE; - break; + case TMR_SELECT_CHANNEL_4: + tmr_x->cctrl_bit.c4en = FALSE; + tmr_x->cctrl_bit.c4p = (uint32_t)input_struct->input_polarity_select; + tmr_x->cm2_input_bit.c4c = input_struct->input_mapped_select; + tmr_x->cm2_input_bit.c4df = input_struct->input_filter_value; + tmr_x->cm2_input_bit.c4idiv = divider_factor; + tmr_x->cctrl_bit.c4en = TRUE; + break; - default: - break; - } + default: + break; + } } /** @@ -936,45 +870,43 @@ void tmr_input_channel_init(tmr_type *tmr_x, tmr_input_config_type *input_struct * @param new_state (TRUE or FALSE) * @retval none */ -void tmr_channel_enable(tmr_type *tmr_x, tmr_channel_select_type tmr_channel, confirm_state new_state) -{ - uint16_t channel; +void tmr_channel_enable(tmr_type *tmr_x, tmr_channel_select_type tmr_channel, confirm_state new_state) { + uint16_t channel; - channel = tmr_channel; + channel = tmr_channel; - switch(channel) - { - case TMR_SELECT_CHANNEL_1: - tmr_x->cctrl_bit.c1en = new_state; - break; + switch (channel) { + case TMR_SELECT_CHANNEL_1: + tmr_x->cctrl_bit.c1en = new_state; + break; - case TMR_SELECT_CHANNEL_1C: - tmr_x->cctrl_bit.c1cen = new_state; - break; + case TMR_SELECT_CHANNEL_1C: + tmr_x->cctrl_bit.c1cen = new_state; + break; - case TMR_SELECT_CHANNEL_2: - tmr_x->cctrl_bit.c2en = new_state; - break; + case TMR_SELECT_CHANNEL_2: + tmr_x->cctrl_bit.c2en = new_state; + break; - case TMR_SELECT_CHANNEL_2C: - tmr_x->cctrl_bit.c2cen = new_state; - break; + case TMR_SELECT_CHANNEL_2C: + tmr_x->cctrl_bit.c2cen = new_state; + break; - case TMR_SELECT_CHANNEL_3: - tmr_x->cctrl_bit.c3en = new_state; - break; + case TMR_SELECT_CHANNEL_3: + tmr_x->cctrl_bit.c3en = new_state; + break; - case TMR_SELECT_CHANNEL_3C: - tmr_x->cctrl_bit.c3cen = new_state; - break; + case TMR_SELECT_CHANNEL_3C: + tmr_x->cctrl_bit.c3cen = new_state; + break; - case TMR_SELECT_CHANNEL_4: - tmr_x->cctrl_bit.c4en = new_state; - break; + case TMR_SELECT_CHANNEL_4: + tmr_x->cctrl_bit.c4en = new_state; + break; - default: - break; - } + default: + break; + } } /** @@ -993,33 +925,31 @@ void tmr_channel_enable(tmr_type *tmr_x, tmr_channel_select_type tmr_channel, co * @retval none */ void tmr_input_channel_filter_set(tmr_type *tmr_x, tmr_channel_select_type tmr_channel, \ - uint16_t filter_value) -{ - uint16_t channel; + uint16_t filter_value) { + uint16_t channel; - channel = tmr_channel; + channel = tmr_channel; - switch(channel) - { - case TMR_SELECT_CHANNEL_1: - tmr_x->cm1_input_bit.c1df = filter_value; - break; + switch (channel) { + case TMR_SELECT_CHANNEL_1: + tmr_x->cm1_input_bit.c1df = filter_value; + break; - case TMR_SELECT_CHANNEL_2: - tmr_x->cm1_input_bit.c2df = filter_value; - break; + case TMR_SELECT_CHANNEL_2: + tmr_x->cm1_input_bit.c2df = filter_value; + break; - case TMR_SELECT_CHANNEL_3: - tmr_x->cm2_input_bit.c3df = filter_value; - break; + case TMR_SELECT_CHANNEL_3: + tmr_x->cm2_input_bit.c3df = filter_value; + break; - case TMR_SELECT_CHANNEL_4: - tmr_x->cm2_input_bit.c4df = filter_value; - break; + case TMR_SELECT_CHANNEL_4: + tmr_x->cm2_input_bit.c4df = filter_value; + break; - default: - break; - } + default: + break; + } } /** @@ -1039,100 +969,86 @@ void tmr_input_channel_filter_set(tmr_type *tmr_x, tmr_channel_select_type tmr_c * @retval none */ void tmr_pwm_input_config(tmr_type *tmr_x, tmr_input_config_type *input_struct, \ - tmr_channel_input_divider_type divider_factor) -{ - uint16_t channel = 0; + tmr_channel_input_divider_type divider_factor) { + uint16_t channel = 0; - /* get channel selected */ - channel = input_struct->input_channel_select; + /* get channel selected */ + channel = input_struct->input_channel_select; - switch(channel) - { - case TMR_SELECT_CHANNEL_1: - if(input_struct->input_polarity_select == TMR_INPUT_RISING_EDGE) - { - /* set channel polarity */ - tmr_x->cctrl_bit.c1p = TMR_INPUT_RISING_EDGE; - tmr_x->cctrl_bit.c2p = TMR_INPUT_FALLING_EDGE; - } - else if(input_struct->input_polarity_select == TMR_INPUT_FALLING_EDGE) - { - /* set channel polarity */ - tmr_x->cctrl_bit.c1p = TMR_INPUT_FALLING_EDGE; - tmr_x->cctrl_bit.c2p = TMR_INPUT_RISING_EDGE; - } + switch (channel) { + case TMR_SELECT_CHANNEL_1: + if (input_struct->input_polarity_select == TMR_INPUT_RISING_EDGE) { + /* set channel polarity */ + tmr_x->cctrl_bit.c1p = TMR_INPUT_RISING_EDGE; + tmr_x->cctrl_bit.c2p = TMR_INPUT_FALLING_EDGE; + } else if (input_struct->input_polarity_select == TMR_INPUT_FALLING_EDGE) { + /* set channel polarity */ + tmr_x->cctrl_bit.c1p = TMR_INPUT_FALLING_EDGE; + tmr_x->cctrl_bit.c2p = TMR_INPUT_RISING_EDGE; + } - if(input_struct->input_mapped_select == TMR_CC_CHANNEL_MAPPED_DIRECT) - { - /* ic1 is mapped on ti1 */ - tmr_x->cm1_input_bit.c1c = TMR_CC_CHANNEL_MAPPED_DIRECT; + if (input_struct->input_mapped_select == TMR_CC_CHANNEL_MAPPED_DIRECT) { + /* ic1 is mapped on ti1 */ + tmr_x->cm1_input_bit.c1c = TMR_CC_CHANNEL_MAPPED_DIRECT; - /* ic1 is mapped on ti2 */ - tmr_x->cm1_input_bit.c2c = TMR_CC_CHANNEL_MAPPED_INDIRECT; - } - else if(input_struct->input_mapped_select == TMR_CC_CHANNEL_MAPPED_INDIRECT) - { - /* ic1 is mapped on ti1 */ - tmr_x->cm1_input_bit.c1c = TMR_CC_CHANNEL_MAPPED_INDIRECT; + /* ic1 is mapped on ti2 */ + tmr_x->cm1_input_bit.c2c = TMR_CC_CHANNEL_MAPPED_INDIRECT; + } else if (input_struct->input_mapped_select == TMR_CC_CHANNEL_MAPPED_INDIRECT) { + /* ic1 is mapped on ti1 */ + tmr_x->cm1_input_bit.c1c = TMR_CC_CHANNEL_MAPPED_INDIRECT; - /* ic1 is mapped on ti2 */ - tmr_x->cm1_input_bit.c2c = TMR_CC_CHANNEL_MAPPED_DIRECT; - } + /* ic1 is mapped on ti2 */ + tmr_x->cm1_input_bit.c2c = TMR_CC_CHANNEL_MAPPED_DIRECT; + } - /* set input ch1 and ch2 filter value*/ - tmr_x->cm1_input_bit.c1df = input_struct->input_filter_value; - tmr_x->cm1_input_bit.c2df = input_struct->input_filter_value; + /* set input ch1 and ch2 filter value*/ + tmr_x->cm1_input_bit.c1df = input_struct->input_filter_value; + tmr_x->cm1_input_bit.c2df = input_struct->input_filter_value; - /*set input ch1 and ch2 divider value*/ - tmr_x->cm1_input_bit.c1idiv = divider_factor; - tmr_x->cm1_input_bit.c2idiv = divider_factor; + /*set input ch1 and ch2 divider value*/ + tmr_x->cm1_input_bit.c1idiv = divider_factor; + tmr_x->cm1_input_bit.c2idiv = divider_factor; - tmr_x->cctrl_bit.c1en = TRUE; - tmr_x->cctrl_bit.c2en = TRUE; - break; + tmr_x->cctrl_bit.c1en = TRUE; + tmr_x->cctrl_bit.c2en = TRUE; + break; - case TMR_SELECT_CHANNEL_2: - if(input_struct->input_polarity_select == TMR_INPUT_RISING_EDGE) - { - /* set channel polarity */ - tmr_x->cctrl_bit.c2p = TMR_INPUT_RISING_EDGE; - tmr_x->cctrl_bit.c1p = TMR_INPUT_FALLING_EDGE; - } - else if(input_struct->input_polarity_select == TMR_INPUT_FALLING_EDGE) - { - /* set channel polarity */ - tmr_x->cctrl_bit.c2p = TMR_INPUT_FALLING_EDGE; - tmr_x->cctrl_bit.c1p = TMR_INPUT_RISING_EDGE; - } + case TMR_SELECT_CHANNEL_2: + if (input_struct->input_polarity_select == TMR_INPUT_RISING_EDGE) { + /* set channel polarity */ + tmr_x->cctrl_bit.c2p = TMR_INPUT_RISING_EDGE; + tmr_x->cctrl_bit.c1p = TMR_INPUT_FALLING_EDGE; + } else if (input_struct->input_polarity_select == TMR_INPUT_FALLING_EDGE) { + /* set channel polarity */ + tmr_x->cctrl_bit.c2p = TMR_INPUT_FALLING_EDGE; + tmr_x->cctrl_bit.c1p = TMR_INPUT_RISING_EDGE; + } - if(input_struct->input_mapped_select == TMR_CC_CHANNEL_MAPPED_DIRECT) - { - /* set mapped direct */ - tmr_x->cm1_input_bit.c2c = TMR_CC_CHANNEL_MAPPED_DIRECT; - tmr_x->cm1_input_bit.c1c = TMR_CC_CHANNEL_MAPPED_INDIRECT; - } - else if(input_struct->input_mapped_select == TMR_CC_CHANNEL_MAPPED_INDIRECT) - { - /* set mapped direct */ - tmr_x->cm1_input_bit.c2c = TMR_CC_CHANNEL_MAPPED_INDIRECT; - tmr_x->cm1_input_bit.c1c = TMR_CC_CHANNEL_MAPPED_DIRECT; - } + if (input_struct->input_mapped_select == TMR_CC_CHANNEL_MAPPED_DIRECT) { + /* set mapped direct */ + tmr_x->cm1_input_bit.c2c = TMR_CC_CHANNEL_MAPPED_DIRECT; + tmr_x->cm1_input_bit.c1c = TMR_CC_CHANNEL_MAPPED_INDIRECT; + } else if (input_struct->input_mapped_select == TMR_CC_CHANNEL_MAPPED_INDIRECT) { + /* set mapped direct */ + tmr_x->cm1_input_bit.c2c = TMR_CC_CHANNEL_MAPPED_INDIRECT; + tmr_x->cm1_input_bit.c1c = TMR_CC_CHANNEL_MAPPED_DIRECT; + } - /* set input ch1 and ch2 filter value*/ - tmr_x->cm1_input_bit.c1df = input_struct->input_filter_value; - tmr_x->cm1_input_bit.c2df = input_struct->input_filter_value; + /* set input ch1 and ch2 filter value*/ + tmr_x->cm1_input_bit.c1df = input_struct->input_filter_value; + tmr_x->cm1_input_bit.c2df = input_struct->input_filter_value; - /*set input ch1 and ch2 divider value*/ - tmr_x->cm1_input_bit.c1idiv = divider_factor; - tmr_x->cm1_input_bit.c2idiv = divider_factor; + /*set input ch1 and ch2 divider value*/ + tmr_x->cm1_input_bit.c1idiv = divider_factor; + tmr_x->cm1_input_bit.c2idiv = divider_factor; - tmr_x->cctrl_bit.c1en = TRUE; - tmr_x->cctrl_bit.c2en = TRUE; - break; + tmr_x->cctrl_bit.c1en = TRUE; + tmr_x->cctrl_bit.c2en = TRUE; + break; - default: - break; - } + default: + break; + } } /** @@ -1146,9 +1062,8 @@ void tmr_pwm_input_config(tmr_type *tmr_x, tmr_input_config_type *input_struct, * - TMR_CHANEL1_2_3_CONNECTED_C1IRAW_XOR * @retval none */ -void tmr_channel1_input_select(tmr_type *tmr_x, tmr_channel1_input_connected_type ch1_connect) -{ - tmr_x->ctrl2_bit.c1insel = ch1_connect; +void tmr_channel1_input_select(tmr_type *tmr_x, tmr_channel1_input_connected_type ch1_connect) { + tmr_x->ctrl2_bit.c1insel = ch1_connect; } /** @@ -1172,33 +1087,31 @@ void tmr_channel1_input_select(tmr_type *tmr_x, tmr_channel1_input_connected_typ * @retval none */ void tmr_input_channel_divider_set(tmr_type *tmr_x, tmr_channel_select_type tmr_channel, \ - tmr_channel_input_divider_type divider_factor) -{ - uint16_t channel; + tmr_channel_input_divider_type divider_factor) { + uint16_t channel; - channel = tmr_channel; + channel = tmr_channel; - switch(channel) - { - case TMR_SELECT_CHANNEL_1: - tmr_x->cm1_input_bit.c1idiv = divider_factor; - break; + switch (channel) { + case TMR_SELECT_CHANNEL_1: + tmr_x->cm1_input_bit.c1idiv = divider_factor; + break; - case TMR_SELECT_CHANNEL_2: - tmr_x->cm1_input_bit.c2idiv = divider_factor; - break; + case TMR_SELECT_CHANNEL_2: + tmr_x->cm1_input_bit.c2idiv = divider_factor; + break; - case TMR_SELECT_CHANNEL_3: - tmr_x->cm2_input_bit.c3idiv = divider_factor; - break; + case TMR_SELECT_CHANNEL_3: + tmr_x->cm2_input_bit.c3idiv = divider_factor; + break; - case TMR_SELECT_CHANNEL_4: - tmr_x->cm2_input_bit.c4idiv = divider_factor; - break; + case TMR_SELECT_CHANNEL_4: + tmr_x->cm2_input_bit.c4idiv = divider_factor; + break; - default: - break; - } + default: + break; + } } /** @@ -1218,9 +1131,8 @@ void tmr_input_channel_divider_set(tmr_type *tmr_x, tmr_channel_select_type tmr_ * - TMR_PRIMARY_SEL_C4ORAW * @retval none */ -void tmr_primary_mode_select(tmr_type *tmr_x, tmr_primary_select_type primary_mode) -{ - tmr_x->ctrl2_bit.ptos = primary_mode; +void tmr_primary_mode_select(tmr_type *tmr_x, tmr_primary_select_type primary_mode) { + tmr_x->ctrl2_bit.ptos = primary_mode; } /** @@ -1241,9 +1153,8 @@ void tmr_primary_mode_select(tmr_type *tmr_x, tmr_primary_select_type primary_mo * @retval none */ -void tmr_sub_mode_select(tmr_type *tmr_x, tmr_sub_mode_select_type sub_mode) -{ - tmr_x->stctrl_bit.smsel = sub_mode; +void tmr_sub_mode_select(tmr_type *tmr_x, tmr_sub_mode_select_type sub_mode) { + tmr_x->stctrl_bit.smsel = sub_mode; } /** @@ -1257,9 +1168,8 @@ void tmr_sub_mode_select(tmr_type *tmr_x, tmr_sub_mode_select_type sub_mode) * - TMR_DMA_REQUEST_BY_OVERFLOW * @retval none */ -void tmr_channel_dma_select(tmr_type *tmr_x, tmr_dma_request_source_type cc_dma_select) -{ - tmr_x->ctrl2_bit.drs = cc_dma_select; +void tmr_channel_dma_select(tmr_type *tmr_x, tmr_dma_request_source_type cc_dma_select) { + tmr_x->ctrl2_bit.drs = cc_dma_select; } /** @@ -1270,9 +1180,8 @@ void tmr_channel_dma_select(tmr_type *tmr_x, tmr_dma_request_source_type cc_dma_ * @param new_state (TRUE or FALSE) * @retval none */ -void tmr_hall_select(tmr_type *tmr_x, confirm_state new_state) -{ - tmr_x->ctrl2_bit.ccfs = new_state; +void tmr_hall_select(tmr_type *tmr_x, confirm_state new_state) { + tmr_x->ctrl2_bit.ccfs = new_state; } /** @@ -1283,9 +1192,8 @@ void tmr_hall_select(tmr_type *tmr_x, confirm_state new_state) * @param new_state (TRUE or FALSE) * @retval none */ -void tmr_channel_buffer_enable(tmr_type *tmr_x, confirm_state new_state) -{ - tmr_x->ctrl2_bit.cbctrl = new_state; +void tmr_channel_buffer_enable(tmr_type *tmr_x, confirm_state new_state) { + tmr_x->ctrl2_bit.cbctrl = new_state; } /** @@ -1296,9 +1204,8 @@ void tmr_channel_buffer_enable(tmr_type *tmr_x, confirm_state new_state) * @param new_state (TRUE or FALSE) * @retval none */ -void tmr_trgout2_enable(tmr_type *tmr_x, confirm_state new_state) -{ - tmr_x->ctrl2_bit.trgout2en = new_state; +void tmr_trgout2_enable(tmr_type *tmr_x, confirm_state new_state) { + tmr_x->ctrl2_bit.trgout2en = new_state; } /** @@ -1318,9 +1225,8 @@ void tmr_trgout2_enable(tmr_type *tmr_x, confirm_state new_state) * - TMR_SUB_INPUT_SEL_EXTIN * @retval none */ -void tmr_trigger_input_select(tmr_type *tmr_x, sub_tmr_input_sel_type trigger_select) -{ - tmr_x->stctrl_bit.stis = trigger_select; +void tmr_trigger_input_select(tmr_type *tmr_x, sub_tmr_input_sel_type trigger_select) { + tmr_x->stctrl_bit.stis = trigger_select; } /** @@ -1331,9 +1237,8 @@ void tmr_trigger_input_select(tmr_type *tmr_x, sub_tmr_input_sel_type trigger_se * @param new_state (TRUE or FALSE) * @retval none */ -void tmr_sub_sync_mode_set(tmr_type *tmr_x, confirm_state new_state) -{ - tmr_x->stctrl_bit.sts = new_state; +void tmr_sub_sync_mode_set(tmr_type *tmr_x, confirm_state new_state) { + tmr_x->stctrl_bit.sts = new_state; } /** @@ -1354,16 +1259,12 @@ void tmr_sub_sync_mode_set(tmr_type *tmr_x, confirm_state new_state) * @param new_state (TRUE or FALSE) * @retval none */ -void tmr_dma_request_enable(tmr_type *tmr_x, tmr_dma_request_type dma_request, confirm_state new_state) -{ - if(new_state == TRUE) - { - tmr_x->iden |= dma_request; - } - else if(new_state == FALSE) - { - tmr_x->iden &= ~dma_request; - } +void tmr_dma_request_enable(tmr_type *tmr_x, tmr_dma_request_type dma_request, confirm_state new_state) { + if (new_state == TRUE) { + tmr_x->iden |= dma_request; + } else if (new_state == FALSE) { + tmr_x->iden &= ~dma_request; + } } /** @@ -1385,16 +1286,12 @@ void tmr_dma_request_enable(tmr_type *tmr_x, tmr_dma_request_type dma_request, c * @param new_state (TRUE or FALSE) * @retval none */ -void tmr_interrupt_enable(tmr_type *tmr_x, uint32_t tmr_interrupt, confirm_state new_state) -{ - if(new_state == TRUE) - { - tmr_x->iden |= tmr_interrupt; - } - else if(new_state == FALSE) - { - tmr_x->iden &= ~tmr_interrupt; - } +void tmr_interrupt_enable(tmr_type *tmr_x, uint32_t tmr_interrupt, confirm_state new_state) { + if (new_state == TRUE) { + tmr_x->iden |= tmr_interrupt; + } else if (new_state == FALSE) { + tmr_x->iden &= ~tmr_interrupt; + } } /** @@ -1415,20 +1312,16 @@ void tmr_interrupt_enable(tmr_type *tmr_x, uint32_t tmr_interrupt, confirm_state * - TMR_BRK_FLAG * @retval state of tmr interrupt flag */ -flag_status tmr_interrupt_flag_get(tmr_type *tmr_x, uint32_t tmr_flag) -{ - flag_status status = RESET; +flag_status tmr_interrupt_flag_get(tmr_type *tmr_x, uint32_t tmr_flag) { + flag_status status = RESET; - if((tmr_x->ists & tmr_flag) && (tmr_x->iden & tmr_flag)) - { - status = SET; - } - else - { - status = RESET; - } + if ((tmr_x->ists & tmr_flag) && (tmr_x->iden & tmr_flag)) { + status = SET; + } else { + status = RESET; + } - return status; + return status; } /** @@ -1454,20 +1347,16 @@ flag_status tmr_interrupt_flag_get(tmr_type *tmr_x, uint32_t tmr_flag) * - TMR_C4_RECAPTURE_FLAG * @retval state of tmr flag */ -flag_status tmr_flag_get(tmr_type *tmr_x, uint32_t tmr_flag) -{ - flag_status status = RESET; +flag_status tmr_flag_get(tmr_type *tmr_x, uint32_t tmr_flag) { + flag_status status = RESET; - if((tmr_x->ists & tmr_flag) != RESET) - { - status = SET; - } - else - { - status = RESET; - } + if ((tmr_x->ists & tmr_flag) != RESET) { + status = SET; + } else { + status = RESET; + } - return status; + return status; } /** @@ -1493,9 +1382,8 @@ flag_status tmr_flag_get(tmr_type *tmr_x, uint32_t tmr_flag) * - TMR_C4_RECAPTURE_FLAG * @retval none */ -void tmr_flag_clear(tmr_type *tmr_x, uint32_t tmr_flag) -{ - tmr_x->ists = ~tmr_flag; +void tmr_flag_clear(tmr_type *tmr_x, uint32_t tmr_flag) { + tmr_x->ists = ~tmr_flag; } /** @@ -1516,9 +1404,8 @@ void tmr_flag_clear(tmr_type *tmr_x, uint32_t tmr_flag) * - TMR_BRK_SWTRIG * @retval none */ -void tmr_event_sw_trigger(tmr_type *tmr_x, tmr_event_trigger_type tmr_event) -{ - tmr_x->swevt |= tmr_event; +void tmr_event_sw_trigger(tmr_type *tmr_x, tmr_event_trigger_type tmr_event) { + tmr_x->swevt |= tmr_event; } /** @@ -1529,9 +1416,8 @@ void tmr_event_sw_trigger(tmr_type *tmr_x, tmr_event_trigger_type tmr_event) * @param new_state (TRUE or FALSE) * @retval none */ -void tmr_output_enable(tmr_type *tmr_x, confirm_state new_state) -{ - tmr_x->brk_bit.oen = new_state; +void tmr_output_enable(tmr_type *tmr_x, confirm_state new_state) { + tmr_x->brk_bit.oen = new_state; } /** @@ -1541,9 +1427,8 @@ void tmr_output_enable(tmr_type *tmr_x, confirm_state new_state) * TMR1, TMR2, TMR3, TMR4, TMR5, TMR8, TMR9, TMR12, TMR20 * @retval none */ -void tmr_internal_clock_set(tmr_type *tmr_x) -{ - tmr_x->stctrl_bit.smsel = TMR_SUB_MODE_DIABLE; +void tmr_internal_clock_set(tmr_type *tmr_x) { + tmr_x->stctrl_bit.smsel = TMR_SUB_MODE_DIABLE; } /** @@ -1568,45 +1453,43 @@ void tmr_internal_clock_set(tmr_type *tmr_x) * @retval none */ void tmr_output_channel_polarity_set(tmr_type *tmr_x, tmr_channel_select_type tmr_channel, \ - tmr_polarity_active_type oc_polarity) -{ - uint16_t channel; + tmr_polarity_active_type oc_polarity) { + uint16_t channel; - channel = tmr_channel; + channel = tmr_channel; - switch(channel) - { - case TMR_SELECT_CHANNEL_1: - tmr_x->cctrl_bit.c1p = (uint32_t)oc_polarity; - break; + switch (channel) { + case TMR_SELECT_CHANNEL_1: + tmr_x->cctrl_bit.c1p = (uint32_t)oc_polarity; + break; - case TMR_SELECT_CHANNEL_2: - tmr_x->cctrl_bit.c2p = (uint32_t)oc_polarity; - break; + case TMR_SELECT_CHANNEL_2: + tmr_x->cctrl_bit.c2p = (uint32_t)oc_polarity; + break; - case TMR_SELECT_CHANNEL_3: - tmr_x->cctrl_bit.c3p = (uint32_t)oc_polarity; - break; + case TMR_SELECT_CHANNEL_3: + tmr_x->cctrl_bit.c3p = (uint32_t)oc_polarity; + break; - case TMR_SELECT_CHANNEL_4: - tmr_x->cctrl_bit.c4p = (uint32_t)oc_polarity; - break; + case TMR_SELECT_CHANNEL_4: + tmr_x->cctrl_bit.c4p = (uint32_t)oc_polarity; + break; - case TMR_SELECT_CHANNEL_1C: - tmr_x->cctrl_bit.c1cp = (uint32_t)oc_polarity; - break; + case TMR_SELECT_CHANNEL_1C: + tmr_x->cctrl_bit.c1cp = (uint32_t)oc_polarity; + break; - case TMR_SELECT_CHANNEL_2C: - tmr_x->cctrl_bit.c2cp = (uint32_t)oc_polarity; - break; + case TMR_SELECT_CHANNEL_2C: + tmr_x->cctrl_bit.c2cp = (uint32_t)oc_polarity; + break; - case TMR_SELECT_CHANNEL_3C: - tmr_x->cctrl_bit.c3cp = (uint32_t)oc_polarity; - break; + case TMR_SELECT_CHANNEL_3C: + tmr_x->cctrl_bit.c3cp = (uint32_t)oc_polarity; + break; - default: - break; - } + default: + break; + } } /** @@ -1628,11 +1511,10 @@ void tmr_output_channel_polarity_set(tmr_type *tmr_x, tmr_channel_select_type tm * @retval none */ void tmr_external_clock_config(tmr_type *tmr_x, tmr_external_signal_divider_type es_divide, \ - tmr_external_signal_polarity_type es_polarity, uint16_t es_filter) -{ - tmr_x->stctrl_bit.esdiv = es_divide; - tmr_x->stctrl_bit.esp = es_polarity; - tmr_x->stctrl_bit.esf = es_filter; + tmr_external_signal_polarity_type es_polarity, uint16_t es_filter) { + tmr_x->stctrl_bit.esdiv = es_divide; + tmr_x->stctrl_bit.esp = es_polarity; + tmr_x->stctrl_bit.esf = es_filter; } /** @@ -1654,11 +1536,10 @@ void tmr_external_clock_config(tmr_type *tmr_x, tmr_external_signal_divider_type * @retval none */ void tmr_external_clock_mode1_config(tmr_type *tmr_x, tmr_external_signal_divider_type es_divide, \ - tmr_external_signal_polarity_type es_polarity, uint16_t es_filter) -{ - tmr_external_clock_config(tmr_x, es_divide, es_polarity, es_filter); - tmr_x->stctrl_bit.smsel = TMR_SUB_EXTERNAL_CLOCK_MODE_A; - tmr_x->stctrl_bit.stis = TMR_SUB_INPUT_SEL_EXTIN; + tmr_external_signal_polarity_type es_polarity, uint16_t es_filter) { + tmr_external_clock_config(tmr_x, es_divide, es_polarity, es_filter); + tmr_x->stctrl_bit.smsel = TMR_SUB_EXTERNAL_CLOCK_MODE_A; + tmr_x->stctrl_bit.stis = TMR_SUB_INPUT_SEL_EXTIN; } /** @@ -1680,10 +1561,9 @@ void tmr_external_clock_mode1_config(tmr_type *tmr_x, tmr_external_signal_divide * @retval none */ void tmr_external_clock_mode2_config(tmr_type *tmr_x, tmr_external_signal_divider_type es_divide, \ - tmr_external_signal_polarity_type es_polarity, uint16_t es_filter) -{ - tmr_external_clock_config(tmr_x, es_divide, es_polarity, es_filter); - tmr_x->stctrl_bit.ecmben = TRUE; + tmr_external_signal_polarity_type es_polarity, uint16_t es_filter) { + tmr_external_clock_config(tmr_x, es_divide, es_polarity, es_filter); + tmr_x->stctrl_bit.ecmben = TRUE; } /** @@ -1709,21 +1589,20 @@ void tmr_external_clock_mode2_config(tmr_type *tmr_x, tmr_external_signal_divide * @retval none */ void tmr_encoder_mode_config(tmr_type *tmr_x, tmr_encoder_mode_type encoder_mode, tmr_input_polarity_type \ - ic1_polarity, tmr_input_polarity_type ic2_polarity) -{ - tmr_x->stctrl_bit.smsel = encoder_mode; + ic1_polarity, tmr_input_polarity_type ic2_polarity) { + tmr_x->stctrl_bit.smsel = encoder_mode; - /* set ic1 polarity */ - tmr_x->cctrl_bit.c1p = (ic1_polarity & 0x1); - tmr_x->cctrl_bit.c1cp = (ic1_polarity >> 1); - /* set ic1 as input channel */ - tmr_x->cm1_input_bit.c1c = TMR_CC_CHANNEL_MAPPED_DIRECT; + /* set ic1 polarity */ + tmr_x->cctrl_bit.c1p = (ic1_polarity & 0x1); + tmr_x->cctrl_bit.c1cp = (ic1_polarity >> 1); + /* set ic1 as input channel */ + tmr_x->cm1_input_bit.c1c = TMR_CC_CHANNEL_MAPPED_DIRECT; - /* set ic2 polarity */ - tmr_x->cctrl_bit.c2p = (ic2_polarity & 0x1); - tmr_x->cctrl_bit.c2cp = (ic2_polarity >> 1); - /* set ic2 as input channel */ - tmr_x->cm1_input_bit.c2c = TMR_CC_CHANNEL_MAPPED_DIRECT; + /* set ic2 polarity */ + tmr_x->cctrl_bit.c2p = (ic2_polarity & 0x1); + tmr_x->cctrl_bit.c2cp = (ic2_polarity >> 1); + /* set ic2 as input channel */ + tmr_x->cm1_input_bit.c2c = TMR_CC_CHANNEL_MAPPED_DIRECT; } /** @@ -1746,37 +1625,35 @@ void tmr_encoder_mode_config(tmr_type *tmr_x, tmr_encoder_mode_type encoder_mode * @retval none */ void tmr_force_output_set(tmr_type *tmr_x, tmr_channel_select_type tmr_channel, \ - tmr_force_output_type force_output) -{ - uint16_t channel; + tmr_force_output_type force_output) { + uint16_t channel; - channel = tmr_channel; + channel = tmr_channel; - switch(channel) - { - case TMR_SELECT_CHANNEL_1: - tmr_x->cm1_output_bit.c1octrl = force_output; - break; + switch (channel) { + case TMR_SELECT_CHANNEL_1: + tmr_x->cm1_output_bit.c1octrl = force_output; + break; - case TMR_SELECT_CHANNEL_2: - tmr_x->cm1_output_bit.c2octrl = force_output; - break; + case TMR_SELECT_CHANNEL_2: + tmr_x->cm1_output_bit.c2octrl = force_output; + break; - case TMR_SELECT_CHANNEL_3: - tmr_x->cm2_output_bit.c3octrl = force_output; - break; + case TMR_SELECT_CHANNEL_3: + tmr_x->cm2_output_bit.c3octrl = force_output; + break; - case TMR_SELECT_CHANNEL_4: - tmr_x->cm2_output_bit.c4octrl = force_output; - break; + case TMR_SELECT_CHANNEL_4: + tmr_x->cm2_output_bit.c4octrl = force_output; + break; - case TMR_SELECT_CHANNEL_5: - tmr_x->cm3_output_bit.c5octrl = force_output; - break; + case TMR_SELECT_CHANNEL_5: + tmr_x->cm3_output_bit.c5octrl = force_output; + break; - default: - break; - } + default: + break; + } } /** @@ -1816,10 +1693,9 @@ void tmr_force_output_set(tmr_type *tmr_x, tmr_channel_select_type tmr_channel, * @retval none */ void tmr_dma_control_config(tmr_type *tmr_x, tmr_dma_transfer_length_type dma_length, \ - tmr_dma_address_type dma_base_address) -{ - tmr_x->dmactrl_bit.dtb = dma_length; - tmr_x->dmactrl_bit.addr = dma_base_address; + tmr_dma_address_type dma_base_address) { + tmr_x->dmactrl_bit.dtb = dma_length; + tmr_x->dmactrl_bit.addr = dma_base_address; } /** @@ -1831,15 +1707,14 @@ void tmr_dma_control_config(tmr_type *tmr_x, tmr_dma_transfer_length_type dma_le * - to the structure of tmr_brkdt_config_type * @retval none */ -void tmr_brkdt_config(tmr_type *tmr_x, tmr_brkdt_config_type *brkdt_struct) -{ - tmr_x->brk_bit.brken = brkdt_struct->brk_enable; - tmr_x->brk_bit.dtc = brkdt_struct->deadtime; - tmr_x->brk_bit.fcsodis = brkdt_struct->fcsodis_state; - tmr_x->brk_bit.fcsoen = brkdt_struct->fcsoen_state; - tmr_x->brk_bit.brkv = brkdt_struct->brk_polarity; - tmr_x->brk_bit.aoen = brkdt_struct->auto_output_enable; - tmr_x->brk_bit.wpc = brkdt_struct->wp_level; +void tmr_brkdt_config(tmr_type *tmr_x, tmr_brkdt_config_type *brkdt_struct) { + tmr_x->brk_bit.brken = brkdt_struct->brk_enable; + tmr_x->brk_bit.dtc = brkdt_struct->deadtime; + tmr_x->brk_bit.fcsodis = brkdt_struct->fcsodis_state; + tmr_x->brk_bit.fcsoen = brkdt_struct->fcsoen_state; + tmr_x->brk_bit.brkv = brkdt_struct->brk_polarity; + tmr_x->brk_bit.aoen = brkdt_struct->auto_output_enable; + tmr_x->brk_bit.wpc = brkdt_struct->wp_level; } /** @@ -1854,16 +1729,12 @@ void tmr_brkdt_config(tmr_type *tmr_x, tmr_brkdt_config_type *brkdt_struct) * - TMR2_OTG2FS_TMR5_ERTC * @retval none */ -void tmr_iremap_config(tmr_type *tmr_x, tmr_input_remap_type input_remap) -{ - if(tmr_x == TMR2) - { - tmr_x->rmp_bit.tmr2_ch1_irmp = input_remap; - } - else if(tmr_x == TMR5) - { - tmr_x->rmp_bit.tmr5_ch4_irmp = input_remap; - } +void tmr_iremap_config(tmr_type *tmr_x, tmr_input_remap_type input_remap) { + if (tmr_x == TMR2) { + tmr_x->rmp_bit.tmr2_ch1_irmp = input_remap; + } else if (tmr_x == TMR5) { + tmr_x->rmp_bit.tmr5_ch4_irmp = input_remap; + } } /** diff --git a/armlib/at32_sys/drivers/src/at32f435_437_usart.c b/armlib/at32_sys/drivers/src/at32f435_437_usart.c index 867da9686..045066928 100644 --- a/armlib/at32_sys/drivers/src/at32f435_437_usart.c +++ b/armlib/at32_sys/drivers/src/at32f435_437_usart.c @@ -49,50 +49,35 @@ * USART1, USART2, USART3, UART4, UART5, USART6, UART7,or UART8. * @retval none */ -void usart_reset(usart_type* usart_x) -{ - if(usart_x == USART1) - { - crm_periph_reset(CRM_USART1_PERIPH_RESET, TRUE); - crm_periph_reset(CRM_USART1_PERIPH_RESET, FALSE); - } - else if(usart_x == USART2) - { - crm_periph_reset(CRM_USART2_PERIPH_RESET, TRUE); - crm_periph_reset(CRM_USART2_PERIPH_RESET, FALSE); - } - else if(usart_x == USART3) - { - crm_periph_reset(CRM_USART3_PERIPH_RESET, TRUE); - crm_periph_reset(CRM_USART3_PERIPH_RESET, FALSE); - } - else if(usart_x == UART4) - { - crm_periph_reset(CRM_UART4_PERIPH_RESET, TRUE); - crm_periph_reset(CRM_UART4_PERIPH_RESET, FALSE); - } - else if(usart_x == UART5) - { - crm_periph_reset(CRM_UART5_PERIPH_RESET, TRUE); - crm_periph_reset(CRM_UART5_PERIPH_RESET, FALSE); - } - else if(usart_x == USART6) - { - crm_periph_reset(CRM_USART6_PERIPH_RESET, TRUE); - crm_periph_reset(CRM_USART6_PERIPH_RESET, FALSE); - } - else if(usart_x == UART7) - { - crm_periph_reset(CRM_UART7_PERIPH_RESET, TRUE); - crm_periph_reset(CRM_UART7_PERIPH_RESET, FALSE); - } +void usart_reset(usart_type *usart_x) { + if (usart_x == USART1) { + crm_periph_reset(CRM_USART1_PERIPH_RESET, TRUE); + crm_periph_reset(CRM_USART1_PERIPH_RESET, FALSE); + } else if (usart_x == USART2) { + crm_periph_reset(CRM_USART2_PERIPH_RESET, TRUE); + crm_periph_reset(CRM_USART2_PERIPH_RESET, FALSE); + } else if (usart_x == USART3) { + crm_periph_reset(CRM_USART3_PERIPH_RESET, TRUE); + crm_periph_reset(CRM_USART3_PERIPH_RESET, FALSE); + } else if (usart_x == UART4) { + crm_periph_reset(CRM_UART4_PERIPH_RESET, TRUE); + crm_periph_reset(CRM_UART4_PERIPH_RESET, FALSE); + } else if (usart_x == UART5) { + crm_periph_reset(CRM_UART5_PERIPH_RESET, TRUE); + crm_periph_reset(CRM_UART5_PERIPH_RESET, FALSE); + } else if (usart_x == USART6) { + crm_periph_reset(CRM_USART6_PERIPH_RESET, TRUE); + crm_periph_reset(CRM_USART6_PERIPH_RESET, FALSE); + } else if (usart_x == UART7) { + crm_periph_reset(CRM_UART7_PERIPH_RESET, TRUE); + crm_periph_reset(CRM_UART7_PERIPH_RESET, FALSE); + } #if defined (AT32F435Zx) || defined (AT32F435Vx) || defined (AT32F435Rx) || \ defined (AT32F437Zx) || defined (AT32F437Vx) || defined (AT32F437Rx) - else if(usart_x == UART8) - { - crm_periph_reset(CRM_UART8_PERIPH_RESET, TRUE); - crm_periph_reset(CRM_UART8_PERIPH_RESET, FALSE); - } + else if (usart_x == UART8) { + crm_periph_reset(CRM_UART8_PERIPH_RESET, TRUE); + crm_periph_reset(CRM_UART8_PERIPH_RESET, FALSE); + } #endif } @@ -118,45 +103,33 @@ void usart_reset(usart_type* usart_x) * - USART_STOP_1_5_BIT. * @retval none */ -void usart_init(usart_type* usart_x, uint32_t baud_rate, usart_data_bit_num_type data_bit, usart_stop_bit_num_type stop_bit) -{ - crm_clocks_freq_type clocks_freq; - uint32_t apb_clock, temp_val; - crm_clocks_freq_get(&clocks_freq); - if((usart_x == USART1) || (usart_x == USART6)) - { - apb_clock = clocks_freq.apb2_freq; - } - else - { - apb_clock = clocks_freq.apb1_freq; - } - temp_val = (apb_clock * 10 / baud_rate); - if((temp_val % 10) < 5) - { - temp_val = (temp_val / 10); - } - else - { - temp_val = (temp_val / 10) + 1; - } - usart_x->baudr_bit.div = temp_val; - if(data_bit == USART_DATA_7BITS) - { - usart_x->ctrl1_bit.dbn_h = 1; - usart_x->ctrl1_bit.dbn_l = 0; - } - else if(data_bit == USART_DATA_8BITS) - { - usart_x->ctrl1_bit.dbn_h = 0; - usart_x->ctrl1_bit.dbn_l = 0; - } - else - { - usart_x->ctrl1_bit.dbn_h = 0; - usart_x->ctrl1_bit.dbn_l = 1; - } - usart_x->ctrl2_bit.stopbn = stop_bit; +void usart_init(usart_type *usart_x, uint32_t baud_rate, usart_data_bit_num_type data_bit, usart_stop_bit_num_type stop_bit) { + crm_clocks_freq_type clocks_freq; + uint32_t apb_clock, temp_val; + crm_clocks_freq_get(&clocks_freq); + if ((usart_x == USART1) || (usart_x == USART6)) { + apb_clock = clocks_freq.apb2_freq; + } else { + apb_clock = clocks_freq.apb1_freq; + } + temp_val = (apb_clock * 10 / baud_rate); + if ((temp_val % 10) < 5) { + temp_val = (temp_val / 10); + } else { + temp_val = (temp_val / 10) + 1; + } + usart_x->baudr_bit.div = temp_val; + if (data_bit == USART_DATA_7BITS) { + usart_x->ctrl1_bit.dbn_h = 1; + usart_x->ctrl1_bit.dbn_l = 0; + } else if (data_bit == USART_DATA_8BITS) { + usart_x->ctrl1_bit.dbn_h = 0; + usart_x->ctrl1_bit.dbn_l = 0; + } else { + usart_x->ctrl1_bit.dbn_h = 0; + usart_x->ctrl1_bit.dbn_l = 1; + } + usart_x->ctrl2_bit.stopbn = stop_bit; } /** @@ -171,23 +144,17 @@ void usart_init(usart_type* usart_x, uint32_t baud_rate, usart_data_bit_num_type * - USART_PARITY_ODD * @retval none */ -void usart_parity_selection_config(usart_type* usart_x, usart_parity_selection_type parity) -{ - if(parity == USART_PARITY_NONE) - { - usart_x->ctrl1_bit.psel = FALSE; - usart_x->ctrl1_bit.pen = FALSE; - } - else if(parity == USART_PARITY_EVEN) - { - usart_x->ctrl1_bit.psel = FALSE; - usart_x->ctrl1_bit.pen = TRUE; - } - else if(parity == USART_PARITY_ODD) - { - usart_x->ctrl1_bit.psel = TRUE; - usart_x->ctrl1_bit.pen = TRUE; - } +void usart_parity_selection_config(usart_type *usart_x, usart_parity_selection_type parity) { + if (parity == USART_PARITY_NONE) { + usart_x->ctrl1_bit.psel = FALSE; + usart_x->ctrl1_bit.pen = FALSE; + } else if (parity == USART_PARITY_EVEN) { + usart_x->ctrl1_bit.psel = FALSE; + usart_x->ctrl1_bit.pen = TRUE; + } else if (parity == USART_PARITY_ODD) { + usart_x->ctrl1_bit.psel = TRUE; + usart_x->ctrl1_bit.pen = TRUE; + } } /** @@ -199,9 +166,8 @@ void usart_parity_selection_config(usart_type* usart_x, usart_parity_selection_t * this parameter can be: TRUE or FALSE. * @retval none */ -void usart_enable(usart_type* usart_x, confirm_state new_state) -{ - usart_x->ctrl1_bit.uen = new_state; +void usart_enable(usart_type *usart_x, confirm_state new_state) { + usart_x->ctrl1_bit.uen = new_state; } /** @@ -212,9 +178,8 @@ void usart_enable(usart_type* usart_x, confirm_state new_state) * @param new_state: TRUE or FALSE. * @retval none */ -void usart_transmitter_enable(usart_type* usart_x, confirm_state new_state) -{ - usart_x->ctrl1_bit.ten = new_state; +void usart_transmitter_enable(usart_type *usart_x, confirm_state new_state) { + usart_x->ctrl1_bit.ten = new_state; } /** @@ -225,9 +190,8 @@ void usart_transmitter_enable(usart_type* usart_x, confirm_state new_state) * @param new_state: TRUE or FALSE. * @retval none */ -void usart_receiver_enable(usart_type* usart_x, confirm_state new_state) -{ - usart_x->ctrl1_bit.ren = new_state; +void usart_receiver_enable(usart_type *usart_x, confirm_state new_state) { + usart_x->ctrl1_bit.ren = new_state; } /** @@ -250,11 +214,10 @@ void usart_receiver_enable(usart_type* usart_x, confirm_state new_state) * - USART_CLOCK_LAST_BIT_OUTPUT * @retval none */ -void usart_clock_config(usart_type* usart_x, usart_clock_polarity_type clk_pol, usart_clock_phase_type clk_pha, usart_lbcp_type clk_lb) -{ - usart_x->ctrl2_bit.clkpol = clk_pol; - usart_x->ctrl2_bit.clkpha = clk_pha; - usart_x->ctrl2_bit.lbcp = clk_lb; +void usart_clock_config(usart_type *usart_x, usart_clock_polarity_type clk_pol, usart_clock_phase_type clk_pha, usart_lbcp_type clk_lb) { + usart_x->ctrl2_bit.clkpol = clk_pol; + usart_x->ctrl2_bit.clkpha = clk_pha; + usart_x->ctrl2_bit.lbcp = clk_lb; } /** @@ -266,9 +229,8 @@ void usart_clock_config(usart_type* usart_x, usart_clock_polarity_type clk_pol, * @param new_state: TRUE or FALSE * @retval none */ -void usart_clock_enable(usart_type* usart_x, confirm_state new_state) -{ - usart_x->ctrl2_bit.clken = new_state; +void usart_clock_enable(usart_type *usart_x, confirm_state new_state) { + usart_x->ctrl2_bit.clken = new_state; } /** @@ -290,12 +252,11 @@ void usart_clock_enable(usart_type* usart_x, confirm_state new_state) * this parameter can be: TRUE or FALSE. * @retval none */ -void usart_interrupt_enable(usart_type* usart_x, uint32_t usart_int, confirm_state new_state) -{ - if(new_state == TRUE) - PERIPH_REG((uint32_t)usart_x, usart_int) |= PERIPH_REG_BIT(usart_int); - else - PERIPH_REG((uint32_t)usart_x, usart_int) &= ~PERIPH_REG_BIT(usart_int); +void usart_interrupt_enable(usart_type *usart_x, uint32_t usart_int, confirm_state new_state) { + if (new_state == TRUE) + PERIPH_REG((uint32_t)usart_x, usart_int) |= PERIPH_REG_BIT(usart_int); + else + PERIPH_REG((uint32_t)usart_x, usart_int) &= ~PERIPH_REG_BIT(usart_int); } /** @@ -307,9 +268,8 @@ void usart_interrupt_enable(usart_type* usart_x, uint32_t usart_int, confirm_sta * this parameter can be: TRUE or FALSE. * @retval none */ -void usart_dma_transmitter_enable(usart_type* usart_x, confirm_state new_state) -{ - usart_x->ctrl3_bit.dmaten = new_state; +void usart_dma_transmitter_enable(usart_type *usart_x, confirm_state new_state) { + usart_x->ctrl3_bit.dmaten = new_state; } /** @@ -321,9 +281,8 @@ void usart_dma_transmitter_enable(usart_type* usart_x, confirm_state new_state) * this parameter can be: TRUE or FALSE. * @retval none */ -void usart_dma_receiver_enable(usart_type* usart_x, confirm_state new_state) -{ - usart_x->ctrl3_bit.dmaren = new_state; +void usart_dma_receiver_enable(usart_type *usart_x, confirm_state new_state) { + usart_x->ctrl3_bit.dmaren = new_state; } /** @@ -334,18 +293,14 @@ void usart_dma_receiver_enable(usart_type* usart_x, confirm_state new_state) * @param usart_id: the matching id(0x0~0xFF). * @retval none */ -void usart_wakeup_id_set(usart_type* usart_x, uint8_t usart_id) -{ - if(usart_x->ctrl2_bit.idbn == USART_ID_FIXED_4_BIT) - { - usart_x->ctrl2_bit.id_l = (usart_id & 0x0F); - usart_x->ctrl2_bit.id_h = 0; - } - else - { - usart_x->ctrl2_bit.id_l = (usart_id & 0x0F); - usart_x->ctrl2_bit.id_h = ((usart_id & 0xF0) >> 4); - } +void usart_wakeup_id_set(usart_type *usart_x, uint8_t usart_id) { + if (usart_x->ctrl2_bit.idbn == USART_ID_FIXED_4_BIT) { + usart_x->ctrl2_bit.id_l = (usart_id & 0x0F); + usart_x->ctrl2_bit.id_h = 0; + } else { + usart_x->ctrl2_bit.id_l = (usart_id & 0x0F); + usart_x->ctrl2_bit.id_h = ((usart_id & 0xF0) >> 4); + } } /** @@ -359,9 +314,8 @@ void usart_wakeup_id_set(usart_type* usart_x, uint8_t usart_id) * - USART_WAKEUP_BY_MATCHING_ID * @retval none */ -void usart_wakeup_mode_set(usart_type* usart_x, usart_wakeup_mode_type wakeup_mode) -{ - usart_x->ctrl1_bit.wum = wakeup_mode; +void usart_wakeup_mode_set(usart_type *usart_x, usart_wakeup_mode_type wakeup_mode) { + usart_x->ctrl1_bit.wum = wakeup_mode; } /** @@ -373,9 +327,8 @@ void usart_wakeup_mode_set(usart_type* usart_x, usart_wakeup_mode_type wakeup_mo * this parameter can be: TRUE or FALSE. * @retval none */ -void usart_receiver_mute_enable(usart_type* usart_x, confirm_state new_state) -{ - usart_x->ctrl1_bit.rm = new_state; +void usart_receiver_mute_enable(usart_type *usart_x, confirm_state new_state) { + usart_x->ctrl1_bit.rm = new_state; } /** @@ -389,9 +342,8 @@ void usart_receiver_mute_enable(usart_type* usart_x, confirm_state new_state) * - USART_BREAK_11BITS * @retval none */ -void usart_break_bit_num_set(usart_type* usart_x, usart_break_bit_num_type break_bit) -{ - usart_x->ctrl2_bit.bfbn = break_bit; +void usart_break_bit_num_set(usart_type *usart_x, usart_break_bit_num_type break_bit) { + usart_x->ctrl2_bit.bfbn = break_bit; } /** @@ -403,9 +355,8 @@ void usart_break_bit_num_set(usart_type* usart_x, usart_break_bit_num_type break * this parameter can be: TRUE or FALSE. * @retval none */ -void usart_lin_mode_enable(usart_type* usart_x, confirm_state new_state) -{ - usart_x->ctrl2_bit.linen = new_state; +void usart_lin_mode_enable(usart_type *usart_x, confirm_state new_state) { + usart_x->ctrl2_bit.linen = new_state; } /** @@ -416,9 +367,8 @@ void usart_lin_mode_enable(usart_type* usart_x, confirm_state new_state) * @param data: the data to transmit. * @retval none */ -void usart_data_transmit(usart_type* usart_x, uint16_t data) -{ - usart_x->dt = (data & 0x01FF); +void usart_data_transmit(usart_type *usart_x, uint16_t data) { + usart_x->dt = (data & 0x01FF); } /** @@ -428,9 +378,8 @@ void usart_data_transmit(usart_type* usart_x, uint16_t data) * USART1, USART2, USART3, UART4, UART5, USART6, UART7 or UART8. * @retval the received data. */ -uint16_t usart_data_receive(usart_type* usart_x) -{ - return (uint16_t)(usart_x->dt); +uint16_t usart_data_receive(usart_type *usart_x) { + return (uint16_t)(usart_x->dt); } /** @@ -440,9 +389,8 @@ uint16_t usart_data_receive(usart_type* usart_x) * USART1, USART2, USART3, UART4, UART5, USART6, UART7 or UART8. * @retval none */ -void usart_break_send(usart_type* usart_x) -{ - usart_x->ctrl1_bit.sbf = TRUE; +void usart_break_send(usart_type *usart_x) { + usart_x->ctrl1_bit.sbf = TRUE; } /** @@ -454,9 +402,8 @@ void usart_break_send(usart_type* usart_x) * @param guard_time_val: specifies the guard time (0x00~0xFF). * @retval none */ -void usart_smartcard_guard_time_set(usart_type* usart_x, uint8_t guard_time_val) -{ - usart_x->gdiv_bit.scgt = guard_time_val; +void usart_smartcard_guard_time_set(usart_type *usart_x, uint8_t guard_time_val) { + usart_x->gdiv_bit.scgt = guard_time_val; } /** @@ -468,9 +415,8 @@ void usart_smartcard_guard_time_set(usart_type* usart_x, uint8_t guard_time_val) * @param div_val: specifies the division. * @retval none */ -void usart_irda_smartcard_division_set(usart_type* usart_x, uint8_t div_val) -{ - usart_x->gdiv_bit.isdiv = div_val; +void usart_irda_smartcard_division_set(usart_type *usart_x, uint8_t div_val) { + usart_x->gdiv_bit.isdiv = div_val; } /** @@ -483,9 +429,8 @@ void usart_irda_smartcard_division_set(usart_type* usart_x, uint8_t div_val) * this parameter can be: TRUE or FALSE. * @retval none */ -void usart_smartcard_mode_enable(usart_type* usart_x, confirm_state new_state) -{ - usart_x->ctrl3_bit.scmen = new_state; +void usart_smartcard_mode_enable(usart_type *usart_x, confirm_state new_state) { + usart_x->ctrl3_bit.scmen = new_state; } /** @@ -498,9 +443,8 @@ void usart_smartcard_mode_enable(usart_type* usart_x, confirm_state new_state) * this parameter can be: TRUE or FALSE. * @retval none */ -void usart_smartcard_nack_set(usart_type* usart_x, confirm_state new_state) -{ - usart_x->ctrl3_bit.scnacken = new_state; +void usart_smartcard_nack_set(usart_type *usart_x, confirm_state new_state) { + usart_x->ctrl3_bit.scnacken = new_state; } /** @@ -512,9 +456,8 @@ void usart_smartcard_nack_set(usart_type* usart_x, confirm_state new_state) * this parameter can be: TRUE or FALSE. * @retval none */ -void usart_single_line_halfduplex_select(usart_type* usart_x, confirm_state new_state) -{ - usart_x->ctrl3_bit.slben = new_state; +void usart_single_line_halfduplex_select(usart_type *usart_x, confirm_state new_state) { + usart_x->ctrl3_bit.slben = new_state; } /** @@ -526,9 +469,8 @@ void usart_single_line_halfduplex_select(usart_type* usart_x, confirm_state new_ * this parameter can be: TRUE or FALSE. * @retval none */ -void usart_irda_mode_enable(usart_type* usart_x, confirm_state new_state) -{ - usart_x->ctrl3_bit.irdaen = new_state; +void usart_irda_mode_enable(usart_type *usart_x, confirm_state new_state) { + usart_x->ctrl3_bit.irdaen = new_state; } /** @@ -540,9 +482,8 @@ void usart_irda_mode_enable(usart_type* usart_x, confirm_state new_state) * this parameter can be: TRUE or FALSE. * @retval none */ -void usart_irda_low_power_enable(usart_type* usart_x, confirm_state new_state) -{ - usart_x->ctrl3_bit.irdalp = new_state; +void usart_irda_low_power_enable(usart_type *usart_x, confirm_state new_state) { + usart_x->ctrl3_bit.irdalp = new_state; } /** @@ -558,28 +499,20 @@ void usart_irda_low_power_enable(usart_type* usart_x, confirm_state new_state) * - USART_HARDWARE_FLOW_RTS_CTS * @retval none */ -void usart_hardware_flow_control_set(usart_type* usart_x,usart_hardware_flow_control_type flow_state) -{ - if(flow_state == USART_HARDWARE_FLOW_NONE) - { - usart_x->ctrl3_bit.rtsen = FALSE; - usart_x->ctrl3_bit.ctsen = FALSE; - } - else if(flow_state == USART_HARDWARE_FLOW_RTS) - { - usart_x->ctrl3_bit.rtsen = TRUE; - usart_x->ctrl3_bit.ctsen = FALSE; - } - else if(flow_state == USART_HARDWARE_FLOW_CTS) - { - usart_x->ctrl3_bit.rtsen = FALSE; - usart_x->ctrl3_bit.ctsen = TRUE; - } - else if(flow_state == USART_HARDWARE_FLOW_RTS_CTS) - { - usart_x->ctrl3_bit.rtsen = TRUE; - usart_x->ctrl3_bit.ctsen = TRUE; - } +void usart_hardware_flow_control_set(usart_type *usart_x, usart_hardware_flow_control_type flow_state) { + if (flow_state == USART_HARDWARE_FLOW_NONE) { + usart_x->ctrl3_bit.rtsen = FALSE; + usart_x->ctrl3_bit.ctsen = FALSE; + } else if (flow_state == USART_HARDWARE_FLOW_RTS) { + usart_x->ctrl3_bit.rtsen = TRUE; + usart_x->ctrl3_bit.ctsen = FALSE; + } else if (flow_state == USART_HARDWARE_FLOW_CTS) { + usart_x->ctrl3_bit.rtsen = FALSE; + usart_x->ctrl3_bit.ctsen = TRUE; + } else if (flow_state == USART_HARDWARE_FLOW_RTS_CTS) { + usart_x->ctrl3_bit.rtsen = TRUE; + usart_x->ctrl3_bit.ctsen = TRUE; + } } /** @@ -601,16 +534,12 @@ void usart_hardware_flow_control_set(usart_type* usart_x,usart_hardware_flow_con * - USART_PERR_FLAG: parity error flag * @retval the new state of usart_flag (SET or RESET). */ -flag_status usart_flag_get(usart_type* usart_x, uint32_t flag) -{ - if(usart_x->sts & flag) - { - return SET; - } - else - { - return RESET; - } +flag_status usart_flag_get(usart_type *usart_x, uint32_t flag) { + if (usart_x->sts & flag) { + return SET; + } else { + return RESET; + } } /** @@ -632,58 +561,52 @@ flag_status usart_flag_get(usart_type* usart_x, uint32_t flag) * - USART_PERR_FLAG: parity error flag * @retval the new state of usart_flag (SET or RESET). */ -flag_status usart_interrupt_flag_get(usart_type* usart_x, uint32_t flag) -{ - flag_status int_status = RESET; +flag_status usart_interrupt_flag_get(usart_type *usart_x, uint32_t flag) { + flag_status int_status = RESET; - switch(flag) - { - case USART_CTSCF_FLAG: - int_status = (flag_status)usart_x->ctrl3_bit.ctscfien; - break; - case USART_BFF_FLAG: - int_status = (flag_status)usart_x->ctrl2_bit.bfien; - break; - case USART_TDBE_FLAG: - int_status = (flag_status)usart_x->ctrl1_bit.tdbeien; - break; - case USART_TDC_FLAG: - int_status = (flag_status)usart_x->ctrl1_bit.tdcien; - break; - case USART_RDBF_FLAG: - int_status = (flag_status)usart_x->ctrl1_bit.rdbfien; - break; - case USART_ROERR_FLAG: - int_status = (flag_status)(usart_x->ctrl1_bit.rdbfien || usart_x->ctrl3_bit.errien); - break; - case USART_IDLEF_FLAG: - int_status = (flag_status)usart_x->ctrl1_bit.idleien; - break; - case USART_NERR_FLAG: - case USART_FERR_FLAG: - int_status = (flag_status)usart_x->ctrl3_bit.errien; - break; - case USART_PERR_FLAG: - int_status = (flag_status)usart_x->ctrl1_bit.perrien; - break; - default: - int_status = RESET; - break; - } + switch (flag) { + case USART_CTSCF_FLAG: + int_status = (flag_status)usart_x->ctrl3_bit.ctscfien; + break; + case USART_BFF_FLAG: + int_status = (flag_status)usart_x->ctrl2_bit.bfien; + break; + case USART_TDBE_FLAG: + int_status = (flag_status)usart_x->ctrl1_bit.tdbeien; + break; + case USART_TDC_FLAG: + int_status = (flag_status)usart_x->ctrl1_bit.tdcien; + break; + case USART_RDBF_FLAG: + int_status = (flag_status)usart_x->ctrl1_bit.rdbfien; + break; + case USART_ROERR_FLAG: + int_status = (flag_status)(usart_x->ctrl1_bit.rdbfien || usart_x->ctrl3_bit.errien); + break; + case USART_IDLEF_FLAG: + int_status = (flag_status)usart_x->ctrl1_bit.idleien; + break; + case USART_NERR_FLAG: + case USART_FERR_FLAG: + int_status = (flag_status)usart_x->ctrl3_bit.errien; + break; + case USART_PERR_FLAG: + int_status = (flag_status)usart_x->ctrl1_bit.perrien; + break; + default: + int_status = RESET; + break; + } - if(int_status != SET) - { - return RESET; - } + if (int_status != SET) { + return RESET; + } - if(usart_x->sts & flag) - { - return SET; - } - else - { - return RESET; - } + if (usart_x->sts & flag) { + return SET; + } else { + return RESET; + } } /** @@ -712,17 +635,13 @@ flag_status usart_interrupt_flag_get(usart_type* usart_x, uint32_t flag) * - USART_TDBE_FLAG is cleared only by a write to the usart dt register(usart_data_transmit()). * @retval none */ -void usart_flag_clear(usart_type* usart_x, uint32_t flag) -{ - if(flag & (USART_PERR_FLAG | USART_FERR_FLAG | USART_NERR_FLAG | USART_ROERR_FLAG | USART_IDLEF_FLAG)) - { - UNUSED(usart_x->sts); - UNUSED(usart_x->dt); - } - else - { - usart_x->sts = ~flag; - } +void usart_flag_clear(usart_type *usart_x, uint32_t flag) { + if (flag & (USART_PERR_FLAG | USART_FERR_FLAG | USART_NERR_FLAG | USART_ROERR_FLAG | USART_IDLEF_FLAG)) { + UNUSED(usart_x->sts); + UNUSED(usart_x->dt); + } else { + usart_x->sts = ~flag; + } } /** @@ -734,10 +653,9 @@ void usart_flag_clear(usart_type* usart_x, uint32_t flag) * @param complete_delay_time: transmit complete delay time. * @retval none */ -void usart_rs485_delay_time_config(usart_type* usart_x, uint8_t start_delay_time, uint8_t complete_delay_time) -{ - usart_x->ctrl1_bit.tsdt = start_delay_time; - usart_x->ctrl1_bit.tcdt = complete_delay_time; +void usart_rs485_delay_time_config(usart_type *usart_x, uint8_t start_delay_time, uint8_t complete_delay_time) { + usart_x->ctrl1_bit.tsdt = start_delay_time; + usart_x->ctrl1_bit.tcdt = complete_delay_time; } /** @@ -749,9 +667,8 @@ void usart_rs485_delay_time_config(usart_type* usart_x, uint8_t start_delay_time * this parameter can be: TRUE or FALSE. * @retval none */ -void usart_transmit_receive_pin_swap(usart_type* usart_x, confirm_state new_state) -{ - usart_x->ctrl2_bit.trpswap = new_state; +void usart_transmit_receive_pin_swap(usart_type *usart_x, confirm_state new_state) { + usart_x->ctrl2_bit.trpswap = new_state; } /** @@ -763,9 +680,8 @@ void usart_transmit_receive_pin_swap(usart_type* usart_x, confirm_state new_stat * this parameter can be: USART_ID_FIXED_4_BIT or USART_ID_RELATED_DATA_BIT. * @retval none */ -void usart_id_bit_num_set(usart_type* usart_x, usart_identification_bit_num_type id_bit_num) -{ - usart_x->ctrl2_bit.idbn = (uint8_t)id_bit_num; +void usart_id_bit_num_set(usart_type *usart_x, usart_identification_bit_num_type id_bit_num) { + usart_x->ctrl2_bit.idbn = (uint8_t)id_bit_num; } /** @@ -777,9 +693,8 @@ void usart_id_bit_num_set(usart_type* usart_x, usart_identification_bit_num_type * this parameter can be: USART_DE_POLARITY_HIGH or USART_DE_POLARITY_LOW. * @retval none */ -void usart_de_polarity_set(usart_type* usart_x, usart_de_polarity_type de_polarity) -{ - usart_x->ctrl3_bit.dep = (uint8_t)de_polarity; +void usart_de_polarity_set(usart_type *usart_x, usart_de_polarity_type de_polarity) { + usart_x->ctrl3_bit.dep = (uint8_t)de_polarity; } /** @@ -791,9 +706,8 @@ void usart_de_polarity_set(usart_type* usart_x, usart_de_polarity_type de_polari * this parameter can be: TRUE or FALSE. * @retval none */ -void usart_rs485_mode_enable(usart_type* usart_x, confirm_state new_state) -{ - usart_x->ctrl3_bit.rs485en = new_state; +void usart_rs485_mode_enable(usart_type *usart_x, confirm_state new_state) { + usart_x->ctrl3_bit.rs485en = new_state; } /** diff --git a/armlib/at32_sys/drivers/src/at32f435_437_usb.c b/armlib/at32_sys/drivers/src/at32f435_437_usb.c index 01a28ba4a..e647a2d75 100644 --- a/armlib/at32_sys/drivers/src/at32f435_437_usb.c +++ b/armlib/at32_sys/drivers/src/at32f435_437_usb.c @@ -49,26 +49,21 @@ * - OTG2_GLOBAL * @retval error status */ -error_status usb_global_reset(otg_global_type *usbx) -{ - uint32_t timeout = 0; - while(usbx->grstctl_bit.ahbidle == RESET) - { - if(timeout ++ > 200000) - { - break; +error_status usb_global_reset(otg_global_type *usbx) { + uint32_t timeout = 0; + while (usbx->grstctl_bit.ahbidle == RESET) { + if (timeout ++ > 200000) { + break; + } } - } - timeout = 0; - usbx->grstctl_bit.csftrst = TRUE; - while(usbx->grstctl_bit.csftrst == SET) - { - if(timeout ++ > 200000) - { - break; + timeout = 0; + usbx->grstctl_bit.csftrst = TRUE; + while (usbx->grstctl_bit.csftrst == SET) { + if (timeout ++ > 200000) { + break; + } } - } - return SUCCESS; + return SUCCESS; } /** @@ -79,13 +74,12 @@ error_status usb_global_reset(otg_global_type *usbx) * - OTG2_GLOBAL * @retval none */ -void usb_global_init(otg_global_type *usbx) -{ - /* reset otg moudle */ - usb_global_reset(usbx); +void usb_global_init(otg_global_type *usbx) { + /* reset otg moudle */ + usb_global_reset(usbx); - /* exit power down mode */ - usbx->gccfg_bit.pwrdown = TRUE; + /* exit power down mode */ + usbx->gccfg_bit.pwrdown = TRUE; } /** @@ -96,18 +90,14 @@ void usb_global_init(otg_global_type *usbx) * - USB_OTG2_ID * @retval usb global register type pointer */ -otg_global_type *usb_global_select_core(uint8_t usb_id) -{ - if(usb_id == USB_OTG1_ID) - { - /* use otg1 */ - return OTG1_GLOBAL; - } - else - { - /* use otg2 */ - return OTG2_GLOBAL; - } +otg_global_type *usb_global_select_core(uint8_t usb_id) { + if (usb_id == USB_OTG1_ID) { + /* use otg1 */ + return OTG1_GLOBAL; + } else { + /* use otg2 */ + return OTG2_GLOBAL; + } } /** @@ -120,22 +110,19 @@ otg_global_type *usb_global_select_core(uint8_t usb_id) * parameter as following values: 0-16 * @retval none */ -void usb_flush_tx_fifo(otg_global_type *usbx, uint32_t fifo_num) -{ - uint32_t timeout = 0; - /* set flush fifo number */ - usbx->grstctl_bit.txfnum = fifo_num; +void usb_flush_tx_fifo(otg_global_type *usbx, uint32_t fifo_num) { + uint32_t timeout = 0; + /* set flush fifo number */ + usbx->grstctl_bit.txfnum = fifo_num; - /* start flush fifo */ - usbx->grstctl_bit.txfflsh = TRUE; + /* start flush fifo */ + usbx->grstctl_bit.txfflsh = TRUE; - while(usbx->grstctl_bit.txfflsh == TRUE) - { - if(timeout ++ > 200000) - { - break; + while (usbx->grstctl_bit.txfflsh == TRUE) { + if (timeout ++ > 200000) { + break; + } } - } } /** @@ -146,17 +133,14 @@ void usb_flush_tx_fifo(otg_global_type *usbx, uint32_t fifo_num) * - OTG2_GLOBAL * @retval none */ -void usb_flush_rx_fifo(otg_global_type *usbx) -{ - uint32_t timeout = 0; - usbx->grstctl_bit.rxfflsh = TRUE; - while(usbx->grstctl_bit.rxfflsh == TRUE) - { - if(timeout ++ > 200000) - { - break; +void usb_flush_rx_fifo(otg_global_type *usbx) { + uint32_t timeout = 0; + usbx->grstctl_bit.rxfflsh = TRUE; + while (usbx->grstctl_bit.rxfflsh == TRUE) { + if (timeout ++ > 200000) { + break; + } } - } } /** @@ -192,16 +176,12 @@ void usb_flush_rx_fifo(otg_global_type *usbx) * @param new_state: TRUE or FALSE * @retval none */ -void usb_global_interrupt_enable(otg_global_type *usbx, uint16_t interrupt, confirm_state new_state) -{ - if(new_state == TRUE) - { - usbx->gintmsk |= interrupt; - } - else - { - usbx->gintmsk &= ~interrupt; - } +void usb_global_interrupt_enable(otg_global_type *usbx, uint16_t interrupt, confirm_state new_state) { + if (new_state == TRUE) { + usbx->gintmsk |= interrupt; + } else { + usbx->gintmsk &= ~interrupt; + } } /** @@ -212,10 +192,9 @@ void usb_global_interrupt_enable(otg_global_type *usbx, uint16_t interrupt, conf * - OTG2_GLOBAL * @retval intterupt flag */ -uint32_t usb_global_get_all_interrupt(otg_global_type *usbx) -{ - uint32_t intsts = usbx->gintsts; - return intsts & usbx->gintmsk; +uint32_t usb_global_get_all_interrupt(otg_global_type *usbx) { + uint32_t intsts = usbx->gintsts; + return intsts & usbx->gintmsk; } /** @@ -251,9 +230,8 @@ uint32_t usb_global_get_all_interrupt(otg_global_type *usbx) * - USB_OTG_WKUP_FLAG * @retval none */ -void usb_global_clear_interrupt(otg_global_type *usbx, uint32_t flag) -{ - usbx->gintsts = flag; +void usb_global_clear_interrupt(otg_global_type *usbx, uint32_t flag) { + usbx->gintsts = flag; } /** @@ -263,9 +241,8 @@ void usb_global_clear_interrupt(otg_global_type *usbx, uint32_t flag) * OTG1_GLOBAL , OTG2_GLOBAL * @retval none */ -void usb_interrupt_enable(otg_global_type *usbx) -{ - usbx->gahbcfg_bit.glbintmsk = TRUE; +void usb_interrupt_enable(otg_global_type *usbx) { + usbx->gahbcfg_bit.glbintmsk = TRUE; } /** @@ -276,9 +253,8 @@ void usb_interrupt_enable(otg_global_type *usbx) * - OTG2_GLOBAL * @retval none */ -void usb_interrupt_disable(otg_global_type *usbx) -{ - usbx->gahbcfg_bit.glbintmsk = FALSE; +void usb_interrupt_disable(otg_global_type *usbx) { + usbx->gahbcfg_bit.glbintmsk = FALSE; } /** @@ -290,9 +266,8 @@ void usb_interrupt_disable(otg_global_type *usbx) * @param size: rx fifo size * @retval none */ -void usb_set_rx_fifo(otg_global_type *usbx, uint16_t size) -{ - usbx->grxfsiz = size; +void usb_set_rx_fifo(otg_global_type *usbx, uint16_t size) { + usbx->grxfsiz = size; } /** @@ -305,25 +280,20 @@ void usb_set_rx_fifo(otg_global_type *usbx, uint16_t size) * @param size: tx fifo size * @retval none */ -void usb_set_tx_fifo(otg_global_type *usbx, uint8_t txfifo, uint16_t size) -{ - uint8_t i_index = 0; - uint32_t offset = 0; +void usb_set_tx_fifo(otg_global_type *usbx, uint8_t txfifo, uint16_t size) { + uint8_t i_index = 0; + uint32_t offset = 0; - offset = usbx->grxfsiz; - if(txfifo == 0) - { - usbx->gnptxfsiz_ept0tx = offset | (size << 16); - } - else - { - offset += usbx->gnptxfsiz_ept0tx_bit.nptxfdep; - for(i_index = 0; i_index < (txfifo - 1); i_index ++) - { - offset += usbx->dieptxfn_bit[i_index].ineptxfdep; + offset = usbx->grxfsiz; + if (txfifo == 0) { + usbx->gnptxfsiz_ept0tx = offset | (size << 16); + } else { + offset += usbx->gnptxfsiz_ept0tx_bit.nptxfdep; + for (i_index = 0; i_index < (txfifo - 1); i_index ++) { + offset += usbx->dieptxfn_bit[i_index].ineptxfdep; + } + usbx->dieptxfn[txfifo - 1] = offset | (size << 16); } - usbx->dieptxfn[txfifo - 1] = offset | (size << 16); - } } @@ -340,28 +310,24 @@ void usb_set_tx_fifo(otg_global_type *usbx, uint8_t txfifo, uint16_t size) * - OTG_DRD_MODE * @retval none */ -void usb_global_set_mode(otg_global_type *usbx, uint32_t mode) -{ - /* set otg to device mode */ - if(mode == OTG_DEVICE_MODE) - { - usbx->gusbcfg_bit.fhstmode = FALSE; - usbx->gusbcfg_bit.fdevmode = TRUE; - } +void usb_global_set_mode(otg_global_type *usbx, uint32_t mode) { + /* set otg to device mode */ + if (mode == OTG_DEVICE_MODE) { + usbx->gusbcfg_bit.fhstmode = FALSE; + usbx->gusbcfg_bit.fdevmode = TRUE; + } - /* set otg to host mode */ - if(mode == OTG_HOST_MODE) - { - usbx->gusbcfg_bit.fdevmode = FALSE; - usbx->gusbcfg_bit.fhstmode = TRUE; - } + /* set otg to host mode */ + if (mode == OTG_HOST_MODE) { + usbx->gusbcfg_bit.fdevmode = FALSE; + usbx->gusbcfg_bit.fhstmode = TRUE; + } - /* set otg to default mode */ - if(mode == OTG_DRD_MODE) - { - usbx->gusbcfg_bit.fdevmode = FALSE; - usbx->gusbcfg_bit.fhstmode = FALSE; - } + /* set otg to default mode */ + if (mode == OTG_DRD_MODE) { + usbx->gusbcfg_bit.fdevmode = FALSE; + usbx->gusbcfg_bit.fhstmode = FALSE; + } } @@ -373,14 +339,13 @@ void usb_global_set_mode(otg_global_type *usbx, uint32_t mode) * - OTG2_GLOBAL * @retval none */ -void usb_global_power_on(otg_global_type *usbx) -{ - /* core soft reset */ - usbx->grstctl_bit.csftrst = TRUE; - while(usbx->grstctl_bit.csftrst); +void usb_global_power_on(otg_global_type *usbx) { + /* core soft reset */ + usbx->grstctl_bit.csftrst = TRUE; + while (usbx->grstctl_bit.csftrst); - /* disable power down mode */ - usbx->gccfg_bit.pwrdown = TRUE; + /* disable power down mode */ + usbx->gccfg_bit.pwrdown = TRUE; } @@ -392,9 +357,8 @@ void usb_global_power_on(otg_global_type *usbx) * - OTG2_GLOBAL * @retval none */ -void usb_stop_phy_clk(otg_global_type *usbx) -{ - OTG_PCGCCTL(usbx)->pcgcctl_bit.stoppclk = TRUE; +void usb_stop_phy_clk(otg_global_type *usbx) { + OTG_PCGCCTL(usbx)->pcgcctl_bit.stoppclk = TRUE; } /** @@ -405,9 +369,8 @@ void usb_stop_phy_clk(otg_global_type *usbx) * - OTG2_GLOBAL * @retval none */ -void usb_open_phy_clk(otg_global_type *usbx) -{ - OTG_PCGCCTL(usbx)->pcgcctl_bit.stoppclk = FALSE; +void usb_open_phy_clk(otg_global_type *usbx) { + OTG_PCGCCTL(usbx)->pcgcctl_bit.stoppclk = FALSE; } @@ -418,20 +381,18 @@ void usb_open_phy_clk(otg_global_type *usbx) * @param nbytes: number of bytes data write to usb buffer * @retval none */ -void usb_write_packet(otg_global_type *usbx, uint8_t *pusr_buf, uint16_t num, uint16_t nbytes) -{ - uint32_t n_index; - uint32_t nhbytes = (nbytes + 3) / 4; - uint32_t *pbuf = (uint32_t *)pusr_buf; - for(n_index = 0; n_index < nhbytes; n_index ++) - { +void usb_write_packet(otg_global_type *usbx, uint8_t *pusr_buf, uint16_t num, uint16_t nbytes) { + uint32_t n_index; + uint32_t nhbytes = (nbytes + 3) / 4; + uint32_t *pbuf = (uint32_t *)pusr_buf; + for (n_index = 0; n_index < nhbytes; n_index ++) { #if defined (__ICCARM__) && (__VER__ < 7000000) - USB_FIFO(usbx, num) = *(__packed uint32_t *)pbuf; + USB_FIFO(usbx, num) = *(__packed uint32_t *)pbuf; #else - USB_FIFO(usbx, num) = __UNALIGNED_UINT32_READ(pbuf); + USB_FIFO(usbx, num) = __UNALIGNED_UINT32_READ(pbuf); #endif - pbuf ++; - } + pbuf ++; + } } /** @@ -441,21 +402,19 @@ void usb_write_packet(otg_global_type *usbx, uint8_t *pusr_buf, uint16_t num, ui * @param nbytes: number of bytes data write to usb buffer * @retval none */ -void usb_read_packet(otg_global_type *usbx, uint8_t *pusr_buf, uint16_t num, uint16_t nbytes) -{ - uint32_t n_index; - uint32_t nhbytes = (nbytes + 3) / 4; - uint32_t *pbuf = (uint32_t *)pusr_buf; - UNUSED(num); - for(n_index = 0; n_index < nhbytes; n_index ++) - { +void usb_read_packet(otg_global_type *usbx, uint8_t *pusr_buf, uint16_t num, uint16_t nbytes) { + uint32_t n_index; + uint32_t nhbytes = (nbytes + 3) / 4; + uint32_t *pbuf = (uint32_t *)pusr_buf; + UNUSED(num); + for (n_index = 0; n_index < nhbytes; n_index ++) { #if defined (__ICCARM__) && (__VER__ < 7000000) - *(__packed uint32_t *)pbuf = USB_FIFO(usbx, 0); + *(__packed uint32_t *)pbuf = USB_FIFO(usbx, 0); #else - __UNALIGNED_UINT32_WRITE(pbuf, (USB_FIFO(usbx, 0))); + __UNALIGNED_UINT32_WRITE(pbuf, (USB_FIFO(usbx, 0))); #endif - pbuf ++; - } + pbuf ++; + } } #endif @@ -470,65 +429,47 @@ void usb_read_packet(otg_global_type *usbx, uint8_t *pusr_buf, uint16_t num, uin * @param ept_info: endpoint information structure * @retval none */ -void usb_ept_open(otg_global_type *usbx, usb_ept_info *ept_info) -{ - uint8_t mps = USB_EPT0_MPS_64; - if(ept_info->eptn == USB_EPT0) - { - if(ept_info->maxpacket == 0x40) - { - mps = USB_EPT0_MPS_64; +void usb_ept_open(otg_global_type *usbx, usb_ept_info *ept_info) { + uint8_t mps = USB_EPT0_MPS_64; + if (ept_info->eptn == USB_EPT0) { + if (ept_info->maxpacket == 0x40) { + mps = USB_EPT0_MPS_64; + } else if (ept_info->maxpacket == 0x20) { + mps = USB_EPT0_MPS_32; + } else if (ept_info->maxpacket == 0x10) { + mps = USB_EPT0_MPS_16; + } else if (ept_info->maxpacket == 0x08) { + mps = USB_EPT0_MPS_8; + } } - else if(ept_info->maxpacket == 0x20) - { - mps = USB_EPT0_MPS_32; + if (ept_info->trans_type == EPT_ISO_TYPE) { + OTG_DEVICE(usbx)->dctl |= 1 << 15; } - else if(ept_info->maxpacket == 0x10) - { - mps = USB_EPT0_MPS_16; + /* endpoint direction is in */ + if (ept_info->inout == EPT_DIR_IN) { + OTG_DEVICE(usbx)->daintmsk |= 1 << ept_info->eptn; + if (ept_info->eptn == USB_EPT0) { + USB_INEPT(usbx, ept_info->eptn)->diepctl_bit.mps = mps; + } else { + USB_INEPT(usbx, ept_info->eptn)->diepctl_bit.mps = ept_info->maxpacket; + } + USB_INEPT(usbx, ept_info->eptn)->diepctl_bit.eptype = ept_info->trans_type; + USB_INEPT(usbx, ept_info->eptn)->diepctl_bit.txfnum = ept_info->eptn; + USB_INEPT(usbx, ept_info->eptn)->diepctl_bit.setd0pid = TRUE; + USB_INEPT(usbx, ept_info->eptn)->diepctl_bit.usbacept = TRUE; } - else if(ept_info->maxpacket == 0x08) - { - mps = USB_EPT0_MPS_8; + /* endpoint direction is out */ + else { + OTG_DEVICE(usbx)->daintmsk |= (1 << ept_info->eptn) << 16; + if (ept_info->eptn == USB_EPT0) { + USB_OUTEPT(usbx, ept_info->eptn)->doepctl_bit.mps = mps; + } else { + USB_OUTEPT(usbx, ept_info->eptn)->doepctl_bit.mps = ept_info->maxpacket; + } + USB_OUTEPT(usbx, ept_info->eptn)->doepctl_bit.eptype = ept_info->trans_type; + USB_OUTEPT(usbx, ept_info->eptn)->doepctl_bit.setd0pid = TRUE; + USB_OUTEPT(usbx, ept_info->eptn)->doepctl_bit.usbacept = TRUE; } - } - if(ept_info->trans_type == EPT_ISO_TYPE) - { - OTG_DEVICE(usbx)->dctl |= 1 << 15; - } - /* endpoint direction is in */ - if(ept_info->inout == EPT_DIR_IN) - { - OTG_DEVICE(usbx)->daintmsk |= 1 << ept_info->eptn; - if(ept_info->eptn == USB_EPT0) - { - USB_INEPT(usbx, ept_info->eptn)->diepctl_bit.mps = mps; - } - else - { - USB_INEPT(usbx, ept_info->eptn)->diepctl_bit.mps = ept_info->maxpacket; - } - USB_INEPT(usbx, ept_info->eptn)->diepctl_bit.eptype = ept_info->trans_type; - USB_INEPT(usbx, ept_info->eptn)->diepctl_bit.txfnum = ept_info->eptn; - USB_INEPT(usbx, ept_info->eptn)->diepctl_bit.setd0pid = TRUE; - USB_INEPT(usbx, ept_info->eptn)->diepctl_bit.usbacept = TRUE; - } - /* endpoint direction is out */ - else - { - OTG_DEVICE(usbx)->daintmsk |= (1 << ept_info->eptn) << 16; - if(ept_info->eptn == USB_EPT0) - { - USB_OUTEPT(usbx, ept_info->eptn)->doepctl_bit.mps = mps; - } - else - { - USB_OUTEPT(usbx, ept_info->eptn)->doepctl_bit.mps = ept_info->maxpacket; - } - USB_OUTEPT(usbx, ept_info->eptn)->doepctl_bit.eptype = ept_info->trans_type; - USB_OUTEPT(usbx, ept_info->eptn)->doepctl_bit.setd0pid = TRUE; - USB_OUTEPT(usbx, ept_info->eptn)->doepctl_bit.usbacept = TRUE; - } } /** @@ -540,29 +481,23 @@ void usb_ept_open(otg_global_type *usbx, usb_ept_info *ept_info) * @param ept_info: endpoint information structure * @retval none */ -void usb_ept_close(otg_global_type *usbx, usb_ept_info *ept_info) -{ - if(ept_info->inout == EPT_DIR_IN) - { - OTG_DEVICE(usbx)->daintmsk &= ~(1 << ept_info->eptn); - if(USB_INEPT(usbx, ept_info->eptn)->diepctl_bit.eptena == SET) - { - USB_INEPT(usbx, ept_info->eptn)->diepctl_bit.eptdis = TRUE; - USB_INEPT(usbx, ept_info->eptn)->diepctl_bit.snak = TRUE; - } - USB_INEPT(usbx, ept_info->eptn)->diepctl_bit.usbacept = FALSE; - } - else - { - OTG_DEVICE(usbx)->daintmsk &= ~((1 << ept_info->eptn) << 16); - if(USB_OUTEPT(usbx, ept_info->eptn)->doepctl_bit.eptena == SET) - { - USB_OUTEPT(usbx, ept_info->eptn)->doepctl_bit.eptdis = TRUE; - USB_OUTEPT(usbx, ept_info->eptn)->doepctl_bit.snak = TRUE; - } +void usb_ept_close(otg_global_type *usbx, usb_ept_info *ept_info) { + if (ept_info->inout == EPT_DIR_IN) { + OTG_DEVICE(usbx)->daintmsk &= ~(1 << ept_info->eptn); + if (USB_INEPT(usbx, ept_info->eptn)->diepctl_bit.eptena == SET) { + USB_INEPT(usbx, ept_info->eptn)->diepctl_bit.eptdis = TRUE; + USB_INEPT(usbx, ept_info->eptn)->diepctl_bit.snak = TRUE; + } + USB_INEPT(usbx, ept_info->eptn)->diepctl_bit.usbacept = FALSE; + } else { + OTG_DEVICE(usbx)->daintmsk &= ~((1 << ept_info->eptn) << 16); + if (USB_OUTEPT(usbx, ept_info->eptn)->doepctl_bit.eptena == SET) { + USB_OUTEPT(usbx, ept_info->eptn)->doepctl_bit.eptdis = TRUE; + USB_OUTEPT(usbx, ept_info->eptn)->doepctl_bit.snak = TRUE; + } - USB_OUTEPT(usbx, ept_info->eptn)->doepctl_bit.usbacept = FALSE; - } + USB_OUTEPT(usbx, ept_info->eptn)->doepctl_bit.usbacept = FALSE; + } } @@ -575,24 +510,18 @@ void usb_ept_close(otg_global_type *usbx, usb_ept_info *ept_info) * @param ept_info: endpoint information structure * @retval none */ -void usb_ept_stall(otg_global_type *usbx, usb_ept_info *ept_info) -{ - if(ept_info->inout == EPT_DIR_IN) - { - if(USB_INEPT(usbx, ept_info->eptn)->diepctl_bit.eptena == RESET) - { - USB_INEPT(usbx, ept_info->eptn)->diepctl_bit.eptdis = FALSE; +void usb_ept_stall(otg_global_type *usbx, usb_ept_info *ept_info) { + if (ept_info->inout == EPT_DIR_IN) { + if (USB_INEPT(usbx, ept_info->eptn)->diepctl_bit.eptena == RESET) { + USB_INEPT(usbx, ept_info->eptn)->diepctl_bit.eptdis = FALSE; + } + USB_INEPT(usbx, ept_info->eptn)->diepctl_bit.stall = SET; + } else { + if (USB_OUTEPT(usbx, ept_info->eptn)->doepctl_bit.eptena == RESET) { + USB_OUTEPT(usbx, ept_info->eptn)->doepctl_bit.eptdis = FALSE; + } + USB_OUTEPT(usbx, ept_info->eptn)->doepctl_bit.stall = TRUE; } - USB_INEPT(usbx, ept_info->eptn)->diepctl_bit.stall = SET; - } - else - { - if(USB_OUTEPT(usbx, ept_info->eptn)->doepctl_bit.eptena == RESET) - { - USB_OUTEPT(usbx, ept_info->eptn)->doepctl_bit.eptdis = FALSE; - } - USB_OUTEPT(usbx, ept_info->eptn)->doepctl_bit.stall = TRUE; - } } /** @@ -604,24 +533,18 @@ void usb_ept_stall(otg_global_type *usbx, usb_ept_info *ept_info) * @param ept_info: endpoint information structure * @retval none */ -void usb_ept_clear_stall(otg_global_type *usbx, usb_ept_info *ept_info) -{ - if(ept_info->inout == EPT_DIR_IN) - { - USB_INEPT(usbx, ept_info->eptn)->diepctl_bit.stall = FALSE; - if(ept_info->trans_type == EPT_INT_TYPE || ept_info->trans_type == EPT_BULK_TYPE) - { - USB_INEPT(usbx, ept_info->eptn)->diepctl_bit.setd0pid = TRUE; +void usb_ept_clear_stall(otg_global_type *usbx, usb_ept_info *ept_info) { + if (ept_info->inout == EPT_DIR_IN) { + USB_INEPT(usbx, ept_info->eptn)->diepctl_bit.stall = FALSE; + if (ept_info->trans_type == EPT_INT_TYPE || ept_info->trans_type == EPT_BULK_TYPE) { + USB_INEPT(usbx, ept_info->eptn)->diepctl_bit.setd0pid = TRUE; + } + } else { + USB_OUTEPT(usbx, ept_info->eptn)->doepctl_bit.stall = FALSE; + if (ept_info->trans_type == EPT_INT_TYPE || ept_info->trans_type == EPT_BULK_TYPE) { + USB_OUTEPT(usbx, ept_info->eptn)->doepctl_bit.setd0pid = TRUE; + } } - } - else - { - USB_OUTEPT(usbx, ept_info->eptn)->doepctl_bit.stall = FALSE; - if(ept_info->trans_type == EPT_INT_TYPE || ept_info->trans_type == EPT_BULK_TYPE) - { - USB_OUTEPT(usbx, ept_info->eptn)->doepctl_bit.setd0pid = TRUE; - } - } } /** @@ -632,10 +555,9 @@ void usb_ept_clear_stall(otg_global_type *usbx, usb_ept_info *ept_info) * - OTG2_GLOBAL * @retval out endpoint interrupt bits */ -uint32_t usb_get_all_out_interrupt(otg_global_type *usbx) -{ - uint32_t intsts = OTG_DEVICE(usbx)->daint; - return ((intsts & (OTG_DEVICE(usbx)->daintmsk)) >> 16); +uint32_t usb_get_all_out_interrupt(otg_global_type *usbx) { + uint32_t intsts = OTG_DEVICE(usbx)->daint; + return ((intsts & (OTG_DEVICE(usbx)->daintmsk)) >> 16); } /** @@ -646,10 +568,9 @@ uint32_t usb_get_all_out_interrupt(otg_global_type *usbx) * - OTG2_GLOBAL * @retval in endpoint interrupt bits */ -uint32_t usb_get_all_in_interrupt(otg_global_type *usbx) -{ - uint32_t intsts = OTG_DEVICE(usbx)->daint; - return ((intsts & (OTG_DEVICE(usbx)->daintmsk)) & 0xFFFF); +uint32_t usb_get_all_in_interrupt(otg_global_type *usbx) { + uint32_t intsts = OTG_DEVICE(usbx)->daint; + return ((intsts & (OTG_DEVICE(usbx)->daintmsk)) & 0xFFFF); } @@ -662,10 +583,9 @@ uint32_t usb_get_all_in_interrupt(otg_global_type *usbx) * @param eptn: endpoint number * @retval out endpoint interrupt flags */ -uint32_t usb_ept_out_interrupt(otg_global_type *usbx, uint32_t eptn) -{ - uint32_t intsts = USB_OUTEPT(usbx, eptn)->doepint; - return (intsts & (OTG_DEVICE(usbx)->doepmsk)); +uint32_t usb_ept_out_interrupt(otg_global_type *usbx, uint32_t eptn) { + uint32_t intsts = USB_OUTEPT(usbx, eptn)->doepint; + return (intsts & (OTG_DEVICE(usbx)->doepmsk)); } /** @@ -677,14 +597,13 @@ uint32_t usb_ept_out_interrupt(otg_global_type *usbx, uint32_t eptn) * @param eptn: endpoint number * @retval in endpoint intterupt flags */ -uint32_t usb_ept_in_interrupt(otg_global_type *usbx, uint32_t eptn) -{ - uint32_t intsts, mask1, mask2; - mask1 = OTG_DEVICE(usbx)->diepmsk; - mask2 = OTG_DEVICE(usbx)->diepempmsk; - mask1 |= ((mask2 >> eptn) & 0x1) << 7; - intsts = USB_INEPT(usbx, eptn)->diepint & mask1; - return intsts; +uint32_t usb_ept_in_interrupt(otg_global_type *usbx, uint32_t eptn) { + uint32_t intsts, mask1, mask2; + mask1 = OTG_DEVICE(usbx)->diepmsk; + mask2 = OTG_DEVICE(usbx)->diepempmsk; + mask1 |= ((mask2 >> eptn) & 0x1) << 7; + intsts = USB_INEPT(usbx, eptn)->diepint & mask1; + return intsts; } /** @@ -702,9 +621,8 @@ uint32_t usb_ept_in_interrupt(otg_global_type *usbx, uint32_t eptn) * - USB_OTG_DOEPINT_OTEPDIS_FLAG * - USB_OTG_DOEPINT_B2BSTUP_FLAG */ -void usb_ept_out_clear(otg_global_type *usbx, uint32_t eptn, uint32_t flag) -{ - USB_OUTEPT(usbx, eptn)->doepint = flag; +void usb_ept_out_clear(otg_global_type *usbx, uint32_t eptn, uint32_t flag) { + USB_OUTEPT(usbx, eptn)->doepint = flag; } /** @@ -723,9 +641,8 @@ void usb_ept_out_clear(otg_global_type *usbx, uint32_t eptn, uint32_t flag) * - USB_OTG_DIEPINT_INEPNE_FLAG * - USB_OTG_DIEPINT_TXFE_FLAG */ -void usb_ept_in_clear(otg_global_type *usbx, uint32_t eptn, uint32_t flag) -{ - USB_INEPT(usbx, eptn)->diepint = flag; +void usb_ept_in_clear(otg_global_type *usbx, uint32_t eptn, uint32_t flag) { + USB_INEPT(usbx, eptn)->diepint = flag; } @@ -738,9 +655,8 @@ void usb_ept_in_clear(otg_global_type *usbx, uint32_t eptn, uint32_t flag) * @param address: host assignment address * @retval none */ -void usb_set_address(otg_global_type *usbx, uint8_t address) -{ - OTG_DEVICE(usbx)->dcfg_bit.devaddr = address; +void usb_set_address(otg_global_type *usbx, uint8_t address) { + OTG_DEVICE(usbx)->dcfg_bit.devaddr = address; } /** @@ -751,13 +667,12 @@ void usb_set_address(otg_global_type *usbx, uint8_t address) * - OTG2_GLOBAL * @retval none */ -void usb_ept0_start(otg_global_type *usbx) -{ - otg_eptout_type *usb_outept = USB_OUTEPT(usbx, 0); - usb_outept->doeptsiz = 0; - usb_outept->doeptsiz_bit.pktcnt = 1; - usb_outept->doeptsiz_bit.xfersize = 24; - usb_outept->doeptsiz_bit.rxdpid_setupcnt = 3; +void usb_ept0_start(otg_global_type *usbx) { + otg_eptout_type *usb_outept = USB_OUTEPT(usbx, 0); + usb_outept->doeptsiz = 0; + usb_outept->doeptsiz_bit.pktcnt = 1; + usb_outept->doeptsiz_bit.xfersize = 24; + usb_outept->doeptsiz_bit.rxdpid_setupcnt = 3; } @@ -769,10 +684,9 @@ void usb_ept0_start(otg_global_type *usbx) * - OTG2_GLOBAL * @retval none */ -void usb_ept0_setup(otg_global_type *usbx) -{ - USB_INEPT(usbx, 0)->diepctl_bit.mps = 0; - OTG_DEVICE(usbx)->dctl_bit.cgnpinak = FALSE; +void usb_ept0_setup(otg_global_type *usbx) { + USB_INEPT(usbx, 0)->diepctl_bit.mps = 0; + OTG_DEVICE(usbx)->dctl_bit.cgnpinak = FALSE; } /** @@ -783,10 +697,9 @@ void usb_ept0_setup(otg_global_type *usbx) * - OTG2_GLOBAL * @retval none */ -void usb_connect(otg_global_type *usbx) -{ - /* D+ 1.5k pull-up enable */ - OTG_DEVICE(usbx)->dctl_bit.sftdiscon = FALSE; +void usb_connect(otg_global_type *usbx) { + /* D+ 1.5k pull-up enable */ + OTG_DEVICE(usbx)->dctl_bit.sftdiscon = FALSE; } /** @@ -797,10 +710,9 @@ void usb_connect(otg_global_type *usbx) * - OTG2_GLOBAL * @retval none */ -void usb_disconnect(otg_global_type *usbx) -{ - /* D+ 1.5k pull-up disable */ - OTG_DEVICE(usbx)->dctl_bit.sftdiscon = TRUE; +void usb_disconnect(otg_global_type *usbx) { + /* D+ 1.5k pull-up disable */ + OTG_DEVICE(usbx)->dctl_bit.sftdiscon = TRUE; } @@ -812,9 +724,8 @@ void usb_disconnect(otg_global_type *usbx) * - OTG2_GLOBAL * @retval none */ -void usb_remote_wkup_set(otg_global_type *usbx) -{ - OTG_DEVICE(usbx)->dctl_bit.rwkupsig = TRUE; +void usb_remote_wkup_set(otg_global_type *usbx) { + OTG_DEVICE(usbx)->dctl_bit.rwkupsig = TRUE; } /** @@ -825,9 +736,8 @@ void usb_remote_wkup_set(otg_global_type *usbx) * - OTG2_GLOBAL * @retval none */ -void usb_remote_wkup_clear(otg_global_type *usbx) -{ - OTG_DEVICE(usbx)->dctl_bit.rwkupsig = FALSE; +void usb_remote_wkup_clear(otg_global_type *usbx) { + OTG_DEVICE(usbx)->dctl_bit.rwkupsig = FALSE; } /** @@ -838,9 +748,8 @@ void usb_remote_wkup_clear(otg_global_type *usbx) * - OTG2_GLOBAL * @retval usb suspend status */ -uint8_t usb_suspend_status_get(otg_global_type *usbx) -{ - return OTG_DEVICE(usbx)->dsts_bit.suspsts; +uint8_t usb_suspend_status_get(otg_global_type *usbx) { + return OTG_DEVICE(usbx)->dsts_bit.suspsts; } #endif @@ -854,22 +763,18 @@ uint8_t usb_suspend_status_get(otg_global_type *usbx) * @param state: state (TRUE or FALSE) * @retval none */ -void usb_port_power_on(otg_global_type *usbx, confirm_state state) -{ - otg_host_type *usb_host = OTG_HOST(usbx); - uint32_t hprt_val = usb_host->hprt; +void usb_port_power_on(otg_global_type *usbx, confirm_state state) { + otg_host_type *usb_host = OTG_HOST(usbx); + uint32_t hprt_val = usb_host->hprt; - hprt_val &= ~(USB_OTG_HPRT_PRTENA | USB_OTG_HPRT_PRTENCHNG | - USB_OTG_HPRT_PRTOVRCACT | USB_OTG_HPRT_PRTCONDET); + hprt_val &= ~(USB_OTG_HPRT_PRTENA | USB_OTG_HPRT_PRTENCHNG | + USB_OTG_HPRT_PRTOVRCACT | USB_OTG_HPRT_PRTCONDET); - if(state == TRUE) - { - usb_host->hprt = hprt_val | USB_OTG_HPRT_PRTPWR; - } - else - { - usb_host->hprt = hprt_val & (~USB_OTG_HPRT_PRTPWR); - } + if (state == TRUE) { + usb_host->hprt = hprt_val | USB_OTG_HPRT_PRTPWR; + } else { + usb_host->hprt = hprt_val & (~USB_OTG_HPRT_PRTPWR); + } } /** @@ -880,10 +785,9 @@ void usb_port_power_on(otg_global_type *usbx, confirm_state state) * - OTG2_GLOBAL * @retval none */ -uint32_t usbh_get_frame(otg_global_type *usbx) -{ - otg_host_type *usb_host = OTG_HOST(usbx); - return usb_host->hfnum & 0xFFFF; +uint32_t usbh_get_frame(otg_global_type *usbx) { + otg_host_type *usb_host = OTG_HOST(usbx); + return usb_host->hfnum & 0xFFFF; } /** @@ -914,51 +818,47 @@ void usb_hc_enable(otg_global_type *usbx, uint8_t dev_address, uint8_t type, uint16_t maxpacket, - uint8_t speed) -{ - otg_hchannel_type *hch = USB_CHL(usbx, chn); - otg_host_type *usb_host = OTG_HOST(usbx); + uint8_t speed) { + otg_hchannel_type *hch = USB_CHL(usbx, chn); + otg_host_type *usb_host = OTG_HOST(usbx); - /* clear old interrupt flag */ - hch->hcint = 0xFFFFFFFF; + /* clear old interrupt flag */ + hch->hcint = 0xFFFFFFFF; - switch(type) - { - case EPT_CONTROL_TYPE: - case EPT_BULK_TYPE: - hch->hcintmsk |= USB_OTG_HC_XFERCM_INT | USB_OTG_HC_STALLM_INT | - USB_OTG_HC_XACTERRM_INT | USB_OTG_HC_NAKM_INT | - USB_OTG_HC_DTGLERRM_INT; - if(ept_num & 0x80) - { - hch->hcintmsk_bit.bblerrmsk = TRUE; - } - break; - case EPT_INT_TYPE: - hch->hcintmsk |= USB_OTG_HC_XFERCM_INT | USB_OTG_HC_STALLM_INT | - USB_OTG_HC_XACTERRM_INT | USB_OTG_HC_NAKM_INT | - USB_OTG_HC_DTGLERRM_INT | USB_OTG_HC_FRMOVRRUN_INT; - break; - case EPT_ISO_TYPE: + switch (type) { + case EPT_CONTROL_TYPE: + case EPT_BULK_TYPE: + hch->hcintmsk |= USB_OTG_HC_XFERCM_INT | USB_OTG_HC_STALLM_INT | + USB_OTG_HC_XACTERRM_INT | USB_OTG_HC_NAKM_INT | + USB_OTG_HC_DTGLERRM_INT; + if (ept_num & 0x80) { + hch->hcintmsk_bit.bblerrmsk = TRUE; + } + break; + case EPT_INT_TYPE: + hch->hcintmsk |= USB_OTG_HC_XFERCM_INT | USB_OTG_HC_STALLM_INT | + USB_OTG_HC_XACTERRM_INT | USB_OTG_HC_NAKM_INT | + USB_OTG_HC_DTGLERRM_INT | USB_OTG_HC_FRMOVRRUN_INT; + break; + case EPT_ISO_TYPE: - hch->hcintmsk |= USB_OTG_HC_XFERCM_INT | USB_OTG_HC_ACKM_INT | - USB_OTG_HC_FRMOVRRUN_INT; - break; - } - usb_host->haintmsk |= 1 << chn; - usbx->gintmsk_bit.hchintmsk = TRUE; + hch->hcintmsk |= USB_OTG_HC_XFERCM_INT | USB_OTG_HC_ACKM_INT | + USB_OTG_HC_FRMOVRRUN_INT; + break; + } + usb_host->haintmsk |= 1 << chn; + usbx->gintmsk_bit.hchintmsk = TRUE; - hch->hcchar_bit.devaddr = dev_address; - hch->hcchar_bit.eptnum = ept_num & 0x7F; - hch->hcchar_bit.eptdir = (ept_num & 0x80)?1:0; - hch->hcchar_bit.lspddev = (speed == USB_PRTSPD_LOW_SPEED)?1:0; - hch->hcchar_bit.eptype = type; - hch->hcchar_bit.mps = maxpacket; + hch->hcchar_bit.devaddr = dev_address; + hch->hcchar_bit.eptnum = ept_num & 0x7F; + hch->hcchar_bit.eptdir = (ept_num & 0x80) ? 1 : 0; + hch->hcchar_bit.lspddev = (speed == USB_PRTSPD_LOW_SPEED) ? 1 : 0; + hch->hcchar_bit.eptype = type; + hch->hcchar_bit.mps = maxpacket; - if(type == EPT_INT_TYPE) - { - hch->hcchar_bit.oddfrm = TRUE; - } + if (type == EPT_INT_TYPE) { + hch->hcchar_bit.oddfrm = TRUE; + } } /** @@ -969,10 +869,9 @@ void usb_hc_enable(otg_global_type *usbx, * - OTG2_GLOBAL * @retval interrupt flag */ -uint32_t usb_hch_read_interrupt(otg_global_type *usbx) -{ - otg_host_type *usb_host = OTG_HOST(usbx); - return usb_host->haint & 0xFFFF; +uint32_t usb_hch_read_interrupt(otg_global_type *usbx) { + otg_host_type *usb_host = OTG_HOST(usbx); + return usb_host->haint & 0xFFFF; } /** @@ -983,27 +882,24 @@ uint32_t usb_hch_read_interrupt(otg_global_type *usbx) * - OTG2_GLOBAL * @retval none */ -void usb_host_disable(otg_global_type *usbx) -{ - uint32_t i_index = 0; - otg_hchannel_type *hch; - otg_host_type *usb_host = OTG_HOST(usbx); +void usb_host_disable(otg_global_type *usbx) { + uint32_t i_index = 0; + otg_hchannel_type *hch; + otg_host_type *usb_host = OTG_HOST(usbx); - usbx->gahbcfg_bit.glbintmsk = FALSE; - usb_flush_rx_fifo(usbx); - usb_flush_tx_fifo(usbx, 0x10); + usbx->gahbcfg_bit.glbintmsk = FALSE; + usb_flush_rx_fifo(usbx); + usb_flush_tx_fifo(usbx, 0x10); - for(i_index = 0; i_index < 16; i_index ++) - { - hch = USB_CHL(usbx, i_index); - if(hch->hcchar_bit.chena == TRUE) - { - hch->hcchar_bit.chdis = TRUE; + for (i_index = 0; i_index < 16; i_index ++) { + hch = USB_CHL(usbx, i_index); + if (hch->hcchar_bit.chena == TRUE) { + hch->hcchar_bit.chdis = TRUE; + } } - } - usb_host->haint = 0xFFFFFFFF; - usbx->gintsts = 0xFFFFFFFF; - usbx->gahbcfg_bit.glbintmsk = TRUE; + usb_host->haint = 0xFFFFFFFF; + usbx->gintsts = 0xFFFFFFFF; + usbx->gahbcfg_bit.glbintmsk = TRUE; } /** @@ -1015,54 +911,42 @@ void usb_host_disable(otg_global_type *usbx) * @param chn: channel number * @retval none */ -void usb_hch_halt(otg_global_type *usbx, uint8_t chn) -{ - uint32_t count = 0; - otg_hchannel_type *usb_chh = USB_CHL(usbx, chn); - otg_host_type *usb_host = OTG_HOST(usbx); +void usb_hch_halt(otg_global_type *usbx, uint8_t chn) { + uint32_t count = 0; + otg_hchannel_type *usb_chh = USB_CHL(usbx, chn); + otg_host_type *usb_host = OTG_HOST(usbx); - /* endpoint type is control or bulk */ - if(usb_chh->hcchar_bit.eptype == EPT_CONTROL_TYPE || - usb_chh->hcchar_bit.eptype == EPT_BULK_TYPE) - { - usb_chh->hcchar_bit.chdis = TRUE; - if((usbx->gnptxsts_bit.nptxqspcavail) == 0) - { - usb_chh->hcchar_bit.chena = FALSE; - if(usb_chh->hcchar_bit.chena != TRUE) - usb_chh->hcchar_bit.chena = TRUE; - do - { - if(count ++ > 1000) - break; - }while(usb_chh->hcchar_bit.chena == SET); + /* endpoint type is control or bulk */ + if (usb_chh->hcchar_bit.eptype == EPT_CONTROL_TYPE || + usb_chh->hcchar_bit.eptype == EPT_BULK_TYPE) { + usb_chh->hcchar_bit.chdis = TRUE; + if ((usbx->gnptxsts_bit.nptxqspcavail) == 0) { + usb_chh->hcchar_bit.chena = FALSE; + if (usb_chh->hcchar_bit.chena != TRUE) + usb_chh->hcchar_bit.chena = TRUE; + do { + if (count ++ > 1000) + break; + } while (usb_chh->hcchar_bit.chena == SET); + } else { + if (usb_chh->hcchar_bit.chena != TRUE) + usb_chh->hcchar_bit.chena = TRUE; + } + } else { + usb_chh->hcchar_bit.chdis = TRUE; + if ((usb_host->hptxsts_bit.ptxqspcavil) == 0) { + usb_chh->hcchar_bit.chena = FALSE; + if (usb_chh->hcchar_bit.chena != TRUE) + usb_chh->hcchar_bit.chena = TRUE; + do { + if (count ++ > 1000) + break; + } while (usb_chh->hcchar_bit.chena == SET); + } else { + if (usb_chh->hcchar_bit.chena != TRUE) + usb_chh->hcchar_bit.chena = TRUE; + } } - else - { - if(usb_chh->hcchar_bit.chena != TRUE) - usb_chh->hcchar_bit.chena = TRUE; - } - } - else - { - usb_chh->hcchar_bit.chdis = TRUE; - if((usb_host->hptxsts_bit.ptxqspcavil) == 0) - { - usb_chh->hcchar_bit.chena = FALSE; - if(usb_chh->hcchar_bit.chena != TRUE) - usb_chh->hcchar_bit.chena = TRUE; - do - { - if(count ++ > 1000) - break; - }while(usb_chh->hcchar_bit.chena == SET); - } - else - { - if(usb_chh->hcchar_bit.chena != TRUE) - usb_chh->hcchar_bit.chena = TRUE; - } - } } /** * @brief select full or low speed clock @@ -1073,19 +957,15 @@ void usb_hch_halt(otg_global_type *usbx, uint8_t chn) * @param clk: clock frequency * @retval none */ -void usbh_fsls_clksel(otg_global_type *usbx, uint8_t clk) -{ - otg_host_type *usb_host = OTG_HOST(usbx); +void usbh_fsls_clksel(otg_global_type *usbx, uint8_t clk) { + otg_host_type *usb_host = OTG_HOST(usbx); - usb_host->hcfg_bit.fslspclksel = clk; - if(clk == USB_HCFG_CLK_6M) - { - usb_host->hfir = 6000; - } - else - { - usb_host->hfir = 48000; - } + usb_host->hcfg_bit.fslspclksel = clk; + if (clk == USB_HCFG_CLK_6M) { + usb_host->hfir = 6000; + } else { + usb_host->hfir = 48000; + } } #endif diff --git a/armlib/at32_sys/drivers/src/at32f435_437_wdt.c b/armlib/at32_sys/drivers/src/at32f435_437_wdt.c index ea3470a8f..c3af7a604 100644 --- a/armlib/at32_sys/drivers/src/at32f435_437_wdt.c +++ b/armlib/at32_sys/drivers/src/at32f435_437_wdt.c @@ -45,9 +45,8 @@ * @param none * @retval none */ -void wdt_enable(void) -{ - WDT->cmd = WDT_CMD_ENABLE; +void wdt_enable(void) { + WDT->cmd = WDT_CMD_ENABLE; } /** @@ -55,9 +54,8 @@ void wdt_enable(void) * @param none * @retval none */ -void wdt_counter_reload(void) -{ - WDT->cmd = WDT_CMD_RELOAD; +void wdt_counter_reload(void) { + WDT->cmd = WDT_CMD_RELOAD; } /** @@ -65,9 +63,8 @@ void wdt_counter_reload(void) * @param reload_value (0x0000~0x0FFF) * @retval none */ -void wdt_reload_value_set(uint16_t reload_value) -{ - WDT->rld = reload_value; +void wdt_reload_value_set(uint16_t reload_value) { + WDT->rld = reload_value; } /** @@ -83,9 +80,8 @@ void wdt_reload_value_set(uint16_t reload_value) * - WDT_CLK_DIV_256 * @retval none */ -void wdt_divider_set(wdt_division_type division) -{ - WDT->div_bit.div = division; +void wdt_divider_set(wdt_division_type division) { + WDT->div_bit.div = division; } /** @@ -93,16 +89,12 @@ void wdt_divider_set(wdt_division_type division) * @param new_state (TRUE or FALSE) * @retval none */ -void wdt_register_write_enable( confirm_state new_state) -{ - if(new_state == FALSE) - { - WDT->cmd = WDT_CMD_LOCK; - } - else - { - WDT->cmd = WDT_CMD_UNLOCK; - } +void wdt_register_write_enable(confirm_state new_state) { + if (new_state == FALSE) { + WDT->cmd = WDT_CMD_LOCK; + } else { + WDT->cmd = WDT_CMD_UNLOCK; + } } /** @@ -114,20 +106,16 @@ void wdt_register_write_enable( confirm_state new_state) * - WDT_WINF_UPDATE_FLAG: window value update complete flag. * @retval state of wdt flag */ -flag_status wdt_flag_get(uint16_t wdt_flag) -{ - flag_status status = RESET; +flag_status wdt_flag_get(uint16_t wdt_flag) { + flag_status status = RESET; - if ((WDT->sts & wdt_flag) != (uint16_t)RESET) - { - status = SET; - } - else - { - status = RESET; - } + if ((WDT->sts & wdt_flag) != (uint16_t)RESET) { + status = SET; + } else { + status = RESET; + } - return status; + return status; } /** @@ -135,9 +123,8 @@ flag_status wdt_flag_get(uint16_t wdt_flag) * @param window_cnt (0x0000~0x0FFF) * @retval none */ -void wdt_window_counter_set(uint16_t window_cnt) -{ - WDT->win_bit.win = window_cnt; +void wdt_window_counter_set(uint16_t window_cnt) { + WDT->win_bit.win = window_cnt; } /** diff --git a/armlib/at32_sys/drivers/src/at32f435_437_wwdt.c b/armlib/at32_sys/drivers/src/at32f435_437_wwdt.c index d819bfadc..e52f92986 100644 --- a/armlib/at32_sys/drivers/src/at32f435_437_wwdt.c +++ b/armlib/at32_sys/drivers/src/at32f435_437_wwdt.c @@ -45,10 +45,9 @@ * @brief wwdt reset by crm reset register * @retval none */ -void wwdt_reset(void) -{ - crm_periph_reset(CRM_WWDT_PERIPH_RESET, TRUE); - crm_periph_reset(CRM_WWDT_PERIPH_RESET, FALSE); +void wwdt_reset(void) { + crm_periph_reset(CRM_WWDT_PERIPH_RESET, TRUE); + crm_periph_reset(CRM_WWDT_PERIPH_RESET, FALSE); } /** @@ -61,9 +60,8 @@ void wwdt_reset(void) * - WWDT_PCLK1_DIV_32768 (wwdt counter clock = (pclk1/4096)/8) * @retval none */ -void wwdt_divider_set(wwdt_division_type division) -{ - WWDT->cfg_bit.div = division; +void wwdt_divider_set(wwdt_division_type division) { + WWDT->cfg_bit.div = division; } /** @@ -71,9 +69,8 @@ void wwdt_divider_set(wwdt_division_type division) * @param none * @retval none */ -void wwdt_flag_clear(void) -{ - WWDT->sts = 0; +void wwdt_flag_clear(void) { + WWDT->sts = 0; } /** @@ -81,9 +78,8 @@ void wwdt_flag_clear(void) * @param wwdt_cnt (0x40~0x7f) * @retval none */ -void wwdt_enable(uint8_t wwdt_cnt) -{ - WWDT->ctrl = wwdt_cnt | WWDT_EN_BIT; +void wwdt_enable(uint8_t wwdt_cnt) { + WWDT->ctrl = wwdt_cnt | WWDT_EN_BIT; } /** @@ -91,9 +87,8 @@ void wwdt_enable(uint8_t wwdt_cnt) * @param none * @retval none */ -void wwdt_interrupt_enable(void) -{ - WWDT->cfg_bit.rldien = TRUE; +void wwdt_interrupt_enable(void) { + WWDT->cfg_bit.rldien = TRUE; } /** @@ -101,9 +96,8 @@ void wwdt_interrupt_enable(void) * @param none * @retval state of reload counter interrupt flag */ -flag_status wwdt_flag_get(void) -{ - return (flag_status)WWDT->sts_bit.rldf; +flag_status wwdt_flag_get(void) { + return (flag_status)WWDT->sts_bit.rldf; } /** @@ -111,9 +105,8 @@ flag_status wwdt_flag_get(void) * @param none * @retval state of reload counter interrupt flag */ -flag_status wwdt_interrupt_flag_get(void) -{ - return (flag_status)(WWDT->sts_bit.rldf && WWDT->cfg_bit.rldien); +flag_status wwdt_interrupt_flag_get(void) { + return (flag_status)(WWDT->sts_bit.rldf && WWDT->cfg_bit.rldien); } /** @@ -121,9 +114,8 @@ flag_status wwdt_interrupt_flag_get(void) * @param wwdt_cnt (0x40~0x7f) * @retval none */ -void wwdt_counter_set(uint8_t wwdt_cnt) -{ - WWDT->ctrl_bit.cnt = wwdt_cnt; +void wwdt_counter_set(uint8_t wwdt_cnt) { + WWDT->ctrl_bit.cnt = wwdt_cnt; } /** @@ -131,9 +123,8 @@ void wwdt_counter_set(uint8_t wwdt_cnt) * @param window_cnt (0x40~0x7f) * @retval none */ -void wwdt_window_counter_set(uint8_t window_cnt) -{ - WWDT->cfg_bit.win = window_cnt; +void wwdt_window_counter_set(uint8_t window_cnt) { + WWDT->cfg_bit.win = window_cnt; } /** diff --git a/armlib/at32_sys/drivers/src/at32f435_437_xmc.c b/armlib/at32_sys/drivers/src/at32f435_437_xmc.c index ba4914dce..719674d41 100644 --- a/armlib/at32_sys/drivers/src/at32f435_437_xmc.c +++ b/armlib/at32_sys/drivers/src/at32f435_437_xmc.c @@ -50,20 +50,17 @@ * - XMC_BANK1_NOR_SRAM4 * @retval none */ -void xmc_nor_sram_reset(xmc_nor_sram_subbank_type xmc_subbank) -{ - /* XMC_BANK1_NORSRAM1 */ - if(xmc_subbank == XMC_BANK1_NOR_SRAM1) - { - XMC_BANK1->ctrl_tmg_group[xmc_subbank].bk1ctrl = 0x000030DB; - } - /* XMC_BANK1_NORSRAM2, XMC_BANK1_NORSRAM3 or XMC_BANK1_NORSRAM4 */ - else - { - XMC_BANK1->ctrl_tmg_group[xmc_subbank].bk1ctrl = 0x000030D2; - } - XMC_BANK1->ctrl_tmg_group[xmc_subbank].bk1tmg = 0x0FFFFFFF; - XMC_BANK1->tmgwr_group[xmc_subbank].bk1tmgwr = 0x0FFFFFFF; +void xmc_nor_sram_reset(xmc_nor_sram_subbank_type xmc_subbank) { + /* XMC_BANK1_NORSRAM1 */ + if (xmc_subbank == XMC_BANK1_NOR_SRAM1) { + XMC_BANK1->ctrl_tmg_group[xmc_subbank].bk1ctrl = 0x000030DB; + } + /* XMC_BANK1_NORSRAM2, XMC_BANK1_NORSRAM3 or XMC_BANK1_NORSRAM4 */ + else { + XMC_BANK1->ctrl_tmg_group[xmc_subbank].bk1ctrl = 0x000030D2; + } + XMC_BANK1->ctrl_tmg_group[xmc_subbank].bk1tmg = 0x0FFFFFFF; + XMC_BANK1->tmgwr_group[xmc_subbank].bk1tmgwr = 0x0FFFFFFF; } /** @@ -74,28 +71,26 @@ void xmc_nor_sram_reset(xmc_nor_sram_subbank_type xmc_subbank) * the xmc nor/sram specified banks. * @retval none */ -void xmc_nor_sram_init(xmc_norsram_init_type* xmc_norsram_init_struct) -{ - /* bank1 nor/sram control register configuration */ - XMC_BANK1->ctrl_tmg_group[xmc_norsram_init_struct->subbank].bk1ctrl = - (uint32_t)xmc_norsram_init_struct->data_addr_multiplex | - xmc_norsram_init_struct->device | - xmc_norsram_init_struct->bus_type | - xmc_norsram_init_struct->burst_mode_enable | - xmc_norsram_init_struct->asynwait_enable | - xmc_norsram_init_struct->wait_signal_lv | - xmc_norsram_init_struct->wrapped_mode_enable | - xmc_norsram_init_struct->wait_signal_config | - xmc_norsram_init_struct->write_enable | - xmc_norsram_init_struct->wait_signal_enable | - xmc_norsram_init_struct->write_timing_enable | - xmc_norsram_init_struct->write_burst_syn; +void xmc_nor_sram_init(xmc_norsram_init_type *xmc_norsram_init_struct) { + /* bank1 nor/sram control register configuration */ + XMC_BANK1->ctrl_tmg_group[xmc_norsram_init_struct->subbank].bk1ctrl = + (uint32_t)xmc_norsram_init_struct->data_addr_multiplex | + xmc_norsram_init_struct->device | + xmc_norsram_init_struct->bus_type | + xmc_norsram_init_struct->burst_mode_enable | + xmc_norsram_init_struct->asynwait_enable | + xmc_norsram_init_struct->wait_signal_lv | + xmc_norsram_init_struct->wrapped_mode_enable | + xmc_norsram_init_struct->wait_signal_config | + xmc_norsram_init_struct->write_enable | + xmc_norsram_init_struct->wait_signal_enable | + xmc_norsram_init_struct->write_timing_enable | + xmc_norsram_init_struct->write_burst_syn; - /* if nor flash device */ - if(xmc_norsram_init_struct->device == XMC_DEVICE_NOR) - { - XMC_BANK1->ctrl_tmg_group[xmc_norsram_init_struct->subbank].bk1ctrl_bit.noren = 0x1; - } + /* if nor flash device */ + if (xmc_norsram_init_struct->device == XMC_DEVICE_NOR) { + XMC_BANK1->ctrl_tmg_group[xmc_norsram_init_struct->subbank].bk1ctrl_bit.noren = 0x1; + } } /** @@ -109,35 +104,31 @@ void xmc_nor_sram_init(xmc_norsram_init_type* xmc_norsram_init_struct) * the xmc nor/sram specified banks. * @retval none */ -void xmc_nor_sram_timing_config(xmc_norsram_timing_init_type* xmc_rw_timing_struct, - xmc_norsram_timing_init_type* xmc_w_timing_struct) -{ - /* bank1 nor/sram timing register configuration */ - XMC_BANK1->ctrl_tmg_group[xmc_rw_timing_struct->subbank].bk1tmg = - (uint32_t)xmc_rw_timing_struct->addr_setup_time | - (xmc_rw_timing_struct->addr_hold_time << 4) | - (xmc_rw_timing_struct->data_setup_time << 8) | - (xmc_rw_timing_struct->bus_latency_time <<16) | - (xmc_rw_timing_struct->clk_psc << 20) | - (xmc_rw_timing_struct->data_latency_time << 24) | - xmc_rw_timing_struct->mode; +void xmc_nor_sram_timing_config(xmc_norsram_timing_init_type *xmc_rw_timing_struct, + xmc_norsram_timing_init_type *xmc_w_timing_struct) { + /* bank1 nor/sram timing register configuration */ + XMC_BANK1->ctrl_tmg_group[xmc_rw_timing_struct->subbank].bk1tmg = + (uint32_t)xmc_rw_timing_struct->addr_setup_time | + (xmc_rw_timing_struct->addr_hold_time << 4) | + (xmc_rw_timing_struct->data_setup_time << 8) | + (xmc_rw_timing_struct->bus_latency_time << 16) | + (xmc_rw_timing_struct->clk_psc << 20) | + (xmc_rw_timing_struct->data_latency_time << 24) | + xmc_rw_timing_struct->mode; - /* bank1 nor/sram timing register for write configuration, if extended mode is used */ - if(xmc_rw_timing_struct->write_timing_enable == XMC_WRITE_TIMING_ENABLE) - { - XMC_BANK1->tmgwr_group[xmc_w_timing_struct->subbank].bk1tmgwr = - (uint32_t)xmc_w_timing_struct->addr_setup_time | - (xmc_w_timing_struct->addr_hold_time << 4) | - (xmc_w_timing_struct->data_setup_time << 8) | - (xmc_w_timing_struct->bus_latency_time << 16) | - (xmc_w_timing_struct->clk_psc << 20) | - (xmc_w_timing_struct->data_latency_time << 24) | - xmc_w_timing_struct->mode; - } - else - { - XMC_BANK1->tmgwr_group[xmc_w_timing_struct->subbank].bk1tmgwr = 0x0FFFFFFF; - } + /* bank1 nor/sram timing register for write configuration, if extended mode is used */ + if (xmc_rw_timing_struct->write_timing_enable == XMC_WRITE_TIMING_ENABLE) { + XMC_BANK1->tmgwr_group[xmc_w_timing_struct->subbank].bk1tmgwr = + (uint32_t)xmc_w_timing_struct->addr_setup_time | + (xmc_w_timing_struct->addr_hold_time << 4) | + (xmc_w_timing_struct->data_setup_time << 8) | + (xmc_w_timing_struct->bus_latency_time << 16) | + (xmc_w_timing_struct->clk_psc << 20) | + (xmc_w_timing_struct->data_latency_time << 24) | + xmc_w_timing_struct->mode; + } else { + XMC_BANK1->tmgwr_group[xmc_w_timing_struct->subbank].bk1tmgwr = 0x0FFFFFFF; + } } /** @@ -146,22 +137,21 @@ void xmc_nor_sram_timing_config(xmc_norsram_timing_init_type* xmc_rw_timing_stru * structure which will be initialized. * @retval none */ -void xmc_norsram_default_para_init(xmc_norsram_init_type* xmc_nor_sram_init_struct) -{ - /* reset nor/sram init structure parameters values */ - xmc_nor_sram_init_struct->subbank = XMC_BANK1_NOR_SRAM1; - xmc_nor_sram_init_struct->data_addr_multiplex = XMC_DATA_ADDR_MUX_ENABLE; - xmc_nor_sram_init_struct->device = XMC_DEVICE_SRAM; - xmc_nor_sram_init_struct->bus_type = XMC_BUSTYPE_8_BITS; - xmc_nor_sram_init_struct->burst_mode_enable = XMC_BURST_MODE_DISABLE; - xmc_nor_sram_init_struct->asynwait_enable = XMC_ASYN_WAIT_DISABLE; - xmc_nor_sram_init_struct->wait_signal_lv = XMC_WAIT_SIGNAL_LEVEL_LOW; - xmc_nor_sram_init_struct->wrapped_mode_enable = XMC_WRAPPED_MODE_DISABLE; - xmc_nor_sram_init_struct->wait_signal_config = XMC_WAIT_SIGNAL_SYN_BEFORE; - xmc_nor_sram_init_struct->write_enable = XMC_WRITE_OPERATION_ENABLE; - xmc_nor_sram_init_struct->wait_signal_enable = XMC_WAIT_SIGNAL_ENABLE; - xmc_nor_sram_init_struct->write_timing_enable = XMC_WRITE_TIMING_DISABLE; - xmc_nor_sram_init_struct->write_burst_syn = XMC_WRITE_BURST_SYN_DISABLE; +void xmc_norsram_default_para_init(xmc_norsram_init_type *xmc_nor_sram_init_struct) { + /* reset nor/sram init structure parameters values */ + xmc_nor_sram_init_struct->subbank = XMC_BANK1_NOR_SRAM1; + xmc_nor_sram_init_struct->data_addr_multiplex = XMC_DATA_ADDR_MUX_ENABLE; + xmc_nor_sram_init_struct->device = XMC_DEVICE_SRAM; + xmc_nor_sram_init_struct->bus_type = XMC_BUSTYPE_8_BITS; + xmc_nor_sram_init_struct->burst_mode_enable = XMC_BURST_MODE_DISABLE; + xmc_nor_sram_init_struct->asynwait_enable = XMC_ASYN_WAIT_DISABLE; + xmc_nor_sram_init_struct->wait_signal_lv = XMC_WAIT_SIGNAL_LEVEL_LOW; + xmc_nor_sram_init_struct->wrapped_mode_enable = XMC_WRAPPED_MODE_DISABLE; + xmc_nor_sram_init_struct->wait_signal_config = XMC_WAIT_SIGNAL_SYN_BEFORE; + xmc_nor_sram_init_struct->write_enable = XMC_WRITE_OPERATION_ENABLE; + xmc_nor_sram_init_struct->wait_signal_enable = XMC_WAIT_SIGNAL_ENABLE; + xmc_nor_sram_init_struct->write_timing_enable = XMC_WRITE_TIMING_DISABLE; + xmc_nor_sram_init_struct->write_burst_syn = XMC_WRITE_BURST_SYN_DISABLE; } /** @@ -172,27 +162,26 @@ void xmc_norsram_default_para_init(xmc_norsram_init_type* xmc_nor_sram_init_stru * structure which will be initialized. * @retval none */ -void xmc_norsram_timing_default_para_init(xmc_norsram_timing_init_type* xmc_rw_timing_struct, - xmc_norsram_timing_init_type* xmc_w_timing_struct) -{ - xmc_rw_timing_struct->subbank = XMC_BANK1_NOR_SRAM1; - xmc_rw_timing_struct->write_timing_enable = XMC_WRITE_TIMING_DISABLE; - xmc_rw_timing_struct->addr_setup_time = 0xF; - xmc_rw_timing_struct->addr_hold_time = 0xF; - xmc_rw_timing_struct->data_setup_time = 0xFF; - xmc_rw_timing_struct->bus_latency_time = 0xF; - xmc_rw_timing_struct->clk_psc = 0xF; - xmc_rw_timing_struct->data_latency_time = 0xF; - xmc_rw_timing_struct->mode = XMC_ACCESS_MODE_A; - xmc_w_timing_struct->subbank = XMC_BANK1_NOR_SRAM1; - xmc_w_timing_struct->write_timing_enable = XMC_WRITE_TIMING_DISABLE; - xmc_w_timing_struct->addr_setup_time = 0xF; - xmc_w_timing_struct->addr_hold_time = 0xF; - xmc_w_timing_struct->data_setup_time = 0xFF; - xmc_w_timing_struct->bus_latency_time = 0xF; - xmc_w_timing_struct->clk_psc = 0xF; - xmc_w_timing_struct->data_latency_time = 0xF; - xmc_w_timing_struct->mode = XMC_ACCESS_MODE_A; +void xmc_norsram_timing_default_para_init(xmc_norsram_timing_init_type *xmc_rw_timing_struct, + xmc_norsram_timing_init_type *xmc_w_timing_struct) { + xmc_rw_timing_struct->subbank = XMC_BANK1_NOR_SRAM1; + xmc_rw_timing_struct->write_timing_enable = XMC_WRITE_TIMING_DISABLE; + xmc_rw_timing_struct->addr_setup_time = 0xF; + xmc_rw_timing_struct->addr_hold_time = 0xF; + xmc_rw_timing_struct->data_setup_time = 0xFF; + xmc_rw_timing_struct->bus_latency_time = 0xF; + xmc_rw_timing_struct->clk_psc = 0xF; + xmc_rw_timing_struct->data_latency_time = 0xF; + xmc_rw_timing_struct->mode = XMC_ACCESS_MODE_A; + xmc_w_timing_struct->subbank = XMC_BANK1_NOR_SRAM1; + xmc_w_timing_struct->write_timing_enable = XMC_WRITE_TIMING_DISABLE; + xmc_w_timing_struct->addr_setup_time = 0xF; + xmc_w_timing_struct->addr_hold_time = 0xF; + xmc_w_timing_struct->data_setup_time = 0xFF; + xmc_w_timing_struct->bus_latency_time = 0xF; + xmc_w_timing_struct->clk_psc = 0xF; + xmc_w_timing_struct->data_latency_time = 0xF; + xmc_w_timing_struct->mode = XMC_ACCESS_MODE_A; } /** @@ -206,9 +195,8 @@ void xmc_norsram_timing_default_para_init(xmc_norsram_timing_init_type* xmc_rw_t * @param new_state (TRUE or FALSE) * @retval none */ -void xmc_nor_sram_enable(xmc_nor_sram_subbank_type xmc_subbank, confirm_state new_state) -{ - XMC_BANK1->ctrl_tmg_group[xmc_subbank].bk1ctrl_bit.en = new_state; +void xmc_nor_sram_enable(xmc_nor_sram_subbank_type xmc_subbank, confirm_state new_state) { + XMC_BANK1->ctrl_tmg_group[xmc_subbank].bk1ctrl_bit.en = new_state; } /** @@ -223,10 +211,9 @@ void xmc_nor_sram_enable(xmc_nor_sram_subbank_type xmc_subbank, confirm_state ne * @param r2r_timing :read timing * @retval none */ -void xmc_ext_timing_config(volatile xmc_nor_sram_subbank_type xmc_sub_bank, uint16_t w2w_timing, uint16_t r2r_timing) -{ - XMC_BANK1->ext_bit[xmc_sub_bank].buslatr2r = r2r_timing; - XMC_BANK1->ext_bit[xmc_sub_bank].buslatw2w = w2w_timing; +void xmc_ext_timing_config(volatile xmc_nor_sram_subbank_type xmc_sub_bank, uint16_t w2w_timing, uint16_t r2r_timing) { + XMC_BANK1->ext_bit[xmc_sub_bank].buslatr2r = r2r_timing; + XMC_BANK1->ext_bit[xmc_sub_bank].buslatw2w = w2w_timing; } /** @@ -237,24 +224,21 @@ void xmc_ext_timing_config(volatile xmc_nor_sram_subbank_type xmc_sub_bank, uint * - XMC_BANK3_NAND * @retval none */ -void xmc_nand_reset(xmc_class_bank_type xmc_bank) -{ - /* set the xmc_bank2_nand registers to their reset values */ - if(xmc_bank == XMC_BANK2_NAND) - { - XMC_BANK2->bk2ctrl = 0x00000018; - XMC_BANK2->bk2is = 0x00000040; - XMC_BANK2->bk2tmgatt = 0xFCFCFCFC; - XMC_BANK2->bk2tmgmem = 0xFCFCFCFC; - } - /* set the xmc_bank3_nand registers to their reset values */ - else - { - XMC_BANK3->bk3ctrl = 0x00000018; - XMC_BANK3->bk3is = 0x00000040; - XMC_BANK3->bk3tmgatt = 0xFCFCFCFC; - XMC_BANK3->bk3tmgmem = 0xFCFCFCFC; - } +void xmc_nand_reset(xmc_class_bank_type xmc_bank) { + /* set the xmc_bank2_nand registers to their reset values */ + if (xmc_bank == XMC_BANK2_NAND) { + XMC_BANK2->bk2ctrl = 0x00000018; + XMC_BANK2->bk2is = 0x00000040; + XMC_BANK2->bk2tmgatt = 0xFCFCFCFC; + XMC_BANK2->bk2tmgmem = 0xFCFCFCFC; + } + /* set the xmc_bank3_nand registers to their reset values */ + else { + XMC_BANK3->bk3ctrl = 0x00000018; + XMC_BANK3->bk3is = 0x00000040; + XMC_BANK3->bk3tmgatt = 0xFCFCFCFC; + XMC_BANK3->bk3tmgmem = 0xFCFCFCFC; + } } /** @@ -265,29 +249,26 @@ void xmc_nand_reset(xmc_class_bank_type xmc_bank) * nand specified banks. * @retval none */ -void xmc_nand_init(xmc_nand_init_type* xmc_nand_init_struct) -{ - uint32_t tempctrl = 0x0; +void xmc_nand_init(xmc_nand_init_type *xmc_nand_init_struct) { + uint32_t tempctrl = 0x0; - /* Set the tempctrl value according to xmc_nand_init_struct parameters */ - tempctrl = (uint32_t)xmc_nand_init_struct->wait_enable | - xmc_nand_init_struct->bus_type | - xmc_nand_init_struct->ecc_enable | - xmc_nand_init_struct->ecc_pagesize | - (xmc_nand_init_struct->delay_time_cycle << 9) | - (xmc_nand_init_struct->delay_time_ar << 13) | - 0x00000008; + /* Set the tempctrl value according to xmc_nand_init_struct parameters */ + tempctrl = (uint32_t)xmc_nand_init_struct->wait_enable | + xmc_nand_init_struct->bus_type | + xmc_nand_init_struct->ecc_enable | + xmc_nand_init_struct->ecc_pagesize | + (xmc_nand_init_struct->delay_time_cycle << 9) | + (xmc_nand_init_struct->delay_time_ar << 13) | + 0x00000008; - /* xmc_bank2_nand registers configuration */ - if(xmc_nand_init_struct->nand_bank == XMC_BANK2_NAND) - { - XMC_BANK2->bk2ctrl = tempctrl; - } - /* xmc_bank3_nand registers configuration */ - else - { - XMC_BANK3->bk3ctrl = tempctrl; - } + /* xmc_bank2_nand registers configuration */ + if (xmc_nand_init_struct->nand_bank == XMC_BANK2_NAND) { + XMC_BANK2->bk2ctrl = tempctrl; + } + /* xmc_bank3_nand registers configuration */ + else { + XMC_BANK3->bk3ctrl = tempctrl; + } } /** @@ -301,33 +282,29 @@ void xmc_nand_init(xmc_nand_init_type* xmc_nand_init_struct) * nand specified banks. * @retval none */ -void xmc_nand_timing_config(xmc_nand_pccard_timinginit_type* xmc_regular_spacetiming_struct, - xmc_nand_pccard_timinginit_type* xmc_special_spacetiming_struct) -{ - uint32_t tempmem = 0x0, tempatt = 0x0; +void xmc_nand_timing_config(xmc_nand_pccard_timinginit_type *xmc_regular_spacetiming_struct, + xmc_nand_pccard_timinginit_type *xmc_special_spacetiming_struct) { + uint32_t tempmem = 0x0, tempatt = 0x0; - /* set the tempmem value according to xmc_nand_init_struct parameters */ - tempmem = (uint32_t)xmc_regular_spacetiming_struct->mem_setup_time | - (xmc_regular_spacetiming_struct->mem_waite_time << 8) | - (xmc_regular_spacetiming_struct->mem_hold_time << 16) | - (xmc_regular_spacetiming_struct->mem_hiz_time << 24); + /* set the tempmem value according to xmc_nand_init_struct parameters */ + tempmem = (uint32_t)xmc_regular_spacetiming_struct->mem_setup_time | + (xmc_regular_spacetiming_struct->mem_waite_time << 8) | + (xmc_regular_spacetiming_struct->mem_hold_time << 16) | + (xmc_regular_spacetiming_struct->mem_hiz_time << 24); - /* set the tempatt value according to xmc_nand_init_struct parameters */ - tempatt = (uint32_t)xmc_special_spacetiming_struct->mem_setup_time | - (xmc_special_spacetiming_struct->mem_waite_time << 8) | - (xmc_special_spacetiming_struct->mem_hold_time << 16) | - (xmc_special_spacetiming_struct->mem_hiz_time << 24); - /* xmc_bank2_nand registers configuration */ - if(xmc_regular_spacetiming_struct->class_bank == XMC_BANK2_NAND) - { - XMC_BANK2->bk2tmgatt = tempatt; - XMC_BANK2->bk2tmgmem = tempmem; - } - else - { - XMC_BANK3->bk3tmgatt = tempatt; - XMC_BANK3->bk3tmgmem = tempmem; - } + /* set the tempatt value according to xmc_nand_init_struct parameters */ + tempatt = (uint32_t)xmc_special_spacetiming_struct->mem_setup_time | + (xmc_special_spacetiming_struct->mem_waite_time << 8) | + (xmc_special_spacetiming_struct->mem_hold_time << 16) | + (xmc_special_spacetiming_struct->mem_hiz_time << 24); + /* xmc_bank2_nand registers configuration */ + if (xmc_regular_spacetiming_struct->class_bank == XMC_BANK2_NAND) { + XMC_BANK2->bk2tmgatt = tempatt; + XMC_BANK2->bk2tmgmem = tempmem; + } else { + XMC_BANK3->bk3tmgatt = tempatt; + XMC_BANK3->bk3tmgmem = tempmem; + } } /** @@ -336,16 +313,15 @@ void xmc_nand_timing_config(xmc_nand_pccard_timinginit_type* xmc_regular_spaceti * structure which will be initialized. * @retval none */ -void xmc_nand_default_para_init(xmc_nand_init_type* xmc_nand_init_struct) -{ - /* reset nand init structure parameters values */ - xmc_nand_init_struct->nand_bank = XMC_BANK2_NAND; - xmc_nand_init_struct->wait_enable = XMC_WAIT_OPERATION_DISABLE; - xmc_nand_init_struct->bus_type = XMC_BUSTYPE_8_BITS; - xmc_nand_init_struct->ecc_enable = XMC_ECC_OPERATION_DISABLE; - xmc_nand_init_struct->ecc_pagesize = XMC_ECC_PAGESIZE_256_BYTES; - xmc_nand_init_struct->delay_time_cycle = 0x0; - xmc_nand_init_struct->delay_time_ar = 0x0; +void xmc_nand_default_para_init(xmc_nand_init_type *xmc_nand_init_struct) { + /* reset nand init structure parameters values */ + xmc_nand_init_struct->nand_bank = XMC_BANK2_NAND; + xmc_nand_init_struct->wait_enable = XMC_WAIT_OPERATION_DISABLE; + xmc_nand_init_struct->bus_type = XMC_BUSTYPE_8_BITS; + xmc_nand_init_struct->ecc_enable = XMC_ECC_OPERATION_DISABLE; + xmc_nand_init_struct->ecc_pagesize = XMC_ECC_PAGESIZE_256_BYTES; + xmc_nand_init_struct->delay_time_cycle = 0x0; + xmc_nand_init_struct->delay_time_ar = 0x0; } /** @@ -356,19 +332,18 @@ void xmc_nand_default_para_init(xmc_nand_init_type* xmc_nand_init_struct) * structure which will be initialized. * @retval none */ -void xmc_nand_timing_default_para_init(xmc_nand_pccard_timinginit_type* xmc_regular_spacetiming_struct, - xmc_nand_pccard_timinginit_type* xmc_special_spacetiming_struct) -{ - xmc_regular_spacetiming_struct->class_bank = XMC_BANK2_NAND; - xmc_regular_spacetiming_struct->mem_hold_time = 0xFC; - xmc_regular_spacetiming_struct->mem_waite_time = 0xFC; - xmc_regular_spacetiming_struct->mem_setup_time = 0xFC; - xmc_regular_spacetiming_struct->mem_hiz_time = 0xFC; - xmc_special_spacetiming_struct->class_bank = XMC_BANK2_NAND; - xmc_special_spacetiming_struct->mem_hold_time = 0xFC; - xmc_special_spacetiming_struct->mem_waite_time = 0xFC; - xmc_special_spacetiming_struct->mem_setup_time = 0xFC; - xmc_special_spacetiming_struct->mem_hiz_time = 0xFC; +void xmc_nand_timing_default_para_init(xmc_nand_pccard_timinginit_type *xmc_regular_spacetiming_struct, + xmc_nand_pccard_timinginit_type *xmc_special_spacetiming_struct) { + xmc_regular_spacetiming_struct->class_bank = XMC_BANK2_NAND; + xmc_regular_spacetiming_struct->mem_hold_time = 0xFC; + xmc_regular_spacetiming_struct->mem_waite_time = 0xFC; + xmc_regular_spacetiming_struct->mem_setup_time = 0xFC; + xmc_regular_spacetiming_struct->mem_hiz_time = 0xFC; + xmc_special_spacetiming_struct->class_bank = XMC_BANK2_NAND; + xmc_special_spacetiming_struct->mem_hold_time = 0xFC; + xmc_special_spacetiming_struct->mem_waite_time = 0xFC; + xmc_special_spacetiming_struct->mem_setup_time = 0xFC; + xmc_special_spacetiming_struct->mem_hiz_time = 0xFC; } /** @@ -380,18 +355,15 @@ void xmc_nand_timing_default_para_init(xmc_nand_pccard_timinginit_type* xmc_regu * @param new_state (TRUE or FALSE) * @retval none */ -void xmc_nand_enable(xmc_class_bank_type xmc_bank, confirm_state new_state) -{ - /* enable or disable the nand bank2 by setting the en bit in the bk2ctrl register */ - if(xmc_bank == XMC_BANK2_NAND) - { - XMC_BANK2->bk2ctrl_bit.en = new_state; - } - /* enable or disable the nand bank3 by setting the en bit in the bk3ctrl register */ - else - { - XMC_BANK3->bk3ctrl_bit.en = new_state; - } +void xmc_nand_enable(xmc_class_bank_type xmc_bank, confirm_state new_state) { + /* enable or disable the nand bank2 by setting the en bit in the bk2ctrl register */ + if (xmc_bank == XMC_BANK2_NAND) { + XMC_BANK2->bk2ctrl_bit.en = new_state; + } + /* enable or disable the nand bank3 by setting the en bit in the bk3ctrl register */ + else { + XMC_BANK3->bk3ctrl_bit.en = new_state; + } } /** @@ -403,18 +375,15 @@ void xmc_nand_enable(xmc_class_bank_type xmc_bank, confirm_state new_state) * @param new_state (TRUE or FALSE) * @retval none */ -void xmc_nand_ecc_enable(xmc_class_bank_type xmc_bank, confirm_state new_state) -{ - /* enable the selected nand bank2 ecc function by setting the eccen bit in the bk2ctrl register */ - if(xmc_bank == XMC_BANK2_NAND) - { - XMC_BANK2->bk2ctrl_bit.eccen = new_state; - } - /* enable the selected nand bank3 ecc function by setting the eccen bit in the bk3ctrl register */ - else - { - XMC_BANK3->bk3ctrl_bit.eccen = new_state; - } +void xmc_nand_ecc_enable(xmc_class_bank_type xmc_bank, confirm_state new_state) { + /* enable the selected nand bank2 ecc function by setting the eccen bit in the bk2ctrl register */ + if (xmc_bank == XMC_BANK2_NAND) { + XMC_BANK2->bk2ctrl_bit.eccen = new_state; + } + /* enable the selected nand bank3 ecc function by setting the eccen bit in the bk3ctrl register */ + else { + XMC_BANK3->bk3ctrl_bit.eccen = new_state; + } } /** @@ -425,22 +394,19 @@ void xmc_nand_ecc_enable(xmc_class_bank_type xmc_bank, confirm_state new_state) * - XMC_BANK3_NAND * @retval the error correction code (ecc) value. */ -uint32_t xmc_ecc_get(xmc_class_bank_type xmc_bank) -{ - uint32_t eccvaule = 0x0; +uint32_t xmc_ecc_get(xmc_class_bank_type xmc_bank) { + uint32_t eccvaule = 0x0; - /* get the bk2ecc register value */ - if(xmc_bank == XMC_BANK2_NAND) - { - eccvaule = XMC_BANK2->bk2ecc; - } - /* get the bk3ecc register value */ - else - { - eccvaule = XMC_BANK3->bk3ecc; - } - /* return the error correction code value */ - return eccvaule; + /* get the bk2ecc register value */ + if (xmc_bank == XMC_BANK2_NAND) { + eccvaule = XMC_BANK2->bk2ecc; + } + /* get the bk3ecc register value */ + else { + eccvaule = XMC_BANK3->bk3ecc; + } + /* return the error correction code value */ + return eccvaule; } /** @@ -451,13 +417,12 @@ uint32_t xmc_ecc_get(xmc_class_bank_type xmc_bank) * - XMC_SDRAM_BANK2 * @retval none */ -void xmc_sdram_reset(xmc_sdram_bank_type xmc_bank) -{ - XMC_SDRAM->ctrl[xmc_bank] = 0x000002D0; - XMC_SDRAM->tm[xmc_bank] = 0x0FFFFFFF; - XMC_SDRAM->cmd = 0x00000000; - XMC_SDRAM->rcnt = 0x00000000; - XMC_SDRAM->sts = 0x00000000; +void xmc_sdram_reset(xmc_sdram_bank_type xmc_bank) { + XMC_SDRAM->ctrl[xmc_bank] = 0x000002D0; + XMC_SDRAM->tm[xmc_bank] = 0x0FFFFFFF; + XMC_SDRAM->cmd = 0x00000000; + XMC_SDRAM->rcnt = 0x00000000; + XMC_SDRAM->sts = 0x00000000; } /** @@ -471,53 +436,50 @@ void xmc_sdram_reset(xmc_sdram_bank_type xmc_bank) * sdram specified banks. * @retval none */ -void xmc_sdram_init(xmc_sdram_init_type *xmc_sdram_init_struct, xmc_sdram_timing_type *xmc_sdram_timing_struct) -{ - if(xmc_sdram_init_struct->sdram_bank == XMC_SDRAM_BANK1) - { - XMC_SDRAM->ctrl_bit[XMC_SDRAM_BANK1].ca = xmc_sdram_init_struct->column_address; - XMC_SDRAM->ctrl_bit[XMC_SDRAM_BANK1].ra = xmc_sdram_init_struct->row_address; - XMC_SDRAM->ctrl_bit[XMC_SDRAM_BANK1].db = xmc_sdram_init_struct->width; - XMC_SDRAM->ctrl_bit[XMC_SDRAM_BANK1].inbk = xmc_sdram_init_struct->internel_banks; - XMC_SDRAM->ctrl_bit[XMC_SDRAM_BANK1].cas = xmc_sdram_init_struct->cas; - XMC_SDRAM->ctrl_bit[XMC_SDRAM_BANK1].wrp = xmc_sdram_init_struct->write_protection; - XMC_SDRAM->ctrl_bit[XMC_SDRAM_BANK1].bstr = xmc_sdram_init_struct->burst_read; - XMC_SDRAM->ctrl_bit[XMC_SDRAM_BANK1].rd = xmc_sdram_init_struct->read_delay; - XMC_SDRAM->ctrl_bit[XMC_SDRAM_BANK1].clkdiv = xmc_sdram_init_struct->clkdiv; +void xmc_sdram_init(xmc_sdram_init_type *xmc_sdram_init_struct, xmc_sdram_timing_type *xmc_sdram_timing_struct) { + if (xmc_sdram_init_struct->sdram_bank == XMC_SDRAM_BANK1) { + XMC_SDRAM->ctrl_bit[XMC_SDRAM_BANK1].ca = xmc_sdram_init_struct->column_address; + XMC_SDRAM->ctrl_bit[XMC_SDRAM_BANK1].ra = xmc_sdram_init_struct->row_address; + XMC_SDRAM->ctrl_bit[XMC_SDRAM_BANK1].db = xmc_sdram_init_struct->width; + XMC_SDRAM->ctrl_bit[XMC_SDRAM_BANK1].inbk = xmc_sdram_init_struct->internel_banks; + XMC_SDRAM->ctrl_bit[XMC_SDRAM_BANK1].cas = xmc_sdram_init_struct->cas; + XMC_SDRAM->ctrl_bit[XMC_SDRAM_BANK1].wrp = xmc_sdram_init_struct->write_protection; + XMC_SDRAM->ctrl_bit[XMC_SDRAM_BANK1].bstr = xmc_sdram_init_struct->burst_read; + XMC_SDRAM->ctrl_bit[XMC_SDRAM_BANK1].rd = xmc_sdram_init_struct->read_delay; + XMC_SDRAM->ctrl_bit[XMC_SDRAM_BANK1].clkdiv = xmc_sdram_init_struct->clkdiv; - XMC_SDRAM->tm_bit[XMC_SDRAM_BANK1].tmrd = xmc_sdram_timing_struct->tmrd; - XMC_SDRAM->tm_bit[XMC_SDRAM_BANK1].txsr = xmc_sdram_timing_struct->txsr; - XMC_SDRAM->tm_bit[XMC_SDRAM_BANK1].tras = xmc_sdram_timing_struct->tras; - XMC_SDRAM->tm_bit[XMC_SDRAM_BANK1].trc = xmc_sdram_timing_struct->trc; - XMC_SDRAM->tm_bit[XMC_SDRAM_BANK1].twr = xmc_sdram_timing_struct->twr; - XMC_SDRAM->tm_bit[XMC_SDRAM_BANK1].trp = xmc_sdram_timing_struct->trp; - XMC_SDRAM->tm_bit[XMC_SDRAM_BANK1].trcd = xmc_sdram_timing_struct->trcd; - } + XMC_SDRAM->tm_bit[XMC_SDRAM_BANK1].tmrd = xmc_sdram_timing_struct->tmrd; + XMC_SDRAM->tm_bit[XMC_SDRAM_BANK1].txsr = xmc_sdram_timing_struct->txsr; + XMC_SDRAM->tm_bit[XMC_SDRAM_BANK1].tras = xmc_sdram_timing_struct->tras; + XMC_SDRAM->tm_bit[XMC_SDRAM_BANK1].trc = xmc_sdram_timing_struct->trc; + XMC_SDRAM->tm_bit[XMC_SDRAM_BANK1].twr = xmc_sdram_timing_struct->twr; + XMC_SDRAM->tm_bit[XMC_SDRAM_BANK1].trp = xmc_sdram_timing_struct->trp; + XMC_SDRAM->tm_bit[XMC_SDRAM_BANK1].trcd = xmc_sdram_timing_struct->trcd; + } - if(xmc_sdram_init_struct->sdram_bank == XMC_SDRAM_BANK2) - { - XMC_SDRAM->ctrl_bit[XMC_SDRAM_BANK2].ca = xmc_sdram_init_struct->column_address; - XMC_SDRAM->ctrl_bit[XMC_SDRAM_BANK2].ra = xmc_sdram_init_struct->row_address; - XMC_SDRAM->ctrl_bit[XMC_SDRAM_BANK2].db = xmc_sdram_init_struct->width; - XMC_SDRAM->ctrl_bit[XMC_SDRAM_BANK2].inbk = xmc_sdram_init_struct->internel_banks; - XMC_SDRAM->ctrl_bit[XMC_SDRAM_BANK2].cas = xmc_sdram_init_struct->cas; - XMC_SDRAM->ctrl_bit[XMC_SDRAM_BANK2].wrp = xmc_sdram_init_struct->write_protection; - /* sdctrl2 bstr is not care */ - XMC_SDRAM->ctrl_bit[XMC_SDRAM_BANK1].bstr = xmc_sdram_init_struct->burst_read; - XMC_SDRAM->ctrl_bit[XMC_SDRAM_BANK1].rd = xmc_sdram_init_struct->read_delay; - /* sdctrl2 clkdiv is not care */ - XMC_SDRAM->ctrl_bit[XMC_SDRAM_BANK1].clkdiv = xmc_sdram_init_struct->clkdiv; + if (xmc_sdram_init_struct->sdram_bank == XMC_SDRAM_BANK2) { + XMC_SDRAM->ctrl_bit[XMC_SDRAM_BANK2].ca = xmc_sdram_init_struct->column_address; + XMC_SDRAM->ctrl_bit[XMC_SDRAM_BANK2].ra = xmc_sdram_init_struct->row_address; + XMC_SDRAM->ctrl_bit[XMC_SDRAM_BANK2].db = xmc_sdram_init_struct->width; + XMC_SDRAM->ctrl_bit[XMC_SDRAM_BANK2].inbk = xmc_sdram_init_struct->internel_banks; + XMC_SDRAM->ctrl_bit[XMC_SDRAM_BANK2].cas = xmc_sdram_init_struct->cas; + XMC_SDRAM->ctrl_bit[XMC_SDRAM_BANK2].wrp = xmc_sdram_init_struct->write_protection; + /* sdctrl2 bstr is not care */ + XMC_SDRAM->ctrl_bit[XMC_SDRAM_BANK1].bstr = xmc_sdram_init_struct->burst_read; + XMC_SDRAM->ctrl_bit[XMC_SDRAM_BANK1].rd = xmc_sdram_init_struct->read_delay; + /* sdctrl2 clkdiv is not care */ + XMC_SDRAM->ctrl_bit[XMC_SDRAM_BANK1].clkdiv = xmc_sdram_init_struct->clkdiv; - XMC_SDRAM->tm_bit[XMC_SDRAM_BANK2].tmrd = xmc_sdram_timing_struct->tmrd; - XMC_SDRAM->tm_bit[XMC_SDRAM_BANK2].txsr = xmc_sdram_timing_struct->txsr; - XMC_SDRAM->tm_bit[XMC_SDRAM_BANK2].tras = xmc_sdram_timing_struct->tras; - /* sdtm2 trc is not care */ - XMC_SDRAM->tm_bit[XMC_SDRAM_BANK1].trc = xmc_sdram_timing_struct->trc; - XMC_SDRAM->tm_bit[XMC_SDRAM_BANK2].twr = xmc_sdram_timing_struct->twr; - /* sdtm2 trp is not care */ - XMC_SDRAM->tm_bit[XMC_SDRAM_BANK1].trp = xmc_sdram_timing_struct->trp; - XMC_SDRAM->tm_bit[XMC_SDRAM_BANK2].trcd = xmc_sdram_timing_struct->trcd; - } + XMC_SDRAM->tm_bit[XMC_SDRAM_BANK2].tmrd = xmc_sdram_timing_struct->tmrd; + XMC_SDRAM->tm_bit[XMC_SDRAM_BANK2].txsr = xmc_sdram_timing_struct->txsr; + XMC_SDRAM->tm_bit[XMC_SDRAM_BANK2].tras = xmc_sdram_timing_struct->tras; + /* sdtm2 trc is not care */ + XMC_SDRAM->tm_bit[XMC_SDRAM_BANK1].trc = xmc_sdram_timing_struct->trc; + XMC_SDRAM->tm_bit[XMC_SDRAM_BANK2].twr = xmc_sdram_timing_struct->twr; + /* sdtm2 trp is not care */ + XMC_SDRAM->tm_bit[XMC_SDRAM_BANK1].trp = xmc_sdram_timing_struct->trp; + XMC_SDRAM->tm_bit[XMC_SDRAM_BANK2].trcd = xmc_sdram_timing_struct->trcd; + } } /** @@ -528,27 +490,26 @@ void xmc_sdram_init(xmc_sdram_init_type *xmc_sdram_init_struct, xmc_sdram_timing * structure which will be initialized. * @retval none */ -void xmc_sdram_default_para_init(xmc_sdram_init_type *xmc_sdram_init_struct, xmc_sdram_timing_type *xmc_sdram_timing_struct) -{ - /* reset sdram init structure parameters values */ - xmc_sdram_init_struct->sdram_bank = XMC_SDRAM_BANK1; - xmc_sdram_init_struct->internel_banks = XMC_INBK_4; - xmc_sdram_init_struct->clkdiv = XMC_NO_CLK; - xmc_sdram_init_struct->write_protection = FALSE; - xmc_sdram_init_struct->burst_read = FALSE; - xmc_sdram_init_struct->column_address = XMC_COLUMN_8; - xmc_sdram_init_struct->row_address = XMC_ROW_11; - xmc_sdram_init_struct->cas = XMC_CAS_1; - xmc_sdram_init_struct->width = XMC_MEM_WIDTH_8; - xmc_sdram_init_struct->read_delay = XMC_READ_DELAY_1; +void xmc_sdram_default_para_init(xmc_sdram_init_type *xmc_sdram_init_struct, xmc_sdram_timing_type *xmc_sdram_timing_struct) { + /* reset sdram init structure parameters values */ + xmc_sdram_init_struct->sdram_bank = XMC_SDRAM_BANK1; + xmc_sdram_init_struct->internel_banks = XMC_INBK_4; + xmc_sdram_init_struct->clkdiv = XMC_NO_CLK; + xmc_sdram_init_struct->write_protection = FALSE; + xmc_sdram_init_struct->burst_read = FALSE; + xmc_sdram_init_struct->column_address = XMC_COLUMN_8; + xmc_sdram_init_struct->row_address = XMC_ROW_11; + xmc_sdram_init_struct->cas = XMC_CAS_1; + xmc_sdram_init_struct->width = XMC_MEM_WIDTH_8; + xmc_sdram_init_struct->read_delay = XMC_READ_DELAY_1; - xmc_sdram_timing_struct->tmrd = XMC_DELAY_CYCLE_16; - xmc_sdram_timing_struct->txsr = XMC_DELAY_CYCLE_16; - xmc_sdram_timing_struct->tras = XMC_DELAY_CYCLE_16; - xmc_sdram_timing_struct->trc = XMC_DELAY_CYCLE_16; - xmc_sdram_timing_struct->twr = XMC_DELAY_CYCLE_16; - xmc_sdram_timing_struct->trp = XMC_DELAY_CYCLE_16; - xmc_sdram_timing_struct->trcd = XMC_DELAY_CYCLE_16; + xmc_sdram_timing_struct->tmrd = XMC_DELAY_CYCLE_16; + xmc_sdram_timing_struct->txsr = XMC_DELAY_CYCLE_16; + xmc_sdram_timing_struct->tras = XMC_DELAY_CYCLE_16; + xmc_sdram_timing_struct->trc = XMC_DELAY_CYCLE_16; + xmc_sdram_timing_struct->twr = XMC_DELAY_CYCLE_16; + xmc_sdram_timing_struct->trp = XMC_DELAY_CYCLE_16; + xmc_sdram_timing_struct->trcd = XMC_DELAY_CYCLE_16; } /** @@ -557,12 +518,11 @@ void xmc_sdram_default_para_init(xmc_sdram_init_type *xmc_sdram_init_struct, xmc * structure which will be initialized. * @retval none */ -void xmc_sdram_cmd(xmc_sdram_cmd_type *xmc_sdram_cmd_struct) -{ - XMC_SDRAM->cmd = (xmc_sdram_cmd_struct->auto_refresh << 5) | - (xmc_sdram_cmd_struct->data << 9) | - xmc_sdram_cmd_struct->cmd | - xmc_sdram_cmd_struct->cmd_banks; +void xmc_sdram_cmd(xmc_sdram_cmd_type *xmc_sdram_cmd_struct) { + XMC_SDRAM->cmd = (xmc_sdram_cmd_struct->auto_refresh << 5) | + (xmc_sdram_cmd_struct->data << 9) | + xmc_sdram_cmd_struct->cmd | + xmc_sdram_cmd_struct->cmd_banks; } @@ -574,16 +534,12 @@ void xmc_sdram_cmd(xmc_sdram_cmd_type *xmc_sdram_cmd_struct) * - XMC_SDRAM_BANK1 * @retval the bank status */ -uint32_t xmc_sdram_status_get(xmc_sdram_bank_type xmc_bank) -{ - if(xmc_bank == XMC_SDRAM_BANK1) - { - return ((XMC_SDRAM->sts >> 1) & XMC_STATUS_MASK); - } - else - { - return ((XMC_SDRAM->sts >> 3) & XMC_STATUS_MASK); - } +uint32_t xmc_sdram_status_get(xmc_sdram_bank_type xmc_bank) { + if (xmc_bank == XMC_SDRAM_BANK1) { + return ((XMC_SDRAM->sts >> 1) & XMC_STATUS_MASK); + } else { + return ((XMC_SDRAM->sts >> 3) & XMC_STATUS_MASK); + } } /** @@ -591,9 +547,8 @@ uint32_t xmc_sdram_status_get(xmc_sdram_bank_type xmc_bank) * @param counter: xmc sdram refresh counter * @retval none */ -void xmc_sdram_refresh_counter_set(uint32_t counter) -{ - XMC_SDRAM->rcnt_bit.rc = counter; +void xmc_sdram_refresh_counter_set(uint32_t counter) { + XMC_SDRAM->rcnt_bit.rc = counter; } /** @@ -601,9 +556,8 @@ void xmc_sdram_refresh_counter_set(uint32_t counter) * @param number: xmc sdram auto refresh number * @retval none */ -void xmc_sdram_auto_refresh_set(uint32_t number) -{ - XMC_SDRAM->cmd_bit.art = number; +void xmc_sdram_auto_refresh_set(uint32_t number) { + XMC_SDRAM->cmd_bit.art = number; } /** @@ -623,54 +577,42 @@ void xmc_sdram_auto_refresh_set(uint32_t number) * @param new_state (TRUE or FALSE) * @retval none */ -void xmc_interrupt_enable(xmc_class_bank_type xmc_bank, xmc_interrupt_sources_type xmc_int, confirm_state new_state) -{ - if(new_state != FALSE) - { - /* enable the selected xmc_bank2 interrupts */ - if(xmc_bank == XMC_BANK2_NAND) - { - XMC_BANK2->bk2is |= xmc_int; +void xmc_interrupt_enable(xmc_class_bank_type xmc_bank, xmc_interrupt_sources_type xmc_int, confirm_state new_state) { + if (new_state != FALSE) { + /* enable the selected xmc_bank2 interrupts */ + if (xmc_bank == XMC_BANK2_NAND) { + XMC_BANK2->bk2is |= xmc_int; + } + /* enable the selected xmc_bank3 interrupts */ + else if (xmc_bank == XMC_BANK3_NAND) { + XMC_BANK3->bk3is |= xmc_int; + } + /* enable the selected xmc_bank4 interrupts */ + else if (xmc_bank == XMC_BANK4_PCCARD) { + XMC_BANK4->bk4is |= xmc_int; + } + /* enable the selected xmc_sdram interrupts */ + else { + XMC_SDRAM->rcnt |= xmc_int; + } + } else { + /* disable the selected xmc_bank2 interrupts */ + if (xmc_bank == XMC_BANK2_NAND) { + XMC_BANK2->bk2is &= ~xmc_int; + } + /* disable the selected xmc_bank3 interrupts */ + else if (xmc_bank == XMC_BANK3_NAND) { + XMC_BANK3->bk3is &= ~xmc_int; + } + /* disable the selected xmc_bank4 interrupts */ + else if (xmc_bank == XMC_BANK4_PCCARD) { + XMC_BANK4->bk4is &= ~xmc_int; + } + /* disable the selected xmc_sdram interrupts */ + else { + XMC_SDRAM->rcnt &= ~xmc_int; + } } - /* enable the selected xmc_bank3 interrupts */ - else if(xmc_bank == XMC_BANK3_NAND) - { - XMC_BANK3->bk3is |= xmc_int; - } - /* enable the selected xmc_bank4 interrupts */ - else if(xmc_bank == XMC_BANK4_PCCARD) - { - XMC_BANK4->bk4is |= xmc_int; - } - /* enable the selected xmc_sdram interrupts */ - else - { - XMC_SDRAM->rcnt |= xmc_int; - } - } - else - { - /* disable the selected xmc_bank2 interrupts */ - if(xmc_bank == XMC_BANK2_NAND) - { - XMC_BANK2->bk2is &= ~xmc_int; - } - /* disable the selected xmc_bank3 interrupts */ - else if(xmc_bank == XMC_BANK3_NAND) - { - XMC_BANK3->bk3is &= ~xmc_int; - } - /* disable the selected xmc_bank4 interrupts */ - else if(xmc_bank == XMC_BANK4_PCCARD) - { - XMC_BANK4->bk4is &= ~xmc_int; - } - /* disable the selected xmc_sdram interrupts */ - else - { - XMC_SDRAM->rcnt &= ~xmc_int; - } - } } /** @@ -691,38 +633,27 @@ void xmc_interrupt_enable(xmc_class_bank_type xmc_bank, xmc_interrupt_sources_ty * - XMC_ERR_FLAG * @retval none */ -flag_status xmc_flag_status_get(xmc_class_bank_type xmc_bank, xmc_interrupt_flag_type xmc_flag) -{ - flag_status status = RESET; - uint32_t temp = 0; +flag_status xmc_flag_status_get(xmc_class_bank_type xmc_bank, xmc_interrupt_flag_type xmc_flag) { + flag_status status = RESET; + uint32_t temp = 0; - if(xmc_bank == XMC_BANK2_NAND) - { - temp = XMC_BANK2->bk2is; - } - else if(xmc_bank == XMC_BANK3_NAND) - { - temp = XMC_BANK3->bk3is; - } - else if(xmc_bank == XMC_BANK4_PCCARD) - { - temp = XMC_BANK4->bk4is; - } - else - { - temp = XMC_SDRAM->sts; - } - /* get the flag status */ - if((temp & xmc_flag) == RESET) - { - status = RESET; - } - else - { - status = SET; - } - /* return the flag status */ - return status; + if (xmc_bank == XMC_BANK2_NAND) { + temp = XMC_BANK2->bk2is; + } else if (xmc_bank == XMC_BANK3_NAND) { + temp = XMC_BANK3->bk3is; + } else if (xmc_bank == XMC_BANK4_PCCARD) { + temp = XMC_BANK4->bk4is; + } else { + temp = XMC_SDRAM->sts; + } + /* get the flag status */ + if ((temp & xmc_flag) == RESET) { + status = RESET; + } else { + status = SET; + } + /* return the flag status */ + return status; } /** @@ -739,81 +670,72 @@ flag_status xmc_flag_status_get(xmc_class_bank_type xmc_bank, xmc_interrupt_flag * - XMC_FALLINGEDGE_FLAG * @retval none */ -flag_status xmc_interrupt_flag_status_get(xmc_class_bank_type xmc_bank, xmc_interrupt_flag_type xmc_flag) -{ - flag_status status = RESET; +flag_status xmc_interrupt_flag_status_get(xmc_class_bank_type xmc_bank, xmc_interrupt_flag_type xmc_flag) { + flag_status status = RESET; - if(xmc_bank == XMC_BANK2_NAND) - { - switch(xmc_flag) - { - case XMC_RISINGEDGE_FLAG: - if(XMC_BANK2->bk2is_bit.reien && XMC_BANK2->bk2is_bit.res) - status = SET; - break; - - case XMC_LEVEL_FLAG: - if(XMC_BANK2->bk2is_bit.feien && XMC_BANK2->bk2is_bit.fes) - status = SET; - break; - - case XMC_FALLINGEDGE_FLAG: - if(XMC_BANK2->bk2is_bit.hlien && XMC_BANK2->bk2is_bit.hls) - status = SET; - break; - - default: - break; + if (xmc_bank == XMC_BANK2_NAND) { + switch (xmc_flag) { + case XMC_RISINGEDGE_FLAG: + if (XMC_BANK2->bk2is_bit.reien && XMC_BANK2->bk2is_bit.res) + status = SET; + break; + + case XMC_LEVEL_FLAG: + if (XMC_BANK2->bk2is_bit.feien && XMC_BANK2->bk2is_bit.fes) + status = SET; + break; + + case XMC_FALLINGEDGE_FLAG: + if (XMC_BANK2->bk2is_bit.hlien && XMC_BANK2->bk2is_bit.hls) + status = SET; + break; + + default: + break; + } + } else if (xmc_bank == XMC_BANK3_NAND) { + switch (xmc_flag) { + case XMC_RISINGEDGE_FLAG: + if (XMC_BANK3->bk3is_bit.reien && XMC_BANK3->bk3is_bit.res) + status = SET; + break; + + case XMC_LEVEL_FLAG: + if (XMC_BANK3->bk3is_bit.feien && XMC_BANK3->bk3is_bit.fes) + status = SET; + break; + + case XMC_FALLINGEDGE_FLAG: + if (XMC_BANK3->bk3is_bit.hlien && XMC_BANK3->bk3is_bit.hls) + status = SET; + break; + + default: + break; + } + } else if (xmc_bank == XMC_BANK4_PCCARD) { + switch (xmc_flag) { + case XMC_RISINGEDGE_FLAG: + if (XMC_BANK4->bk4is_bit.reien && XMC_BANK4->bk4is_bit.res) + status = SET; + break; + + case XMC_LEVEL_FLAG: + if (XMC_BANK4->bk4is_bit.feien && XMC_BANK4->bk4is_bit.fes) + status = SET; + break; + + case XMC_FALLINGEDGE_FLAG: + if (XMC_BANK4->bk4is_bit.hlien && XMC_BANK4->bk4is_bit.hls) + status = SET; + break; + + default: + break; + } } - } - else if(xmc_bank == XMC_BANK3_NAND) - { - switch(xmc_flag) - { - case XMC_RISINGEDGE_FLAG: - if(XMC_BANK3->bk3is_bit.reien && XMC_BANK3->bk3is_bit.res) - status = SET; - break; - - case XMC_LEVEL_FLAG: - if(XMC_BANK3->bk3is_bit.feien && XMC_BANK3->bk3is_bit.fes) - status = SET; - break; - - case XMC_FALLINGEDGE_FLAG: - if(XMC_BANK3->bk3is_bit.hlien && XMC_BANK3->bk3is_bit.hls) - status = SET; - break; - - default: - break; - } - } - else if(xmc_bank == XMC_BANK4_PCCARD) - { - switch(xmc_flag) - { - case XMC_RISINGEDGE_FLAG: - if(XMC_BANK4->bk4is_bit.reien && XMC_BANK4->bk4is_bit.res) - status = SET; - break; - - case XMC_LEVEL_FLAG: - if(XMC_BANK4->bk4is_bit.feien && XMC_BANK4->bk4is_bit.fes) - status = SET; - break; - - case XMC_FALLINGEDGE_FLAG: - if(XMC_BANK4->bk4is_bit.hlien && XMC_BANK4->bk4is_bit.hls) - status = SET; - break; - - default: - break; - } - } - /* return the flag status */ - return status; + /* return the flag status */ + return status; } /** @@ -832,28 +754,20 @@ flag_status xmc_interrupt_flag_status_get(xmc_class_bank_type xmc_bank, xmc_inte * - XMC_ERR_FLAG * @retval none */ -void xmc_flag_clear(xmc_class_bank_type xmc_bank, xmc_interrupt_flag_type xmc_flag) -{ - __IO uint32_t int_state; - if(xmc_bank == XMC_BANK2_NAND) - { - int_state = XMC_BANK2->bk2is & 0x38; /* keep interrupt state */ - XMC_BANK2->bk2is = (~(xmc_flag | 0x38) | int_state); - } - else if(xmc_bank == XMC_BANK3_NAND) - { - int_state = XMC_BANK3->bk3is & 0x38; /* keep interrupt state */ - XMC_BANK3->bk3is = (~(xmc_flag | 0x38) | int_state); - } - else if(xmc_bank == XMC_BANK4_PCCARD) - { - int_state = XMC_BANK4->bk4is & 0x38; /* keep interrupt state */ - XMC_BANK4->bk4is = (~(xmc_flag | 0x38) | int_state); - } - else - { - XMC_SDRAM->rcnt |= xmc_flag; - } +void xmc_flag_clear(xmc_class_bank_type xmc_bank, xmc_interrupt_flag_type xmc_flag) { + __IO uint32_t int_state; + if (xmc_bank == XMC_BANK2_NAND) { + int_state = XMC_BANK2->bk2is & 0x38; /* keep interrupt state */ + XMC_BANK2->bk2is = (~(xmc_flag | 0x38) | int_state); + } else if (xmc_bank == XMC_BANK3_NAND) { + int_state = XMC_BANK3->bk3is & 0x38; /* keep interrupt state */ + XMC_BANK3->bk3is = (~(xmc_flag | 0x38) | int_state); + } else if (xmc_bank == XMC_BANK4_PCCARD) { + int_state = XMC_BANK4->bk4is & 0x38; /* keep interrupt state */ + XMC_BANK4->bk4is = (~(xmc_flag | 0x38) | int_state); + } else { + XMC_SDRAM->rcnt |= xmc_flag; + } } /** @@ -861,14 +775,13 @@ void xmc_flag_clear(xmc_class_bank_type xmc_bank, xmc_interrupt_flag_type xmc_fl * @param none * @retval none */ -void xmc_pccard_reset(void) -{ - /* Set the XMC_Bank4 registers to their reset values */ - XMC_BANK4->bk4ctrl = 0x00000018; - XMC_BANK4->bk4is = 0x00000000; - XMC_BANK4->bk4tmgatt = 0xFCFCFCFC; - XMC_BANK4->bk4tmgio = 0xFCFCFCFC; - XMC_BANK4->bk4tmgmem = 0xFCFCFCFC; +void xmc_pccard_reset(void) { + /* Set the XMC_Bank4 registers to their reset values */ + XMC_BANK4->bk4ctrl = 0x00000018; + XMC_BANK4->bk4is = 0x00000000; + XMC_BANK4->bk4tmgatt = 0xFCFCFCFC; + XMC_BANK4->bk4tmgio = 0xFCFCFCFC; + XMC_BANK4->bk4tmgmem = 0xFCFCFCFC; } /** @@ -879,13 +792,12 @@ void xmc_pccard_reset(void) * pccard bank. * @retval none */ -void xmc_pccard_init(xmc_pccard_init_type* xmc_pccard_init_struct) -{ - /* set the bk4ctrl register value according to xmc_pccard_init_struct parameters */ - XMC_BANK4->bk4ctrl = (uint32_t)xmc_pccard_init_struct->enable_wait | - XMC_BUSTYPE_16_BITS | - (xmc_pccard_init_struct->delay_time_cr << 9) | - (xmc_pccard_init_struct->delay_time_ar << 13); +void xmc_pccard_init(xmc_pccard_init_type *xmc_pccard_init_struct) { + /* set the bk4ctrl register value according to xmc_pccard_init_struct parameters */ + XMC_BANK4->bk4ctrl = (uint32_t)xmc_pccard_init_struct->enable_wait | + XMC_BUSTYPE_16_BITS | + (xmc_pccard_init_struct->delay_time_cr << 9) | + (xmc_pccard_init_struct->delay_time_ar << 13); } /** @@ -903,27 +815,26 @@ void xmc_pccard_init(xmc_pccard_init_type* xmc_pccard_init_struct) * pccard bank. * @retval none */ -void xmc_pccard_timing_config(xmc_nand_pccard_timinginit_type* xmc_regular_spacetiming_struct, - xmc_nand_pccard_timinginit_type* xmc_special_spacetiming_struct, - xmc_nand_pccard_timinginit_type* xmc_iospace_timing_struct) -{ - /* set bk4tmgmem register value according to xmc_regular_spacetiming_struct parameters */ - XMC_BANK4->bk4tmgmem = (uint32_t)xmc_regular_spacetiming_struct->mem_setup_time | - (xmc_regular_spacetiming_struct->mem_waite_time << 8) | - (xmc_regular_spacetiming_struct->mem_hold_time << 16) | - (xmc_regular_spacetiming_struct->mem_hiz_time << 24); +void xmc_pccard_timing_config(xmc_nand_pccard_timinginit_type *xmc_regular_spacetiming_struct, + xmc_nand_pccard_timinginit_type *xmc_special_spacetiming_struct, + xmc_nand_pccard_timinginit_type *xmc_iospace_timing_struct) { + /* set bk4tmgmem register value according to xmc_regular_spacetiming_struct parameters */ + XMC_BANK4->bk4tmgmem = (uint32_t)xmc_regular_spacetiming_struct->mem_setup_time | + (xmc_regular_spacetiming_struct->mem_waite_time << 8) | + (xmc_regular_spacetiming_struct->mem_hold_time << 16) | + (xmc_regular_spacetiming_struct->mem_hiz_time << 24); - /* Set bk4tmgatt register value according to xmc_special_spacetiming_struct parameters */ - XMC_BANK4->bk4tmgatt = (uint32_t)xmc_special_spacetiming_struct->mem_setup_time | - (xmc_special_spacetiming_struct->mem_waite_time << 8) | - (xmc_special_spacetiming_struct->mem_hold_time << 16) | - (xmc_special_spacetiming_struct->mem_hiz_time << 24); + /* Set bk4tmgatt register value according to xmc_special_spacetiming_struct parameters */ + XMC_BANK4->bk4tmgatt = (uint32_t)xmc_special_spacetiming_struct->mem_setup_time | + (xmc_special_spacetiming_struct->mem_waite_time << 8) | + (xmc_special_spacetiming_struct->mem_hold_time << 16) | + (xmc_special_spacetiming_struct->mem_hiz_time << 24); - /* Set bk4tmgio register value according to xmc_iospace_timing_struct parameters */ - XMC_BANK4->bk4tmgio = (uint32_t)xmc_iospace_timing_struct->mem_setup_time | - (xmc_iospace_timing_struct->mem_waite_time << 8) | - (xmc_iospace_timing_struct->mem_hold_time << 16) | - (xmc_iospace_timing_struct->mem_hiz_time << 24); + /* Set bk4tmgio register value according to xmc_iospace_timing_struct parameters */ + XMC_BANK4->bk4tmgio = (uint32_t)xmc_iospace_timing_struct->mem_setup_time | + (xmc_iospace_timing_struct->mem_waite_time << 8) | + (xmc_iospace_timing_struct->mem_hold_time << 16) | + (xmc_iospace_timing_struct->mem_hiz_time << 24); } /** * @brief fill each xmc_pccard_init_struct member with its default value. @@ -931,12 +842,11 @@ void xmc_pccard_timing_config(xmc_nand_pccard_timinginit_type* xmc_regular_space * structure which will be initialized. * @retval none */ -void xmc_pccard_default_para_init(xmc_pccard_init_type* xmc_pccard_init_struct) -{ - /* reset pccard init structure parameters values */ - xmc_pccard_init_struct->enable_wait = XMC_WAIT_OPERATION_DISABLE; - xmc_pccard_init_struct->delay_time_ar = 0x0; - xmc_pccard_init_struct->delay_time_cr = 0x0; +void xmc_pccard_default_para_init(xmc_pccard_init_type *xmc_pccard_init_struct) { + /* reset pccard init structure parameters values */ + xmc_pccard_init_struct->enable_wait = XMC_WAIT_OPERATION_DISABLE; + xmc_pccard_init_struct->delay_time_ar = 0x0; + xmc_pccard_init_struct->delay_time_cr = 0x0; } /** @@ -953,35 +863,33 @@ void xmc_pccard_default_para_init(xmc_pccard_init_type* xmc_pccard_init_struct) * pccard bank. * @retval none */ -void xmc_pccard_timing_default_para_init(xmc_nand_pccard_timinginit_type* xmc_regular_spacetiming_struct, - xmc_nand_pccard_timinginit_type* xmc_special_spacetiming_struct, - xmc_nand_pccard_timinginit_type* xmc_iospace_timing_struct) -{ - xmc_regular_spacetiming_struct->class_bank = XMC_BANK4_PCCARD; - xmc_regular_spacetiming_struct->mem_hold_time = 0xFC; - xmc_regular_spacetiming_struct->mem_waite_time = 0xFC; - xmc_regular_spacetiming_struct->mem_setup_time = 0xFC; - xmc_regular_spacetiming_struct->mem_hiz_time = 0xFC; - xmc_special_spacetiming_struct->class_bank = XMC_BANK4_PCCARD; - xmc_special_spacetiming_struct->mem_hold_time = 0xFC; - xmc_special_spacetiming_struct->mem_waite_time = 0xFC; - xmc_special_spacetiming_struct->mem_setup_time = 0xFC; - xmc_special_spacetiming_struct->mem_hiz_time = 0xFC; - xmc_iospace_timing_struct->class_bank = XMC_BANK4_PCCARD; - xmc_iospace_timing_struct->mem_hold_time = 0xFC; - xmc_iospace_timing_struct->mem_waite_time = 0xFC; - xmc_iospace_timing_struct->mem_setup_time = 0xFC; - xmc_iospace_timing_struct->mem_hiz_time = 0xFC; +void xmc_pccard_timing_default_para_init(xmc_nand_pccard_timinginit_type *xmc_regular_spacetiming_struct, + xmc_nand_pccard_timinginit_type *xmc_special_spacetiming_struct, + xmc_nand_pccard_timinginit_type *xmc_iospace_timing_struct) { + xmc_regular_spacetiming_struct->class_bank = XMC_BANK4_PCCARD; + xmc_regular_spacetiming_struct->mem_hold_time = 0xFC; + xmc_regular_spacetiming_struct->mem_waite_time = 0xFC; + xmc_regular_spacetiming_struct->mem_setup_time = 0xFC; + xmc_regular_spacetiming_struct->mem_hiz_time = 0xFC; + xmc_special_spacetiming_struct->class_bank = XMC_BANK4_PCCARD; + xmc_special_spacetiming_struct->mem_hold_time = 0xFC; + xmc_special_spacetiming_struct->mem_waite_time = 0xFC; + xmc_special_spacetiming_struct->mem_setup_time = 0xFC; + xmc_special_spacetiming_struct->mem_hiz_time = 0xFC; + xmc_iospace_timing_struct->class_bank = XMC_BANK4_PCCARD; + xmc_iospace_timing_struct->mem_hold_time = 0xFC; + xmc_iospace_timing_struct->mem_waite_time = 0xFC; + xmc_iospace_timing_struct->mem_setup_time = 0xFC; + xmc_iospace_timing_struct->mem_hiz_time = 0xFC; } /** * @brief enable or disable the pccard memory bank. * @param new_state (TRUE or FALSE) * @retval none */ -void xmc_pccard_enable(confirm_state new_state) -{ - /* enable the pccard bank4 by setting the en bit in the bk4ctrl register */ - XMC_BANK4->bk4ctrl_bit.en = new_state; +void xmc_pccard_enable(confirm_state new_state) { + /* enable the pccard bank4 by setting the en bit in the bk4ctrl register */ + XMC_BANK4->bk4ctrl_bit.en = new_state; } /** diff --git a/armlib/at32_usb/usb_drivers/inc/usb_core.h b/armlib/at32_usb/usb_drivers/inc/usb_core.h index e28f8725c..c609ef4bc 100644 --- a/armlib/at32_usb/usb_drivers/inc/usb_core.h +++ b/armlib/at32_usb/usb_drivers/inc/usb_core.h @@ -56,64 +56,61 @@ extern "C" { /** * @brief usb core speed select */ -typedef enum -{ - USB_LOW_SPEED_CORE_ID, /*!< usb low speed core id */ - USB_FULL_SPEED_CORE_ID, /*!< usb full speed core id */ - USB_HIGH_SPEED_CORE_ID, /*!< usb high speed core id */ +typedef enum { + USB_LOW_SPEED_CORE_ID, /*!< usb low speed core id */ + USB_FULL_SPEED_CORE_ID, /*!< usb full speed core id */ + USB_HIGH_SPEED_CORE_ID, /*!< usb high speed core id */ } usb_speed_type; /** * @brief usb core cofig struct */ -typedef struct -{ - uint8_t speed; /*!< otg speed */ - uint8_t dma_en; /*!< dma enable state, not use*/ - uint8_t hc_num; /*!< the otg host support number of channel */ - uint8_t ept_num; /*!< the otg device support number of endpoint */ +typedef struct { + uint8_t speed; /*!< otg speed */ + uint8_t dma_en; /*!< dma enable state, not use*/ + uint8_t hc_num; /*!< the otg host support number of channel */ + uint8_t ept_num; /*!< the otg device support number of endpoint */ - uint16_t max_size; /*!< support max packet size */ - uint16_t fifo_size; /*!< the usb otg total file size */ - uint8_t phy_itface; /*!< usb phy select */ - uint8_t core_id; /*!< the usb otg core id */ - uint8_t low_power; /*!< the usb otg low power option */ - uint8_t sof_out; /*!< the sof signal output */ - uint8_t usb_id; /*!< select otgfs1 or otgfs2 */ - uint8_t vbusig; /*!< vbus ignore */ + uint16_t max_size; /*!< support max packet size */ + uint16_t fifo_size; /*!< the usb otg total file size */ + uint8_t phy_itface; /*!< usb phy select */ + uint8_t core_id; /*!< the usb otg core id */ + uint8_t low_power; /*!< the usb otg low power option */ + uint8_t sof_out; /*!< the sof signal output */ + uint8_t usb_id; /*!< select otgfs1 or otgfs2 */ + uint8_t vbusig; /*!< vbus ignore */ } usb_core_cfg; /** * @brief usb otg core struct type */ -typedef struct -{ - usb_reg_type *usb_reg; /*!< the usb otg register type */ +typedef struct { + usb_reg_type *usb_reg; /*!< the usb otg register type */ #ifdef USE_OTG_DEVICE_MODE - usbd_core_type dev; /*!< the usb device core type */ + usbd_core_type dev; /*!< the usb device core type */ #endif #ifdef USE_OTG_HOST_MODE - usbh_core_type host; /*!< the usb host core type */ + usbh_core_type host; /*!< the usb host core type */ #endif - usb_core_cfg cfg; /*!< the usb otg core config type */ + usb_core_cfg cfg; /*!< the usb otg core config type */ } otg_core_type; usb_sts_type usb_core_config(otg_core_type *otgdev, uint8_t core_id); #ifdef USE_OTG_DEVICE_MODE usb_sts_type usbd_init(otg_core_type *udev, - uint8_t core_id, uint8_t usb_id, - usbd_class_handler *class_handler, - usbd_desc_handler *desc_handler); + uint8_t core_id, uint8_t usb_id, + usbd_class_handler *class_handler, + usbd_desc_handler *desc_handler); #endif #ifdef USE_OTG_HOST_MODE usb_sts_type usbh_init(otg_core_type *hdev, - uint8_t core_id, uint8_t usb_id, - usbh_class_handler_type *class_handler, - usbh_user_handler_type *user_handler); + uint8_t core_id, uint8_t usb_id, + usbh_class_handler_type *class_handler, + usbh_user_handler_type *user_handler); #endif /** * @} diff --git a/armlib/at32_usb/usb_drivers/inc/usb_std.h b/armlib/at32_usb/usb_drivers/inc/usb_std.h index f689e27ad..fb91939dd 100644 --- a/armlib/at32_usb/usb_drivers/inc/usb_std.h +++ b/armlib/at32_usb/usb_drivers/inc/usb_std.h @@ -129,13 +129,12 @@ extern "C" { /** * @brief usb device connect state */ -typedef enum -{ - USB_CONN_STATE_DEFAULT =1, /*!< usb device connect state default */ - USB_CONN_STATE_ADDRESSED, /*!< usb device connect state address */ - USB_CONN_STATE_CONFIGURED, /*!< usb device connect state configured */ - USB_CONN_STATE_SUSPENDED /*!< usb device connect state suspend */ -}usbd_conn_state; +typedef enum { + USB_CONN_STATE_DEFAULT = 1, /*!< usb device connect state default */ + USB_CONN_STATE_ADDRESSED, /*!< usb device connect state address */ + USB_CONN_STATE_CONFIGURED, /*!< usb device connect state configured */ + USB_CONN_STATE_SUSPENDED /*!< usb device connect state suspend */ +} usbd_conn_state; /** * @brief endpoint 0 state @@ -214,13 +213,12 @@ typedef enum /** * @brief usb cdc class set line coding struct */ -typedef struct -{ - uint32_t bitrate; /* line coding baud rate */ - uint8_t format; /* line coding foramt */ - uint8_t parity; /* line coding parity */ - uint8_t data; /* line coding data bit */ -}linecoding_type; +typedef struct { + uint32_t bitrate; /* line coding baud rate */ + uint8_t format; /* line coding foramt */ + uint8_t parity; /* line coding parity */ + uint8_t data; /* line coding data bit */ +} linecoding_type; /** * @brief usb hid class descriptor define @@ -272,107 +270,100 @@ typedef struct /** * @brief usb return status */ -typedef enum -{ - USB_OK, /*!< usb status ok */ - USB_FAIL, /*!< usb status fail */ - USB_WAIT, /*!< usb status wait */ - USB_NOT_SUPPORT, /*!< usb status not support */ - USB_ERROR, /*!< usb status error */ -}usb_sts_type; +typedef enum { + USB_OK, /*!< usb status ok */ + USB_FAIL, /*!< usb status fail */ + USB_WAIT, /*!< usb status wait */ + USB_NOT_SUPPORT, /*!< usb status not support */ + USB_ERROR, /*!< usb status error */ +} usb_sts_type; /** * @brief format of usb setup data */ -typedef struct -{ - uint8_t bmRequestType; /*!< characteristics of request */ - uint8_t bRequest; /*!< specific request */ - uint16_t wValue; /*!< word-sized field that varies according to request */ - uint16_t wIndex; /*!< word-sized field that varies according to request +typedef struct { + uint8_t bmRequestType; /*!< characteristics of request */ + uint8_t bRequest; /*!< specific request */ + uint16_t wValue; /*!< word-sized field that varies according to request */ + uint16_t wIndex; /*!< word-sized field that varies according to request typically used to pass an index or offset */ - uint16_t wLength; /*!< number of bytes to transfer if there is a data stage */ + uint16_t wLength; /*!< number of bytes to transfer if there is a data stage */ } usb_setup_type; /** * @brief format of standard device descriptor */ -typedef struct -{ - uint8_t bLength; /*!< size of this descriptor in bytes */ - uint8_t bDescriptorType; /*!< device descriptor type */ - uint16_t bcdUSB; /*!< usb specification release number */ - uint8_t bDeviceClass; /*!< class code (assigned by the usb-if) */ - uint8_t bDeviceSubClass; /*!< subclass code (assigned by the usb-if) */ - uint8_t bDeviceProtocol; /*!< protocol code ((assigned by the usb-if)) */ - uint8_t bMaxPacketSize0; /*!< maximum packet size for endpoint zero */ - uint16_t idVendor; /*!< verndor id ((assigned by the usb-if)) */ - uint16_t idProduct; /*!< product id ((assigned by the usb-if)) */ - uint16_t bcdDevice; /*!< device release number in binary-coded decimal */ - uint8_t iManufacturer; /*!< index of string descriptor describing manufacturer */ - uint8_t iProduct; /*!< index of string descriptor describing product */ - uint8_t iSerialNumber; /*!< index of string descriptor describing serial number */ - uint8_t bNumConfigurations; /*!< number of possible configurations */ +typedef struct { + uint8_t bLength; /*!< size of this descriptor in bytes */ + uint8_t bDescriptorType; /*!< device descriptor type */ + uint16_t bcdUSB; /*!< usb specification release number */ + uint8_t bDeviceClass; /*!< class code (assigned by the usb-if) */ + uint8_t bDeviceSubClass; /*!< subclass code (assigned by the usb-if) */ + uint8_t bDeviceProtocol; /*!< protocol code ((assigned by the usb-if)) */ + uint8_t bMaxPacketSize0; /*!< maximum packet size for endpoint zero */ + uint16_t idVendor; /*!< verndor id ((assigned by the usb-if)) */ + uint16_t idProduct; /*!< product id ((assigned by the usb-if)) */ + uint16_t bcdDevice; /*!< device release number in binary-coded decimal */ + uint8_t iManufacturer; /*!< index of string descriptor describing manufacturer */ + uint8_t iProduct; /*!< index of string descriptor describing product */ + uint8_t iSerialNumber; /*!< index of string descriptor describing serial number */ + uint8_t bNumConfigurations; /*!< number of possible configurations */ } usb_device_desc_type; /** * @brief format of standard configuration descriptor */ -typedef struct -{ - uint8_t bLength; /*!< size of this descriptor in bytes */ - uint8_t bDescriptorType; /*!< configuration descriptor type */ - uint16_t wTotalLength; /*!< total length of data returned for this configuration */ - uint8_t bNumInterfaces; /*!< number of interfaces supported by this configuration */ - uint8_t bConfigurationValue; /*!< value to use as an argument to the SetConfiguration() request */ - uint8_t iConfiguration; /*!< index of string descriptor describing this configuration */ - uint8_t bmAttributes; /*!< configuration characteristics +typedef struct { + uint8_t bLength; /*!< size of this descriptor in bytes */ + uint8_t bDescriptorType; /*!< configuration descriptor type */ + uint16_t wTotalLength; /*!< total length of data returned for this configuration */ + uint8_t bNumInterfaces; /*!< number of interfaces supported by this configuration */ + uint8_t bConfigurationValue; /*!< value to use as an argument to the SetConfiguration() request */ + uint8_t iConfiguration; /*!< index of string descriptor describing this configuration */ + uint8_t bmAttributes; /*!< configuration characteristics D7 reserved D6 self-powered D5 remote wakeup D4~D0 reserved */ - uint8_t bMaxPower; /*!< maximum power consumption of the usb device from the bus */ + uint8_t bMaxPower; /*!< maximum power consumption of the usb device from the bus */ -}usb_configuration_desc_type; +} usb_configuration_desc_type; /** * @brief format of standard interface descriptor */ -typedef struct -{ - uint8_t bLength; /*!< size of this descriptor in bytes */ - uint8_t bDescriptorType; /*!< interface descriptor type */ - uint8_t bInterfaceNumber; /*!< number of this interface */ - uint8_t bAlternateSetting; /*!< value used to select this alternate setting for the interface */ - uint8_t bNumEndpoints; /*!< number of endpoints used by this interface */ - uint8_t bInterfaceClass; /*!< class code (assigned by the usb-if) */ - uint8_t bInterfaceSubClass; /*!< subclass code (assigned by the usb-if) */ - uint8_t bInterfaceProtocol; /*!< protocol code (assigned by the usb-if) */ - uint8_t iInterface; /*!< index of string descriptor describing this interface */ +typedef struct { + uint8_t bLength; /*!< size of this descriptor in bytes */ + uint8_t bDescriptorType; /*!< interface descriptor type */ + uint8_t bInterfaceNumber; /*!< number of this interface */ + uint8_t bAlternateSetting; /*!< value used to select this alternate setting for the interface */ + uint8_t bNumEndpoints; /*!< number of endpoints used by this interface */ + uint8_t bInterfaceClass; /*!< class code (assigned by the usb-if) */ + uint8_t bInterfaceSubClass; /*!< subclass code (assigned by the usb-if) */ + uint8_t bInterfaceProtocol; /*!< protocol code (assigned by the usb-if) */ + uint8_t iInterface; /*!< index of string descriptor describing this interface */ } usb_interface_desc_type; /** * @brief format of standard endpoint descriptor */ -typedef struct -{ - uint8_t bLength; /*!< size of this descriptor in bytes */ - uint8_t bDescriptorType; /*!< endpoint descriptor type */ - uint8_t bEndpointAddress; /*!< the address of the endpoint on the usb device described by this descriptor */ - uint8_t bmAttributes; /*!< describes the endpoints attributes when it is configured using bConfiguration value */ - uint16_t wMaxPacketSize; /*!< maximum packet size this endpoint */ - uint8_t bInterval; /*!< interval for polling endpoint for data transfers */ +typedef struct { + uint8_t bLength; /*!< size of this descriptor in bytes */ + uint8_t bDescriptorType; /*!< endpoint descriptor type */ + uint8_t bEndpointAddress; /*!< the address of the endpoint on the usb device described by this descriptor */ + uint8_t bmAttributes; /*!< describes the endpoints attributes when it is configured using bConfiguration value */ + uint16_t wMaxPacketSize; /*!< maximum packet size this endpoint */ + uint8_t bInterval; /*!< interval for polling endpoint for data transfers */ } usb_endpoint_desc_type; /** * @brief format of header */ -typedef struct -{ - uint8_t bLength; /*!< size of this descriptor in bytes */ - uint8_t bDescriptorType; /*!< descriptor type */ +typedef struct { + uint8_t bLength; /*!< size of this descriptor in bytes */ + uint8_t bDescriptorType; /*!< descriptor type */ } usb_header_desc_type; diff --git a/armlib/at32_usb/usb_drivers/inc/usbd_core.h b/armlib/at32_usb/usb_drivers/inc/usbd_core.h index ce6beba31..d2595b3d7 100644 --- a/armlib/at32_usb/usb_drivers/inc/usbd_core.h +++ b/armlib/at32_usb/usb_drivers/inc/usbd_core.h @@ -96,15 +96,15 @@ typedef struct { * @brief usb device class handler */ typedef struct { - usb_sts_type (*init_handler)(void *udev); /*!< usb class init handler */ - usb_sts_type (*clear_handler)(void *udev); /*!< usb class clear handler */ - usb_sts_type (*setup_handler)(void *udev, usb_setup_type *setup); /*!< usb class setup handler */ - usb_sts_type (*ept0_tx_handler)(void *udev); /*!< usb class endpoint 0 tx complete handler */ - usb_sts_type (*ept0_rx_handler)(void *udev); /*!< usb class endpoint 0 rx complete handler */ - usb_sts_type (*in_handler)(void *udev, uint8_t ept_num); /*!< usb class in transfer complete handler */ - usb_sts_type (*out_handler)(void *udev, uint8_t ept_num); /*!< usb class out transfer complete handler */ - usb_sts_type (*sof_handler)(void *udev); /*!< usb class sof handler */ - usb_sts_type (*event_handler)(void *udev, usbd_event_type event); /*!< usb class event handler */ + usb_sts_type(*init_handler)(void *udev); /*!< usb class init handler */ + usb_sts_type(*clear_handler)(void *udev); /*!< usb class clear handler */ + usb_sts_type(*setup_handler)(void *udev, usb_setup_type *setup); /*!< usb class setup handler */ + usb_sts_type(*ept0_tx_handler)(void *udev); /*!< usb class endpoint 0 tx complete handler */ + usb_sts_type(*ept0_rx_handler)(void *udev); /*!< usb class endpoint 0 rx complete handler */ + usb_sts_type(*in_handler)(void *udev, uint8_t ept_num); /*!< usb class in transfer complete handler */ + usb_sts_type(*out_handler)(void *udev, uint8_t ept_num); /*!< usb class out transfer complete handler */ + usb_sts_type(*sof_handler)(void *udev); /*!< usb class sof handler */ + usb_sts_type(*event_handler)(void *udev, usbd_event_type event); /*!< usb class event handler */ void *pdata; /*!< usb class data pointer */ } usbd_class_handler; diff --git a/armlib/at32_usb/usb_drivers/inc/usbh_core.h b/armlib/at32_usb/usb_drivers/inc/usbh_core.h index 91d6a3d90..457df33c2 100644 --- a/armlib/at32_usb/usb_drivers/inc/usbh_core.h +++ b/armlib/at32_usb/usb_drivers/inc/usbh_core.h @@ -51,117 +51,110 @@ extern "C" { /** * @brief usb channel flag */ -typedef enum -{ - HCH_IDLE, /*!< usb host channel idle */ - HCH_XFRC, /*!< usb host channel transfer completed */ - HCH_HALTED, /*!< usb host channel halted */ - HCH_NAK, /*!< usb host channel nak */ - HCH_NYET, /*!< usb host channel nyet */ - HCH_STALL, /*!< usb host channel stall */ - HCH_XACTERR, /*!< usb host channel transaction error */ - HCH_BBLERR, /*!< usb host channel babble error */ - HCH_DATATGLERR /*!< usb host channel data toggle error */ +typedef enum { + HCH_IDLE, /*!< usb host channel idle */ + HCH_XFRC, /*!< usb host channel transfer completed */ + HCH_HALTED, /*!< usb host channel halted */ + HCH_NAK, /*!< usb host channel nak */ + HCH_NYET, /*!< usb host channel nyet */ + HCH_STALL, /*!< usb host channel stall */ + HCH_XACTERR, /*!< usb host channel transaction error */ + HCH_BBLERR, /*!< usb host channel babble error */ + HCH_DATATGLERR /*!< usb host channel data toggle error */ } hch_sts_type; /** * @brief usb channel state */ -typedef enum -{ - URB_IDLE = 0, /*!< usb request idle state */ - URB_DONE, /*!< usb request done state */ - URB_NOTREADY, /*!< usb request not ready state */ - URB_NYET, /*!< usb request nyet stat e*/ - URB_ERROR, /*!< usb request error state */ - URB_STALL /*!< usb request stall state */ +typedef enum { + URB_IDLE = 0, /*!< usb request idle state */ + URB_DONE, /*!< usb request done state */ + URB_NOTREADY, /*!< usb request not ready state */ + URB_NYET, /*!< usb request nyet stat e*/ + URB_ERROR, /*!< usb request error state */ + URB_STALL /*!< usb request stall state */ } urb_sts_type; /** * @brief usb control channel flag */ -typedef enum -{ - CTRL_START = 0, /*!< usb control request start */ - CTRL_XFERC, /*!< usb control request completed */ - CTRL_HALTED, /*!< usb control request halted */ - CTRL_NAK, /*!< usb control request nak */ - CTRL_STALL, /*!< usb control request stall */ - CTRL_XACTERR, /*!< usb control request transaction error */ - CTRL_BBLERR, /*!< usb control request babble error */ - CTRL_DATATGLERR, /*!< usb control request data toggle error */ - CTRL_FAIL /*!< usb control request failed */ +typedef enum { + CTRL_START = 0, /*!< usb control request start */ + CTRL_XFERC, /*!< usb control request completed */ + CTRL_HALTED, /*!< usb control request halted */ + CTRL_NAK, /*!< usb control request nak */ + CTRL_STALL, /*!< usb control request stall */ + CTRL_XACTERR, /*!< usb control request transaction error */ + CTRL_BBLERR, /*!< usb control request babble error */ + CTRL_DATATGLERR, /*!< usb control request data toggle error */ + CTRL_FAIL /*!< usb control request failed */ } ctrl_sts_type; /** * @brief usb host control state machine */ -typedef enum -{ - CONTROL_IDLE, /*!< usb control state idle */ - CONTROL_SETUP, /*!< usb control state setup */ - CONTROL_SETUP_WAIT, /*!< usb control state setup wait */ - CONTROL_DATA_IN, /*!< usb control state data in */ - CONTROL_DATA_IN_WAIT, /*!< usb control state data in wait */ - CONTROL_DATA_OUT, /*!< usb control state data out */ - CONTROL_DATA_OUT_WAIT, /*!< usb control state data out wait */ - CONTROL_STATUS_IN, /*!< usb control state status in */ - CONTROL_STATUS_IN_WAIT, /*!< usb control state status in wait */ - CONTROL_STATUS_OUT, /*!< usb control state out */ - CONTROL_STATUS_OUT_WAIT, /*!< usb control state out wait */ - CONTROL_ERROR, /*!< usb control state error */ - CONTROL_STALL, /*!< usb control state stall */ - CONTROL_COMPLETE /*!< usb control state complete */ +typedef enum { + CONTROL_IDLE, /*!< usb control state idle */ + CONTROL_SETUP, /*!< usb control state setup */ + CONTROL_SETUP_WAIT, /*!< usb control state setup wait */ + CONTROL_DATA_IN, /*!< usb control state data in */ + CONTROL_DATA_IN_WAIT, /*!< usb control state data in wait */ + CONTROL_DATA_OUT, /*!< usb control state data out */ + CONTROL_DATA_OUT_WAIT, /*!< usb control state data out wait */ + CONTROL_STATUS_IN, /*!< usb control state status in */ + CONTROL_STATUS_IN_WAIT, /*!< usb control state status in wait */ + CONTROL_STATUS_OUT, /*!< usb control state out */ + CONTROL_STATUS_OUT_WAIT, /*!< usb control state out wait */ + CONTROL_ERROR, /*!< usb control state error */ + CONTROL_STALL, /*!< usb control state stall */ + CONTROL_COMPLETE /*!< usb control state complete */ } ctrl_ept0_sts_type; /** * @brief usb host enumration state machine */ -typedef enum -{ - ENUM_IDLE, /*!< usb host enumration state idle */ - ENUM_GET_MIN_DESC, /*!< usb host enumration state get descriptor 8 byte*/ - ENUM_GET_FULL_DESC, /*!< usb host enumration state get descriptor 18 byte*/ - ENUM_SET_ADDR, /*!< usb host enumration state set address */ - ENUM_GET_CFG, /*!< usb host enumration state get configuration */ - ENUM_GET_FULL_CFG, /*!< usb host enumration state get full configuration */ - ENUM_GET_MFC_STRING, /*!< usb host enumration state get manufacturer string */ - ENUM_GET_PRODUCT_STRING, /*!< usb host enumration state get product string */ - ENUM_GET_SERIALNUM_STRING, /*!< usb host enumration state get serial number string */ - ENUM_SET_CONFIG, /*!< usb host enumration state set config */ - ENUM_COMPLETE, /*!< usb host enumration state complete */ +typedef enum { + ENUM_IDLE, /*!< usb host enumration state idle */ + ENUM_GET_MIN_DESC, /*!< usb host enumration state get descriptor 8 byte*/ + ENUM_GET_FULL_DESC, /*!< usb host enumration state get descriptor 18 byte*/ + ENUM_SET_ADDR, /*!< usb host enumration state set address */ + ENUM_GET_CFG, /*!< usb host enumration state get configuration */ + ENUM_GET_FULL_CFG, /*!< usb host enumration state get full configuration */ + ENUM_GET_MFC_STRING, /*!< usb host enumration state get manufacturer string */ + ENUM_GET_PRODUCT_STRING, /*!< usb host enumration state get product string */ + ENUM_GET_SERIALNUM_STRING, /*!< usb host enumration state get serial number string */ + ENUM_SET_CONFIG, /*!< usb host enumration state set config */ + ENUM_COMPLETE, /*!< usb host enumration state complete */ } usbh_enum_sts_type; /** * @brief usb host global state machine */ -typedef enum -{ - USBH_IDLE, /*!< usb host global state idle */ - USBH_PORT_EN, /*!< usb host global state port enable */ - USBH_ATTACHED, /*!< usb host global state attached */ - USBH_DISCONNECT, /*!< usb host global state disconnect */ - USBH_DEV_SPEED, /*!< usb host global state device speed */ - USBH_ENUMERATION, /*!< usb host global state enumeration */ - USBH_CLASS_REQUEST, /*!< usb host global state class request */ - USBH_CLASS, /*!< usb host global state class */ - USBH_CTRL_XFER, /*!< usb host global state control transfer */ - USBH_USER_HANDLER, /*!< usb host global state user handler */ - USBH_SUSPEND, /*!< usb host global state suspend */ - USBH_SUSPENDED, /*!< usb host have in suspend mode */ - USBH_WAKEUP, /*!< usb host global state wakeup */ - USBH_UNSUPPORT, /*!< usb host global unsupport device */ - USBH_ERROR_STATE, /*!< usb host global state error */ +typedef enum { + USBH_IDLE, /*!< usb host global state idle */ + USBH_PORT_EN, /*!< usb host global state port enable */ + USBH_ATTACHED, /*!< usb host global state attached */ + USBH_DISCONNECT, /*!< usb host global state disconnect */ + USBH_DEV_SPEED, /*!< usb host global state device speed */ + USBH_ENUMERATION, /*!< usb host global state enumeration */ + USBH_CLASS_REQUEST, /*!< usb host global state class request */ + USBH_CLASS, /*!< usb host global state class */ + USBH_CTRL_XFER, /*!< usb host global state control transfer */ + USBH_USER_HANDLER, /*!< usb host global state user handler */ + USBH_SUSPEND, /*!< usb host global state suspend */ + USBH_SUSPENDED, /*!< usb host have in suspend mode */ + USBH_WAKEUP, /*!< usb host global state wakeup */ + USBH_UNSUPPORT, /*!< usb host global unsupport device */ + USBH_ERROR_STATE, /*!< usb host global state error */ } usbh_gstate_type; /** * @brief usb host transfer state */ -typedef enum -{ - CMD_IDLE, /*!< usb host transfer state idle */ - CMD_SEND, /*!< usb host transfer state send */ - CMD_WAIT /*!< usb host transfer state wait */ +typedef enum { + CMD_IDLE, /*!< usb host transfer state idle */ + CMD_SEND, /*!< usb host transfer state send */ + CMD_WAIT /*!< usb host transfer state wait */ } cmd_sts_type; /** @@ -203,109 +196,102 @@ typedef enum /** * @brief interface descriptor */ -typedef struct -{ - usb_interface_desc_type interface; /*!< usb device interface descriptor structure */ - usb_endpoint_desc_type endpoint[USBH_MAX_ENDPOINT]; /*!< usb device endpoint descriptor structure array */ +typedef struct { + usb_interface_desc_type interface; /*!< usb device interface descriptor structure */ + usb_endpoint_desc_type endpoint[USBH_MAX_ENDPOINT]; /*!< usb device endpoint descriptor structure array */ } usb_itf_desc_type; /** * @brief configure descriptor */ -typedef struct -{ - usb_configuration_desc_type cfg; /*!< usb device configuration descriptor structure */ - usb_itf_desc_type interface[USBH_MAX_INTERFACE]; /*!< usb device interface descriptor structure array*/ +typedef struct { + usb_configuration_desc_type cfg; /*!< usb device configuration descriptor structure */ + usb_itf_desc_type interface[USBH_MAX_INTERFACE]; /*!< usb device interface descriptor structure array*/ } usb_cfg_desc_type; /** * @brief device descriptor */ -typedef struct -{ - uint8_t address; /*!< usb device address */ - uint8_t speed; /*!< usb device speed */ - usb_device_desc_type dev_desc; /*!< usb device descriptor */ - usb_cfg_desc_type cfg_desc; /*!< usb device configuration */ +typedef struct { + uint8_t address; /*!< usb device address */ + uint8_t speed; /*!< usb device speed */ + usb_device_desc_type dev_desc; /*!< usb device descriptor */ + usb_cfg_desc_type cfg_desc; /*!< usb device configuration */ } usbh_dev_desc_type; /** * @brief usb host control struct type */ -typedef struct -{ - uint8_t hch_in; /*!< in channel number */ - uint8_t hch_out; /*!< out channel number */ - uint8_t ept0_size; /*!< endpoint 0 size */ - uint8_t *buffer; /*!< endpoint 0 transfer buffer */ - usb_setup_type setup; /*!< control setup type */ - uint16_t len; /*!< transfer length */ - uint8_t err_cnt; /*!< error counter */ - uint32_t timer; /*!< transfer timer */ - ctrl_sts_type sts; /*!< control transfer status */ - ctrl_ept0_sts_type state; /*!< endpoint 0 state */ +typedef struct { + uint8_t hch_in; /*!< in channel number */ + uint8_t hch_out; /*!< out channel number */ + uint8_t ept0_size; /*!< endpoint 0 size */ + uint8_t *buffer; /*!< endpoint 0 transfer buffer */ + usb_setup_type setup; /*!< control setup type */ + uint16_t len; /*!< transfer length */ + uint8_t err_cnt; /*!< error counter */ + uint32_t timer; /*!< transfer timer */ + ctrl_sts_type sts; /*!< control transfer status */ + ctrl_ept0_sts_type state; /*!< endpoint 0 state */ } usbh_ctrl_type; /** * @brief host class handler type */ -typedef struct -{ - usb_sts_type (*init_handler)(void *uhost); /*!< usb host class init handler */ - usb_sts_type (*reset_handler)(void *uhost); /*!< usb host class reset handler */ - usb_sts_type (*request_handler)(void *uhost); /*!< usb host class request handler */ - usb_sts_type (*process_handler)(void *uhost); /*!< usb host class process handler */ - void *pdata; /*!< usb host class data */ +typedef struct { + usb_sts_type(*init_handler)(void *uhost); /*!< usb host class init handler */ + usb_sts_type(*reset_handler)(void *uhost); /*!< usb host class reset handler */ + usb_sts_type(*request_handler)(void *uhost); /*!< usb host class request handler */ + usb_sts_type(*process_handler)(void *uhost); /*!< usb host class process handler */ + void *pdata; /*!< usb host class data */ } usbh_class_handler_type; /** * @brief host user handler type */ -typedef struct -{ - usb_sts_type (*user_init)(void); /*!< usb host user init handler */ - usb_sts_type (*user_reset)(void); /*!< usb host user reset handler */ - usb_sts_type (*user_attached)(void); /*!< usb host user attached handler */ - usb_sts_type (*user_disconnect)(void); /*!< usb host user disconnect handler */ - usb_sts_type (*user_speed)(uint8_t speed); /*!< usb host user speed handler */ - usb_sts_type (*user_mfc_string)(void *); /*!< usb host user manufacturer string handler */ - usb_sts_type (*user_product_string)(void *); /*!< usb host user product string handler */ - usb_sts_type (*user_serial_string)(void *); /*!< usb host user serial handler */ - usb_sts_type (*user_enumeration_done)(void); /*!< usb host user enumeration done handler */ - usb_sts_type (*user_application)(void); /*!< usb host user application handler */ - usb_sts_type (*user_active_vbus)(void *uhost, confirm_state state); /*!< usb host user active vbus */ - usb_sts_type (*user_not_support)(void); /*!< usb host user not support handler */ +typedef struct { + usb_sts_type(*user_init)(void); /*!< usb host user init handler */ + usb_sts_type(*user_reset)(void); /*!< usb host user reset handler */ + usb_sts_type(*user_attached)(void); /*!< usb host user attached handler */ + usb_sts_type(*user_disconnect)(void); /*!< usb host user disconnect handler */ + usb_sts_type(*user_speed)(uint8_t speed); /*!< usb host user speed handler */ + usb_sts_type(*user_mfc_string)(void *); /*!< usb host user manufacturer string handler */ + usb_sts_type(*user_product_string)(void *); /*!< usb host user product string handler */ + usb_sts_type(*user_serial_string)(void *); /*!< usb host user serial handler */ + usb_sts_type(*user_enumeration_done)(void); /*!< usb host user enumeration done handler */ + usb_sts_type(*user_application)(void); /*!< usb host user application handler */ + usb_sts_type(*user_active_vbus)(void *uhost, confirm_state state); /*!< usb host user active vbus */ + usb_sts_type(*user_not_support)(void); /*!< usb host user not support handler */ } usbh_user_handler_type; /** * @brief host host core handler type */ -typedef struct -{ - usb_reg_type *usb_reg; /*!< usb register pointer */ +typedef struct { + usb_reg_type *usb_reg; /*!< usb register pointer */ - uint8_t global_state; /*!< usb host global state machine */ - uint8_t enum_state; /*!< usb host enumeration state machine */ - uint8_t req_state; /*!< usb host request state machine */ + uint8_t global_state; /*!< usb host global state machine */ + uint8_t enum_state; /*!< usb host enumeration state machine */ + uint8_t req_state; /*!< usb host request state machine */ - usbh_dev_desc_type dev; /*!< usb device descriptor */ - usbh_ctrl_type ctrl; /*!< usb host control transfer struct */ + usbh_dev_desc_type dev; /*!< usb device descriptor */ + usbh_ctrl_type ctrl; /*!< usb host control transfer struct */ - usbh_class_handler_type *class_handler; /*!< usb host class handler pointer */ - usbh_user_handler_type *user_handler; /*!< usb host user handler pointer */ + usbh_class_handler_type *class_handler; /*!< usb host class handler pointer */ + usbh_user_handler_type *user_handler; /*!< usb host user handler pointer */ - usb_hch_type hch[USB_HOST_CHANNEL_NUM]; /*!< usb host channel array */ - uint8_t rx_buffer[USB_MAX_DATA_LENGTH]; /*!< usb host rx buffer */ + usb_hch_type hch[USB_HOST_CHANNEL_NUM]; /*!< usb host channel array */ + uint8_t rx_buffer[USB_MAX_DATA_LENGTH]; /*!< usb host rx buffer */ - uint32_t conn_sts; /*!< connect status */ - uint32_t port_enable; /*!< port enable status */ - uint32_t timer; /*!< sof timer */ + uint32_t conn_sts; /*!< connect status */ + uint32_t port_enable; /*!< port enable status */ + uint32_t timer; /*!< sof timer */ - uint32_t err_cnt[USB_HOST_CHANNEL_NUM]; /*!< error counter */ - uint32_t xfer_cnt[USB_HOST_CHANNEL_NUM]; /*!< xfer counter */ - hch_sts_type hch_state[USB_HOST_CHANNEL_NUM];/*!< channel state */ - urb_sts_type urb_state[USB_HOST_CHANNEL_NUM];/*!< usb request state */ - uint16_t channel[USB_HOST_CHANNEL_NUM]; /*!< channel array */ + uint32_t err_cnt[USB_HOST_CHANNEL_NUM]; /*!< error counter */ + uint32_t xfer_cnt[USB_HOST_CHANNEL_NUM]; /*!< xfer counter */ + hch_sts_type hch_state[USB_HOST_CHANNEL_NUM];/*!< channel state */ + urb_sts_type urb_state[USB_HOST_CHANNEL_NUM];/*!< usb request state */ + uint16_t channel[USB_HOST_CHANNEL_NUM]; /*!< channel array */ } usbh_core_type; @@ -314,9 +300,9 @@ uint16_t usbh_get_free_channel(usbh_core_type *uhost); usb_sts_type usbh_set_toggle(usbh_core_type *uhost, uint8_t hc_num, uint8_t toggle); usb_sts_type usbh_in_out_request(usbh_core_type *uhost, uint8_t hc_num); usb_sts_type usbh_interrupt_recv(usbh_core_type *uhost, uint8_t hc_num, - uint8_t *buffer, uint16_t length); + uint8_t *buffer, uint16_t length); usb_sts_type usbh_interrupt_send(usbh_core_type *uhost, uint8_t hc_num, - uint8_t *buffer, uint16_t length); + uint8_t *buffer, uint16_t length); usb_sts_type usbh_bulk_recv(usbh_core_type *uhost, uint8_t hc_num, uint8_t *buffer, uint16_t length); usb_sts_type usbh_bulk_send(usbh_core_type *uhost, uint8_t hc_num, @@ -339,12 +325,12 @@ void usbh_reset_port(usbh_core_type *uhost); usb_sts_type usbh_loop_handler(usbh_core_type *uhost); void usbh_ch_disable(usbh_core_type *uhost, uint8_t chn); void usbh_hc_open(usbh_core_type *uhost, - uint8_t chn, - uint8_t ept_num, - uint8_t dev_address, - uint8_t type, - uint16_t maxpacket, - uint8_t speed); + uint8_t chn, + uint8_t ept_num, + uint8_t dev_address, + uint8_t type, + uint16_t maxpacket, + uint8_t speed); void usbh_active_vbus(usbh_core_type *uhost, confirm_state state); usb_sts_type usbh_core_init(usbh_core_type *uhost, diff --git a/armlib/at32_usb/usb_drivers/inc/usbh_ctrl.h b/armlib/at32_usb/usb_drivers/inc/usbh_ctrl.h index 4d6312855..0cddf2ef0 100644 --- a/armlib/at32_usb/usb_drivers/inc/usbh_ctrl.h +++ b/armlib/at32_usb/usb_drivers/inc/usbh_ctrl.h @@ -49,9 +49,9 @@ extern "C" { usb_sts_type usbh_ctrl_send_setup(usbh_core_type *uhost, uint8_t *buffer, uint8_t hc_num); usb_sts_type usbh_ctrl_recv_data(usbh_core_type *uhost, uint8_t *buffer, - uint16_t length, uint16_t hc_num); + uint16_t length, uint16_t hc_num); usb_sts_type usbh_ctrl_send_data(usbh_core_type *uhost, uint8_t *buffer, - uint16_t length, uint16_t hc_num); + uint16_t length, uint16_t hc_num); usb_sts_type usbh_ctrl_setup_handler(usbh_core_type *uhost); usb_sts_type usbh_ctrl_setup_wait_handler(usbh_core_type *uhost, uint32_t *timeout); usb_sts_type usbh_ctrl_data_in_handler(usbh_core_type *uhost); @@ -68,20 +68,20 @@ usb_sts_type usbh_ctrl_complete_handler(usbh_core_type *uhost); usb_sts_type usbh_ctrl_transfer_loop(usbh_core_type *uhost); usb_sts_type usbh_ctrl_request(usbh_core_type *uhost, uint8_t *buffer, uint16_t length); usb_sts_type usbh_get_descriptor(usbh_core_type *uhost, uint16_t length, - uint8_t req_type, uint16_t wvalue, - uint8_t *buffer); + uint8_t req_type, uint16_t wvalue, + uint8_t *buffer); void usbh_parse_dev_desc(usbh_core_type *uhost, uint8_t *buffer, uint16_t length); usb_header_desc_type *usbh_get_next_header(uint8_t *buf, uint16_t *index_len); void usbh_parse_interface_desc(usb_interface_desc_type *intf, uint8_t *buf); void usbh_parse_endpoint_desc(usb_endpoint_desc_type *ept_desc, uint8_t *buf); usb_sts_type usbh_parse_configure_desc(usbh_core_type *uhost, - uint8_t *buffer, uint16_t length); + uint8_t *buffer, uint16_t length); uint8_t usbh_find_interface(usbh_core_type *uhost, uint8_t class_code, uint8_t sub_class, uint8_t protocol); void usbh_parse_string_desc(uint8_t *src, uint8_t *dest, uint16_t length); usb_sts_type usbh_get_device_descriptor(usbh_core_type *uhost, uint16_t length); usb_sts_type usbh_get_configure_descriptor(usbh_core_type *uhost, uint16_t length); usb_sts_type usbh_get_sting_descriptor(usbh_core_type *uhost, uint8_t string_id, - uint8_t *buffer, uint16_t length); + uint8_t *buffer, uint16_t length); usb_sts_type usbh_set_configuration(usbh_core_type *uhost, uint16_t config); usb_sts_type usbh_set_address(usbh_core_type *uhost, uint8_t address); usb_sts_type usbh_set_interface(usbh_core_type *uhost, uint8_t ept_num, uint8_t altsetting); diff --git a/armlib/at32_usb/usb_drivers/src/usb_core.c b/armlib/at32_usb/usb_drivers/src/usb_core.c index 8b11f3c37..0ed68f235 100644 --- a/armlib/at32_usb/usb_drivers/src/usb_core.c +++ b/armlib/at32_usb/usb_drivers/src/usb_core.c @@ -44,40 +44,38 @@ usb_sts_type usb_core_config(otg_core_type *udev, uint8_t core_id); * @param core_id: usb core id number (USB_FULL_SPEED_CORE_ID) * @retval usb_sts_type */ -usb_sts_type usb_core_config(otg_core_type *otgdev, uint8_t core_id) -{ - /* set usb speed and core id */ - otgdev->cfg.speed = core_id; - otgdev->cfg.core_id = core_id; +usb_sts_type usb_core_config(otg_core_type *otgdev, uint8_t core_id) { + /* set usb speed and core id */ + otgdev->cfg.speed = core_id; + otgdev->cfg.core_id = core_id; - /* default sof out and vbus ignore */ - otgdev->cfg.sof_out = FALSE; - otgdev->cfg.vbusig = FALSE; + /* default sof out and vbus ignore */ + otgdev->cfg.sof_out = FALSE; + otgdev->cfg.vbusig = FALSE; - /* set max size */ - otgdev->cfg.max_size = 64; + /* set max size */ + otgdev->cfg.max_size = 64; - /* set support number of channel and endpoint */ + /* set support number of channel and endpoint */ #ifdef USE_OTG_HOST_MODE - otgdev->cfg.hc_num = USB_HOST_CHANNEL_NUM; + otgdev->cfg.hc_num = USB_HOST_CHANNEL_NUM; #endif #ifdef USE_OTG_DEVICE_MODE - otgdev->cfg.ept_num = USB_EPT_MAX_NUM; + otgdev->cfg.ept_num = USB_EPT_MAX_NUM; #endif - otgdev->cfg.fifo_size = OTG_FIFO_SIZE; - if(core_id == USB_FULL_SPEED_CORE_ID) - { - otgdev->cfg.phy_itface = 2; - } + otgdev->cfg.fifo_size = OTG_FIFO_SIZE; + if (core_id == USB_FULL_SPEED_CORE_ID) { + otgdev->cfg.phy_itface = 2; + } #ifdef USB_SOF_OUTPUT_ENABLE - otgdev->cfg.sof_out = TRUE; + otgdev->cfg.sof_out = TRUE; #endif #ifdef USB_VBUS_IGNORE - otgdev->cfg.vbusig = TRUE; + otgdev->cfg.vbusig = TRUE; #endif - return USB_OK; + return USB_OK; } #ifdef USE_OTG_DEVICE_MODE @@ -94,35 +92,32 @@ usb_sts_type usb_core_config(otg_core_type *otgdev, uint8_t core_id) * @retval usb_sts_type */ usb_sts_type usbd_init(otg_core_type *otgdev, - uint8_t core_id, uint8_t usb_id, - usbd_class_handler *class_handler, - usbd_desc_handler *desc_handler) -{ - usb_sts_type usb_sts = USB_OK; + uint8_t core_id, uint8_t usb_id, + usbd_class_handler *class_handler, + usbd_desc_handler *desc_handler) { + usb_sts_type usb_sts = USB_OK; - /* select use OTG1 or OTG2 */ - otgdev->usb_reg = usb_global_select_core(usb_id); + /* select use OTG1 or OTG2 */ + otgdev->usb_reg = usb_global_select_core(usb_id); - /* usb device core config */ - usb_core_config(otgdev, core_id); + /* usb device core config */ + usb_core_config(otgdev, core_id); - if(otgdev->cfg.sof_out) - { - otgdev->usb_reg->gccfg_bit.sofouten = TRUE; - } + if (otgdev->cfg.sof_out) { + otgdev->usb_reg->gccfg_bit.sofouten = TRUE; + } - if(otgdev->cfg.vbusig) - { - otgdev->usb_reg->gccfg_bit.vbusig = TRUE; - } + if (otgdev->cfg.vbusig) { + otgdev->usb_reg->gccfg_bit.vbusig = TRUE; + } - /* usb device core init */ - usbd_core_init(&(otgdev->dev), otgdev->usb_reg, - class_handler, - desc_handler, - core_id); + /* usb device core init */ + usbd_core_init(&(otgdev->dev), otgdev->usb_reg, + class_handler, + desc_handler, + core_id); - return usb_sts; + return usb_sts; } #endif @@ -141,35 +136,32 @@ usb_sts_type usbd_init(otg_core_type *otgdev, * @retval usb_sts_type */ usb_sts_type usbh_init(otg_core_type *otgdev, - uint8_t core_id, uint8_t usb_id, - usbh_class_handler_type *class_handler, - usbh_user_handler_type *user_handler) -{ - usb_sts_type status = USB_OK; + uint8_t core_id, uint8_t usb_id, + usbh_class_handler_type *class_handler, + usbh_user_handler_type *user_handler) { + usb_sts_type status = USB_OK; - /* select use otg1 or otg2 */ - otgdev->usb_reg = usb_global_select_core(usb_id); + /* select use otg1 or otg2 */ + otgdev->usb_reg = usb_global_select_core(usb_id); - /* usb core config */ - usb_core_config(otgdev, core_id); + /* usb core config */ + usb_core_config(otgdev, core_id); - if(otgdev->cfg.sof_out) - { - otgdev->usb_reg->gccfg_bit.sofouten = TRUE; - } + if (otgdev->cfg.sof_out) { + otgdev->usb_reg->gccfg_bit.sofouten = TRUE; + } - if(otgdev->cfg.vbusig) - { - otgdev->usb_reg->gccfg_bit.vbusig = TRUE; - } + if (otgdev->cfg.vbusig) { + otgdev->usb_reg->gccfg_bit.vbusig = TRUE; + } - /* usb host core init */ - usbh_core_init(&otgdev->host, otgdev->usb_reg, - class_handler, - user_handler, - core_id); + /* usb host core init */ + usbh_core_init(&otgdev->host, otgdev->usb_reg, + class_handler, + user_handler, + core_id); - return status; + return status; } #endif diff --git a/armlib/at32_usb/usb_drivers/src/usbd_core.c b/armlib/at32_usb/usb_drivers/src/usbd_core.c index ac033cfea..cb9209fa8 100644 --- a/armlib/at32_usb/usb_drivers/src/usbd_core.c +++ b/armlib/at32_usb/usb_drivers/src/usbd_core.c @@ -45,49 +45,39 @@ * @param ept_addr: endpoint number * @retval none */ -void usbd_core_in_handler(usbd_core_type *udev, uint8_t ept_addr) -{ - /* get endpoint info*/ - usb_ept_info *ept_info = &udev->ept_in[ept_addr & 0x7F]; +void usbd_core_in_handler(usbd_core_type *udev, uint8_t ept_addr) { + /* get endpoint info*/ + usb_ept_info *ept_info = &udev->ept_in[ept_addr & 0x7F]; - if(ept_addr == 0) - { - if(udev->ept0_sts == USB_EPT0_DATA_IN) - { - if(ept_info->rem0_len > ept_info->maxpacket) - { - ept_info->rem0_len -= ept_info->maxpacket; - usbd_ept_send(udev, 0, ept_info->trans_buf, - MIN(ept_info->rem0_len, ept_info->maxpacket)); - } - /* endpoint 0 */ - else if(ept_info->last_len == ept_info->maxpacket - && ept_info->ept0_slen >= ept_info->maxpacket - && ept_info->ept0_slen < udev->ept0_wlength) - { - ept_info->last_len = 0; - usbd_ept_send(udev, 0, 0, 0); - usbd_ept_recv(udev, ept_addr, 0, 0); - } - else - { + if (ept_addr == 0) { + if (udev->ept0_sts == USB_EPT0_DATA_IN) { + if (ept_info->rem0_len > ept_info->maxpacket) { + ept_info->rem0_len -= ept_info->maxpacket; + usbd_ept_send(udev, 0, ept_info->trans_buf, + MIN(ept_info->rem0_len, ept_info->maxpacket)); + } + /* endpoint 0 */ + else if (ept_info->last_len == ept_info->maxpacket + && ept_info->ept0_slen >= ept_info->maxpacket + && ept_info->ept0_slen < udev->ept0_wlength) { + ept_info->last_len = 0; + usbd_ept_send(udev, 0, 0, 0); + usbd_ept_recv(udev, ept_addr, 0, 0); + } else { - if(udev->class_handler->ept0_tx_handler != 0 && - udev->conn_state == USB_CONN_STATE_CONFIGURED) - { - udev->class_handler->ept0_tx_handler(udev); + if (udev->class_handler->ept0_tx_handler != 0 && + udev->conn_state == USB_CONN_STATE_CONFIGURED) { + udev->class_handler->ept0_tx_handler(udev); + } + usbd_ctrl_recv_status(udev); + + } } - usbd_ctrl_recv_status(udev); - - } + } else if (udev->class_handler->in_handler != 0 && + udev->conn_state == USB_CONN_STATE_CONFIGURED) { + /* other user define endpoint */ + udev->class_handler->in_handler(udev, ept_addr); } - } - else if(udev->class_handler->in_handler != 0 && - udev->conn_state == USB_CONN_STATE_CONFIGURED) - { - /* other user define endpoint */ - udev->class_handler->in_handler(udev, ept_addr); - } } /** @@ -96,38 +86,29 @@ void usbd_core_in_handler(usbd_core_type *udev, uint8_t ept_addr) * @param ept_addr: endpoint number * @retval none */ -void usbd_core_out_handler(usbd_core_type *udev, uint8_t ept_addr) -{ - /* get endpoint info*/ - usb_ept_info *ept_info = &udev->ept_out[ept_addr & 0x7F]; +void usbd_core_out_handler(usbd_core_type *udev, uint8_t ept_addr) { + /* get endpoint info*/ + usb_ept_info *ept_info = &udev->ept_out[ept_addr & 0x7F]; - if(ept_addr == 0) - { - /* endpoint 0 */ - if(udev->ept0_sts == USB_EPT0_DATA_OUT) - { - if(ept_info->rem0_len > ept_info->maxpacket) - { - ept_info->rem0_len -= ept_info->maxpacket; - usbd_ept_recv(udev, ept_addr, ept_info->trans_buf, - MIN(ept_info->rem0_len, ept_info->maxpacket)); - } - else - { - if(udev->class_handler->ept0_rx_handler != 0) - { - udev->class_handler->ept0_rx_handler(udev); - } - usbd_ctrl_send_status(udev); - } + if (ept_addr == 0) { + /* endpoint 0 */ + if (udev->ept0_sts == USB_EPT0_DATA_OUT) { + if (ept_info->rem0_len > ept_info->maxpacket) { + ept_info->rem0_len -= ept_info->maxpacket; + usbd_ept_recv(udev, ept_addr, ept_info->trans_buf, + MIN(ept_info->rem0_len, ept_info->maxpacket)); + } else { + if (udev->class_handler->ept0_rx_handler != 0) { + udev->class_handler->ept0_rx_handler(udev); + } + usbd_ctrl_send_status(udev); + } + } + } else if (udev->class_handler->out_handler != 0 && + udev->conn_state == USB_CONN_STATE_CONFIGURED) { + /* other user define endpoint */ + udev->class_handler->out_handler(udev, ept_addr); } - } - else if(udev->class_handler->out_handler != 0 && - udev->conn_state == USB_CONN_STATE_CONFIGURED) - { - /* other user define endpoint */ - udev->class_handler->out_handler(udev, ept_addr); - } } /** @@ -136,33 +117,31 @@ void usbd_core_out_handler(usbd_core_type *udev, uint8_t ept_addr) * @param ept_addr: endpoint number * @retval none */ -void usbd_core_setup_handler(usbd_core_type *udev, uint8_t ept_num) -{ - /* setup parse */ - usbd_setup_request_parse(&udev->setup, udev->setup_buffer); +void usbd_core_setup_handler(usbd_core_type *udev, uint8_t ept_num) { + /* setup parse */ + usbd_setup_request_parse(&udev->setup, udev->setup_buffer); - /* set ept0 status */ - udev->ept0_sts = USB_EPT0_SETUP; - udev->ept0_wlength = udev->setup.wLength; + /* set ept0 status */ + udev->ept0_sts = USB_EPT0_SETUP; + udev->ept0_wlength = udev->setup.wLength; - switch(udev->setup.bmRequestType & USB_REQ_RECIPIENT_MASK) - { - case USB_REQ_RECIPIENT_DEVICE: - /* recipient device request */ - usbd_device_request(udev); - break; - case USB_REQ_RECIPIENT_INTERFACE: - /* recipient interface request */ - usbd_interface_request(udev); - break; - case USB_REQ_RECIPIENT_ENDPOINT: - /* recipient endpoint request */ - usbd_endpoint_request(udev); - break; - default: - usbd_ctrl_unsupport(udev); - break; - } + switch (udev->setup.bmRequestType & USB_REQ_RECIPIENT_MASK) { + case USB_REQ_RECIPIENT_DEVICE: + /* recipient device request */ + usbd_device_request(udev); + break; + case USB_REQ_RECIPIENT_INTERFACE: + /* recipient interface request */ + usbd_interface_request(udev); + break; + case USB_REQ_RECIPIENT_ENDPOINT: + /* recipient endpoint request */ + usbd_endpoint_request(udev); + break; + default: + usbd_ctrl_unsupport(udev); + break; + } } /** @@ -173,15 +152,14 @@ void usbd_core_setup_handler(usbd_core_type *udev, uint8_t ept_num) * @param len: send data length * @retval none */ -void usbd_ctrl_send(usbd_core_type *udev, uint8_t *buffer, uint16_t len) -{ - usb_ept_info *ept_info = &udev->ept_in[0]; +void usbd_ctrl_send(usbd_core_type *udev, uint8_t *buffer, uint16_t len) { + usb_ept_info *ept_info = &udev->ept_in[0]; - ept_info->ept0_slen = len; - ept_info->rem0_len = len; - udev->ept0_sts = USB_EPT0_DATA_IN; + ept_info->ept0_slen = len; + ept_info->rem0_len = len; + udev->ept0_sts = USB_EPT0_DATA_IN; - usbd_ept_send(udev, 0, buffer, len); + usbd_ept_send(udev, 0, buffer, len); } /** @@ -192,15 +170,14 @@ void usbd_ctrl_send(usbd_core_type *udev, uint8_t *buffer, uint16_t len) * @param len: recv data length * @retval none */ -void usbd_ctrl_recv(usbd_core_type *udev, uint8_t *buffer, uint16_t len) -{ - usb_ept_info *ept_info = &udev->ept_out[0]; +void usbd_ctrl_recv(usbd_core_type *udev, uint8_t *buffer, uint16_t len) { + usb_ept_info *ept_info = &udev->ept_out[0]; - ept_info->ept0_slen = len; - ept_info->rem0_len = len; - udev->ept0_sts = USB_EPT0_DATA_OUT; + ept_info->ept0_slen = len; + ept_info->rem0_len = len; + udev->ept0_sts = USB_EPT0_DATA_OUT; - usbd_ept_recv(udev, 0, buffer, len); + usbd_ept_recv(udev, 0, buffer, len); } /** @@ -208,11 +185,10 @@ void usbd_ctrl_recv(usbd_core_type *udev, uint8_t *buffer, uint16_t len) * @param udev: to the structure of usbd_core_type * @retval none */ -void usbd_ctrl_send_status(usbd_core_type *udev) -{ - udev->ept0_sts = USB_EPT0_STATUS_IN; +void usbd_ctrl_send_status(usbd_core_type *udev) { + udev->ept0_sts = USB_EPT0_STATUS_IN; - usbd_ept_send(udev, 0, 0, 0); + usbd_ept_send(udev, 0, 0, 0); } /** @@ -220,11 +196,10 @@ void usbd_ctrl_send_status(usbd_core_type *udev) * @param udev: to the structure of usbd_core_type * @retval none */ -void usbd_ctrl_recv_status(usbd_core_type *udev) -{ - udev->ept0_sts = USB_EPT0_STATUS_OUT; +void usbd_ctrl_recv_status(usbd_core_type *udev) { + udev->ept0_sts = USB_EPT0_STATUS_OUT; - usbd_ept_recv(udev, 0, 0, 0); + usbd_ept_recv(udev, 0, 0, 0); } /** @@ -233,23 +208,19 @@ void usbd_ctrl_recv_status(usbd_core_type *udev) * @param ept_addr: endpoint number * @retval none */ -void usbd_clear_stall(usbd_core_type *udev, uint8_t ept_addr) -{ - usb_ept_info *ept_info; - usb_reg_type *usbx = udev->usb_reg; +void usbd_clear_stall(usbd_core_type *udev, uint8_t ept_addr) { + usb_ept_info *ept_info; + usb_reg_type *usbx = udev->usb_reg; - if(ept_addr & 0x80) - { - /* in endpoint */ - ept_info = &udev->ept_in[ept_addr & 0x7F]; - } - else - { - /* out endpoint */ - ept_info = &udev->ept_out[ept_addr & 0x7F]; - } - usb_ept_clear_stall(usbx, ept_info); - ept_info->stall = 0; + if (ept_addr & 0x80) { + /* in endpoint */ + ept_info = &udev->ept_in[ept_addr & 0x7F]; + } else { + /* out endpoint */ + ept_info = &udev->ept_out[ept_addr & 0x7F]; + } + usb_ept_clear_stall(usbx, ept_info); + ept_info->stall = 0; } /** @@ -258,24 +229,20 @@ void usbd_clear_stall(usbd_core_type *udev, uint8_t ept_addr) * @param ept_addr: endpoint number * @retval none */ -void usbd_set_stall(usbd_core_type *udev, uint8_t ept_addr) -{ - usb_ept_info *ept_info; - usb_reg_type *usbx = udev->usb_reg; +void usbd_set_stall(usbd_core_type *udev, uint8_t ept_addr) { + usb_ept_info *ept_info; + usb_reg_type *usbx = udev->usb_reg; - if(ept_addr & 0x80) - { - /* in endpoint */ - ept_info = &udev->ept_in[ept_addr & 0x7F]; - } - else - { - /* out endpoint */ - ept_info = &udev->ept_out[ept_addr & 0x7F]; - } - usb_ept_stall(usbx, ept_info); + if (ept_addr & 0x80) { + /* in endpoint */ + ept_info = &udev->ept_in[ept_addr & 0x7F]; + } else { + /* out endpoint */ + ept_info = &udev->ept_out[ept_addr & 0x7F]; + } + usb_ept_stall(usbx, ept_info); - ept_info->stall = 1; + ept_info->stall = 1; } /** @@ -283,11 +250,10 @@ void usbd_set_stall(usbd_core_type *udev, uint8_t ept_addr) * @param udev: to the structure of usbd_core_type * @retval none */ -void usbd_ctrl_unsupport(usbd_core_type *udev) -{ - /* return stall status */ - usbd_set_stall(udev, 0x00); - usbd_set_stall(udev, 0x80); +void usbd_ctrl_unsupport(usbd_core_type *udev) { + /* return stall status */ + usbd_set_stall(udev, 0x00); + usbd_set_stall(udev, 0x80); } /** @@ -296,10 +262,9 @@ void usbd_ctrl_unsupport(usbd_core_type *udev) * @param ept_addr: endpoint number * @retval data receive len */ -uint32_t usbd_get_recv_len(usbd_core_type *udev, uint8_t ept_addr) -{ - usb_ept_info *ept = &udev->ept_out[ept_addr & 0x7F]; - return ept->trans_len; +uint32_t usbd_get_recv_len(usbd_core_type *udev, uint8_t ept_addr) { + usb_ept_info *ept = &udev->ept_out[ept_addr & 0x7F]; + return ept->trans_len; } /** @@ -310,30 +275,26 @@ uint32_t usbd_get_recv_len(usbd_core_type *udev, uint8_t ept_addr) * @param maxpacket: endpoint support max buffer size * @retval none */ -void usbd_ept_open(usbd_core_type *udev, uint8_t ept_addr, uint8_t ept_type, uint16_t maxpacket) -{ - usb_reg_type *usbx = udev->usb_reg; - usb_ept_info *ept_info; +void usbd_ept_open(usbd_core_type *udev, uint8_t ept_addr, uint8_t ept_type, uint16_t maxpacket) { + usb_reg_type *usbx = udev->usb_reg; + usb_ept_info *ept_info; - if((ept_addr & 0x80) == 0) - { - /* out endpoint info */ - ept_info = &udev->ept_out[ept_addr & 0x7F]; - ept_info->inout = EPT_DIR_OUT; - } - else - { - /* in endpoint info */ - ept_info = &udev->ept_in[ept_addr & 0x7F]; - ept_info->inout = EPT_DIR_IN; - } + if ((ept_addr & 0x80) == 0) { + /* out endpoint info */ + ept_info = &udev->ept_out[ept_addr & 0x7F]; + ept_info->inout = EPT_DIR_OUT; + } else { + /* in endpoint info */ + ept_info = &udev->ept_in[ept_addr & 0x7F]; + ept_info->inout = EPT_DIR_IN; + } - /* set endpoint maxpacket and type */ - ept_info->maxpacket = maxpacket; - ept_info->trans_type = ept_type; + /* set endpoint maxpacket and type */ + ept_info->maxpacket = maxpacket; + ept_info->trans_type = ept_type; - /* open endpoint */ - usb_ept_open(usbx, ept_info); + /* open endpoint */ + usb_ept_open(usbx, ept_info); } /** @@ -342,20 +303,18 @@ void usbd_ept_open(usbd_core_type *udev, uint8_t ept_addr, uint8_t ept_type, uin * @param ept_addr: endpoint number * @retval none */ -void usbd_ept_in_check_fifo(usbd_core_type *udev, uint8_t ept_addr) -{ - otg_global_type *usbx = udev->usb_reg; - uint32_t timeout = 0xFFFF; - uint8_t endp = ept_addr & 0x7F; - if(USB_INEPT(usbx, endp)->diepctl_bit.eptena == SET && - USB_INEPT(usbx, endp)->diepctl_bit.usbacept == SET) - { - USB_INEPT(usbx, endp)->diepctl_bit.snak = TRUE; - USB_INEPT(usbx, endp)->diepctl_bit.eptdis = TRUE; - USB_INEPT(usbx, endp)->diepctl_bit.snak = TRUE; - while(USB_INEPT(usbx, endp)->diepctl_bit.eptdis && timeout --); - usbd_flush_tx_fifo(udev, endp); - } +void usbd_ept_in_check_fifo(usbd_core_type *udev, uint8_t ept_addr) { + otg_global_type *usbx = udev->usb_reg; + uint32_t timeout = 0xFFFF; + uint8_t endp = ept_addr & 0x7F; + if (USB_INEPT(usbx, endp)->diepctl_bit.eptena == SET && + USB_INEPT(usbx, endp)->diepctl_bit.usbacept == SET) { + USB_INEPT(usbx, endp)->diepctl_bit.snak = TRUE; + USB_INEPT(usbx, endp)->diepctl_bit.eptdis = TRUE; + USB_INEPT(usbx, endp)->diepctl_bit.snak = TRUE; + while (USB_INEPT(usbx, endp)->diepctl_bit.eptdis && timeout --); + usbd_flush_tx_fifo(udev, endp); + } } /** @@ -364,22 +323,18 @@ void usbd_ept_in_check_fifo(usbd_core_type *udev, uint8_t ept_addr) * @param ept_addr: endpoint number * @retval none */ -void usbd_ept_close(usbd_core_type *udev, uint8_t ept_addr) -{ - usb_ept_info *ept_info; - if(ept_addr & 0x80) - { - /* in endpoint */ - ept_info = &udev->ept_in[ept_addr & 0x7F]; - } - else - { - /* out endpoint */ - ept_info = &udev->ept_out[ept_addr & 0x7F]; - } +void usbd_ept_close(usbd_core_type *udev, uint8_t ept_addr) { + usb_ept_info *ept_info; + if (ept_addr & 0x80) { + /* in endpoint */ + ept_info = &udev->ept_in[ept_addr & 0x7F]; + } else { + /* out endpoint */ + ept_info = &udev->ept_out[ept_addr & 0x7F]; + } - /* close endpoint */ - usb_ept_close(udev->usb_reg, ept_info); + /* close endpoint */ + usb_ept_close(udev->usb_reg, ept_info); } /** @@ -387,9 +342,8 @@ void usbd_ept_close(usbd_core_type *udev, uint8_t ept_addr) * @param udev: to the structure of usbd_core_type * @retval none */ -void usbd_connect(usbd_core_type *udev) -{ - usb_connect(udev->usb_reg); +void usbd_connect(usbd_core_type *udev) { + usb_connect(udev->usb_reg); } /** @@ -397,9 +351,8 @@ void usbd_connect(usbd_core_type *udev) * @param udev: to the structure of usbd_core_type * @retval none */ -void usbd_disconnect(usbd_core_type *udev) -{ - usb_disconnect(udev->usb_reg); +void usbd_disconnect(usbd_core_type *udev) { + usb_disconnect(udev->usb_reg); } /** @@ -408,9 +361,8 @@ void usbd_disconnect(usbd_core_type *udev) * @param address: host assignment address * @retval none */ -void usbd_set_device_addr(usbd_core_type *udev, uint8_t address) -{ - usb_set_address(udev->usb_reg, address); +void usbd_set_device_addr(usbd_core_type *udev, uint8_t address) { + usb_set_address(udev->usb_reg, address); } /** @@ -418,30 +370,27 @@ void usbd_set_device_addr(usbd_core_type *udev, uint8_t address) * @param udev: to the structure of usbd_core_type * @retval none */ -static void usb_ept_default_init(usbd_core_type *udev) -{ - uint8_t i_index = 0; - /* init in endpoint info structure */ - for(i_index = 0; i_index < USB_EPT_MAX_NUM; i_index ++) - { - udev->ept_in[i_index].eptn = i_index; - udev->ept_in[i_index].ept_address = i_index; - udev->ept_in[i_index].inout = EPT_DIR_IN; - udev->ept_in[i_index].maxpacket = 0; - udev->ept_in[i_index].trans_buf = 0; - udev->ept_in[i_index].total_len = 0; - } +static void usb_ept_default_init(usbd_core_type *udev) { + uint8_t i_index = 0; + /* init in endpoint info structure */ + for (i_index = 0; i_index < USB_EPT_MAX_NUM; i_index ++) { + udev->ept_in[i_index].eptn = i_index; + udev->ept_in[i_index].ept_address = i_index; + udev->ept_in[i_index].inout = EPT_DIR_IN; + udev->ept_in[i_index].maxpacket = 0; + udev->ept_in[i_index].trans_buf = 0; + udev->ept_in[i_index].total_len = 0; + } - /* init out endpoint info structure */ - for(i_index = 0; i_index < USB_EPT_MAX_NUM; i_index ++) - { - udev->ept_out[i_index].eptn = i_index; - udev->ept_out[i_index].ept_address = i_index; - udev->ept_out[i_index].inout = EPT_DIR_OUT; - udev->ept_out[i_index].maxpacket = 0; - udev->ept_out[i_index].trans_buf = 0; - udev->ept_out[i_index].total_len = 0; - } + /* init out endpoint info structure */ + for (i_index = 0; i_index < USB_EPT_MAX_NUM; i_index ++) { + udev->ept_out[i_index].eptn = i_index; + udev->ept_out[i_index].ept_address = i_index; + udev->ept_out[i_index].inout = EPT_DIR_OUT; + udev->ept_out[i_index].maxpacket = 0; + udev->ept_out[i_index].trans_buf = 0; + udev->ept_out[i_index].total_len = 0; + } } /** @@ -452,98 +401,81 @@ static void usb_ept_default_init(usbd_core_type *udev) * @param len: send data length * @retval none */ -void usbd_ept_send(usbd_core_type *udev, uint8_t ept_addr, uint8_t *buffer, uint16_t len) -{ - /* get endpoint info struct and register */ - usb_reg_type *usbx = udev->usb_reg; - usb_ept_info *ept_info = &udev->ept_in[ept_addr & 0x7F]; - otg_eptin_type *ept_in = USB_INEPT(usbx, ept_info->eptn); - otg_device_type *dev = OTG_DEVICE(usbx); - uint32_t pktcnt; - - /* check endpoint fifo */ - usbd_ept_in_check_fifo(udev, ept_addr); - - /* set send data buffer and length */ - ept_info->trans_buf = buffer; - ept_info->total_len = len; - ept_info->trans_len = 0; +void usbd_ept_send(usbd_core_type *udev, uint8_t ept_addr, uint8_t *buffer, uint16_t len) { + /* get endpoint info struct and register */ + usb_reg_type *usbx = udev->usb_reg; + usb_ept_info *ept_info = &udev->ept_in[ept_addr & 0x7F]; + otg_eptin_type *ept_in = USB_INEPT(usbx, ept_info->eptn); + otg_device_type *dev = OTG_DEVICE(usbx); + uint32_t pktcnt; - /* transfer data len is zero */ - if(ept_info->total_len == 0) - { - ept_in->dieptsiz_bit.pktcnt = 1; - ept_in->dieptsiz_bit.xfersize = 0; - } - else - { - if((ept_addr & 0x7F) == 0) // endpoint 0 - { - /* endpoint 0 */ - if(ept_info->total_len > ept_info->maxpacket) - { - ept_info->total_len = ept_info->maxpacket; - } + /* check endpoint fifo */ + usbd_ept_in_check_fifo(udev, ept_addr); - /* set transfer size */ - ept_in->dieptsiz_bit.xfersize = ept_info->total_len; + /* set send data buffer and length */ + ept_info->trans_buf = buffer; + ept_info->total_len = len; + ept_info->trans_len = 0; - /* set packet count */ - ept_in->dieptsiz_bit.pktcnt = 1; + /* transfer data len is zero */ + if (ept_info->total_len == 0) { + ept_in->dieptsiz_bit.pktcnt = 1; + ept_in->dieptsiz_bit.xfersize = 0; + } else { + if ((ept_addr & 0x7F) == 0) { // endpoint 0 + /* endpoint 0 */ + if (ept_info->total_len > ept_info->maxpacket) { + ept_info->total_len = ept_info->maxpacket; + } - ept_info->last_len = ept_info->total_len; + /* set transfer size */ + ept_in->dieptsiz_bit.xfersize = ept_info->total_len; + + /* set packet count */ + ept_in->dieptsiz_bit.pktcnt = 1; + + ept_info->last_len = ept_info->total_len; + } else { + /* other endpoint */ + + /* packet count */ + pktcnt = (ept_info->total_len + ept_info->maxpacket - 1) / ept_info->maxpacket; + + /* set transfer size */ + ept_in->dieptsiz_bit.xfersize = ept_info->total_len; + + /* set packet count */ + ept_in->dieptsiz_bit.pktcnt = pktcnt; + + if (ept_info->trans_type == EPT_ISO_TYPE) { + ept_in->dieptsiz_bit.mc = 1; + } + } } - else - { - /* other endpoint */ - /* packet count */ - pktcnt = (ept_info->total_len + ept_info->maxpacket - 1) / ept_info->maxpacket; - - /* set transfer size */ - ept_in->dieptsiz_bit.xfersize = ept_info->total_len; - - /* set packet count */ - ept_in->dieptsiz_bit.pktcnt = pktcnt; - - if(ept_info->trans_type == EPT_ISO_TYPE) - { - ept_in->dieptsiz_bit.mc = 1; - } + if (ept_info->trans_type == EPT_ISO_TYPE) { + if ((dev->dsts_bit.soffn & 0x1) == 0) { + ept_in->diepctl_bit.setd1pid = TRUE; + } else { + ept_in->diepctl_bit.setd0pid = TRUE; + } } - } - if(ept_info->trans_type == EPT_ISO_TYPE) - { - if((dev->dsts_bit.soffn & 0x1) == 0) - { - ept_in->diepctl_bit.setd1pid = TRUE; + /* clear endpoint nak */ + ept_in->diepctl_bit.cnak = TRUE; + + /* endpoint enable */ + ept_in->diepctl_bit.eptena = TRUE; + + if (ept_info->trans_type != EPT_ISO_TYPE) { + if (ept_info->total_len > 0) { + /* set in endpoint tx fifo empty interrupt mask */ + dev->diepempmsk |= 1 << ept_info->eptn; + } + } else { + /* write data to fifo */ + usb_write_packet(usbx, ept_info->trans_buf, ept_info->eptn, ept_info->total_len); } - else - { - ept_in->diepctl_bit.setd0pid = TRUE; - } - } - - /* clear endpoint nak */ - ept_in->diepctl_bit.cnak = TRUE; - - /* endpoint enable */ - ept_in->diepctl_bit.eptena = TRUE; - - if(ept_info->trans_type != EPT_ISO_TYPE) - { - if(ept_info->total_len > 0) - { - /* set in endpoint tx fifo empty interrupt mask */ - dev->diepempmsk |= 1 << ept_info->eptn; - } - } - else - { - /* write data to fifo */ - usb_write_packet(usbx, ept_info->trans_buf, ept_info->eptn, ept_info->total_len); - } } /** @@ -554,62 +486,53 @@ void usbd_ept_send(usbd_core_type *udev, uint8_t ept_addr, uint8_t *buffer, uint * @param len: receive data length * @retval none */ -void usbd_ept_recv(usbd_core_type *udev, uint8_t ept_addr, uint8_t *buffer, uint16_t len) -{ - /* get endpoint info struct and register */ - usb_reg_type *usbx = udev->usb_reg; - usb_ept_info *ept_info = &udev->ept_out[ept_addr & 0x7F]; - otg_eptout_type *ept_out = USB_OUTEPT(usbx, ept_info->eptn); - otg_device_type *dev = OTG_DEVICE(usbx); - uint32_t pktcnt; +void usbd_ept_recv(usbd_core_type *udev, uint8_t ept_addr, uint8_t *buffer, uint16_t len) { + /* get endpoint info struct and register */ + usb_reg_type *usbx = udev->usb_reg; + usb_ept_info *ept_info = &udev->ept_out[ept_addr & 0x7F]; + otg_eptout_type *ept_out = USB_OUTEPT(usbx, ept_info->eptn); + otg_device_type *dev = OTG_DEVICE(usbx); + uint32_t pktcnt; - /* set receive data buffer and length */ - ept_info->trans_buf = buffer; - ept_info->total_len = len; - ept_info->trans_len = 0; + /* set receive data buffer and length */ + ept_info->trans_buf = buffer; + ept_info->total_len = len; + ept_info->trans_len = 0; - if((ept_addr & 0x7F) == 0) - { - /* endpoint 0 */ - ept_info->total_len = ept_info->maxpacket; - } + if ((ept_addr & 0x7F) == 0) { + /* endpoint 0 */ + ept_info->total_len = ept_info->maxpacket; + } - if(ept_info->total_len == 0 || ((ept_addr & 0x7F) == 0)) - { - /* set transfer size */ - ept_out->doeptsiz_bit.xfersize = ept_info->maxpacket; + if (ept_info->total_len == 0 || ((ept_addr & 0x7F) == 0)) { + /* set transfer size */ + ept_out->doeptsiz_bit.xfersize = ept_info->maxpacket; - /* set packet count */ - ept_out->doeptsiz_bit.pktcnt = 1; - } - else - { - pktcnt = (ept_info->total_len + ept_info->maxpacket - 1) / ept_info->maxpacket; + /* set packet count */ + ept_out->doeptsiz_bit.pktcnt = 1; + } else { + pktcnt = (ept_info->total_len + ept_info->maxpacket - 1) / ept_info->maxpacket; - /* set transfer size */ - ept_out->doeptsiz_bit.xfersize = ept_info->maxpacket * pktcnt; + /* set transfer size */ + ept_out->doeptsiz_bit.xfersize = ept_info->maxpacket * pktcnt; - /* set packet count */ - ept_out->doeptsiz_bit.pktcnt = pktcnt; - } + /* set packet count */ + ept_out->doeptsiz_bit.pktcnt = pktcnt; + } - if(ept_info->trans_type == EPT_ISO_TYPE) - { - if((dev->dsts_bit.soffn & 0x01) == 0) - { - ept_out->doepctl_bit.setd1pid = TRUE; - } - else - { - ept_out->doepctl_bit.setd0pid = TRUE; - } - } + if (ept_info->trans_type == EPT_ISO_TYPE) { + if ((dev->dsts_bit.soffn & 0x01) == 0) { + ept_out->doepctl_bit.setd1pid = TRUE; + } else { + ept_out->doepctl_bit.setd0pid = TRUE; + } + } - /* clear endpoint nak */ - ept_out->doepctl_bit.cnak = TRUE; + /* clear endpoint nak */ + ept_out->doepctl_bit.cnak = TRUE; - /* endpoint enable */ - ept_out->doepctl_bit.eptena = TRUE; + /* endpoint enable */ + ept_out->doepctl_bit.eptena = TRUE; } /** @@ -617,9 +540,8 @@ void usbd_ept_recv(usbd_core_type *udev, uint8_t ept_addr, uint8_t *buffer, uint * @param udev: to the structure of usbd_core_type * @retval usb connect state */ -usbd_conn_state usbd_connect_state_get(usbd_core_type *udev) -{ - return udev->conn_state; +usbd_conn_state usbd_connect_state_get(usbd_core_type *udev) { + return udev->conn_state; } /** @@ -627,26 +549,24 @@ usbd_conn_state usbd_connect_state_get(usbd_core_type *udev) * @param udev: to the structure of usbd_core_type * @retval none */ -void usbd_remote_wakeup(usbd_core_type *udev) -{ - /* check device is in suspend mode */ - if(usb_suspend_status_get(udev->usb_reg) == 1) - { - /* set connect state */ - udev->conn_state = udev->old_conn_state; +void usbd_remote_wakeup(usbd_core_type *udev) { + /* check device is in suspend mode */ + if (usb_suspend_status_get(udev->usb_reg) == 1) { + /* set connect state */ + udev->conn_state = udev->old_conn_state; - /* open phy clock */ - usb_open_phy_clk(udev->usb_reg); + /* open phy clock */ + usb_open_phy_clk(udev->usb_reg); - /* set remote wakeup */ - usb_remote_wkup_set(udev->usb_reg); + /* set remote wakeup */ + usb_remote_wkup_set(udev->usb_reg); - /* delay 10 ms */ - usb_delay_ms(10); + /* delay 10 ms */ + usb_delay_ms(10); - /* clear remote wakup */ - usb_remote_wkup_clear(udev->usb_reg); - } + /* clear remote wakup */ + usb_remote_wkup_clear(udev->usb_reg); + } } /** @@ -654,14 +574,12 @@ void usbd_remote_wakeup(usbd_core_type *udev) * @param udev: to the structure of usbd_core_type * @retval none */ -void usbd_enter_suspend(usbd_core_type *udev) -{ - /* check device is in suspend mode */ - if(usb_suspend_status_get(udev->usb_reg) == 1) - { - /* stop phy clk */ - usb_stop_phy_clk(udev->usb_reg); - } +void usbd_enter_suspend(usbd_core_type *udev) { + /* check device is in suspend mode */ + if (usb_suspend_status_get(udev->usb_reg) == 1) { + /* stop phy clk */ + usb_stop_phy_clk(udev->usb_reg); + } } /** @@ -670,10 +588,9 @@ void usbd_enter_suspend(usbd_core_type *udev) * @param ept_num: endpoint number * @retval none */ -void usbd_flush_tx_fifo(usbd_core_type *udev, uint8_t ept_num) -{ - /* flush endpoint tx fifo */ - usb_flush_tx_fifo(udev->usb_reg, ept_num & 0x1F); +void usbd_flush_tx_fifo(usbd_core_type *udev, uint8_t ept_num) { + /* flush endpoint tx fifo */ + usb_flush_tx_fifo(udev->usb_reg, ept_num & 0x1F); } /** @@ -681,75 +598,70 @@ void usbd_flush_tx_fifo(usbd_core_type *udev, uint8_t ept_num) * @param udev: to the structure of usbd_core_type * @retval none */ -void usbd_fifo_alloc(usbd_core_type *udev) -{ - usb_reg_type *usbx = udev->usb_reg; +void usbd_fifo_alloc(usbd_core_type *udev) { + usb_reg_type *usbx = udev->usb_reg; - if(usbx == OTG1_GLOBAL) - { - /* set receive fifo size */ - usb_set_rx_fifo(usbx, USBD_RX_SIZE); + if (usbx == OTG1_GLOBAL) { + /* set receive fifo size */ + usb_set_rx_fifo(usbx, USBD_RX_SIZE); - /* set endpoint0 tx fifo size */ - usb_set_tx_fifo(usbx, USB_EPT0, USBD_EP0_TX_SIZE); + /* set endpoint0 tx fifo size */ + usb_set_tx_fifo(usbx, USB_EPT0, USBD_EP0_TX_SIZE); - /* set endpoint1 tx fifo size */ - usb_set_tx_fifo(usbx, USB_EPT1, USBD_EP1_TX_SIZE); + /* set endpoint1 tx fifo size */ + usb_set_tx_fifo(usbx, USB_EPT1, USBD_EP1_TX_SIZE); - /* set endpoint2 tx fifo size */ - usb_set_tx_fifo(usbx, USB_EPT2, USBD_EP2_TX_SIZE); + /* set endpoint2 tx fifo size */ + usb_set_tx_fifo(usbx, USB_EPT2, USBD_EP2_TX_SIZE); - /* set endpoint3 tx fifo size */ - usb_set_tx_fifo(usbx, USB_EPT3, USBD_EP3_TX_SIZE); + /* set endpoint3 tx fifo size */ + usb_set_tx_fifo(usbx, USB_EPT3, USBD_EP3_TX_SIZE); - if(USB_EPT_MAX_NUM == 8) - { - /* set endpoint4 tx fifo size */ - usb_set_tx_fifo(usbx, USB_EPT4, USBD_EP4_TX_SIZE); + if (USB_EPT_MAX_NUM == 8) { + /* set endpoint4 tx fifo size */ + usb_set_tx_fifo(usbx, USB_EPT4, USBD_EP4_TX_SIZE); - /* set endpoint5 tx fifo size */ - usb_set_tx_fifo(usbx, USB_EPT5, USBD_EP5_TX_SIZE); + /* set endpoint5 tx fifo size */ + usb_set_tx_fifo(usbx, USB_EPT5, USBD_EP5_TX_SIZE); - /* set endpoint6 tx fifo size */ - usb_set_tx_fifo(usbx, USB_EPT6, USBD_EP6_TX_SIZE); + /* set endpoint6 tx fifo size */ + usb_set_tx_fifo(usbx, USB_EPT6, USBD_EP6_TX_SIZE); - /* set endpoint7 tx fifo size */ - usb_set_tx_fifo(usbx, USB_EPT7, USBD_EP7_TX_SIZE); + /* set endpoint7 tx fifo size */ + usb_set_tx_fifo(usbx, USB_EPT7, USBD_EP7_TX_SIZE); + } } - } #ifdef OTG2_GLOBAL - if(usbx == OTG2_GLOBAL) - { - /* set receive fifo size */ - usb_set_rx_fifo(usbx, USBD2_RX_SIZE); + if (usbx == OTG2_GLOBAL) { + /* set receive fifo size */ + usb_set_rx_fifo(usbx, USBD2_RX_SIZE); - /* set endpoint0 tx fifo size */ - usb_set_tx_fifo(usbx, USB_EPT0, USBD2_EP0_TX_SIZE); + /* set endpoint0 tx fifo size */ + usb_set_tx_fifo(usbx, USB_EPT0, USBD2_EP0_TX_SIZE); - /* set endpoint1 tx fifo size */ - usb_set_tx_fifo(usbx, USB_EPT1, USBD2_EP1_TX_SIZE); + /* set endpoint1 tx fifo size */ + usb_set_tx_fifo(usbx, USB_EPT1, USBD2_EP1_TX_SIZE); - /* set endpoint2 tx fifo size */ - usb_set_tx_fifo(usbx, USB_EPT2, USBD2_EP2_TX_SIZE); + /* set endpoint2 tx fifo size */ + usb_set_tx_fifo(usbx, USB_EPT2, USBD2_EP2_TX_SIZE); - /* set endpoint3 tx fifo size */ - usb_set_tx_fifo(usbx, USB_EPT3, USBD2_EP3_TX_SIZE); + /* set endpoint3 tx fifo size */ + usb_set_tx_fifo(usbx, USB_EPT3, USBD2_EP3_TX_SIZE); - if(USB_EPT_MAX_NUM == 8) - { - /* set endpoint4 tx fifo size */ - usb_set_tx_fifo(usbx, USB_EPT4, USBD2_EP4_TX_SIZE); + if (USB_EPT_MAX_NUM == 8) { + /* set endpoint4 tx fifo size */ + usb_set_tx_fifo(usbx, USB_EPT4, USBD2_EP4_TX_SIZE); - /* set endpoint5 tx fifo size */ - usb_set_tx_fifo(usbx, USB_EPT5, USBD2_EP5_TX_SIZE); + /* set endpoint5 tx fifo size */ + usb_set_tx_fifo(usbx, USB_EPT5, USBD2_EP5_TX_SIZE); - /* set endpoint6 tx fifo size */ - usb_set_tx_fifo(usbx, USB_EPT6, USBD2_EP6_TX_SIZE); + /* set endpoint6 tx fifo size */ + usb_set_tx_fifo(usbx, USB_EPT6, USBD2_EP6_TX_SIZE); - /* set endpoint7 tx fifo size */ - usb_set_tx_fifo(usbx, USB_EPT7, USBD2_EP7_TX_SIZE); + /* set endpoint7 tx fifo size */ + usb_set_tx_fifo(usbx, USB_EPT7, USBD2_EP7_TX_SIZE); + } } - } #endif } @@ -768,125 +680,115 @@ usb_sts_type usbd_core_init(usbd_core_type *udev, usb_reg_type *usb_reg, usbd_class_handler *class_handler, usbd_desc_handler *desc_handler, - uint8_t core_id) -{ - usb_reg_type *usbx; - otg_device_type *dev; - otg_eptin_type *ept_in; - otg_eptout_type *ept_out; - uint32_t i_index; + uint8_t core_id) { + usb_reg_type *usbx; + otg_device_type *dev; + otg_eptin_type *ept_in; + otg_eptout_type *ept_out; + uint32_t i_index; - udev->usb_reg = usb_reg; - usbx = usb_reg; - dev = OTG_DEVICE(usbx); + udev->usb_reg = usb_reg; + usbx = usb_reg; + dev = OTG_DEVICE(usbx); - /* set connect state */ - udev->conn_state = USB_CONN_STATE_DEFAULT; + /* set connect state */ + udev->conn_state = USB_CONN_STATE_DEFAULT; - /* device class config */ - udev->device_addr = 0; - udev->class_handler = class_handler; - udev->desc_handler = desc_handler; - /* set device disconnect */ - usbd_disconnect(udev); + /* device class config */ + udev->device_addr = 0; + udev->class_handler = class_handler; + udev->desc_handler = desc_handler; + /* set device disconnect */ + usbd_disconnect(udev); - /* set endpoint to default status */ - usb_ept_default_init(udev); + /* set endpoint to default status */ + usb_ept_default_init(udev); - /* disable usb global interrupt */ - usb_interrupt_disable(usbx); + /* disable usb global interrupt */ + usb_interrupt_disable(usbx); - /* init global register */ - usb_global_init(usbx); + /* init global register */ + usb_global_init(usbx); - /* set device mode */ - usb_global_set_mode(usbx, OTG_DEVICE_MODE); + /* set device mode */ + usb_global_set_mode(usbx, OTG_DEVICE_MODE); - /* open phy clock */ - usb_open_phy_clk(udev->usb_reg); + /* open phy clock */ + usb_open_phy_clk(udev->usb_reg); - /* set periodic frame interval */ - dev->dcfg_bit.perfrint = DCFG_PERFRINT_80; + /* set periodic frame interval */ + dev->dcfg_bit.perfrint = DCFG_PERFRINT_80; - /* set device speed to full-speed */ - dev->dcfg_bit.devspd = USB_DCFG_FULL_SPEED; + /* set device speed to full-speed */ + dev->dcfg_bit.devspd = USB_DCFG_FULL_SPEED; - /* flush all tx fifo */ - usb_flush_tx_fifo(usbx, 16); + /* flush all tx fifo */ + usb_flush_tx_fifo(usbx, 16); - /* flush share rx fifo */ - usb_flush_rx_fifo(usbx); + /* flush share rx fifo */ + usb_flush_rx_fifo(usbx); - /* clear all endpoint interrupt flag and mask */ - dev->daint = 0xFFFFFFFF; - dev->daintmsk = 0; - dev->diepmsk = 0; - dev->doepmsk = 0; + /* clear all endpoint interrupt flag and mask */ + dev->daint = 0xFFFFFFFF; + dev->daintmsk = 0; + dev->diepmsk = 0; + dev->doepmsk = 0; - for(i_index = 0; i_index < USB_EPT_MAX_NUM; i_index ++) - { - usbx->dieptxfn[i_index] = 0; - } - - /* endpoint fifo alloc */ - usbd_fifo_alloc(udev); - - /* disable all in endpoint */ - for(i_index = 0; i_index < USB_EPT_MAX_NUM; i_index ++) - { - ept_in = USB_INEPT(usbx, i_index); - if(ept_in->diepctl_bit.eptena) - { - ept_in->diepctl = 0; - ept_in->diepctl_bit.eptdis = TRUE; - ept_in->diepctl_bit.snak = TRUE; + for (i_index = 0; i_index < USB_EPT_MAX_NUM; i_index ++) { + usbx->dieptxfn[i_index] = 0; } - else - { - ept_in->diepctl = 0; + + /* endpoint fifo alloc */ + usbd_fifo_alloc(udev); + + /* disable all in endpoint */ + for (i_index = 0; i_index < USB_EPT_MAX_NUM; i_index ++) { + ept_in = USB_INEPT(usbx, i_index); + if (ept_in->diepctl_bit.eptena) { + ept_in->diepctl = 0; + ept_in->diepctl_bit.eptdis = TRUE; + ept_in->diepctl_bit.snak = TRUE; + } else { + ept_in->diepctl = 0; + } + ept_in->dieptsiz = 0; + ept_in->diepint = 0xFF; } - ept_in->dieptsiz = 0; - ept_in->diepint = 0xFF; - } - /* disable all out endpoint */ - for(i_index = 0; i_index < USB_EPT_MAX_NUM; i_index ++) - { - ept_out = USB_OUTEPT(usbx, i_index); - if(ept_out->doepctl_bit.eptena) - { - ept_out->doepctl = 0; - ept_out->doepctl_bit.eptdis = TRUE; - ept_out->doepctl_bit.snak = TRUE; + /* disable all out endpoint */ + for (i_index = 0; i_index < USB_EPT_MAX_NUM; i_index ++) { + ept_out = USB_OUTEPT(usbx, i_index); + if (ept_out->doepctl_bit.eptena) { + ept_out->doepctl = 0; + ept_out->doepctl_bit.eptdis = TRUE; + ept_out->doepctl_bit.snak = TRUE; + } else { + ept_out->doepctl = 0; + } + ept_out->doeptsiz = 0; + ept_out->doepint = 0xFF; } - else - { - ept_out->doepctl = 0; - } - ept_out->doeptsiz = 0; - ept_out->doepint = 0xFF; - } - dev->diepmsk_bit.txfifoudrmsk = TRUE; + dev->diepmsk_bit.txfifoudrmsk = TRUE; - /* clear global interrupt and mask */ - usbx->gintmsk = 0; - usbx->gintsts = 0xBFFFFFFF; + /* clear global interrupt and mask */ + usbx->gintmsk = 0; + usbx->gintsts = 0xBFFFFFFF; - /* enable global interrupt mask */ - usbx->gintmsk = USB_OTG_SOF_INT | USB_OTG_RXFLVL_INT | - USB_OTG_USBSUSP_INT | USB_OTG_USBRST_INT | - USB_OTG_ENUMDONE_INT | USB_OTG_IEPT_INT | - USB_OTG_OEPT_INT | USB_OTG_INCOMISOIN_INT | - USB_OTG_INCOMPIP_INCOMPISOOUT_INT | USB_OTG_WKUP_INT | - USB_OTG_OTGINT_INT; + /* enable global interrupt mask */ + usbx->gintmsk = USB_OTG_SOF_INT | USB_OTG_RXFLVL_INT | + USB_OTG_USBSUSP_INT | USB_OTG_USBRST_INT | + USB_OTG_ENUMDONE_INT | USB_OTG_IEPT_INT | + USB_OTG_OEPT_INT | USB_OTG_INCOMISOIN_INT | + USB_OTG_INCOMPIP_INCOMPISOOUT_INT | USB_OTG_WKUP_INT | + USB_OTG_OTGINT_INT; - /* usb connect */ - usbd_connect(udev); + /* usb connect */ + usbd_connect(udev); - /* enable global interrupt */ - usb_interrupt_enable(usbx); + /* enable global interrupt */ + usb_interrupt_enable(usbx); - return USB_OK; + return USB_OK; } diff --git a/armlib/at32_usb/usb_drivers/src/usbd_int.c b/armlib/at32_usb/usb_drivers/src/usbd_int.c index fe15df0cd..d80f70dbf 100644 --- a/armlib/at32_usb/usb_drivers/src/usbd_int.c +++ b/armlib/at32_usb/usb_drivers/src/usbd_int.c @@ -41,99 +41,85 @@ * @param otgdev: to the structure of otg_core_type * @retval none */ -void usbd_irq_handler(otg_core_type *otgdev) -{ - otg_global_type *usbx = otgdev->usb_reg; - usbd_core_type *udev = &otgdev->dev; - uint32_t intsts = usb_global_get_all_interrupt(usbx); +void usbd_irq_handler(otg_core_type *otgdev) { + otg_global_type *usbx = otgdev->usb_reg; + usbd_core_type *udev = &otgdev->dev; + uint32_t intsts = usb_global_get_all_interrupt(usbx); - /* check current device mode */ - if(usbx->gintsts_bit.curmode == 0) - { - /* mode mismatch interrupt */ - if(intsts & USB_OTG_MODEMIS_FLAG) - { - usb_global_clear_interrupt(usbx, USB_OTG_MODEMIS_FLAG); - } + /* check current device mode */ + if (usbx->gintsts_bit.curmode == 0) { + /* mode mismatch interrupt */ + if (intsts & USB_OTG_MODEMIS_FLAG) { + usb_global_clear_interrupt(usbx, USB_OTG_MODEMIS_FLAG); + } - /* in endpoint interrupt */ - if(intsts & USB_OTG_IEPT_FLAG) - { - usbd_inept_handler(udev); - } + /* in endpoint interrupt */ + if (intsts & USB_OTG_IEPT_FLAG) { + usbd_inept_handler(udev); + } - /* out endpoint interrupt */ - if(intsts & USB_OTG_OEPT_FLAG) - { - usbd_outept_handler(udev); - } + /* out endpoint interrupt */ + if (intsts & USB_OTG_OEPT_FLAG) { + usbd_outept_handler(udev); + } - /* usb reset interrupt */ - if(intsts & USB_OTG_USBRST_FLAG) - { - usbd_reset_handler(udev); - usb_global_clear_interrupt(usbx, USB_OTG_USBRST_FLAG); - } + /* usb reset interrupt */ + if (intsts & USB_OTG_USBRST_FLAG) { + usbd_reset_handler(udev); + usb_global_clear_interrupt(usbx, USB_OTG_USBRST_FLAG); + } - /* sof interrupt */ - if(intsts & USB_OTG_SOF_FLAG) - { - usbd_sof_handler(udev); - usb_global_clear_interrupt(usbx, USB_OTG_SOF_FLAG); - } + /* sof interrupt */ + if (intsts & USB_OTG_SOF_FLAG) { + usbd_sof_handler(udev); + usb_global_clear_interrupt(usbx, USB_OTG_SOF_FLAG); + } - /* enumeration done interrupt */ - if(intsts & USB_OTG_ENUMDONE_FLAG) - { - usbd_enumdone_handler(udev); - usb_global_clear_interrupt(usbx, USB_OTG_ENUMDONE_FLAG); - } + /* enumeration done interrupt */ + if (intsts & USB_OTG_ENUMDONE_FLAG) { + usbd_enumdone_handler(udev); + usb_global_clear_interrupt(usbx, USB_OTG_ENUMDONE_FLAG); + } - /* rx non-empty interrupt, indicates that there is at least one - data packet pending to be read in rx fifo */ - if(intsts & USB_OTG_RXFLVL_FLAG) - { - usbd_rxflvl_handler(udev); - } + /* rx non-empty interrupt, indicates that there is at least one + data packet pending to be read in rx fifo */ + if (intsts & USB_OTG_RXFLVL_FLAG) { + usbd_rxflvl_handler(udev); + } - /* incomplete isochronous in transfer interrupt */ - if(intsts & USB_OTG_INCOMISOIN_FLAG) - { - usbd_incomisioin_handler(udev); - usb_global_clear_interrupt(usbx, USB_OTG_INCOMISOIN_FLAG); - } - #ifndef USB_VBUS_IGNORE - /* disconnect detected interrupt */ - if(intsts & USB_OTG_OTGINT_FLAG) - { - uint32_t tmp = udev->usb_reg->gotgint; - if(udev->usb_reg->gotgint_bit.sesenddet) - usbd_discon_handler(udev); - udev->usb_reg->gotgint = tmp; - usb_global_clear_interrupt(usbx, USB_OTG_OTGINT_FLAG); - } + /* incomplete isochronous in transfer interrupt */ + if (intsts & USB_OTG_INCOMISOIN_FLAG) { + usbd_incomisioin_handler(udev); + usb_global_clear_interrupt(usbx, USB_OTG_INCOMISOIN_FLAG); + } +#ifndef USB_VBUS_IGNORE + /* disconnect detected interrupt */ + if (intsts & USB_OTG_OTGINT_FLAG) { + uint32_t tmp = udev->usb_reg->gotgint; + if (udev->usb_reg->gotgint_bit.sesenddet) + usbd_discon_handler(udev); + udev->usb_reg->gotgint = tmp; + usb_global_clear_interrupt(usbx, USB_OTG_OTGINT_FLAG); + } #endif - /* incomplete isochronous out transfer interrupt */ - if(intsts & USB_OTG_INCOMPIP_INCOMPISOOUT_FLAG) - { - usbd_incomisoout_handler(udev); - usb_global_clear_interrupt(usbx, USB_OTG_INCOMPIP_INCOMPISOOUT_FLAG); - } + /* incomplete isochronous out transfer interrupt */ + if (intsts & USB_OTG_INCOMPIP_INCOMPISOOUT_FLAG) { + usbd_incomisoout_handler(udev); + usb_global_clear_interrupt(usbx, USB_OTG_INCOMPIP_INCOMPISOOUT_FLAG); + } - /* resume/remote wakeup interrupt */ - if(intsts & USB_OTG_WKUP_FLAG) - { - usbd_wakeup_handler(udev); - usb_global_clear_interrupt(usbx, USB_OTG_WKUP_FLAG); - } + /* resume/remote wakeup interrupt */ + if (intsts & USB_OTG_WKUP_FLAG) { + usbd_wakeup_handler(udev); + usb_global_clear_interrupt(usbx, USB_OTG_WKUP_FLAG); + } - /* usb suspend interrupt */ - if(intsts & USB_OTG_USBSUSP_FLAG) - { - usbd_suspend_handler(udev); - usb_global_clear_interrupt(usbx, USB_OTG_USBSUSP_FLAG); + /* usb suspend interrupt */ + if (intsts & USB_OTG_USBSUSP_FLAG) { + usbd_suspend_handler(udev); + usb_global_clear_interrupt(usbx, USB_OTG_USBSUSP_FLAG); + } } - } } /** @@ -142,38 +128,33 @@ void usbd_irq_handler(otg_core_type *otgdev) * @param ept_num: endpoint number * @retval none */ -void usb_write_empty_txfifo(usbd_core_type *udev, uint32_t ept_num) -{ - otg_global_type *usbx = udev->usb_reg; - usb_ept_info *ept_info = &udev->ept_in[ept_num]; - uint32_t length = ept_info->total_len - ept_info->trans_len; - uint32_t wlen = 0; +void usb_write_empty_txfifo(usbd_core_type *udev, uint32_t ept_num) { + otg_global_type *usbx = udev->usb_reg; + usb_ept_info *ept_info = &udev->ept_in[ept_num]; + uint32_t length = ept_info->total_len - ept_info->trans_len; + uint32_t wlen = 0; - if(length > ept_info->maxpacket) - { - length = ept_info->maxpacket; - } - wlen = (length + 3) / 4; - - while((USB_INEPT(usbx, ept_num)->dtxfsts & USB_OTG_DTXFSTS_INEPTFSAV) > wlen && - (ept_info->trans_len < ept_info->total_len) && (ept_info->total_len != 0)) - { - length = ept_info->total_len - ept_info->trans_len; - if(length > ept_info->maxpacket) - { - length = ept_info->maxpacket; + if (length > ept_info->maxpacket) { + length = ept_info->maxpacket; } wlen = (length + 3) / 4; - usb_write_packet(usbx, ept_info->trans_buf, ept_num, length); - ept_info->trans_buf += length; - ept_info->trans_len += length; + while ((USB_INEPT(usbx, ept_num)->dtxfsts & USB_OTG_DTXFSTS_INEPTFSAV) > wlen && + (ept_info->trans_len < ept_info->total_len) && (ept_info->total_len != 0)) { + length = ept_info->total_len - ept_info->trans_len; + if (length > ept_info->maxpacket) { + length = ept_info->maxpacket; + } + wlen = (length + 3) / 4; + usb_write_packet(usbx, ept_info->trans_buf, ept_num, length); - } - if(length <= 0) - { - OTG_DEVICE(usbx)->diepempmsk &= ~(0x1 << ept_num); - } + ept_info->trans_buf += length; + ept_info->trans_len += length; + + } + if (length <= 0) { + OTG_DEVICE(usbx)->diepempmsk &= ~(0x1 << ept_num); + } } @@ -182,62 +163,53 @@ void usb_write_empty_txfifo(usbd_core_type *udev, uint32_t ept_num) * @param udev: to the structure of usbd_core_type * @retval none */ -void usbd_inept_handler(usbd_core_type *udev) -{ - otg_global_type *usbx = udev->usb_reg; - uint32_t ept_num = 0, ept_int; - uint32_t intsts; +void usbd_inept_handler(usbd_core_type *udev) { + otg_global_type *usbx = udev->usb_reg; + uint32_t ept_num = 0, ept_int; + uint32_t intsts; - /*get all endpoint interrut */ - intsts = usb_get_all_in_interrupt(usbx); - while(intsts) - { - if(intsts & 0x1) - { - /* get endpoint interrupt flag */ - ept_int = usb_ept_in_interrupt(usbx, ept_num); + /*get all endpoint interrut */ + intsts = usb_get_all_in_interrupt(usbx); + while (intsts) { + if (intsts & 0x1) { + /* get endpoint interrupt flag */ + ept_int = usb_ept_in_interrupt(usbx, ept_num); - /* transfer completed interrupt */ - if(ept_int & USB_OTG_DIEPINT_XFERC_FLAG) - { - OTG_DEVICE(usbx)->diepempmsk &= ~(1 << ept_num); - usb_ept_in_clear(usbx, ept_num , USB_OTG_DIEPINT_XFERC_FLAG); - usbd_core_in_handler(udev, ept_num); - } + /* transfer completed interrupt */ + if (ept_int & USB_OTG_DIEPINT_XFERC_FLAG) { + OTG_DEVICE(usbx)->diepempmsk &= ~(1 << ept_num); + usb_ept_in_clear(usbx, ept_num, USB_OTG_DIEPINT_XFERC_FLAG); + usbd_core_in_handler(udev, ept_num); + } - /* timeout condition interrupt */ - if(ept_int & USB_OTG_DIEPINT_TIMEOUT_FLAG) - { - usb_ept_in_clear(usbx, ept_num , USB_OTG_DIEPINT_TIMEOUT_FLAG); - } + /* timeout condition interrupt */ + if (ept_int & USB_OTG_DIEPINT_TIMEOUT_FLAG) { + usb_ept_in_clear(usbx, ept_num, USB_OTG_DIEPINT_TIMEOUT_FLAG); + } - /* in token received when tx fifo is empty */ - if(ept_int & USB_OTG_DIEPINT_INTKNTXFEMP_FLAG) - { - usb_ept_in_clear(usbx, ept_num , USB_OTG_DIEPINT_INTKNTXFEMP_FLAG); - } + /* in token received when tx fifo is empty */ + if (ept_int & USB_OTG_DIEPINT_INTKNTXFEMP_FLAG) { + usb_ept_in_clear(usbx, ept_num, USB_OTG_DIEPINT_INTKNTXFEMP_FLAG); + } - /* in endpoint nak effective */ - if(ept_int & USB_OTG_DIEPINT_INEPTNAK_FLAG) - { - usb_ept_in_clear(usbx, ept_num , USB_OTG_DIEPINT_INEPTNAK_FLAG); - } + /* in endpoint nak effective */ + if (ept_int & USB_OTG_DIEPINT_INEPTNAK_FLAG) { + usb_ept_in_clear(usbx, ept_num, USB_OTG_DIEPINT_INEPTNAK_FLAG); + } - /* endpoint disable interrupt */ - if(ept_int & USB_OTG_DIEPINT_EPTDISD_FLAG) - { - usb_ept_in_clear(usbx, ept_num , USB_OTG_DIEPINT_EPTDISD_FLAG); - } + /* endpoint disable interrupt */ + if (ept_int & USB_OTG_DIEPINT_EPTDISD_FLAG) { + usb_ept_in_clear(usbx, ept_num, USB_OTG_DIEPINT_EPTDISD_FLAG); + } - /* transmit fifo empty interrupt */ - if(ept_int & USB_OTG_DIEPINT_TXFEMP_FLAG) - { - usb_write_empty_txfifo(udev, ept_num); - } + /* transmit fifo empty interrupt */ + if (ept_int & USB_OTG_DIEPINT_TXFEMP_FLAG) { + usb_write_empty_txfifo(udev, ept_num); + } + } + ept_num ++; + intsts >>= 1; } - ept_num ++; - intsts >>= 1; - } } /** @@ -245,50 +217,43 @@ void usbd_inept_handler(usbd_core_type *udev) * @param udev: to the structure of usbd_core_type * @retval none */ -void usbd_outept_handler(usbd_core_type *udev) -{ - otg_global_type *usbx = udev->usb_reg; - uint32_t ept_num = 0, ept_int; - uint32_t intsts; +void usbd_outept_handler(usbd_core_type *udev) { + otg_global_type *usbx = udev->usb_reg; + uint32_t ept_num = 0, ept_int; + uint32_t intsts; - /* get all out endpoint interrupt */ - intsts = usb_get_all_out_interrupt(usbx); + /* get all out endpoint interrupt */ + intsts = usb_get_all_out_interrupt(usbx); - while(intsts) - { - if(intsts & 0x1) - { - /* get out endpoint interrupt */ - ept_int = usb_ept_out_interrupt(usbx, ept_num); + while (intsts) { + if (intsts & 0x1) { + /* get out endpoint interrupt */ + ept_int = usb_ept_out_interrupt(usbx, ept_num); - /* transfer completed interrupt */ - if(ept_int & USB_OTG_DOEPINT_XFERC_FLAG) - { - usb_ept_out_clear(usbx, ept_num , USB_OTG_DOEPINT_XFERC_FLAG); - usbd_core_out_handler(udev, ept_num); - } + /* transfer completed interrupt */ + if (ept_int & USB_OTG_DOEPINT_XFERC_FLAG) { + usb_ept_out_clear(usbx, ept_num, USB_OTG_DOEPINT_XFERC_FLAG); + usbd_core_out_handler(udev, ept_num); + } - /* setup phase done interrupt */ - if(ept_int & USB_OTG_DOEPINT_SETUP_FLAG) - { - usb_ept_out_clear(usbx, ept_num , USB_OTG_DOEPINT_SETUP_FLAG); - usbd_core_setup_handler(udev, ept_num); - if(udev->device_addr != 0) - { - OTG_DEVICE(udev->usb_reg)->dcfg_bit.devaddr = udev->device_addr; - udev->device_addr = 0; + /* setup phase done interrupt */ + if (ept_int & USB_OTG_DOEPINT_SETUP_FLAG) { + usb_ept_out_clear(usbx, ept_num, USB_OTG_DOEPINT_SETUP_FLAG); + usbd_core_setup_handler(udev, ept_num); + if (udev->device_addr != 0) { + OTG_DEVICE(udev->usb_reg)->dcfg_bit.devaddr = udev->device_addr; + udev->device_addr = 0; + } + } + + /* endpoint disable interrupt */ + if (ept_int & USB_OTG_DOEPINT_OUTTEPD_FLAG) { + usb_ept_out_clear(usbx, ept_num, USB_OTG_DOEPINT_OUTTEPD_FLAG); + } } - } - - /* endpoint disable interrupt */ - if(ept_int & USB_OTG_DOEPINT_OUTTEPD_FLAG) - { - usb_ept_out_clear(usbx, ept_num , USB_OTG_DOEPINT_OUTTEPD_FLAG); - } + ept_num ++; + intsts >>= 1; } - ept_num ++; - intsts >>= 1; - } } /** @@ -296,26 +261,25 @@ void usbd_outept_handler(usbd_core_type *udev) * @param udev: to the structure of usbd_core_type * @retval none */ -void usbd_enumdone_handler(usbd_core_type *udev) -{ - otg_global_type *usbx = udev->usb_reg; +void usbd_enumdone_handler(usbd_core_type *udev) { + otg_global_type *usbx = udev->usb_reg; - usb_ept0_setup(usbx); + usb_ept0_setup(usbx); - usbx->gusbcfg_bit.usbtrdtim = USB_TRDTIM_16; + usbx->gusbcfg_bit.usbtrdtim = USB_TRDTIM_16; - /* open endpoint 0 out */ - usbd_ept_open(udev, 0x00, EPT_CONTROL_TYPE, 0x40); + /* open endpoint 0 out */ + usbd_ept_open(udev, 0x00, EPT_CONTROL_TYPE, 0x40); - /* open endpoint 0 in */ - usbd_ept_open(udev, 0x80, EPT_CONTROL_TYPE, 0x40); + /* open endpoint 0 in */ + usbd_ept_open(udev, 0x80, EPT_CONTROL_TYPE, 0x40); - /* usb connect state set to default */ - udev->conn_state = USB_CONN_STATE_DEFAULT; + /* usb connect state set to default */ + udev->conn_state = USB_CONN_STATE_DEFAULT; - /* clear callback */ - if(udev->class_handler->clear_handler != 0) - udev->class_handler->clear_handler(udev); + /* clear callback */ + if (udev->class_handler->clear_handler != 0) + udev->class_handler->clear_handler(udev); } /** @@ -323,51 +287,47 @@ void usbd_enumdone_handler(usbd_core_type *udev) * @param udev: to the structure of usbd_core_type * @retval none */ -void usbd_rxflvl_handler(usbd_core_type *udev) -{ - otg_global_type *usbx = udev->usb_reg; - uint32_t stsp; - uint32_t count; - uint32_t pktsts; - usb_ept_info *ept_info; +void usbd_rxflvl_handler(usbd_core_type *udev) { + otg_global_type *usbx = udev->usb_reg; + uint32_t stsp; + uint32_t count; + uint32_t pktsts; + usb_ept_info *ept_info; - /* disable rxflvl interrupt */ - usb_global_interrupt_enable(usbx, USB_OTG_RXFLVL_INT, FALSE); + /* disable rxflvl interrupt */ + usb_global_interrupt_enable(usbx, USB_OTG_RXFLVL_INT, FALSE); - /* get rx status */ - stsp = usbx->grxstsp; + /* get rx status */ + stsp = usbx->grxstsp; - /*get the byte count of receive */ - count = (stsp & USB_OTG_GRXSTSP_BCNT) >> 4; + /*get the byte count of receive */ + count = (stsp & USB_OTG_GRXSTSP_BCNT) >> 4; - /* get packet status */ - pktsts = (stsp &USB_OTG_GRXSTSP_PKTSTS) >> 17; + /* get packet status */ + pktsts = (stsp & USB_OTG_GRXSTSP_PKTSTS) >> 17; - /* get endpoint infomation struct */ - ept_info = &udev->ept_out[stsp & USB_OTG_GRXSTSP_EPTNUM]; + /* get endpoint infomation struct */ + ept_info = &udev->ept_out[stsp & USB_OTG_GRXSTSP_EPTNUM]; - /* received out data packet */ - if(pktsts == USB_OUT_STS_DATA) - { - if(count != 0) - { - /* read packet to buffer */ - usb_read_packet(usbx, ept_info->trans_buf, (stsp & USB_OTG_GRXSTSP_EPTNUM), count); - ept_info->trans_buf += count; - ept_info->trans_len += count; + /* received out data packet */ + if (pktsts == USB_OUT_STS_DATA) { + if (count != 0) { + /* read packet to buffer */ + usb_read_packet(usbx, ept_info->trans_buf, (stsp & USB_OTG_GRXSTSP_EPTNUM), count); + ept_info->trans_buf += count; + ept_info->trans_len += count; + } + } + /* setup data received */ + else if (pktsts == USB_SETUP_STS_DATA) { + /* read packet to buffer */ + usb_read_packet(usbx, udev->setup_buffer, (stsp & USB_OTG_GRXSTSP_EPTNUM), count); + ept_info->trans_len += count; } - } - /* setup data received */ - else if ( pktsts == USB_SETUP_STS_DATA) - { - /* read packet to buffer */ - usb_read_packet(usbx, udev->setup_buffer, (stsp & USB_OTG_GRXSTSP_EPTNUM), count); - ept_info->trans_len += count; - } - /* enable rxflvl interrupt */ - usb_global_interrupt_enable(usbx, USB_OTG_RXFLVL_INT, TRUE); + /* enable rxflvl interrupt */ + usb_global_interrupt_enable(usbx, USB_OTG_RXFLVL_INT, TRUE); } @@ -376,11 +336,10 @@ void usbd_rxflvl_handler(usbd_core_type *udev) * @param udev: to the structure of usbd_core_type * @retval none */ -void usbd_discon_handler(usbd_core_type *udev) -{ - /* disconnect callback handler */ - if(udev->class_handler->event_handler != 0) - udev->class_handler->event_handler(udev, USBD_DISCONNECT_EVNET); +void usbd_discon_handler(usbd_core_type *udev) { + /* disconnect callback handler */ + if (udev->class_handler->event_handler != 0) + udev->class_handler->event_handler(udev, USBD_DISCONNECT_EVNET); } @@ -389,10 +348,9 @@ void usbd_discon_handler(usbd_core_type *udev) * @param udev: to the structure of usbd_core_type * @retval none */ -void usbd_incomisoout_handler(usbd_core_type *udev) -{ - if(udev->class_handler->event_handler != 0) - udev->class_handler->event_handler(udev, USBD_OUTISOINCOM_EVENT); +void usbd_incomisoout_handler(usbd_core_type *udev) { + if (udev->class_handler->event_handler != 0) + udev->class_handler->event_handler(udev, USBD_OUTISOINCOM_EVENT); } /** @@ -400,10 +358,9 @@ void usbd_incomisoout_handler(usbd_core_type *udev) * @param udev: to the structure of usbd_core_type * @retval none */ -void usbd_incomisioin_handler(usbd_core_type *udev) -{ - if(udev->class_handler->event_handler != 0) - udev->class_handler->event_handler(udev, USBD_INISOINCOM_EVENT); +void usbd_incomisioin_handler(usbd_core_type *udev) { + if (udev->class_handler->event_handler != 0) + udev->class_handler->event_handler(udev, USBD_INISOINCOM_EVENT); } /** @@ -411,60 +368,58 @@ void usbd_incomisioin_handler(usbd_core_type *udev) * @param udev: to the structure of usbd_core_type * @retval none */ -void usbd_reset_handler(usbd_core_type *udev) -{ - otg_global_type *usbx = udev->usb_reg; - otg_device_type *dev = OTG_DEVICE(usbx); - uint32_t i_index = 0; +void usbd_reset_handler(usbd_core_type *udev) { + otg_global_type *usbx = udev->usb_reg; + otg_device_type *dev = OTG_DEVICE(usbx); + uint32_t i_index = 0; - /* disable remote wakeup singal */ - dev->dctl_bit.rwkupsig = FALSE; + /* disable remote wakeup singal */ + dev->dctl_bit.rwkupsig = FALSE; - /* endpoint fifo alloc */ - usbd_fifo_alloc(udev); + /* endpoint fifo alloc */ + usbd_fifo_alloc(udev); - /* flush all tx fifo */ - usb_flush_tx_fifo(usbx, 0x10); + /* flush all tx fifo */ + usb_flush_tx_fifo(usbx, 0x10); - /* clear in and out endpoint interrupt flag */ - for(i_index = 0; i_index < USB_EPT_MAX_NUM; i_index ++) - { - USB_INEPT(usbx, i_index)->diepint = 0xFFFF; - USB_INEPT(usbx, i_index)->diepctl_bit.stall = FALSE; - USB_INEPT(usbx, i_index)->diepctl_bit.snak = TRUE; - USB_OUTEPT(usbx, i_index)->doepint = 0xFFFF; - USB_OUTEPT(usbx, i_index)->doepctl_bit.stall = FALSE; - USB_OUTEPT(usbx, i_index)->doepctl_bit.snak = TRUE; - } + /* clear in and out endpoint interrupt flag */ + for (i_index = 0; i_index < USB_EPT_MAX_NUM; i_index ++) { + USB_INEPT(usbx, i_index)->diepint = 0xFFFF; + USB_INEPT(usbx, i_index)->diepctl_bit.stall = FALSE; + USB_INEPT(usbx, i_index)->diepctl_bit.snak = TRUE; + USB_OUTEPT(usbx, i_index)->doepint = 0xFFFF; + USB_OUTEPT(usbx, i_index)->doepctl_bit.stall = FALSE; + USB_OUTEPT(usbx, i_index)->doepctl_bit.snak = TRUE; + } - /* clear endpoint flag */ - dev->daint = 0xFFFFFFFF; + /* clear endpoint flag */ + dev->daint = 0xFFFFFFFF; - /*clear endpoint interrupt mask */ - dev->daintmsk = 0x10001; + /*clear endpoint interrupt mask */ + dev->daintmsk = 0x10001; - /* enable out endpoint xfer, eptdis, setup interrupt mask */ - dev->doepmsk_bit.xfercmsk = TRUE; - dev->doepmsk_bit.eptdismsk = TRUE; - dev->doepmsk_bit.setupmsk = TRUE; + /* enable out endpoint xfer, eptdis, setup interrupt mask */ + dev->doepmsk_bit.xfercmsk = TRUE; + dev->doepmsk_bit.eptdismsk = TRUE; + dev->doepmsk_bit.setupmsk = TRUE; - /* enable in endpoint xfer, eptdis, timeout interrupt mask */ - dev->diepmsk_bit.xfercmsk = TRUE; - dev->diepmsk_bit.eptdismsk = TRUE; - dev->diepmsk_bit.timeoutmsk = TRUE; + /* enable in endpoint xfer, eptdis, timeout interrupt mask */ + dev->diepmsk_bit.xfercmsk = TRUE; + dev->diepmsk_bit.eptdismsk = TRUE; + dev->diepmsk_bit.timeoutmsk = TRUE; - /* set device address to 0 */ - usb_set_address(usbx, 0); + /* set device address to 0 */ + usb_set_address(usbx, 0); - /* enable endpoint 0 */ - usb_ept0_start(usbx); + /* enable endpoint 0 */ + usb_ept0_start(usbx); - /* usb connect state set to default */ - udev->conn_state = USB_CONN_STATE_DEFAULT; + /* usb connect state set to default */ + udev->conn_state = USB_CONN_STATE_DEFAULT; - /* user define reset event */ - if(udev->class_handler->event_handler) - udev->class_handler->event_handler(udev, USBD_RESET_EVENT); + /* user define reset event */ + if (udev->class_handler->event_handler) + udev->class_handler->event_handler(udev, USBD_RESET_EVENT); } /** @@ -472,11 +427,10 @@ void usbd_reset_handler(usbd_core_type *udev) * @param udev: to the structure of usbd_core_type * @retval none */ -void usbd_sof_handler(usbd_core_type *udev) -{ - /* user sof handler in class define */ - if(udev->class_handler->sof_handler) - udev->class_handler->sof_handler(udev); +void usbd_sof_handler(usbd_core_type *udev) { + /* user sof handler in class define */ + if (udev->class_handler->sof_handler) + udev->class_handler->sof_handler(udev); } /** @@ -484,25 +438,23 @@ void usbd_sof_handler(usbd_core_type *udev) * @param udev: to the structure of usbd_core_type * @retval none */ -void usbd_suspend_handler(usbd_core_type *udev) -{ - otg_global_type *usbx = udev->usb_reg; +void usbd_suspend_handler(usbd_core_type *udev) { + otg_global_type *usbx = udev->usb_reg; - if(OTG_DEVICE(usbx)->dsts_bit.suspsts) - { - /* save connect state */ - udev->old_conn_state = udev->conn_state; + if (OTG_DEVICE(usbx)->dsts_bit.suspsts) { + /* save connect state */ + udev->old_conn_state = udev->conn_state; - /* set current state to suspend */ - udev->conn_state = USB_CONN_STATE_SUSPENDED; + /* set current state to suspend */ + udev->conn_state = USB_CONN_STATE_SUSPENDED; - /* enter suspend mode */ - usbd_enter_suspend(udev); + /* enter suspend mode */ + usbd_enter_suspend(udev); - /* user suspend handler */ - if(udev->class_handler->event_handler != 0) - udev->class_handler->event_handler(udev, USBD_SUSPEND_EVENT); - } + /* user suspend handler */ + if (udev->class_handler->event_handler != 0) + udev->class_handler->event_handler(udev, USBD_SUSPEND_EVENT); + } } /** @@ -510,22 +462,21 @@ void usbd_suspend_handler(usbd_core_type *udev) * @param udev: to the structure of usbd_core_type * @retval none */ -void usbd_wakeup_handler(usbd_core_type *udev) -{ - otg_global_type *usbx = udev->usb_reg; +void usbd_wakeup_handler(usbd_core_type *udev) { + otg_global_type *usbx = udev->usb_reg; - /* clear remote wakeup bit */ - OTG_DEVICE(usbx)->dctl_bit.rwkupsig = FALSE; + /* clear remote wakeup bit */ + OTG_DEVICE(usbx)->dctl_bit.rwkupsig = FALSE; - /* exit suspend mode */ - usb_open_phy_clk(udev->usb_reg); + /* exit suspend mode */ + usb_open_phy_clk(udev->usb_reg); - /* restore connect state */ - udev->conn_state = udev->old_conn_state; + /* restore connect state */ + udev->conn_state = udev->old_conn_state; /* user suspend handler */ - if(udev->class_handler->event_handler != 0) - udev->class_handler->event_handler(udev, USBD_WAKEUP_EVENT); + if (udev->class_handler->event_handler != 0) + udev->class_handler->event_handler(udev, USBD_WAKEUP_EVENT); } /** * @} diff --git a/armlib/at32_usb/usb_drivers/src/usbd_sdr.c b/armlib/at32_usb/usb_drivers/src/usbd_sdr.c index 534b2e074..0071376a6 100644 --- a/armlib/at32_usb/usb_drivers/src/usbd_sdr.c +++ b/armlib/at32_usb/usb_drivers/src/usbd_sdr.c @@ -50,13 +50,12 @@ static usb_sts_type usbd_set_configuration(usbd_core_type *udev); * @param buf: setup buffer * @retval none */ -void usbd_setup_request_parse(usb_setup_type *setup, uint8_t *buf) -{ - setup->bmRequestType = *(uint8_t *) buf; - setup->bRequest = *(uint8_t *) (buf + 1); - setup->wValue = SWAPBYTE(buf + 2); - setup->wIndex = SWAPBYTE(buf + 4); - setup->wLength = SWAPBYTE(buf + 6); +void usbd_setup_request_parse(usb_setup_type *setup, uint8_t *buf) { + setup->bmRequestType = *(uint8_t *) buf; + setup->bRequest = *(uint8_t *)(buf + 1); + setup->wValue = SWAPBYTE(buf + 2); + setup->wIndex = SWAPBYTE(buf + 4); + setup->wLength = SWAPBYTE(buf + 6); } /** @@ -64,83 +63,74 @@ void usbd_setup_request_parse(usb_setup_type *setup, uint8_t *buf) * @param udev: to the structure of usbd_core_type * @retval status of usb_sts_type */ -static usb_sts_type usbd_get_descriptor(usbd_core_type *udev) -{ - usb_sts_type ret = USB_OK; - uint16_t len = 0; - usbd_desc_t *desc = NULL; - uint8_t desc_type = udev->setup.wValue >> 8; - switch(desc_type) - { - case USB_DESCIPTOR_TYPE_DEVICE: - desc = udev->desc_handler->get_device_descriptor(); - break; - case USB_DESCIPTOR_TYPE_CONFIGURATION: - desc = udev->desc_handler->get_device_configuration(); - break; - case USB_DESCIPTOR_TYPE_STRING: - { - uint8_t str_desc = (uint8_t)udev->setup.wValue; - switch(str_desc) - { - case USB_LANGID_STRING: - desc = udev->desc_handler->get_device_lang_id(); - break; - case USB_MFC_STRING: - desc = udev->desc_handler->get_device_manufacturer_string(); - break; - case USB_PRODUCT_STRING: - desc = udev->desc_handler->get_device_product_string(); - break; - case USB_SERIAL_STRING: - desc = udev->desc_handler->get_device_serial_string(); - break; - case USB_CONFIG_STRING: - desc = udev->desc_handler->get_device_config_string(); - break; - case USB_INTERFACE_STRING: - desc = udev->desc_handler->get_device_interface_string(); - break; - case USB_WINUSB_OS_STRING: +static usb_sts_type usbd_get_descriptor(usbd_core_type *udev) { + usb_sts_type ret = USB_OK; + uint16_t len = 0; + usbd_desc_t *desc = NULL; + uint8_t desc_type = udev->setup.wValue >> 8; + switch (desc_type) { + case USB_DESCIPTOR_TYPE_DEVICE: + desc = udev->desc_handler->get_device_descriptor(); + break; + case USB_DESCIPTOR_TYPE_CONFIGURATION: + desc = udev->desc_handler->get_device_configuration(); + break; + case USB_DESCIPTOR_TYPE_STRING: { + uint8_t str_desc = (uint8_t)udev->setup.wValue; + switch (str_desc) { + case USB_LANGID_STRING: + desc = udev->desc_handler->get_device_lang_id(); + break; + case USB_MFC_STRING: + desc = udev->desc_handler->get_device_manufacturer_string(); + break; + case USB_PRODUCT_STRING: + desc = udev->desc_handler->get_device_product_string(); + break; + case USB_SERIAL_STRING: + desc = udev->desc_handler->get_device_serial_string(); + break; + case USB_CONFIG_STRING: + desc = udev->desc_handler->get_device_config_string(); + break; + case USB_INTERFACE_STRING: + desc = udev->desc_handler->get_device_interface_string(); + break; + case USB_WINUSB_OS_STRING: #if (USBD_SUPPORT_WINUSB == 1) - if(udev->desc_handler->get_device_winusb_os_string != NULL) - { - desc = udev->desc_handler->get_device_winusb_os_string(); - } - else - { - usbd_ctrl_unsupport(udev); - } + if (udev->desc_handler->get_device_winusb_os_string != NULL) { + desc = udev->desc_handler->get_device_winusb_os_string(); + } else { + usbd_ctrl_unsupport(udev); + } #else - usbd_ctrl_unsupport(udev); + usbd_ctrl_unsupport(udev); #endif - break; + break; + default: + udev->class_handler->setup_handler(udev, &udev->setup); + return ret; + } + break; + } + case USB_DESCIPTOR_TYPE_DEVICE_QUALIFIER: + usbd_ctrl_unsupport(udev); + break; + case USB_DESCIPTOR_TYPE_OTHER_SPEED: + usbd_ctrl_unsupport(udev); + return ret; default: - udev->class_handler->setup_handler(udev, &udev->setup); - return ret; - } - break; + usbd_ctrl_unsupport(udev); + return ret; } - case USB_DESCIPTOR_TYPE_DEVICE_QUALIFIER: - usbd_ctrl_unsupport(udev); - break; - case USB_DESCIPTOR_TYPE_OTHER_SPEED: - usbd_ctrl_unsupport(udev); - return ret; - default: - usbd_ctrl_unsupport(udev); - return ret; - } - if(desc != NULL) - { - if((desc->length != 0) && (udev->setup.wLength != 0)) - { - len = MIN(desc->length , udev->setup.wLength); - usbd_ctrl_send(udev, desc->descriptor, len); + if (desc != NULL) { + if ((desc->length != 0) && (udev->setup.wLength != 0)) { + len = MIN(desc->length, udev->setup.wLength); + usbd_ctrl_send(udev, desc->descriptor, len); + } } - } - return ret; + return ret; } /** @@ -148,46 +138,36 @@ static usb_sts_type usbd_get_descriptor(usbd_core_type *udev) * @param udev: to the structure of usbd_core_type * @retval status of usb_sts_type */ -static usb_sts_type usbd_set_address(usbd_core_type *udev) -{ - usb_sts_type ret = USB_OK; - usb_setup_type *setup = &udev->setup; - uint8_t dev_addr; +static usb_sts_type usbd_set_address(usbd_core_type *udev) { + usb_sts_type ret = USB_OK; + usb_setup_type *setup = &udev->setup; + uint8_t dev_addr; - /* if wIndex or wLength are non-zero, then the behavior of - the device is not specified - */ - if(setup->wIndex == 0 && setup->wLength == 0) - { - dev_addr = (uint8_t)(setup->wValue) & 0x7f; + /* if wIndex or wLength are non-zero, then the behavior of + the device is not specified + */ + if (setup->wIndex == 0 && setup->wLength == 0) { + dev_addr = (uint8_t)(setup->wValue) & 0x7f; - /* device behavior when this request is received - while the device is in the configured state is not specified.*/ - if(udev->conn_state == USB_CONN_STATE_CONFIGURED ) - { - usbd_ctrl_unsupport(udev); + /* device behavior when this request is received + while the device is in the configured state is not specified.*/ + if (udev->conn_state == USB_CONN_STATE_CONFIGURED) { + usbd_ctrl_unsupport(udev); + } else { + udev->device_addr = dev_addr; + usbd_set_device_addr(udev, udev->device_addr); + + if (dev_addr != 0) { + udev->conn_state = USB_CONN_STATE_ADDRESSED; + } else { + udev->conn_state = USB_CONN_STATE_DEFAULT; + } + usbd_ctrl_send_status(udev); + } + } else { + usbd_ctrl_unsupport(udev); } - else - { - udev->device_addr = dev_addr; - usbd_set_device_addr(udev, udev->device_addr); - - if(dev_addr != 0) - { - udev->conn_state = USB_CONN_STATE_ADDRESSED; - } - else - { - udev->conn_state = USB_CONN_STATE_DEFAULT; - } - usbd_ctrl_send_status(udev); - } - } - else - { - usbd_ctrl_unsupport(udev); - } - return ret; + return ret; } /** @@ -195,24 +175,21 @@ static usb_sts_type usbd_set_address(usbd_core_type *udev) * @param udev: to the structure of usbd_core_type * @retval status of usb_sts_type */ -static usb_sts_type usbd_get_status(usbd_core_type *udev) -{ - usb_sts_type ret = USB_OK; - switch(udev->conn_state) - { - case USB_CONN_STATE_ADDRESSED: - case USB_CONN_STATE_CONFIGURED: - if(udev->remote_wakup) - { - udev->config_status |= USB_CONF_REMOTE_WAKEUP; - } - usbd_ctrl_send(udev, (uint8_t *)(&udev->config_status), 2); - break; - default: - usbd_ctrl_unsupport(udev); - break; - } - return ret; +static usb_sts_type usbd_get_status(usbd_core_type *udev) { + usb_sts_type ret = USB_OK; + switch (udev->conn_state) { + case USB_CONN_STATE_ADDRESSED: + case USB_CONN_STATE_CONFIGURED: + if (udev->remote_wakup) { + udev->config_status |= USB_CONF_REMOTE_WAKEUP; + } + usbd_ctrl_send(udev, (uint8_t *)(&udev->config_status), 2); + break; + default: + usbd_ctrl_unsupport(udev); + break; + } + return ret; } /** @@ -220,27 +197,24 @@ static usb_sts_type usbd_get_status(usbd_core_type *udev) * @param udev: to the structure of usbd_core_type * @retval status of usb_sts_type */ -static usb_sts_type usbd_clear_feature(usbd_core_type *udev) -{ - usb_sts_type ret = USB_OK; - usb_setup_type *setup = &udev->setup; - switch(udev->conn_state) - { - case USB_CONN_STATE_ADDRESSED: - case USB_CONN_STATE_CONFIGURED: - if(setup->wValue == USB_FEATURE_REMOTE_WAKEUP) - { - udev->remote_wakup = 0; - udev->config_status &= ~USB_CONF_REMOTE_WAKEUP; - udev->class_handler->setup_handler(udev, &udev->setup); - usbd_ctrl_send_status(udev); - } - break; - default: - usbd_ctrl_unsupport(udev); - break; - } - return ret; +static usb_sts_type usbd_clear_feature(usbd_core_type *udev) { + usb_sts_type ret = USB_OK; + usb_setup_type *setup = &udev->setup; + switch (udev->conn_state) { + case USB_CONN_STATE_ADDRESSED: + case USB_CONN_STATE_CONFIGURED: + if (setup->wValue == USB_FEATURE_REMOTE_WAKEUP) { + udev->remote_wakup = 0; + udev->config_status &= ~USB_CONF_REMOTE_WAKEUP; + udev->class_handler->setup_handler(udev, &udev->setup); + usbd_ctrl_send_status(udev); + } + break; + default: + usbd_ctrl_unsupport(udev); + break; + } + return ret; } /** @@ -248,21 +222,17 @@ static usb_sts_type usbd_clear_feature(usbd_core_type *udev) * @param udev: to the structure of usbd_core_type * @retval status of usb_sts_type */ -static usb_sts_type usbd_set_feature(usbd_core_type *udev) -{ - usb_sts_type ret = USB_OK; - usb_setup_type *setup = &udev->setup; - if(setup->wValue == USB_FEATURE_REMOTE_WAKEUP) - { - udev->remote_wakup = 1; - udev->class_handler->setup_handler(udev, &udev->setup); - usbd_ctrl_send_status(udev); - } - else - { - usbd_ctrl_unsupport(udev); - } - return ret; +static usb_sts_type usbd_set_feature(usbd_core_type *udev) { + usb_sts_type ret = USB_OK; + usb_setup_type *setup = &udev->setup; + if (setup->wValue == USB_FEATURE_REMOTE_WAKEUP) { + udev->remote_wakup = 1; + udev->class_handler->setup_handler(udev, &udev->setup); + usbd_ctrl_send_status(udev); + } else { + usbd_ctrl_unsupport(udev); + } + return ret; } /** @@ -270,31 +240,26 @@ static usb_sts_type usbd_set_feature(usbd_core_type *udev) * @param udev: to the structure of usbd_core_type * @retval status of usb_sts_type */ -static usb_sts_type usbd_get_configuration(usbd_core_type *udev) -{ - usb_sts_type ret = USB_OK; - usb_setup_type *setup = &udev->setup; - if(setup->wLength != 1) - { - usbd_ctrl_unsupport(udev); - } - else - { - switch(udev->conn_state) - { - case USB_CONN_STATE_ADDRESSED: - udev->default_config = 0; - usbd_ctrl_send(udev, (uint8_t *)(&udev->default_config), 1); - break; - case USB_CONN_STATE_CONFIGURED: - usbd_ctrl_send(udev, (uint8_t *)(&udev->dev_config), 1); - break; - default: +static usb_sts_type usbd_get_configuration(usbd_core_type *udev) { + usb_sts_type ret = USB_OK; + usb_setup_type *setup = &udev->setup; + if (setup->wLength != 1) { usbd_ctrl_unsupport(udev); - break; + } else { + switch (udev->conn_state) { + case USB_CONN_STATE_ADDRESSED: + udev->default_config = 0; + usbd_ctrl_send(udev, (uint8_t *)(&udev->default_config), 1); + break; + case USB_CONN_STATE_CONFIGURED: + usbd_ctrl_send(udev, (uint8_t *)(&udev->dev_config), 1); + break; + default: + usbd_ctrl_unsupport(udev); + break; + } } - } - return ret; + return ret; } /** @@ -302,61 +267,48 @@ static usb_sts_type usbd_get_configuration(usbd_core_type *udev) * @param udev: to the structure of usbd_core_type * @retval status of usb_sts_type */ -static usb_sts_type usbd_set_configuration(usbd_core_type *udev) -{ - usb_sts_type ret = USB_OK; - static uint8_t config_value; - usb_setup_type *setup = &udev->setup; - config_value = (uint8_t)setup->wValue; +static usb_sts_type usbd_set_configuration(usbd_core_type *udev) { + usb_sts_type ret = USB_OK; + static uint8_t config_value; + usb_setup_type *setup = &udev->setup; + config_value = (uint8_t)setup->wValue; - if(setup->wIndex == 0 && setup->wLength == 0) - { - switch(udev->conn_state) - { - case USB_CONN_STATE_ADDRESSED: - if(config_value) - { - udev->dev_config = config_value; - udev->conn_state = USB_CONN_STATE_CONFIGURED; - udev->class_handler->init_handler(udev); - usbd_ctrl_send_status(udev); - } - else - { - usbd_ctrl_send_status(udev); - } + if (setup->wIndex == 0 && setup->wLength == 0) { + switch (udev->conn_state) { + case USB_CONN_STATE_ADDRESSED: + if (config_value) { + udev->dev_config = config_value; + udev->conn_state = USB_CONN_STATE_CONFIGURED; + udev->class_handler->init_handler(udev); + usbd_ctrl_send_status(udev); + } else { + usbd_ctrl_send_status(udev); + } - break; - case USB_CONN_STATE_CONFIGURED: - if(config_value == 0) - { - udev->conn_state = USB_CONN_STATE_ADDRESSED; - udev->dev_config = config_value; - udev->class_handler->clear_handler(udev); - usbd_ctrl_send_status(udev); + break; + case USB_CONN_STATE_CONFIGURED: + if (config_value == 0) { + udev->conn_state = USB_CONN_STATE_ADDRESSED; + udev->dev_config = config_value; + udev->class_handler->clear_handler(udev); + usbd_ctrl_send_status(udev); + } else if (config_value != udev->dev_config) { + udev->class_handler->clear_handler(udev); + udev->dev_config = config_value; + udev->class_handler->init_handler(udev); + usbd_ctrl_send_status(udev); + } else { + usbd_ctrl_send_status(udev); + } + break; + default: + usbd_ctrl_unsupport(udev); + break; } - else if(config_value != udev->dev_config) - { - udev->class_handler->clear_handler(udev); - udev->dev_config = config_value; - udev->class_handler->init_handler(udev); - usbd_ctrl_send_status(udev); - } - else - { - usbd_ctrl_send_status(udev); - } - break; - default: + } else { usbd_ctrl_unsupport(udev); - break; } - } - else - { - usbd_ctrl_unsupport(udev); - } - return ret; + return ret; } /** @@ -364,43 +316,40 @@ static usb_sts_type usbd_set_configuration(usbd_core_type *udev) * @param udev: to the structure of usbd_core_type * @retval status of usb_sts_type */ -usb_sts_type usbd_device_request(usbd_core_type *udev) -{ - usb_sts_type ret = USB_OK; - usb_setup_type *setup = &udev->setup; - if((setup->bmRequestType & USB_REQ_TYPE_RESERVED) != USB_REQ_TYPE_STANDARD) - { - udev->class_handler->setup_handler(udev, &udev->setup); +usb_sts_type usbd_device_request(usbd_core_type *udev) { + usb_sts_type ret = USB_OK; + usb_setup_type *setup = &udev->setup; + if ((setup->bmRequestType & USB_REQ_TYPE_RESERVED) != USB_REQ_TYPE_STANDARD) { + udev->class_handler->setup_handler(udev, &udev->setup); + return ret; + } + switch (udev->setup.bRequest) { + case USB_STD_REQ_GET_STATUS: + usbd_get_status(udev); + break; + case USB_STD_REQ_CLEAR_FEATURE: + usbd_clear_feature(udev); + break; + case USB_STD_REQ_SET_FEATURE: + usbd_set_feature(udev); + break; + case USB_STD_REQ_SET_ADDRESS: + usbd_set_address(udev); + break; + case USB_STD_REQ_GET_DESCRIPTOR: + usbd_get_descriptor(udev); + break; + case USB_STD_REQ_GET_CONFIGURATION: + usbd_get_configuration(udev); + break; + case USB_STD_REQ_SET_CONFIGURATION: + usbd_set_configuration(udev); + break; + default: + usbd_ctrl_unsupport(udev); + break; + } return ret; - } - switch(udev->setup.bRequest) - { - case USB_STD_REQ_GET_STATUS: - usbd_get_status(udev); - break; - case USB_STD_REQ_CLEAR_FEATURE: - usbd_clear_feature(udev); - break; - case USB_STD_REQ_SET_FEATURE: - usbd_set_feature(udev); - break; - case USB_STD_REQ_SET_ADDRESS: - usbd_set_address(udev); - break; - case USB_STD_REQ_GET_DESCRIPTOR: - usbd_get_descriptor(udev); - break; - case USB_STD_REQ_GET_CONFIGURATION: - usbd_get_configuration(udev); - break; - case USB_STD_REQ_SET_CONFIGURATION: - usbd_set_configuration(udev); - break; - default: - usbd_ctrl_unsupport(udev); - break; - } - return ret; } /** @@ -408,26 +357,23 @@ usb_sts_type usbd_device_request(usbd_core_type *udev) * @param udev: to the structure of usbd_core_type * @retval status of usb_sts_type */ -usb_sts_type usbd_interface_request(usbd_core_type *udev) -{ - usb_sts_type ret = USB_OK; - usb_setup_type *setup = &udev->setup; - switch(udev->conn_state) - { - case USB_CONN_STATE_DEFAULT: - case USB_CONN_STATE_ADDRESSED: - case USB_CONN_STATE_CONFIGURED: - ret = udev->class_handler->setup_handler(udev, &udev->setup); - if(setup->wLength == 0 && ret == USB_OK) - { - usbd_ctrl_send_status(udev); - } - break; - default: - usbd_ctrl_unsupport(udev); - break; - } - return ret; +usb_sts_type usbd_interface_request(usbd_core_type *udev) { + usb_sts_type ret = USB_OK; + usb_setup_type *setup = &udev->setup; + switch (udev->conn_state) { + case USB_CONN_STATE_DEFAULT: + case USB_CONN_STATE_ADDRESSED: + case USB_CONN_STATE_CONFIGURED: + ret = udev->class_handler->setup_handler(udev, &udev->setup); + if (setup->wLength == 0 && ret == USB_OK) { + usbd_ctrl_send_status(udev); + } + break; + default: + usbd_ctrl_unsupport(udev); + break; + } + return ret; } /** @@ -435,121 +381,98 @@ usb_sts_type usbd_interface_request(usbd_core_type *udev) * @param udev: to the structure of usbd_core_type * @retval status of usb_sts_type */ -usb_sts_type usbd_endpoint_request(usbd_core_type *udev) -{ - usb_sts_type ret = USB_OK; - usb_setup_type *setup = &udev->setup; - uint8_t ept_addr = LBYTE(setup->wIndex); - usb_ept_info *ept_info; +usb_sts_type usbd_endpoint_request(usbd_core_type *udev) { + usb_sts_type ret = USB_OK; + usb_setup_type *setup = &udev->setup; + uint8_t ept_addr = LBYTE(setup->wIndex); + usb_ept_info *ept_info; - if((setup->bmRequestType & USB_REQ_TYPE_RESERVED) != USB_REQ_TYPE_STANDARD) - { - udev->class_handler->setup_handler(udev, &udev->setup); + if ((setup->bmRequestType & USB_REQ_TYPE_RESERVED) != USB_REQ_TYPE_STANDARD) { + udev->class_handler->setup_handler(udev, &udev->setup); + return ret; + } + switch (setup->bRequest) { + case USB_STD_REQ_GET_STATUS: + switch (udev->conn_state) { + case USB_CONN_STATE_ADDRESSED: + if ((ept_addr & 0x7F) != 0) { + usbd_set_stall(udev, ept_addr); + } + if ((ept_addr & 0x80) != 0) { + ept_info = &udev->ept_in[ept_addr & 0x7F]; + } else { + ept_info = &udev->ept_out[ept_addr & 0x7F]; + } + ept_info->status = 0x0000; + usbd_ctrl_send(udev, (uint8_t *)(&ept_info->status), 2); + + break; + case USB_CONN_STATE_CONFIGURED: { + if ((ept_addr & 0x80) != 0) { + ept_info = &udev->ept_in[ept_addr & 0x7F]; + } else { + ept_info = &udev->ept_out[ept_addr & 0x7F]; + } + if (ept_info->stall == 1) { + ept_info->status = 0x0001; + } else { + ept_info->status = 0x0000; + } + usbd_ctrl_send(udev, (uint8_t *)(&ept_info->status), 2); + } + break; + default: + usbd_ctrl_unsupport(udev); + break; + } + break; + case USB_STD_REQ_CLEAR_FEATURE: + switch (udev->conn_state) { + case USB_CONN_STATE_ADDRESSED: + if ((ept_addr != 0x00) && (ept_addr != 0x80)) { + usbd_set_stall(udev, ept_addr); + } + break; + case USB_CONN_STATE_CONFIGURED: + if (setup->wValue == USB_FEATURE_EPT_HALT) { + if ((ept_addr & 0x7F) != 0x00) { + usbd_clear_stall(udev, ept_addr); + udev->class_handler->setup_handler(udev, &udev->setup); + } + usbd_ctrl_send_status(udev); + } + break; + default: + usbd_ctrl_unsupport(udev); + break; + } + break; + case USB_STD_REQ_SET_FEATURE: + switch (udev->conn_state) { + case USB_CONN_STATE_ADDRESSED: + if ((ept_addr != 0x00) && (ept_addr != 0x80)) { + usbd_set_stall(udev, ept_addr); + } + break; + case USB_CONN_STATE_CONFIGURED: + if (setup->wValue == USB_FEATURE_EPT_HALT) { + if ((ept_addr != 0x00) && (ept_addr != 0x80)) { + usbd_set_stall(udev, ept_addr); + } + } + udev->class_handler->setup_handler(udev, &udev->setup); + usbd_ctrl_send_status(udev); + break; + default: + usbd_ctrl_unsupport(udev); + break; + } + break; + default: + usbd_ctrl_unsupport(udev); + break; + } return ret; - } - switch(setup->bRequest) - { - case USB_STD_REQ_GET_STATUS: - switch(udev->conn_state) - { - case USB_CONN_STATE_ADDRESSED: - if((ept_addr & 0x7F) != 0) - { - usbd_set_stall(udev, ept_addr); - } - if((ept_addr & 0x80) != 0) - { - ept_info = &udev->ept_in[ept_addr & 0x7F]; - } - else - { - ept_info = &udev->ept_out[ept_addr & 0x7F]; - } - ept_info->status = 0x0000; - usbd_ctrl_send(udev, (uint8_t *)(&ept_info->status), 2); - - break; - case USB_CONN_STATE_CONFIGURED: - { - if((ept_addr & 0x80) != 0) - { - ept_info = &udev->ept_in[ept_addr & 0x7F]; - } - else - { - ept_info = &udev->ept_out[ept_addr & 0x7F]; - } - if(ept_info->stall == 1) - { - ept_info->status = 0x0001; - } - else - { - ept_info->status = 0x0000; - } - usbd_ctrl_send(udev, (uint8_t *)(&ept_info->status), 2); - } - break; - default: - usbd_ctrl_unsupport(udev); - break; - } - break; - case USB_STD_REQ_CLEAR_FEATURE: - switch(udev->conn_state) - { - case USB_CONN_STATE_ADDRESSED: - if((ept_addr != 0x00) && (ept_addr != 0x80)) - { - usbd_set_stall(udev, ept_addr); - } - break; - case USB_CONN_STATE_CONFIGURED: - if(setup->wValue == USB_FEATURE_EPT_HALT) - { - if((ept_addr & 0x7F) != 0x00 ) - { - usbd_clear_stall(udev, ept_addr); - udev->class_handler->setup_handler(udev, &udev->setup); - } - usbd_ctrl_send_status(udev); - } - break; - default: - usbd_ctrl_unsupport(udev); - break; - } - break; - case USB_STD_REQ_SET_FEATURE: - switch(udev->conn_state) - { - case USB_CONN_STATE_ADDRESSED: - if((ept_addr != 0x00) && (ept_addr != 0x80)) - { - usbd_set_stall(udev, ept_addr); - } - break; - case USB_CONN_STATE_CONFIGURED: - if(setup->wValue == USB_FEATURE_EPT_HALT) - { - if((ept_addr != 0x00) && (ept_addr != 0x80)) - { - usbd_set_stall(udev, ept_addr); - } - } - udev->class_handler->setup_handler(udev, &udev->setup); - usbd_ctrl_send_status(udev); - break; - default: - usbd_ctrl_unsupport(udev); - break; - } - break; - default: - usbd_ctrl_unsupport(udev); - break; - } - return ret; } /** * @} diff --git a/armlib/at32_usb/usb_drivers/src/usbh_core.c b/armlib/at32_usb/usb_drivers/src/usbh_core.c index 205ec473b..f90faa558 100644 --- a/armlib/at32_usb/usb_drivers/src/usbh_core.c +++ b/armlib/at32_usb/usb_drivers/src/usbh_core.c @@ -52,13 +52,11 @@ static void usbh_disconnect(usbh_core_type *uhost); * @param index: channle number * @retval none */ -void usbh_free_channel(usbh_core_type *uhost, uint8_t index) -{ - if(index < USB_HOST_CHANNEL_NUM) - { - /* free host channel */ - uhost->channel[index] = 0x0; - } +void usbh_free_channel(usbh_core_type *uhost, uint8_t index) { + if (index < USB_HOST_CHANNEL_NUM) { + /* free host channel */ + uhost->channel[index] = 0x0; + } } /** @@ -66,19 +64,16 @@ void usbh_free_channel(usbh_core_type *uhost, uint8_t index) * @param uhost: to the structure of usbh_core_type * @retval channel index */ -uint16_t usbh_get_free_channel(usbh_core_type *uhost) -{ - uint16_t i_index = 0; - for(i_index = 0; i_index < USB_HOST_CHANNEL_NUM; i_index ++) - { - /* find unuse channel */ - if((uhost->channel[i_index] & HCH_USED) == 0) - { - /* return channel index */ - return i_index; +uint16_t usbh_get_free_channel(usbh_core_type *uhost) { + uint16_t i_index = 0; + for (i_index = 0; i_index < USB_HOST_CHANNEL_NUM; i_index ++) { + /* find unuse channel */ + if ((uhost->channel[i_index] & HCH_USED) == 0) { + /* return channel index */ + return i_index; + } } - } - return HCH_ERROR; + return HCH_ERROR; } @@ -89,19 +84,15 @@ uint16_t usbh_get_free_channel(usbh_core_type *uhost) * @param toggle: toggle value * @retval status: usb_sts_type status */ -usb_sts_type usbh_set_toggle(usbh_core_type *uhost, uint8_t hc_num, uint8_t toggle) -{ - if(uhost->hch[hc_num].dir) - { - /* direction in */ - uhost->hch[hc_num].toggle_in = toggle; - } - else - { - /* direction out */ - uhost->hch[hc_num].toggle_out = toggle; - } - return USB_OK; +usb_sts_type usbh_set_toggle(usbh_core_type *uhost, uint8_t hc_num, uint8_t toggle) { + if (uhost->hch[hc_num].dir) { + /* direction in */ + uhost->hch[hc_num].toggle_in = toggle; + } else { + /* direction out */ + uhost->hch[hc_num].toggle_out = toggle; + } + return USB_OK; } /** @@ -110,98 +101,88 @@ usb_sts_type usbh_set_toggle(usbh_core_type *uhost, uint8_t hc_num, uint8_t togg * @param hc_num: channel number * @retval status: usb_sts_type status */ -usb_sts_type usbh_in_out_request(usbh_core_type *uhost, uint8_t hc_num) -{ - usb_sts_type status = USB_OK; - uint32_t n_packet = 0; - uint32_t num_words = 0; - uint32_t tmp; - otg_global_type *usbx = uhost->usb_reg; - otg_hchannel_type *ch = USB_CHL(uhost->usb_reg, hc_num); +usb_sts_type usbh_in_out_request(usbh_core_type *uhost, uint8_t hc_num) { + usb_sts_type status = USB_OK; + uint32_t n_packet = 0; + uint32_t num_words = 0; + uint32_t tmp; + otg_global_type *usbx = uhost->usb_reg; + otg_hchannel_type *ch = USB_CHL(uhost->usb_reg, hc_num); - /* set usb request block to idle */ - uhost->urb_state[hc_num] = URB_IDLE; - uhost->hch[hc_num].state = HCH_IDLE; + /* set usb request block to idle */ + uhost->urb_state[hc_num] = URB_IDLE; + uhost->hch[hc_num].state = HCH_IDLE; - /* set usb channel transmit count to zero */ - uhost->hch[hc_num].trans_count = 0; + /* set usb channel transmit count to zero */ + uhost->hch[hc_num].trans_count = 0; - /* check transmit data len */ - if(uhost->hch[hc_num].trans_len > 0) - { - /* count how many packet need to send */ - n_packet = (uhost->hch[hc_num].trans_len + \ - uhost->hch[hc_num].maxpacket - 1) / \ - uhost->hch[hc_num].maxpacket; + /* check transmit data len */ + if (uhost->hch[hc_num].trans_len > 0) { + /* count how many packet need to send */ + n_packet = (uhost->hch[hc_num].trans_len + \ + uhost->hch[hc_num].maxpacket - 1) / \ + uhost->hch[hc_num].maxpacket; - /* packet count max 256 */ - if(n_packet > 256) - { - n_packet = 256; - uhost->hch[hc_num].trans_len = n_packet * uhost->hch[hc_num].maxpacket; - } - } - else - { - /* zero data len */ - n_packet = 1; - } - - /* direction is in */ - if(uhost->hch[hc_num].dir) - { - uhost->hch[hc_num].trans_len = n_packet * uhost->hch[hc_num].maxpacket; - } - - /* set transfer information to channel register */ - ch->hctsiz = (uhost->hch[hc_num].trans_len & USB_OTG_HCTSIZ_XFERSIZE) | - ((n_packet << 19) & USB_OTG_HCTSIZ_PKTCNT) | - ((uhost->hch[hc_num].data_pid << 29) & USB_OTG_HCTSIZ_PID); - - /* set odd frame */ - ch->hcchar_bit.oddfrm = !(OTG_HOST(uhost->usb_reg)->hfnum & 0x1); - - /* clear channel disable bit and enable channel */ - tmp = ch->hcchar; - tmp &= ~(USB_OTG_HCCHAR_CHDIS); - tmp |= USB_OTG_HCCHAR_CHENA; - ch->hcchar = tmp; - - /* channel direction is out and transfer len > 0 */ - if((uhost->hch[hc_num].dir == 0) && - (uhost->hch[hc_num].trans_len > 0 )) - { - switch(uhost->hch[hc_num].ept_type) - { - case EPT_CONTROL_TYPE: - case EPT_BULK_TYPE: - num_words = (uhost->hch[hc_num].trans_len + 3) / 4; - - /* non-periodic transfer */ - if(num_words > usbx->gnptxsts_bit.nptxfspcavail) - { - usbx->gintmsk_bit.nptxfempmsk = 1; + /* packet count max 256 */ + if (n_packet > 256) { + n_packet = 256; + uhost->hch[hc_num].trans_len = n_packet * uhost->hch[hc_num].maxpacket; } - break; - case EPT_ISO_TYPE: - case EPT_INT_TYPE: - num_words = (uhost->hch[hc_num].trans_len + 3) / 4; - - /* periodic transfer */ - if(num_words > OTG_HOST(usbx)->hptxsts_bit.ptxfspcavil) - { - usbx->gintmsk_bit.ptxfempmsk = 1; - } - break; - default: - break; + } else { + /* zero data len */ + n_packet = 1; } - /* write data to fifo */ - usb_write_packet(usbx, uhost->hch[hc_num].trans_buf, - hc_num, uhost->hch[hc_num].trans_len); - } - return status; + /* direction is in */ + if (uhost->hch[hc_num].dir) { + uhost->hch[hc_num].trans_len = n_packet * uhost->hch[hc_num].maxpacket; + } + + /* set transfer information to channel register */ + ch->hctsiz = (uhost->hch[hc_num].trans_len & USB_OTG_HCTSIZ_XFERSIZE) | + ((n_packet << 19) & USB_OTG_HCTSIZ_PKTCNT) | + ((uhost->hch[hc_num].data_pid << 29) & USB_OTG_HCTSIZ_PID); + + /* set odd frame */ + ch->hcchar_bit.oddfrm = !(OTG_HOST(uhost->usb_reg)->hfnum & 0x1); + + /* clear channel disable bit and enable channel */ + tmp = ch->hcchar; + tmp &= ~(USB_OTG_HCCHAR_CHDIS); + tmp |= USB_OTG_HCCHAR_CHENA; + ch->hcchar = tmp; + + /* channel direction is out and transfer len > 0 */ + if ((uhost->hch[hc_num].dir == 0) && + (uhost->hch[hc_num].trans_len > 0)) { + switch (uhost->hch[hc_num].ept_type) { + case EPT_CONTROL_TYPE: + case EPT_BULK_TYPE: + num_words = (uhost->hch[hc_num].trans_len + 3) / 4; + + /* non-periodic transfer */ + if (num_words > usbx->gnptxsts_bit.nptxfspcavail) { + usbx->gintmsk_bit.nptxfempmsk = 1; + } + break; + case EPT_ISO_TYPE: + case EPT_INT_TYPE: + num_words = (uhost->hch[hc_num].trans_len + 3) / 4; + + /* periodic transfer */ + if (num_words > OTG_HOST(usbx)->hptxsts_bit.ptxfspcavil) { + usbx->gintmsk_bit.ptxfempmsk = 1; + } + break; + default: + break; + } + /* write data to fifo */ + usb_write_packet(usbx, uhost->hch[hc_num].trans_buf, + hc_num, uhost->hch[hc_num].trans_len); + } + + return status; } /** @@ -213,29 +194,25 @@ usb_sts_type usbh_in_out_request(usbh_core_type *uhost, uint8_t hc_num) * @retval status: usb_sts_type status */ usb_sts_type usbh_interrupt_recv(usbh_core_type *uhost, uint8_t hc_num, - uint8_t *buffer, uint16_t length) -{ - /* set direction is in */ - uhost->hch[hc_num].dir = 1; + uint8_t *buffer, uint16_t length) { + /* set direction is in */ + uhost->hch[hc_num].dir = 1; - /* set transfer buffer */ - uhost->hch[hc_num].trans_buf = buffer; + /* set transfer buffer */ + uhost->hch[hc_num].trans_buf = buffer; - /* set transfer len*/ - uhost->hch[hc_num].trans_len = length; + /* set transfer len*/ + uhost->hch[hc_num].trans_len = length; - if(uhost->hch[hc_num].toggle_in == 0) - { - /* pid: data0 */ - uhost->hch[hc_num].data_pid = HCH_PID_DATA0; - } - else - { - /* pid: data1 */ - uhost->hch[hc_num].data_pid = HCH_PID_DATA1; - } + if (uhost->hch[hc_num].toggle_in == 0) { + /* pid: data0 */ + uhost->hch[hc_num].data_pid = HCH_PID_DATA0; + } else { + /* pid: data1 */ + uhost->hch[hc_num].data_pid = HCH_PID_DATA1; + } - return usbh_in_out_request(uhost, hc_num); + return usbh_in_out_request(uhost, hc_num); } /** @@ -247,29 +224,25 @@ usb_sts_type usbh_interrupt_recv(usbh_core_type *uhost, uint8_t hc_num, * @retval status: usb_sts_type status */ usb_sts_type usbh_interrupt_send(usbh_core_type *uhost, uint8_t hc_num, - uint8_t *buffer, uint16_t length) -{ - /* set direction is out */ - uhost->hch[hc_num].dir = 0; + uint8_t *buffer, uint16_t length) { + /* set direction is out */ + uhost->hch[hc_num].dir = 0; - /* set transfer buffer */ - uhost->hch[hc_num].trans_buf = buffer; + /* set transfer buffer */ + uhost->hch[hc_num].trans_buf = buffer; - /* set transfer len*/ - uhost->hch[hc_num].trans_len = length; + /* set transfer len*/ + uhost->hch[hc_num].trans_len = length; - if(uhost->hch[hc_num].toggle_out == 0) - { - /* pid: data0 */ - uhost->hch[hc_num].data_pid = HCH_PID_DATA0; - } - else - { - /* pid: data1 */ - uhost->hch[hc_num].data_pid = HCH_PID_DATA1; - } + if (uhost->hch[hc_num].toggle_out == 0) { + /* pid: data0 */ + uhost->hch[hc_num].data_pid = HCH_PID_DATA0; + } else { + /* pid: data1 */ + uhost->hch[hc_num].data_pid = HCH_PID_DATA1; + } - return usbh_in_out_request(uhost, hc_num); + return usbh_in_out_request(uhost, hc_num); } @@ -282,29 +255,25 @@ usb_sts_type usbh_interrupt_send(usbh_core_type *uhost, uint8_t hc_num, * @retval status: usb_sts_type status */ usb_sts_type usbh_bulk_recv(usbh_core_type *uhost, uint8_t hc_num, - uint8_t *buffer, uint16_t length) -{ - /* set direction is in */ - uhost->hch[hc_num].dir = 1; + uint8_t *buffer, uint16_t length) { + /* set direction is in */ + uhost->hch[hc_num].dir = 1; - /* set transfer buffer */ - uhost->hch[hc_num].trans_buf = buffer; + /* set transfer buffer */ + uhost->hch[hc_num].trans_buf = buffer; - /* set transfer len*/ - uhost->hch[hc_num].trans_len = length; + /* set transfer len*/ + uhost->hch[hc_num].trans_len = length; - if(uhost->hch[hc_num].toggle_in == 0) - { - /* pid: data0 */ - uhost->hch[hc_num].data_pid = HCH_PID_DATA0; - } - else - { - /* pid: data1 */ - uhost->hch[hc_num].data_pid = HCH_PID_DATA1; - } + if (uhost->hch[hc_num].toggle_in == 0) { + /* pid: data0 */ + uhost->hch[hc_num].data_pid = HCH_PID_DATA0; + } else { + /* pid: data1 */ + uhost->hch[hc_num].data_pid = HCH_PID_DATA1; + } - return usbh_in_out_request(uhost, hc_num); + return usbh_in_out_request(uhost, hc_num); } @@ -317,29 +286,25 @@ usb_sts_type usbh_bulk_recv(usbh_core_type *uhost, uint8_t hc_num, * @retval status: usb_sts_type status */ usb_sts_type usbh_bulk_send(usbh_core_type *uhost, uint8_t hc_num, - uint8_t *buffer, uint16_t length) -{ - /* set direction is out */ - uhost->hch[hc_num].dir = 0; + uint8_t *buffer, uint16_t length) { + /* set direction is out */ + uhost->hch[hc_num].dir = 0; - /* set transfer buffer */ - uhost->hch[hc_num].trans_buf = buffer; + /* set transfer buffer */ + uhost->hch[hc_num].trans_buf = buffer; - /* set transfer len*/ - uhost->hch[hc_num].trans_len = length; + /* set transfer len*/ + uhost->hch[hc_num].trans_len = length; - if(uhost->hch[hc_num].toggle_out == 0) - { - /* pid: data0 */ - uhost->hch[hc_num].data_pid = HCH_PID_DATA0; - } - else - { - /* pid: data1 */ - uhost->hch[hc_num].data_pid = HCH_PID_DATA1; - } + if (uhost->hch[hc_num].toggle_out == 0) { + /* pid: data0 */ + uhost->hch[hc_num].data_pid = HCH_PID_DATA0; + } else { + /* pid: data1 */ + uhost->hch[hc_num].data_pid = HCH_PID_DATA1; + } - return usbh_in_out_request(uhost, hc_num); + return usbh_in_out_request(uhost, hc_num); } @@ -352,21 +317,20 @@ usb_sts_type usbh_bulk_send(usbh_core_type *uhost, uint8_t hc_num, * @retval status: usb_sts_type status */ usb_sts_type usbh_isoc_send(usbh_core_type *uhost, uint8_t hc_num, - uint8_t *buffer, uint16_t length) -{ - /* set direction is out */ - uhost->hch[hc_num].dir = 0; + uint8_t *buffer, uint16_t length) { + /* set direction is out */ + uhost->hch[hc_num].dir = 0; - /* set transfer buffer */ - uhost->hch[hc_num].trans_buf = buffer; + /* set transfer buffer */ + uhost->hch[hc_num].trans_buf = buffer; - /* set transfer len*/ - uhost->hch[hc_num].trans_len = length; + /* set transfer len*/ + uhost->hch[hc_num].trans_len = length; - /* pid: data0 */ - uhost->hch[hc_num].data_pid = HCH_PID_DATA0; + /* pid: data0 */ + uhost->hch[hc_num].data_pid = HCH_PID_DATA0; - return usbh_in_out_request(uhost, hc_num); + return usbh_in_out_request(uhost, hc_num); } /** @@ -378,21 +342,20 @@ usb_sts_type usbh_isoc_send(usbh_core_type *uhost, uint8_t hc_num, * @retval status: usb_sts_type status */ usb_sts_type usbh_isoc_recv(usbh_core_type *uhost, uint8_t hc_num, - uint8_t *buffer, uint16_t length) -{ - /* set direction is in */ - uhost->hch[hc_num].dir = 1; + uint8_t *buffer, uint16_t length) { + /* set direction is in */ + uhost->hch[hc_num].dir = 1; - /* set transfer buffer */ - uhost->hch[hc_num].trans_buf = buffer; + /* set transfer buffer */ + uhost->hch[hc_num].trans_buf = buffer; - /* set transfer len*/ - uhost->hch[hc_num].trans_len = length; + /* set transfer len*/ + uhost->hch[hc_num].trans_len = length; - /* pid: data0 */ - uhost->hch[hc_num].data_pid = HCH_PID_DATA0; + /* pid: data0 */ + uhost->hch[hc_num].data_pid = HCH_PID_DATA0; - return usbh_in_out_request(uhost, hc_num); + return usbh_in_out_request(uhost, hc_num); } /** @@ -400,37 +363,36 @@ usb_sts_type usbh_isoc_recv(usbh_core_type *uhost, uint8_t hc_num, * @param uhost: to the structure of usbh_core_type * @retval status: usb_sts_type status */ -usb_sts_type usbh_cfg_default_init(usbh_core_type *uhost) -{ - /* set global state to idle */ - uhost->global_state = USBH_IDLE; +usb_sts_type usbh_cfg_default_init(usbh_core_type *uhost) { + /* set global state to idle */ + uhost->global_state = USBH_IDLE; - /* enumeration state to get description */ - uhost->enum_state = ENUM_GET_MIN_DESC; + /* enumeration state to get description */ + uhost->enum_state = ENUM_GET_MIN_DESC; - /* request state send */ - uhost->req_state = CMD_SEND; + /* request state send */ + uhost->req_state = CMD_SEND; - /* control transfer state is idle*/ - uhost->ctrl.state = CONTROL_IDLE; + /* control transfer state is idle*/ + uhost->ctrl.state = CONTROL_IDLE; - /* defaut endpoint 0 max size is 8byte */ - uhost->ctrl.ept0_size = 8; + /* defaut endpoint 0 max size is 8byte */ + uhost->ctrl.ept0_size = 8; - /* default device address is 0 */ - uhost->dev.address = 0; + /* default device address is 0 */ + uhost->dev.address = 0; - /* default speed is full speed */ - uhost->dev.speed = USB_FULL_SPEED_CORE_ID; + /* default speed is full speed */ + uhost->dev.speed = USB_FULL_SPEED_CORE_ID; - uhost->timer = 0; + uhost->timer = 0; - uhost->ctrl.err_cnt = 0; + uhost->ctrl.err_cnt = 0; - /* free all channel */ - usbh_free_channel(uhost, uhost->ctrl.hch_in); - usbh_free_channel(uhost, uhost->ctrl.hch_out); - return USB_OK; + /* free all channel */ + usbh_free_channel(uhost, uhost->ctrl.hch_in); + usbh_free_channel(uhost, uhost->ctrl.hch_out); + return USB_OK; } /** @@ -438,19 +400,18 @@ usb_sts_type usbh_cfg_default_init(usbh_core_type *uhost) * @param uhost: to the structure of usbh_core_type * @retval none */ -void usbh_enter_suspend(usbh_core_type *uhost) -{ - otg_host_type *host = OTG_HOST(uhost->usb_reg); - uint32_t hprt_val = host->hprt; +void usbh_enter_suspend(usbh_core_type *uhost) { + otg_host_type *host = OTG_HOST(uhost->usb_reg); + uint32_t hprt_val = host->hprt; - hprt_val &= ~(USB_OTG_HPRT_PRTENA | USB_OTG_HPRT_PRTENCHNG | - USB_OTG_HPRT_PRTOVRCACT | USB_OTG_HPRT_PRTCONDET); + hprt_val &= ~(USB_OTG_HPRT_PRTENA | USB_OTG_HPRT_PRTENCHNG | + USB_OTG_HPRT_PRTOVRCACT | USB_OTG_HPRT_PRTCONDET); - /* set port suspend */ - host->hprt = hprt_val | USB_OTG_HPRT_PRTSUSP; + /* set port suspend */ + host->hprt = hprt_val | USB_OTG_HPRT_PRTSUSP; - /* stop phy clock */ - usb_stop_phy_clk(uhost->usb_reg); + /* stop phy clock */ + usb_stop_phy_clk(uhost->usb_reg); } @@ -459,30 +420,29 @@ void usbh_enter_suspend(usbh_core_type *uhost) * @param uhost: to the structure of usbh_core_type * @retval none */ -void usbh_resume(usbh_core_type *uhost) -{ - otg_host_type *host = OTG_HOST(uhost->usb_reg); - uint32_t temp = host->hprt; +void usbh_resume(usbh_core_type *uhost) { + otg_host_type *host = OTG_HOST(uhost->usb_reg); + uint32_t temp = host->hprt; - /* open phy clock */ - usb_open_phy_clk(uhost->usb_reg); + /* open phy clock */ + usb_open_phy_clk(uhost->usb_reg); - /* clear port suspend and set port resume*/ - temp &= ~(USB_OTG_HPRT_PRTENA | USB_OTG_HPRT_PRTENCHNG | - USB_OTG_HPRT_PRTOVRCACT | USB_OTG_HPRT_PRTCONDET - | USB_OTG_HPRT_PRTSUSP); - host->hprt = temp | USB_OTG_HPRT_PRTRES; + /* clear port suspend and set port resume*/ + temp &= ~(USB_OTG_HPRT_PRTENA | USB_OTG_HPRT_PRTENCHNG | + USB_OTG_HPRT_PRTOVRCACT | USB_OTG_HPRT_PRTCONDET + | USB_OTG_HPRT_PRTSUSP); + host->hprt = temp | USB_OTG_HPRT_PRTRES; - /* delay 20 ms */ - usb_delay_ms(20); + /* delay 20 ms */ + usb_delay_ms(20); - /*clear port resume */ - temp = host->hprt; - temp &= ~(USB_OTG_HPRT_PRTENA | USB_OTG_HPRT_PRTENCHNG | - USB_OTG_HPRT_PRTOVRCACT | USB_OTG_HPRT_PRTCONDET - | USB_OTG_HPRT_PRTRES); - host->hprt = temp; - usb_delay_ms(5); + /*clear port resume */ + temp = host->hprt; + temp &= ~(USB_OTG_HPRT_PRTENA | USB_OTG_HPRT_PRTENCHNG | + USB_OTG_HPRT_PRTOVRCACT | USB_OTG_HPRT_PRTCONDET + | USB_OTG_HPRT_PRTRES); + host->hprt = temp; + usb_delay_ms(5); } /** @@ -500,117 +460,112 @@ usb_sts_type usbh_core_init(usbh_core_type *uhost, usb_reg_type *usb_reg, usbh_class_handler_type *class_handler, usbh_user_handler_type *user_handler, - uint8_t core_id) -{ - usb_sts_type status = USB_OK; - uint32_t i_index; - otg_global_type *usbx = usb_reg; - otg_host_type *host = OTG_HOST(usbx); - uhost->usb_reg = usb_reg; + uint8_t core_id) { + usb_sts_type status = USB_OK; + uint32_t i_index; + otg_global_type *usbx = usb_reg; + otg_host_type *host = OTG_HOST(usbx); + uhost->usb_reg = usb_reg; - /* host class handler */ - uhost->class_handler = class_handler; - uhost->user_handler = user_handler; + /* host class handler */ + uhost->class_handler = class_handler; + uhost->user_handler = user_handler; - /* host user handler */ - uhost->user_handler->user_init(); + /* host user handler */ + uhost->user_handler->user_init(); - uhost->timer = 0; + uhost->timer = 0; - /* usb host cfg default init */ - usbh_cfg_default_init(uhost); + /* usb host cfg default init */ + usbh_cfg_default_init(uhost); - /* clear host config to default value */ - for(i_index = 0; i_index < USB_HOST_CHANNEL_NUM; i_index ++) - { - uhost->err_cnt[i_index] = 0; - uhost->xfer_cnt[i_index] = 0; - uhost->hch_state[i_index] = HCH_IDLE; - uhost->hch[0].maxpacket = 8; - } + /* clear host config to default value */ + for (i_index = 0; i_index < USB_HOST_CHANNEL_NUM; i_index ++) { + uhost->err_cnt[i_index] = 0; + uhost->xfer_cnt[i_index] = 0; + uhost->hch_state[i_index] = HCH_IDLE; + uhost->hch[0].maxpacket = 8; + } - /* no device connect */ - uhost->conn_sts = 0; + /* no device connect */ + uhost->conn_sts = 0; - /* disable usb interrupt */ - usb_interrupt_disable(usbx); + /* disable usb interrupt */ + usb_interrupt_disable(usbx); - /* usb global init */ - usb_global_init(usbx); + /* usb global init */ + usb_global_init(usbx); - /* set usb host mode */ - usb_global_set_mode(usbx, OTG_HOST_MODE); + /* set usb host mode */ + usb_global_set_mode(usbx, OTG_HOST_MODE); - /* open usb phy clock*/ - usb_open_phy_clk(usbx); + /* open usb phy clock*/ + usb_open_phy_clk(usbx); - /* clock select */ - usbh_fsls_clksel(usbx, USB_HCFG_CLK_48M); + /* clock select */ + usbh_fsls_clksel(usbx, USB_HCFG_CLK_48M); - /* set support ls and fs device */ - host->hcfg_bit.fslssupp = 0; + /* set support ls and fs device */ + host->hcfg_bit.fslssupp = 0; - if(usbx == OTG1_GLOBAL) - { - /* set receive fifo size */ - usbx->grxfsiz = USBH_RX_FIFO_SIZE; + if (usbx == OTG1_GLOBAL) { + /* set receive fifo size */ + usbx->grxfsiz = USBH_RX_FIFO_SIZE; - /* set non-periodic transmit fifo start address and depth */ - usbx->gnptxfsiz_ept0tx_bit.nptxfstaddr = USBH_RX_FIFO_SIZE; - usbx->gnptxfsiz_ept0tx_bit.nptxfdep = USBH_NP_TX_FIFO_SIZE; + /* set non-periodic transmit fifo start address and depth */ + usbx->gnptxfsiz_ept0tx_bit.nptxfstaddr = USBH_RX_FIFO_SIZE; + usbx->gnptxfsiz_ept0tx_bit.nptxfdep = USBH_NP_TX_FIFO_SIZE; - /* set periodic transmit fifo start address and depth */ - usbx->hptxfsiz_bit.ptxfstaddr = USBH_RX_FIFO_SIZE + USBH_NP_TX_FIFO_SIZE; - usbx->hptxfsiz_bit.ptxfsize = USBH_P_TX_FIFO_SIZE; - } + /* set periodic transmit fifo start address and depth */ + usbx->hptxfsiz_bit.ptxfstaddr = USBH_RX_FIFO_SIZE + USBH_NP_TX_FIFO_SIZE; + usbx->hptxfsiz_bit.ptxfsize = USBH_P_TX_FIFO_SIZE; + } #ifdef OTG2_GLOBAL - if(usbx == OTG2_GLOBAL) - { - /* set receive fifo size */ - usbx->grxfsiz = USBH2_RX_FIFO_SIZE; + if (usbx == OTG2_GLOBAL) { + /* set receive fifo size */ + usbx->grxfsiz = USBH2_RX_FIFO_SIZE; - /* set non-periodic transmit fifo start address and depth */ - usbx->gnptxfsiz_ept0tx_bit.nptxfstaddr = USBH2_RX_FIFO_SIZE; - usbx->gnptxfsiz_ept0tx_bit.nptxfdep = USBH2_NP_TX_FIFO_SIZE; + /* set non-periodic transmit fifo start address and depth */ + usbx->gnptxfsiz_ept0tx_bit.nptxfstaddr = USBH2_RX_FIFO_SIZE; + usbx->gnptxfsiz_ept0tx_bit.nptxfdep = USBH2_NP_TX_FIFO_SIZE; - /* set periodic transmit fifo start address and depth */ - usbx->hptxfsiz_bit.ptxfstaddr = USBH2_RX_FIFO_SIZE + USBH2_NP_TX_FIFO_SIZE; - usbx->hptxfsiz_bit.ptxfsize = USBH2_P_TX_FIFO_SIZE; - } + /* set periodic transmit fifo start address and depth */ + usbx->hptxfsiz_bit.ptxfstaddr = USBH2_RX_FIFO_SIZE + USBH2_NP_TX_FIFO_SIZE; + usbx->hptxfsiz_bit.ptxfsize = USBH2_P_TX_FIFO_SIZE; + } #endif - /* flush tx fifo */ - usb_flush_tx_fifo(usbx, 16); + /* flush tx fifo */ + usb_flush_tx_fifo(usbx, 16); - /* flush rx fifo */ - usb_flush_rx_fifo(usbx); + /* flush rx fifo */ + usb_flush_rx_fifo(usbx); - /* clear host channel interrut mask and status */ - for(i_index = 0; i_index < USB_HOST_CHANNEL_NUM; i_index ++) - { - USB_CHL(usbx, i_index)->hcintmsk = 0; - USB_CHL(usbx, i_index)->hcint = 0xFFFFFFFF; - } + /* clear host channel interrut mask and status */ + for (i_index = 0; i_index < USB_HOST_CHANNEL_NUM; i_index ++) { + USB_CHL(usbx, i_index)->hcintmsk = 0; + USB_CHL(usbx, i_index)->hcint = 0xFFFFFFFF; + } - /* power on to this port */ - usb_port_power_on(usbx, TRUE); + /* power on to this port */ + usb_port_power_on(usbx, TRUE); - /* clear global interrupt mask and status */ - usbx->gintmsk = 0; - usbx->gintsts = 0xBFFFFFFF; + /* clear global interrupt mask and status */ + usbx->gintmsk = 0; + usbx->gintsts = 0xBFFFFFFF; - /* set global interrut mask */ - usbx->gintmsk = USB_OTG_SOF_INT | USB_OTG_RXFLVL_INT | - USB_OTG_USBSUSP_INT | USB_OTG_PRT_INT | - USB_OTG_HCH_INT | USB_OTG_INCOMISOIN_INT | - USB_OTG_INCOMPIP_INCOMPISOOUT_INT | USB_OTG_WKUP_INT | - USB_OTG_DISCON_INT; + /* set global interrut mask */ + usbx->gintmsk = USB_OTG_SOF_INT | USB_OTG_RXFLVL_INT | + USB_OTG_USBSUSP_INT | USB_OTG_PRT_INT | + USB_OTG_HCH_INT | USB_OTG_INCOMISOIN_INT | + USB_OTG_INCOMPIP_INCOMPISOOUT_INT | USB_OTG_WKUP_INT | + USB_OTG_DISCON_INT; - /* enable usb global interrupt */ - usb_interrupt_enable(usbx); + /* enable usb global interrupt */ + usb_interrupt_enable(usbx); - /* active vbus */ - usbh_active_vbus(uhost, TRUE); - return status; + /* active vbus */ + usbh_active_vbus(uhost, TRUE); + return status; } /** @@ -634,39 +589,38 @@ usb_sts_type usbh_core_init(usbh_core_type *uhost, * @retval usb_sts_type */ void usbh_hc_open(usbh_core_type *uhost, - uint8_t chn, - uint8_t ept_num, - uint8_t dev_address, - uint8_t type, - uint16_t maxpacket, - uint8_t speed) -{ - /* device address */ - uhost->hch[chn].address = dev_address; + uint8_t chn, + uint8_t ept_num, + uint8_t dev_address, + uint8_t type, + uint16_t maxpacket, + uint8_t speed) { + /* device address */ + uhost->hch[chn].address = dev_address; - /* device speed */ - uhost->hch[chn].speed = speed; + /* device speed */ + uhost->hch[chn].speed = speed; - /* endpoint transfer type */ - uhost->hch[chn].ept_type = type; + /* endpoint transfer type */ + uhost->hch[chn].ept_type = type; - /* endpoint support maxpacket */ - uhost->hch[chn].maxpacket = maxpacket; + /* endpoint support maxpacket */ + uhost->hch[chn].maxpacket = maxpacket; - /* endpoint direction in or out */ - uhost->hch[chn].dir = (ept_num & 0x80)?1:0;; + /* endpoint direction in or out */ + uhost->hch[chn].dir = (ept_num & 0x80) ? 1 : 0;; - /* host channel number */ - uhost->hch[chn].ch_num = chn; + /* host channel number */ + uhost->hch[chn].ch_num = chn; - /* device endpoint number */ - uhost->hch[chn].ept_num = ept_num; + /* device endpoint number */ + uhost->hch[chn].ept_num = ept_num; - /* enable channel */ - usb_hc_enable(uhost->usb_reg, chn, - ept_num, dev_address, - type, maxpacket, speed - ); + /* enable channel */ + usb_hc_enable(uhost->usb_reg, chn, + ept_num, dev_address, + type, maxpacket, speed + ); } /** @@ -678,9 +632,8 @@ void usbh_hc_open(usbh_core_type *uhost, * @param chn: channel number * @retval none */ -void usbh_ch_disable(usbh_core_type *uhost, uint8_t chn) -{ - usb_hch_halt(uhost->usb_reg, chn); +void usbh_ch_disable(usbh_core_type *uhost, uint8_t chn) { + usb_hch_halt(uhost->usb_reg, chn); } /** @@ -689,17 +642,16 @@ void usbh_ch_disable(usbh_core_type *uhost, uint8_t chn) * @param ept_addr: endpoint address * @retval usb_sts_type */ -uint16_t usbh_alloc_channel(usbh_core_type *uhost, uint8_t ept_addr) -{ - /* get one free channel */ - uint16_t ch_num = usbh_get_free_channel(uhost); +uint16_t usbh_alloc_channel(usbh_core_type *uhost, uint8_t ept_addr) { + /* get one free channel */ + uint16_t ch_num = usbh_get_free_channel(uhost); - if(ch_num == HCH_ERROR) - return USB_FAIL; + if (ch_num == HCH_ERROR) + return USB_FAIL; - /* set channel to used */ - uhost->channel[ch_num] = HCH_USED | ept_addr; - return ch_num; + /* set channel to used */ + uhost->channel[ch_num] = HCH_USED | ept_addr; + return ch_num; } /** @@ -708,9 +660,8 @@ uint16_t usbh_alloc_channel(usbh_core_type *uhost, uint8_t ept_addr) * @param ch_num: channel number * @retval urb_sts_type: urb status */ -urb_sts_type usbh_get_urb_status(usbh_core_type *uhost, uint8_t ch_num) -{ - return uhost->urb_state[ch_num]; +urb_sts_type usbh_get_urb_status(usbh_core_type *uhost, uint8_t ch_num) { + return uhost->urb_state[ch_num]; } /** * @brief usb wait control setup complete @@ -719,31 +670,25 @@ urb_sts_type usbh_get_urb_status(usbh_core_type *uhost, uint8_t ch_num) * @param next_enum_state: next enum state when setup complete * @retval status: usb_sts_type status */ -usb_sts_type usbh_ctrl_result_check(usbh_core_type *uhost, ctrl_ept0_sts_type next_ctrl_state, uint8_t next_enum_state) -{ - usb_sts_type status; +usb_sts_type usbh_ctrl_result_check(usbh_core_type *uhost, ctrl_ept0_sts_type next_ctrl_state, uint8_t next_enum_state) { + usb_sts_type status; - /* control transfer loop */ - status = usbh_ctrl_transfer_loop(uhost); + /* control transfer loop */ + status = usbh_ctrl_transfer_loop(uhost); - if(status == USB_OK) - { - uhost->ctrl.state = next_ctrl_state; - uhost->enum_state = next_enum_state; - uhost->req_state = CMD_SEND; - } - else if(status == USB_ERROR) - { - uhost->ctrl.state = CONTROL_IDLE; - uhost->req_state = CMD_SEND; - } - else if(status == USB_NOT_SUPPORT) - { - uhost->ctrl.state = next_ctrl_state; - uhost->enum_state = next_enum_state; - uhost->req_state = CMD_SEND; - } - return status; + if (status == USB_OK) { + uhost->ctrl.state = next_ctrl_state; + uhost->enum_state = next_enum_state; + uhost->req_state = CMD_SEND; + } else if (status == USB_ERROR) { + uhost->ctrl.state = CONTROL_IDLE; + uhost->req_state = CMD_SEND; + } else if (status == USB_NOT_SUPPORT) { + uhost->ctrl.state = next_ctrl_state; + uhost->enum_state = next_enum_state; + uhost->req_state = CMD_SEND; + } + return status; } /** @@ -751,12 +696,11 @@ usb_sts_type usbh_ctrl_result_check(usbh_core_type *uhost, ctrl_ept0_sts_type ne * @param none * @retval address (1...20) */ -uint8_t usbh_alloc_address(void) -{ - static uint8_t address = 1; - if(address == 20) - address = 1; - return address ++; +uint8_t usbh_alloc_address(void) { + static uint8_t address = 1; + if (address == 20) + address = 1; + return address ++; } @@ -765,167 +709,148 @@ uint8_t usbh_alloc_address(void) * @param uhost: to the structure of usbh_core_type * @retval status: usb_sts_type status */ -usb_sts_type usbh_enum_handler(usbh_core_type *uhost) -{ - usb_sts_type status = USB_WAIT; - switch(uhost->enum_state) - { - case ENUM_IDLE: - break; - case ENUM_GET_MIN_DESC: - /* get description */ - if(uhost->ctrl.state == CONTROL_IDLE) - { - usbh_get_device_descriptor(uhost, 8); - } - if(usbh_ctrl_result_check(uhost, CONTROL_IDLE, ENUM_GET_FULL_DESC) == USB_OK) - { - usbh_parse_dev_desc(uhost, uhost->rx_buffer, 8); +usb_sts_type usbh_enum_handler(usbh_core_type *uhost) { + usb_sts_type status = USB_WAIT; + switch (uhost->enum_state) { + case ENUM_IDLE: + break; + case ENUM_GET_MIN_DESC: + /* get description */ + if (uhost->ctrl.state == CONTROL_IDLE) { + usbh_get_device_descriptor(uhost, 8); + } + if (usbh_ctrl_result_check(uhost, CONTROL_IDLE, ENUM_GET_FULL_DESC) == USB_OK) { + usbh_parse_dev_desc(uhost, uhost->rx_buffer, 8); - /* set new control endpoint maxpacket size */ - uhost->ctrl.ept0_size = (uhost->dev).dev_desc.bMaxPacketSize0; + /* set new control endpoint maxpacket size */ + uhost->ctrl.ept0_size = (uhost->dev).dev_desc.bMaxPacketSize0; - /* enable channel */ - usbh_hc_open(uhost, uhost->ctrl.hch_in,0x80, - uhost->dev.address, EPT_CONTROL_TYPE, - uhost->ctrl.ept0_size, - uhost->dev.speed); + /* enable channel */ + usbh_hc_open(uhost, uhost->ctrl.hch_in, 0x80, + uhost->dev.address, EPT_CONTROL_TYPE, + uhost->ctrl.ept0_size, + uhost->dev.speed); - /* enable channel */ - usbh_hc_open(uhost, uhost->ctrl.hch_out,0x00, - uhost->dev.address, EPT_CONTROL_TYPE, - uhost->ctrl.ept0_size, - uhost->dev.speed); - } - break; + /* enable channel */ + usbh_hc_open(uhost, uhost->ctrl.hch_out, 0x00, + uhost->dev.address, EPT_CONTROL_TYPE, + uhost->ctrl.ept0_size, + uhost->dev.speed); + } + break; - case ENUM_GET_FULL_DESC: - /* get description */ - if(uhost->ctrl.state == CONTROL_IDLE) - { - usbh_get_device_descriptor(uhost, 18); - } - if(usbh_ctrl_result_check(uhost, CONTROL_IDLE, ENUM_SET_ADDR) == USB_OK) - { - usbh_parse_dev_desc(uhost, uhost->rx_buffer, 18); - USBH_DEBUG("VID: %xh", uhost->dev.dev_desc.idVendor); - USBH_DEBUG("PID: %xh", uhost->dev.dev_desc.idProduct); - } - break; + case ENUM_GET_FULL_DESC: + /* get description */ + if (uhost->ctrl.state == CONTROL_IDLE) { + usbh_get_device_descriptor(uhost, 18); + } + if (usbh_ctrl_result_check(uhost, CONTROL_IDLE, ENUM_SET_ADDR) == USB_OK) { + usbh_parse_dev_desc(uhost, uhost->rx_buffer, 18); + USBH_DEBUG("VID: %xh", uhost->dev.dev_desc.idVendor); + USBH_DEBUG("PID: %xh", uhost->dev.dev_desc.idProduct); + } + break; - case ENUM_SET_ADDR: - /* set device address */ - if(uhost->ctrl.state == CONTROL_IDLE) - { - uhost->dev.address = usbh_alloc_address(); - USBH_DEBUG("Set Address: %d", uhost->dev.address); - usbh_set_address(uhost, uhost->dev.address); - } - if (usbh_ctrl_result_check(uhost, CONTROL_IDLE, ENUM_GET_CFG) == USB_OK) - { - /* enable channel */ - usbh_hc_open(uhost, uhost->ctrl.hch_in,0x80, - uhost->dev.address, EPT_CONTROL_TYPE, - uhost->ctrl.ept0_size, - uhost->dev.speed); + case ENUM_SET_ADDR: + /* set device address */ + if (uhost->ctrl.state == CONTROL_IDLE) { + uhost->dev.address = usbh_alloc_address(); + USBH_DEBUG("Set Address: %d", uhost->dev.address); + usbh_set_address(uhost, uhost->dev.address); + } + if (usbh_ctrl_result_check(uhost, CONTROL_IDLE, ENUM_GET_CFG) == USB_OK) { + /* enable channel */ + usbh_hc_open(uhost, uhost->ctrl.hch_in, 0x80, + uhost->dev.address, EPT_CONTROL_TYPE, + uhost->ctrl.ept0_size, + uhost->dev.speed); - /* enable channel */ - usbh_hc_open(uhost, uhost->ctrl.hch_out,0x00, - uhost->dev.address, EPT_CONTROL_TYPE, - uhost->ctrl.ept0_size, - uhost->dev.speed); - } - break; + /* enable channel */ + usbh_hc_open(uhost, uhost->ctrl.hch_out, 0x00, + uhost->dev.address, EPT_CONTROL_TYPE, + uhost->ctrl.ept0_size, + uhost->dev.speed); + } + break; - case ENUM_GET_CFG: - /* get device confiuration */ - if(uhost->ctrl.state == CONTROL_IDLE) - { - usbh_get_configure_descriptor(uhost, 9); - } + case ENUM_GET_CFG: + /* get device confiuration */ + if (uhost->ctrl.state == CONTROL_IDLE) { + usbh_get_configure_descriptor(uhost, 9); + } - if(usbh_ctrl_result_check(uhost, CONTROL_IDLE, ENUM_GET_FULL_CFG) == USB_OK) - { - usbh_parse_configure_desc(uhost, uhost->rx_buffer, 9); - } - break; + if (usbh_ctrl_result_check(uhost, CONTROL_IDLE, ENUM_GET_FULL_CFG) == USB_OK) { + usbh_parse_configure_desc(uhost, uhost->rx_buffer, 9); + } + break; - case ENUM_GET_FULL_CFG: - /* get device confiuration */ - if(uhost->ctrl.state == CONTROL_IDLE) - { - usbh_get_configure_descriptor(uhost, uhost->dev.cfg_desc.cfg.wTotalLength); - } + case ENUM_GET_FULL_CFG: + /* get device confiuration */ + if (uhost->ctrl.state == CONTROL_IDLE) { + usbh_get_configure_descriptor(uhost, uhost->dev.cfg_desc.cfg.wTotalLength); + } - if(usbh_ctrl_result_check(uhost, CONTROL_IDLE, ENUM_GET_MFC_STRING) == USB_OK) - { - usbh_parse_configure_desc(uhost, uhost->rx_buffer, uhost->dev.cfg_desc.cfg.wTotalLength); - } - break; + if (usbh_ctrl_result_check(uhost, CONTROL_IDLE, ENUM_GET_MFC_STRING) == USB_OK) { + usbh_parse_configure_desc(uhost, uhost->rx_buffer, uhost->dev.cfg_desc.cfg.wTotalLength); + } + break; - case ENUM_GET_MFC_STRING: - /* get device mfc string */ - if(uhost->ctrl.state == CONTROL_IDLE) - { - usbh_get_sting_descriptor(uhost, uhost->dev.dev_desc.iManufacturer, - uhost->rx_buffer, 0xFF); - } + case ENUM_GET_MFC_STRING: + /* get device mfc string */ + if (uhost->ctrl.state == CONTROL_IDLE) { + usbh_get_sting_descriptor(uhost, uhost->dev.dev_desc.iManufacturer, + uhost->rx_buffer, 0xFF); + } - if(usbh_ctrl_result_check(uhost, CONTROL_IDLE, ENUM_GET_PRODUCT_STRING) == USB_OK) - { - usbh_parse_string_desc(uhost->rx_buffer, uhost->rx_buffer, 0xFF); - uhost->user_handler->user_mfc_string(uhost->rx_buffer); - } - break; + if (usbh_ctrl_result_check(uhost, CONTROL_IDLE, ENUM_GET_PRODUCT_STRING) == USB_OK) { + usbh_parse_string_desc(uhost->rx_buffer, uhost->rx_buffer, 0xFF); + uhost->user_handler->user_mfc_string(uhost->rx_buffer); + } + break; - case ENUM_GET_PRODUCT_STRING: - /* get device product string */ - if(uhost->ctrl.state == CONTROL_IDLE) - { - usbh_get_sting_descriptor(uhost, uhost->dev.dev_desc.iProduct, - uhost->rx_buffer, 0xFF); - } + case ENUM_GET_PRODUCT_STRING: + /* get device product string */ + if (uhost->ctrl.state == CONTROL_IDLE) { + usbh_get_sting_descriptor(uhost, uhost->dev.dev_desc.iProduct, + uhost->rx_buffer, 0xFF); + } - if(usbh_ctrl_result_check(uhost, CONTROL_IDLE, ENUM_GET_SERIALNUM_STRING) == USB_OK) - { - usbh_parse_string_desc(uhost->rx_buffer, uhost->rx_buffer, 0xFF); - uhost->user_handler->user_product_string(uhost->rx_buffer); - } - break; + if (usbh_ctrl_result_check(uhost, CONTROL_IDLE, ENUM_GET_SERIALNUM_STRING) == USB_OK) { + usbh_parse_string_desc(uhost->rx_buffer, uhost->rx_buffer, 0xFF); + uhost->user_handler->user_product_string(uhost->rx_buffer); + } + break; - case ENUM_GET_SERIALNUM_STRING: - /* get device serial string */ - if(uhost->ctrl.state == CONTROL_IDLE) - { - usbh_get_sting_descriptor(uhost, uhost->dev.dev_desc.iSerialNumber, - uhost->rx_buffer, 0xFF); - } + case ENUM_GET_SERIALNUM_STRING: + /* get device serial string */ + if (uhost->ctrl.state == CONTROL_IDLE) { + usbh_get_sting_descriptor(uhost, uhost->dev.dev_desc.iSerialNumber, + uhost->rx_buffer, 0xFF); + } - if(usbh_ctrl_result_check(uhost, CONTROL_IDLE, ENUM_SET_CONFIG) == USB_OK) - { - usbh_parse_string_desc(uhost->rx_buffer, uhost->rx_buffer, 0xFF); - uhost->user_handler->user_serial_string(uhost->rx_buffer); - } - break; + if (usbh_ctrl_result_check(uhost, CONTROL_IDLE, ENUM_SET_CONFIG) == USB_OK) { + usbh_parse_string_desc(uhost->rx_buffer, uhost->rx_buffer, 0xFF); + uhost->user_handler->user_serial_string(uhost->rx_buffer); + } + break; - case ENUM_SET_CONFIG: - /* set device config */ - if(uhost->ctrl.state == CONTROL_IDLE) - { - usbh_set_configuration(uhost, uhost->dev.cfg_desc.cfg.bConfigurationValue); - } - usbh_ctrl_result_check(uhost, CONTROL_IDLE, ENUM_COMPLETE); + case ENUM_SET_CONFIG: + /* set device config */ + if (uhost->ctrl.state == CONTROL_IDLE) { + usbh_set_configuration(uhost, uhost->dev.cfg_desc.cfg.bConfigurationValue); + } + usbh_ctrl_result_check(uhost, CONTROL_IDLE, ENUM_COMPLETE); - break; + break; - case ENUM_COMPLETE: - /* enum complete */ - status = USB_OK; - break; - default: - break; - } - return status; + case ENUM_COMPLETE: + /* enum complete */ + status = USB_OK; + break; + default: + break; + } + return status; } /** @@ -934,9 +859,8 @@ usb_sts_type usbh_enum_handler(usbh_core_type *uhost) * @param state: vbus state * @retval none */ -void usbh_active_vbus(usbh_core_type *uhost, confirm_state state) -{ - uhost->user_handler->user_active_vbus(uhost, state); +void usbh_active_vbus(usbh_core_type *uhost, confirm_state state) { + uhost->user_handler->user_active_vbus(uhost, state); } /** @@ -944,23 +868,22 @@ void usbh_active_vbus(usbh_core_type *uhost, confirm_state state) * @param usbx: to the structure of otg_global_type * @retval none */ -void usbh_reset_port(usbh_core_type *uhost) -{ - otg_host_type *usb_host = OTG_HOST(uhost->usb_reg); - uint32_t hprt_val = usb_host->hprt; +void usbh_reset_port(usbh_core_type *uhost) { + otg_host_type *usb_host = OTG_HOST(uhost->usb_reg); + uint32_t hprt_val = usb_host->hprt; - hprt_val &= ~(USB_OTG_HPRT_PRTENA | USB_OTG_HPRT_PRTENCHNG | - USB_OTG_HPRT_PRTOVRCACT | USB_OTG_HPRT_PRTCONDET); + hprt_val &= ~(USB_OTG_HPRT_PRTENA | USB_OTG_HPRT_PRTENCHNG | + USB_OTG_HPRT_PRTOVRCACT | USB_OTG_HPRT_PRTCONDET); - /* set port reset */ - usb_host->hprt = hprt_val | USB_OTG_HPRT_PRTRST; + /* set port reset */ + usb_host->hprt = hprt_val | USB_OTG_HPRT_PRTRST; - usb_delay_ms(100); + usb_delay_ms(100); - /* clear port reset */ - usb_host->hprt = hprt_val & (~USB_OTG_HPRT_PRTRST); + /* clear port reset */ + usb_host->hprt = hprt_val & (~USB_OTG_HPRT_PRTRST); - usb_delay_ms(20); + usb_delay_ms(20); } @@ -969,37 +892,36 @@ void usbh_reset_port(usbh_core_type *uhost) * @param uhost: to the structure of usbh_core_type * @retval none */ -static void usbh_attached(usbh_core_type *uhost) -{ - /* get free channel */ - uhost->ctrl.hch_in = usbh_alloc_channel(uhost, 0x80); - uhost->ctrl.hch_out = usbh_alloc_channel(uhost, 0x00); +static void usbh_attached(usbh_core_type *uhost) { + /* get free channel */ + uhost->ctrl.hch_in = usbh_alloc_channel(uhost, 0x80); + uhost->ctrl.hch_out = usbh_alloc_channel(uhost, 0x00); - /* user reset callback handler */ - uhost->user_handler->user_reset(); + /* user reset callback handler */ + uhost->user_handler->user_reset(); - /* get device speed */ - uhost->dev.speed = OTG_HOST(uhost->usb_reg)->hprt_bit.prtspd; - uhost->global_state = USBH_ENUMERATION; - uhost->user_handler->user_speed(uhost->dev.speed); + /* get device speed */ + uhost->dev.speed = OTG_HOST(uhost->usb_reg)->hprt_bit.prtspd; + uhost->global_state = USBH_ENUMERATION; + uhost->user_handler->user_speed(uhost->dev.speed); - /* enable channel */ - usbh_hc_open(uhost, uhost->ctrl.hch_in,0x80, - uhost->dev.address, EPT_CONTROL_TYPE, - uhost->ctrl.ept0_size, - uhost->dev.speed); + /* enable channel */ + usbh_hc_open(uhost, uhost->ctrl.hch_in, 0x80, + uhost->dev.address, EPT_CONTROL_TYPE, + uhost->ctrl.ept0_size, + uhost->dev.speed); - /* enable channel */ - usbh_hc_open(uhost, uhost->ctrl.hch_out,0x00, - uhost->dev.address, EPT_CONTROL_TYPE, - uhost->ctrl.ept0_size, - uhost->dev.speed); + /* enable channel */ + usbh_hc_open(uhost, uhost->ctrl.hch_out, 0x00, + uhost->dev.address, EPT_CONTROL_TYPE, + uhost->ctrl.ept0_size, + uhost->dev.speed); - usb_flush_tx_fifo(uhost->usb_reg, 0x10); - usb_flush_rx_fifo(uhost->usb_reg); + usb_flush_tx_fifo(uhost->usb_reg, 0x10); + usb_flush_rx_fifo(uhost->usb_reg); - /* user attached callback */ - uhost->user_handler->user_attached(); + /* user attached callback */ + uhost->user_handler->user_attached(); } @@ -1008,15 +930,13 @@ static void usbh_attached(usbh_core_type *uhost) * @param uhost: to the structure of usbh_core_type * @retval none */ -static void usbh_enumeration(usbh_core_type *uhost) -{ - /* enumeration process */ - if(usbh_enum_handler(uhost) == USB_OK) - { - /* user enumeration done callback */ - uhost->user_handler->user_enumeration_done(); - uhost->global_state = USBH_USER_HANDLER; - } +static void usbh_enumeration(usbh_core_type *uhost) { + /* enumeration process */ + if (usbh_enum_handler(uhost) == USB_OK) { + /* user enumeration done callback */ + uhost->user_handler->user_enumeration_done(); + uhost->global_state = USBH_USER_HANDLER; + } } /** @@ -1024,24 +944,18 @@ static void usbh_enumeration(usbh_core_type *uhost) * @param uhost: to the structure of usbh_core_type * @retval none */ -static void usbh_class_request(usbh_core_type *uhost) -{ - usb_sts_type status; +static void usbh_class_request(usbh_core_type *uhost) { + usb_sts_type status; - /* class request callback */ - status = uhost->class_handler->request_handler((void *)uhost); - if(status == USB_OK) - { - uhost->global_state = USBH_CLASS; - } - else if(status == USB_ERROR || status == USB_FAIL) - { - uhost->global_state = USBH_ERROR_STATE; - } - else if(status == USB_NOT_SUPPORT) - { - uhost->global_state = USBH_ERROR_STATE; - } + /* class request callback */ + status = uhost->class_handler->request_handler((void *)uhost); + if (status == USB_OK) { + uhost->global_state = USBH_CLASS; + } else if (status == USB_ERROR || status == USB_FAIL) { + uhost->global_state = USBH_ERROR_STATE; + } else if (status == USB_NOT_SUPPORT) { + uhost->global_state = USBH_ERROR_STATE; + } } /** @@ -1049,12 +963,10 @@ static void usbh_class_request(usbh_core_type *uhost) * @param uhost: to the structure of usbh_core_type * @retval none */ -static void usbh_class(usbh_core_type *uhost) -{ - /* process handler */ - if(uhost->class_handler->process_handler((void *)uhost) == USB_OK) - { - } +static void usbh_class(usbh_core_type *uhost) { + /* process handler */ + if (uhost->class_handler->process_handler((void *)uhost) == USB_OK) { + } } /** @@ -1062,21 +974,18 @@ static void usbh_class(usbh_core_type *uhost) * @param uhost: to the structure of usbh_core_type * @retval none */ -static void usbh_suspend(usbh_core_type *uhost) -{ - /* set device feature */ - if(uhost->ctrl.state == CONTROL_IDLE) - { - usbh_set_feature(uhost, 0x01, 0); - } - if(usbh_ctrl_result_check(uhost, CONTROL_IDLE, ENUM_IDLE) == USB_OK) - { - /* enter suspend mode */ - usb_delay_ms(3); - usbh_enter_suspend(uhost); - uhost->global_state = USBH_SUSPENDED; +static void usbh_suspend(usbh_core_type *uhost) { + /* set device feature */ + if (uhost->ctrl.state == CONTROL_IDLE) { + usbh_set_feature(uhost, 0x01, 0); + } + if (usbh_ctrl_result_check(uhost, CONTROL_IDLE, ENUM_IDLE) == USB_OK) { + /* enter suspend mode */ + usb_delay_ms(3); + usbh_enter_suspend(uhost); + uhost->global_state = USBH_SUSPENDED; - } + } } /** @@ -1084,20 +993,17 @@ static void usbh_suspend(usbh_core_type *uhost) * @param uhost: to the structure of usbh_core_type * @retval none */ -static void usbh_wakeup(usbh_core_type *uhost) -{ - /* clear device feature */ - if(uhost->ctrl.state == CONTROL_IDLE) - { - /* usb host resume */ - usbh_resume(uhost); - usbh_clear_dev_feature(uhost, 0x01, 0); - } - if(usbh_ctrl_result_check(uhost, CONTROL_IDLE, ENUM_IDLE) == USB_OK) - { - uhost->global_state = USBH_CLASS_REQUEST; - USBH_DEBUG("Remote Wakeup"); - } +static void usbh_wakeup(usbh_core_type *uhost) { + /* clear device feature */ + if (uhost->ctrl.state == CONTROL_IDLE) { + /* usb host resume */ + usbh_resume(uhost); + usbh_clear_dev_feature(uhost, 0x01, 0); + } + if (usbh_ctrl_result_check(uhost, CONTROL_IDLE, ENUM_IDLE) == USB_OK) { + uhost->global_state = USBH_CLASS_REQUEST; + USBH_DEBUG("Remote Wakeup"); + } } /** @@ -1105,30 +1011,27 @@ static void usbh_wakeup(usbh_core_type *uhost) * @param uhost: to the structure of usbh_core_type * @retval none */ -static void usbh_disconnect(usbh_core_type *uhost) -{ - uint8_t i_index = 0; +static void usbh_disconnect(usbh_core_type *uhost) { + uint8_t i_index = 0; - /* set host to default state */ - usbh_cfg_default_init(uhost); + /* set host to default state */ + usbh_cfg_default_init(uhost); - /* free host channel */ - for(i_index = 0; i_index < USB_HOST_CHANNEL_NUM; i_index ++) - { - usbh_free_channel(uhost, i_index); - } + /* free host channel */ + for (i_index = 0; i_index < USB_HOST_CHANNEL_NUM; i_index ++) { + usbh_free_channel(uhost, i_index); + } - /* call class reset handler */ - if(uhost->class_handler->reset_handler != NULL) - { - uhost->class_handler->reset_handler(uhost); - } + /* call class reset handler */ + if (uhost->class_handler->reset_handler != NULL) { + uhost->class_handler->reset_handler(uhost); + } - /* set global state to idle */ - uhost->global_state = USBH_IDLE; + /* set global state to idle */ + uhost->global_state = USBH_IDLE; - /*call user disconnect function */ - uhost->user_handler->user_disconnect(); + /*call user disconnect function */ + uhost->user_handler->user_disconnect(); } @@ -1137,93 +1040,87 @@ static void usbh_disconnect(usbh_core_type *uhost) * @param uhost: to the structure of usbh_core_type * @retval none */ -usb_sts_type usbh_loop_handler(usbh_core_type *uhost) -{ - usb_sts_type status = USB_FAIL; +usb_sts_type usbh_loop_handler(usbh_core_type *uhost) { + usb_sts_type status = USB_FAIL; - if(uhost->conn_sts == 0 && - uhost->global_state != USBH_IDLE && - uhost->global_state != USBH_DISCONNECT) - { - uhost->global_state = USBH_IDLE; - } - switch(uhost->global_state) - { - case USBH_IDLE: - if(uhost->conn_sts == 1) - { - uhost->global_state = USBH_PORT_EN; + if (uhost->conn_sts == 0 && + uhost->global_state != USBH_IDLE && + uhost->global_state != USBH_DISCONNECT) { + uhost->global_state = USBH_IDLE; + } + switch (uhost->global_state) { + case USBH_IDLE: + if (uhost->conn_sts == 1) { + uhost->global_state = USBH_PORT_EN; - /* wait stable */ - usb_delay_ms(200); + /* wait stable */ + usb_delay_ms(200); - /* port reset */ - usbh_reset_port(uhost); + /* port reset */ + usbh_reset_port(uhost); - /* user reset */ - uhost->user_handler->user_reset(); - } - break; + /* user reset */ + uhost->user_handler->user_reset(); + } + break; - case USBH_PORT_EN: - if(uhost->port_enable) - { - uhost->global_state = USBH_ATTACHED; - usb_delay_ms(50); - } - break; + case USBH_PORT_EN: + if (uhost->port_enable) { + uhost->global_state = USBH_ATTACHED; + usb_delay_ms(50); + } + break; - case USBH_ATTACHED: - usbh_attached(uhost); - break; + case USBH_ATTACHED: + usbh_attached(uhost); + break; - case USBH_ENUMERATION: - usbh_enumeration(uhost); - break; + case USBH_ENUMERATION: + usbh_enumeration(uhost); + break; - case USBH_USER_HANDLER: - uhost->global_state = USBH_CLASS_REQUEST; - if( uhost->class_handler->init_handler(uhost) == USB_NOT_SUPPORT) - { - uhost->global_state = USBH_UNSUPPORT; - } - break; + case USBH_USER_HANDLER: + uhost->global_state = USBH_CLASS_REQUEST; + if (uhost->class_handler->init_handler(uhost) == USB_NOT_SUPPORT) { + uhost->global_state = USBH_UNSUPPORT; + } + break; - case USBH_CLASS_REQUEST: - usbh_class_request(uhost); - break; + case USBH_CLASS_REQUEST: + usbh_class_request(uhost); + break; - case USBH_CLASS: - usbh_class(uhost); - break; + case USBH_CLASS: + usbh_class(uhost); + break; - case USBH_SUSPEND: - usbh_suspend(uhost); - break; + case USBH_SUSPEND: + usbh_suspend(uhost); + break; - case USBH_SUSPENDED: - break; + case USBH_SUSPENDED: + break; - case USBH_WAKEUP: - usbh_wakeup(uhost); - break; + case USBH_WAKEUP: + usbh_wakeup(uhost); + break; - case USBH_DISCONNECT: - usbh_disconnect(uhost); - break; + case USBH_DISCONNECT: + usbh_disconnect(uhost); + break; - case USBH_ERROR_STATE: - usbh_cfg_default_init(uhost); - uhost->class_handler->reset_handler(uhost); - uhost->user_handler->user_reset(); - break; - case USBH_UNSUPPORT: - break; - default: - break; - } + case USBH_ERROR_STATE: + usbh_cfg_default_init(uhost); + uhost->class_handler->reset_handler(uhost); + uhost->user_handler->user_reset(); + break; + case USBH_UNSUPPORT: + break; + default: + break; + } - return status; + return status; } /** diff --git a/armlib/at32_usb/usb_drivers/src/usbh_ctrl.c b/armlib/at32_usb/usb_drivers/src/usbh_ctrl.c index 98f92b48e..3834ba671 100644 --- a/armlib/at32_usb/usb_drivers/src/usbh_ctrl.c +++ b/armlib/at32_usb/usb_drivers/src/usbh_ctrl.c @@ -48,14 +48,13 @@ * @param hc_num: channel number * @retval status: usb_sts_type status */ -usb_sts_type usbh_ctrl_send_setup(usbh_core_type *uhost, uint8_t *buffer, uint8_t hc_num) -{ - uhost->hch[hc_num].dir = 0; - uhost->hch[hc_num].data_pid = HCH_PID_SETUP; - uhost->hch[hc_num].trans_buf = buffer; - uhost->hch[hc_num].trans_len = 8; /*setup */ +usb_sts_type usbh_ctrl_send_setup(usbh_core_type *uhost, uint8_t *buffer, uint8_t hc_num) { + uhost->hch[hc_num].dir = 0; + uhost->hch[hc_num].data_pid = HCH_PID_SETUP; + uhost->hch[hc_num].trans_buf = buffer; + uhost->hch[hc_num].trans_len = 8; /*setup */ - return usbh_in_out_request(uhost, hc_num); + return usbh_in_out_request(uhost, hc_num); } /** @@ -67,14 +66,13 @@ usb_sts_type usbh_ctrl_send_setup(usbh_core_type *uhost, uint8_t *buffer, uint8_ * @retval status: usb_sts_type status */ usb_sts_type usbh_ctrl_recv_data(usbh_core_type *uhost, uint8_t *buffer, - uint16_t length, uint16_t hc_num) -{ - uhost->hch[hc_num].dir = 1; - uhost->hch[hc_num].data_pid = HCH_PID_DATA1; - uhost->hch[hc_num].trans_buf = buffer; - uhost->hch[hc_num].trans_len = length; + uint16_t length, uint16_t hc_num) { + uhost->hch[hc_num].dir = 1; + uhost->hch[hc_num].data_pid = HCH_PID_DATA1; + uhost->hch[hc_num].trans_buf = buffer; + uhost->hch[hc_num].trans_len = length; - return usbh_in_out_request(uhost, hc_num); + return usbh_in_out_request(uhost, hc_num); } /** @@ -86,25 +84,20 @@ usb_sts_type usbh_ctrl_recv_data(usbh_core_type *uhost, uint8_t *buffer, * @retval status: usb_sts_type status */ usb_sts_type usbh_ctrl_send_data(usbh_core_type *uhost, uint8_t *buffer, - uint16_t length, uint16_t hc_num) -{ - uhost->hch[hc_num].dir = 0; - uhost->hch[hc_num].trans_buf = buffer; - uhost->hch[hc_num].trans_len = length; + uint16_t length, uint16_t hc_num) { + uhost->hch[hc_num].dir = 0; + uhost->hch[hc_num].trans_buf = buffer; + uhost->hch[hc_num].trans_len = length; - if(length == 0) - { - uhost->hch[uhost->ctrl.hch_out].toggle_out = 1; - } - if(uhost->hch[uhost->ctrl.hch_out].toggle_out == 0) - { - uhost->hch[hc_num].data_pid = HCH_PID_DATA0; - } - else - { - uhost->hch[hc_num].data_pid = HCH_PID_DATA1; - } - return usbh_in_out_request(uhost, hc_num); + if (length == 0) { + uhost->hch[uhost->ctrl.hch_out].toggle_out = 1; + } + if (uhost->hch[uhost->ctrl.hch_out].toggle_out == 0) { + uhost->hch[hc_num].data_pid = HCH_PID_DATA0; + } else { + uhost->hch[hc_num].data_pid = HCH_PID_DATA1; + } + return usbh_in_out_request(uhost, hc_num); } /** @@ -112,12 +105,11 @@ usb_sts_type usbh_ctrl_send_data(usbh_core_type *uhost, uint8_t *buffer, * @param uhost: to the structure of usbh_core_type * @retval status: usb_sts_type status */ -usb_sts_type usbh_ctrl_setup_handler(usbh_core_type *uhost) -{ - usbh_ctrl_send_setup(uhost, (uint8_t *)(&uhost->ctrl.setup), - uhost->ctrl.hch_out); - uhost->ctrl.state = CONTROL_SETUP_WAIT; - return USB_OK; +usb_sts_type usbh_ctrl_setup_handler(usbh_core_type *uhost) { + usbh_ctrl_send_setup(uhost, (uint8_t *)(&uhost->ctrl.setup), + uhost->ctrl.hch_out); + uhost->ctrl.state = CONTROL_SETUP_WAIT; + return USB_OK; } /** @@ -126,59 +118,43 @@ usb_sts_type usbh_ctrl_setup_handler(usbh_core_type *uhost) * @param timeout: pointer of wait timeout * @retval status: usb_sts_type status */ -usb_sts_type usbh_ctrl_setup_wait_handler(usbh_core_type *uhost, uint32_t *timeout) -{ - urb_sts_type urb_state; - usb_sts_type status = USB_WAIT; - uint8_t dir; - urb_state = uhost->urb_state[uhost->ctrl.hch_out]; - if(urb_state == URB_DONE) - { - dir = uhost->ctrl.setup.bmRequestType & USB_REQUEST_DIR_MASK; - if(uhost->ctrl.setup.wLength != 0) - { - *timeout = DATA_STAGE_TIMEOUT; - if(dir == USB_DIR_D2H) //in - { - uhost->ctrl.state = CONTROL_DATA_IN; - } - else //out - { - uhost->ctrl.state = CONTROL_DATA_OUT; - } +usb_sts_type usbh_ctrl_setup_wait_handler(usbh_core_type *uhost, uint32_t *timeout) { + urb_sts_type urb_state; + usb_sts_type status = USB_WAIT; + uint8_t dir; + urb_state = uhost->urb_state[uhost->ctrl.hch_out]; + if (urb_state == URB_DONE) { + dir = uhost->ctrl.setup.bmRequestType & USB_REQUEST_DIR_MASK; + if (uhost->ctrl.setup.wLength != 0) { + *timeout = DATA_STAGE_TIMEOUT; + if (dir == USB_DIR_D2H) { //in + uhost->ctrl.state = CONTROL_DATA_IN; + } else { //out + uhost->ctrl.state = CONTROL_DATA_OUT; + } + } else { + *timeout = NODATA_STAGE_TIMEOUT; + if (dir == USB_DIR_D2H) { //no data, send status + uhost->ctrl.state = CONTROL_STATUS_OUT; + } else { //out + uhost->ctrl.state = CONTROL_STATUS_IN; + } + } + uhost->ctrl.timer = uhost->timer; + status = USB_OK; + } else if (urb_state == URB_ERROR || urb_state == URB_NOTREADY) { + uhost->ctrl.state = CONTROL_ERROR; + uhost->ctrl.sts = CTRL_XACTERR; + status = USB_ERROR; + } else { + /* wait nak timeout 5s*/ + if (uhost->timer - uhost->ctrl.timer > CTRL_TIMEOUT) { + uhost->ctrl.state = CONTROL_ERROR; + uhost->ctrl.sts = CTRL_XACTERR; + status = USB_ERROR; + } } - else - { - *timeout = NODATA_STAGE_TIMEOUT; - if(dir == USB_DIR_D2H) //no data, send status - { - uhost->ctrl.state = CONTROL_STATUS_OUT; - } - else //out - { - uhost->ctrl.state = CONTROL_STATUS_IN; - } - } - uhost->ctrl.timer = uhost->timer; - status = USB_OK; - } - else if(urb_state == URB_ERROR || urb_state == URB_NOTREADY) - { - uhost->ctrl.state = CONTROL_ERROR; - uhost->ctrl.sts = CTRL_XACTERR; - status = USB_ERROR; - } - else - { - /* wait nak timeout 5s*/ - if(uhost->timer - uhost->ctrl.timer > CTRL_TIMEOUT) - { - uhost->ctrl.state = CONTROL_ERROR; - uhost->ctrl.sts = CTRL_XACTERR; - status = USB_ERROR; - } - } - return status; + return status; } /** @@ -186,15 +162,14 @@ usb_sts_type usbh_ctrl_setup_wait_handler(usbh_core_type *uhost, uint32_t *timeo * @param uhost: to the structure of usbh_core_type * @retval status: usb_sts_type status */ -usb_sts_type usbh_ctrl_data_in_handler(usbh_core_type *uhost) -{ - usb_sts_type status = USB_OK; - usbh_ctrl_recv_data(uhost, uhost->ctrl.buffer, - uhost->ctrl.len, - uhost->ctrl.hch_in); - uhost->ctrl.state = CONTROL_DATA_IN_WAIT; +usb_sts_type usbh_ctrl_data_in_handler(usbh_core_type *uhost) { + usb_sts_type status = USB_OK; + usbh_ctrl_recv_data(uhost, uhost->ctrl.buffer, + uhost->ctrl.len, + uhost->ctrl.hch_in); + uhost->ctrl.state = CONTROL_DATA_IN_WAIT; - return status; + return status; } /** @@ -203,36 +178,27 @@ usb_sts_type usbh_ctrl_data_in_handler(usbh_core_type *uhost) * @param timeout: wait timeout * @retval status: usb_sts_type status */ -usb_sts_type usbh_ctrl_data_in_wait_handler(usbh_core_type *uhost, uint32_t timeout) -{ - usb_sts_type status = USB_OK; - urb_sts_type urb_state; - urb_state = uhost->urb_state[uhost->ctrl.hch_in]; +usb_sts_type usbh_ctrl_data_in_wait_handler(usbh_core_type *uhost, uint32_t timeout) { + usb_sts_type status = USB_OK; + urb_sts_type urb_state; + urb_state = uhost->urb_state[uhost->ctrl.hch_in]; + + if (urb_state == URB_DONE) { + uhost->ctrl.state = CONTROL_STATUS_OUT; + } else if (urb_state == URB_STALL) { + uhost->ctrl.state = CONTROL_STALL; + } else if (urb_state == URB_ERROR) { + uhost->ctrl.state = CONTROL_ERROR; + } else { + /* wait nak timeout 5s*/ + if (uhost->timer - uhost->ctrl.timer > CTRL_TIMEOUT) { + uhost->ctrl.state = CONTROL_ERROR; + uhost->ctrl.sts = CTRL_XACTERR; + status = USB_ERROR; + } - if(urb_state == URB_DONE) - { - uhost->ctrl.state = CONTROL_STATUS_OUT; - } - else if(urb_state == URB_STALL) - { - uhost->ctrl.state = CONTROL_STALL; - } - else if(urb_state == URB_ERROR) - { - uhost->ctrl.state = CONTROL_ERROR; - } - else - { - /* wait nak timeout 5s*/ - if(uhost->timer - uhost->ctrl.timer > CTRL_TIMEOUT) - { - uhost->ctrl.state = CONTROL_ERROR; - uhost->ctrl.sts = CTRL_XACTERR; - status = USB_ERROR; } - - } - return status; + return status; } /** @@ -240,17 +206,16 @@ usb_sts_type usbh_ctrl_data_in_wait_handler(usbh_core_type *uhost, uint32_t time * @param uhost: to the structure of usbh_core_type * @retval status: usb_sts_type status */ -usb_sts_type usbh_ctrl_data_out_handler(usbh_core_type *uhost) -{ - usb_sts_type status = USB_OK; - uhost->hch[uhost->ctrl.hch_out].toggle_out = 1; +usb_sts_type usbh_ctrl_data_out_handler(usbh_core_type *uhost) { + usb_sts_type status = USB_OK; + uhost->hch[uhost->ctrl.hch_out].toggle_out = 1; - usbh_ctrl_send_data(uhost, uhost->ctrl.buffer, - uhost->ctrl.len, - uhost->ctrl.hch_out); - uhost->ctrl.state = CONTROL_DATA_OUT_WAIT; + usbh_ctrl_send_data(uhost, uhost->ctrl.buffer, + uhost->ctrl.len, + uhost->ctrl.hch_out); + uhost->ctrl.state = CONTROL_DATA_OUT_WAIT; - return status; + return status; } /** @@ -259,36 +224,27 @@ usb_sts_type usbh_ctrl_data_out_handler(usbh_core_type *uhost) * @param timeout: wait timeout * @retval status: usb_sts_type status */ -usb_sts_type usbh_ctrl_data_out_wait_handler(usbh_core_type *uhost, uint32_t timeout) -{ - usb_sts_type status = USB_OK; - urb_sts_type urb_state; - urb_state = uhost->urb_state[uhost->ctrl.hch_out]; - if(urb_state == URB_DONE) - { - uhost->ctrl.state = CONTROL_STATUS_IN; - } - else if(urb_state == URB_STALL) - { - uhost->ctrl.state = CONTROL_STALL; - } - else if(urb_state == URB_ERROR) - { - uhost->ctrl.state = CONTROL_ERROR; - } - else if(urb_state == URB_NOTREADY) - { - uhost->ctrl.state = CONTROL_DATA_OUT; - } +usb_sts_type usbh_ctrl_data_out_wait_handler(usbh_core_type *uhost, uint32_t timeout) { + usb_sts_type status = USB_OK; + urb_sts_type urb_state; + urb_state = uhost->urb_state[uhost->ctrl.hch_out]; + if (urb_state == URB_DONE) { + uhost->ctrl.state = CONTROL_STATUS_IN; + } else if (urb_state == URB_STALL) { + uhost->ctrl.state = CONTROL_STALL; + } else if (urb_state == URB_ERROR) { + uhost->ctrl.state = CONTROL_ERROR; + } else if (urb_state == URB_NOTREADY) { + uhost->ctrl.state = CONTROL_DATA_OUT; + } - /* wait nak timeout 5s*/ - if((uhost->timer - uhost->ctrl.timer > CTRL_TIMEOUT) && (urb_state == URB_NOTREADY)) - { - uhost->ctrl.state = CONTROL_ERROR; - uhost->ctrl.sts = CTRL_XACTERR; - status = USB_ERROR; - } - return status; + /* wait nak timeout 5s*/ + if ((uhost->timer - uhost->ctrl.timer > CTRL_TIMEOUT) && (urb_state == URB_NOTREADY)) { + uhost->ctrl.state = CONTROL_ERROR; + uhost->ctrl.sts = CTRL_XACTERR; + status = USB_ERROR; + } + return status; } /** @@ -296,15 +252,14 @@ usb_sts_type usbh_ctrl_data_out_wait_handler(usbh_core_type *uhost, uint32_t tim * @param uhost: to the structure of usbh_core_type * @retval status: usb_sts_type status */ -usb_sts_type usbh_ctrl_status_in_handler(usbh_core_type *uhost) -{ - usb_sts_type status = USB_OK; - usbh_ctrl_recv_data(uhost, 0, 0, - uhost->ctrl.hch_in); - uhost->ctrl.state = CONTROL_STATUS_IN_WAIT; +usb_sts_type usbh_ctrl_status_in_handler(usbh_core_type *uhost) { + usb_sts_type status = USB_OK; + usbh_ctrl_recv_data(uhost, 0, 0, + uhost->ctrl.hch_in); + uhost->ctrl.state = CONTROL_STATUS_IN_WAIT; - return status; + return status; } /** @@ -313,35 +268,26 @@ usb_sts_type usbh_ctrl_status_in_handler(usbh_core_type *uhost) * @param timeout: wait timeout * @retval status: usb_sts_type status */ -usb_sts_type usbh_ctrl_status_in_wait_handler(usbh_core_type *uhost, uint32_t timeout) -{ - usb_sts_type status = USB_OK; - urb_sts_type urb_state; - urb_state = uhost->urb_state[uhost->ctrl.hch_in]; - if(urb_state == URB_DONE) - { - uhost->ctrl.state = CONTROL_COMPLETE; - } - else if(urb_state == URB_STALL) - { - uhost->ctrl.state = CONTROL_STALL; - status = USB_NOT_SUPPORT; - } - else if(urb_state == URB_ERROR) - { - uhost->ctrl.state = CONTROL_ERROR; - } - else - { - /* wait nak timeout 5s*/ - if(uhost->timer - uhost->ctrl.timer > CTRL_TIMEOUT) - { - uhost->ctrl.state = CONTROL_ERROR; - uhost->ctrl.sts = CTRL_XACTERR; - status = USB_ERROR; +usb_sts_type usbh_ctrl_status_in_wait_handler(usbh_core_type *uhost, uint32_t timeout) { + usb_sts_type status = USB_OK; + urb_sts_type urb_state; + urb_state = uhost->urb_state[uhost->ctrl.hch_in]; + if (urb_state == URB_DONE) { + uhost->ctrl.state = CONTROL_COMPLETE; + } else if (urb_state == URB_STALL) { + uhost->ctrl.state = CONTROL_STALL; + status = USB_NOT_SUPPORT; + } else if (urb_state == URB_ERROR) { + uhost->ctrl.state = CONTROL_ERROR; + } else { + /* wait nak timeout 5s*/ + if (uhost->timer - uhost->ctrl.timer > CTRL_TIMEOUT) { + uhost->ctrl.state = CONTROL_ERROR; + uhost->ctrl.sts = CTRL_XACTERR; + status = USB_ERROR; + } } - } - return status; + return status; } /** @@ -349,15 +295,14 @@ usb_sts_type usbh_ctrl_status_in_wait_handler(usbh_core_type *uhost, uint32_t ti * @param uhost: to the structure of usbh_core_type * @retval status: usb_sts_type status */ -usb_sts_type usbh_ctrl_status_out_handler(usbh_core_type *uhost) -{ - usb_sts_type status = USB_OK; - uhost->hch[uhost->ctrl.hch_out].toggle_out ^= 1; +usb_sts_type usbh_ctrl_status_out_handler(usbh_core_type *uhost) { + usb_sts_type status = USB_OK; + uhost->hch[uhost->ctrl.hch_out].toggle_out ^= 1; - usbh_ctrl_send_data(uhost, 0, 0, uhost->ctrl.hch_out); - uhost->ctrl.state = CONTROL_STATUS_OUT_WAIT; + usbh_ctrl_send_data(uhost, 0, 0, uhost->ctrl.hch_out); + uhost->ctrl.state = CONTROL_STATUS_OUT_WAIT; - return status; + return status; } /** @@ -366,35 +311,26 @@ usb_sts_type usbh_ctrl_status_out_handler(usbh_core_type *uhost) * @param timeout: wait timeout * @retval status: usb_sts_type status */ -usb_sts_type usbh_ctrl_status_out_wait_handler(usbh_core_type *uhost, uint32_t timeout) -{ - usb_sts_type status = USB_OK; - urb_sts_type urb_state; - urb_state = uhost->urb_state[uhost->ctrl.hch_out]; - if(urb_state == URB_DONE) - { - uhost->ctrl.state = CONTROL_COMPLETE; - } - else if(urb_state == URB_STALL) - { - uhost->ctrl.state = CONTROL_STALL; - } - else if(urb_state == URB_ERROR) - { - uhost->ctrl.state = CONTROL_ERROR; - } - else if(urb_state == URB_NOTREADY) - { - uhost->ctrl.state = CONTROL_STATUS_OUT; - } - /* wait nak timeout 5s*/ - if((uhost->timer - uhost->ctrl.timer > CTRL_TIMEOUT) && (urb_state == URB_NOTREADY)) - { - uhost->ctrl.state = CONTROL_ERROR; - uhost->ctrl.sts = CTRL_XACTERR; - status = USB_ERROR; - } - return status; +usb_sts_type usbh_ctrl_status_out_wait_handler(usbh_core_type *uhost, uint32_t timeout) { + usb_sts_type status = USB_OK; + urb_sts_type urb_state; + urb_state = uhost->urb_state[uhost->ctrl.hch_out]; + if (urb_state == URB_DONE) { + uhost->ctrl.state = CONTROL_COMPLETE; + } else if (urb_state == URB_STALL) { + uhost->ctrl.state = CONTROL_STALL; + } else if (urb_state == URB_ERROR) { + uhost->ctrl.state = CONTROL_ERROR; + } else if (urb_state == URB_NOTREADY) { + uhost->ctrl.state = CONTROL_STATUS_OUT; + } + /* wait nak timeout 5s*/ + if ((uhost->timer - uhost->ctrl.timer > CTRL_TIMEOUT) && (urb_state == URB_NOTREADY)) { + uhost->ctrl.state = CONTROL_ERROR; + uhost->ctrl.sts = CTRL_XACTERR; + status = USB_ERROR; + } + return status; } /** @@ -402,22 +338,18 @@ usb_sts_type usbh_ctrl_status_out_wait_handler(usbh_core_type *uhost, uint32_t t * @param uhost: to the structure of usbh_core_type * @retval status: usb_sts_type status */ -usb_sts_type usbh_ctrl_error_handler(usbh_core_type *uhost) -{ - usb_sts_type status = USB_WAIT; - if(++ uhost->ctrl.err_cnt <= USBH_MAX_ERROR_COUNT) - { - uhost->ctrl.state = CONTROL_SETUP; - } - else - { - uhost->ctrl.sts = CTRL_FAIL; - uhost->global_state = USBH_ERROR_STATE; - uhost->ctrl.err_cnt = 0; - USBH_DEBUG("control error: **** Device No Response ****"); - status = USB_ERROR; - } - return status; +usb_sts_type usbh_ctrl_error_handler(usbh_core_type *uhost) { + usb_sts_type status = USB_WAIT; + if (++ uhost->ctrl.err_cnt <= USBH_MAX_ERROR_COUNT) { + uhost->ctrl.state = CONTROL_SETUP; + } else { + uhost->ctrl.sts = CTRL_FAIL; + uhost->global_state = USBH_ERROR_STATE; + uhost->ctrl.err_cnt = 0; + USBH_DEBUG("control error: **** Device No Response ****"); + status = USB_ERROR; + } + return status; } /** @@ -425,9 +357,8 @@ usb_sts_type usbh_ctrl_error_handler(usbh_core_type *uhost) * @param uhost: to the structure of usbh_core_type * @retval usb_sts_type */ -usb_sts_type usbh_ctrl_stall_handler(usbh_core_type *uhost) -{ - return USB_NOT_SUPPORT; +usb_sts_type usbh_ctrl_stall_handler(usbh_core_type *uhost) { + return USB_NOT_SUPPORT; } /** @@ -435,9 +366,8 @@ usb_sts_type usbh_ctrl_stall_handler(usbh_core_type *uhost) * @param uhost: to the structure of usbh_core_type * @retval status: usb_sts_type status */ -usb_sts_type usbh_ctrl_complete_handler(usbh_core_type *uhost) -{ - return USB_OK; +usb_sts_type usbh_ctrl_complete_handler(usbh_core_type *uhost) { + return USB_OK; } /** @@ -445,69 +375,67 @@ usb_sts_type usbh_ctrl_complete_handler(usbh_core_type *uhost) * @param uhost: to the structure of usbh_core_type * @retval status: usb_sts_type status */ -usb_sts_type usbh_ctrl_transfer_loop(usbh_core_type *uhost) -{ - usb_sts_type status = USB_WAIT; - static uint32_t timeout = 0; - uhost->ctrl.sts = CTRL_START; +usb_sts_type usbh_ctrl_transfer_loop(usbh_core_type *uhost) { + usb_sts_type status = USB_WAIT; + static uint32_t timeout = 0; + uhost->ctrl.sts = CTRL_START; - switch(uhost->ctrl.state) - { - case CONTROL_SETUP: - usbh_ctrl_setup_handler(uhost); - uhost->ctrl.timer = uhost->timer; - break; + switch (uhost->ctrl.state) { + case CONTROL_SETUP: + usbh_ctrl_setup_handler(uhost); + uhost->ctrl.timer = uhost->timer; + break; - case CONTROL_SETUP_WAIT: - usbh_ctrl_setup_wait_handler(uhost, &timeout); - break; + case CONTROL_SETUP_WAIT: + usbh_ctrl_setup_wait_handler(uhost, &timeout); + break; - case CONTROL_DATA_IN: - usbh_ctrl_data_in_handler(uhost); - break; + case CONTROL_DATA_IN: + usbh_ctrl_data_in_handler(uhost); + break; - case CONTROL_DATA_IN_WAIT: - usbh_ctrl_data_in_wait_handler(uhost, timeout); - break; + case CONTROL_DATA_IN_WAIT: + usbh_ctrl_data_in_wait_handler(uhost, timeout); + break; - case CONTROL_DATA_OUT: - usbh_ctrl_data_out_handler(uhost); - break; + case CONTROL_DATA_OUT: + usbh_ctrl_data_out_handler(uhost); + break; - case CONTROL_DATA_OUT_WAIT: - usbh_ctrl_data_out_wait_handler(uhost, timeout); - break; + case CONTROL_DATA_OUT_WAIT: + usbh_ctrl_data_out_wait_handler(uhost, timeout); + break; - case CONTROL_STATUS_IN: - usbh_ctrl_status_in_handler(uhost); - break; + case CONTROL_STATUS_IN: + usbh_ctrl_status_in_handler(uhost); + break; - case CONTROL_STATUS_IN_WAIT: - usbh_ctrl_status_in_wait_handler(uhost, timeout); - break; + case CONTROL_STATUS_IN_WAIT: + usbh_ctrl_status_in_wait_handler(uhost, timeout); + break; - case CONTROL_STATUS_OUT: - usbh_ctrl_status_out_handler(uhost); - break; + case CONTROL_STATUS_OUT: + usbh_ctrl_status_out_handler(uhost); + break; - case CONTROL_STATUS_OUT_WAIT: - usbh_ctrl_status_out_wait_handler(uhost, timeout); - break; - case CONTROL_STALL: - status = usbh_ctrl_stall_handler(uhost); - break; - case CONTROL_ERROR: - status = usbh_ctrl_error_handler(uhost); - break; - case CONTROL_COMPLETE: - status = usbh_ctrl_complete_handler(uhost); - break; + case CONTROL_STATUS_OUT_WAIT: + usbh_ctrl_status_out_wait_handler(uhost, timeout); + break; + case CONTROL_STALL: + status = usbh_ctrl_stall_handler(uhost); + break; + case CONTROL_ERROR: + status = usbh_ctrl_error_handler(uhost); + break; + case CONTROL_COMPLETE: + status = usbh_ctrl_complete_handler(uhost); + break; - default: - break; - } + default: + break; + } - return status; + return status; } /** @@ -517,17 +445,15 @@ usb_sts_type usbh_ctrl_transfer_loop(usbh_core_type *uhost) * @param length: usb request length * @retval status: usb_sts_type status */ -usb_sts_type usbh_ctrl_request(usbh_core_type *uhost, uint8_t *buffer, uint16_t length) -{ - usb_sts_type status = USB_OK; - if(uhost->req_state == CMD_SEND) - { - uhost->req_state = CMD_WAIT; - uhost->ctrl.buffer = buffer; - uhost->ctrl.len = length; - uhost->ctrl.state = CONTROL_SETUP; - } - return status; +usb_sts_type usbh_ctrl_request(usbh_core_type *uhost, uint8_t *buffer, uint16_t length) { + usb_sts_type status = USB_OK; + if (uhost->req_state == CMD_SEND) { + uhost->req_state = CMD_WAIT; + uhost->ctrl.buffer = buffer; + uhost->ctrl.len = length; + uhost->ctrl.state = CONTROL_SETUP; + } + return status; } /** @@ -540,26 +466,22 @@ usb_sts_type usbh_ctrl_request(usbh_core_type *uhost, uint8_t *buffer, uint16_t * @retval status: usb_sts_type status */ usb_sts_type usbh_get_descriptor(usbh_core_type *uhost, uint16_t length, - uint8_t req_type, uint16_t wvalue, - uint8_t *buffer) -{ - usb_sts_type status; - uhost->ctrl.setup.bmRequestType = USB_DIR_D2H | req_type; - uhost->ctrl.setup.bRequest = USB_STD_REQ_GET_DESCRIPTOR; - uhost->ctrl.setup.wValue = wvalue; - uhost->ctrl.setup.wLength = length; + uint8_t req_type, uint16_t wvalue, + uint8_t *buffer) { + usb_sts_type status; + uhost->ctrl.setup.bmRequestType = USB_DIR_D2H | req_type; + uhost->ctrl.setup.bRequest = USB_STD_REQ_GET_DESCRIPTOR; + uhost->ctrl.setup.wValue = wvalue; + uhost->ctrl.setup.wLength = length; - if((wvalue & 0xFF00) == ((USB_DESCIPTOR_TYPE_STRING << 8) & 0xFF00)) - { - uhost->ctrl.setup.wIndex = 0x0409; - } - else - { - uhost->ctrl.setup.wIndex = 0; - } + if ((wvalue & 0xFF00) == ((USB_DESCIPTOR_TYPE_STRING << 8) & 0xFF00)) { + uhost->ctrl.setup.wIndex = 0x0409; + } else { + uhost->ctrl.setup.wIndex = 0; + } - status = usbh_ctrl_request(uhost, buffer, length); - return status; + status = usbh_ctrl_request(uhost, buffer, length); + return status; } /** @@ -569,28 +491,26 @@ usb_sts_type usbh_get_descriptor(usbh_core_type *uhost, uint16_t length, * @param length: usb device descriptor length * @retval status: usb_sts_type status */ -void usbh_parse_dev_desc(usbh_core_type *uhost, uint8_t *buffer, uint16_t length) -{ - usbh_dev_desc_type *desc = &(uhost->dev); +void usbh_parse_dev_desc(usbh_core_type *uhost, uint8_t *buffer, uint16_t length) { + usbh_dev_desc_type *desc = &(uhost->dev); - desc->dev_desc.bLength = *(uint8_t *)(buffer + 0); - desc->dev_desc.bDescriptorType = *(uint8_t *)(buffer + 1); - desc->dev_desc.bcdUSB = SWAPBYTE(buffer + 2); - desc->dev_desc.bDeviceClass = *(uint8_t *)(buffer + 4); - desc->dev_desc.bDeviceSubClass = *(uint8_t *)(buffer + 5); - desc->dev_desc.bDeviceProtocol = *(uint8_t *)(buffer + 6); - desc->dev_desc.bMaxPacketSize0 = *(uint8_t *)(buffer + 7); + desc->dev_desc.bLength = *(uint8_t *)(buffer + 0); + desc->dev_desc.bDescriptorType = *(uint8_t *)(buffer + 1); + desc->dev_desc.bcdUSB = SWAPBYTE(buffer + 2); + desc->dev_desc.bDeviceClass = *(uint8_t *)(buffer + 4); + desc->dev_desc.bDeviceSubClass = *(uint8_t *)(buffer + 5); + desc->dev_desc.bDeviceProtocol = *(uint8_t *)(buffer + 6); + desc->dev_desc.bMaxPacketSize0 = *(uint8_t *)(buffer + 7); - if(length > 8) - { - desc->dev_desc.idVendor = SWAPBYTE(buffer + 8); - desc->dev_desc.idProduct = SWAPBYTE(buffer + 10); - desc->dev_desc.bcdDevice = SWAPBYTE(buffer + 12); - desc->dev_desc.iManufacturer = *(uint8_t *)(buffer + 14); - desc->dev_desc.iProduct = *(uint8_t *)(buffer + 15); - desc->dev_desc.iSerialNumber = *(uint8_t *)(buffer + 16); - desc->dev_desc.bNumConfigurations = *(uint8_t *)(buffer + 17); - } + if (length > 8) { + desc->dev_desc.idVendor = SWAPBYTE(buffer + 8); + desc->dev_desc.idProduct = SWAPBYTE(buffer + 10); + desc->dev_desc.bcdDevice = SWAPBYTE(buffer + 12); + desc->dev_desc.iManufacturer = *(uint8_t *)(buffer + 14); + desc->dev_desc.iProduct = *(uint8_t *)(buffer + 15); + desc->dev_desc.iSerialNumber = *(uint8_t *)(buffer + 16); + desc->dev_desc.bNumConfigurations = *(uint8_t *)(buffer + 17); + } } /** @@ -599,11 +519,10 @@ void usbh_parse_dev_desc(usbh_core_type *uhost, uint8_t *buffer, uint16_t length * @param index_len: pointer of index len * @retval status: usb_sts_type status */ -usb_header_desc_type *usbh_get_next_header(uint8_t *buf, uint16_t *index_len) -{ - *index_len += ((usb_header_desc_type *)buf)->bLength; - return (usb_header_desc_type *) - ((uint8_t *)buf + ((usb_header_desc_type *)buf)->bLength); +usb_header_desc_type *usbh_get_next_header(uint8_t *buf, uint16_t *index_len) { + *index_len += ((usb_header_desc_type *)buf)->bLength; + return (usb_header_desc_type *) + ((uint8_t *)buf + ((usb_header_desc_type *)buf)->bLength); } /** @@ -612,17 +531,16 @@ usb_header_desc_type *usbh_get_next_header(uint8_t *buf, uint16_t *index_len) * @param buf: interface description data buffer * @retval none */ -void usbh_parse_interface_desc(usb_interface_desc_type *intf, uint8_t *buf) -{ - intf->bLength = *(uint8_t *)buf; - intf->bDescriptorType = *(uint8_t *)(buf + 1); - intf->bInterfaceNumber = *(uint8_t *)(buf + 2); - intf->bAlternateSetting = *(uint8_t *)(buf + 3); - intf->bNumEndpoints = *(uint8_t *)(buf + 4); - intf->bInterfaceClass = *(uint8_t *)(buf + 5); - intf->bInterfaceSubClass = *(uint8_t *)(buf + 6); - intf->bInterfaceProtocol = *(uint8_t *)(buf + 7); - intf->iInterface = *(uint8_t *)(buf + 8); +void usbh_parse_interface_desc(usb_interface_desc_type *intf, uint8_t *buf) { + intf->bLength = *(uint8_t *)buf; + intf->bDescriptorType = *(uint8_t *)(buf + 1); + intf->bInterfaceNumber = *(uint8_t *)(buf + 2); + intf->bAlternateSetting = *(uint8_t *)(buf + 3); + intf->bNumEndpoints = *(uint8_t *)(buf + 4); + intf->bInterfaceClass = *(uint8_t *)(buf + 5); + intf->bInterfaceSubClass = *(uint8_t *)(buf + 6); + intf->bInterfaceProtocol = *(uint8_t *)(buf + 7); + intf->iInterface = *(uint8_t *)(buf + 8); } /** @@ -631,14 +549,13 @@ void usbh_parse_interface_desc(usb_interface_desc_type *intf, uint8_t *buf) * @param buf: endpoint description data buffer * @retval none */ -void usbh_parse_endpoint_desc(usb_endpoint_desc_type *ept_desc, uint8_t *buf) -{ - ept_desc->bLength = *(uint8_t *)(buf + 0); - ept_desc->bDescriptorType = *(uint8_t *)(buf + 1); - ept_desc->bEndpointAddress = *(uint8_t *)(buf + 2); - ept_desc->bmAttributes = *(uint8_t *)(buf + 3); - ept_desc->wMaxPacketSize = SWAPBYTE(buf + 4); - ept_desc->bInterval = *(uint8_t *)(buf + 6); +void usbh_parse_endpoint_desc(usb_endpoint_desc_type *ept_desc, uint8_t *buf) { + ept_desc->bLength = *(uint8_t *)(buf + 0); + ept_desc->bDescriptorType = *(uint8_t *)(buf + 1); + ept_desc->bEndpointAddress = *(uint8_t *)(buf + 2); + ept_desc->bmAttributes = *(uint8_t *)(buf + 3); + ept_desc->wMaxPacketSize = SWAPBYTE(buf + 4); + ept_desc->bInterval = *(uint8_t *)(buf + 6); } /** @@ -649,54 +566,48 @@ void usbh_parse_endpoint_desc(usb_endpoint_desc_type *ept_desc, uint8_t *buf) * @retval status: usb_sts_type status */ usb_sts_type usbh_parse_configure_desc(usbh_core_type *uhost, - uint8_t *buffer, uint16_t length) -{ - usb_cfg_desc_type *cfg_desc = &(uhost->dev.cfg_desc); - usb_interface_desc_type *intf_desc; - usb_endpoint_desc_type *ept_desc; - usb_header_desc_type *desc; - uint16_t index_len; - uint8_t index_intf = 0; - uint8_t index_ept = 0; + uint8_t *buffer, uint16_t length) { + usb_cfg_desc_type *cfg_desc = &(uhost->dev.cfg_desc); + usb_interface_desc_type *intf_desc; + usb_endpoint_desc_type *ept_desc; + usb_header_desc_type *desc; + uint16_t index_len; + uint8_t index_intf = 0; + uint8_t index_ept = 0; - desc = (usb_header_desc_type *)buffer; - cfg_desc->cfg.bLength = *(uint8_t *)buffer; - cfg_desc->cfg.bDescriptorType = *(uint8_t *)(buffer + 1); - cfg_desc->cfg.wTotalLength = SWAPBYTE(buffer + 2); - cfg_desc->cfg.bNumInterfaces = *(uint8_t *)(buffer + 4); - cfg_desc->cfg.bConfigurationValue = *(uint8_t *)(buffer + 5); - cfg_desc->cfg.iConfiguration = *(uint8_t *)(buffer + 6); - cfg_desc->cfg.bmAttributes = *(uint8_t *)(buffer + 7); - cfg_desc->cfg.bMaxPower = *(uint8_t *)(buffer + 8); + desc = (usb_header_desc_type *)buffer; + cfg_desc->cfg.bLength = *(uint8_t *)buffer; + cfg_desc->cfg.bDescriptorType = *(uint8_t *)(buffer + 1); + cfg_desc->cfg.wTotalLength = SWAPBYTE(buffer + 2); + cfg_desc->cfg.bNumInterfaces = *(uint8_t *)(buffer + 4); + cfg_desc->cfg.bConfigurationValue = *(uint8_t *)(buffer + 5); + cfg_desc->cfg.iConfiguration = *(uint8_t *)(buffer + 6); + cfg_desc->cfg.bmAttributes = *(uint8_t *)(buffer + 7); + cfg_desc->cfg.bMaxPower = *(uint8_t *)(buffer + 8); - if(length > USB_DEVICE_CFG_DESC_LEN) - { - index_len = USB_DEVICE_CFG_DESC_LEN; + if (length > USB_DEVICE_CFG_DESC_LEN) { + index_len = USB_DEVICE_CFG_DESC_LEN; - while((index_intf < USBH_MAX_INTERFACE) && index_len < cfg_desc->cfg.wTotalLength) - { - desc = usbh_get_next_header((uint8_t *)desc, &index_len); - if(desc->bDescriptorType == USB_DESCIPTOR_TYPE_INTERFACE) - { - index_ept = 0; - intf_desc = &cfg_desc->interface[index_intf].interface; - usbh_parse_interface_desc(intf_desc, (uint8_t *)desc); + while ((index_intf < USBH_MAX_INTERFACE) && index_len < cfg_desc->cfg.wTotalLength) { + desc = usbh_get_next_header((uint8_t *)desc, &index_len); + if (desc->bDescriptorType == USB_DESCIPTOR_TYPE_INTERFACE) { + index_ept = 0; + intf_desc = &cfg_desc->interface[index_intf].interface; + usbh_parse_interface_desc(intf_desc, (uint8_t *)desc); - while(index_ept < intf_desc->bNumEndpoints && index_len < cfg_desc->cfg.wTotalLength) - { - desc = usbh_get_next_header((uint8_t *)desc, &index_len); - if(desc->bDescriptorType == USB_DESCIPTOR_TYPE_ENDPOINT) - { - ept_desc = &(cfg_desc->interface[index_intf].endpoint[index_ept]); - usbh_parse_endpoint_desc(ept_desc, (uint8_t *)desc); - index_ept ++; - } + while (index_ept < intf_desc->bNumEndpoints && index_len < cfg_desc->cfg.wTotalLength) { + desc = usbh_get_next_header((uint8_t *)desc, &index_len); + if (desc->bDescriptorType == USB_DESCIPTOR_TYPE_ENDPOINT) { + ept_desc = &(cfg_desc->interface[index_intf].endpoint[index_ept]); + usbh_parse_endpoint_desc(ept_desc, (uint8_t *)desc); + index_ept ++; + } + } + index_intf ++; + } } - index_intf ++; - } } - } - return USB_OK; + return USB_OK; } /** @@ -707,22 +618,19 @@ usb_sts_type usbh_parse_configure_desc(usbh_core_type *uhost, * @param protocol: prtocol code * @retval idx: interface index */ -uint8_t usbh_find_interface(usbh_core_type *uhost, uint8_t class_code, uint8_t sub_class, uint8_t protocol) -{ - uint8_t idx = 0; - usb_itf_desc_type *usbitf; - for(idx = 0; idx < uhost->dev.cfg_desc.cfg.bNumInterfaces; idx ++) - { - usbitf = &uhost->dev.cfg_desc.interface[idx]; - if(((usbitf->interface.bInterfaceClass == class_code) || (class_code == 0xFF)) && - ((usbitf->interface.bInterfaceSubClass == sub_class) || (sub_class == 0xFF)) && - ((usbitf->interface.bInterfaceProtocol == protocol) || (protocol == 0xFF)) - ) - { - return idx; +uint8_t usbh_find_interface(usbh_core_type *uhost, uint8_t class_code, uint8_t sub_class, uint8_t protocol) { + uint8_t idx = 0; + usb_itf_desc_type *usbitf; + for (idx = 0; idx < uhost->dev.cfg_desc.cfg.bNumInterfaces; idx ++) { + usbitf = &uhost->dev.cfg_desc.interface[idx]; + if (((usbitf->interface.bInterfaceClass == class_code) || (class_code == 0xFF)) && + ((usbitf->interface.bInterfaceSubClass == sub_class) || (sub_class == 0xFF)) && + ((usbitf->interface.bInterfaceProtocol == protocol) || (protocol == 0xFF)) + ) { + return idx; + } } - } - return 0xFF; + return 0xFF; } /** @@ -732,22 +640,19 @@ uint8_t usbh_find_interface(usbh_core_type *uhost, uint8_t class_code, uint8_t s * @param length: string length * @retval none */ -void usbh_parse_string_desc(uint8_t *src, uint8_t *dest, uint16_t length) -{ - uint16_t len; - uint16_t i_index; +void usbh_parse_string_desc(uint8_t *src, uint8_t *dest, uint16_t length) { + uint16_t len; + uint16_t i_index; - if(src[1] == USB_DESCIPTOR_TYPE_STRING) - { - len = ((src[0] - 2) <= length ? (src[0] - 2) : length); - src += 2; - for(i_index = 0; i_index < len; i_index += 2) - { - *dest = src[i_index]; - dest ++; + if (src[1] == USB_DESCIPTOR_TYPE_STRING) { + len = ((src[0] - 2) <= length ? (src[0] - 2) : length); + src += 2; + for (i_index = 0; i_index < len; i_index += 2) { + *dest = src[i_index]; + dest ++; + } + *dest = 0; } - *dest = 0; - } } /** @@ -756,18 +661,17 @@ void usbh_parse_string_desc(uint8_t *src, uint8_t *dest, uint16_t length) * @param length: get device descriptor length * @retval status: usb_sts_type status */ -usb_sts_type usbh_get_device_descriptor(usbh_core_type *uhost, uint16_t length) -{ - usb_sts_type status = USB_WAIT; - uint8_t bm_req; - uint16_t wvalue; +usb_sts_type usbh_get_device_descriptor(usbh_core_type *uhost, uint16_t length) { + usb_sts_type status = USB_WAIT; + uint8_t bm_req; + uint16_t wvalue; - bm_req = USB_REQ_RECIPIENT_DEVICE | USB_REQ_TYPE_STANDARD; - wvalue = (USB_DESCIPTOR_TYPE_DEVICE << 8) & 0xFF00; + bm_req = USB_REQ_RECIPIENT_DEVICE | USB_REQ_TYPE_STANDARD; + wvalue = (USB_DESCIPTOR_TYPE_DEVICE << 8) & 0xFF00; - status = usbh_get_descriptor(uhost, length, bm_req, - wvalue, uhost->rx_buffer); - return status; + status = usbh_get_descriptor(uhost, length, bm_req, + wvalue, uhost->rx_buffer); + return status; } /** @@ -776,19 +680,18 @@ usb_sts_type usbh_get_device_descriptor(usbh_core_type *uhost, uint16_t length) * @param length: get device configure length * @retval status: usb_sts_type status */ -usb_sts_type usbh_get_configure_descriptor(usbh_core_type *uhost, uint16_t length) -{ - usb_sts_type status = USB_WAIT; - uint8_t bm_req; - uint16_t wvalue; +usb_sts_type usbh_get_configure_descriptor(usbh_core_type *uhost, uint16_t length) { + usb_sts_type status = USB_WAIT; + uint8_t bm_req; + uint16_t wvalue; - bm_req = USB_REQ_RECIPIENT_DEVICE | USB_REQ_TYPE_STANDARD; - wvalue = (USB_DESCIPTOR_TYPE_CONFIGURATION << 8) & 0xFF00; + bm_req = USB_REQ_RECIPIENT_DEVICE | USB_REQ_TYPE_STANDARD; + wvalue = (USB_DESCIPTOR_TYPE_CONFIGURATION << 8) & 0xFF00; - status = usbh_get_descriptor(uhost, length, bm_req, - wvalue, uhost->rx_buffer); + status = usbh_get_descriptor(uhost, length, bm_req, + wvalue, uhost->rx_buffer); - return status; + return status; } /** @@ -800,19 +703,18 @@ usb_sts_type usbh_get_configure_descriptor(usbh_core_type *uhost, uint16_t lengt * @retval status: usb_sts_type status */ usb_sts_type usbh_get_sting_descriptor(usbh_core_type *uhost, uint8_t string_id, - uint8_t *buffer, uint16_t length) -{ - usb_sts_type status = USB_WAIT; - uint8_t bm_req; - uint16_t wvalue; + uint8_t *buffer, uint16_t length) { + usb_sts_type status = USB_WAIT; + uint8_t bm_req; + uint16_t wvalue; - bm_req = USB_REQ_RECIPIENT_DEVICE | USB_REQ_TYPE_STANDARD; - wvalue = (USB_DESCIPTOR_TYPE_STRING << 8) | string_id; + bm_req = USB_REQ_RECIPIENT_DEVICE | USB_REQ_TYPE_STANDARD; + wvalue = (USB_DESCIPTOR_TYPE_STRING << 8) | string_id; - status = usbh_get_descriptor(uhost, length, bm_req, - wvalue, uhost->rx_buffer); + status = usbh_get_descriptor(uhost, length, bm_req, + wvalue, uhost->rx_buffer); - return status; + return status; } /** @@ -821,19 +723,18 @@ usb_sts_type usbh_get_sting_descriptor(usbh_core_type *uhost, uint8_t string_id, * @param config: usb configuration * @retval status: usb_sts_type status */ -usb_sts_type usbh_set_configuration(usbh_core_type *uhost, uint16_t config) -{ - usb_sts_type status = USB_WAIT; - uint8_t bm_req; - bm_req = USB_REQ_RECIPIENT_DEVICE | USB_REQ_TYPE_STANDARD; +usb_sts_type usbh_set_configuration(usbh_core_type *uhost, uint16_t config) { + usb_sts_type status = USB_WAIT; + uint8_t bm_req; + bm_req = USB_REQ_RECIPIENT_DEVICE | USB_REQ_TYPE_STANDARD; - uhost->ctrl.setup.bmRequestType = USB_DIR_H2D | bm_req; - uhost->ctrl.setup.bRequest = USB_STD_REQ_SET_CONFIGURATION; - uhost->ctrl.setup.wValue = config; - uhost->ctrl.setup.wLength = 0; - uhost->ctrl.setup.wIndex = 0; - status = usbh_ctrl_request(uhost, 0, 0); - return status; + uhost->ctrl.setup.bmRequestType = USB_DIR_H2D | bm_req; + uhost->ctrl.setup.bRequest = USB_STD_REQ_SET_CONFIGURATION; + uhost->ctrl.setup.wValue = config; + uhost->ctrl.setup.wLength = 0; + uhost->ctrl.setup.wIndex = 0; + status = usbh_ctrl_request(uhost, 0, 0); + return status; } /** @@ -842,19 +743,18 @@ usb_sts_type usbh_set_configuration(usbh_core_type *uhost, uint16_t config) * @param address: device address * @retval status: usb_sts_type status */ -usb_sts_type usbh_set_address(usbh_core_type *uhost, uint8_t address) -{ - usb_sts_type status = USB_WAIT; - uint8_t bm_req; - bm_req = USB_REQ_RECIPIENT_DEVICE | USB_REQ_TYPE_STANDARD; +usb_sts_type usbh_set_address(usbh_core_type *uhost, uint8_t address) { + usb_sts_type status = USB_WAIT; + uint8_t bm_req; + bm_req = USB_REQ_RECIPIENT_DEVICE | USB_REQ_TYPE_STANDARD; - uhost->ctrl.setup.bmRequestType = USB_DIR_H2D | bm_req; - uhost->ctrl.setup.bRequest = USB_STD_REQ_SET_ADDRESS; - uhost->ctrl.setup.wValue = (uint16_t)address; - uhost->ctrl.setup.wLength = 0; - uhost->ctrl.setup.wIndex = 0; - status = usbh_ctrl_request(uhost, 0, 0); - return status; + uhost->ctrl.setup.bmRequestType = USB_DIR_H2D | bm_req; + uhost->ctrl.setup.bRequest = USB_STD_REQ_SET_ADDRESS; + uhost->ctrl.setup.wValue = (uint16_t)address; + uhost->ctrl.setup.wLength = 0; + uhost->ctrl.setup.wIndex = 0; + status = usbh_ctrl_request(uhost, 0, 0); + return status; } /** @@ -864,19 +764,18 @@ usb_sts_type usbh_set_address(usbh_core_type *uhost, uint8_t address) * @param altsetting: alter setting * @retval status: usb_sts_type status */ -usb_sts_type usbh_set_interface(usbh_core_type *uhost, uint8_t ept_num, uint8_t altsetting) -{ - usb_sts_type status = USB_WAIT; - uint8_t bm_req; - bm_req = USB_REQ_RECIPIENT_INTERFACE | USB_REQ_TYPE_STANDARD; +usb_sts_type usbh_set_interface(usbh_core_type *uhost, uint8_t ept_num, uint8_t altsetting) { + usb_sts_type status = USB_WAIT; + uint8_t bm_req; + bm_req = USB_REQ_RECIPIENT_INTERFACE | USB_REQ_TYPE_STANDARD; - uhost->ctrl.setup.bmRequestType = USB_DIR_H2D | bm_req; - uhost->ctrl.setup.bRequest = USB_STD_REQ_SET_INTERFACE; - uhost->ctrl.setup.wValue = (uint16_t)altsetting; - uhost->ctrl.setup.wLength = 0; - uhost->ctrl.setup.wIndex = ept_num; - status = usbh_ctrl_request(uhost, 0, 0); - return status; + uhost->ctrl.setup.bmRequestType = USB_DIR_H2D | bm_req; + uhost->ctrl.setup.bRequest = USB_STD_REQ_SET_INTERFACE; + uhost->ctrl.setup.wValue = (uint16_t)altsetting; + uhost->ctrl.setup.wLength = 0; + uhost->ctrl.setup.wIndex = ept_num; + status = usbh_ctrl_request(uhost, 0, 0); + return status; } /** @@ -886,19 +785,18 @@ usb_sts_type usbh_set_interface(usbh_core_type *uhost, uint8_t ept_num, uint8_t * @param index: index number * @retval status: usb_sts_type status */ -usb_sts_type usbh_set_feature(usbh_core_type *uhost, uint8_t feature, uint16_t index) -{ - usb_sts_type status = USB_WAIT; - uint8_t bm_req; - bm_req = USB_REQ_RECIPIENT_DEVICE | USB_REQ_TYPE_STANDARD; +usb_sts_type usbh_set_feature(usbh_core_type *uhost, uint8_t feature, uint16_t index) { + usb_sts_type status = USB_WAIT; + uint8_t bm_req; + bm_req = USB_REQ_RECIPIENT_DEVICE | USB_REQ_TYPE_STANDARD; - uhost->ctrl.setup.bmRequestType = USB_DIR_H2D | bm_req; - uhost->ctrl.setup.bRequest = USB_STD_REQ_SET_FEATURE; - uhost->ctrl.setup.wValue = (uint16_t)feature; - uhost->ctrl.setup.wLength = 0; - uhost->ctrl.setup.wIndex = index; - status = usbh_ctrl_request(uhost, 0, 0); - return status; + uhost->ctrl.setup.bmRequestType = USB_DIR_H2D | bm_req; + uhost->ctrl.setup.bRequest = USB_STD_REQ_SET_FEATURE; + uhost->ctrl.setup.wValue = (uint16_t)feature; + uhost->ctrl.setup.wLength = 0; + uhost->ctrl.setup.wIndex = index; + status = usbh_ctrl_request(uhost, 0, 0); + return status; } @@ -909,19 +807,18 @@ usb_sts_type usbh_set_feature(usbh_core_type *uhost, uint8_t feature, uint16_t i * @param index: index number * @retval status: usb_sts_type status */ -usb_sts_type usbh_clear_dev_feature(usbh_core_type *uhost, uint8_t feature, uint16_t index) -{ - usb_sts_type status = USB_WAIT; - uint8_t bm_req; - bm_req = USB_REQ_RECIPIENT_DEVICE | USB_REQ_TYPE_STANDARD; +usb_sts_type usbh_clear_dev_feature(usbh_core_type *uhost, uint8_t feature, uint16_t index) { + usb_sts_type status = USB_WAIT; + uint8_t bm_req; + bm_req = USB_REQ_RECIPIENT_DEVICE | USB_REQ_TYPE_STANDARD; - uhost->ctrl.setup.bmRequestType = USB_DIR_H2D | bm_req; - uhost->ctrl.setup.bRequest = USB_STD_REQ_CLEAR_FEATURE; - uhost->ctrl.setup.wValue = (uint16_t)feature; - uhost->ctrl.setup.wLength = 0; - uhost->ctrl.setup.wIndex = index; - status = usbh_ctrl_request(uhost, 0, 0); - return status; + uhost->ctrl.setup.bmRequestType = USB_DIR_H2D | bm_req; + uhost->ctrl.setup.bRequest = USB_STD_REQ_CLEAR_FEATURE; + uhost->ctrl.setup.wValue = (uint16_t)feature; + uhost->ctrl.setup.wLength = 0; + uhost->ctrl.setup.wIndex = index; + status = usbh_ctrl_request(uhost, 0, 0); + return status; } /** @@ -931,26 +828,23 @@ usb_sts_type usbh_clear_dev_feature(usbh_core_type *uhost, uint8_t feature, uint * @param hc_num: host channel number * @retval status: usb_sts_type status */ -usb_sts_type usbh_clear_ept_feature(usbh_core_type *uhost, uint8_t ept_num, uint8_t hc_num) -{ - usb_sts_type status = USB_WAIT; - uint8_t bm_req; - if(uhost->ctrl.state == CONTROL_IDLE ) - { - bm_req = USB_REQ_RECIPIENT_ENDPOINT | USB_REQ_TYPE_STANDARD; +usb_sts_type usbh_clear_ept_feature(usbh_core_type *uhost, uint8_t ept_num, uint8_t hc_num) { + usb_sts_type status = USB_WAIT; + uint8_t bm_req; + if (uhost->ctrl.state == CONTROL_IDLE) { + bm_req = USB_REQ_RECIPIENT_ENDPOINT | USB_REQ_TYPE_STANDARD; - uhost->ctrl.setup.bmRequestType = USB_DIR_H2D | bm_req; - uhost->ctrl.setup.bRequest = USB_STD_REQ_CLEAR_FEATURE; - uhost->ctrl.setup.wValue = USB_FEATURE_EPT_HALT; - uhost->ctrl.setup.wLength = 0; - uhost->ctrl.setup.wIndex = ept_num; - usbh_ctrl_request(uhost, 0, 0); - } - if(usbh_ctrl_result_check(uhost, CONTROL_IDLE, ENUM_IDLE) == USB_OK) - { - status = USB_OK; - } - return status; + uhost->ctrl.setup.bmRequestType = USB_DIR_H2D | bm_req; + uhost->ctrl.setup.bRequest = USB_STD_REQ_CLEAR_FEATURE; + uhost->ctrl.setup.wValue = USB_FEATURE_EPT_HALT; + uhost->ctrl.setup.wLength = 0; + uhost->ctrl.setup.wIndex = ept_num; + usbh_ctrl_request(uhost, 0, 0); + } + if (usbh_ctrl_result_check(uhost, CONTROL_IDLE, ENUM_IDLE) == USB_OK) { + status = USB_OK; + } + return status; } /** diff --git a/armlib/at32_usb/usb_drivers/src/usbh_int.c b/armlib/at32_usb/usb_drivers/src/usbh_int.c index 95750b85c..72acca23c 100644 --- a/armlib/at32_usb/usb_drivers/src/usbh_int.c +++ b/armlib/at32_usb/usb_drivers/src/usbh_int.c @@ -42,63 +42,50 @@ * @param otgdev: to the structure of otg_core_type * @retval none */ -void usbh_irq_handler(otg_core_type *otgdev) -{ - otg_global_type *usbx = otgdev->usb_reg; - usbh_core_type *uhost = &otgdev->host; +void usbh_irq_handler(otg_core_type *otgdev) { + otg_global_type *usbx = otgdev->usb_reg; + usbh_core_type *uhost = &otgdev->host; - if(usbx->gintsts_bit.curmode == 1) - { - if(usb_global_get_all_interrupt(usbx) & USB_OTG_RXFLVL_FLAG) - { - usbh_rx_qlvl_handler(uhost); - usb_global_clear_interrupt(usbx, USB_OTG_RXFLVL_FLAG); + if (usbx->gintsts_bit.curmode == 1) { + if (usb_global_get_all_interrupt(usbx) & USB_OTG_RXFLVL_FLAG) { + usbh_rx_qlvl_handler(uhost); + usb_global_clear_interrupt(usbx, USB_OTG_RXFLVL_FLAG); + } + if (usb_global_get_all_interrupt(usbx) & USB_OTG_HCH_FLAG) { + usbh_hch_handler(uhost); + usb_global_clear_interrupt(usbx, USB_OTG_HCH_FLAG); + } + if (usb_global_get_all_interrupt(usbx) & USB_OTG_SOF_FLAG) { + usbh_sof_handler(uhost); + usb_global_clear_interrupt(usbx, USB_OTG_SOF_FLAG); + } + if (usb_global_get_all_interrupt(usbx) & USB_OTG_MODEMIS_FLAG) { + usb_global_clear_interrupt(usbx, USB_OTG_MODEMIS_FLAG); + } + if (usb_global_get_all_interrupt(usbx) & USB_OTG_WKUP_FLAG) { + usbh_wakeup_handler(uhost); + usb_global_clear_interrupt(usbx, USB_OTG_WKUP_FLAG); + } + if (usb_global_get_all_interrupt(usbx) & USB_OTG_DISCON_FLAG) { + usbh_disconnect_handler(uhost); + usb_global_clear_interrupt(usbx, USB_OTG_DISCON_FLAG); + } + if (usb_global_get_all_interrupt(usbx) & USB_OTG_PRT_FLAG) { + usbh_port_handler(uhost); + } + if (usb_global_get_all_interrupt(usbx) & USB_OTG_INCOMPIP_INCOMPISOOUT_FLAG) { + usb_global_clear_interrupt(usbx, USB_OTG_INCOMPIP_INCOMPISOOUT_FLAG); + } + if (usb_global_get_all_interrupt(usbx) & USB_OTG_INCOMISOIN_FLAG) { + usb_global_clear_interrupt(usbx, USB_OTG_INCOMISOIN_FLAG); + } + if (usb_global_get_all_interrupt(usbx) & USB_OTG_PTXFEMP_FLAG) { + usb_global_clear_interrupt(usbx, USB_OTG_PTXFEMP_FLAG); + } + if (usb_global_get_all_interrupt(usbx) & USB_OTG_ISOOUTDROP_FLAG) { + usb_global_clear_interrupt(usbx, USB_OTG_ISOOUTDROP_FLAG); + } } - if(usb_global_get_all_interrupt(usbx) & USB_OTG_HCH_FLAG) - { - usbh_hch_handler(uhost); - usb_global_clear_interrupt(usbx, USB_OTG_HCH_FLAG); - } - if(usb_global_get_all_interrupt(usbx) & USB_OTG_SOF_FLAG) - { - usbh_sof_handler(uhost); - usb_global_clear_interrupt(usbx, USB_OTG_SOF_FLAG); - } - if(usb_global_get_all_interrupt(usbx) & USB_OTG_MODEMIS_FLAG) - { - usb_global_clear_interrupt(usbx, USB_OTG_MODEMIS_FLAG); - } - if(usb_global_get_all_interrupt(usbx) & USB_OTG_WKUP_FLAG) - { - usbh_wakeup_handler(uhost); - usb_global_clear_interrupt(usbx, USB_OTG_WKUP_FLAG); - } - if(usb_global_get_all_interrupt(usbx) & USB_OTG_DISCON_FLAG) - { - usbh_disconnect_handler(uhost); - usb_global_clear_interrupt(usbx, USB_OTG_DISCON_FLAG); - } - if(usb_global_get_all_interrupt(usbx) & USB_OTG_PRT_FLAG) - { - usbh_port_handler(uhost); - } - if(usb_global_get_all_interrupt(usbx) & USB_OTG_INCOMPIP_INCOMPISOOUT_FLAG) - { - usb_global_clear_interrupt(usbx, USB_OTG_INCOMPIP_INCOMPISOOUT_FLAG); - } - if(usb_global_get_all_interrupt(usbx) & USB_OTG_INCOMISOIN_FLAG) - { - usb_global_clear_interrupt(usbx, USB_OTG_INCOMISOIN_FLAG); - } - if(usb_global_get_all_interrupt(usbx) & USB_OTG_PTXFEMP_FLAG) - { - usb_global_clear_interrupt(usbx, USB_OTG_PTXFEMP_FLAG); - } - if(usb_global_get_all_interrupt(usbx) & USB_OTG_ISOOUTDROP_FLAG) - { - usb_global_clear_interrupt(usbx, USB_OTG_ISOOUTDROP_FLAG); - } - } } /** @@ -106,9 +93,8 @@ void usbh_irq_handler(otg_core_type *otgdev) * @param uhost: to the structure of usbh_core_type * @retval none */ -void usbh_wakeup_handler(usbh_core_type *uhost) -{ - uhost->global_state = USBH_WAKEUP; +void usbh_wakeup_handler(usbh_core_type *uhost) { + uhost->global_state = USBH_WAKEUP; } /** @@ -116,9 +102,8 @@ void usbh_wakeup_handler(usbh_core_type *uhost) * @param uhost: to the structure of usbh_core_type * @retval none */ -void usbh_sof_handler(usbh_core_type *uhost) -{ - uhost->timer ++; +void usbh_sof_handler(usbh_core_type *uhost) { + uhost->timer ++; } /** @@ -126,23 +111,21 @@ void usbh_sof_handler(usbh_core_type *uhost) * @param uhost: to the structure of usbh_core_type * @retval none */ -void usbh_disconnect_handler(usbh_core_type *uhost) -{ - otg_global_type *usbx = uhost->usb_reg; +void usbh_disconnect_handler(usbh_core_type *uhost) { + otg_global_type *usbx = uhost->usb_reg; - uint8_t i_index; + uint8_t i_index; - usb_host_disable(usbx); + usb_host_disable(usbx); - uhost->conn_sts = 0; + uhost->conn_sts = 0; - uhost->global_state = USBH_DISCONNECT; + uhost->global_state = USBH_DISCONNECT; - for(i_index = 0; i_index < USB_HOST_CHANNEL_NUM; i_index ++) - { - usbh_free_channel(uhost, i_index); - } - usbh_fsls_clksel(usbx, USB_HCFG_CLK_48M); + for (i_index = 0; i_index < USB_HOST_CHANNEL_NUM; i_index ++) { + usbh_free_channel(uhost, i_index); + } + usbh_fsls_clksel(usbx, USB_HCFG_CLK_48M); } /** @@ -151,133 +134,96 @@ void usbh_disconnect_handler(usbh_core_type *uhost) * @param chn: channel number * @retval none */ -void usbh_hch_in_handler(usbh_core_type *uhost, uint8_t chn) -{ - otg_global_type *usbx = uhost->usb_reg; - otg_hchannel_type *usb_chh = USB_CHL(usbx, chn); - uint32_t hcint_value = usb_chh->hcint; - hcint_value &= usb_chh->hcintmsk; +void usbh_hch_in_handler(usbh_core_type *uhost, uint8_t chn) { + otg_global_type *usbx = uhost->usb_reg; + otg_hchannel_type *usb_chh = USB_CHL(usbx, chn); + uint32_t hcint_value = usb_chh->hcint; + hcint_value &= usb_chh->hcintmsk; - if( hcint_value & USB_OTG_HC_ACK_FLAG) - { - usb_chh->hcint = USB_OTG_HC_ACK_FLAG; - } - else if(hcint_value & USB_OTG_HC_STALL_FLAG) - { - usb_chh->hcintmsk_bit.chhltdmsk = TRUE; - usb_chh->hcint = USB_OTG_HC_NAK_FLAG | USB_OTG_HC_STALL_FLAG; - uhost->hch[chn].state = HCH_STALL; - usb_hch_halt(usbx, chn); - } - else if(hcint_value & USB_OTG_HC_DTGLERR_FLAG) - { - usb_chh->hcintmsk_bit.chhltdmsk = TRUE; - usb_hch_halt(usbx, chn); - usb_chh->hcint = USB_OTG_HC_DTGLERR_FLAG | USB_OTG_HC_NAK_FLAG; - uhost->hch[chn].state = HCH_DATATGLERR; - } + if (hcint_value & USB_OTG_HC_ACK_FLAG) { + usb_chh->hcint = USB_OTG_HC_ACK_FLAG; + } else if (hcint_value & USB_OTG_HC_STALL_FLAG) { + usb_chh->hcintmsk_bit.chhltdmsk = TRUE; + usb_chh->hcint = USB_OTG_HC_NAK_FLAG | USB_OTG_HC_STALL_FLAG; + uhost->hch[chn].state = HCH_STALL; + usb_hch_halt(usbx, chn); + } else if (hcint_value & USB_OTG_HC_DTGLERR_FLAG) { + usb_chh->hcintmsk_bit.chhltdmsk = TRUE; + usb_hch_halt(usbx, chn); + usb_chh->hcint = USB_OTG_HC_DTGLERR_FLAG | USB_OTG_HC_NAK_FLAG; + uhost->hch[chn].state = HCH_DATATGLERR; + } - else if(hcint_value & USB_OTG_HC_FRMOVRRUN_FLAG) - { - usb_chh->hcintmsk_bit.chhltdmsk = TRUE; - usb_hch_halt(usbx, chn); - usb_chh->hcint = USB_OTG_HC_FRMOVRRUN_FLAG; - } - else if(hcint_value & USB_OTG_HC_XFERC_FLAG) - { - uhost->hch[chn].state = HCH_XFRC; - usb_chh->hcint = USB_OTG_HC_XFERC_FLAG; + else if (hcint_value & USB_OTG_HC_FRMOVRRUN_FLAG) { + usb_chh->hcintmsk_bit.chhltdmsk = TRUE; + usb_hch_halt(usbx, chn); + usb_chh->hcint = USB_OTG_HC_FRMOVRRUN_FLAG; + } else if (hcint_value & USB_OTG_HC_XFERC_FLAG) { + uhost->hch[chn].state = HCH_XFRC; + usb_chh->hcint = USB_OTG_HC_XFERC_FLAG; - if(usb_chh->hcchar_bit.eptype == EPT_BULK_TYPE || usb_chh->hcchar_bit.eptype == EPT_CONTROL_TYPE) - { - usb_chh->hcintmsk_bit.chhltdmsk = TRUE; - usb_hch_halt(usbx, chn); - usb_chh->hcint = USB_OTG_HC_NAK_FLAG; + if (usb_chh->hcchar_bit.eptype == EPT_BULK_TYPE || usb_chh->hcchar_bit.eptype == EPT_CONTROL_TYPE) { + usb_chh->hcintmsk_bit.chhltdmsk = TRUE; + usb_hch_halt(usbx, chn); + usb_chh->hcint = USB_OTG_HC_NAK_FLAG; + } else if (usb_chh->hcchar_bit.eptype == EPT_INT_TYPE) { + usb_chh->hcchar_bit.oddfrm = TRUE; + uhost->urb_state[chn] = URB_DONE; + } else if (usb_chh->hcchar_bit.eptype == EPT_ISO_TYPE) { + uhost->urb_state[chn] = URB_DONE; + } + uhost->hch[chn].toggle_in ^= 1; + } else if (hcint_value & USB_OTG_HC_CHHLTD_FLAG) { + usb_chh->hcintmsk_bit.chhltdmsk = FALSE; + if (uhost->hch[chn].state == HCH_XFRC) { + uhost->urb_state[chn] = URB_DONE; + } else if (uhost->hch[chn].state == HCH_STALL) { + uhost->urb_state[chn] = URB_STALL; + } else if (uhost->hch[chn].state == HCH_XACTERR || + uhost->hch[chn].state == HCH_DATATGLERR) { + uhost->err_cnt[chn] ++; + if (uhost->err_cnt[chn] > 3) { + uhost->urb_state[chn] = URB_ERROR; + uhost->err_cnt[chn] = 0; + } else { + uhost->urb_state[chn] = URB_NOTREADY; + } + if (usb_chh->hcchar_bit.eptype == EPT_CONTROL_TYPE || + usb_chh->hcchar_bit.eptype == EPT_BULK_TYPE) { + usb_chh->hcchar_bit.chdis = FALSE; + usb_chh->hcchar_bit.chena = TRUE; + } + } else if (uhost->hch[chn].state == HCH_NAK) { + if (usb_chh->hcchar_bit.eptype == EPT_CONTROL_TYPE || + usb_chh->hcchar_bit.eptype == EPT_BULK_TYPE) { + usb_chh->hcchar_bit.chdis = FALSE; + usb_chh->hcchar_bit.chena = TRUE; + } + uhost->urb_state[chn] = URB_NOTREADY; + } + usb_chh->hcint = USB_OTG_HC_CHHLTD_FLAG; + } else if (hcint_value & USB_OTG_HC_XACTERR_FLAG) { + usb_chh->hcintmsk_bit.chhltdmsk = TRUE; + uhost->hch[chn].state = HCH_XACTERR; + usb_hch_halt(usbx, chn); + uhost->err_cnt[chn] ++; + usb_chh->hcint = USB_OTG_HC_XACTERR_FLAG; + } else if (hcint_value & USB_OTG_HC_NAK_FLAG) { + if (usb_chh->hcchar_bit.eptype == EPT_INT_TYPE) { + uhost->err_cnt[chn] = 0; + usb_chh->hcintmsk_bit.chhltdmsk = TRUE; + usb_hch_halt(usbx, chn); + } else if (usb_chh->hcchar_bit.eptype == EPT_BULK_TYPE || + usb_chh->hcchar_bit.eptype == EPT_CONTROL_TYPE) { + uhost->err_cnt[chn] = 0; + usb_chh->hcintmsk_bit.chhltdmsk = TRUE; + usb_hch_halt(usbx, chn); + } + uhost->hch[chn].state = HCH_NAK; + usb_chh->hcint = USB_OTG_HC_NAK_FLAG; + } else if (hcint_value & USB_OTG_HC_BBLERR_FLAG) { + usb_chh->hcint = USB_OTG_HC_BBLERR_FLAG; } - else if(usb_chh->hcchar_bit.eptype == EPT_INT_TYPE) - { - usb_chh->hcchar_bit.oddfrm = TRUE; - uhost->urb_state[chn] = URB_DONE; - } - else if(usb_chh->hcchar_bit.eptype == EPT_ISO_TYPE) - { - uhost->urb_state[chn] = URB_DONE; - } - uhost->hch[chn].toggle_in ^= 1; - } - else if(hcint_value & USB_OTG_HC_CHHLTD_FLAG) - { - usb_chh->hcintmsk_bit.chhltdmsk = FALSE; - if(uhost->hch[chn].state == HCH_XFRC ) - { - uhost->urb_state[chn] = URB_DONE; - } - else if(uhost->hch[chn].state == HCH_STALL) - { - uhost->urb_state[chn] = URB_STALL; - } - else if(uhost->hch[chn].state == HCH_XACTERR || - uhost->hch[chn].state == HCH_DATATGLERR) - { - uhost->err_cnt[chn] ++; - if(uhost->err_cnt[chn] > 3) - { - uhost->urb_state[chn] = URB_ERROR; - uhost->err_cnt[chn] = 0; - } - else - { - uhost->urb_state[chn] = URB_NOTREADY; - } - if(usb_chh->hcchar_bit.eptype == EPT_CONTROL_TYPE || - usb_chh->hcchar_bit.eptype == EPT_BULK_TYPE) - { - usb_chh->hcchar_bit.chdis = FALSE; - usb_chh->hcchar_bit.chena = TRUE; - } - } - else if(uhost->hch[chn].state == HCH_NAK) - { - if(usb_chh->hcchar_bit.eptype == EPT_CONTROL_TYPE || - usb_chh->hcchar_bit.eptype == EPT_BULK_TYPE) - { - usb_chh->hcchar_bit.chdis = FALSE; - usb_chh->hcchar_bit.chena = TRUE; - } - uhost->urb_state[chn] = URB_NOTREADY; - } - usb_chh->hcint = USB_OTG_HC_CHHLTD_FLAG; - } - else if(hcint_value & USB_OTG_HC_XACTERR_FLAG) - { - usb_chh->hcintmsk_bit.chhltdmsk = TRUE; - uhost->hch[chn].state = HCH_XACTERR; - usb_hch_halt(usbx, chn); - uhost->err_cnt[chn] ++; - usb_chh->hcint = USB_OTG_HC_XACTERR_FLAG; - } - else if(hcint_value & USB_OTG_HC_NAK_FLAG) - { - if(usb_chh->hcchar_bit.eptype == EPT_INT_TYPE) - { - uhost->err_cnt[chn] = 0; - usb_chh->hcintmsk_bit.chhltdmsk = TRUE; - usb_hch_halt(usbx, chn); - } - else if(usb_chh->hcchar_bit.eptype == EPT_BULK_TYPE || - usb_chh->hcchar_bit.eptype == EPT_CONTROL_TYPE) - { - uhost->err_cnt[chn] = 0; - usb_chh->hcintmsk_bit.chhltdmsk = TRUE; - usb_hch_halt(usbx, chn); - } - uhost->hch[chn].state = HCH_NAK; - usb_chh->hcint = USB_OTG_HC_NAK_FLAG; - } - else if(hcint_value & USB_OTG_HC_BBLERR_FLAG) - { - usb_chh->hcint = USB_OTG_HC_BBLERR_FLAG; - } } /** @@ -286,99 +232,72 @@ void usbh_hch_in_handler(usbh_core_type *uhost, uint8_t chn) * @param chn: channel number * @retval none */ -void usbh_hch_out_handler(usbh_core_type *uhost, uint8_t chn) -{ - otg_global_type *usbx = uhost->usb_reg; - otg_hchannel_type *usb_chh = USB_CHL(usbx, chn); - uint32_t hcint_value = usb_chh->hcint; - hcint_value &= usb_chh->hcintmsk; +void usbh_hch_out_handler(usbh_core_type *uhost, uint8_t chn) { + otg_global_type *usbx = uhost->usb_reg; + otg_hchannel_type *usb_chh = USB_CHL(usbx, chn); + uint32_t hcint_value = usb_chh->hcint; + hcint_value &= usb_chh->hcintmsk; - if( hcint_value & USB_OTG_HC_ACK_FLAG) - { - usb_chh->hcint = USB_OTG_HC_ACK_FLAG; - } - else if( hcint_value & USB_OTG_HC_FRMOVRRUN_FLAG) - { - usb_chh->hcintmsk_bit.chhltdmsk = TRUE; - usb_hch_halt(usbx, chn); - usb_chh->hcint = USB_OTG_HC_FRMOVRRUN_FLAG; - } - else if( hcint_value & USB_OTG_HC_XFERC_FLAG) - { - usb_chh->hcintmsk_bit.chhltdmsk = TRUE; - usb_hch_halt(usbx, chn); - uhost->hch[chn].state = HCH_XFRC; - usb_chh->hcint = USB_OTG_HC_XFERC_FLAG; - } - else if( hcint_value & USB_OTG_HC_STALL_FLAG) - { - usb_chh->hcintmsk_bit.chhltdmsk = TRUE; - usb_chh->hcint = USB_OTG_HC_STALL_FLAG; - uhost->hch[chn].state = HCH_STALL; - usb_hch_halt(usbx, chn); - } - else if( hcint_value & USB_OTG_HC_DTGLERR_FLAG) - { - usb_chh->hcintmsk_bit.chhltdmsk = TRUE; - usb_hch_halt(usbx, chn); - usb_chh->hcint = USB_OTG_HC_DTGLERR_FLAG | USB_OTG_HC_NAK_FLAG; - uhost->hch[chn].state = HCH_DATATGLERR; - } - else if( hcint_value & USB_OTG_HC_CHHLTD_FLAG) - { - usb_chh->hcintmsk_bit.chhltdmsk = FALSE; - if(uhost->hch[chn].state == HCH_XFRC) - { - uhost->urb_state[chn] = URB_DONE; - if(uhost->hch[chn].ept_type == EPT_BULK_TYPE || - uhost->hch[chn].ept_type == EPT_INT_TYPE) - { - uhost->hch[chn].toggle_out ^= 1; - } - } - else if(uhost->hch[chn].state == HCH_NAK) - { - uhost->urb_state[chn] = URB_NOTREADY; - } - else if(uhost->hch[chn].state == HCH_STALL) - { - uhost->urb_state[chn] = URB_STALL; - } - else if(uhost->hch[chn].state == HCH_XACTERR || - uhost->hch[chn].state == HCH_DATATGLERR) - { - uhost->err_cnt[chn] ++; - if(uhost->err_cnt[chn] > 3) - { - uhost->urb_state[chn] = URB_ERROR; + if (hcint_value & USB_OTG_HC_ACK_FLAG) { + usb_chh->hcint = USB_OTG_HC_ACK_FLAG; + } else if (hcint_value & USB_OTG_HC_FRMOVRRUN_FLAG) { + usb_chh->hcintmsk_bit.chhltdmsk = TRUE; + usb_hch_halt(usbx, chn); + usb_chh->hcint = USB_OTG_HC_FRMOVRRUN_FLAG; + } else if (hcint_value & USB_OTG_HC_XFERC_FLAG) { + usb_chh->hcintmsk_bit.chhltdmsk = TRUE; + usb_hch_halt(usbx, chn); + uhost->hch[chn].state = HCH_XFRC; + usb_chh->hcint = USB_OTG_HC_XFERC_FLAG; + } else if (hcint_value & USB_OTG_HC_STALL_FLAG) { + usb_chh->hcintmsk_bit.chhltdmsk = TRUE; + usb_chh->hcint = USB_OTG_HC_STALL_FLAG; + uhost->hch[chn].state = HCH_STALL; + usb_hch_halt(usbx, chn); + } else if (hcint_value & USB_OTG_HC_DTGLERR_FLAG) { + usb_chh->hcintmsk_bit.chhltdmsk = TRUE; + usb_hch_halt(usbx, chn); + usb_chh->hcint = USB_OTG_HC_DTGLERR_FLAG | USB_OTG_HC_NAK_FLAG; + uhost->hch[chn].state = HCH_DATATGLERR; + } else if (hcint_value & USB_OTG_HC_CHHLTD_FLAG) { + usb_chh->hcintmsk_bit.chhltdmsk = FALSE; + if (uhost->hch[chn].state == HCH_XFRC) { + uhost->urb_state[chn] = URB_DONE; + if (uhost->hch[chn].ept_type == EPT_BULK_TYPE || + uhost->hch[chn].ept_type == EPT_INT_TYPE) { + uhost->hch[chn].toggle_out ^= 1; + } + } else if (uhost->hch[chn].state == HCH_NAK) { + uhost->urb_state[chn] = URB_NOTREADY; + } else if (uhost->hch[chn].state == HCH_STALL) { + uhost->urb_state[chn] = URB_STALL; + } else if (uhost->hch[chn].state == HCH_XACTERR || + uhost->hch[chn].state == HCH_DATATGLERR) { + uhost->err_cnt[chn] ++; + if (uhost->err_cnt[chn] > 3) { + uhost->urb_state[chn] = URB_ERROR; + uhost->err_cnt[chn] = 0; + } else { + uhost->urb_state[chn] = URB_NOTREADY; + } + + usb_chh->hcchar_bit.chdis = FALSE; + usb_chh->hcchar_bit.chena = TRUE; + } + usb_chh->hcint = USB_OTG_HC_CHHLTD_FLAG; + } else if (hcint_value & USB_OTG_HC_XACTERR_FLAG) { + usb_chh->hcintmsk_bit.chhltdmsk = TRUE; + uhost->err_cnt[chn] ++; + uhost->hch[chn].state = HCH_XACTERR; + usb_hch_halt(usbx, chn); + usb_chh->hcint = USB_OTG_HC_XACTERR_FLAG | USB_OTG_HC_NAK_FLAG; + } else if (hcint_value & USB_OTG_HC_NAK_FLAG) { + usb_chh->hcintmsk_bit.chhltdmsk = TRUE; uhost->err_cnt[chn] = 0; - } - else - { - uhost->urb_state[chn] = URB_NOTREADY; - } - - usb_chh->hcchar_bit.chdis = FALSE; - usb_chh->hcchar_bit.chena = TRUE; + usb_hch_halt(usbx, chn); + uhost->hch[chn].state = HCH_NAK; + usb_chh->hcint = USB_OTG_HC_NAK_FLAG; } - usb_chh->hcint = USB_OTG_HC_CHHLTD_FLAG; - } - else if( hcint_value & USB_OTG_HC_XACTERR_FLAG) - { - usb_chh->hcintmsk_bit.chhltdmsk = TRUE; - uhost->err_cnt[chn] ++; - uhost->hch[chn].state = HCH_XACTERR; - usb_hch_halt(usbx, chn); - usb_chh->hcint = USB_OTG_HC_XACTERR_FLAG | USB_OTG_HC_NAK_FLAG; - } - else if( hcint_value & USB_OTG_HC_NAK_FLAG) - { - usb_chh->hcintmsk_bit.chhltdmsk = TRUE; - uhost->err_cnt[chn] = 0; - usb_hch_halt(usbx, chn); - uhost->hch[chn].state = HCH_NAK; - usb_chh->hcint = USB_OTG_HC_NAK_FLAG; - } } /** @@ -386,29 +305,23 @@ void usbh_hch_out_handler(usbh_core_type *uhost, uint8_t chn) * @param uhost: to the structure of usbh_core_type * @retval none */ -void usbh_hch_handler(usbh_core_type *uhost) -{ - otg_global_type *usbx = uhost->usb_reg; - otg_host_type *usb_host = OTG_HOST(usbx); - uint32_t intsts, i_index; +void usbh_hch_handler(usbh_core_type *uhost) { + otg_global_type *usbx = uhost->usb_reg; + otg_host_type *usb_host = OTG_HOST(usbx); + uint32_t intsts, i_index; - intsts = usb_host->haint & 0xFFFF; - for(i_index = 0; i_index < 16; i_index ++) - { - if(intsts & (1 << i_index)) - { - if(USB_CHL(usbx, i_index)->hcchar_bit.eptdir) - { - //hc in - usbh_hch_in_handler(uhost, i_index); - } - else - { - //hc out - usbh_hch_out_handler(uhost, i_index); - } + intsts = usb_host->haint & 0xFFFF; + for (i_index = 0; i_index < 16; i_index ++) { + if (intsts & (1 << i_index)) { + if (USB_CHL(usbx, i_index)->hcchar_bit.eptdir) { + //hc in + usbh_hch_in_handler(uhost, i_index); + } else { + //hc out + usbh_hch_out_handler(uhost, i_index); + } + } } - } } /** @@ -416,50 +329,46 @@ void usbh_hch_handler(usbh_core_type *uhost) * @param uhost: to the structure of usbh_core_type * @retval none */ -void usbh_rx_qlvl_handler(usbh_core_type *uhost) -{ - uint8_t chn; - uint32_t pktsts; - uint32_t pktcnt; - uint32_t tmp; - otg_hchannel_type *ch; - otg_global_type *usbx = uhost->usb_reg; +void usbh_rx_qlvl_handler(usbh_core_type *uhost) { + uint8_t chn; + uint32_t pktsts; + uint32_t pktcnt; + uint32_t tmp; + otg_hchannel_type *ch; + otg_global_type *usbx = uhost->usb_reg; - usbx->gintmsk_bit.rxflvlmsk = 0; + usbx->gintmsk_bit.rxflvlmsk = 0; - tmp = usbx->grxstsp; - chn = tmp & 0xF; - pktsts = (tmp >> 17) & 0xF; - pktcnt = (tmp >> 4) & 0x7FF; - ch = USB_CHL(usbx, chn); - switch(pktsts) - { - case PKTSTS_IN_DATA_PACKET_RECV: - if(pktcnt > 0 && (uhost->hch[chn].trans_buf) != 0) - { - usb_read_packet(usbx, uhost->hch[chn].trans_buf, chn, pktcnt); - uhost->hch[chn].trans_buf += pktcnt; - uhost->hch[chn].trans_count += pktcnt; + tmp = usbx->grxstsp; + chn = tmp & 0xF; + pktsts = (tmp >> 17) & 0xF; + pktcnt = (tmp >> 4) & 0x7FF; + ch = USB_CHL(usbx, chn); + switch (pktsts) { + case PKTSTS_IN_DATA_PACKET_RECV: + if (pktcnt > 0 && (uhost->hch[chn].trans_buf) != 0) { + usb_read_packet(usbx, uhost->hch[chn].trans_buf, chn, pktcnt); + uhost->hch[chn].trans_buf += pktcnt; + uhost->hch[chn].trans_count += pktcnt; - if(ch->hctsiz_bit.pktcnt > 0) - { - ch->hcchar_bit.chdis = FALSE; - ch->hcchar_bit.chena = TRUE; - uhost->hch[chn].toggle_in ^= 1; - } - } - break; - case PKTSTS_IN_TRANSFER_COMPLETE: - break; - case PKTSTS_DATA_BIT_ERROR: - break; - case PKTSTS_CHANNEL_STOP: - break; - default: - break; + if (ch->hctsiz_bit.pktcnt > 0) { + ch->hcchar_bit.chdis = FALSE; + ch->hcchar_bit.chena = TRUE; + uhost->hch[chn].toggle_in ^= 1; + } + } + break; + case PKTSTS_IN_TRANSFER_COMPLETE: + break; + case PKTSTS_DATA_BIT_ERROR: + break; + case PKTSTS_CHANNEL_STOP: + break; + default: + break; - } - usbx->gintmsk_bit.rxflvlmsk = 1; + } + usbx->gintmsk_bit.rxflvlmsk = 1; } /** @@ -467,58 +376,47 @@ void usbh_rx_qlvl_handler(usbh_core_type *uhost) * @param uhost: to the structure of usbh_core_type * @retval none */ -void usbh_port_handler(usbh_core_type *uhost) -{ - otg_global_type *usbx = uhost->usb_reg; - otg_host_type *usb_host = OTG_HOST(usbx); +void usbh_port_handler(usbh_core_type *uhost) { + otg_global_type *usbx = uhost->usb_reg; + otg_host_type *usb_host = OTG_HOST(usbx); - uint32_t prt = 0, prt_0; + uint32_t prt = 0, prt_0; - prt = usb_host->hprt; - prt_0 = prt; + prt = usb_host->hprt; + prt_0 = prt; - prt_0 &= ~(USB_OTG_HPRT_PRTENA | USB_OTG_HPRT_PRTENCHNG | + prt_0 &= ~(USB_OTG_HPRT_PRTENA | USB_OTG_HPRT_PRTENCHNG | USB_OTG_HPRT_PRTOVRCACT | USB_OTG_HPRT_PRTCONDET); - if(prt & USB_OTG_HPRT_PRTCONDET) - { - if(prt & USB_OTG_HPRT_PRTCONSTS) - { - /* connect callback */ - uhost->conn_sts = 1; + if (prt & USB_OTG_HPRT_PRTCONDET) { + if (prt & USB_OTG_HPRT_PRTCONSTS) { + /* connect callback */ + uhost->conn_sts = 1; + } + prt_0 |= USB_OTG_HPRT_PRTCONDET; } - prt_0 |= USB_OTG_HPRT_PRTCONDET; - } - if(prt & USB_OTG_HPRT_PRTENCHNG) - { - prt_0 |= USB_OTG_HPRT_PRTENCHNG; + if (prt & USB_OTG_HPRT_PRTENCHNG) { + prt_0 |= USB_OTG_HPRT_PRTENCHNG; - if(prt & USB_OTG_HPRT_PRTENA) - { - if((prt & USB_OTG_HPRT_PRTSPD) == (USB_PRTSPD_LOW_SPEED << 17)) - { - usbh_fsls_clksel(usbx, USB_HCFG_CLK_6M); - } - else - { - usbh_fsls_clksel(usbx, USB_HCFG_CLK_48M); - } - /* connect callback */ - uhost->port_enable = 1; + if (prt & USB_OTG_HPRT_PRTENA) { + if ((prt & USB_OTG_HPRT_PRTSPD) == (USB_PRTSPD_LOW_SPEED << 17)) { + usbh_fsls_clksel(usbx, USB_HCFG_CLK_6M); + } else { + usbh_fsls_clksel(usbx, USB_HCFG_CLK_48M); + } + /* connect callback */ + uhost->port_enable = 1; + } else { + /* clean up hprt */ + uhost->port_enable = 0; + } } - else - { - /* clean up hprt */ - uhost->port_enable = 0; + + if (prt & USB_OTG_HPRT_PRTOVRCACT) { + prt_0 |= USB_OTG_HPRT_PRTOVRCACT; } - } - if(prt & USB_OTG_HPRT_PRTOVRCACT) - { - prt_0 |= USB_OTG_HPRT_PRTOVRCACT; - } - - usb_host->hprt = prt_0; + usb_host->hprt = prt_0; } /** diff --git a/armlib/at32_usb/usbd_class/cdc/cdc_class.c b/armlib/at32_usb/usbd_class/cdc/cdc_class.c index ed551c4eb..2b28ca44f 100644 --- a/armlib/at32_usb/usbd_class/cdc/cdc_class.c +++ b/armlib/at32_usb/usbd_class/cdc/cdc_class.c @@ -25,8 +25,7 @@ extern void usb_usart_config(linecoding_type linecoding); static void usb_vcp_cmd_process(void *udev, uint8_t cmd, uint8_t *buff, uint16_t len); -linecoding_type linecoding = -{ +linecoding_type linecoding = { 115200, 0, 0, @@ -37,8 +36,7 @@ linecoding_type linecoding = cdc_struct_type cdc_struct; /* usb device class handler */ -usbd_class_handler cdc_class_handler = -{ +usbd_class_handler cdc_class_handler = { class_init_handler, class_clear_handler, class_setup_handler, @@ -349,7 +347,7 @@ static void usb_vcp_cmd_process(void *udev, uint8_t cmd, uint8_t *buff, uint16_t cdc_struct_type *pcdc = (cdc_struct_type *) pudev->class_handler->pdata; switch (cmd) { case SET_LINE_CODING: - pcdc->linecoding.bitrate = (uint32_t) (buff[0] | (buff[1] << 8) | (buff[2] << 16) | (buff[3] << 24)); + pcdc->linecoding.bitrate = (uint32_t)(buff[0] | (buff[1] << 8) | (buff[2] << 16) | (buff[3] << 24)); pcdc->linecoding.format = buff[4]; pcdc->linecoding.parity = buff[5]; pcdc->linecoding.data = buff[6]; @@ -361,12 +359,12 @@ static void usb_vcp_cmd_process(void *udev, uint8_t cmd, uint8_t *buff, uint16_t case GET_LINE_CODING: buff[0] = (uint8_t) pcdc->linecoding.bitrate; - buff[1] = (uint8_t) (pcdc->linecoding.bitrate >> 8); - buff[2] = (uint8_t) (pcdc->linecoding.bitrate >> 16); - buff[3] = (uint8_t) (pcdc->linecoding.bitrate >> 24); - buff[4] = (uint8_t) (pcdc->linecoding.format); - buff[5] = (uint8_t) (pcdc->linecoding.parity); - buff[6] = (uint8_t) (pcdc->linecoding.data); + buff[1] = (uint8_t)(pcdc->linecoding.bitrate >> 8); + buff[2] = (uint8_t)(pcdc->linecoding.bitrate >> 16); + buff[3] = (uint8_t)(pcdc->linecoding.bitrate >> 24); + buff[4] = (uint8_t)(pcdc->linecoding.format); + buff[5] = (uint8_t)(pcdc->linecoding.parity); + buff[6] = (uint8_t)(pcdc->linecoding.data); break; default: diff --git a/armsrc/appmain.c b/armsrc/appmain.c index 954ac987d..133477033 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -3867,23 +3867,23 @@ static void PacketReceived(PacketCommandNG *packet) { break; } case CMD_PM5_BWM_WIFI: { - #if defined(WITH_BWM_FORWARD) - uint8_t action = packet->data.asBytes[0]; - uint32_t ip = 0; - int res; - if (action == BWM_WIFI_ACTION_STOP) { - res = bwm_wifi_forward_down(); - } else { - uint16_t port = packet->data.asBytes[1] | (packet->data.asBytes[2] << 8); - char *ssid = (char *)&packet->data.asBytes[3]; - char *pwd = ssid + strlen(ssid) + 1; - char *host = pwd + strlen(pwd) + 1; - res = bwm_wifi_forward_up(ssid, pwd, host, port, &ip); - } - reply_ng (CMD_PM5_BWM_WIFI, res, (uint8_t *)&ip, sizeof(ip)); - #else - reply_ng(CMD_PM5_BWM_WIFI, PM3_ENOTIMPL, NULL, 0); - #endif +#if defined(WITH_BWM_FORWARD) + uint8_t action = packet->data.asBytes[0]; + uint32_t ip = 0; + int res; + if (action == BWM_WIFI_ACTION_STOP) { + res = bwm_wifi_forward_down(); + } else { + uint16_t port = packet->data.asBytes[1] | (packet->data.asBytes[2] << 8); + char *ssid = (char *)&packet->data.asBytes[3]; + char *pwd = ssid + strlen(ssid) + 1; + char *host = pwd + strlen(pwd) + 1; + res = bwm_wifi_forward_up(ssid, pwd, host, port, &ip); + } + reply_ng(CMD_PM5_BWM_WIFI, res, (uint8_t *)&ip, sizeof(ip)); +#else + reply_ng(CMD_PM5_BWM_WIFI, PM3_ENOTIMPL, NULL, 0); +#endif break; } case CMD_PM5_BWM_AUTOOFF: { diff --git a/armsrc/at32_unit_test.c b/armsrc/at32_unit_test.c index 66e9e1c98..edf589094 100644 --- a/armsrc/at32_unit_test.c +++ b/armsrc/at32_unit_test.c @@ -173,7 +173,7 @@ void test_i2c_rgb(void) { } if ((i2c_status = i2c_master_receive(&hi2cx, I2Cx_ADDRESS, rx_buf, I2C_RGB_TEST_BUF_SIZE, I2C_TIMEOUT)) != - I2C_OK) { + I2C_OK) { dxl_print_dbg("读取异常:%d\r\n", i2c_status); continue; // 异常的话,直接跳过下面的代码,重新尝试执行 } @@ -202,7 +202,7 @@ void test_i2c_rgb(void) { dxl_print_dbg("开始写入... \r\n"); if ((i2c_status = i2c_master_transmit(&hi2cx, I2Cx_ADDRESS, tx_buf, I2C_RGB_TEST_BUF_SIZE, I2C_TIMEOUT)) != - I2C_OK) { + I2C_OK) { dxl_print_dbg("写入异常:%d\r\n", i2c_status); continue; // 异常的话,直接跳过下面的代码,重新尝试执行 } @@ -1000,7 +1000,7 @@ void test_beep(void) { gpio_init_struct.gpio_pins = BEEPER_EN_GPIO_PIN; gpio_init_struct.gpio_pull = GPIO_PULL_NONE; gpio_init(BEEPER_EN_GPIO, &gpio_init_struct); - gpio_bits_write(BEEPER_EN_GPIO,BEEPER_EN_GPIO_PIN, FALSE); + gpio_bits_write(BEEPER_EN_GPIO, BEEPER_EN_GPIO_PIN, FALSE); // 蜂鸣器调制脚 gpio_init_struct.gpio_mode = GPIO_MODE_MUX; gpio_init_struct.gpio_pins = BEEPER_MOD_GPIO_PIN; @@ -1022,27 +1022,27 @@ void test_beep(void) { while (1) { BEEPER_MOD_TMR->pr = 999; - gpio_bits_write(BEEPER_EN_GPIO,BEEPER_EN_GPIO_PIN, TRUE); + gpio_bits_write(BEEPER_EN_GPIO, BEEPER_EN_GPIO_PIN, TRUE); SpinDelay(20); - gpio_bits_write(BEEPER_EN_GPIO,BEEPER_EN_GPIO_PIN, FALSE); + gpio_bits_write(BEEPER_EN_GPIO, BEEPER_EN_GPIO_PIN, FALSE); SpinDelay(400); BEEPER_MOD_TMR->pr = 1100; tmr_channel_value_set(BEEPER_MOD_TMR, BEEPER_MOD_TMR_CH, 550); - gpio_bits_write(BEEPER_EN_GPIO,BEEPER_EN_GPIO_PIN, TRUE); + gpio_bits_write(BEEPER_EN_GPIO, BEEPER_EN_GPIO_PIN, TRUE); SpinDelay(20); - gpio_bits_write(BEEPER_EN_GPIO,BEEPER_EN_GPIO_PIN, FALSE); + gpio_bits_write(BEEPER_EN_GPIO, BEEPER_EN_GPIO_PIN, FALSE); SpinDelay(400); BEEPER_MOD_TMR->pr = 1200; tmr_channel_value_set(BEEPER_MOD_TMR, BEEPER_MOD_TMR_CH, 600); - gpio_bits_write(BEEPER_EN_GPIO,BEEPER_EN_GPIO_PIN, TRUE); + gpio_bits_write(BEEPER_EN_GPIO, BEEPER_EN_GPIO_PIN, TRUE); SpinDelay(20); - gpio_bits_write(BEEPER_EN_GPIO,BEEPER_EN_GPIO_PIN, FALSE); + gpio_bits_write(BEEPER_EN_GPIO, BEEPER_EN_GPIO_PIN, FALSE); SpinDelay(400); BEEPER_MOD_TMR->pr = 1300; tmr_channel_value_set(BEEPER_MOD_TMR, BEEPER_MOD_TMR_CH, 650); - gpio_bits_write(BEEPER_EN_GPIO,BEEPER_EN_GPIO_PIN, TRUE); + gpio_bits_write(BEEPER_EN_GPIO, BEEPER_EN_GPIO_PIN, TRUE); SpinDelay(20); - gpio_bits_write(BEEPER_EN_GPIO,BEEPER_EN_GPIO_PIN, FALSE); + gpio_bits_write(BEEPER_EN_GPIO, BEEPER_EN_GPIO_PIN, FALSE); SpinDelay(400); // 响完一轮之后直接软件reset @@ -1703,9 +1703,9 @@ void test_24c02(void) { uint8_t aes_key[16]; uint8_t reserved[147]; } - PACKED info; + PACKED info; } - PACKED; + PACKED; struct factory_info_v1 *factory_info = (struct factory_info_v1 *) data; // 打印全部信息 dxl_print_dbg("factory_info_version: %d\n", factory_info->factory_info_version); @@ -1800,12 +1800,12 @@ void test_bwm_uart(void) { // 测试发送和接收数据,看看BWM是否正常通信 uint8_t data_tx[] = { 0x7c, 0xc7, 0xfa, 0x03, 0x00, 0x00, 0xb5, 0xba }; for (size_t i = 0; i < sizeof(data_tx); ++i) { - while(usart_flag_get(UART4, USART_TDBE_FLAG) == RESET); + while (usart_flag_get(UART4, USART_TDBE_FLAG) == RESET); usart_data_transmit(UART4, data_tx[i]); } uint8_t data_rx[9] = { 0x00 }; // 应答是 2d3dfa03010001c8d1 for (size_t i = 0; i < sizeof(data_rx); ++i) { - while(usart_flag_get(UART4, USART_RDBF_FLAG) == RESET); + while (usart_flag_get(UART4, USART_RDBF_FLAG) == RESET); data_rx[i] = usart_data_receive(UART4); } dxl_print_dbg("Received data from BWM: "); diff --git a/armsrc/bwm_charger.c b/armsrc/bwm_charger.c index 85494dce5..e52a46ac3 100644 --- a/armsrc/bwm_charger.c +++ b/armsrc/bwm_charger.c @@ -366,10 +366,14 @@ void bwm_detect_and_init(void) { I2C_BufferWrite(&v, 1, 0x01, BWM_CHG_ADDR); } uint8_t w; - w = 0x1F; I2C_BufferWrite(&w, 1, 0x02, BWM_CHG_ADDR); // charge current 256 mA - w = 0xE1; I2C_BufferWrite(&w, 1, 0x03, BWM_CHG_ADDR); // discharge current 3 A - w = 0x1A; I2C_BufferWrite(&w, 1, 0x05, BWM_CHG_ADDR); // safety timer disabled (upstream) - w = 0x6B; I2C_BufferWrite(&w, 1, 0x0B, BWM_CHG_ADDR); // pre-charge 11 mA + w = 0x1F; + I2C_BufferWrite(&w, 1, 0x02, BWM_CHG_ADDR); // charge current 256 mA + w = 0xE1; + I2C_BufferWrite(&w, 1, 0x03, BWM_CHG_ADDR); // discharge current 3 A + w = 0x1A; + I2C_BufferWrite(&w, 1, 0x05, BWM_CHG_ADDR); // safety timer disabled (upstream) + w = 0x6B; + I2C_BufferWrite(&w, 1, 0x0B, BWM_CHG_ADDR); // pre-charge 11 mA } #endif // WITH_BWM_STATUS diff --git a/armsrc/bwm_forward.c b/armsrc/bwm_forward.c index 12765654f..5cd63981b 100644 --- a/armsrc/bwm_forward.c +++ b/armsrc/bwm_forward.c @@ -160,9 +160,13 @@ static void bwm_feed_byte(bwm_parser_t *p, uint8_t byte) { switch (p->state) { case S_IDLE: if (byte == BWM_HDR_SLAVE_BCAST_1) { - p->hdr1 = byte; p->is_bcast = true; p->state = S_HDR2; + p->hdr1 = byte; + p->is_bcast = true; + p->state = S_HDR2; } else if (byte == BWM_HDR_SLAVE_RESP_1) { - p->hdr1 = byte; p->is_bcast = false; p->state = S_HDR2; + p->hdr1 = byte; + p->is_bcast = false; + p->state = S_HDR2; } // any other byte: stay idle (resync) break; @@ -182,9 +186,21 @@ static void bwm_feed_byte(bwm_parser_t *p, uint8_t byte) { break; } - case S_CMD_LO: p->cmd = byte; crc_step(p, byte); p->state = S_CMD_HI; break; - case S_CMD_HI: p->cmd |= (uint16_t)byte << 8; crc_step(p, byte); p->state = S_LEN_LO; break; - case S_LEN_LO: p->len = byte; crc_step(p, byte); p->state = S_LEN_HI; break; + case S_CMD_LO: + p->cmd = byte; + crc_step(p, byte); + p->state = S_CMD_HI; + break; + case S_CMD_HI: + p->cmd |= (uint16_t)byte << 8; + crc_step(p, byte); + p->state = S_LEN_LO; + break; + case S_LEN_LO: + p->len = byte; + crc_step(p, byte); + p->state = S_LEN_HI; + break; case S_LEN_HI: p->len |= (uint16_t)byte << 8; crc_step(p, byte); @@ -204,7 +220,10 @@ static void bwm_feed_byte(bwm_parser_t *p, uint8_t byte) { } break; - case S_CRC_LO: p->crc_recv = byte; p->state = S_CRC_HI; break; + case S_CRC_LO: + p->crc_recv = byte; + p->state = S_CRC_HI; + break; case S_CRC_HI: p->crc_recv |= (uint16_t)byte << 8; if (p->crc_recv == p->crc_calc) { @@ -285,8 +304,8 @@ uint32_t bwm_read_ng(uint8_t *data, size_t len) { continue; } if (try++ >= maxtry) { - break; - } + break; + } } return out; } diff --git a/armsrc/bwm_wifi.c b/armsrc/bwm_wifi.c index c33e4b165..9701eee48 100644 --- a/armsrc/bwm_wifi.c +++ b/armsrc/bwm_wifi.c @@ -89,19 +89,35 @@ int bwm_cmd(uint16_t cmd, const uint8_t *req, uint16_t req_len, } break; } - case W_CL: rcmd = byte; rcrc_calc = wifi_crc16(&byte,1,rcrc_calc); st = W_CH; break; - case W_CH: rcmd |= (uint16_t)byte << 8; rcrc_calc = wifi_crc16(&byte,1,rcrc_calc); st = W_LL; break; - case W_LL: rlen = byte; rcrc_calc = wifi_crc16(&byte,1,rcrc_calc); st = W_LH; break; + case W_CL: + rcmd = byte; + rcrc_calc = wifi_crc16(&byte, 1, rcrc_calc); + st = W_CH; + break; + case W_CH: + rcmd |= (uint16_t)byte << 8; + rcrc_calc = wifi_crc16(&byte, 1, rcrc_calc); + st = W_LL; + break; + case W_LL: + rlen = byte; + rcrc_calc = wifi_crc16(&byte, 1, rcrc_calc); + st = W_LH; + break; case W_LH: - rlen |= (uint16_t)byte << 8; rcrc_calc = wifi_crc16(&byte,1,rcrc_calc); + rlen |= (uint16_t)byte << 8; + rcrc_calc = wifi_crc16(&byte, 1, rcrc_calc); st = (rlen ? W_PL : W_KL); break; case W_PL: if (rgot < sizeof(pbuf)) pbuf[rgot] = byte; - rcrc_calc = wifi_crc16(&byte,1,rcrc_calc); + rcrc_calc = wifi_crc16(&byte, 1, rcrc_calc); if (++rgot >= rlen) st = W_KL; break; - case W_KL: rcrc_recv = byte; st = W_KH; break; + case W_KL: + rcrc_recv = byte; + st = W_KH; + break; case W_KH: { rcrc_recv |= (uint16_t)byte << 8; if (rcrc_recv == rcrc_calc) { @@ -161,7 +177,7 @@ int bwm_wifi_forward_up(const char *ssid, const char *password, // 2) STA credentials if ((r = step(BWM_CMD_SET_WIFI_CONNECT_CFG_SSID, (const uint8_t *)ssid, (uint16_t)strlen(ssid), NULL, NULL, TO, "set ssid")) != PM3_SUCCESS) return r; - if ((r = step(BWM_CMD_SET_WIFI_CONNECT_CFG_PWD, (const uint8_t *)password, (uint16_t)strlen(password), NULL, NULL, TO, "set password")) != PM3_SUCCESS) return r; + if ((r = step(BWM_CMD_SET_WIFI_CONNECT_CFG_PWD, (const uint8_t *)password, (uint16_t)strlen(password), NULL, NULL, TO, "set password")) != PM3_SUCCESS) return r; // 3) TCP listen port (LE) uint8_t p2[2] = { (uint8_t)(tcp_port & 0xFF), (uint8_t)(tcp_port >> 8) }; @@ -173,7 +189,8 @@ int bwm_wifi_forward_up(const char *ssid, const char *password, // 4) join the AP and wait for it to finish (up to ~15s) if ((r = step(BWM_CMD_START_WIFI_CONNECT_TASK, NULL, 0, NULL, NULL, TO, "start connect")) != PM3_SUCCESS) return r; uint8_t secs = 25; // iPhone/phone hotspots can be slow to become joinable - uint8_t wr[2]; uint16_t wl = sizeof(wr); + uint8_t wr[2]; + uint16_t wl = sizeof(wr); if ((r = step(BWM_CMD_WAIT_FOR_WIFI_CONNECT_TASK, &secs, 1, wr, &wl, 30000, "wait connect")) != PM3_SUCCESS) return r; // 5) wait for DHCP. The STA reports "connected" on association, before it @@ -182,7 +199,8 @@ int bwm_wifi_forward_up(const char *ssid, const char *password, uint32_t ip = 0; uint32_t dhcp_start = GetTickCount(); for (;;) { - uint8_t ipb[12]; uint16_t il = sizeof(ipb); + uint8_t ipb[12]; + uint16_t il = sizeof(ipb); if ((bwm_cmd(BWM_CMD_GET_WIFI_CFG_IP_ADDR, NULL, 0, ipb, &il, TO) == PM3_SUCCESS) && (il >= 4)) { ip = (uint32_t)ipb[0] | ((uint32_t)ipb[1] << 8) | ((uint32_t)ipb[2] << 16) | ((uint32_t)ipb[3] << 24); if (ip != 0) { diff --git a/armsrc/em4x50.c b/armsrc/em4x50.c index 11727856a..a2481738f 100644 --- a/armsrc/em4x50.c +++ b/armsrc/em4x50.c @@ -1176,8 +1176,7 @@ static void em4x50_sim_wait_edge(const int mode) { // Dbprintf("timeout wait clk(1)"); return; } - } - while (!Gpio_SSC_CLK_Read()); // wait to high + } while (!Gpio_SSC_CLK_Read()); // wait to high } if (mode & 0x02) { ticks_start = GET_TICKS; // reset start time value diff --git a/armsrc/iclass.c b/armsrc/iclass.c index 1679a8f49..0c4660838 100644 --- a/armsrc/iclass.c +++ b/armsrc/iclass.c @@ -39,7 +39,7 @@ #include "iso15693.h" #include "iclass_cmd.h" // iclass_card_select_t struct #include "i2c.h" // i2c defines (SIM module access) -#include "sam_common.h" +#include "sam_common.h" #include "printf.h" uint8_t get_pagemap(const picopass_hdr_t *hdr) { diff --git a/armsrc/mifarecmd.c b/armsrc/mifarecmd.c index b77897a78..c35953ac0 100644 --- a/armsrc/mifarecmd.c +++ b/armsrc/mifarecmd.c @@ -1522,7 +1522,7 @@ out: crypto1_deinit(pcs); LED_B_ON(); if (reply) { - uint8_t respbuf[sizeof(mf_nonces_resp_t) + (MIFARE_BLOCK_SIZE *(MIFARE_1K_MAXSECTOR + 1))] = {0x00}; + uint8_t respbuf[sizeof(mf_nonces_resp_t) + (MIFARE_BLOCK_SIZE * (MIFARE_1K_MAXSECTOR + 1))] = {0x00}; mf_nonces_resp_t *response = (mf_nonces_resp_t *)respbuf; response->cuid = cuid; response->num_nonces = 0; diff --git a/armsrc/sam_sc.c b/armsrc/sam_sc.c index bf2b3eba5..5bcd88395 100644 --- a/armsrc/sam_sc.c +++ b/armsrc/sam_sc.c @@ -181,7 +181,7 @@ static uint16_t sam_sc_emit_ber_len(uint8_t *out, uint16_t len) { } static uint16_t sam_sc_copy_payload_nfc2sam(uint8_t *out, uint16_t out_size, - const uint8_t *nfc, uint16_t nfc_len) { + const uint8_t *nfc, uint16_t nfc_len) { if (out == NULL || nfc == NULL || nfc_len == 0) return 0; const uint16_t inner_len = (uint16_t)(1 + sam_sc_ber_len_size(nfc_len) + nfc_len + 4); @@ -266,7 +266,7 @@ static int sam_sc_card_api_loop(uint8_t *response, uint16_t *response_len, memset(&card_info, 0, sizeof(card_info)); iso14443a_setup(FPGA_HF_ISO14443A_READER_MOD); bool selected = iso14443a_select_card(NULL, &card_info, - NULL, true, 0, false); + NULL, true, 0, false); switch_clock_to_ticks(); if (selected == false || card_info.uidlen == 0 || card_info.uidlen > 10) { static const uint8_t no_card[] = {0xbd, 0x02, 0x8a, 0x00}; @@ -367,7 +367,7 @@ static int sam_sc_card_api_loop(uint8_t *response, uint16_t *response_len, if (iso14a) { switch_clock_to_countsspclk(); int apdu_len = iso14_apdu((uint8_t *)op_value, op_len, false, - nfc_rx, sizeof(nfc_rx), NULL); + nfc_rx, sizeof(nfc_rx), NULL); switch_clock_to_ticks(); if (apdu_len >= 2) { nfc_rx_len = (uint16_t)(apdu_len - 2); @@ -403,7 +403,7 @@ static int sam_sc_card_api_loop(uint8_t *response, uint16_t *response_len, do { iclass_send_as_reader((uint8_t *)op_value, op_len, &start_time, &eof_time, false); res = GetIso15693AnswerFromTag(nfc_rx, sizeof(nfc_rx), timeout, &eof_time, - false, true, &nfc_rx_len); + false, true, &nfc_rx_len); if (res == PM3_SUCCESS && nfc_rx_len > 0) break; start_time = eof_time + ((DELAY_ICLASS_VICC_TO_VCD_READER + DELAY_ISO15693_VCD_TO_VICC_READER + @@ -415,7 +415,7 @@ static int sam_sc_card_api_loop(uint8_t *response, uint16_t *response_len, if (res == PM3_SUCCESS && nfc_rx_len > 0) { continuation_len = sam_sc_copy_payload_nfc2sam(continuation, ISO7816_MAX_FRAME, - nfc_rx, nfc_rx_len); + nfc_rx, nfc_rx_len); if (continuation_len == 0) res = PM3_ECARDEXCHANGE; } else { @@ -566,8 +566,8 @@ void sam_sc_handler(const PacketCommandNG *c) { iclass_send_as_reader((uint8_t *)read_aia, sizeof(read_aia), &start_time, &eof_time, false); res = GetIso15693AnswerFromTag(aia_rx, sizeof(aia_rx), - ICLASS_READER_TIMEOUT_ACTALL, - &eof_time, false, true, &aia_rx_len); + ICLASS_READER_TIMEOUT_ACTALL, + &eof_time, false, true, &aia_rx_len); if (res == PM3_SUCCESS && aia_rx_len == sizeof(aia_rx)) { memcpy(aia, aia_rx, sizeof(aia)); got_aia = true; @@ -662,12 +662,12 @@ void sam_sc_handler(const PacketCommandNG *c) { if (snmp_loader && res == PM3_SUCCESS) { reply_ng(CMD_HF_SAM_SC, PM3_SUCCESS, response, response_len); - // Reformat the buffer for the host: prepend the SAM-assigned scFlag, - // then the SAM payload. Grace SAMs mirror either a five- or six-byte - // routing tail; deriving both positions from the BD success or BE - // error response node avoids exposing the final routing byte as part - // of the payload. - // memmove is safe across the overlapping ranges. + // Reformat the buffer for the host: prepend the SAM-assigned scFlag, + // then the SAM payload. Grace SAMs mirror either a five- or six-byte + // routing tail; deriving both positions from the BD success or BE + // error response node avoids exposing the final routing byte as part + // of the payload. + // memmove is safe across the overlapping ranges. } else if (res == PM3_SUCCESS) { uint16_t reply_offset = sam_sc_reply_offset(response, response_len); if (reply_offset == 0) { diff --git a/armsrc/util.c b/armsrc/util.c index c41c0c57a..0eca65dba 100644 --- a/armsrc/util.c +++ b/armsrc/util.c @@ -274,7 +274,7 @@ int BUTTON_CLICKED(int ms) { if (BUTTON_PRESS()) return BUTTON_DOUBLE_CLICK; - // Have we ran out of time to double click? + // Have we ran out of time to double click? else if (ms <= 0) // At least we did a single click return BUTTON_SINGLE_CLICK; diff --git a/client/deps/openjpeg/bio.c b/client/deps/openjpeg/bio.c index 8106df754..4b4264f87 100644 --- a/client/deps/openjpeg/bio.c +++ b/client/deps/openjpeg/bio.c @@ -72,8 +72,7 @@ static OPJ_BOOL opj_bio_bytein(opj_bio_t *bio); ========================================================== */ -static OPJ_BOOL opj_bio_byteout(opj_bio_t *bio) -{ +static OPJ_BOOL opj_bio_byteout(opj_bio_t *bio) { bio->buf = (bio->buf << 8) & 0xffff; bio->ct = bio->buf == 0xff00 ? 7 : 8; if ((OPJ_SIZE_T)bio->bp >= (OPJ_SIZE_T)bio->end) { @@ -83,8 +82,7 @@ static OPJ_BOOL opj_bio_byteout(opj_bio_t *bio) return OPJ_TRUE; } -static OPJ_BOOL opj_bio_bytein(opj_bio_t *bio) -{ +static OPJ_BOOL opj_bio_bytein(opj_bio_t *bio) { bio->buf = (bio->buf << 8) & 0xffff; bio->ct = bio->buf == 0xff00 ? 7 : 8; if ((OPJ_SIZE_T)bio->bp >= (OPJ_SIZE_T)bio->end) { @@ -94,8 +92,7 @@ static OPJ_BOOL opj_bio_bytein(opj_bio_t *bio) return OPJ_TRUE; } -static OPJ_UINT32 opj_bio_getbit(opj_bio_t *bio) -{ +static OPJ_UINT32 opj_bio_getbit(opj_bio_t *bio) { if (bio->ct == 0) { opj_bio_bytein( bio); /* MSD: why not check the return value of this function ? */ @@ -110,26 +107,22 @@ static OPJ_UINT32 opj_bio_getbit(opj_bio_t *bio) ========================================================== */ -opj_bio_t* opj_bio_create(void) -{ - opj_bio_t *bio = (opj_bio_t*)opj_malloc(sizeof(opj_bio_t)); +opj_bio_t *opj_bio_create(void) { + opj_bio_t *bio = (opj_bio_t *)opj_malloc(sizeof(opj_bio_t)); return bio; } -void opj_bio_destroy(opj_bio_t *bio) -{ +void opj_bio_destroy(opj_bio_t *bio) { if (bio) { opj_free(bio); } } -ptrdiff_t opj_bio_numbytes(opj_bio_t *bio) -{ +ptrdiff_t opj_bio_numbytes(opj_bio_t *bio) { return (bio->bp - bio->start); } -void opj_bio_init_enc(opj_bio_t *bio, OPJ_BYTE *bp, OPJ_UINT32 len) -{ +void opj_bio_init_enc(opj_bio_t *bio, OPJ_BYTE *bp, OPJ_UINT32 len) { bio->start = bp; bio->end = bp + len; bio->bp = bp; @@ -137,8 +130,7 @@ void opj_bio_init_enc(opj_bio_t *bio, OPJ_BYTE *bp, OPJ_UINT32 len) bio->ct = 8; } -void opj_bio_init_dec(opj_bio_t *bio, OPJ_BYTE *bp, OPJ_UINT32 len) -{ +void opj_bio_init_dec(opj_bio_t *bio, OPJ_BYTE *bp, OPJ_UINT32 len) { bio->start = bp; bio->end = bp + len; bio->bp = bp; @@ -146,8 +138,7 @@ void opj_bio_init_dec(opj_bio_t *bio, OPJ_BYTE *bp, OPJ_UINT32 len) bio->ct = 0; } -void opj_bio_putbit(opj_bio_t *bio, OPJ_UINT32 b) -{ +void opj_bio_putbit(opj_bio_t *bio, OPJ_UINT32 b) { if (bio->ct == 0) { opj_bio_byteout( bio); /* MSD: why not check the return value of this function ? */ @@ -156,8 +147,7 @@ void opj_bio_putbit(opj_bio_t *bio, OPJ_UINT32 b) bio->buf |= b << bio->ct; } -void opj_bio_write(opj_bio_t *bio, OPJ_UINT32 v, OPJ_UINT32 n) -{ +void opj_bio_write(opj_bio_t *bio, OPJ_UINT32 v, OPJ_UINT32 n) { OPJ_INT32 i; assert((n > 0U) && (n <= 32U)); @@ -166,8 +156,7 @@ void opj_bio_write(opj_bio_t *bio, OPJ_UINT32 v, OPJ_UINT32 n) } } -OPJ_UINT32 opj_bio_read(opj_bio_t *bio, OPJ_UINT32 n) -{ +OPJ_UINT32 opj_bio_read(opj_bio_t *bio, OPJ_UINT32 n) { OPJ_INT32 i; OPJ_UINT32 v; @@ -186,8 +175,7 @@ OPJ_UINT32 opj_bio_read(opj_bio_t *bio, OPJ_UINT32 n) return v; } -OPJ_BOOL opj_bio_flush(opj_bio_t *bio) -{ +OPJ_BOOL opj_bio_flush(opj_bio_t *bio) { if (! opj_bio_byteout(bio)) { return OPJ_FALSE; } @@ -199,8 +187,7 @@ OPJ_BOOL opj_bio_flush(opj_bio_t *bio) return OPJ_TRUE; } -OPJ_BOOL opj_bio_inalign(opj_bio_t *bio) -{ +OPJ_BOOL opj_bio_inalign(opj_bio_t *bio) { if ((bio->buf & 0xff) == 0xff) { if (! opj_bio_bytein(bio)) { return OPJ_FALSE; diff --git a/client/deps/openjpeg/bio.h b/client/deps/openjpeg/bio.h index d482f9ead..46f33af63 100644 --- a/client/deps/openjpeg/bio.h +++ b/client/deps/openjpeg/bio.h @@ -73,7 +73,7 @@ typedef struct opj_bio { Create a new BIO handle @return Returns a new BIO handle if successful, returns NULL otherwise */ -opj_bio_t* opj_bio_create(void); +opj_bio_t *opj_bio_create(void); /** Destroy a previously created BIO handle @param bio BIO handle to destroy diff --git a/client/deps/openjpeg/cio.c b/client/deps/openjpeg/cio.c index 4fde9fe23..a357236a1 100644 --- a/client/deps/openjpeg/cio.c +++ b/client/deps/openjpeg/cio.c @@ -44,21 +44,19 @@ /* ----------------------------------------------------------------------- */ -void opj_write_bytes_BE(OPJ_BYTE * p_buffer, OPJ_UINT32 p_value, - OPJ_UINT32 p_nb_bytes) -{ - const OPJ_BYTE * l_data_ptr = ((const OPJ_BYTE *) &p_value) + sizeof( - OPJ_UINT32) - p_nb_bytes; +void opj_write_bytes_BE(OPJ_BYTE *p_buffer, OPJ_UINT32 p_value, + OPJ_UINT32 p_nb_bytes) { + const OPJ_BYTE *l_data_ptr = ((const OPJ_BYTE *) &p_value) + sizeof( + OPJ_UINT32) - p_nb_bytes; assert(p_nb_bytes > 0 && p_nb_bytes <= sizeof(OPJ_UINT32)); memcpy(p_buffer, l_data_ptr, p_nb_bytes); } -void opj_write_bytes_LE(OPJ_BYTE * p_buffer, OPJ_UINT32 p_value, - OPJ_UINT32 p_nb_bytes) -{ - const OPJ_BYTE * l_data_ptr = ((const OPJ_BYTE *) &p_value) + p_nb_bytes - 1; +void opj_write_bytes_LE(OPJ_BYTE *p_buffer, OPJ_UINT32 p_value, + OPJ_UINT32 p_nb_bytes) { + const OPJ_BYTE *l_data_ptr = ((const OPJ_BYTE *) &p_value) + p_nb_bytes - 1; OPJ_UINT32 i; assert(p_nb_bytes > 0 && p_nb_bytes <= sizeof(OPJ_UINT32)); @@ -68,10 +66,9 @@ void opj_write_bytes_LE(OPJ_BYTE * p_buffer, OPJ_UINT32 p_value, } } -void opj_read_bytes_BE(const OPJ_BYTE * p_buffer, OPJ_UINT32 * p_value, - OPJ_UINT32 p_nb_bytes) -{ - OPJ_BYTE * l_data_ptr = ((OPJ_BYTE *) p_value); +void opj_read_bytes_BE(const OPJ_BYTE *p_buffer, OPJ_UINT32 *p_value, + OPJ_UINT32 p_nb_bytes) { + OPJ_BYTE *l_data_ptr = ((OPJ_BYTE *) p_value); assert(p_nb_bytes > 0 && p_nb_bytes <= sizeof(OPJ_UINT32)); @@ -79,10 +76,9 @@ void opj_read_bytes_BE(const OPJ_BYTE * p_buffer, OPJ_UINT32 * p_value, memcpy(l_data_ptr + sizeof(OPJ_UINT32) - p_nb_bytes, p_buffer, p_nb_bytes); } -void opj_read_bytes_LE(const OPJ_BYTE * p_buffer, OPJ_UINT32 * p_value, - OPJ_UINT32 p_nb_bytes) -{ - OPJ_BYTE * l_data_ptr = ((OPJ_BYTE *) p_value) + p_nb_bytes - 1; +void opj_read_bytes_LE(const OPJ_BYTE *p_buffer, OPJ_UINT32 *p_value, + OPJ_UINT32 p_nb_bytes) { + OPJ_BYTE *l_data_ptr = ((OPJ_BYTE *) p_value) + p_nb_bytes - 1; OPJ_UINT32 i; assert(p_nb_bytes > 0 && p_nb_bytes <= sizeof(OPJ_UINT32)); @@ -93,73 +89,64 @@ void opj_read_bytes_LE(const OPJ_BYTE * p_buffer, OPJ_UINT32 * p_value, } } -void opj_write_double_BE(OPJ_BYTE * p_buffer, OPJ_FLOAT64 p_value) -{ - const OPJ_BYTE * l_data_ptr = ((const OPJ_BYTE *) &p_value); +void opj_write_double_BE(OPJ_BYTE *p_buffer, OPJ_FLOAT64 p_value) { + const OPJ_BYTE *l_data_ptr = ((const OPJ_BYTE *) &p_value); memcpy(p_buffer, l_data_ptr, sizeof(OPJ_FLOAT64)); } -void opj_write_double_LE(OPJ_BYTE * p_buffer, OPJ_FLOAT64 p_value) -{ - const OPJ_BYTE * l_data_ptr = ((const OPJ_BYTE *) &p_value) + sizeof( - OPJ_FLOAT64) - 1; +void opj_write_double_LE(OPJ_BYTE *p_buffer, OPJ_FLOAT64 p_value) { + const OPJ_BYTE *l_data_ptr = ((const OPJ_BYTE *) &p_value) + sizeof( + OPJ_FLOAT64) - 1; OPJ_UINT32 i; for (i = 0; i < sizeof(OPJ_FLOAT64); ++i) { *(p_buffer++) = *(l_data_ptr--); } } -void opj_read_double_BE(const OPJ_BYTE * p_buffer, OPJ_FLOAT64 * p_value) -{ - OPJ_BYTE * l_data_ptr = ((OPJ_BYTE *) p_value); +void opj_read_double_BE(const OPJ_BYTE *p_buffer, OPJ_FLOAT64 *p_value) { + OPJ_BYTE *l_data_ptr = ((OPJ_BYTE *) p_value); memcpy(l_data_ptr, p_buffer, sizeof(OPJ_FLOAT64)); } -void opj_read_double_LE(const OPJ_BYTE * p_buffer, OPJ_FLOAT64 * p_value) -{ - OPJ_BYTE * l_data_ptr = ((OPJ_BYTE *) p_value) + sizeof(OPJ_FLOAT64) - 1; +void opj_read_double_LE(const OPJ_BYTE *p_buffer, OPJ_FLOAT64 *p_value) { + OPJ_BYTE *l_data_ptr = ((OPJ_BYTE *) p_value) + sizeof(OPJ_FLOAT64) - 1; OPJ_UINT32 i; for (i = 0; i < sizeof(OPJ_FLOAT64); ++i) { *(l_data_ptr--) = *(p_buffer++); } } -void opj_write_float_BE(OPJ_BYTE * p_buffer, OPJ_FLOAT32 p_value) -{ - const OPJ_BYTE * l_data_ptr = ((const OPJ_BYTE *) &p_value); +void opj_write_float_BE(OPJ_BYTE *p_buffer, OPJ_FLOAT32 p_value) { + const OPJ_BYTE *l_data_ptr = ((const OPJ_BYTE *) &p_value); memcpy(p_buffer, l_data_ptr, sizeof(OPJ_FLOAT32)); } -void opj_write_float_LE(OPJ_BYTE * p_buffer, OPJ_FLOAT32 p_value) -{ - const OPJ_BYTE * l_data_ptr = ((const OPJ_BYTE *) &p_value) + sizeof( - OPJ_FLOAT32) - 1; +void opj_write_float_LE(OPJ_BYTE *p_buffer, OPJ_FLOAT32 p_value) { + const OPJ_BYTE *l_data_ptr = ((const OPJ_BYTE *) &p_value) + sizeof( + OPJ_FLOAT32) - 1; OPJ_UINT32 i; for (i = 0; i < sizeof(OPJ_FLOAT32); ++i) { *(p_buffer++) = *(l_data_ptr--); } } -void opj_read_float_BE(const OPJ_BYTE * p_buffer, OPJ_FLOAT32 * p_value) -{ - OPJ_BYTE * l_data_ptr = ((OPJ_BYTE *) p_value); +void opj_read_float_BE(const OPJ_BYTE *p_buffer, OPJ_FLOAT32 *p_value) { + OPJ_BYTE *l_data_ptr = ((OPJ_BYTE *) p_value); memcpy(l_data_ptr, p_buffer, sizeof(OPJ_FLOAT32)); } -void opj_read_float_LE(const OPJ_BYTE * p_buffer, OPJ_FLOAT32 * p_value) -{ - OPJ_BYTE * l_data_ptr = ((OPJ_BYTE *) p_value) + sizeof(OPJ_FLOAT32) - 1; +void opj_read_float_LE(const OPJ_BYTE *p_buffer, OPJ_FLOAT32 *p_value) { + OPJ_BYTE *l_data_ptr = ((OPJ_BYTE *) p_value) + sizeof(OPJ_FLOAT32) - 1; OPJ_UINT32 i; for (i = 0; i < sizeof(OPJ_FLOAT32); ++i) { *(l_data_ptr--) = *(p_buffer++); } } -opj_stream_t* OPJ_CALLCONV opj_stream_create(OPJ_SIZE_T p_buffer_size, - OPJ_BOOL l_is_input) -{ - opj_stream_private_t * l_stream = 00; - l_stream = (opj_stream_private_t*) opj_calloc(1, sizeof(opj_stream_private_t)); +opj_stream_t *OPJ_CALLCONV opj_stream_create(OPJ_SIZE_T p_buffer_size, + OPJ_BOOL l_is_input) { + opj_stream_private_t *l_stream = 00; + l_stream = (opj_stream_private_t *) opj_calloc(1, sizeof(opj_stream_private_t)); if (! l_stream) { return 00; } @@ -191,14 +178,12 @@ opj_stream_t* OPJ_CALLCONV opj_stream_create(OPJ_SIZE_T p_buffer_size, return (opj_stream_t *) l_stream; } -opj_stream_t* OPJ_CALLCONV opj_stream_default_create(OPJ_BOOL l_is_input) -{ +opj_stream_t *OPJ_CALLCONV opj_stream_default_create(OPJ_BOOL l_is_input) { return opj_stream_create(OPJ_J2K_STREAM_CHUNK_SIZE, l_is_input); } -void OPJ_CALLCONV opj_stream_destroy(opj_stream_t* p_stream) -{ - opj_stream_private_t* l_stream = (opj_stream_private_t*) p_stream; +void OPJ_CALLCONV opj_stream_destroy(opj_stream_t *p_stream) { + opj_stream_private_t *l_stream = (opj_stream_private_t *) p_stream; if (l_stream) { if (l_stream->m_free_user_data_fn) { @@ -210,10 +195,9 @@ void OPJ_CALLCONV opj_stream_destroy(opj_stream_t* p_stream) } } -void OPJ_CALLCONV opj_stream_set_read_function(opj_stream_t* p_stream, - opj_stream_read_fn p_function) -{ - opj_stream_private_t* l_stream = (opj_stream_private_t*) p_stream; +void OPJ_CALLCONV opj_stream_set_read_function(opj_stream_t *p_stream, + opj_stream_read_fn p_function) { + opj_stream_private_t *l_stream = (opj_stream_private_t *) p_stream; if ((!l_stream) || (!(l_stream->m_status & OPJ_STREAM_STATUS_INPUT))) { return; @@ -222,10 +206,9 @@ void OPJ_CALLCONV opj_stream_set_read_function(opj_stream_t* p_stream, l_stream->m_read_fn = p_function; } -void OPJ_CALLCONV opj_stream_set_seek_function(opj_stream_t* p_stream, - opj_stream_seek_fn p_function) -{ - opj_stream_private_t* l_stream = (opj_stream_private_t*) p_stream; +void OPJ_CALLCONV opj_stream_set_seek_function(opj_stream_t *p_stream, + opj_stream_seek_fn p_function) { + opj_stream_private_t *l_stream = (opj_stream_private_t *) p_stream; if (!l_stream) { return; @@ -233,10 +216,9 @@ void OPJ_CALLCONV opj_stream_set_seek_function(opj_stream_t* p_stream, l_stream->m_seek_fn = p_function; } -void OPJ_CALLCONV opj_stream_set_write_function(opj_stream_t* p_stream, - opj_stream_write_fn p_function) -{ - opj_stream_private_t* l_stream = (opj_stream_private_t*) p_stream; +void OPJ_CALLCONV opj_stream_set_write_function(opj_stream_t *p_stream, + opj_stream_write_fn p_function) { + opj_stream_private_t *l_stream = (opj_stream_private_t *) p_stream; if ((!l_stream) || (!(l_stream->m_status & OPJ_STREAM_STATUS_OUTPUT))) { return; @@ -245,10 +227,9 @@ void OPJ_CALLCONV opj_stream_set_write_function(opj_stream_t* p_stream, l_stream->m_write_fn = p_function; } -void OPJ_CALLCONV opj_stream_set_skip_function(opj_stream_t* p_stream, - opj_stream_skip_fn p_function) -{ - opj_stream_private_t* l_stream = (opj_stream_private_t*) p_stream; +void OPJ_CALLCONV opj_stream_set_skip_function(opj_stream_t *p_stream, + opj_stream_skip_fn p_function) { + opj_stream_private_t *l_stream = (opj_stream_private_t *) p_stream; if (! l_stream) { return; @@ -257,10 +238,9 @@ void OPJ_CALLCONV opj_stream_set_skip_function(opj_stream_t* p_stream, l_stream->m_skip_fn = p_function; } -void OPJ_CALLCONV opj_stream_set_user_data(opj_stream_t* p_stream, - void * p_data, opj_stream_free_user_data_fn p_function) -{ - opj_stream_private_t* l_stream = (opj_stream_private_t*) p_stream; +void OPJ_CALLCONV opj_stream_set_user_data(opj_stream_t *p_stream, + void *p_data, opj_stream_free_user_data_fn p_function) { + opj_stream_private_t *l_stream = (opj_stream_private_t *) p_stream; if (!l_stream) { return; } @@ -268,19 +248,17 @@ void OPJ_CALLCONV opj_stream_set_user_data(opj_stream_t* p_stream, l_stream->m_free_user_data_fn = p_function; } -void OPJ_CALLCONV opj_stream_set_user_data_length(opj_stream_t* p_stream, - OPJ_UINT64 data_length) -{ - opj_stream_private_t* l_stream = (opj_stream_private_t*) p_stream; +void OPJ_CALLCONV opj_stream_set_user_data_length(opj_stream_t *p_stream, + OPJ_UINT64 data_length) { + opj_stream_private_t *l_stream = (opj_stream_private_t *) p_stream; if (!l_stream) { return; } l_stream->m_user_data_length = data_length; } -OPJ_SIZE_T opj_stream_read_data(opj_stream_private_t * p_stream, - OPJ_BYTE * p_buffer, OPJ_SIZE_T p_size, opj_event_mgr_t * p_event_mgr) -{ +OPJ_SIZE_T opj_stream_read_data(opj_stream_private_t *p_stream, + OPJ_BYTE *p_buffer, OPJ_SIZE_T p_size, opj_event_mgr_t *p_event_mgr) { OPJ_SIZE_T l_read_nb_bytes = 0; if (p_stream->m_bytes_in_buffer >= p_size) { memcpy(p_buffer, p_stream->m_current_data, p_size); @@ -322,7 +300,7 @@ OPJ_SIZE_T opj_stream_read_data(opj_stream_private_t * p_stream, if (p_size < p_stream->m_buffer_size) { /* we should do an actual read on the media */ p_stream->m_bytes_in_buffer = p_stream->m_read_fn(p_stream->m_stored_data, - p_stream->m_buffer_size, p_stream->m_user_data); + p_stream->m_buffer_size, p_stream->m_user_data); if (p_stream->m_bytes_in_buffer == (OPJ_SIZE_T) - 1) { /* end of stream */ @@ -352,7 +330,7 @@ OPJ_SIZE_T opj_stream_read_data(opj_stream_private_t * p_stream, } else { /* direct read on the dest buffer */ p_stream->m_bytes_in_buffer = p_stream->m_read_fn(p_buffer, p_size, - p_stream->m_user_data); + p_stream->m_user_data); if (p_stream->m_bytes_in_buffer == (OPJ_SIZE_T) - 1) { /* end of stream */ @@ -382,11 +360,10 @@ OPJ_SIZE_T opj_stream_read_data(opj_stream_private_t * p_stream, } } -OPJ_SIZE_T opj_stream_write_data(opj_stream_private_t * p_stream, - const OPJ_BYTE * p_buffer, +OPJ_SIZE_T opj_stream_write_data(opj_stream_private_t *p_stream, + const OPJ_BYTE *p_buffer, OPJ_SIZE_T p_size, - opj_event_mgr_t * p_event_mgr) -{ + opj_event_mgr_t *p_event_mgr) { OPJ_SIZE_T l_remaining_bytes = 0; OPJ_SIZE_T l_write_nb_bytes = 0; @@ -430,9 +407,8 @@ OPJ_SIZE_T opj_stream_write_data(opj_stream_private_t * p_stream, } -OPJ_BOOL opj_stream_flush(opj_stream_private_t * p_stream, - opj_event_mgr_t * p_event_mgr) -{ +OPJ_BOOL opj_stream_flush(opj_stream_private_t *p_stream, + opj_event_mgr_t *p_event_mgr) { /* the number of bytes written on the media. */ OPJ_SIZE_T l_current_write_nb_bytes = 0; @@ -441,8 +417,8 @@ OPJ_BOOL opj_stream_flush(opj_stream_private_t * p_stream, while (p_stream->m_bytes_in_buffer) { /* we should do an actual write on the media */ l_current_write_nb_bytes = p_stream->m_write_fn(p_stream->m_current_data, - p_stream->m_bytes_in_buffer, - p_stream->m_user_data); + p_stream->m_bytes_in_buffer, + p_stream->m_user_data); if (l_current_write_nb_bytes == (OPJ_SIZE_T) - 1) { p_stream->m_status |= OPJ_STREAM_STATUS_ERROR; @@ -460,9 +436,8 @@ OPJ_BOOL opj_stream_flush(opj_stream_private_t * p_stream, return OPJ_TRUE; } -OPJ_OFF_T opj_stream_read_skip(opj_stream_private_t * p_stream, - OPJ_OFF_T p_size, opj_event_mgr_t * p_event_mgr) -{ +OPJ_OFF_T opj_stream_read_skip(opj_stream_private_t *p_stream, + OPJ_OFF_T p_size, opj_event_mgr_t *p_event_mgr) { OPJ_OFF_T l_skip_nb_bytes = 0; OPJ_OFF_T l_current_skip_nb_bytes = 0; @@ -535,9 +510,8 @@ OPJ_OFF_T opj_stream_read_skip(opj_stream_private_t * p_stream, return l_skip_nb_bytes; } -OPJ_OFF_T opj_stream_write_skip(opj_stream_private_t * p_stream, - OPJ_OFF_T p_size, opj_event_mgr_t * p_event_mgr) -{ +OPJ_OFF_T opj_stream_write_skip(opj_stream_private_t *p_stream, + OPJ_OFF_T p_size, opj_event_mgr_t *p_event_mgr) { OPJ_BOOL l_is_written = 0; OPJ_OFF_T l_current_skip_nb_bytes = 0; OPJ_OFF_T l_skip_nb_bytes = 0; @@ -576,13 +550,11 @@ OPJ_OFF_T opj_stream_write_skip(opj_stream_private_t * p_stream, return l_skip_nb_bytes; } -OPJ_OFF_T opj_stream_tell(const opj_stream_private_t * p_stream) -{ +OPJ_OFF_T opj_stream_tell(const opj_stream_private_t *p_stream) { return p_stream->m_byte_offset; } -OPJ_OFF_T opj_stream_get_number_byte_left(const opj_stream_private_t * p_stream) -{ +OPJ_OFF_T opj_stream_get_number_byte_left(const opj_stream_private_t *p_stream) { assert(p_stream->m_byte_offset >= 0); assert(p_stream->m_user_data_length >= (OPJ_UINT64)p_stream->m_byte_offset); return p_stream->m_user_data_length ? @@ -590,16 +562,14 @@ OPJ_OFF_T opj_stream_get_number_byte_left(const opj_stream_private_t * p_stream) 0; } -OPJ_OFF_T opj_stream_skip(opj_stream_private_t * p_stream, OPJ_OFF_T p_size, - opj_event_mgr_t * p_event_mgr) -{ +OPJ_OFF_T opj_stream_skip(opj_stream_private_t *p_stream, OPJ_OFF_T p_size, + opj_event_mgr_t *p_event_mgr) { assert(p_size >= 0); return p_stream->m_opj_skip(p_stream, p_size, p_event_mgr); } -OPJ_BOOL opj_stream_read_seek(opj_stream_private_t * p_stream, OPJ_OFF_T p_size, - opj_event_mgr_t * p_event_mgr) -{ +OPJ_BOOL opj_stream_read_seek(opj_stream_private_t *p_stream, OPJ_OFF_T p_size, + opj_event_mgr_t *p_event_mgr) { OPJ_ARG_NOT_USED(p_event_mgr); p_stream->m_current_data = p_stream->m_stored_data; p_stream->m_bytes_in_buffer = 0; @@ -617,9 +587,8 @@ OPJ_BOOL opj_stream_read_seek(opj_stream_private_t * p_stream, OPJ_OFF_T p_size, return OPJ_TRUE; } -OPJ_BOOL opj_stream_write_seek(opj_stream_private_t * p_stream, - OPJ_OFF_T p_size, opj_event_mgr_t * p_event_mgr) -{ +OPJ_BOOL opj_stream_write_seek(opj_stream_private_t *p_stream, + OPJ_OFF_T p_size, opj_event_mgr_t *p_event_mgr) { if (! opj_stream_flush(p_stream, p_event_mgr)) { p_stream->m_status |= OPJ_STREAM_STATUS_ERROR; return OPJ_FALSE; @@ -638,45 +607,39 @@ OPJ_BOOL opj_stream_write_seek(opj_stream_private_t * p_stream, return OPJ_TRUE; } -OPJ_BOOL opj_stream_seek(opj_stream_private_t * p_stream, OPJ_OFF_T p_size, - struct opj_event_mgr * p_event_mgr) -{ +OPJ_BOOL opj_stream_seek(opj_stream_private_t *p_stream, OPJ_OFF_T p_size, + struct opj_event_mgr *p_event_mgr) { assert(p_size >= 0); return p_stream->m_opj_seek(p_stream, p_size, p_event_mgr); } -OPJ_BOOL opj_stream_has_seek(const opj_stream_private_t * p_stream) -{ +OPJ_BOOL opj_stream_has_seek(const opj_stream_private_t *p_stream) { return p_stream->m_seek_fn != opj_stream_default_seek; } -OPJ_SIZE_T opj_stream_default_read(void * p_buffer, OPJ_SIZE_T p_nb_bytes, - void * p_user_data) -{ +OPJ_SIZE_T opj_stream_default_read(void *p_buffer, OPJ_SIZE_T p_nb_bytes, + void *p_user_data) { OPJ_ARG_NOT_USED(p_buffer); OPJ_ARG_NOT_USED(p_nb_bytes); OPJ_ARG_NOT_USED(p_user_data); return (OPJ_SIZE_T) - 1; } -OPJ_SIZE_T opj_stream_default_write(void * p_buffer, OPJ_SIZE_T p_nb_bytes, - void * p_user_data) -{ +OPJ_SIZE_T opj_stream_default_write(void *p_buffer, OPJ_SIZE_T p_nb_bytes, + void *p_user_data) { OPJ_ARG_NOT_USED(p_buffer); OPJ_ARG_NOT_USED(p_nb_bytes); OPJ_ARG_NOT_USED(p_user_data); return (OPJ_SIZE_T) - 1; } -OPJ_OFF_T opj_stream_default_skip(OPJ_OFF_T p_nb_bytes, void * p_user_data) -{ +OPJ_OFF_T opj_stream_default_skip(OPJ_OFF_T p_nb_bytes, void *p_user_data) { OPJ_ARG_NOT_USED(p_nb_bytes); OPJ_ARG_NOT_USED(p_user_data); return (OPJ_OFF_T) - 1; } -OPJ_BOOL opj_stream_default_seek(OPJ_OFF_T p_nb_bytes, void * p_user_data) -{ +OPJ_BOOL opj_stream_default_seek(OPJ_OFF_T p_nb_bytes, void *p_user_data) { OPJ_ARG_NOT_USED(p_nb_bytes); OPJ_ARG_NOT_USED(p_user_data); return OPJ_FALSE; diff --git a/client/deps/openjpeg/cio.h b/client/deps/openjpeg/cio.h index 7caee30af..c763a7c96 100644 --- a/client/deps/openjpeg/cio.h +++ b/client/deps/openjpeg/cio.h @@ -82,7 +82,7 @@ typedef struct opj_stream_private { /** * User data, be it files, ... The actual data depends on the type of the stream. */ - void * m_user_data; + void *m_user_data; /** * Pointer to function to free m_user_data (NULL at initialization) @@ -121,12 +121,12 @@ typedef struct opj_stream_private { * Actual data stored into the stream if read from. Data is read by chunk of fixed size. * you should never access this data directly. */ - OPJ_BYTE * m_stored_data; + OPJ_BYTE *m_stored_data; /** * Pointer to the current read data. */ - OPJ_BYTE * m_current_data; + OPJ_BYTE *m_current_data; /** * FIXME DOC. @@ -173,7 +173,7 @@ opj_stream_private_t; * @param p_value the value to write * @param p_nb_bytes the number of bytes to write */ -void opj_write_bytes_BE(OPJ_BYTE * p_buffer, OPJ_UINT32 p_value, +void opj_write_bytes_BE(OPJ_BYTE *p_buffer, OPJ_UINT32 p_value, OPJ_UINT32 p_nb_bytes); /** @@ -183,7 +183,7 @@ void opj_write_bytes_BE(OPJ_BYTE * p_buffer, OPJ_UINT32 p_value, * @param p_nb_bytes the nb bytes to read. * @return the number of bytes read or -1 if an error occurred. */ -void opj_read_bytes_BE(const OPJ_BYTE * p_buffer, OPJ_UINT32 * p_value, +void opj_read_bytes_BE(const OPJ_BYTE *p_buffer, OPJ_UINT32 *p_value, OPJ_UINT32 p_nb_bytes); /** @@ -193,7 +193,7 @@ void opj_read_bytes_BE(const OPJ_BYTE * p_buffer, OPJ_UINT32 * p_value, * @param p_nb_bytes the number of bytes to write * @return the number of bytes written or -1 if an error occurred */ -void opj_write_bytes_LE(OPJ_BYTE * p_buffer, OPJ_UINT32 p_value, +void opj_write_bytes_LE(OPJ_BYTE *p_buffer, OPJ_UINT32 p_value, OPJ_UINT32 p_nb_bytes); /** @@ -203,7 +203,7 @@ void opj_write_bytes_LE(OPJ_BYTE * p_buffer, OPJ_UINT32 p_value, * @param p_nb_bytes the nb bytes to read. * @return the number of bytes read or -1 if an error occurred. */ -void opj_read_bytes_LE(const OPJ_BYTE * p_buffer, OPJ_UINT32 * p_value, +void opj_read_bytes_LE(const OPJ_BYTE *p_buffer, OPJ_UINT32 *p_value, OPJ_UINT32 p_nb_bytes); @@ -212,56 +212,56 @@ void opj_read_bytes_LE(const OPJ_BYTE * p_buffer, OPJ_UINT32 * p_value, * @param p_buffer pointer the data buffer to write data to. * @param p_value the value to write */ -void opj_write_double_LE(OPJ_BYTE * p_buffer, OPJ_FLOAT64 p_value); +void opj_write_double_LE(OPJ_BYTE *p_buffer, OPJ_FLOAT64 p_value); /*** * Write some bytes to the given data buffer, this function is used in Big Endian cpus. * @param p_buffer pointer the data buffer to write data to. * @param p_value the value to write */ -void opj_write_double_BE(OPJ_BYTE * p_buffer, OPJ_FLOAT64 p_value); +void opj_write_double_BE(OPJ_BYTE *p_buffer, OPJ_FLOAT64 p_value); /** * Reads some bytes from the given data buffer, this function is used in Little Endian cpus. * @param p_buffer pointer the data buffer to read data from. * @param p_value pointer to the value that will store the data. */ -void opj_read_double_LE(const OPJ_BYTE * p_buffer, OPJ_FLOAT64 * p_value); +void opj_read_double_LE(const OPJ_BYTE *p_buffer, OPJ_FLOAT64 *p_value); /** * Reads some bytes from the given data buffer, this function is used in Big Endian cpus. * @param p_buffer pointer the data buffer to read data from. * @param p_value pointer to the value that will store the data. */ -void opj_read_double_BE(const OPJ_BYTE * p_buffer, OPJ_FLOAT64 * p_value); +void opj_read_double_BE(const OPJ_BYTE *p_buffer, OPJ_FLOAT64 *p_value); /** * Reads some bytes from the given data buffer, this function is used in Little Endian cpus. * @param p_buffer pointer the data buffer to read data from. * @param p_value pointer to the value that will store the data. */ -void opj_read_float_LE(const OPJ_BYTE * p_buffer, OPJ_FLOAT32 * p_value); +void opj_read_float_LE(const OPJ_BYTE *p_buffer, OPJ_FLOAT32 *p_value); /** * Reads some bytes from the given data buffer, this function is used in Big Endian cpus. * @param p_buffer pointer the data buffer to read data from. * @param p_value pointer to the value that will store the data. */ -void opj_read_float_BE(const OPJ_BYTE * p_buffer, OPJ_FLOAT32 * p_value); +void opj_read_float_BE(const OPJ_BYTE *p_buffer, OPJ_FLOAT32 *p_value); /** * Write some bytes to the given data buffer, this function is used in Little Endian cpus. * @param p_buffer pointer the data buffer to write data to. * @param p_value the value to write */ -void opj_write_float_LE(OPJ_BYTE * p_buffer, OPJ_FLOAT32 p_value); +void opj_write_float_LE(OPJ_BYTE *p_buffer, OPJ_FLOAT32 p_value); /*** * Write some bytes to the given data buffer, this function is used in Big Endian cpus. * @param p_buffer pointer the data buffer to write data to. * @param p_value the value to write */ -void opj_write_float_BE(OPJ_BYTE * p_buffer, OPJ_FLOAT32 p_value); +void opj_write_float_BE(OPJ_BYTE *p_buffer, OPJ_FLOAT32 p_value); /** * Reads some bytes from the stream. @@ -271,8 +271,8 @@ void opj_write_float_BE(OPJ_BYTE * p_buffer, OPJ_FLOAT32 p_value); * @param p_event_mgr the user event manager to be notified of special events. * @return the number of bytes read, or -1 if an error occurred or if the stream is at the end. */ -OPJ_SIZE_T opj_stream_read_data(opj_stream_private_t * p_stream, - OPJ_BYTE * p_buffer, OPJ_SIZE_T p_size, struct opj_event_mgr * p_event_mgr); +OPJ_SIZE_T opj_stream_read_data(opj_stream_private_t *p_stream, + OPJ_BYTE *p_buffer, OPJ_SIZE_T p_size, struct opj_event_mgr *p_event_mgr); /** * Writes some bytes to the stream. @@ -282,9 +282,9 @@ OPJ_SIZE_T opj_stream_read_data(opj_stream_private_t * p_stream, * @param p_event_mgr the user event manager to be notified of special events. * @return the number of bytes writtent, or -1 if an error occurred. */ -OPJ_SIZE_T opj_stream_write_data(opj_stream_private_t * p_stream, - const OPJ_BYTE * p_buffer, OPJ_SIZE_T p_size, - struct opj_event_mgr * p_event_mgr); +OPJ_SIZE_T opj_stream_write_data(opj_stream_private_t *p_stream, + const OPJ_BYTE *p_buffer, OPJ_SIZE_T p_size, + struct opj_event_mgr *p_event_mgr); /** * Writes the content of the stream buffer to the stream. @@ -292,8 +292,8 @@ OPJ_SIZE_T opj_stream_write_data(opj_stream_private_t * p_stream, * @param p_event_mgr the user event manager to be notified of special events. * @return true if the data could be flushed, false else. */ -OPJ_BOOL opj_stream_flush(opj_stream_private_t * p_stream, - struct opj_event_mgr * p_event_mgr); +OPJ_BOOL opj_stream_flush(opj_stream_private_t *p_stream, + struct opj_event_mgr *p_event_mgr); /** * Skips a number of bytes from the stream. @@ -302,8 +302,8 @@ OPJ_BOOL opj_stream_flush(opj_stream_private_t * p_stream, * @param p_event_mgr the user event manager to be notified of special events. * @return the number of bytes skipped, or -1 if an error occurred. */ -OPJ_OFF_T opj_stream_skip(opj_stream_private_t * p_stream, OPJ_OFF_T p_size, - struct opj_event_mgr * p_event_mgr); +OPJ_OFF_T opj_stream_skip(opj_stream_private_t *p_stream, OPJ_OFF_T p_size, + struct opj_event_mgr *p_event_mgr); /** * Tells the byte offset on the stream (similar to ftell). @@ -312,7 +312,7 @@ OPJ_OFF_T opj_stream_skip(opj_stream_private_t * p_stream, OPJ_OFF_T p_size, * * @return the current position o fthe stream. */ -OPJ_OFF_T opj_stream_tell(const opj_stream_private_t * p_stream); +OPJ_OFF_T opj_stream_tell(const opj_stream_private_t *p_stream); /** @@ -323,7 +323,7 @@ OPJ_OFF_T opj_stream_tell(const opj_stream_private_t * p_stream); * @return Number of bytes left before the end of the stream. */ OPJ_OFF_T opj_stream_get_number_byte_left(const opj_stream_private_t * - p_stream); + p_stream); /** * Skips a number of bytes from the stream. @@ -332,8 +332,8 @@ OPJ_OFF_T opj_stream_get_number_byte_left(const opj_stream_private_t * * @param p_event_mgr the user event manager to be notified of special events. * @return the number of bytes skipped, or -1 if an error occurred. */ -OPJ_OFF_T opj_stream_write_skip(opj_stream_private_t * p_stream, - OPJ_OFF_T p_size, struct opj_event_mgr * p_event_mgr); +OPJ_OFF_T opj_stream_write_skip(opj_stream_private_t *p_stream, + OPJ_OFF_T p_size, struct opj_event_mgr *p_event_mgr); /** * Skips a number of bytes from the stream. @@ -342,8 +342,8 @@ OPJ_OFF_T opj_stream_write_skip(opj_stream_private_t * p_stream, * @param p_event_mgr the user event manager to be notified of special events. * @return the number of bytes skipped, or -1 if an error occurred. */ -OPJ_OFF_T opj_stream_read_skip(opj_stream_private_t * p_stream, - OPJ_OFF_T p_size, struct opj_event_mgr * p_event_mgr); +OPJ_OFF_T opj_stream_read_skip(opj_stream_private_t *p_stream, + OPJ_OFF_T p_size, struct opj_event_mgr *p_event_mgr); /** * Skips a number of bytes from the stream. @@ -352,8 +352,8 @@ OPJ_OFF_T opj_stream_read_skip(opj_stream_private_t * p_stream, * @param p_event_mgr the user event manager to be notified of special events. * @return OPJ_TRUE if success, or OPJ_FALSE if an error occurred. */ -OPJ_BOOL opj_stream_read_seek(opj_stream_private_t * p_stream, OPJ_OFF_T p_size, - struct opj_event_mgr * p_event_mgr); +OPJ_BOOL opj_stream_read_seek(opj_stream_private_t *p_stream, OPJ_OFF_T p_size, + struct opj_event_mgr *p_event_mgr); /** * Skips a number of bytes from the stream. @@ -362,8 +362,8 @@ OPJ_BOOL opj_stream_read_seek(opj_stream_private_t * p_stream, OPJ_OFF_T p_size, * @param p_event_mgr the user event manager to be notified of special events. * @return the number of bytes skipped, or -1 if an error occurred. */ -OPJ_BOOL opj_stream_write_seek(opj_stream_private_t * p_stream, - OPJ_OFF_T p_size, struct opj_event_mgr * p_event_mgr); +OPJ_BOOL opj_stream_write_seek(opj_stream_private_t *p_stream, + OPJ_OFF_T p_size, struct opj_event_mgr *p_event_mgr); /** * Seeks a number of bytes from the stream. @@ -372,35 +372,35 @@ OPJ_BOOL opj_stream_write_seek(opj_stream_private_t * p_stream, * @param p_event_mgr the user event manager to be notified of special events. * @return true if the stream is seekable. */ -OPJ_BOOL opj_stream_seek(opj_stream_private_t * p_stream, OPJ_OFF_T p_size, - struct opj_event_mgr * p_event_mgr); +OPJ_BOOL opj_stream_seek(opj_stream_private_t *p_stream, OPJ_OFF_T p_size, + struct opj_event_mgr *p_event_mgr); /** * Tells if the given stream is seekable. */ -OPJ_BOOL opj_stream_has_seek(const opj_stream_private_t * p_stream); +OPJ_BOOL opj_stream_has_seek(const opj_stream_private_t *p_stream); /** * FIXME DOC. */ -OPJ_SIZE_T opj_stream_default_read(void * p_buffer, OPJ_SIZE_T p_nb_bytes, - void * p_user_data); +OPJ_SIZE_T opj_stream_default_read(void *p_buffer, OPJ_SIZE_T p_nb_bytes, + void *p_user_data); /** * FIXME DOC. */ -OPJ_SIZE_T opj_stream_default_write(void * p_buffer, OPJ_SIZE_T p_nb_bytes, - void * p_user_data); +OPJ_SIZE_T opj_stream_default_write(void *p_buffer, OPJ_SIZE_T p_nb_bytes, + void *p_user_data); /** * FIXME DOC. */ -OPJ_OFF_T opj_stream_default_skip(OPJ_OFF_T p_nb_bytes, void * p_user_data); +OPJ_OFF_T opj_stream_default_skip(OPJ_OFF_T p_nb_bytes, void *p_user_data); /** * FIXME DOC. */ -OPJ_BOOL opj_stream_default_seek(OPJ_OFF_T p_nb_bytes, void * p_user_data); +OPJ_BOOL opj_stream_default_seek(OPJ_OFF_T p_nb_bytes, void *p_user_data); /* ----------------------------------------------------------------------- */ /*@}*/ diff --git a/client/deps/openjpeg/dwt.c b/client/deps/openjpeg/dwt.c index 11aae472d..7bbf4a76c 100644 --- a/client/deps/openjpeg/dwt.c +++ b/client/deps/openjpeg/dwt.c @@ -84,7 +84,7 @@ /*@{*/ typedef struct dwt_local { - OPJ_INT32* mem; + OPJ_INT32 *mem; OPJ_INT32 dn; /* number of elements in high pass band */ OPJ_INT32 sn; /* number of elements in low pass band */ OPJ_INT32 cas; /* 0 = start on even coord, 1 = start on odd coord */ @@ -97,7 +97,7 @@ typedef union { } opj_v8_t; typedef struct v8dwt_local { - opj_v8_t* wavelet ; + opj_v8_t *wavelet ; OPJ_INT32 dn ; /* number of elements in high pass band */ OPJ_INT32 sn ; /* number of elements in low pass band */ OPJ_INT32 cas ; /* 0 = start on even coord, 1 = start on odd coord */ @@ -124,8 +124,8 @@ static const OPJ_FLOAT32 opj_invK = (OPJ_FLOAT32)(1.0 / 1.230174105); /** Forward lazy transform (horizontal) */ -static void opj_dwt_deinterleave_h(const OPJ_INT32 * OPJ_RESTRICT a, - OPJ_INT32 * OPJ_RESTRICT b, +static void opj_dwt_deinterleave_h(const OPJ_INT32 *OPJ_RESTRICT a, + OPJ_INT32 *OPJ_RESTRICT b, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_INT32 cas); @@ -142,11 +142,11 @@ static void opj_dwt_encode_stepsize(OPJ_INT32 stepsize, OPJ_INT32 numbps, /** Inverse wavelet transform in 2-D. */ -static OPJ_BOOL opj_dwt_decode_tile(opj_thread_pool_t* tp, - opj_tcd_tilecomp_t* tilec, OPJ_UINT32 i); +static OPJ_BOOL opj_dwt_decode_tile(opj_thread_pool_t *tp, + opj_tcd_tilecomp_t *tilec, OPJ_UINT32 i); static OPJ_BOOL opj_dwt_decode_partial_tile( - opj_tcd_tilecomp_t* tilec, + opj_tcd_tilecomp_t *tilec, OPJ_UINT32 numres); /* Forward transform, for the vertical pass, processing cols columns */ @@ -167,14 +167,14 @@ typedef void (*opj_encode_and_deinterleave_h_one_row_fnptr_type)( OPJ_UINT32 width, OPJ_BOOL even); -static OPJ_BOOL opj_dwt_encode_procedure(opj_thread_pool_t* tp, - opj_tcd_tilecomp_t * tilec, - opj_encode_and_deinterleave_v_fnptr_type p_encode_and_deinterleave_v, - opj_encode_and_deinterleave_h_one_row_fnptr_type - p_encode_and_deinterleave_h_one_row); +static OPJ_BOOL opj_dwt_encode_procedure(opj_thread_pool_t *tp, + opj_tcd_tilecomp_t *tilec, + opj_encode_and_deinterleave_v_fnptr_type p_encode_and_deinterleave_v, + opj_encode_and_deinterleave_h_one_row_fnptr_type + p_encode_and_deinterleave_h_one_row); -static OPJ_UINT32 opj_dwt_max_resolution(opj_tcd_resolution_t* OPJ_RESTRICT r, - OPJ_UINT32 i); +static OPJ_UINT32 opj_dwt_max_resolution(opj_tcd_resolution_t *OPJ_RESTRICT r, + OPJ_UINT32 i); /* */ /* Inverse 9-7 wavelet transform in 1-D. */ @@ -225,14 +225,13 @@ static const OPJ_FLOAT64 opj_dwt_norms_real[4][10] = { /* */ /* Forward lazy transform (horizontal). */ /* */ -static void opj_dwt_deinterleave_h(const OPJ_INT32 * OPJ_RESTRICT a, - OPJ_INT32 * OPJ_RESTRICT b, +static void opj_dwt_deinterleave_h(const OPJ_INT32 *OPJ_RESTRICT a, + OPJ_INT32 *OPJ_RESTRICT b, OPJ_INT32 dn, - OPJ_INT32 sn, OPJ_INT32 cas) -{ + OPJ_INT32 sn, OPJ_INT32 cas) { OPJ_INT32 i; - OPJ_INT32 * OPJ_RESTRICT l_dest = b; - const OPJ_INT32 * OPJ_RESTRICT l_src = a + cas; + OPJ_INT32 *OPJ_RESTRICT l_dest = b; + const OPJ_INT32 *OPJ_RESTRICT l_src = a + cas; for (i = 0; i < sn; ++i) { *l_dest++ = *l_src; @@ -252,8 +251,7 @@ static void opj_dwt_deinterleave_h(const OPJ_INT32 * OPJ_RESTRICT a, /* */ /* Inverse lazy transform (horizontal). */ /* */ -static void opj_dwt_interleave_h(const opj_dwt_t* h, OPJ_INT32 *a) -{ +static void opj_dwt_interleave_h(const opj_dwt_t *h, OPJ_INT32 *a) { const OPJ_INT32 *ai = a; OPJ_INT32 *bi = h->mem + h->cas; OPJ_INT32 i = h->sn; @@ -273,8 +271,7 @@ static void opj_dwt_interleave_h(const opj_dwt_t* h, OPJ_INT32 *a) /* */ /* Inverse lazy transform (vertical). */ /* */ -static void opj_dwt_interleave_v(const opj_dwt_t* v, OPJ_INT32 *a, OPJ_INT32 x) -{ +static void opj_dwt_interleave_v(const opj_dwt_t *v, OPJ_INT32 *a, OPJ_INT32 x) { const OPJ_INT32 *ai = a; OPJ_INT32 *bi = v->mem + v->cas; OPJ_INT32 i = v->sn; @@ -300,8 +297,7 @@ static void opj_dwt_interleave_v(const opj_dwt_t* v, OPJ_INT32 *a, OPJ_INT32 x) /* Inverse 5-3 wavelet transform in 1-D. */ /* */ static void opj_dwt_decode_1_(OPJ_INT32 *a, OPJ_INT32 dn, OPJ_INT32 sn, - OPJ_INT32 cas) -{ + OPJ_INT32 cas) { OPJ_INT32 i; if (!cas) { @@ -327,27 +323,25 @@ static void opj_dwt_decode_1_(OPJ_INT32 *a, OPJ_INT32 dn, OPJ_INT32 sn, } } -static void opj_dwt_decode_1(const opj_dwt_t *v) -{ +static void opj_dwt_decode_1(const opj_dwt_t *v) { opj_dwt_decode_1_(v->mem, v->dn, v->sn, v->cas); } #endif /* STANDARD_SLOW_VERSION */ #if defined(__AVX512F__) -static int32_t loop_short_sse(int32_t len, const int32_t** lf_ptr, - const int32_t** hf_ptr, int32_t** out_ptr, - int32_t* prev_even) -{ +static int32_t loop_short_sse(int32_t len, const int32_t **lf_ptr, + const int32_t **hf_ptr, int32_t **out_ptr, + int32_t *prev_even) { int32_t next_even; __m128i odd, even_m1, unpack1, unpack2; const int32_t batch = (len - 2) / 8; const __m128i two = _mm_set1_epi32(2); for (int32_t i = 0; i < batch; i++) { - const __m128i lf_ = _mm_loadu_si128((__m128i*)(*lf_ptr + 1)); - const __m128i hf1_ = _mm_loadu_si128((__m128i*)(*hf_ptr)); - const __m128i hf2_ = _mm_loadu_si128((__m128i*)(*hf_ptr + 1)); + const __m128i lf_ = _mm_loadu_si128((__m128i *)(*lf_ptr + 1)); + const __m128i hf1_ = _mm_loadu_si128((__m128i *)(*hf_ptr)); + const __m128i hf2_ = _mm_loadu_si128((__m128i *)(*hf_ptr + 1)); __m128i even = _mm_add_epi32(hf1_, hf2_); even = _mm_add_epi32(even, two); @@ -366,8 +360,8 @@ static int32_t loop_short_sse(int32_t len, const int32_t** lf_ptr, unpack1 = _mm_unpacklo_epi32(even_m1, odd); unpack2 = _mm_unpackhi_epi32(even_m1, odd); - _mm_storeu_si128((__m128i*)(*out_ptr + 0), unpack1); - _mm_storeu_si128((__m128i*)(*out_ptr + 4), unpack2); + _mm_storeu_si128((__m128i *)(*out_ptr + 0), unpack1); + _mm_storeu_si128((__m128i *)(*out_ptr + 4), unpack2); *prev_even = next_even; @@ -380,14 +374,13 @@ static int32_t loop_short_sse(int32_t len, const int32_t** lf_ptr, #endif #if !defined(STANDARD_SLOW_VERSION) -static void opj_idwt53_h_cas0(OPJ_INT32* tmp, +static void opj_idwt53_h_cas0(OPJ_INT32 *tmp, const OPJ_INT32 sn, const OPJ_INT32 len, - OPJ_INT32* tiledp) -{ + OPJ_INT32 *tiledp) { OPJ_INT32 i, j; - const OPJ_INT32* in_even = &tiledp[0]; - const OPJ_INT32* in_odd = &tiledp[sn]; + const OPJ_INT32 *in_even = &tiledp[0]; + const OPJ_INT32 *in_odd = &tiledp[sn]; #ifdef TWO_PASS_VERSION /* For documentation purpose: performs lifting in two iterations, */ @@ -413,16 +406,16 @@ static void opj_idwt53_h_cas0(OPJ_INT32* tmp, } #else #if defined(__AVX512F__) - OPJ_INT32* out_ptr = tmp; + OPJ_INT32 *out_ptr = tmp; int32_t prev_even = in_even[0] - ((in_odd[0] + 1) >> 1); const __m512i permutevar_mask = _mm512_setr_epi32( 0x10, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e); const __m512i store1_perm = _mm512_setr_epi64(0x00, 0x01, 0x08, 0x09, 0x02, - 0x03, 0x0a, 0x0b); + 0x03, 0x0a, 0x0b); const __m512i store2_perm = _mm512_setr_epi64(0x04, 0x05, 0x0c, 0x0d, 0x06, - 0x07, 0x0e, 0x0f); + 0x07, 0x0e, 0x0f); const __m512i two = _mm512_set1_epi32(2); @@ -430,9 +423,9 @@ static void opj_idwt53_h_cas0(OPJ_INT32* tmp, int32_t leftover; for (i = 0; i < simd_batch_512; i++) { - const __m512i lf_avx2 = _mm512_loadu_si512((__m512i*)(in_even + 1)); - const __m512i hf1_avx2 = _mm512_loadu_si512((__m512i*)(in_odd)); - const __m512i hf2_avx2 = _mm512_loadu_si512((__m512i*)(in_odd + 1)); + const __m512i lf_avx2 = _mm512_loadu_si512((__m512i *)(in_even + 1)); + const __m512i hf1_avx2 = _mm512_loadu_si512((__m512i *)(in_odd)); + const __m512i hf2_avx2 = _mm512_loadu_si512((__m512i *)(in_odd + 1)); int32_t next_even; __m512i duplicate, even_m1, odd, unpack1, unpack2, store1, store2; @@ -489,11 +482,11 @@ static void opj_idwt53_h_cas0(OPJ_INT32* tmp, out_ptr[1] = in_odd[0] + out_ptr[0]; } #elif defined(__AVX2__) - OPJ_INT32* out_ptr = tmp; + OPJ_INT32 *out_ptr = tmp; int32_t prev_even = in_even[0] - ((in_odd[0] + 1) >> 1); const __m256i reg_permutevar_mask_move_right = _mm256_setr_epi32(0x00, 0x00, - 0x01, 0x02, 0x03, 0x04, 0x05, 0x06); + 0x01, 0x02, 0x03, 0x04, 0x05, 0x06); const __m256i two = _mm256_set1_epi32(2); int32_t simd_batch = (len - 2) / 16; @@ -501,9 +494,9 @@ static void opj_idwt53_h_cas0(OPJ_INT32* tmp, __m256i even_m1, odd, unpack1_avx2, unpack2_avx2; for (i = 0; i < simd_batch; i++) { - const __m256i lf_avx2 = _mm256_loadu_si256((__m256i*)(in_even + 1)); - const __m256i hf1_avx2 = _mm256_loadu_si256((__m256i*)(in_odd)); - const __m256i hf2_avx2 = _mm256_loadu_si256((__m256i*)(in_odd + 1)); + const __m256i lf_avx2 = _mm256_loadu_si256((__m256i *)(in_even + 1)); + const __m256i hf1_avx2 = _mm256_loadu_si256((__m256i *)(in_odd)); + const __m256i hf2_avx2 = _mm256_loadu_si256((__m256i *)(in_odd + 1)); __m256i even = _mm256_add_epi32(hf1_avx2, hf2_avx2); even = _mm256_add_epi32(even, two); @@ -522,11 +515,11 @@ static void opj_idwt53_h_cas0(OPJ_INT32* tmp, unpack1_avx2 = _mm256_unpacklo_epi32(even_m1, odd); unpack2_avx2 = _mm256_unpackhi_epi32(even_m1, odd); - _mm_storeu_si128((__m128i*)(out_ptr + 0), _mm256_castsi256_si128(unpack1_avx2)); - _mm_storeu_si128((__m128i*)(out_ptr + 4), _mm256_castsi256_si128(unpack2_avx2)); - _mm_storeu_si128((__m128i*)(out_ptr + 8), _mm256_extracti128_si256(unpack1_avx2, + _mm_storeu_si128((__m128i *)(out_ptr + 0), _mm256_castsi256_si128(unpack1_avx2)); + _mm_storeu_si128((__m128i *)(out_ptr + 4), _mm256_castsi256_si128(unpack2_avx2)); + _mm_storeu_si128((__m128i *)(out_ptr + 8), _mm256_extracti128_si256(unpack1_avx2, 0x1)); - _mm_storeu_si128((__m128i*)(out_ptr + 12), + _mm_storeu_si128((__m128i *)(out_ptr + 12), _mm256_extracti128_si256(unpack2_avx2, 0x1)); prev_even = next_even; @@ -589,14 +582,13 @@ static void opj_idwt53_h_cas0(OPJ_INT32* tmp, memcpy(tiledp, tmp, (OPJ_UINT32)len * sizeof(OPJ_INT32)); } -static void opj_idwt53_h_cas1(OPJ_INT32* tmp, +static void opj_idwt53_h_cas1(OPJ_INT32 *tmp, const OPJ_INT32 sn, const OPJ_INT32 len, - OPJ_INT32* tiledp) -{ + OPJ_INT32 *tiledp) { OPJ_INT32 i, j; - const OPJ_INT32* in_even = &tiledp[sn]; - const OPJ_INT32* in_odd = &tiledp[0]; + const OPJ_INT32 *in_even = &tiledp[sn]; + const OPJ_INT32 *in_odd = &tiledp[0]; #ifdef TWO_PASS_VERSION /* For documentation purpose: performs lifting in two iterations, */ @@ -666,8 +658,7 @@ static void opj_idwt53_h_cas1(OPJ_INT32* tmp, /* */ /* Performs interleave, inverse wavelet transform and copy back to buffer */ static void opj_idwt53_h(const opj_dwt_t *dwt, - OPJ_INT32* tiledp) -{ + OPJ_INT32 *tiledp) { #ifdef STANDARD_SLOW_VERSION /* For documentation purpose */ opj_dwt_interleave_h(dwt, tiledp); @@ -686,9 +677,9 @@ static void opj_idwt53_h(const opj_dwt_t *dwt, if (len == 1) { tiledp[0] /= 2; } else if (len == 2) { - OPJ_INT32* out = dwt->mem; - const OPJ_INT32* in_even = &tiledp[sn]; - const OPJ_INT32* in_odd = &tiledp[0]; + OPJ_INT32 *out = dwt->mem; + const OPJ_INT32 *in_even = &tiledp[sn]; + const OPJ_INT32 *in_odd = &tiledp[0]; out[1] = in_odd[0] - ((in_even[0] + 1) >> 1); out[0] = in_even[0] + out[1]; memcpy(tiledp, dwt->mem, (OPJ_UINT32)len * sizeof(OPJ_INT32)); @@ -736,11 +727,10 @@ static void opj_idwt53_h(const opj_dwt_t *dwt, #define ADD3(x,y,z) ADD(ADD(x,y),z) static -void opj_idwt53_v_final_memcpy(OPJ_INT32* tiledp_col, - const OPJ_INT32* tmp, +void opj_idwt53_v_final_memcpy(OPJ_INT32 *tiledp_col, + const OPJ_INT32 *tmp, OPJ_INT32 len, - OPJ_SIZE_T stride) -{ + OPJ_SIZE_T stride) { OPJ_INT32 i; for (i = 0; i < len; ++i) { /* A memcpy(&tiledp_col[i * stride + 0], @@ -758,14 +748,13 @@ void opj_idwt53_v_final_memcpy(OPJ_INT32* tiledp_col, /** Vertical inverse 5x3 wavelet transform for 8 columns in SSE2, or * 16 in AVX2, when top-most pixel is on even coordinate */ static void opj_idwt53_v_cas0_mcols_SSE2_OR_AVX2( - OPJ_INT32* tmp, + OPJ_INT32 *tmp, const OPJ_INT32 sn, const OPJ_INT32 len, - OPJ_INT32* tiledp_col, - const OPJ_SIZE_T stride) -{ - const OPJ_INT32* in_even = &tiledp_col[0]; - const OPJ_INT32* in_odd = &tiledp_col[(OPJ_SIZE_T)sn * stride]; + OPJ_INT32 *tiledp_col, + const OPJ_SIZE_T stride) { + const OPJ_INT32 *in_even = &tiledp_col[0]; + const OPJ_INT32 *in_odd = &tiledp_col[(OPJ_SIZE_T)sn * stride]; OPJ_INT32 i; OPJ_SIZE_T j; @@ -865,12 +854,11 @@ static void opj_idwt53_v_cas0_mcols_SSE2_OR_AVX2( /** Vertical inverse 5x3 wavelet transform for 8 columns in SSE2, or * 16 in AVX2, when top-most pixel is on odd coordinate */ static void opj_idwt53_v_cas1_mcols_SSE2_OR_AVX2( - OPJ_INT32* tmp, + OPJ_INT32 *tmp, const OPJ_INT32 sn, const OPJ_INT32 len, - OPJ_INT32* tiledp_col, - const OPJ_SIZE_T stride) -{ + OPJ_INT32 *tiledp_col, + const OPJ_SIZE_T stride) { OPJ_INT32 i; OPJ_SIZE_T j; @@ -878,8 +866,8 @@ static void opj_idwt53_v_cas1_mcols_SSE2_OR_AVX2( VREG s1_1, s2_1, dc_1, dn_1; const VREG two = LOAD_CST(2); - const OPJ_INT32* in_even = &tiledp_col[(OPJ_SIZE_T)sn * stride]; - const OPJ_INT32* in_odd = &tiledp_col[0]; + const OPJ_INT32 *in_even = &tiledp_col[(OPJ_SIZE_T)sn * stride]; + const OPJ_INT32 *in_odd = &tiledp_col[0]; assert(len > 2); #if defined(__AVX512F__) @@ -982,12 +970,11 @@ static void opj_idwt53_v_cas1_mcols_SSE2_OR_AVX2( #if !defined(STANDARD_SLOW_VERSION) /** Vertical inverse 5x3 wavelet transform for one column, when top-most * pixel is on even coordinate */ -static void opj_idwt3_v_cas0(OPJ_INT32* tmp, +static void opj_idwt3_v_cas0(OPJ_INT32 *tmp, const OPJ_INT32 sn, const OPJ_INT32 len, - OPJ_INT32* tiledp_col, - const OPJ_SIZE_T stride) -{ + OPJ_INT32 *tiledp_col, + const OPJ_SIZE_T stride) { OPJ_INT32 i, j; OPJ_INT32 d1c, d1n, s1n, s0c, s0n; @@ -1034,16 +1021,15 @@ static void opj_idwt3_v_cas0(OPJ_INT32* tmp, /** Vertical inverse 5x3 wavelet transform for one column, when top-most * pixel is on odd coordinate */ -static void opj_idwt3_v_cas1(OPJ_INT32* tmp, +static void opj_idwt3_v_cas1(OPJ_INT32 *tmp, const OPJ_INT32 sn, const OPJ_INT32 len, - OPJ_INT32* tiledp_col, - const OPJ_SIZE_T stride) -{ + OPJ_INT32 *tiledp_col, + const OPJ_SIZE_T stride) { OPJ_INT32 i, j; OPJ_INT32 s1, s2, dc, dn; - const OPJ_INT32* in_even = &tiledp_col[(OPJ_SIZE_T)sn * stride]; - const OPJ_INT32* in_odd = &tiledp_col[0]; + const OPJ_INT32 *in_even = &tiledp_col[(OPJ_SIZE_T)sn * stride]; + const OPJ_INT32 *in_odd = &tiledp_col[0]; assert(len > 2); @@ -1084,10 +1070,9 @@ static void opj_idwt3_v_cas1(OPJ_INT32* tmp, /* */ /* Performs interleave, inverse wavelet transform and copy back to buffer */ static void opj_idwt53_v(const opj_dwt_t *dwt, - OPJ_INT32* tiledp_col, + OPJ_INT32 *tiledp_col, OPJ_SIZE_T stride, - OPJ_INT32 nb_cols) -{ + OPJ_INT32 nb_cols) { #ifdef STANDARD_SLOW_VERSION /* For documentation purpose */ OPJ_INT32 k, c; @@ -1130,11 +1115,11 @@ static void opj_idwt53_v(const opj_dwt_t *dwt, if (len == 2) { OPJ_INT32 c; - OPJ_INT32* out = dwt->mem; + OPJ_INT32 *out = dwt->mem; for (c = 0; c < nb_cols; c++, tiledp_col++) { OPJ_INT32 i; - const OPJ_INT32* in_even = &tiledp_col[(OPJ_SIZE_T)sn * stride]; - const OPJ_INT32* in_odd = &tiledp_col[0]; + const OPJ_INT32 *in_even = &tiledp_col[(OPJ_SIZE_T)sn * stride]; + const OPJ_INT32 *in_odd = &tiledp_col[0]; out[1] = in_odd[0] - ((in_even[0] + 1) >> 1); out[0] = in_even[0] + out[1]; @@ -1167,10 +1152,9 @@ static void opj_idwt53_v(const opj_dwt_t *dwt, } #if 0 -static void opj_dwt_encode_step1(OPJ_FLOAT32* fw, +static void opj_dwt_encode_step1(OPJ_FLOAT32 *fw, OPJ_UINT32 end, - const OPJ_FLOAT32 c) -{ + const OPJ_FLOAT32 c) { OPJ_UINT32 i = 0; for (; i < end; ++i) { fw[0] *= c; @@ -1178,12 +1162,11 @@ static void opj_dwt_encode_step1(OPJ_FLOAT32* fw, } } #else -static void opj_dwt_encode_step1_combined(OPJ_FLOAT32* fw, - OPJ_UINT32 iters_c1, - OPJ_UINT32 iters_c2, - const OPJ_FLOAT32 c1, - const OPJ_FLOAT32 c2) -{ +static void opj_dwt_encode_step1_combined(OPJ_FLOAT32 *fw, + OPJ_UINT32 iters_c1, + OPJ_UINT32 iters_c2, + const OPJ_FLOAT32 c1, + const OPJ_FLOAT32 c2) { OPJ_UINT32 i = 0; const OPJ_UINT32 iters_common = opj_uint_min(iters_c1, iters_c2); assert((((OPJ_SIZE_T)fw) & 0xf) == 0); @@ -1191,8 +1174,8 @@ static void opj_dwt_encode_step1_combined(OPJ_FLOAT32* fw, for (; i + 3 < iters_common; i += 4) { #ifdef __SSE__ const __m128 vcst = _mm_set_ps(c2, c1, c2, c1); - *(__m128*)fw = _mm_mul_ps(*(__m128*)fw, vcst); - *(__m128*)(fw + 4) = _mm_mul_ps(*(__m128*)(fw + 4), vcst); + *(__m128 *)fw = _mm_mul_ps(*(__m128 *)fw, vcst); + *(__m128 *)(fw + 4) = _mm_mul_ps(*(__m128 *)(fw + 4), vcst); #else fw[0] *= c1; fw[1] *= c2; @@ -1219,11 +1202,10 @@ static void opj_dwt_encode_step1_combined(OPJ_FLOAT32* fw, #endif -static void opj_dwt_encode_step2(OPJ_FLOAT32* fl, OPJ_FLOAT32* fw, +static void opj_dwt_encode_step2(OPJ_FLOAT32 *fl, OPJ_FLOAT32 *fw, OPJ_UINT32 end, OPJ_UINT32 m, - OPJ_FLOAT32 c) -{ + OPJ_FLOAT32 c) { OPJ_UINT32 i; OPJ_UINT32 imax = opj_uint_min(end, m); if (imax > 0) { @@ -1249,9 +1231,8 @@ static void opj_dwt_encode_step2(OPJ_FLOAT32* fl, OPJ_FLOAT32* fw, } static void opj_dwt_encode_1_real(void *aIn, OPJ_INT32 dn, OPJ_INT32 sn, - OPJ_INT32 cas) -{ - OPJ_FLOAT32* w = (OPJ_FLOAT32*)aIn; + OPJ_INT32 cas) { + OPJ_FLOAT32 *w = (OPJ_FLOAT32 *)aIn; OPJ_INT32 a, b; assert(dn + sn > 1); if (cas == 0) { @@ -1300,8 +1281,7 @@ static void opj_dwt_encode_1_real(void *aIn, OPJ_INT32 dn, OPJ_INT32 sn, } static void opj_dwt_encode_stepsize(OPJ_INT32 stepsize, OPJ_INT32 numbps, - opj_stepsize_t *bandno_stepsize) -{ + opj_stepsize_t *bandno_stepsize) { OPJ_INT32 p, n; p = opj_int_floorlog2(stepsize) - 13; n = 11 - opj_int_floorlog2(stepsize); @@ -1317,13 +1297,12 @@ static void opj_dwt_encode_stepsize(OPJ_INT32 stepsize, OPJ_INT32 numbps, /** Process one line for the horizontal pass of the 5x3 forward transform */ static -void opj_dwt_encode_and_deinterleave_h_one_row(void* rowIn, - void* tmpIn, - OPJ_UINT32 width, - OPJ_BOOL even) -{ - OPJ_INT32* OPJ_RESTRICT row = (OPJ_INT32*)rowIn; - OPJ_INT32* OPJ_RESTRICT tmp = (OPJ_INT32*)tmpIn; +void opj_dwt_encode_and_deinterleave_h_one_row(void *rowIn, + void *tmpIn, + OPJ_UINT32 width, + OPJ_BOOL even) { + OPJ_INT32 *OPJ_RESTRICT row = (OPJ_INT32 *)rowIn; + OPJ_INT32 *OPJ_RESTRICT tmp = (OPJ_INT32 *)tmpIn; const OPJ_INT32 sn = (OPJ_INT32)((width + (even ? 1 : 0)) >> 1); const OPJ_INT32 dn = (OPJ_INT32)(width - (OPJ_UINT32)sn); @@ -1371,13 +1350,12 @@ void opj_dwt_encode_and_deinterleave_h_one_row(void* rowIn, /** Process one line for the horizontal pass of the 9x7 forward transform */ static -void opj_dwt_encode_and_deinterleave_h_one_row_real(void* rowIn, - void* tmpIn, - OPJ_UINT32 width, - OPJ_BOOL even) -{ - OPJ_FLOAT32* OPJ_RESTRICT row = (OPJ_FLOAT32*)rowIn; - OPJ_FLOAT32* OPJ_RESTRICT tmp = (OPJ_FLOAT32*)tmpIn; +void opj_dwt_encode_and_deinterleave_h_one_row_real(void *rowIn, + void *tmpIn, + OPJ_UINT32 width, + OPJ_BOOL even) { + OPJ_FLOAT32 *OPJ_RESTRICT row = (OPJ_FLOAT32 *)rowIn; + OPJ_FLOAT32 *OPJ_RESTRICT tmp = (OPJ_FLOAT32 *)tmpIn; const OPJ_INT32 sn = (OPJ_INT32)((width + (even ? 1 : 0)) >> 1); const OPJ_INT32 dn = (OPJ_INT32)(width - (OPJ_UINT32)sn); if (width == 1) { @@ -1394,21 +1372,20 @@ typedef struct { opj_dwt_t h; OPJ_UINT32 rw; /* Width of the resolution to process */ OPJ_UINT32 w; /* Width of tiledp */ - OPJ_INT32 * OPJ_RESTRICT tiledp; + OPJ_INT32 *OPJ_RESTRICT tiledp; OPJ_UINT32 min_j; OPJ_UINT32 max_j; opj_encode_and_deinterleave_h_one_row_fnptr_type p_function; } opj_dwt_encode_h_job_t; -static void opj_dwt_encode_h_func(void* user_data, opj_tls_t* tls) -{ +static void opj_dwt_encode_h_func(void *user_data, opj_tls_t *tls) { OPJ_UINT32 j; - opj_dwt_encode_h_job_t* job; + opj_dwt_encode_h_job_t *job; (void)tls; - job = (opj_dwt_encode_h_job_t*)user_data; + job = (opj_dwt_encode_h_job_t *)user_data; for (j = job->min_j; j < job->max_j; j++) { - OPJ_INT32* OPJ_RESTRICT aj = job->tiledp + j * job->w; + OPJ_INT32 *OPJ_RESTRICT aj = job->tiledp + j * job->w; (*job->p_function)(aj, job->h.mem, job->rw, job->h.cas == 0 ? OPJ_TRUE : OPJ_FALSE); } @@ -1421,19 +1398,18 @@ typedef struct { opj_dwt_t v; OPJ_UINT32 rh; OPJ_UINT32 w; - OPJ_INT32 * OPJ_RESTRICT tiledp; + OPJ_INT32 *OPJ_RESTRICT tiledp; OPJ_UINT32 min_j; OPJ_UINT32 max_j; opj_encode_and_deinterleave_v_fnptr_type p_encode_and_deinterleave_v; } opj_dwt_encode_v_job_t; -static void opj_dwt_encode_v_func(void* user_data, opj_tls_t* tls) -{ +static void opj_dwt_encode_v_func(void *user_data, opj_tls_t *tls) { OPJ_UINT32 j; - opj_dwt_encode_v_job_t* job; + opj_dwt_encode_v_job_t *job; (void)tls; - job = (opj_dwt_encode_v_job_t*)user_data; + job = (opj_dwt_encode_v_job_t *)user_data; for (j = job->min_j; j + NB_ELTS_V8 - 1 < job->max_j; j += NB_ELTS_V8) { (*job->p_encode_and_deinterleave_v)(job->tiledp + j, job->v.mem, @@ -1458,13 +1434,12 @@ static void opj_dwt_encode_v_func(void* user_data, opj_tls_t* tls) /** Fetch up to cols <= NB_ELTS_V8 for each line, and put them in tmpOut */ /* that has a NB_ELTS_V8 interleave factor. */ static void opj_dwt_fetch_cols_vertical_pass(const void *arrayIn, - void *tmpOut, - OPJ_UINT32 height, - OPJ_UINT32 stride_width, - OPJ_UINT32 cols) -{ - const OPJ_INT32* OPJ_RESTRICT array = (const OPJ_INT32 * OPJ_RESTRICT)arrayIn; - OPJ_INT32* OPJ_RESTRICT tmp = (OPJ_INT32 * OPJ_RESTRICT)tmpOut; + void *tmpOut, + OPJ_UINT32 height, + OPJ_UINT32 stride_width, + OPJ_UINT32 cols) { + const OPJ_INT32 *OPJ_RESTRICT array = (const OPJ_INT32 * OPJ_RESTRICT)arrayIn; + OPJ_INT32 *OPJ_RESTRICT tmp = (OPJ_INT32 * OPJ_RESTRICT)tmpOut; if (cols == NB_ELTS_V8) { OPJ_UINT32 k; for (k = 0; k < height; ++k) { @@ -1490,18 +1465,17 @@ static void opj_dwt_fetch_cols_vertical_pass(const void *arrayIn, /* and src contains NB_ELTS_V8 consecutive values for up to NB_ELTS_V8 */ /* columns. */ static INLINE void opj_dwt_deinterleave_v_cols( - const OPJ_INT32 * OPJ_RESTRICT src, - OPJ_INT32 * OPJ_RESTRICT dst, + const OPJ_INT32 *OPJ_RESTRICT src, + OPJ_INT32 *OPJ_RESTRICT dst, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_UINT32 stride_width, OPJ_INT32 cas, - OPJ_UINT32 cols) -{ + OPJ_UINT32 cols) { OPJ_INT32 k; OPJ_INT32 i = sn; - OPJ_INT32 * OPJ_RESTRICT l_dest = dst; - const OPJ_INT32 * OPJ_RESTRICT l_src = src + cas * NB_ELTS_V8; + OPJ_INT32 *OPJ_RESTRICT l_dest = dst; + const OPJ_INT32 *OPJ_RESTRICT l_src = src + cas * NB_ELTS_V8; OPJ_UINT32 c; for (k = 0; k < 2; k++) { @@ -1511,27 +1485,27 @@ static INLINE void opj_dwt_deinterleave_v_cols( } else { c = 0; switch (cols) { - case 7: - l_dest[c] = l_src[c]; - c++; /* fallthru */ - case 6: - l_dest[c] = l_src[c]; - c++; /* fallthru */ - case 5: - l_dest[c] = l_src[c]; - c++; /* fallthru */ - case 4: - l_dest[c] = l_src[c]; - c++; /* fallthru */ - case 3: - l_dest[c] = l_src[c]; - c++; /* fallthru */ - case 2: - l_dest[c] = l_src[c]; - c++; /* fallthru */ - default: - l_dest[c] = l_src[c]; - break; + case 7: + l_dest[c] = l_src[c]; + c++; /* fallthru */ + case 6: + l_dest[c] = l_src[c]; + c++; /* fallthru */ + case 5: + l_dest[c] = l_src[c]; + c++; /* fallthru */ + case 4: + l_dest[c] = l_src[c]; + c++; /* fallthru */ + case 3: + l_dest[c] = l_src[c]; + c++; /* fallthru */ + case 2: + l_dest[c] = l_src[c]; + c++; /* fallthru */ + default: + l_dest[c] = l_src[c]; + break; } } l_dest += stride_width; @@ -1553,10 +1527,9 @@ static void opj_dwt_encode_and_deinterleave_v( OPJ_UINT32 height, OPJ_BOOL even, OPJ_UINT32 stride_width, - OPJ_UINT32 cols) -{ - OPJ_INT32* OPJ_RESTRICT array = (OPJ_INT32 * OPJ_RESTRICT)arrayIn; - OPJ_INT32* OPJ_RESTRICT tmp = (OPJ_INT32 * OPJ_RESTRICT)tmpIn; + OPJ_UINT32 cols) { + OPJ_INT32 *OPJ_RESTRICT array = (OPJ_INT32 * OPJ_RESTRICT)arrayIn; + OPJ_INT32 *OPJ_RESTRICT tmp = (OPJ_INT32 * OPJ_RESTRICT)tmpIn; const OPJ_UINT32 sn = (height + (even ? 1 : 0)) >> 1; const OPJ_UINT32 dn = height - sn; @@ -1578,23 +1551,23 @@ static void opj_dwt_encode_and_deinterleave_v( OPJ_UINT32 i; i = 0; if (i + 1 < sn) { - __m128i xmm_Si_0 = *(const __m128i*)(tmp + 4 * 0); - __m128i xmm_Si_1 = *(const __m128i*)(tmp + 4 * 1); + __m128i xmm_Si_0 = *(const __m128i *)(tmp + 4 * 0); + __m128i xmm_Si_1 = *(const __m128i *)(tmp + 4 * 1); for (; i + 1 < sn; i++) { - __m128i xmm_Sip1_0 = *(const __m128i*)(tmp + - (i + 1) * 2 * NB_ELTS_V8 + 4 * 0); - __m128i xmm_Sip1_1 = *(const __m128i*)(tmp + - (i + 1) * 2 * NB_ELTS_V8 + 4 * 1); - __m128i xmm_Di_0 = *(const __m128i*)(tmp + - (1 + i * 2) * NB_ELTS_V8 + 4 * 0); - __m128i xmm_Di_1 = *(const __m128i*)(tmp + - (1 + i * 2) * NB_ELTS_V8 + 4 * 1); + __m128i xmm_Sip1_0 = *(const __m128i *)(tmp + + (i + 1) * 2 * NB_ELTS_V8 + 4 * 0); + __m128i xmm_Sip1_1 = *(const __m128i *)(tmp + + (i + 1) * 2 * NB_ELTS_V8 + 4 * 1); + __m128i xmm_Di_0 = *(const __m128i *)(tmp + + (1 + i * 2) * NB_ELTS_V8 + 4 * 0); + __m128i xmm_Di_1 = *(const __m128i *)(tmp + + (1 + i * 2) * NB_ELTS_V8 + 4 * 1); xmm_Di_0 = _mm_sub_epi32(xmm_Di_0, _mm_srai_epi32(_mm_add_epi32(xmm_Si_0, xmm_Sip1_0), 1)); xmm_Di_1 = _mm_sub_epi32(xmm_Di_1, _mm_srai_epi32(_mm_add_epi32(xmm_Si_1, xmm_Sip1_1), 1)); - *(__m128i*)(tmp + (1 + i * 2) * NB_ELTS_V8 + 4 * 0) = xmm_Di_0; - *(__m128i*)(tmp + (1 + i * 2) * NB_ELTS_V8 + 4 * 1) = xmm_Di_1; + *(__m128i *)(tmp + (1 + i * 2) * NB_ELTS_V8 + 4 * 0) = xmm_Di_0; + *(__m128i *)(tmp + (1 + i * 2) * NB_ELTS_V8 + 4 * 1) = xmm_Di_1; xmm_Si_0 = xmm_Sip1_0; xmm_Si_1 = xmm_Sip1_1; } @@ -1609,26 +1582,26 @@ static void opj_dwt_encode_and_deinterleave_v( } i = 1; if (i < dn) { - __m128i xmm_Dim1_0 = *(const __m128i*)(tmp + (1 + - (i - 1) * 2) * NB_ELTS_V8 + 4 * 0); - __m128i xmm_Dim1_1 = *(const __m128i*)(tmp + (1 + - (i - 1) * 2) * NB_ELTS_V8 + 4 * 1); + __m128i xmm_Dim1_0 = *(const __m128i *)(tmp + (1 + + (i - 1) * 2) * NB_ELTS_V8 + 4 * 0); + __m128i xmm_Dim1_1 = *(const __m128i *)(tmp + (1 + + (i - 1) * 2) * NB_ELTS_V8 + 4 * 1); const __m128i xmm_two = _mm_set1_epi32(2); for (; i < dn; i++) { - __m128i xmm_Di_0 = *(const __m128i*)(tmp + - (1 + i * 2) * NB_ELTS_V8 + 4 * 0); - __m128i xmm_Di_1 = *(const __m128i*)(tmp + - (1 + i * 2) * NB_ELTS_V8 + 4 * 1); - __m128i xmm_Si_0 = *(const __m128i*)(tmp + - (i * 2) * NB_ELTS_V8 + 4 * 0); - __m128i xmm_Si_1 = *(const __m128i*)(tmp + - (i * 2) * NB_ELTS_V8 + 4 * 1); + __m128i xmm_Di_0 = *(const __m128i *)(tmp + + (1 + i * 2) * NB_ELTS_V8 + 4 * 0); + __m128i xmm_Di_1 = *(const __m128i *)(tmp + + (1 + i * 2) * NB_ELTS_V8 + 4 * 1); + __m128i xmm_Si_0 = *(const __m128i *)(tmp + + (i * 2) * NB_ELTS_V8 + 4 * 0); + __m128i xmm_Si_1 = *(const __m128i *)(tmp + + (i * 2) * NB_ELTS_V8 + 4 * 1); xmm_Si_0 = _mm_add_epi32(xmm_Si_0, _mm_srai_epi32(_mm_add_epi32(_mm_add_epi32(xmm_Dim1_0, xmm_Di_0), xmm_two), 2)); xmm_Si_1 = _mm_add_epi32(xmm_Si_1, _mm_srai_epi32(_mm_add_epi32(_mm_add_epi32(xmm_Dim1_1, xmm_Di_1), xmm_two), 2)); - *(__m128i*)(tmp + (i * 2) * NB_ELTS_V8 + 4 * 0) = xmm_Si_0; - *(__m128i*)(tmp + (i * 2) * NB_ELTS_V8 + 4 * 1) = xmm_Si_1; + *(__m128i *)(tmp + (i * 2) * NB_ELTS_V8 + 4 * 0) = xmm_Si_0; + *(__m128i *)(tmp + (i * 2) * NB_ELTS_V8 + 4 * 1) = xmm_Si_1; xmm_Dim1_0 = xmm_Di_0; xmm_Dim1_1 = xmm_Di_1; } @@ -1646,25 +1619,25 @@ static void opj_dwt_encode_and_deinterleave_v( } i = 1; if (i < sn) { - __m128i xmm_Dim1_0 = *(const __m128i*)(tmp + (1 + - (i - 1) * 2) * NB_ELTS_V8 + 4 * 0); - __m128i xmm_Dim1_1 = *(const __m128i*)(tmp + (1 + - (i - 1) * 2) * NB_ELTS_V8 + 4 * 1); + __m128i xmm_Dim1_0 = *(const __m128i *)(tmp + (1 + + (i - 1) * 2) * NB_ELTS_V8 + 4 * 0); + __m128i xmm_Dim1_1 = *(const __m128i *)(tmp + (1 + + (i - 1) * 2) * NB_ELTS_V8 + 4 * 1); for (; i < sn; i++) { - __m128i xmm_Di_0 = *(const __m128i*)(tmp + - (1 + i * 2) * NB_ELTS_V8 + 4 * 0); - __m128i xmm_Di_1 = *(const __m128i*)(tmp + - (1 + i * 2) * NB_ELTS_V8 + 4 * 1); - __m128i xmm_Si_0 = *(const __m128i*)(tmp + - (i * 2) * NB_ELTS_V8 + 4 * 0); - __m128i xmm_Si_1 = *(const __m128i*)(tmp + - (i * 2) * NB_ELTS_V8 + 4 * 1); + __m128i xmm_Di_0 = *(const __m128i *)(tmp + + (1 + i * 2) * NB_ELTS_V8 + 4 * 0); + __m128i xmm_Di_1 = *(const __m128i *)(tmp + + (1 + i * 2) * NB_ELTS_V8 + 4 * 1); + __m128i xmm_Si_0 = *(const __m128i *)(tmp + + (i * 2) * NB_ELTS_V8 + 4 * 0); + __m128i xmm_Si_1 = *(const __m128i *)(tmp + + (i * 2) * NB_ELTS_V8 + 4 * 1); xmm_Si_0 = _mm_sub_epi32(xmm_Si_0, _mm_srai_epi32(_mm_add_epi32(xmm_Di_0, xmm_Dim1_0), 1)); xmm_Si_1 = _mm_sub_epi32(xmm_Si_1, _mm_srai_epi32(_mm_add_epi32(xmm_Di_1, xmm_Dim1_1), 1)); - *(__m128i*)(tmp + (i * 2) * NB_ELTS_V8 + 4 * 0) = xmm_Si_0; - *(__m128i*)(tmp + (i * 2) * NB_ELTS_V8 + 4 * 1) = xmm_Si_1; + *(__m128i *)(tmp + (i * 2) * NB_ELTS_V8 + 4 * 0) = xmm_Si_0; + *(__m128i *)(tmp + (i * 2) * NB_ELTS_V8 + 4 * 1) = xmm_Si_1; xmm_Dim1_0 = xmm_Di_0; xmm_Dim1_1 = xmm_Di_1; } @@ -1676,24 +1649,24 @@ static void opj_dwt_encode_and_deinterleave_v( } i = 0; if (i + 1 < dn) { - __m128i xmm_Si_0 = *((const __m128i*)(tmp + 4 * 0)); - __m128i xmm_Si_1 = *((const __m128i*)(tmp + 4 * 1)); + __m128i xmm_Si_0 = *((const __m128i *)(tmp + 4 * 0)); + __m128i xmm_Si_1 = *((const __m128i *)(tmp + 4 * 1)); const __m128i xmm_two = _mm_set1_epi32(2); for (; i + 1 < dn; i++) { - __m128i xmm_Sip1_0 = *(const __m128i*)(tmp + - (i + 1) * 2 * NB_ELTS_V8 + 4 * 0); - __m128i xmm_Sip1_1 = *(const __m128i*)(tmp + - (i + 1) * 2 * NB_ELTS_V8 + 4 * 1); - __m128i xmm_Di_0 = *(const __m128i*)(tmp + - (1 + i * 2) * NB_ELTS_V8 + 4 * 0); - __m128i xmm_Di_1 = *(const __m128i*)(tmp + - (1 + i * 2) * NB_ELTS_V8 + 4 * 1); + __m128i xmm_Sip1_0 = *(const __m128i *)(tmp + + (i + 1) * 2 * NB_ELTS_V8 + 4 * 0); + __m128i xmm_Sip1_1 = *(const __m128i *)(tmp + + (i + 1) * 2 * NB_ELTS_V8 + 4 * 1); + __m128i xmm_Di_0 = *(const __m128i *)(tmp + + (1 + i * 2) * NB_ELTS_V8 + 4 * 0); + __m128i xmm_Di_1 = *(const __m128i *)(tmp + + (1 + i * 2) * NB_ELTS_V8 + 4 * 1); xmm_Di_0 = _mm_add_epi32(xmm_Di_0, _mm_srai_epi32(_mm_add_epi32(_mm_add_epi32(xmm_Si_0, xmm_Sip1_0), xmm_two), 2)); xmm_Di_1 = _mm_add_epi32(xmm_Di_1, _mm_srai_epi32(_mm_add_epi32(_mm_add_epi32(xmm_Si_1, xmm_Sip1_1), xmm_two), 2)); - *(__m128i*)(tmp + (1 + i * 2) * NB_ELTS_V8 + 4 * 0) = xmm_Di_0; - *(__m128i*)(tmp + (1 + i * 2) * NB_ELTS_V8 + 4 * 1) = xmm_Di_1; + *(__m128i *)(tmp + (1 + i * 2) * NB_ELTS_V8 + 4 * 0) = xmm_Di_0; + *(__m128i *)(tmp + (1 + i * 2) * NB_ELTS_V8 + 4 * 1) = xmm_Di_1; xmm_Si_0 = xmm_Sip1_0; xmm_Si_1 = xmm_Sip1_1; } @@ -1777,13 +1750,12 @@ static void opj_dwt_encode_and_deinterleave_v( } } -static void opj_v8dwt_encode_step1(OPJ_FLOAT32* fw, +static void opj_v8dwt_encode_step1(OPJ_FLOAT32 *fw, OPJ_UINT32 end, - const OPJ_FLOAT32 cst) -{ + const OPJ_FLOAT32 cst) { OPJ_UINT32 i; #ifdef __SSE__ - __m128* vw = (__m128*) fw; + __m128 *vw = (__m128 *) fw; const __m128 vcst = _mm_set1_ps(cst); for (i = 0; i < end; ++i) { vw[0] = _mm_mul_ps(vw[0], vcst); @@ -1800,18 +1772,17 @@ static void opj_v8dwt_encode_step1(OPJ_FLOAT32* fw, #endif } -static void opj_v8dwt_encode_step2(OPJ_FLOAT32* fl, OPJ_FLOAT32* fw, +static void opj_v8dwt_encode_step2(OPJ_FLOAT32 *fl, OPJ_FLOAT32 *fw, OPJ_UINT32 end, OPJ_UINT32 m, - OPJ_FLOAT32 cst) -{ + OPJ_FLOAT32 cst) { OPJ_UINT32 i; OPJ_UINT32 imax = opj_uint_min(end, m); #ifdef __SSE__ - __m128* vw = (__m128*) fw; + __m128 *vw = (__m128 *) fw; __m128 vcst = _mm_set1_ps(cst); if (imax > 0) { - __m128* vl = (__m128*) fl; + __m128 *vl = (__m128 *) fl; vw[-2] = _mm_add_ps(vw[-2], _mm_mul_ps(_mm_add_ps(vl[0], vw[0]), vcst)); vw[-1] = _mm_add_ps(vw[-1], _mm_mul_ps(_mm_add_ps(vl[1], vw[1]), vcst)); vw += 2 * (NB_ELTS_V8 * sizeof(OPJ_FLOAT32) / sizeof(__m128)); @@ -1863,10 +1834,9 @@ static void opj_dwt_encode_and_deinterleave_v_real( OPJ_UINT32 height, OPJ_BOOL even, OPJ_UINT32 stride_width, - OPJ_UINT32 cols) -{ - OPJ_FLOAT32* OPJ_RESTRICT array = (OPJ_FLOAT32 * OPJ_RESTRICT)arrayIn; - OPJ_FLOAT32* OPJ_RESTRICT tmp = (OPJ_FLOAT32 * OPJ_RESTRICT)tmpIn; + OPJ_UINT32 cols) { + OPJ_FLOAT32 *OPJ_RESTRICT array = (OPJ_FLOAT32 * OPJ_RESTRICT)arrayIn; + OPJ_FLOAT32 *OPJ_RESTRICT tmp = (OPJ_FLOAT32 * OPJ_RESTRICT)tmpIn; const OPJ_INT32 sn = (OPJ_INT32)((height + (even ? 1 : 0)) >> 1); const OPJ_INT32 dn = (OPJ_INT32)(height - (OPJ_UINT32)sn); OPJ_INT32 a, b; @@ -1911,13 +1881,13 @@ static void opj_dwt_encode_and_deinterleave_v_real( if (cols == NB_ELTS_V8) { - opj_dwt_deinterleave_v_cols((OPJ_INT32*)tmp, - (OPJ_INT32*)array, + opj_dwt_deinterleave_v_cols((OPJ_INT32 *)tmp, + (OPJ_INT32 *)array, (OPJ_INT32)dn, (OPJ_INT32)sn, stride_width, even ? 0 : 1, NB_ELTS_V8); } else { - opj_dwt_deinterleave_v_cols((OPJ_INT32*)tmp, - (OPJ_INT32*)array, + opj_dwt_deinterleave_v_cols((OPJ_INT32 *)tmp, + (OPJ_INT32 *)array, (OPJ_INT32)dn, (OPJ_INT32)sn, stride_width, even ? 0 : 1, cols); } @@ -1927,12 +1897,11 @@ static void opj_dwt_encode_and_deinterleave_v_real( /* */ /* Forward 5-3 wavelet transform in 2-D. */ /* */ -static INLINE OPJ_BOOL opj_dwt_encode_procedure(opj_thread_pool_t* tp, - opj_tcd_tilecomp_t * tilec, - opj_encode_and_deinterleave_v_fnptr_type p_encode_and_deinterleave_v, - opj_encode_and_deinterleave_h_one_row_fnptr_type - p_encode_and_deinterleave_h_one_row) -{ +static INLINE OPJ_BOOL opj_dwt_encode_procedure(opj_thread_pool_t *tp, + opj_tcd_tilecomp_t *tilec, + opj_encode_and_deinterleave_v_fnptr_type p_encode_and_deinterleave_v, + opj_encode_and_deinterleave_h_one_row_fnptr_type + p_encode_and_deinterleave_h_one_row) { OPJ_INT32 i; OPJ_INT32 *bj = 00; OPJ_UINT32 w; @@ -1940,10 +1909,10 @@ static INLINE OPJ_BOOL opj_dwt_encode_procedure(opj_thread_pool_t* tp, OPJ_SIZE_T l_data_size; - opj_tcd_resolution_t * l_cur_res = 0; - opj_tcd_resolution_t * l_last_res = 0; + opj_tcd_resolution_t *l_cur_res = 0; + opj_tcd_resolution_t *l_last_res = 0; const int num_threads = opj_thread_pool_get_thread_count(tp); - OPJ_INT32 * OPJ_RESTRICT tiledp = tilec->data; + OPJ_INT32 *OPJ_RESTRICT tiledp = tilec->data; w = (OPJ_UINT32)(tilec->x1 - tilec->x0); l = (OPJ_INT32)tilec->numresolutions - 1; @@ -1958,7 +1927,7 @@ static INLINE OPJ_BOOL opj_dwt_encode_procedure(opj_thread_pool_t* tp, return OPJ_FALSE; } l_data_size *= NB_ELTS_V8 * sizeof(OPJ_INT32); - bj = (OPJ_INT32*)opj_aligned_32_malloc(l_data_size); + bj = (OPJ_INT32 *)opj_aligned_32_malloc(l_data_size); /* l_data_size is equal to 0 when numresolutions == 1 but bj is not used */ /* in that case, so do not error out */ if (l_data_size != 0 && ! bj) { @@ -2017,15 +1986,15 @@ static INLINE OPJ_BOOL opj_dwt_encode_procedure(opj_thread_pool_t* tp, step_j = ((rw / num_jobs) / NB_ELTS_V8) * NB_ELTS_V8; for (j = 0; j < num_jobs; j++) { - opj_dwt_encode_v_job_t* job; + opj_dwt_encode_v_job_t *job; - job = (opj_dwt_encode_v_job_t*) opj_malloc(sizeof(opj_dwt_encode_v_job_t)); + job = (opj_dwt_encode_v_job_t *) opj_malloc(sizeof(opj_dwt_encode_v_job_t)); if (!job) { opj_thread_pool_wait_completion(tp, 0); opj_aligned_free(bj); return OPJ_FALSE; } - job->v.mem = (OPJ_INT32*)opj_aligned_32_malloc(l_data_size); + job->v.mem = (OPJ_INT32 *)opj_aligned_32_malloc(l_data_size); if (!job->v.mem) { opj_thread_pool_wait_completion(tp, 0); opj_free(job); @@ -2052,7 +2021,7 @@ static INLINE OPJ_BOOL opj_dwt_encode_procedure(opj_thread_pool_t* tp, /* Perform horizontal pass */ if (num_threads <= 1 || rh <= 1) { for (j = 0; j < rh; j++) { - OPJ_INT32* OPJ_RESTRICT aj = tiledp + j * w; + OPJ_INT32 *OPJ_RESTRICT aj = tiledp + j * w; (*p_encode_and_deinterleave_h_one_row)(aj, bj, rw, cas_row == 0 ? OPJ_TRUE : OPJ_FALSE); } @@ -2066,15 +2035,15 @@ static INLINE OPJ_BOOL opj_dwt_encode_procedure(opj_thread_pool_t* tp, step_j = (rh / num_jobs); for (j = 0; j < num_jobs; j++) { - opj_dwt_encode_h_job_t* job; + opj_dwt_encode_h_job_t *job; - job = (opj_dwt_encode_h_job_t*) opj_malloc(sizeof(opj_dwt_encode_h_job_t)); + job = (opj_dwt_encode_h_job_t *) opj_malloc(sizeof(opj_dwt_encode_h_job_t)); if (!job) { opj_thread_pool_wait_completion(tp, 0); opj_aligned_free(bj); return OPJ_FALSE; } - job->h.mem = (OPJ_INT32*)opj_aligned_32_malloc(l_data_size); + job->h.mem = (OPJ_INT32 *)opj_aligned_32_malloc(l_data_size); if (!job->h.mem) { opj_thread_pool_wait_completion(tp, 0); opj_free(job); @@ -2110,8 +2079,7 @@ static INLINE OPJ_BOOL opj_dwt_encode_procedure(opj_thread_pool_t* tp, /* Forward 5-3 wavelet transform in 2-D. */ /* */ OPJ_BOOL opj_dwt_encode(opj_tcd_t *p_tcd, - opj_tcd_tilecomp_t * tilec) -{ + opj_tcd_tilecomp_t *tilec) { return opj_dwt_encode_procedure(p_tcd->thread_pool, tilec, opj_dwt_encode_and_deinterleave_v, opj_dwt_encode_and_deinterleave_h_one_row); @@ -2120,9 +2088,8 @@ OPJ_BOOL opj_dwt_encode(opj_tcd_t *p_tcd, /* */ /* Inverse 5-3 wavelet transform in 2-D. */ /* */ -OPJ_BOOL opj_dwt_decode(opj_tcd_t *p_tcd, opj_tcd_tilecomp_t* tilec, - OPJ_UINT32 numres) -{ +OPJ_BOOL opj_dwt_decode(opj_tcd_t *p_tcd, opj_tcd_tilecomp_t *tilec, + OPJ_UINT32 numres) { if (p_tcd->whole_tile_decoding) { return opj_dwt_decode_tile(p_tcd->thread_pool, tilec, numres); } else { @@ -2133,8 +2100,7 @@ OPJ_BOOL opj_dwt_decode(opj_tcd_t *p_tcd, opj_tcd_tilecomp_t* tilec, /* */ /* Get norm of 5-3 wavelet. */ /* */ -OPJ_FLOAT64 opj_dwt_getnorm(OPJ_UINT32 level, OPJ_UINT32 orient) -{ +OPJ_FLOAT64 opj_dwt_getnorm(OPJ_UINT32 level, OPJ_UINT32 orient) { /* FIXME ! This is just a band-aid to avoid a buffer overflow */ /* but the array should really be extended up to 33 resolution levels */ /* See https://github.com/uclouvain/openjpeg/issues/493 */ @@ -2150,8 +2116,7 @@ OPJ_FLOAT64 opj_dwt_getnorm(OPJ_UINT32 level, OPJ_UINT32 orient) /* Forward 9-7 wavelet transform in 2-D. */ /* */ OPJ_BOOL opj_dwt_encode_real(opj_tcd_t *p_tcd, - opj_tcd_tilecomp_t * tilec) -{ + opj_tcd_tilecomp_t *tilec) { return opj_dwt_encode_procedure(p_tcd->thread_pool, tilec, opj_dwt_encode_and_deinterleave_v_real, opj_dwt_encode_and_deinterleave_h_one_row_real); @@ -2160,8 +2125,7 @@ OPJ_BOOL opj_dwt_encode_real(opj_tcd_t *p_tcd, /* */ /* Get norm of 9-7 wavelet. */ /* */ -OPJ_FLOAT64 opj_dwt_getnorm_real(OPJ_UINT32 level, OPJ_UINT32 orient) -{ +OPJ_FLOAT64 opj_dwt_getnorm_real(OPJ_UINT32 level, OPJ_UINT32 orient) { /* FIXME ! This is just a band-aid to avoid a buffer overflow */ /* but the array should really be extended up to 33 resolution levels */ /* See https://github.com/uclouvain/openjpeg/issues/493 */ @@ -2173,8 +2137,7 @@ OPJ_FLOAT64 opj_dwt_getnorm_real(OPJ_UINT32 level, OPJ_UINT32 orient) return opj_dwt_norms_real[orient][level]; } -void opj_dwt_calc_explicit_stepsizes(opj_tccp_t * tccp, OPJ_UINT32 prec) -{ +void opj_dwt_calc_explicit_stepsizes(opj_tccp_t *tccp, OPJ_UINT32 prec) { OPJ_UINT32 numbands, bandno; numbands = 3 * tccp->numresolutions - 2; for (bandno = 0; bandno < numbands; bandno++) { @@ -2185,7 +2148,7 @@ void opj_dwt_calc_explicit_stepsizes(opj_tccp_t * tccp, OPJ_UINT32 prec) orient = (bandno == 0) ? 0 : ((bandno - 1) % 3 + 1); level = tccp->numresolutions - 1 - resno; gain = (tccp->qmfbid == 0) ? 0 : ((orient == 0) ? 0 : (((orient == 1) || - (orient == 2)) ? 1 : 2)); + (orient == 2)) ? 1 : 2)); if (tccp->qntsty == J2K_CCP_QNTSTY_NOQNT) { stepsize = 1.0; } else { @@ -2200,9 +2163,8 @@ void opj_dwt_calc_explicit_stepsizes(opj_tccp_t * tccp, OPJ_UINT32 prec) /* */ /* Determine maximum computed resolution level for inverse wavelet transform */ /* */ -static OPJ_UINT32 opj_dwt_max_resolution(opj_tcd_resolution_t* OPJ_RESTRICT r, - OPJ_UINT32 i) -{ +static OPJ_UINT32 opj_dwt_max_resolution(opj_tcd_resolution_t *OPJ_RESTRICT r, + OPJ_UINT32 i) { OPJ_UINT32 mr = 0; OPJ_UINT32 w; while (--i) { @@ -2221,18 +2183,17 @@ typedef struct { opj_dwt_t h; OPJ_UINT32 rw; OPJ_UINT32 w; - OPJ_INT32 * OPJ_RESTRICT tiledp; + OPJ_INT32 *OPJ_RESTRICT tiledp; OPJ_UINT32 min_j; OPJ_UINT32 max_j; } opj_dwt_decode_h_job_t; -static void opj_dwt_decode_h_func(void* user_data, opj_tls_t* tls) -{ +static void opj_dwt_decode_h_func(void *user_data, opj_tls_t *tls) { OPJ_UINT32 j; - opj_dwt_decode_h_job_t* job; + opj_dwt_decode_h_job_t *job; (void)tls; - job = (opj_dwt_decode_h_job_t*)user_data; + job = (opj_dwt_decode_h_job_t *)user_data; for (j = job->min_j; j < job->max_j; j++) { opj_idwt53_h(&job->h, &job->tiledp[j * job->w]); } @@ -2245,18 +2206,17 @@ typedef struct { opj_dwt_t v; OPJ_UINT32 rh; OPJ_UINT32 w; - OPJ_INT32 * OPJ_RESTRICT tiledp; + OPJ_INT32 *OPJ_RESTRICT tiledp; OPJ_UINT32 min_j; OPJ_UINT32 max_j; } opj_dwt_decode_v_job_t; -static void opj_dwt_decode_v_func(void* user_data, opj_tls_t* tls) -{ +static void opj_dwt_decode_v_func(void *user_data, opj_tls_t *tls) { OPJ_UINT32 j; - opj_dwt_decode_v_job_t* job; + opj_dwt_decode_v_job_t *job; (void)tls; - job = (opj_dwt_decode_v_job_t*)user_data; + job = (opj_dwt_decode_v_job_t *)user_data; for (j = job->min_j; j + PARALLEL_COLS_53 <= job->max_j; j += PARALLEL_COLS_53) { opj_idwt53_v(&job->v, &job->tiledp[j], (OPJ_SIZE_T)job->w, @@ -2274,13 +2234,12 @@ static void opj_dwt_decode_v_func(void* user_data, opj_tls_t* tls) /* */ /* Inverse wavelet transform in 2-D. */ /* */ -static OPJ_BOOL opj_dwt_decode_tile(opj_thread_pool_t* tp, - opj_tcd_tilecomp_t* tilec, OPJ_UINT32 numres) -{ +static OPJ_BOOL opj_dwt_decode_tile(opj_thread_pool_t *tp, + opj_tcd_tilecomp_t *tilec, OPJ_UINT32 numres) { opj_dwt_t h; opj_dwt_t v; - opj_tcd_resolution_t* tr = tilec->resolutions; + opj_tcd_resolution_t *tr = tilec->resolutions; OPJ_UINT32 rw = (OPJ_UINT32)(tr->x1 - tr->x0); /* width of the resolution level computed */ @@ -2288,7 +2247,7 @@ static OPJ_BOOL opj_dwt_decode_tile(opj_thread_pool_t* tp, tr->y0); /* height of the resolution level computed */ OPJ_UINT32 w = (OPJ_UINT32)(tilec->resolutions[tilec->minimum_num_resolutions - - 1].x1 - + 1].x1 - tilec->resolutions[tilec->minimum_num_resolutions - 1].x0); OPJ_SIZE_T h_mem_size; int num_threads; @@ -2309,7 +2268,7 @@ static OPJ_BOOL opj_dwt_decode_tile(opj_thread_pool_t* tp, /* since for the vertical pass */ /* we process PARALLEL_COLS_53 columns at a time */ h_mem_size *= PARALLEL_COLS_53 * sizeof(OPJ_INT32); - h.mem = (OPJ_INT32*)opj_aligned_32_malloc(h_mem_size); + h.mem = (OPJ_INT32 *)opj_aligned_32_malloc(h_mem_size); if (! h.mem) { /* FIXME event manager error callback */ return OPJ_FALSE; @@ -2318,7 +2277,7 @@ static OPJ_BOOL opj_dwt_decode_tile(opj_thread_pool_t* tp, v.mem = h.mem; while (--numres) { - OPJ_INT32 * OPJ_RESTRICT tiledp = tilec->data; + OPJ_INT32 *OPJ_RESTRICT tiledp = tilec->data; OPJ_UINT32 j; ++tr; @@ -2345,9 +2304,9 @@ static OPJ_BOOL opj_dwt_decode_tile(opj_thread_pool_t* tp, step_j = (rh / num_jobs); for (j = 0; j < num_jobs; j++) { - opj_dwt_decode_h_job_t* job; + opj_dwt_decode_h_job_t *job; - job = (opj_dwt_decode_h_job_t*) opj_malloc(sizeof(opj_dwt_decode_h_job_t)); + job = (opj_dwt_decode_h_job_t *) opj_malloc(sizeof(opj_dwt_decode_h_job_t)); if (!job) { /* It would be nice to fallback to single thread case, but */ /* unfortunately some jobs may be launched and have modified */ @@ -2366,7 +2325,7 @@ static OPJ_BOOL opj_dwt_decode_tile(opj_thread_pool_t* tp, if (j == (num_jobs - 1U)) { /* this will take care of the overflow */ job->max_j = rh; } - job->h.mem = (OPJ_INT32*)opj_aligned_32_malloc(h_mem_size); + job->h.mem = (OPJ_INT32 *)opj_aligned_32_malloc(h_mem_size); if (!job->h.mem) { /* FIXME event manager error callback */ opj_thread_pool_wait_completion(tp, 0); @@ -2400,9 +2359,9 @@ static OPJ_BOOL opj_dwt_decode_tile(opj_thread_pool_t* tp, step_j = (rw / num_jobs); for (j = 0; j < num_jobs; j++) { - opj_dwt_decode_v_job_t* job; + opj_dwt_decode_v_job_t *job; - job = (opj_dwt_decode_v_job_t*) opj_malloc(sizeof(opj_dwt_decode_v_job_t)); + job = (opj_dwt_decode_v_job_t *) opj_malloc(sizeof(opj_dwt_decode_v_job_t)); if (!job) { /* It would be nice to fallback to single thread case, but */ /* unfortunately some jobs may be launched and have modified */ @@ -2421,7 +2380,7 @@ static OPJ_BOOL opj_dwt_decode_tile(opj_thread_pool_t* tp, if (j == (num_jobs - 1U)) { /* this will take care of the overflow */ job->max_j = rw; } - job->v.mem = (OPJ_INT32*)opj_aligned_32_malloc(h_mem_size); + job->v.mem = (OPJ_INT32 *)opj_aligned_32_malloc(h_mem_size); if (!job->v.mem) { /* FIXME event manager error callback */ opj_thread_pool_wait_completion(tp, 0); @@ -2439,15 +2398,14 @@ static OPJ_BOOL opj_dwt_decode_tile(opj_thread_pool_t* tp, } static void opj_dwt_interleave_partial_h(OPJ_INT32 *dest, - OPJ_INT32 cas, - opj_sparse_array_int32_t* sa, - OPJ_UINT32 sa_line, - OPJ_UINT32 sn, - OPJ_UINT32 win_l_x0, - OPJ_UINT32 win_l_x1, - OPJ_UINT32 win_h_x0, - OPJ_UINT32 win_h_x1) -{ + OPJ_INT32 cas, + opj_sparse_array_int32_t *sa, + OPJ_UINT32 sa_line, + OPJ_UINT32 sn, + OPJ_UINT32 win_l_x0, + OPJ_UINT32 win_l_x1, + OPJ_UINT32 win_h_x0, + OPJ_UINT32 win_h_x1) { OPJ_BOOL ret; ret = opj_sparse_array_int32_read(sa, win_l_x0, sa_line, @@ -2466,16 +2424,15 @@ static void opj_dwt_interleave_partial_h(OPJ_INT32 *dest, static void opj_dwt_interleave_partial_v(OPJ_INT32 *dest, - OPJ_INT32 cas, - opj_sparse_array_int32_t* sa, - OPJ_UINT32 sa_col, - OPJ_UINT32 nb_cols, - OPJ_UINT32 sn, - OPJ_UINT32 win_l_y0, - OPJ_UINT32 win_l_y1, - OPJ_UINT32 win_h_y0, - OPJ_UINT32 win_h_y1) -{ + OPJ_INT32 cas, + opj_sparse_array_int32_t *sa, + OPJ_UINT32 sa_col, + OPJ_UINT32 nb_cols, + OPJ_UINT32 sn, + OPJ_UINT32 win_l_y0, + OPJ_UINT32 win_l_y1, + OPJ_UINT32 win_h_y0, + OPJ_UINT32 win_h_y1) { OPJ_BOOL ret; ret = opj_sparse_array_int32_read(sa, sa_col, win_l_y0, @@ -2497,8 +2454,7 @@ static void opj_dwt_decode_partial_1(OPJ_INT32 *a, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_INT32 win_l_x0, OPJ_INT32 win_l_x1, OPJ_INT32 win_h_x0, - OPJ_INT32 win_h_x1) -{ + OPJ_INT32 win_h_x1) { OPJ_INT32 i; if (!cas) { @@ -2560,7 +2516,7 @@ static void opj_dwt_decode_partial_1(OPJ_INT32 *a, OPJ_INT32 dn, OPJ_INT32 sn, for (i = win_l_x0; i < win_l_x1; i++) { OPJ_D(i) = opj_int_sub_no_overflow(OPJ_D(i), opj_int_add_no_overflow(opj_int_add_no_overflow(OPJ_SS_(i), OPJ_SS_(i + 1)), - 2) >> 2); + 2) >> 2); } for (i = win_h_x0; i < win_h_x1; i++) { OPJ_S(i) = opj_int_add_no_overflow(OPJ_S(i), @@ -2578,14 +2534,13 @@ static void opj_dwt_decode_partial_1(OPJ_INT32 *a, OPJ_INT32 dn, OPJ_INT32 sn, #define OPJ_DD__off(i,off) ((i)<0?OPJ_D_off(0,off):((i)>=sn?OPJ_D_off(sn-1,off):OPJ_D_off(i,off))) static void opj_dwt_decode_partial_1_parallel(OPJ_INT32 *a, - OPJ_UINT32 nb_cols, - OPJ_INT32 dn, OPJ_INT32 sn, - OPJ_INT32 cas, - OPJ_INT32 win_l_x0, - OPJ_INT32 win_l_x1, - OPJ_INT32 win_h_x0, - OPJ_INT32 win_h_x1) -{ + OPJ_UINT32 nb_cols, + OPJ_INT32 dn, OPJ_INT32 sn, + OPJ_INT32 cas, + OPJ_INT32 win_l_x0, + OPJ_INT32 win_l_x1, + OPJ_INT32 win_h_x0, + OPJ_INT32 win_h_x1) { OPJ_INT32 i; OPJ_UINT32 off; @@ -2634,8 +2589,8 @@ static void opj_dwt_decode_partial_1_parallel(OPJ_INT32 *a, _mm_srai_epi32(_mm_add_epi32(_mm_add_epi32(Dm1, D), two), 2)); S1 = _mm_sub_epi32(S1, _mm_srai_epi32(_mm_add_epi32(_mm_add_epi32(D, D1), two), 2)); - _mm_store_si128((__m128i*)(a + i * 8), S); - _mm_store_si128((__m128i*)(a + (i + 1) * 8), S1); + _mm_store_si128((__m128i *)(a + i * 8), S); + _mm_store_si128((__m128i *)(a + (i + 1) * 8), S1); Dm1 = D1; } } @@ -2673,8 +2628,8 @@ static void opj_dwt_decode_partial_1_parallel(OPJ_INT32 *a, __m128i S2 = _mm_load_si128((__m128i * const)(a + (i + 2) * 8)); D = _mm_add_epi32(D, _mm_srai_epi32(_mm_add_epi32(S, S1), 1)); D1 = _mm_add_epi32(D1, _mm_srai_epi32(_mm_add_epi32(S1, S2), 1)); - _mm_store_si128((__m128i*)(a + 4 + i * 8), D); - _mm_store_si128((__m128i*)(a + 4 + (i + 1) * 8), D1); + _mm_store_si128((__m128i *)(a + 4 + i * 8), D); + _mm_store_si128((__m128i *)(a + 4 + (i + 1) * 8), D1); S = S2; } } @@ -2719,18 +2674,17 @@ static void opj_dwt_decode_partial_1_parallel(OPJ_INT32 *a, } } -static void opj_dwt_get_band_coordinates(opj_tcd_tilecomp_t* tilec, - OPJ_UINT32 resno, - OPJ_UINT32 bandno, - OPJ_UINT32 tcx0, - OPJ_UINT32 tcy0, - OPJ_UINT32 tcx1, - OPJ_UINT32 tcy1, - OPJ_UINT32* tbx0, - OPJ_UINT32* tby0, - OPJ_UINT32* tbx1, - OPJ_UINT32* tby1) -{ +static void opj_dwt_get_band_coordinates(opj_tcd_tilecomp_t *tilec, + OPJ_UINT32 resno, + OPJ_UINT32 bandno, + OPJ_UINT32 tcx0, + OPJ_UINT32 tcy0, + OPJ_UINT32 tcx1, + OPJ_UINT32 tcy1, + OPJ_UINT32 *tbx0, + OPJ_UINT32 *tby0, + OPJ_UINT32 *tbx1, + OPJ_UINT32 *tby1) { /* Compute number of decomposition for this band. See table F-1 */ OPJ_UINT32 nb = (resno == 0) ? tilec->numresolutions - 1 : @@ -2763,39 +2717,37 @@ static void opj_dwt_get_band_coordinates(opj_tcd_tilecomp_t* tilec, static void opj_dwt_segment_grow(OPJ_UINT32 filter_width, OPJ_UINT32 max_size, - OPJ_UINT32* start, - OPJ_UINT32* end) -{ + OPJ_UINT32 *start, + OPJ_UINT32 *end) { *start = opj_uint_subs(*start, filter_width); *end = opj_uint_adds(*end, filter_width); *end = opj_uint_min(*end, max_size); } -static opj_sparse_array_int32_t* opj_dwt_init_sparse_array( - opj_tcd_tilecomp_t* tilec, - OPJ_UINT32 numres) -{ - opj_tcd_resolution_t* tr_max = &(tilec->resolutions[numres - 1]); +static opj_sparse_array_int32_t *opj_dwt_init_sparse_array( + opj_tcd_tilecomp_t *tilec, + OPJ_UINT32 numres) { + opj_tcd_resolution_t *tr_max = &(tilec->resolutions[numres - 1]); OPJ_UINT32 w = (OPJ_UINT32)(tr_max->x1 - tr_max->x0); OPJ_UINT32 h = (OPJ_UINT32)(tr_max->y1 - tr_max->y0); OPJ_UINT32 resno, bandno, precno, cblkno; - opj_sparse_array_int32_t* sa = opj_sparse_array_int32_create( + opj_sparse_array_int32_t *sa = opj_sparse_array_int32_create( w, h, opj_uint_min(w, 64), opj_uint_min(h, 64)); if (sa == NULL) { return NULL; } for (resno = 0; resno < numres; ++resno) { - opj_tcd_resolution_t* res = &tilec->resolutions[resno]; + opj_tcd_resolution_t *res = &tilec->resolutions[resno]; for (bandno = 0; bandno < res->numbands; ++bandno) { - opj_tcd_band_t* band = &res->bands[bandno]; + opj_tcd_band_t *band = &res->bands[bandno]; for (precno = 0; precno < res->pw * res->ph; ++precno) { - opj_tcd_precinct_t* precinct = &band->precincts[precno]; + opj_tcd_precinct_t *precinct = &band->precincts[precno]; for (cblkno = 0; cblkno < precinct->cw * precinct->ch; ++cblkno) { - opj_tcd_cblk_dec_t* cblk = &precinct->cblks.dec[cblkno]; + opj_tcd_cblk_dec_t *cblk = &precinct->cblks.dec[cblkno]; if (cblk->decoded_data != NULL) { OPJ_UINT32 x = (OPJ_UINT32)(cblk->x0 - band->x0); OPJ_UINT32 y = (OPJ_UINT32)(cblk->y0 - band->y0); @@ -2803,11 +2755,11 @@ static opj_sparse_array_int32_t* opj_dwt_init_sparse_array( OPJ_UINT32 cblk_h = (OPJ_UINT32)(cblk->y1 - cblk->y0); if (band->bandno & 1) { - opj_tcd_resolution_t* pres = &tilec->resolutions[resno - 1]; + opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; x += (OPJ_UINT32)(pres->x1 - pres->x0); } if (band->bandno & 2) { - opj_tcd_resolution_t* pres = &tilec->resolutions[resno - 1]; + opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; y += (OPJ_UINT32)(pres->y1 - pres->y0); } @@ -2829,10 +2781,9 @@ static opj_sparse_array_int32_t* opj_dwt_init_sparse_array( static OPJ_BOOL opj_dwt_decode_partial_tile( - opj_tcd_tilecomp_t* tilec, - OPJ_UINT32 numres) -{ - opj_sparse_array_int32_t* sa; + opj_tcd_tilecomp_t *tilec, + OPJ_UINT32 numres) { + opj_sparse_array_int32_t *sa; opj_dwt_t h; opj_dwt_t v; OPJ_UINT32 resno; @@ -2840,8 +2791,8 @@ static OPJ_BOOL opj_dwt_decode_partial_tile( /* F.2 and F.3 of the standard. */ const OPJ_UINT32 filter_width = 2U; - opj_tcd_resolution_t* tr = tilec->resolutions; - opj_tcd_resolution_t* tr_max = &(tilec->resolutions[numres - 1]); + opj_tcd_resolution_t *tr = tilec->resolutions; + opj_tcd_resolution_t *tr_max = &(tilec->resolutions[numres - 1]); OPJ_UINT32 rw = (OPJ_UINT32)(tr->x1 - tr->x0); /* width of the resolution level computed */ @@ -2868,13 +2819,13 @@ static OPJ_BOOL opj_dwt_decode_partial_tile( if (numres == 1U) { OPJ_BOOL ret = opj_sparse_array_int32_read(sa, - tr_max->win_x0 - (OPJ_UINT32)tr_max->x0, - tr_max->win_y0 - (OPJ_UINT32)tr_max->y0, - tr_max->win_x1 - (OPJ_UINT32)tr_max->x0, - tr_max->win_y1 - (OPJ_UINT32)tr_max->y0, - tilec->data_win, - 1, tr_max->win_x1 - tr_max->win_x0, - OPJ_TRUE); + tr_max->win_x0 - (OPJ_UINT32)tr_max->x0, + tr_max->win_y0 - (OPJ_UINT32)tr_max->y0, + tr_max->win_x1 - (OPJ_UINT32)tr_max->x0, + tr_max->win_y1 - (OPJ_UINT32)tr_max->y0, + tilec->data_win, + 1, tr_max->win_x1 - tr_max->win_x0, + OPJ_TRUE); assert(ret); OPJ_UNUSED(ret); opj_sparse_array_int32_free(sa); @@ -2890,7 +2841,7 @@ static OPJ_BOOL opj_dwt_decode_partial_tile( } h_mem_size *= 4 * sizeof(OPJ_INT32); - h.mem = (OPJ_INT32*)opj_aligned_32_malloc(h_mem_size); + h.mem = (OPJ_INT32 *)opj_aligned_32_malloc(h_mem_size); if (! h.mem) { /* FIXME event manager error callback */ opj_sparse_array_int32_free(sa); @@ -3060,13 +3011,13 @@ static OPJ_BOOL opj_dwt_decode_partial_tile( { OPJ_BOOL ret = opj_sparse_array_int32_read(sa, - tr_max->win_x0 - (OPJ_UINT32)tr_max->x0, - tr_max->win_y0 - (OPJ_UINT32)tr_max->y0, - tr_max->win_x1 - (OPJ_UINT32)tr_max->x0, - tr_max->win_y1 - (OPJ_UINT32)tr_max->y0, - tilec->data_win, - 1, tr_max->win_x1 - tr_max->win_x0, - OPJ_TRUE); + tr_max->win_x0 - (OPJ_UINT32)tr_max->x0, + tr_max->win_y0 - (OPJ_UINT32)tr_max->y0, + tr_max->win_x1 - (OPJ_UINT32)tr_max->x0, + tr_max->win_y1 - (OPJ_UINT32)tr_max->y0, + tilec->data_win, + 1, tr_max->win_x1 - tr_max->win_x0, + OPJ_TRUE); assert(ret); OPJ_UNUSED(ret); } @@ -3074,12 +3025,11 @@ static OPJ_BOOL opj_dwt_decode_partial_tile( return OPJ_TRUE; } -static void opj_v8dwt_interleave_h(opj_v8dwt_t* OPJ_RESTRICT dwt, - OPJ_FLOAT32* OPJ_RESTRICT a, +static void opj_v8dwt_interleave_h(opj_v8dwt_t *OPJ_RESTRICT dwt, + OPJ_FLOAT32 *OPJ_RESTRICT a, OPJ_UINT32 width, - OPJ_UINT32 remaining_height) -{ - OPJ_FLOAT32* OPJ_RESTRICT bi = (OPJ_FLOAT32*)(dwt->wavelet + dwt->cas); + OPJ_UINT32 remaining_height) { + OPJ_FLOAT32 *OPJ_RESTRICT bi = (OPJ_FLOAT32 *)(dwt->wavelet + dwt->cas); OPJ_UINT32 i, k; OPJ_UINT32 x0 = dwt->win_l_x0; OPJ_UINT32 x1 = dwt->win_l_x1; @@ -3090,7 +3040,7 @@ static void opj_v8dwt_interleave_h(opj_v8dwt_t* OPJ_RESTRICT dwt, /* Fast code path */ for (i = x0; i < x1; ++i) { OPJ_UINT32 j = i; - OPJ_FLOAT32* OPJ_RESTRICT dst = bi + i * 2 * NB_ELTS_V8; + OPJ_FLOAT32 *OPJ_RESTRICT dst = bi + i * 2 * NB_ELTS_V8; dst[0] = a[j]; j += width; dst[1] = a[j]; @@ -3111,7 +3061,7 @@ static void opj_v8dwt_interleave_h(opj_v8dwt_t* OPJ_RESTRICT dwt, /* Slow code path */ for (i = x0; i < x1; ++i) { OPJ_UINT32 j = i; - OPJ_FLOAT32* OPJ_RESTRICT dst = bi + i * 2 * NB_ELTS_V8; + OPJ_FLOAT32 *OPJ_RESTRICT dst = bi + i * 2 * NB_ELTS_V8; dst[0] = a[j]; j += width; if (remaining_height == 1) { @@ -3151,18 +3101,17 @@ static void opj_v8dwt_interleave_h(opj_v8dwt_t* OPJ_RESTRICT dwt, } } - bi = (OPJ_FLOAT32*)(dwt->wavelet + 1 - dwt->cas); + bi = (OPJ_FLOAT32 *)(dwt->wavelet + 1 - dwt->cas); a += dwt->sn; x0 = dwt->win_h_x0; x1 = dwt->win_h_x1; } } -static void opj_v8dwt_interleave_partial_h(opj_v8dwt_t* dwt, - opj_sparse_array_int32_t* sa, - OPJ_UINT32 sa_line, - OPJ_UINT32 remaining_height) -{ +static void opj_v8dwt_interleave_partial_h(opj_v8dwt_t *dwt, + opj_sparse_array_int32_t *sa, + OPJ_UINT32 sa_line, + OPJ_UINT32 remaining_height) { OPJ_UINT32 i; for (i = 0; i < remaining_height; i++) { OPJ_BOOL ret; @@ -3170,26 +3119,25 @@ static void opj_v8dwt_interleave_partial_h(opj_v8dwt_t* dwt, dwt->win_l_x0, sa_line + i, dwt->win_l_x1, sa_line + i + 1, /* Nasty cast from float* to int32* */ - (OPJ_INT32*)(dwt->wavelet + dwt->cas + 2 * dwt->win_l_x0) + i, + (OPJ_INT32 *)(dwt->wavelet + dwt->cas + 2 * dwt->win_l_x0) + i, 2 * NB_ELTS_V8, 0, OPJ_TRUE); assert(ret); ret = opj_sparse_array_int32_read(sa, (OPJ_UINT32)dwt->sn + dwt->win_h_x0, sa_line + i, (OPJ_UINT32)dwt->sn + dwt->win_h_x1, sa_line + i + 1, /* Nasty cast from float* to int32* */ - (OPJ_INT32*)(dwt->wavelet + 1 - dwt->cas + 2 * dwt->win_h_x0) + i, + (OPJ_INT32 *)(dwt->wavelet + 1 - dwt->cas + 2 * dwt->win_h_x0) + i, 2 * NB_ELTS_V8, 0, OPJ_TRUE); assert(ret); OPJ_UNUSED(ret); } } -static INLINE void opj_v8dwt_interleave_v(opj_v8dwt_t* OPJ_RESTRICT dwt, - OPJ_FLOAT32* OPJ_RESTRICT a, - OPJ_UINT32 width, - OPJ_UINT32 nb_elts_read) -{ - opj_v8_t* OPJ_RESTRICT bi = dwt->wavelet + dwt->cas; +static INLINE void opj_v8dwt_interleave_v(opj_v8dwt_t *OPJ_RESTRICT dwt, + OPJ_FLOAT32 *OPJ_RESTRICT a, + OPJ_UINT32 width, + OPJ_UINT32 nb_elts_read) { + opj_v8_t *OPJ_RESTRICT bi = dwt->wavelet + dwt->cas; OPJ_UINT32 i; for (i = dwt->win_l_x0; i < dwt->win_l_x1; ++i) { @@ -3206,22 +3154,21 @@ static INLINE void opj_v8dwt_interleave_v(opj_v8dwt_t* OPJ_RESTRICT dwt, } } -static void opj_v8dwt_interleave_partial_v(opj_v8dwt_t* OPJ_RESTRICT dwt, - opj_sparse_array_int32_t* sa, - OPJ_UINT32 sa_col, - OPJ_UINT32 nb_elts_read) -{ +static void opj_v8dwt_interleave_partial_v(opj_v8dwt_t *OPJ_RESTRICT dwt, + opj_sparse_array_int32_t *sa, + OPJ_UINT32 sa_col, + OPJ_UINT32 nb_elts_read) { OPJ_BOOL ret; ret = opj_sparse_array_int32_read(sa, sa_col, dwt->win_l_x0, sa_col + nb_elts_read, dwt->win_l_x1, - (OPJ_INT32*)(dwt->wavelet + dwt->cas + 2 * dwt->win_l_x0), + (OPJ_INT32 *)(dwt->wavelet + dwt->cas + 2 * dwt->win_l_x0), 1, 2 * NB_ELTS_V8, OPJ_TRUE); assert(ret); ret = opj_sparse_array_int32_read(sa, sa_col, (OPJ_UINT32)dwt->sn + dwt->win_h_x0, sa_col + nb_elts_read, (OPJ_UINT32)dwt->sn + dwt->win_h_x1, - (OPJ_INT32*)(dwt->wavelet + 1 - dwt->cas + 2 * dwt->win_h_x0), + (OPJ_INT32 *)(dwt->wavelet + 1 - dwt->cas + 2 * dwt->win_h_x0), 1, 2 * NB_ELTS_V8, OPJ_TRUE); assert(ret); OPJ_UNUSED(ret); @@ -3229,12 +3176,11 @@ static void opj_v8dwt_interleave_partial_v(opj_v8dwt_t* OPJ_RESTRICT dwt, #ifdef __SSE__ -static void opj_v8dwt_decode_step1_sse(opj_v8_t* w, +static void opj_v8dwt_decode_step1_sse(opj_v8_t *w, OPJ_UINT32 start, OPJ_UINT32 end, - const __m128 c) -{ - __m128* OPJ_RESTRICT vw = (__m128*) w; + const __m128 c) { + __m128 *OPJ_RESTRICT vw = (__m128 *) w; OPJ_UINT32 i = start; /* To be adapted if NB_ELTS_V8 changes */ vw += 4 * start; @@ -3245,14 +3191,13 @@ static void opj_v8dwt_decode_step1_sse(opj_v8_t* w, } } -static void opj_v8dwt_decode_step2_sse(opj_v8_t* l, opj_v8_t* w, +static void opj_v8dwt_decode_step2_sse(opj_v8_t *l, opj_v8_t *w, OPJ_UINT32 start, OPJ_UINT32 end, OPJ_UINT32 m, - __m128 c) -{ - __m128* OPJ_RESTRICT vl = (__m128*) l; - __m128* OPJ_RESTRICT vw = (__m128*) w; + __m128 c) { + __m128 *OPJ_RESTRICT vl = (__m128 *) l; + __m128 *OPJ_RESTRICT vw = (__m128 *) w; /* To be adapted if NB_ELTS_V8 changes */ OPJ_UINT32 i; OPJ_UINT32 imax = opj_uint_min(end, m); @@ -3284,12 +3229,11 @@ static void opj_v8dwt_decode_step2_sse(opj_v8_t* l, opj_v8_t* w, #else -static void opj_v8dwt_decode_step1(opj_v8_t* w, +static void opj_v8dwt_decode_step1(opj_v8_t *w, OPJ_UINT32 start, OPJ_UINT32 end, - const OPJ_FLOAT32 c) -{ - OPJ_FLOAT32* OPJ_RESTRICT fw = (OPJ_FLOAT32*) w; + const OPJ_FLOAT32 c) { + OPJ_FLOAT32 *OPJ_RESTRICT fw = (OPJ_FLOAT32 *) w; OPJ_UINT32 i; /* To be adapted if NB_ELTS_V8 changes */ for (i = start; i < end; ++i) { @@ -3304,14 +3248,13 @@ static void opj_v8dwt_decode_step1(opj_v8_t* w, } } -static void opj_v8dwt_decode_step2(opj_v8_t* l, opj_v8_t* w, +static void opj_v8dwt_decode_step2(opj_v8_t *l, opj_v8_t *w, OPJ_UINT32 start, OPJ_UINT32 end, OPJ_UINT32 m, - OPJ_FLOAT32 c) -{ - OPJ_FLOAT32* fl = (OPJ_FLOAT32*) l; - OPJ_FLOAT32* fw = (OPJ_FLOAT32*) w; + OPJ_FLOAT32 c) { + OPJ_FLOAT32 *fl = (OPJ_FLOAT32 *) l; + OPJ_FLOAT32 *fw = (OPJ_FLOAT32 *) w; OPJ_UINT32 i; OPJ_UINT32 imax = opj_uint_min(end, m); if (start > 0) { @@ -3350,8 +3293,7 @@ static void opj_v8dwt_decode_step2(opj_v8_t* l, opj_v8_t* w, /* */ /* Inverse 9-7 wavelet transform in 1-D. */ /* */ -static void opj_v8dwt_decode(opj_v8dwt_t* OPJ_RESTRICT dwt) -{ +static void opj_v8dwt_decode(opj_v8dwt_t *OPJ_RESTRICT dwt) { OPJ_INT32 a, b; /* BUG_WEIRD_TWO_INVK (look for this identifier in tcd.c) */ /* Historic value for 2 / opj_invK */ @@ -3423,19 +3365,18 @@ typedef struct { opj_v8dwt_t h; OPJ_UINT32 rw; OPJ_UINT32 w; - OPJ_FLOAT32 * OPJ_RESTRICT aj; + OPJ_FLOAT32 *OPJ_RESTRICT aj; OPJ_UINT32 nb_rows; } opj_dwt97_decode_h_job_t; -static void opj_dwt97_decode_h_func(void* user_data, opj_tls_t* tls) -{ +static void opj_dwt97_decode_h_func(void *user_data, opj_tls_t *tls) { OPJ_UINT32 j; - opj_dwt97_decode_h_job_t* job; - OPJ_FLOAT32 * OPJ_RESTRICT aj; + opj_dwt97_decode_h_job_t *job; + OPJ_FLOAT32 *OPJ_RESTRICT aj; OPJ_UINT32 w; (void)tls; - job = (opj_dwt97_decode_h_job_t*)user_data; + job = (opj_dwt97_decode_h_job_t *)user_data; w = job->w; assert((job->nb_rows % NB_ELTS_V8) == 0); @@ -3472,18 +3413,17 @@ typedef struct { opj_v8dwt_t v; OPJ_UINT32 rh; OPJ_UINT32 w; - OPJ_FLOAT32 * OPJ_RESTRICT aj; + OPJ_FLOAT32 *OPJ_RESTRICT aj; OPJ_UINT32 nb_columns; } opj_dwt97_decode_v_job_t; -static void opj_dwt97_decode_v_func(void* user_data, opj_tls_t* tls) -{ +static void opj_dwt97_decode_v_func(void *user_data, opj_tls_t *tls) { OPJ_UINT32 j; - opj_dwt97_decode_v_job_t* job; - OPJ_FLOAT32 * OPJ_RESTRICT aj; + opj_dwt97_decode_v_job_t *job; + OPJ_FLOAT32 *OPJ_RESTRICT aj; (void)tls; - job = (opj_dwt97_decode_v_job_t*)user_data; + job = (opj_dwt97_decode_v_job_t *)user_data; assert((job->nb_columns % NB_ELTS_V8) == 0); @@ -3510,14 +3450,13 @@ static void opj_dwt97_decode_v_func(void* user_data, opj_tls_t* tls) /* Inverse 9-7 wavelet transform in 2-D. */ /* */ static -OPJ_BOOL opj_dwt_decode_tile_97(opj_thread_pool_t* tp, - opj_tcd_tilecomp_t* OPJ_RESTRICT tilec, - OPJ_UINT32 numres) -{ +OPJ_BOOL opj_dwt_decode_tile_97(opj_thread_pool_t *tp, + opj_tcd_tilecomp_t *OPJ_RESTRICT tilec, + OPJ_UINT32 numres) { opj_v8dwt_t h; opj_v8dwt_t v; - opj_tcd_resolution_t* res = tilec->resolutions; + opj_tcd_resolution_t *res = tilec->resolutions; OPJ_UINT32 rw = (OPJ_UINT32)(res->x1 - res->x0); /* width of the resolution level computed */ @@ -3525,7 +3464,7 @@ OPJ_BOOL opj_dwt_decode_tile_97(opj_thread_pool_t* tp, res->y0); /* height of the resolution level computed */ OPJ_UINT32 w = (OPJ_UINT32)(tilec->resolutions[tilec->minimum_num_resolutions - - 1].x1 - + 1].x1 - tilec->resolutions[tilec->minimum_num_resolutions - 1].x0); OPJ_SIZE_T l_data_size; @@ -3541,7 +3480,7 @@ OPJ_BOOL opj_dwt_decode_tile_97(opj_thread_pool_t* tp, /* FIXME event manager error callback */ return OPJ_FALSE; } - h.wavelet = (opj_v8_t*) opj_aligned_malloc(l_data_size * sizeof(opj_v8_t)); + h.wavelet = (opj_v8_t *) opj_aligned_malloc(l_data_size * sizeof(opj_v8_t)); if (!h.wavelet) { /* FIXME event manager error callback */ return OPJ_FALSE; @@ -3549,7 +3488,7 @@ OPJ_BOOL opj_dwt_decode_tile_97(opj_thread_pool_t* tp, v.wavelet = h.wavelet; while (--numres) { - OPJ_FLOAT32 * OPJ_RESTRICT aj = (OPJ_FLOAT32*) tilec->data; + OPJ_FLOAT32 *OPJ_RESTRICT aj = (OPJ_FLOAT32 *) tilec->data; OPJ_UINT32 j; h.sn = (OPJ_INT32)rw; @@ -3601,15 +3540,15 @@ OPJ_BOOL opj_dwt_decode_tile_97(opj_thread_pool_t* tp, } step_j = ((rh / num_jobs) / NB_ELTS_V8) * NB_ELTS_V8; for (j = 0; j < num_jobs; j++) { - opj_dwt97_decode_h_job_t* job; + opj_dwt97_decode_h_job_t *job; - job = (opj_dwt97_decode_h_job_t*) opj_malloc(sizeof(opj_dwt97_decode_h_job_t)); + job = (opj_dwt97_decode_h_job_t *) opj_malloc(sizeof(opj_dwt97_decode_h_job_t)); if (!job) { opj_thread_pool_wait_completion(tp, 0); opj_aligned_free(h.wavelet); return OPJ_FALSE; } - job->h.wavelet = (opj_v8_t*)opj_aligned_malloc(l_data_size * sizeof(opj_v8_t)); + job->h.wavelet = (opj_v8_t *)opj_aligned_malloc(l_data_size * sizeof(opj_v8_t)); if (!job->h.wavelet) { opj_thread_pool_wait_completion(tp, 0); opj_free(job); @@ -3654,7 +3593,7 @@ OPJ_BOOL opj_dwt_decode_tile_97(opj_thread_pool_t* tp, v.win_h_x0 = 0; v.win_h_x1 = (OPJ_UINT32)v.dn; - aj = (OPJ_FLOAT32*) tilec->data; + aj = (OPJ_FLOAT32 *) tilec->data; if (num_threads <= 1 || rw < 2 * NB_ELTS_V8) { for (j = rw; j > (NB_ELTS_V8 - 1); j -= NB_ELTS_V8) { OPJ_UINT32 k; @@ -3680,15 +3619,15 @@ OPJ_BOOL opj_dwt_decode_tile_97(opj_thread_pool_t* tp, } step_j = ((rw / num_jobs) / NB_ELTS_V8) * NB_ELTS_V8; for (j = 0; j < num_jobs; j++) { - opj_dwt97_decode_v_job_t* job; + opj_dwt97_decode_v_job_t *job; - job = (opj_dwt97_decode_v_job_t*) opj_malloc(sizeof(opj_dwt97_decode_v_job_t)); + job = (opj_dwt97_decode_v_job_t *) opj_malloc(sizeof(opj_dwt97_decode_v_job_t)); if (!job) { opj_thread_pool_wait_completion(tp, 0); opj_aligned_free(h.wavelet); return OPJ_FALSE; } - job->v.wavelet = (opj_v8_t*)opj_aligned_malloc(l_data_size * sizeof(opj_v8_t)); + job->v.wavelet = (opj_v8_t *)opj_aligned_malloc(l_data_size * sizeof(opj_v8_t)); if (!job->v.wavelet) { opj_thread_pool_wait_completion(tp, 0); opj_free(job); @@ -3706,7 +3645,7 @@ OPJ_BOOL opj_dwt_decode_tile_97(opj_thread_pool_t* tp, job->w = w; job->aj = aj; job->nb_columns = (j + 1 == num_jobs) ? (rw & (OPJ_UINT32)~ - (NB_ELTS_V8 - 1)) - j * step_j : step_j; + (NB_ELTS_V8 - 1)) - j * step_j : step_j; aj += job->nb_columns; opj_thread_pool_submit_job(tp, opj_dwt97_decode_v_func, job); } @@ -3733,10 +3672,9 @@ OPJ_BOOL opj_dwt_decode_tile_97(opj_thread_pool_t* tp, } static -OPJ_BOOL opj_dwt_decode_partial_97(opj_tcd_tilecomp_t* OPJ_RESTRICT tilec, - OPJ_UINT32 numres) -{ - opj_sparse_array_int32_t* sa; +OPJ_BOOL opj_dwt_decode_partial_97(opj_tcd_tilecomp_t *OPJ_RESTRICT tilec, + OPJ_UINT32 numres) { + opj_sparse_array_int32_t *sa; opj_v8dwt_t h; opj_v8dwt_t v; OPJ_UINT32 resno; @@ -3745,8 +3683,8 @@ OPJ_BOOL opj_dwt_decode_partial_97(opj_tcd_tilecomp_t* OPJ_RESTRICT tilec, /* we currently use 3. */ const OPJ_UINT32 filter_width = 4U; - opj_tcd_resolution_t* tr = tilec->resolutions; - opj_tcd_resolution_t* tr_max = &(tilec->resolutions[numres - 1]); + opj_tcd_resolution_t *tr = tilec->resolutions; + opj_tcd_resolution_t *tr_max = &(tilec->resolutions[numres - 1]); OPJ_UINT32 rw = (OPJ_UINT32)(tr->x1 - tr->x0); /* width of the resolution level computed */ @@ -3773,13 +3711,13 @@ OPJ_BOOL opj_dwt_decode_partial_97(opj_tcd_tilecomp_t* OPJ_RESTRICT tilec, if (numres == 1U) { OPJ_BOOL ret = opj_sparse_array_int32_read(sa, - tr_max->win_x0 - (OPJ_UINT32)tr_max->x0, - tr_max->win_y0 - (OPJ_UINT32)tr_max->y0, - tr_max->win_x1 - (OPJ_UINT32)tr_max->x0, - tr_max->win_y1 - (OPJ_UINT32)tr_max->y0, - tilec->data_win, - 1, tr_max->win_x1 - tr_max->win_x0, - OPJ_TRUE); + tr_max->win_x0 - (OPJ_UINT32)tr_max->x0, + tr_max->win_y0 - (OPJ_UINT32)tr_max->y0, + tr_max->win_x1 - (OPJ_UINT32)tr_max->x0, + tr_max->win_y1 - (OPJ_UINT32)tr_max->y0, + tilec->data_win, + 1, tr_max->win_x1 - tr_max->win_x0, + OPJ_TRUE); assert(ret); OPJ_UNUSED(ret); opj_sparse_array_int32_free(sa); @@ -3793,7 +3731,7 @@ OPJ_BOOL opj_dwt_decode_partial_97(opj_tcd_tilecomp_t* OPJ_RESTRICT tilec, opj_sparse_array_int32_free(sa); return OPJ_FALSE; } - h.wavelet = (opj_v8_t*) opj_aligned_malloc(l_data_size * sizeof(opj_v8_t)); + h.wavelet = (opj_v8_t *) opj_aligned_malloc(l_data_size * sizeof(opj_v8_t)); if (!h.wavelet) { /* FIXME event manager error callback */ opj_sparse_array_int32_free(sa); @@ -3897,7 +3835,7 @@ OPJ_BOOL opj_dwt_decode_partial_97(opj_tcd_tilecomp_t* OPJ_RESTRICT tilec, if (!opj_sparse_array_int32_write(sa, win_tr_x0, j, win_tr_x1, j + NB_ELTS_V8, - (OPJ_INT32*)&h.wavelet[win_tr_x0].f[0], + (OPJ_INT32 *)&h.wavelet[win_tr_x0].f[0], NB_ELTS_V8, 1, OPJ_TRUE)) { /* FIXME event manager error callback */ opj_sparse_array_int32_free(sa); @@ -3916,7 +3854,7 @@ OPJ_BOOL opj_dwt_decode_partial_97(opj_tcd_tilecomp_t* OPJ_RESTRICT tilec, if (!opj_sparse_array_int32_write(sa, win_tr_x0, j, win_tr_x1, rh, - (OPJ_INT32*)&h.wavelet[win_tr_x0].f[0], + (OPJ_INT32 *)&h.wavelet[win_tr_x0].f[0], NB_ELTS_V8, 1, OPJ_TRUE)) { /* FIXME event manager error callback */ opj_sparse_array_int32_free(sa); @@ -3938,7 +3876,7 @@ OPJ_BOOL opj_dwt_decode_partial_97(opj_tcd_tilecomp_t* OPJ_RESTRICT tilec, if (!opj_sparse_array_int32_write(sa, j, win_tr_y0, j + nb_elts, win_tr_y1, - (OPJ_INT32*)&h.wavelet[win_tr_y0].f[0], + (OPJ_INT32 *)&h.wavelet[win_tr_y0].f[0], 1, NB_ELTS_V8, OPJ_TRUE)) { /* FIXME event manager error callback */ opj_sparse_array_int32_free(sa); @@ -3950,13 +3888,13 @@ OPJ_BOOL opj_dwt_decode_partial_97(opj_tcd_tilecomp_t* OPJ_RESTRICT tilec, { OPJ_BOOL ret = opj_sparse_array_int32_read(sa, - tr_max->win_x0 - (OPJ_UINT32)tr_max->x0, - tr_max->win_y0 - (OPJ_UINT32)tr_max->y0, - tr_max->win_x1 - (OPJ_UINT32)tr_max->x0, - tr_max->win_y1 - (OPJ_UINT32)tr_max->y0, - tilec->data_win, - 1, tr_max->win_x1 - tr_max->win_x0, - OPJ_TRUE); + tr_max->win_x0 - (OPJ_UINT32)tr_max->x0, + tr_max->win_y0 - (OPJ_UINT32)tr_max->y0, + tr_max->win_x1 - (OPJ_UINT32)tr_max->x0, + tr_max->win_y1 - (OPJ_UINT32)tr_max->y0, + tilec->data_win, + 1, tr_max->win_x1 - tr_max->win_x0, + OPJ_TRUE); assert(ret); OPJ_UNUSED(ret); } @@ -3968,9 +3906,8 @@ OPJ_BOOL opj_dwt_decode_partial_97(opj_tcd_tilecomp_t* OPJ_RESTRICT tilec, OPJ_BOOL opj_dwt_decode_real(opj_tcd_t *p_tcd, - opj_tcd_tilecomp_t* OPJ_RESTRICT tilec, - OPJ_UINT32 numres) -{ + opj_tcd_tilecomp_t *OPJ_RESTRICT tilec, + OPJ_UINT32 numres) { if (p_tcd->whole_tile_decoding) { return opj_dwt_decode_tile_97(p_tcd->thread_pool, tilec, numres); } else { diff --git a/client/deps/openjpeg/dwt.h b/client/deps/openjpeg/dwt.h index 215061e6b..aea78537c 100644 --- a/client/deps/openjpeg/dwt.h +++ b/client/deps/openjpeg/dwt.h @@ -60,7 +60,7 @@ Apply a reversible DWT transform to a component of an image. @param tilec Tile component information (current tile) */ OPJ_BOOL opj_dwt_encode(opj_tcd_t *p_tcd, - opj_tcd_tilecomp_t * tilec); + opj_tcd_tilecomp_t *tilec); /** Inverse 5-3 wavelet transform in 2-D. @@ -70,7 +70,7 @@ Apply a reversible inverse DWT transform to a component of an image. @param numres Number of resolution levels to decode */ OPJ_BOOL opj_dwt_decode(opj_tcd_t *p_tcd, - opj_tcd_tilecomp_t* tilec, + opj_tcd_tilecomp_t *tilec, OPJ_UINT32 numres); /** @@ -87,7 +87,7 @@ Apply an irreversible DWT transform to a component of an image. @param tilec Tile component information (current tile) */ OPJ_BOOL opj_dwt_encode_real(opj_tcd_t *p_tcd, - opj_tcd_tilecomp_t * tilec); + opj_tcd_tilecomp_t *tilec); /** Inverse 9-7 wavelet transform in 2-D. Apply an irreversible inverse DWT transform to a component of an image. @@ -96,7 +96,7 @@ Apply an irreversible inverse DWT transform to a component of an image. @param numres Number of resolution levels to decode */ OPJ_BOOL opj_dwt_decode_real(opj_tcd_t *p_tcd, - opj_tcd_tilecomp_t* OPJ_RESTRICT tilec, + opj_tcd_tilecomp_t *OPJ_RESTRICT tilec, OPJ_UINT32 numres); /** @@ -111,7 +111,7 @@ Explicit calculation of the Quantization Stepsizes @param tccp Tile-component coding parameters @param prec Precint analyzed */ -void opj_dwt_calc_explicit_stepsizes(opj_tccp_t * tccp, OPJ_UINT32 prec); +void opj_dwt_calc_explicit_stepsizes(opj_tccp_t *tccp, OPJ_UINT32 prec); /* ----------------------------------------------------------------------- */ /*@}*/ diff --git a/client/deps/openjpeg/event.c b/client/deps/openjpeg/event.c index aad9d76c9..99e4cf1ee 100644 --- a/client/deps/openjpeg/event.c +++ b/client/deps/openjpeg/event.c @@ -39,9 +39,8 @@ #ifdef OPJ_CODE_NOT_USED #ifndef _WIN32 -static char* -i2a(unsigned i, char *a, unsigned r) -{ +static char * +i2a(unsigned i, char *a, unsigned r) { if (i / r > 0) { a = i2a(i / r, a, r); } @@ -58,8 +57,7 @@ i2a(unsigned i, char *a, unsigned r) @return Returns a */ static char * -_itoa(int i, char *a, int r) -{ +_itoa(int i, char *a, int r) { r = ((r < 2) || (r > 36)) ? 10 : r; if (i < 0) { *a = '-'; @@ -78,8 +76,7 @@ _itoa(int i, char *a, int r) * Default callback function. * Do nothing. */ -static void opj_default_callback(const char *msg, void *client_data) -{ +static void opj_default_callback(const char *msg, void *client_data) { OPJ_ARG_NOT_USED(msg); OPJ_ARG_NOT_USED(client_data); } @@ -88,29 +85,28 @@ static void opj_default_callback(const char *msg, void *client_data) /* ----------------------------------------------------------------------- */ -OPJ_BOOL opj_event_msg(opj_event_mgr_t* p_event_mgr, OPJ_INT32 event_type, - const char *fmt, ...) -{ +OPJ_BOOL opj_event_msg(opj_event_mgr_t *p_event_mgr, OPJ_INT32 event_type, + const char *fmt, ...) { #define OPJ_MSG_SIZE 512 /* 512 bytes should be more than enough for a short message */ opj_msg_callback msg_handler = 00; - void * l_data = 00; + void *l_data = 00; if (p_event_mgr != 00) { switch (event_type) { - case EVT_ERROR: - msg_handler = p_event_mgr->error_handler; - l_data = p_event_mgr->m_error_data; - break; - case EVT_WARNING: - msg_handler = p_event_mgr->warning_handler; - l_data = p_event_mgr->m_warning_data; - break; - case EVT_INFO: - msg_handler = p_event_mgr->info_handler; - l_data = p_event_mgr->m_info_data; - break; - default: - break; + case EVT_ERROR: + msg_handler = p_event_mgr->error_handler; + l_data = p_event_mgr->m_error_data; + break; + case EVT_WARNING: + msg_handler = p_event_mgr->warning_handler; + l_data = p_event_mgr->m_warning_data; + break; + case EVT_INFO: + msg_handler = p_event_mgr->info_handler; + l_data = p_event_mgr->m_info_data; + break; + default: + break; } if (msg_handler == 00) { return OPJ_FALSE; @@ -139,8 +135,7 @@ OPJ_BOOL opj_event_msg(opj_event_mgr_t* p_event_mgr, OPJ_INT32 event_type, return OPJ_TRUE; } -void opj_set_default_event_handler(opj_event_mgr_t * p_manager) -{ +void opj_set_default_event_handler(opj_event_mgr_t *p_manager) { p_manager->m_error_data = 00; p_manager->m_warning_data = 00; p_manager->m_info_data = 00; diff --git a/client/deps/openjpeg/event.h b/client/deps/openjpeg/event.h index d880388d0..9220a9334 100644 --- a/client/deps/openjpeg/event.h +++ b/client/deps/openjpeg/event.h @@ -49,11 +49,11 @@ used for */ typedef struct opj_event_mgr { /** Data to call the event manager upon */ - void * m_error_data; + void *m_error_data; /** Data to call the event manager upon */ - void * m_warning_data; + void *m_warning_data; /** Data to call the event manager upon */ - void * m_info_data; + void *m_info_data; /** Error message callback if available, NULL otherwise */ opj_msg_callback error_handler; /** Warning message callback if available, NULL otherwise */ @@ -86,14 +86,14 @@ typedef struct opj_event_mgr { * * @return Returns true if successful, returns false otherwise */ -OPJ_BOOL opj_event_msg(opj_event_mgr_t* event_mgr, OPJ_INT32 event_type, +OPJ_BOOL opj_event_msg(opj_event_mgr_t *event_mgr, OPJ_INT32 event_type, const char *fmt, ...); /* ----------------------------------------------------------------------- */ /** * Set the event manager with the default callback function for the 3 levels. */ -void opj_set_default_event_handler(opj_event_mgr_t * p_manager); +void opj_set_default_event_handler(opj_event_mgr_t *p_manager); /* #ifdef __GNUC__ diff --git a/client/deps/openjpeg/function_list.c b/client/deps/openjpeg/function_list.c index e1c1af389..5f9e682d7 100644 --- a/client/deps/openjpeg/function_list.c +++ b/client/deps/openjpeg/function_list.c @@ -36,18 +36,17 @@ */ #define OPJ_VALIDATION_SIZE 10 -opj_procedure_list_t * opj_procedure_list_create() -{ +opj_procedure_list_t *opj_procedure_list_create() { /* memory allocation */ - opj_procedure_list_t * l_validation = (opj_procedure_list_t *) opj_calloc(1, - sizeof(opj_procedure_list_t)); + opj_procedure_list_t *l_validation = (opj_procedure_list_t *) opj_calloc(1, + sizeof(opj_procedure_list_t)); if (! l_validation) { return 00; } /* initialization */ l_validation->m_nb_max_procedures = OPJ_VALIDATION_SIZE; - l_validation->m_procedures = (opj_procedure*)opj_calloc(OPJ_VALIDATION_SIZE, - sizeof(opj_procedure)); + l_validation->m_procedures = (opj_procedure *)opj_calloc(OPJ_VALIDATION_SIZE, + sizeof(opj_procedure)); if (! l_validation->m_procedures) { opj_free(l_validation); return 00; @@ -55,8 +54,7 @@ opj_procedure_list_t * opj_procedure_list_create() return l_validation; } -void opj_procedure_list_destroy(opj_procedure_list_t * p_list) -{ +void opj_procedure_list_destroy(opj_procedure_list_t *p_list) { if (! p_list) { return; } @@ -68,17 +66,16 @@ void opj_procedure_list_destroy(opj_procedure_list_t * p_list) } OPJ_BOOL opj_procedure_list_add_procedure(opj_procedure_list_t * - p_validation_list, opj_procedure p_procedure, opj_event_mgr_t* p_manager) -{ + p_validation_list, opj_procedure p_procedure, opj_event_mgr_t *p_manager) { assert(p_manager != NULL); if (p_validation_list->m_nb_max_procedures == p_validation_list->m_nb_procedures) { - opj_procedure * new_procedures; + opj_procedure *new_procedures; p_validation_list->m_nb_max_procedures += OPJ_VALIDATION_SIZE; - new_procedures = (opj_procedure*)opj_realloc( + new_procedures = (opj_procedure *)opj_realloc( p_validation_list->m_procedures, p_validation_list->m_nb_max_procedures * sizeof(opj_procedure)); if (! new_procedures) { @@ -100,18 +97,15 @@ OPJ_BOOL opj_procedure_list_add_procedure(opj_procedure_list_t * } OPJ_UINT32 opj_procedure_list_get_nb_procedures(opj_procedure_list_t * - p_validation_list) -{ + p_validation_list) { return p_validation_list->m_nb_procedures; } -opj_procedure* opj_procedure_list_get_first_procedure(opj_procedure_list_t * - p_validation_list) -{ +opj_procedure *opj_procedure_list_get_first_procedure(opj_procedure_list_t * + p_validation_list) { return p_validation_list->m_procedures; } -void opj_procedure_list_clear(opj_procedure_list_t * p_validation_list) -{ +void opj_procedure_list_clear(opj_procedure_list_t *p_validation_list) { p_validation_list->m_nb_procedures = 0; } diff --git a/client/deps/openjpeg/function_list.h b/client/deps/openjpeg/function_list.h index 81a3954a1..009471302 100644 --- a/client/deps/openjpeg/function_list.h +++ b/client/deps/openjpeg/function_list.h @@ -66,7 +66,7 @@ typedef struct opj_procedure_list { /** * The array of procedures. */ - opj_procedure * m_procedures; + opj_procedure *m_procedures; } opj_procedure_list_t; @@ -77,14 +77,14 @@ typedef struct opj_procedure_list { * * @return the newly created validation list. */ -opj_procedure_list_t * opj_procedure_list_create(void); +opj_procedure_list_t *opj_procedure_list_create(void); /** * Destroys a validation list. * * @param p_list the list to destroy. */ -void opj_procedure_list_destroy(opj_procedure_list_t * p_list); +void opj_procedure_list_destroy(opj_procedure_list_t *p_list); /** * Adds a new validation procedure. @@ -96,7 +96,7 @@ void opj_procedure_list_destroy(opj_procedure_list_t * p_list); * @return OPJ_TRUE if the procedure could be added. */ OPJ_BOOL opj_procedure_list_add_procedure(opj_procedure_list_t * - p_validation_list, opj_procedure p_procedure, opj_event_mgr_t* p_manager); + p_validation_list, opj_procedure p_procedure, opj_event_mgr_t *p_manager); /** * Gets the number of validation procedures. @@ -106,7 +106,7 @@ OPJ_BOOL opj_procedure_list_add_procedure(opj_procedure_list_t * * @return the number of validation procedures. */ OPJ_UINT32 opj_procedure_list_get_nb_procedures(opj_procedure_list_t * - p_validation_list); + p_validation_list); /** * Gets the pointer on the first validation procedure. This function is similar to the C++ @@ -117,8 +117,8 @@ OPJ_UINT32 opj_procedure_list_get_nb_procedures(opj_procedure_list_t * * * @return a pointer to the first procedure. */ -opj_procedure* opj_procedure_list_get_first_procedure(opj_procedure_list_t * - p_validation_list); +opj_procedure *opj_procedure_list_get_first_procedure(opj_procedure_list_t * + p_validation_list); /** @@ -127,7 +127,7 @@ opj_procedure* opj_procedure_list_get_first_procedure(opj_procedure_list_t * * @param p_validation_list the list of procedure to clear. * */ -void opj_procedure_list_clear(opj_procedure_list_t * p_validation_list); +void opj_procedure_list_clear(opj_procedure_list_t *p_validation_list); /*@}*/ #endif /* OPJ_FUNCTION_LIST_H */ diff --git a/client/deps/openjpeg/ht_dec.c b/client/deps/openjpeg/ht_dec.c index 2984f5609..ce65f473f 100644 --- a/client/deps/openjpeg/ht_dec.c +++ b/client/deps/openjpeg/ht_dec.c @@ -77,8 +77,7 @@ static OPJ_BOOL only_cleanup_pass_is_decoded = OPJ_FALSE; * @param [in] val is the value for which population count is sought */ static INLINE -OPJ_UINT32 population_count(OPJ_UINT32 val) -{ +OPJ_UINT32 population_count(OPJ_UINT32 val) { #if defined(OPJ_COMPILER_MSVC) && (defined(_M_IX86) || defined(_M_AMD64)) return (OPJ_UINT32)__popcnt(val); #elif defined(OPJ_COMPILER_MSVC) && defined(MSVC_NEON_INTRINSICS) @@ -105,8 +104,7 @@ OPJ_UINT32 population_count(OPJ_UINT32 val) #pragma intrinsic(_BitScanReverse) #endif static INLINE -OPJ_UINT32 count_leading_zeros(OPJ_UINT32 val) -{ +OPJ_UINT32 count_leading_zeros(OPJ_UINT32 val) { #ifdef OPJ_COMPILER_MSVC unsigned long result = 0; _BitScanReverse(&result, val); @@ -128,16 +126,15 @@ OPJ_UINT32 count_leading_zeros(OPJ_UINT32 val) * * @param [in] dataIn pointer to byte stream to read from */ -static INLINE OPJ_UINT32 read_le_uint32(const void* dataIn) -{ +static INLINE OPJ_UINT32 read_le_uint32(const void *dataIn) { #if defined(OPJ_BIG_ENDIAN) - const OPJ_UINT8* data = (const OPJ_UINT8*)dataIn; + const OPJ_UINT8 *data = (const OPJ_UINT8 *)dataIn; return ((OPJ_UINT32)data[0]) | (OPJ_UINT32)(data[1] << 8) | (OPJ_UINT32)( data[2] << 16) | ((( OPJ_UINT32)data[3]) << 24U); #else - return *(OPJ_UINT32*)dataIn; + return *(OPJ_UINT32 *)dataIn; #endif } @@ -150,7 +147,7 @@ static INLINE OPJ_UINT32 read_le_uint32(const void* dataIn) */ typedef struct dec_mel { // data decoding machinery - OPJ_UINT8* data; //!num_runs == 0) { //if no runs, decode more bit from MEL segment mel_decode(melp); @@ -376,7 +369,7 @@ int mel_get_run(dec_mel_t *melp) */ typedef struct rev_struct { //storage - OPJ_UINT8* data; //!bits < 32) { // if there are less then 32 bits, read more rev_read(vlcp); // read 32 bits, but unstuffing might reduce this if (vlcp->bits < 32) { // if there is still space in vlcp->tmp for 32 bits @@ -536,8 +526,7 @@ OPJ_UINT32 rev_fetch(rev_struct_t *vlcp) * @param [in] num_bits is the number of bits to be removed */ static INLINE -OPJ_UINT32 rev_advance(rev_struct_t *vlcp, OPJ_UINT32 num_bits) -{ +OPJ_UINT32 rev_advance(rev_struct_t *vlcp, OPJ_UINT32 num_bits) { assert(num_bits <= vlcp->bits); // vlcp->tmp must have more than num_bits vlcp->tmp >>= num_bits; // remove bits vlcp->bits -= num_bits; // decrement the number of bits @@ -556,8 +545,7 @@ OPJ_UINT32 rev_advance(rev_struct_t *vlcp, OPJ_UINT32 num_bits) * @param [in] mrp is a pointer to rev_struct structure */ static INLINE -void rev_read_mrp(rev_struct_t *mrp) -{ +void rev_read_mrp(rev_struct_t *mrp) { OPJ_UINT32 val; OPJ_UINT32 tmp; OPJ_UINT32 bits; @@ -625,8 +613,7 @@ void rev_read_mrp(rev_struct_t *mrp) * @param [in] len2 is the length of SPP+MRP segments */ static INLINE -void rev_init_mrp(rev_struct_t *mrp, OPJ_UINT8* data, int lcup, int len2) -{ +void rev_init_mrp(rev_struct_t *mrp, OPJ_UINT8 *data, int lcup, int len2) { int num, i; mrp->data = data + lcup + len2 - 1; @@ -663,8 +650,7 @@ void rev_init_mrp(rev_struct_t *mrp, OPJ_UINT8* data, int lcup, int len2) * @param [in] mrp is a pointer to rev_struct structure */ static INLINE -OPJ_UINT32 rev_fetch_mrp(rev_struct_t *mrp) -{ +OPJ_UINT32 rev_fetch_mrp(rev_struct_t *mrp) { if (mrp->bits < 32) { // if there are less than 32 bits in mrp->tmp rev_read_mrp(mrp); // read 30-32 bits from mrp if (mrp->bits < 32) { // if there is a space of 32 bits @@ -681,8 +667,7 @@ OPJ_UINT32 rev_fetch_mrp(rev_struct_t *mrp) * @param [in] num_bits is the number of bits to be removed */ static INLINE -OPJ_UINT32 rev_advance_mrp(rev_struct_t *mrp, OPJ_UINT32 num_bits) -{ +OPJ_UINT32 rev_advance_mrp(rev_struct_t *mrp, OPJ_UINT32 num_bits) { assert(num_bits <= mrp->bits); // we must not consume more than mrp->bits mrp->tmp >>= num_bits; // discard the lowest num_bits bits mrp->bits -= num_bits; @@ -701,8 +686,7 @@ OPJ_UINT32 rev_advance_mrp(rev_struct_t *mrp, OPJ_UINT32 num_bits) * this value is a partial calculation of u + kappa. */ static INLINE -OPJ_UINT32 decode_init_uvlc(OPJ_UINT32 vlc, OPJ_UINT32 mode, OPJ_UINT32 *u) -{ +OPJ_UINT32 decode_init_uvlc(OPJ_UINT32 vlc, OPJ_UINT32 mode, OPJ_UINT32 *u) { //table stores possible decoding three bits from vlc // there are 8 entries for xx1, x10, 100, 000, where x means do not care // table value is made up of @@ -814,8 +798,7 @@ OPJ_UINT32 decode_init_uvlc(OPJ_UINT32 vlc, OPJ_UINT32 mode, OPJ_UINT32 *u) * this value is a partial calculation of u + kappa. */ static INLINE -OPJ_UINT32 decode_noninit_uvlc(OPJ_UINT32 vlc, OPJ_UINT32 mode, OPJ_UINT32 *u) -{ +OPJ_UINT32 decode_noninit_uvlc(OPJ_UINT32 vlc, OPJ_UINT32 mode, OPJ_UINT32 *u) { //table stores possible decoding three bits from vlc // there are 8 entries for xx1, x10, 100, 000, where x means do not care // table value is made up of @@ -884,7 +867,7 @@ OPJ_UINT32 decode_noninit_uvlc(OPJ_UINT32 vlc, OPJ_UINT32 mode, OPJ_UINT32 *u) * bitstreams; these are: MagSgn and SPP bitstreams */ typedef struct frwd_struct { - const OPJ_UINT8* data; //!data = data; @@ -1005,8 +986,7 @@ void frwd_init(frwd_struct_t *msp, const OPJ_UINT8* data, int size, * @param [in] num_bits is the number of bit to consume */ static INLINE -void frwd_advance(frwd_struct_t *msp, OPJ_UINT32 num_bits) -{ +void frwd_advance(frwd_struct_t *msp, OPJ_UINT32 num_bits) { assert(num_bits <= msp->bits); msp->tmp >>= num_bits; // consume num_bits msp->bits -= num_bits; @@ -1018,8 +998,7 @@ void frwd_advance(frwd_struct_t *msp, OPJ_UINT32 num_bits) * @param [in] msp is a pointer to frwd_struct_t */ static INLINE -OPJ_UINT32 frwd_fetch(frwd_struct_t *msp) -{ +OPJ_UINT32 frwd_fetch(frwd_struct_t *msp) { if (msp->bits < 32) { frwd_read(msp); if (msp->bits < 32) { //need to test @@ -1039,8 +1018,7 @@ OPJ_UINT32 frwd_fetch(frwd_struct_t *msp) static OPJ_BOOL opj_t1_allocate_buffers( opj_t1_t *t1, OPJ_UINT32 w, - OPJ_UINT32 h) -{ + OPJ_UINT32 h) { OPJ_UINT32 flagssize; /* No risk of overflow. Prior checks ensure those assert are met */ @@ -1055,7 +1033,7 @@ static OPJ_BOOL opj_t1_allocate_buffers( if (datasize > t1->datasize) { opj_aligned_free(t1->data); - t1->data = (OPJ_INT32*) + t1->data = (OPJ_INT32 *) opj_aligned_malloc(datasize * sizeof(OPJ_INT32)); if (!t1->data) { /* FIXME event manager error callback */ @@ -1079,7 +1057,7 @@ static OPJ_BOOL opj_t1_allocate_buffers( if (flagssize > t1->flagssize) { opj_aligned_free(t1->flags); - t1->flags = (opj_flag_t*) opj_aligned_malloc(flagssize * sizeof(opj_flag_t)); + t1->flags = (opj_flag_t *) opj_aligned_malloc(flagssize * sizeof(opj_flag_t)); if (!t1->flags) { /* FIXME event manager error callback */ return OPJ_FALSE; @@ -1108,12 +1086,12 @@ Decode 1 HT code-block @param check_pterm whether PTERM correct termination should be checked */ OPJ_BOOL opj_t1_ht_decode_cblk(opj_t1_t *t1, - opj_tcd_cblk_dec_t* cblk, + opj_tcd_cblk_dec_t *cblk, OPJ_UINT32 orient, OPJ_UINT32 roishift, OPJ_UINT32 cblksty, opj_event_mgr_t *p_manager, - opj_mutex_t* p_manager_mutex, + opj_mutex_t *p_manager_mutex, OPJ_BOOL check_pterm); //************************************************************************/ @@ -1130,17 +1108,16 @@ OPJ_BOOL opj_t1_ht_decode_cblk(opj_t1_t *t1, * @param [in] check_pterm: check termination (not used) */ OPJ_BOOL opj_t1_ht_decode_cblk(opj_t1_t *t1, - opj_tcd_cblk_dec_t* cblk, + opj_tcd_cblk_dec_t *cblk, OPJ_UINT32 orient, OPJ_UINT32 roishift, OPJ_UINT32 cblksty, opj_event_mgr_t *p_manager, - opj_mutex_t* p_manager_mutex, - OPJ_BOOL check_pterm) -{ - OPJ_BYTE* cblkdata = NULL; - OPJ_UINT8* coded_data; - OPJ_UINT32* decoded_data; + opj_mutex_t *p_manager_mutex, + OPJ_BOOL check_pterm) { + OPJ_BYTE *cblkdata = NULL; + OPJ_UINT8 *coded_data; + OPJ_UINT32 *decoded_data; OPJ_UINT32 zero_bplanes; OPJ_UINT32 num_passes; OPJ_UINT32 lengths1; @@ -1162,7 +1139,7 @@ OPJ_BOOL opj_t1_ht_decode_cblk(opj_t1_t *t1, OPJ_UINT32 vlc_val; // fetched data from VLC bitstream OPJ_UINT32 qinf[2]; OPJ_UINT32 c_q; - OPJ_UINT32* sp; + OPJ_UINT32 *sp; OPJ_INT32 x, y; // loop indices OPJ_BOOL stripe_causal = (cblksty & J2K_CCP_CBLKSTY_VSC) != 0; OPJ_UINT32 cblk_len = 0; @@ -1212,7 +1189,7 @@ OPJ_BOOL opj_t1_ht_decode_cblk(opj_t1_t *t1, /* Allocate temporary memory if needed */ if (cblk_len > t1->cblkdatabuffersize) { - cblkdata = (OPJ_BYTE*)opj_realloc( + cblkdata = (OPJ_BYTE *)opj_realloc( t1->cblkdatabuffer, cblk_len); if (cblkdata == NULL) { return OPJ_FALSE; @@ -1242,7 +1219,7 @@ OPJ_BOOL opj_t1_ht_decode_cblk(opj_t1_t *t1, // OPJ_BYTE* coded_data is a pointer to bitstream coded_data = cblkdata; // OPJ_UINT32* decoded_data is a pointer to decoded codeblock data buf. - decoded_data = (OPJ_UINT32*)t1->data; + decoded_data = (OPJ_UINT32 *)t1->data; // OPJ_UINT32 num_passes is the number of passes: 1 if CUP only, 2 for // CUP+SPP, and 3 for CUP+SPP+MRP num_passes = cblk->numsegs > 0 ? cblk->segs[0].real_num_passes : 0; @@ -2677,7 +2654,7 @@ OPJ_BOOL opj_t1_ht_decode_cblk(opj_t1_t *t1, { OPJ_INT32 x, y; for (y = 0; y < height; ++y) { - OPJ_INT32* sp = (OPJ_INT32*)decoded_data + y * stride; + OPJ_INT32 *sp = (OPJ_INT32 *)decoded_data + y * stride; for (x = 0; x < width; ++x, ++sp) { OPJ_INT32 val = (*sp & 0x7FFFFFFF); *sp = ((OPJ_UINT32) * sp & 0x80000000) ? -val : val; diff --git a/client/deps/openjpeg/image.c b/client/deps/openjpeg/image.c index 017201a00..efc47926a 100644 --- a/client/deps/openjpeg/image.c +++ b/client/deps/openjpeg/image.c @@ -31,25 +31,23 @@ #include "opj_includes.h" -opj_image_t* opj_image_create0(void) -{ - opj_image_t *image = (opj_image_t*)opj_calloc(1, sizeof(opj_image_t)); +opj_image_t *opj_image_create0(void) { + opj_image_t *image = (opj_image_t *)opj_calloc(1, sizeof(opj_image_t)); return image; } -opj_image_t* OPJ_CALLCONV opj_image_create(OPJ_UINT32 numcmpts, - opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc) -{ +opj_image_t *OPJ_CALLCONV opj_image_create(OPJ_UINT32 numcmpts, + opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc) { OPJ_UINT32 compno; opj_image_t *image = NULL; - image = (opj_image_t*) opj_calloc(1, sizeof(opj_image_t)); + image = (opj_image_t *) opj_calloc(1, sizeof(opj_image_t)); if (image) { image->color_space = clrspc; image->numcomps = numcmpts; /* allocate memory for the per-component information */ - image->comps = (opj_image_comp_t*)opj_calloc(image->numcomps, - sizeof(opj_image_comp_t)); + image->comps = (opj_image_comp_t *)opj_calloc(image->numcomps, + sizeof(opj_image_comp_t)); if (!image->comps) { /* TODO replace with event manager, breaks API */ /* fprintf(stderr,"Unable to allocate memory for image.\n"); */ @@ -73,7 +71,7 @@ opj_image_t* OPJ_CALLCONV opj_image_create(OPJ_UINT32 numcmpts, opj_image_destroy(image); return NULL; } - comp->data = (OPJ_INT32*) opj_image_data_alloc( + comp->data = (OPJ_INT32 *) opj_image_data_alloc( (size_t)comp->w * comp->h * sizeof(OPJ_INT32)); if (!comp->data) { /* TODO replace with event manager, breaks API */ @@ -88,8 +86,7 @@ opj_image_t* OPJ_CALLCONV opj_image_create(OPJ_UINT32 numcmpts, return image; } -void OPJ_CALLCONV opj_image_destroy(opj_image_t *image) -{ +void OPJ_CALLCONV opj_image_destroy(opj_image_t *image) { if (image) { if (image->comps) { OPJ_UINT32 compno; @@ -118,13 +115,12 @@ void OPJ_CALLCONV opj_image_destroy(opj_image_t *image) * @param p_image_header the image header to update. * @param p_cp the coding parameters from which to update the image. */ -void opj_image_comp_header_update(opj_image_t * p_image_header, - const struct opj_cp * p_cp) -{ +void opj_image_comp_header_update(opj_image_t *p_image_header, + const struct opj_cp *p_cp) { OPJ_UINT32 i, l_width, l_height; OPJ_UINT32 l_x0, l_y0, l_x1, l_y1; OPJ_UINT32 l_comp_x0, l_comp_y0, l_comp_x1, l_comp_y1; - opj_image_comp_t* l_img_comp = NULL; + opj_image_comp_t *l_img_comp = NULL; l_x0 = opj_uint_max(p_cp->tx0, p_image_header->x0); l_y0 = opj_uint_max(p_cp->ty0, p_image_header->y0); @@ -161,9 +157,8 @@ void opj_image_comp_header_update(opj_image_t * p_image_header, * @param p_image_dest the dest image * */ -void opj_copy_image_header(const opj_image_t* p_image_src, - opj_image_t* p_image_dest) -{ +void opj_copy_image_header(const opj_image_t *p_image_src, + opj_image_t *p_image_dest) { OPJ_UINT32 compno; /* preconditions */ @@ -188,8 +183,8 @@ void opj_copy_image_header(const opj_image_t* p_image_src, p_image_dest->numcomps = p_image_src->numcomps; - p_image_dest->comps = (opj_image_comp_t*) opj_malloc(p_image_dest->numcomps * - sizeof(opj_image_comp_t)); + p_image_dest->comps = (opj_image_comp_t *) opj_malloc(p_image_dest->numcomps * + sizeof(opj_image_comp_t)); if (!p_image_dest->comps) { p_image_dest->comps = NULL; p_image_dest->numcomps = 0; @@ -207,7 +202,7 @@ void opj_copy_image_header(const opj_image_t* p_image_src, p_image_dest->icc_profile_len = p_image_src->icc_profile_len; if (p_image_dest->icc_profile_len) { - p_image_dest->icc_profile_buf = (OPJ_BYTE*)opj_malloc( + p_image_dest->icc_profile_buf = (OPJ_BYTE *)opj_malloc( p_image_dest->icc_profile_len); if (!p_image_dest->icc_profile_buf) { p_image_dest->icc_profile_buf = NULL; @@ -224,21 +219,20 @@ void opj_copy_image_header(const opj_image_t* p_image_src, return; } -opj_image_t* OPJ_CALLCONV opj_image_tile_create(OPJ_UINT32 numcmpts, - opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc) -{ +opj_image_t *OPJ_CALLCONV opj_image_tile_create(OPJ_UINT32 numcmpts, + opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc) { OPJ_UINT32 compno; opj_image_t *image = 00; - image = (opj_image_t*) opj_calloc(1, sizeof(opj_image_t)); + image = (opj_image_t *) opj_calloc(1, sizeof(opj_image_t)); if (image) { image->color_space = clrspc; image->numcomps = numcmpts; /* allocate memory for the per-component information */ - image->comps = (opj_image_comp_t*)opj_calloc(image->numcomps, - sizeof(opj_image_comp_t)); + image->comps = (opj_image_comp_t *)opj_calloc(image->numcomps, + sizeof(opj_image_comp_t)); if (!image->comps) { opj_image_destroy(image); return 00; diff --git a/client/deps/openjpeg/image.h b/client/deps/openjpeg/image.h index bad83c613..2544d9d14 100644 --- a/client/deps/openjpeg/image.h +++ b/client/deps/openjpeg/image.h @@ -48,7 +48,7 @@ struct opj_cp; * * @return returns an empty image if successful, returns NULL otherwise */ -opj_image_t* opj_image_create0(void); +opj_image_t *opj_image_create0(void); @@ -58,11 +58,11 @@ opj_image_t* opj_image_create0(void); * @param p_image_header the image header to update. * @param p_cp the coding parameters from which to update the image. */ -void opj_image_comp_header_update(opj_image_t * p_image, - const struct opj_cp* p_cp); +void opj_image_comp_header_update(opj_image_t *p_image, + const struct opj_cp *p_cp); -void opj_copy_image_header(const opj_image_t* p_image_src, - opj_image_t* p_image_dest); +void opj_copy_image_header(const opj_image_t *p_image_src, + opj_image_t *p_image_dest); /*@}*/ diff --git a/client/deps/openjpeg/invert.c b/client/deps/openjpeg/invert.c index 89f607155..ea23508c6 100644 --- a/client/deps/openjpeg/invert.c +++ b/client/deps/openjpeg/invert.c @@ -34,30 +34,30 @@ /** * LUP decomposition */ -static OPJ_BOOL opj_lupDecompose(OPJ_FLOAT32 * matrix, - OPJ_UINT32 * permutations, - OPJ_FLOAT32 * p_swap_area, +static OPJ_BOOL opj_lupDecompose(OPJ_FLOAT32 *matrix, + OPJ_UINT32 *permutations, + OPJ_FLOAT32 *p_swap_area, OPJ_UINT32 nb_compo); /** * LUP solving */ -static void opj_lupSolve(OPJ_FLOAT32 * pResult, - OPJ_FLOAT32* pMatrix, - OPJ_FLOAT32* pVector, - OPJ_UINT32* pPermutations, +static void opj_lupSolve(OPJ_FLOAT32 *pResult, + OPJ_FLOAT32 *pMatrix, + OPJ_FLOAT32 *pVector, + OPJ_UINT32 *pPermutations, OPJ_UINT32 nb_compo, - OPJ_FLOAT32 * p_intermediate_data); + OPJ_FLOAT32 *p_intermediate_data); /** *LUP inversion (call with the result of lupDecompose) */ -static void opj_lupInvert(OPJ_FLOAT32 * pSrcMatrix, - OPJ_FLOAT32 * pDestMatrix, +static void opj_lupInvert(OPJ_FLOAT32 *pSrcMatrix, + OPJ_FLOAT32 *pDestMatrix, OPJ_UINT32 nb_compo, - OPJ_UINT32 * pPermutations, - OPJ_FLOAT32 * p_src_temp, - OPJ_FLOAT32 * p_dest_temp, - OPJ_FLOAT32 * p_swap_area); + OPJ_UINT32 *pPermutations, + OPJ_FLOAT32 *p_src_temp, + OPJ_FLOAT32 *p_dest_temp, + OPJ_FLOAT32 *p_swap_area); /* ========================================================== @@ -67,16 +67,15 @@ static void opj_lupInvert(OPJ_FLOAT32 * pSrcMatrix, /** * Matrix inversion. */ -OPJ_BOOL opj_matrix_inversion_f(OPJ_FLOAT32 * pSrcMatrix, - OPJ_FLOAT32 * pDestMatrix, - OPJ_UINT32 nb_compo) -{ - OPJ_BYTE * l_data = 00; +OPJ_BOOL opj_matrix_inversion_f(OPJ_FLOAT32 *pSrcMatrix, + OPJ_FLOAT32 *pDestMatrix, + OPJ_UINT32 nb_compo) { + OPJ_BYTE *l_data = 00; OPJ_UINT32 l_permutation_size = nb_compo * (OPJ_UINT32)sizeof(OPJ_UINT32); OPJ_UINT32 l_swap_size = nb_compo * (OPJ_UINT32)sizeof(OPJ_FLOAT32); OPJ_UINT32 l_total_size = l_permutation_size + 3 * l_swap_size; - OPJ_UINT32 * lPermutations = 00; - OPJ_FLOAT32 * l_double_data = 00; + OPJ_UINT32 *lPermutations = 00; + OPJ_FLOAT32 *l_double_data = 00; l_data = (OPJ_BYTE *) opj_malloc(l_total_size); if (l_data == 0) { @@ -104,21 +103,20 @@ OPJ_BOOL opj_matrix_inversion_f(OPJ_FLOAT32 * pSrcMatrix, Local functions ========================================================== */ -static OPJ_BOOL opj_lupDecompose(OPJ_FLOAT32 * matrix, - OPJ_UINT32 * permutations, - OPJ_FLOAT32 * p_swap_area, - OPJ_UINT32 nb_compo) -{ - OPJ_UINT32 * tmpPermutations = permutations; - OPJ_UINT32 * dstPermutations; +static OPJ_BOOL opj_lupDecompose(OPJ_FLOAT32 *matrix, + OPJ_UINT32 *permutations, + OPJ_FLOAT32 *p_swap_area, + OPJ_UINT32 nb_compo) { + OPJ_UINT32 *tmpPermutations = permutations; + OPJ_UINT32 *dstPermutations; OPJ_UINT32 k2 = 0, t; OPJ_FLOAT32 temp; OPJ_UINT32 i, j, k; OPJ_FLOAT32 p; OPJ_UINT32 lLastColum = nb_compo - 1; OPJ_UINT32 lSwapSize = nb_compo * (OPJ_UINT32)sizeof(OPJ_FLOAT32); - OPJ_FLOAT32 * lTmpMatrix = matrix; - OPJ_FLOAT32 * lColumnMatrix, * lDestMatrix; + OPJ_FLOAT32 *lTmpMatrix = matrix; + OPJ_FLOAT32 *lColumnMatrix, * lDestMatrix; OPJ_UINT32 offset = 1; OPJ_UINT32 lStride = nb_compo - 1; @@ -205,25 +203,24 @@ static OPJ_BOOL opj_lupDecompose(OPJ_FLOAT32 * matrix, return OPJ_TRUE; } -static void opj_lupSolve(OPJ_FLOAT32 * pResult, - OPJ_FLOAT32 * pMatrix, - OPJ_FLOAT32 * pVector, - OPJ_UINT32* pPermutations, - OPJ_UINT32 nb_compo, OPJ_FLOAT32 * p_intermediate_data) -{ +static void opj_lupSolve(OPJ_FLOAT32 *pResult, + OPJ_FLOAT32 *pMatrix, + OPJ_FLOAT32 *pVector, + OPJ_UINT32 *pPermutations, + OPJ_UINT32 nb_compo, OPJ_FLOAT32 *p_intermediate_data) { OPJ_INT32 k; OPJ_UINT32 i, j; OPJ_FLOAT32 sum; OPJ_FLOAT32 u; OPJ_UINT32 lStride = nb_compo + 1; - OPJ_FLOAT32 * lCurrentPtr; - OPJ_FLOAT32 * lIntermediatePtr; - OPJ_FLOAT32 * lDestPtr; - OPJ_FLOAT32 * lTmpMatrix; - OPJ_FLOAT32 * lLineMatrix = pMatrix; - OPJ_FLOAT32 * lBeginPtr = pResult + nb_compo - 1; - OPJ_FLOAT32 * lGeneratedData; - OPJ_UINT32 * lCurrentPermutationPtr = pPermutations; + OPJ_FLOAT32 *lCurrentPtr; + OPJ_FLOAT32 *lIntermediatePtr; + OPJ_FLOAT32 *lDestPtr; + OPJ_FLOAT32 *lTmpMatrix; + OPJ_FLOAT32 *lLineMatrix = pMatrix; + OPJ_FLOAT32 *lBeginPtr = pResult + nb_compo - 1; + OPJ_FLOAT32 *lGeneratedData; + OPJ_UINT32 *lCurrentPermutationPtr = pPermutations; lIntermediatePtr = p_intermediate_data; @@ -266,17 +263,16 @@ static void opj_lupSolve(OPJ_FLOAT32 * pResult, } -static void opj_lupInvert(OPJ_FLOAT32 * pSrcMatrix, - OPJ_FLOAT32 * pDestMatrix, +static void opj_lupInvert(OPJ_FLOAT32 *pSrcMatrix, + OPJ_FLOAT32 *pDestMatrix, OPJ_UINT32 nb_compo, - OPJ_UINT32 * pPermutations, - OPJ_FLOAT32 * p_src_temp, - OPJ_FLOAT32 * p_dest_temp, - OPJ_FLOAT32 * p_swap_area) -{ + OPJ_UINT32 *pPermutations, + OPJ_FLOAT32 *p_src_temp, + OPJ_FLOAT32 *p_dest_temp, + OPJ_FLOAT32 *p_swap_area) { OPJ_UINT32 j, i; - OPJ_FLOAT32 * lCurrentPtr; - OPJ_FLOAT32 * lLineMatrix = pDestMatrix; + OPJ_FLOAT32 *lCurrentPtr; + OPJ_FLOAT32 *lLineMatrix = pDestMatrix; OPJ_UINT32 lSwapSize = nb_compo * (OPJ_UINT32)sizeof(OPJ_FLOAT32); for (j = 0; j < nb_compo; ++j) { diff --git a/client/deps/openjpeg/invert.h b/client/deps/openjpeg/invert.h index 704021355..9c3349ed8 100644 --- a/client/deps/openjpeg/invert.h +++ b/client/deps/openjpeg/invert.h @@ -53,8 +53,8 @@ The function in INVERT.H compute a matrix inversion with a LUP method * @param nb_compo size of the matrix * @return OPJ_TRUE if the inversion is successful, OPJ_FALSE if the matrix is singular. */ -OPJ_BOOL opj_matrix_inversion_f(OPJ_FLOAT32 * pSrcMatrix, - OPJ_FLOAT32 * pDestMatrix, +OPJ_BOOL opj_matrix_inversion_f(OPJ_FLOAT32 *pSrcMatrix, + OPJ_FLOAT32 *pDestMatrix, OPJ_UINT32 nb_compo); /* ----------------------------------------------------------------------- */ /*@}*/ diff --git a/client/deps/openjpeg/j2k.c b/client/deps/openjpeg/j2k.c index 29ce1c735..000426a62 100644 --- a/client/deps/openjpeg/j2k.c +++ b/client/deps/openjpeg/j2k.c @@ -53,14 +53,14 @@ * Sets up the procedures to do on reading header. Developers wanting to extend the library can add their own reading procedures. */ static OPJ_BOOL opj_j2k_setup_header_reading(opj_j2k_t *p_j2k, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * The read header procedure. */ static OPJ_BOOL opj_j2k_read_header_procedure(opj_j2k_t *p_j2k, - opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager); + opj_stream_private_t *p_stream, + opj_event_mgr_t *p_manager); /** * The default encoding validation procedure without any extension. @@ -71,9 +71,9 @@ static OPJ_BOOL opj_j2k_read_header_procedure(opj_j2k_t *p_j2k, * * @return true if the parameters are correct. */ -static OPJ_BOOL opj_j2k_encoding_validation(opj_j2k_t * p_j2k, - opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager); +static OPJ_BOOL opj_j2k_encoding_validation(opj_j2k_t *p_j2k, + opj_stream_private_t *p_stream, + opj_event_mgr_t *p_manager); /** * The default decoding validation procedure without any extension. @@ -84,30 +84,30 @@ static OPJ_BOOL opj_j2k_encoding_validation(opj_j2k_t * p_j2k, * * @return true if the parameters are correct. */ -static OPJ_BOOL opj_j2k_decoding_validation(opj_j2k_t * p_j2k, - opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager); +static OPJ_BOOL opj_j2k_decoding_validation(opj_j2k_t *p_j2k, + opj_stream_private_t *p_stream, + opj_event_mgr_t *p_manager); /** * Sets up the validation ,i.e. adds the procedures to launch to make sure the codec parameters * are valid. Developers wanting to extend the library can add their own validation procedures. */ static OPJ_BOOL opj_j2k_setup_encoding_validation(opj_j2k_t *p_j2k, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Sets up the validation ,i.e. adds the procedures to launch to make sure the codec parameters * are valid. Developers wanting to extend the library can add their own validation procedures. */ static OPJ_BOOL opj_j2k_setup_decoding_validation(opj_j2k_t *p_j2k, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Sets up the validation ,i.e. adds the procedures to launch to make sure the codec parameters * are valid. Developers wanting to extend the library can add their own validation procedures. */ static OPJ_BOOL opj_j2k_setup_end_compress(opj_j2k_t *p_j2k, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * The mct encoding validation procedure. @@ -118,22 +118,22 @@ static OPJ_BOOL opj_j2k_setup_end_compress(opj_j2k_t *p_j2k, * * @return true if the parameters are correct. */ -static OPJ_BOOL opj_j2k_mct_validation(opj_j2k_t * p_j2k, +static OPJ_BOOL opj_j2k_mct_validation(opj_j2k_t *p_j2k, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Builds the tcd decoder to use to decode tile. */ -static OPJ_BOOL opj_j2k_build_decoder(opj_j2k_t * p_j2k, +static OPJ_BOOL opj_j2k_build_decoder(opj_j2k_t *p_j2k, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Builds the tcd encoder to use to encode tile. */ -static OPJ_BOOL opj_j2k_build_encoder(opj_j2k_t * p_j2k, +static OPJ_BOOL opj_j2k_build_encoder(opj_j2k_t *p_j2k, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Creates a tile-coder encoder. @@ -144,7 +144,7 @@ static OPJ_BOOL opj_j2k_build_encoder(opj_j2k_t * p_j2k, */ static OPJ_BOOL opj_j2k_create_tcd(opj_j2k_t *p_j2k, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Executes the given procedures on the given codec. @@ -156,10 +156,10 @@ static OPJ_BOOL opj_j2k_create_tcd(opj_j2k_t *p_j2k, * * @return true if all the procedures were successfully executed. */ -static OPJ_BOOL opj_j2k_exec(opj_j2k_t * p_j2k, - opj_procedure_list_t * p_procedure_list, +static OPJ_BOOL opj_j2k_exec(opj_j2k_t *p_j2k, + opj_procedure_list_t *p_procedure_list, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Updates the rates of the tcp. @@ -170,22 +170,22 @@ static OPJ_BOOL opj_j2k_exec(opj_j2k_t * p_j2k, */ static OPJ_BOOL opj_j2k_update_rates(opj_j2k_t *p_j2k, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Copies the decoding tile parameters onto all the tile parameters. * Creates also the tile decoder. */ -static OPJ_BOOL opj_j2k_copy_default_tcp_and_create_tcd(opj_j2k_t * p_j2k, - opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager); +static OPJ_BOOL opj_j2k_copy_default_tcp_and_create_tcd(opj_j2k_t *p_j2k, + opj_stream_private_t *p_stream, + opj_event_mgr_t *p_manager); /** * Destroys the memory associated with the decoding of headers. */ -static OPJ_BOOL opj_j2k_destroy_header_memory(opj_j2k_t * p_j2k, - opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager); +static OPJ_BOOL opj_j2k_destroy_header_memory(opj_j2k_t *p_j2k, + opj_stream_private_t *p_stream, + opj_event_mgr_t *p_manager); /** * Reads the lookup table containing all the marker, status and action, and returns the handler associated @@ -194,7 +194,7 @@ static OPJ_BOOL opj_j2k_destroy_header_memory(opj_j2k_t * p_j2k, * * @return the handler associated with the id. */ -static const struct opj_dec_memory_marker_handler * opj_j2k_get_marker_handler( +static const struct opj_dec_memory_marker_handler *opj_j2k_get_marker_handler( OPJ_UINT32 p_id); /** @@ -229,7 +229,7 @@ static void opj_j2k_cp_destroy(opj_cp_t *p_cp); * @return OPJ_TRUE if SPCdod are equals. */ static OPJ_BOOL opj_j2k_compare_SPCod_SPCoc(opj_j2k_t *p_j2k, - OPJ_UINT32 p_tile_no, OPJ_UINT32 p_first_comp_no, OPJ_UINT32 p_second_comp_no); + OPJ_UINT32 p_tile_no, OPJ_UINT32 p_first_comp_no, OPJ_UINT32 p_second_comp_no); /** * Writes a SPCod or SPCoc element, i.e. the coding style of a given component of a tile. @@ -244,11 +244,11 @@ static OPJ_BOOL opj_j2k_compare_SPCod_SPCoc(opj_j2k_t *p_j2k, * @return FIXME DOC */ static OPJ_BOOL opj_j2k_write_SPCod_SPCoc(opj_j2k_t *p_j2k, - OPJ_UINT32 p_tile_no, - OPJ_UINT32 p_comp_no, - OPJ_BYTE * p_data, - OPJ_UINT32 * p_header_size, - opj_event_mgr_t * p_manager); + OPJ_UINT32 p_tile_no, + OPJ_UINT32 p_comp_no, + OPJ_BYTE *p_data, + OPJ_UINT32 *p_header_size, + opj_event_mgr_t *p_manager); /** * Gets the size taken by writing a SPCod or SPCoc for the given tile and component. @@ -260,8 +260,8 @@ static OPJ_BOOL opj_j2k_write_SPCod_SPCoc(opj_j2k_t *p_j2k, * @return the number of bytes taken by the SPCod element. */ static OPJ_UINT32 opj_j2k_get_SPCod_SPCoc_size(opj_j2k_t *p_j2k, - OPJ_UINT32 p_tile_no, - OPJ_UINT32 p_comp_no); + OPJ_UINT32 p_tile_no, + OPJ_UINT32 p_comp_no); /** * Reads a SPCod or SPCoc element, i.e. the coding style of a given component of a tile. @@ -272,10 +272,10 @@ static OPJ_UINT32 opj_j2k_get_SPCod_SPCoc_size(opj_j2k_t *p_j2k, * @param p_manager the user event manager. */ static OPJ_BOOL opj_j2k_read_SPCod_SPCoc(opj_j2k_t *p_j2k, - OPJ_UINT32 compno, - OPJ_BYTE * p_header_data, - OPJ_UINT32 * p_header_size, - opj_event_mgr_t * p_manager); + OPJ_UINT32 compno, + OPJ_BYTE *p_header_data, + OPJ_UINT32 *p_header_size, + opj_event_mgr_t *p_manager); /** * Gets the size taken by writing SQcd or SQcc element, i.e. the quantization values of a band in the QCD or QCC. @@ -287,8 +287,8 @@ static OPJ_BOOL opj_j2k_read_SPCod_SPCoc(opj_j2k_t *p_j2k, * @return the number of bytes taken by the SPCod element. */ static OPJ_UINT32 opj_j2k_get_SQcd_SQcc_size(opj_j2k_t *p_j2k, - OPJ_UINT32 p_tile_no, - OPJ_UINT32 p_comp_no); + OPJ_UINT32 p_tile_no, + OPJ_UINT32 p_comp_no); /** * Compares 2 SQcd or SQcc element, i.e. the quantization values of a band in the QCD or QCC. @@ -301,7 +301,7 @@ static OPJ_UINT32 opj_j2k_get_SQcd_SQcc_size(opj_j2k_t *p_j2k, * @return OPJ_TRUE if equals. */ static OPJ_BOOL opj_j2k_compare_SQcd_SQcc(opj_j2k_t *p_j2k, - OPJ_UINT32 p_tile_no, OPJ_UINT32 p_first_comp_no, OPJ_UINT32 p_second_comp_no); + OPJ_UINT32 p_tile_no, OPJ_UINT32 p_first_comp_no, OPJ_UINT32 p_second_comp_no); /** @@ -318,14 +318,14 @@ static OPJ_BOOL opj_j2k_compare_SQcd_SQcc(opj_j2k_t *p_j2k, static OPJ_BOOL opj_j2k_write_SQcd_SQcc(opj_j2k_t *p_j2k, OPJ_UINT32 p_tile_no, OPJ_UINT32 p_comp_no, - OPJ_BYTE * p_data, - OPJ_UINT32 * p_header_size, - opj_event_mgr_t * p_manager); + OPJ_BYTE *p_data, + OPJ_UINT32 *p_header_size, + opj_event_mgr_t *p_manager); /** * Updates the Tile Length Marker. */ -static void opj_j2k_update_tlm(opj_j2k_t * p_j2k, OPJ_UINT32 p_tile_part_size); +static void opj_j2k_update_tlm(opj_j2k_t *p_j2k, OPJ_UINT32 p_tile_part_size); /** * Reads a SQcd or SQcc element, i.e. the quantization values of a band in the QCD or QCC. @@ -339,9 +339,9 @@ static void opj_j2k_update_tlm(opj_j2k_t * p_j2k, OPJ_UINT32 p_tile_part_size); */ static OPJ_BOOL opj_j2k_read_SQcd_SQcc(opj_j2k_t *p_j2k, OPJ_UINT32 compno, - OPJ_BYTE * p_header_data, - OPJ_UINT32 * p_header_size, - opj_event_mgr_t * p_manager); + OPJ_BYTE *p_header_data, + OPJ_UINT32 *p_header_size, + opj_event_mgr_t *p_manager); /** * Copies the tile component parameters of all the component from the first tile component. @@ -362,54 +362,54 @@ static void opj_j2k_copy_tile_quantization_parameters(opj_j2k_t *p_j2k); */ static OPJ_BOOL opj_j2k_decode_tiles(opj_j2k_t *p_j2k, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); -static OPJ_BOOL opj_j2k_pre_write_tile(opj_j2k_t * p_j2k, +static OPJ_BOOL opj_j2k_pre_write_tile(opj_j2k_t *p_j2k, OPJ_UINT32 p_tile_index, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); -static OPJ_BOOL opj_j2k_update_image_data(opj_tcd_t * p_tcd, - opj_image_t* p_output_image); +static OPJ_BOOL opj_j2k_update_image_data(opj_tcd_t *p_tcd, + opj_image_t *p_output_image); -static void opj_get_tile_dimensions(opj_image_t * l_image, - opj_tcd_tilecomp_t * l_tilec, - opj_image_comp_t * l_img_comp, - OPJ_UINT32* l_size_comp, - OPJ_UINT32* l_width, - OPJ_UINT32* l_height, - OPJ_UINT32* l_offset_x, - OPJ_UINT32* l_offset_y, - OPJ_UINT32* l_image_width, - OPJ_UINT32* l_stride, - OPJ_UINT32* l_tile_offset); +static void opj_get_tile_dimensions(opj_image_t *l_image, + opj_tcd_tilecomp_t *l_tilec, + opj_image_comp_t *l_img_comp, + OPJ_UINT32 *l_size_comp, + OPJ_UINT32 *l_width, + OPJ_UINT32 *l_height, + OPJ_UINT32 *l_offset_x, + OPJ_UINT32 *l_offset_y, + OPJ_UINT32 *l_image_width, + OPJ_UINT32 *l_stride, + OPJ_UINT32 *l_tile_offset); -static void opj_j2k_get_tile_data(opj_tcd_t * p_tcd, OPJ_BYTE * p_data); +static void opj_j2k_get_tile_data(opj_tcd_t *p_tcd, OPJ_BYTE *p_data); -static OPJ_BOOL opj_j2k_post_write_tile(opj_j2k_t * p_j2k, +static OPJ_BOOL opj_j2k_post_write_tile(opj_j2k_t *p_j2k, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Sets up the procedures to do on writing header. * Developers wanting to extend the library can add their own writing procedures. */ static OPJ_BOOL opj_j2k_setup_header_writing(opj_j2k_t *p_j2k, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); static OPJ_BOOL opj_j2k_write_first_tile_part(opj_j2k_t *p_j2k, - OPJ_BYTE * p_data, - OPJ_UINT32 * p_data_written, - OPJ_UINT32 total_data_size, - opj_stream_private_t *p_stream, - struct opj_event_mgr * p_manager); + OPJ_BYTE *p_data, + OPJ_UINT32 *p_data_written, + OPJ_UINT32 total_data_size, + opj_stream_private_t *p_stream, + struct opj_event_mgr *p_manager); static OPJ_BOOL opj_j2k_write_all_tile_parts(opj_j2k_t *p_j2k, - OPJ_BYTE * p_data, - OPJ_UINT32 * p_data_written, - OPJ_UINT32 total_data_size, - opj_stream_private_t *p_stream, - struct opj_event_mgr * p_manager); + OPJ_BYTE *p_data, + OPJ_UINT32 *p_data_written, + OPJ_UINT32 total_data_size, + opj_stream_private_t *p_stream, + struct opj_event_mgr *p_manager); /** * Gets the offset of the header. @@ -420,7 +420,7 @@ static OPJ_BOOL opj_j2k_write_all_tile_parts(opj_j2k_t *p_j2k, */ static OPJ_BOOL opj_j2k_get_end_header(opj_j2k_t *p_j2k, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); static OPJ_BOOL opj_j2k_allocate_tile_element_cstr_index(opj_j2k_t *p_j2k); @@ -439,7 +439,7 @@ static OPJ_BOOL opj_j2k_allocate_tile_element_cstr_index(opj_j2k_t *p_j2k); */ static OPJ_BOOL opj_j2k_write_soc(opj_j2k_t *p_j2k, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Reads a SOC marker (Start of Codestream) @@ -449,7 +449,7 @@ static OPJ_BOOL opj_j2k_write_soc(opj_j2k_t *p_j2k, */ static OPJ_BOOL opj_j2k_read_soc(opj_j2k_t *p_j2k, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Writes the SIZ marker (image and tile size) @@ -460,7 +460,7 @@ static OPJ_BOOL opj_j2k_read_soc(opj_j2k_t *p_j2k, */ static OPJ_BOOL opj_j2k_write_siz(opj_j2k_t *p_j2k, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Reads a SIZ marker (image and tile size) @@ -470,9 +470,9 @@ static OPJ_BOOL opj_j2k_write_siz(opj_j2k_t *p_j2k, * @param p_manager the user event manager. */ static OPJ_BOOL opj_j2k_read_siz(opj_j2k_t *p_j2k, - OPJ_BYTE * p_header_data, + OPJ_BYTE *p_header_data, OPJ_UINT32 p_header_size, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Writes the COM marker (comment) @@ -483,7 +483,7 @@ static OPJ_BOOL opj_j2k_read_siz(opj_j2k_t *p_j2k, */ static OPJ_BOOL opj_j2k_write_com(opj_j2k_t *p_j2k, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Reads a COM marker (comments) @@ -493,9 +493,9 @@ static OPJ_BOOL opj_j2k_write_com(opj_j2k_t *p_j2k, * @param p_manager the user event manager. */ static OPJ_BOOL opj_j2k_read_com(opj_j2k_t *p_j2k, - OPJ_BYTE * p_header_data, + OPJ_BYTE *p_header_data, OPJ_UINT32 p_header_size, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Writes the COD marker (Coding style default) * @@ -505,7 +505,7 @@ static OPJ_BOOL opj_j2k_read_com(opj_j2k_t *p_j2k, */ static OPJ_BOOL opj_j2k_write_cod(opj_j2k_t *p_j2k, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Reads a COD marker (Coding style defaults) @@ -515,9 +515,9 @@ static OPJ_BOOL opj_j2k_write_cod(opj_j2k_t *p_j2k, * @param p_manager the user event manager. */ static OPJ_BOOL opj_j2k_read_cod(opj_j2k_t *p_j2k, - OPJ_BYTE * p_header_data, + OPJ_BYTE *p_header_data, OPJ_UINT32 p_header_size, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Compares 2 COC markers (Coding style component) @@ -542,7 +542,7 @@ static OPJ_BOOL opj_j2k_compare_coc(opj_j2k_t *p_j2k, static OPJ_BOOL opj_j2k_write_coc(opj_j2k_t *p_j2k, OPJ_UINT32 p_comp_no, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Writes the COC marker (Coding style component) @@ -555,9 +555,9 @@ static OPJ_BOOL opj_j2k_write_coc(opj_j2k_t *p_j2k, */ static void opj_j2k_write_coc_in_memory(opj_j2k_t *p_j2k, OPJ_UINT32 p_comp_no, - OPJ_BYTE * p_data, - OPJ_UINT32 * p_data_written, - opj_event_mgr_t * p_manager); + OPJ_BYTE *p_data, + OPJ_UINT32 *p_data_written, + opj_event_mgr_t *p_manager); /** * Gets the maximum size taken by a coc. @@ -574,9 +574,9 @@ static OPJ_UINT32 opj_j2k_get_max_coc_size(opj_j2k_t *p_j2k); * @param p_manager the user event manager. */ static OPJ_BOOL opj_j2k_read_coc(opj_j2k_t *p_j2k, - OPJ_BYTE * p_header_data, + OPJ_BYTE *p_header_data, OPJ_UINT32 p_header_size, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Writes the QCD marker (quantization default) @@ -587,7 +587,7 @@ static OPJ_BOOL opj_j2k_read_coc(opj_j2k_t *p_j2k, */ static OPJ_BOOL opj_j2k_write_qcd(opj_j2k_t *p_j2k, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Reads a QCD marker (Quantization defaults) @@ -597,9 +597,9 @@ static OPJ_BOOL opj_j2k_write_qcd(opj_j2k_t *p_j2k, * @param p_manager the user event manager. */ static OPJ_BOOL opj_j2k_read_qcd(opj_j2k_t *p_j2k, - OPJ_BYTE * p_header_data, + OPJ_BYTE *p_header_data, OPJ_UINT32 p_header_size, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Compare QCC markers (quantization component) @@ -624,7 +624,7 @@ static OPJ_BOOL opj_j2k_compare_qcc(opj_j2k_t *p_j2k, static OPJ_BOOL opj_j2k_write_qcc(opj_j2k_t *p_j2k, OPJ_UINT32 p_comp_no, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Writes the QCC marker (quantization component) @@ -637,9 +637,9 @@ static OPJ_BOOL opj_j2k_write_qcc(opj_j2k_t *p_j2k, */ static void opj_j2k_write_qcc_in_memory(opj_j2k_t *p_j2k, OPJ_UINT32 p_comp_no, - OPJ_BYTE * p_data, - OPJ_UINT32 * p_data_written, - opj_event_mgr_t * p_manager); + OPJ_BYTE *p_data, + OPJ_UINT32 *p_data_written, + opj_event_mgr_t *p_manager); /** * Gets the maximum size taken by a qcc. @@ -654,9 +654,9 @@ static OPJ_UINT32 opj_j2k_get_max_qcc_size(opj_j2k_t *p_j2k); * @param p_manager the user event manager. */ static OPJ_BOOL opj_j2k_read_qcc(opj_j2k_t *p_j2k, - OPJ_BYTE * p_header_data, + OPJ_BYTE *p_header_data, OPJ_UINT32 p_header_size, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Writes the POC marker (Progression Order Change) * @@ -666,7 +666,7 @@ static OPJ_BOOL opj_j2k_read_qcc(opj_j2k_t *p_j2k, */ static OPJ_BOOL opj_j2k_write_poc(opj_j2k_t *p_j2k, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Writes the POC marker (Progression Order Change) * @@ -676,9 +676,9 @@ static OPJ_BOOL opj_j2k_write_poc(opj_j2k_t *p_j2k, * @param p_manager the user event manager. */ static void opj_j2k_write_poc_in_memory(opj_j2k_t *p_j2k, - OPJ_BYTE * p_data, - OPJ_UINT32 * p_data_written, - opj_event_mgr_t * p_manager); + OPJ_BYTE *p_data, + OPJ_UINT32 *p_data_written, + opj_event_mgr_t *p_manager); /** * Gets the maximum size taken by the writing of a POC. */ @@ -693,9 +693,9 @@ static OPJ_UINT32 opj_j2k_get_max_poc_size(opj_j2k_t *p_j2k); * @param p_manager the user event manager. */ static OPJ_BOOL opj_j2k_read_poc(opj_j2k_t *p_j2k, - OPJ_BYTE * p_header_data, + OPJ_BYTE *p_header_data, OPJ_UINT32 p_header_size, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Gets the maximum size taken by the toc headers of all the tile parts of any given tile. @@ -718,9 +718,9 @@ static OPJ_UINT32 opj_j2k_get_specific_header_sizes(opj_j2k_t *p_j2k); * @param p_manager the user event manager. */ static OPJ_BOOL opj_j2k_read_crg(opj_j2k_t *p_j2k, - OPJ_BYTE * p_header_data, + OPJ_BYTE *p_header_data, OPJ_UINT32 p_header_size, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Reads a TLM marker (Tile Length Marker) * @@ -730,9 +730,9 @@ static OPJ_BOOL opj_j2k_read_crg(opj_j2k_t *p_j2k, * @param p_manager the user event manager. */ static OPJ_BOOL opj_j2k_read_tlm(opj_j2k_t *p_j2k, - OPJ_BYTE * p_header_data, + OPJ_BYTE *p_header_data, OPJ_UINT32 p_header_size, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Writes the updated tlm. @@ -742,8 +742,8 @@ static OPJ_BOOL opj_j2k_read_tlm(opj_j2k_t *p_j2k, * @param p_manager the user event manager. */ static OPJ_BOOL opj_j2k_write_updated_tlm(opj_j2k_t *p_j2k, - opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager); + opj_stream_private_t *p_stream, + opj_event_mgr_t *p_manager); /** * Reads a PLM marker (Packet length, main header marker) @@ -754,9 +754,9 @@ static OPJ_BOOL opj_j2k_write_updated_tlm(opj_j2k_t *p_j2k, * @param p_manager the user event manager. */ static OPJ_BOOL opj_j2k_read_plm(opj_j2k_t *p_j2k, - OPJ_BYTE * p_header_data, + OPJ_BYTE *p_header_data, OPJ_UINT32 p_header_size, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Reads a PLT marker (Packet length, tile-part header) * @@ -766,9 +766,9 @@ static OPJ_BOOL opj_j2k_read_plm(opj_j2k_t *p_j2k, * @param p_manager the user event manager. */ static OPJ_BOOL opj_j2k_read_plt(opj_j2k_t *p_j2k, - OPJ_BYTE * p_header_data, + OPJ_BYTE *p_header_data, OPJ_UINT32 p_header_size, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Reads a PPM marker (Packed headers, main header) @@ -781,9 +781,9 @@ static OPJ_BOOL opj_j2k_read_plt(opj_j2k_t *p_j2k, static OPJ_BOOL opj_j2k_read_ppm( opj_j2k_t *p_j2k, - OPJ_BYTE * p_header_data, + OPJ_BYTE *p_header_data, OPJ_UINT32 p_header_size, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Merges all PPM markers read (Packed headers, main header) @@ -791,7 +791,7 @@ static OPJ_BOOL opj_j2k_read_ppm( * @param p_cp main coding parameters. * @param p_manager the user event manager. */ -static OPJ_BOOL opj_j2k_merge_ppm(opj_cp_t *p_cp, opj_event_mgr_t * p_manager); +static OPJ_BOOL opj_j2k_merge_ppm(opj_cp_t *p_cp, opj_event_mgr_t *p_manager); /** * Reads a PPT marker (Packed packet headers, tile-part header) @@ -802,9 +802,9 @@ static OPJ_BOOL opj_j2k_merge_ppm(opj_cp_t *p_cp, opj_event_mgr_t * p_manager); * @param p_manager the user event manager. */ static OPJ_BOOL opj_j2k_read_ppt(opj_j2k_t *p_j2k, - OPJ_BYTE * p_header_data, + OPJ_BYTE *p_header_data, OPJ_UINT32 p_header_size, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Merges all PPT markers read (Packed headers, tile-part header) @@ -813,7 +813,7 @@ static OPJ_BOOL opj_j2k_read_ppt(opj_j2k_t *p_j2k, * @param p_manager the user event manager. */ static OPJ_BOOL opj_j2k_merge_ppt(opj_tcp_t *p_tcp, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** @@ -825,7 +825,7 @@ static OPJ_BOOL opj_j2k_merge_ppt(opj_tcp_t *p_tcp, */ static OPJ_BOOL opj_j2k_write_tlm(opj_j2k_t *p_j2k, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Writes the SOT marker (Start of tile-part) @@ -838,11 +838,11 @@ static OPJ_BOOL opj_j2k_write_tlm(opj_j2k_t *p_j2k, * @param p_manager the user event manager. */ static OPJ_BOOL opj_j2k_write_sot(opj_j2k_t *p_j2k, - OPJ_BYTE * p_data, + OPJ_BYTE *p_data, OPJ_UINT32 total_data_size, - OPJ_UINT32 * p_data_written, + OPJ_UINT32 *p_data_written, const opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Reads values from a SOT marker (Start of tile-part) @@ -857,13 +857,13 @@ static OPJ_BOOL opj_j2k_write_sot(opj_j2k_t *p_j2k, * @param p_num_parts TNsot. * @param p_manager the user event manager. */ -static OPJ_BOOL opj_j2k_get_sot_values(OPJ_BYTE * p_header_data, +static OPJ_BOOL opj_j2k_get_sot_values(OPJ_BYTE *p_header_data, OPJ_UINT32 p_header_size, - OPJ_UINT32* p_tile_no, - OPJ_UINT32* p_tot_len, - OPJ_UINT32* p_current_part, - OPJ_UINT32* p_num_parts, - opj_event_mgr_t * p_manager); + OPJ_UINT32 *p_tile_no, + OPJ_UINT32 *p_tot_len, + OPJ_UINT32 *p_current_part, + OPJ_UINT32 *p_num_parts, + opj_event_mgr_t *p_manager); /** * Reads a SOT marker (Start of tile-part) * @@ -873,9 +873,9 @@ static OPJ_BOOL opj_j2k_get_sot_values(OPJ_BYTE * p_header_data, * @param p_manager the user event manager. */ static OPJ_BOOL opj_j2k_read_sot(opj_j2k_t *p_j2k, - OPJ_BYTE * p_header_data, + OPJ_BYTE *p_header_data, OPJ_UINT32 p_header_size, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Writes the SOD marker (Start of data) * @@ -890,12 +890,12 @@ static OPJ_BOOL opj_j2k_read_sot(opj_j2k_t *p_j2k, * @param p_manager the user event manager. */ static OPJ_BOOL opj_j2k_write_sod(opj_j2k_t *p_j2k, - opj_tcd_t * p_tile_coder, - OPJ_BYTE * p_data, - OPJ_UINT32 * p_data_written, + opj_tcd_t *p_tile_coder, + OPJ_BYTE *p_data, + OPJ_UINT32 *p_data_written, OPJ_UINT32 total_data_size, const opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Reads a SOD marker (Start Of Data) @@ -906,10 +906,9 @@ static OPJ_BOOL opj_j2k_write_sod(opj_j2k_t *p_j2k, */ static OPJ_BOOL opj_j2k_read_sod(opj_j2k_t *p_j2k, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); -static void opj_j2k_update_tlm(opj_j2k_t * p_j2k, OPJ_UINT32 p_tile_part_size) -{ +static void opj_j2k_update_tlm(opj_j2k_t *p_j2k, OPJ_UINT32 p_tile_part_size) { if (p_j2k->m_specific_param.m_encoder.m_Ttlmi_is_byte) { opj_write_bytes(p_j2k->m_specific_param.m_encoder.m_tlm_sot_offsets_current, p_j2k->m_current_tile_number, 1); @@ -940,7 +939,7 @@ static OPJ_BOOL opj_j2k_write_rgn(opj_j2k_t *p_j2k, OPJ_UINT32 p_comp_no, OPJ_UINT32 nb_comps, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Reads a RGN marker (Region Of Interest) @@ -951,9 +950,9 @@ static OPJ_BOOL opj_j2k_write_rgn(opj_j2k_t *p_j2k, * @param p_manager the user event manager. */ static OPJ_BOOL opj_j2k_read_rgn(opj_j2k_t *p_j2k, - OPJ_BYTE * p_header_data, + OPJ_BYTE *p_header_data, OPJ_UINT32 p_header_size, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Writes the EOC marker (End of Codestream) @@ -964,7 +963,7 @@ static OPJ_BOOL opj_j2k_read_rgn(opj_j2k_t *p_j2k, */ static OPJ_BOOL opj_j2k_write_eoc(opj_j2k_t *p_j2k, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); #if 0 /** @@ -976,7 +975,7 @@ static OPJ_BOOL opj_j2k_write_eoc(opj_j2k_t *p_j2k, */ static OPJ_BOOL opj_j2k_read_eoc(opj_j2k_t *p_j2k, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); #endif /** @@ -987,8 +986,8 @@ static OPJ_BOOL opj_j2k_read_eoc(opj_j2k_t *p_j2k, * @param p_manager the user event manager. */ static OPJ_BOOL opj_j2k_write_mct_data_group(opj_j2k_t *p_j2k, - opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager); + opj_stream_private_t *p_stream, + opj_event_mgr_t *p_manager); /** * Inits the Info @@ -999,7 +998,7 @@ static OPJ_BOOL opj_j2k_write_mct_data_group(opj_j2k_t *p_j2k, */ static OPJ_BOOL opj_j2k_init_info(opj_j2k_t *p_j2k, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** Add main header marker information @@ -1035,7 +1034,7 @@ static OPJ_BOOL opj_j2k_add_tlmarker(OPJ_UINT32 tileno, static OPJ_BOOL opj_j2k_read_unk(opj_j2k_t *p_j2k, opj_stream_private_t *p_stream, OPJ_UINT32 *output_marker, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Writes the MCT marker (Multiple Component Transform) @@ -1046,9 +1045,9 @@ static OPJ_BOOL opj_j2k_read_unk(opj_j2k_t *p_j2k, * @param p_manager the user event manager. */ static OPJ_BOOL opj_j2k_write_mct_record(opj_j2k_t *p_j2k, - opj_mct_data_t * p_mct_record, - opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager); + opj_mct_data_t *p_mct_record, + opj_stream_private_t *p_stream, + opj_event_mgr_t *p_manager); /** * Reads a MCT marker (Multiple Component Transform) @@ -1059,9 +1058,9 @@ static OPJ_BOOL opj_j2k_write_mct_record(opj_j2k_t *p_j2k, * @param p_manager the user event manager. */ static OPJ_BOOL opj_j2k_read_mct(opj_j2k_t *p_j2k, - OPJ_BYTE * p_header_data, + OPJ_BYTE *p_header_data, OPJ_UINT32 p_header_size, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Writes the MCC marker (Multiple Component Collection) @@ -1072,9 +1071,9 @@ static OPJ_BOOL opj_j2k_read_mct(opj_j2k_t *p_j2k, * @param p_manager the user event manager. */ static OPJ_BOOL opj_j2k_write_mcc_record(opj_j2k_t *p_j2k, - opj_simple_mcc_decorrelation_data_t * p_mcc_record, - opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager); + opj_simple_mcc_decorrelation_data_t *p_mcc_record, + opj_stream_private_t *p_stream, + opj_event_mgr_t *p_manager); /** * Reads a MCC marker (Multiple Component Collection) @@ -1085,9 +1084,9 @@ static OPJ_BOOL opj_j2k_write_mcc_record(opj_j2k_t *p_j2k, * @param p_manager the user event manager. */ static OPJ_BOOL opj_j2k_read_mcc(opj_j2k_t *p_j2k, - OPJ_BYTE * p_header_data, + OPJ_BYTE *p_header_data, OPJ_UINT32 p_header_size, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Writes the MCO marker (Multiple component transformation ordering) @@ -1098,7 +1097,7 @@ static OPJ_BOOL opj_j2k_read_mcc(opj_j2k_t *p_j2k, */ static OPJ_BOOL opj_j2k_write_mco(opj_j2k_t *p_j2k, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Reads a MCO marker (Multiple Component Transform Ordering) @@ -1109,39 +1108,39 @@ static OPJ_BOOL opj_j2k_write_mco(opj_j2k_t *p_j2k, * @param p_manager the user event manager. */ static OPJ_BOOL opj_j2k_read_mco(opj_j2k_t *p_j2k, - OPJ_BYTE * p_header_data, + OPJ_BYTE *p_header_data, OPJ_UINT32 p_header_size, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); -static OPJ_BOOL opj_j2k_add_mct(opj_tcp_t * p_tcp, opj_image_t * p_image, +static OPJ_BOOL opj_j2k_add_mct(opj_tcp_t *p_tcp, opj_image_t *p_image, OPJ_UINT32 p_index); -static void opj_j2k_read_int16_to_float(const void * p_src_data, - void * p_dest_data, OPJ_UINT32 p_nb_elem); -static void opj_j2k_read_int32_to_float(const void * p_src_data, - void * p_dest_data, OPJ_UINT32 p_nb_elem); -static void opj_j2k_read_float32_to_float(const void * p_src_data, - void * p_dest_data, OPJ_UINT32 p_nb_elem); -static void opj_j2k_read_float64_to_float(const void * p_src_data, - void * p_dest_data, OPJ_UINT32 p_nb_elem); +static void opj_j2k_read_int16_to_float(const void *p_src_data, + void *p_dest_data, OPJ_UINT32 p_nb_elem); +static void opj_j2k_read_int32_to_float(const void *p_src_data, + void *p_dest_data, OPJ_UINT32 p_nb_elem); +static void opj_j2k_read_float32_to_float(const void *p_src_data, + void *p_dest_data, OPJ_UINT32 p_nb_elem); +static void opj_j2k_read_float64_to_float(const void *p_src_data, + void *p_dest_data, OPJ_UINT32 p_nb_elem); -static void opj_j2k_read_int16_to_int32(const void * p_src_data, - void * p_dest_data, OPJ_UINT32 p_nb_elem); -static void opj_j2k_read_int32_to_int32(const void * p_src_data, - void * p_dest_data, OPJ_UINT32 p_nb_elem); -static void opj_j2k_read_float32_to_int32(const void * p_src_data, - void * p_dest_data, OPJ_UINT32 p_nb_elem); -static void opj_j2k_read_float64_to_int32(const void * p_src_data, - void * p_dest_data, OPJ_UINT32 p_nb_elem); +static void opj_j2k_read_int16_to_int32(const void *p_src_data, + void *p_dest_data, OPJ_UINT32 p_nb_elem); +static void opj_j2k_read_int32_to_int32(const void *p_src_data, + void *p_dest_data, OPJ_UINT32 p_nb_elem); +static void opj_j2k_read_float32_to_int32(const void *p_src_data, + void *p_dest_data, OPJ_UINT32 p_nb_elem); +static void opj_j2k_read_float64_to_int32(const void *p_src_data, + void *p_dest_data, OPJ_UINT32 p_nb_elem); -static void opj_j2k_write_float_to_int16(const void * p_src_data, - void * p_dest_data, OPJ_UINT32 p_nb_elem); -static void opj_j2k_write_float_to_int32(const void * p_src_data, - void * p_dest_data, OPJ_UINT32 p_nb_elem); -static void opj_j2k_write_float_to_float(const void * p_src_data, - void * p_dest_data, OPJ_UINT32 p_nb_elem); -static void opj_j2k_write_float_to_float64(const void * p_src_data, - void * p_dest_data, OPJ_UINT32 p_nb_elem); +static void opj_j2k_write_float_to_int16(const void *p_src_data, + void *p_dest_data, OPJ_UINT32 p_nb_elem); +static void opj_j2k_write_float_to_int32(const void *p_src_data, + void *p_dest_data, OPJ_UINT32 p_nb_elem); +static void opj_j2k_write_float_to_float(const void *p_src_data, + void *p_dest_data, OPJ_UINT32 p_nb_elem); +static void opj_j2k_write_float_to_float64(const void *p_src_data, + void *p_dest_data, OPJ_UINT32 p_nb_elem); /** * Ends the encoding, i.e. frees memory. @@ -1152,7 +1151,7 @@ static void opj_j2k_write_float_to_float64(const void * p_src_data, */ static OPJ_BOOL opj_j2k_end_encoding(opj_j2k_t *p_j2k, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Writes the CBD marker (Component bit depth definition) @@ -1163,7 +1162,7 @@ static OPJ_BOOL opj_j2k_end_encoding(opj_j2k_t *p_j2k, */ static OPJ_BOOL opj_j2k_write_cbd(opj_j2k_t *p_j2k, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Reads a CBD marker (Component bit depth definition) @@ -1173,9 +1172,9 @@ static OPJ_BOOL opj_j2k_write_cbd(opj_j2k_t *p_j2k, * @param p_manager the user event manager. */ static OPJ_BOOL opj_j2k_read_cbd(opj_j2k_t *p_j2k, - OPJ_BYTE * p_header_data, + OPJ_BYTE *p_header_data, OPJ_UINT32 p_header_size, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Reads a CAP marker (extended capabilities definition). Empty implementation. @@ -1187,9 +1186,9 @@ static OPJ_BOOL opj_j2k_read_cbd(opj_j2k_t *p_j2k, * @param p_manager the user event manager. */ static OPJ_BOOL opj_j2k_read_cap(opj_j2k_t *p_j2k, - OPJ_BYTE * p_header_data, + OPJ_BYTE *p_header_data, OPJ_UINT32 p_header_size, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Reads a CPF marker (corresponding profile). Empty implementation. Found in HTJ2K files @@ -1199,9 +1198,9 @@ static OPJ_BOOL opj_j2k_read_cap(opj_j2k_t *p_j2k, * @param p_manager the user event manager. */ static OPJ_BOOL opj_j2k_read_cpf(opj_j2k_t *p_j2k, - OPJ_BYTE * p_header_data, + OPJ_BYTE *p_header_data, OPJ_UINT32 p_header_size, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** @@ -1213,7 +1212,7 @@ static OPJ_BOOL opj_j2k_read_cpf(opj_j2k_t *p_j2k, */ static OPJ_BOOL opj_j2k_write_all_coc(opj_j2k_t *p_j2k, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Writes QCC marker for each component. @@ -1224,7 +1223,7 @@ static OPJ_BOOL opj_j2k_write_all_coc(opj_j2k_t *p_j2k, */ static OPJ_BOOL opj_j2k_write_all_qcc(opj_j2k_t *p_j2k, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Writes regions of interests. @@ -1235,7 +1234,7 @@ static OPJ_BOOL opj_j2k_write_all_qcc(opj_j2k_t *p_j2k, */ static OPJ_BOOL opj_j2k_write_regions(opj_j2k_t *p_j2k, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Writes EPC ???? @@ -1246,7 +1245,7 @@ static OPJ_BOOL opj_j2k_write_regions(opj_j2k_t *p_j2k, */ static OPJ_BOOL opj_j2k_write_epc(opj_j2k_t *p_j2k, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Checks the progression order changes values. Tells of the poc given as input are valid. @@ -1268,7 +1267,7 @@ static OPJ_BOOL opj_j2k_check_poc_val(const opj_poc_t *p_pocs, OPJ_UINT32 p_nb_resolutions, OPJ_UINT32 numcomps, OPJ_UINT32 numlayers, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Gets the number of tile parts used for the given change of progression (if any) and the given tile. @@ -1296,34 +1295,34 @@ static OPJ_UINT32 opj_j2k_get_num_tp(opj_cp_t *cp, OPJ_UINT32 pino, */ static OPJ_BOOL opj_j2k_calculate_tp(opj_j2k_t *p_j2k, opj_cp_t *cp, - OPJ_UINT32 * p_nb_tiles, + OPJ_UINT32 *p_nb_tiles, opj_image_t *image, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); -static void opj_j2k_dump_MH_info(opj_j2k_t* p_j2k, FILE* out_stream); +static void opj_j2k_dump_MH_info(opj_j2k_t *p_j2k, FILE *out_stream); -static void opj_j2k_dump_MH_index(opj_j2k_t* p_j2k, FILE* out_stream); +static void opj_j2k_dump_MH_index(opj_j2k_t *p_j2k, FILE *out_stream); -static opj_codestream_index_t* opj_j2k_create_cstr_index(void); +static opj_codestream_index_t *opj_j2k_create_cstr_index(void); -static OPJ_FLOAT32 opj_j2k_get_tp_stride(opj_tcp_t * p_tcp); +static OPJ_FLOAT32 opj_j2k_get_tp_stride(opj_tcp_t *p_tcp); -static OPJ_FLOAT32 opj_j2k_get_default_stride(opj_tcp_t * p_tcp); +static OPJ_FLOAT32 opj_j2k_get_default_stride(opj_tcp_t *p_tcp); static int opj_j2k_initialise_4K_poc(opj_poc_t *POC, int numres); static void opj_j2k_set_cinema_parameters(opj_cparameters_t *parameters, - opj_image_t *image, opj_event_mgr_t *p_manager); + opj_image_t *image, opj_event_mgr_t *p_manager); static OPJ_BOOL opj_j2k_is_cinema_compliant(opj_image_t *image, OPJ_UINT16 rsiz, - opj_event_mgr_t *p_manager); + opj_event_mgr_t *p_manager); static void opj_j2k_set_imf_parameters(opj_cparameters_t *parameters, opj_image_t *image, opj_event_mgr_t *p_manager); static OPJ_BOOL opj_j2k_is_imf_compliant(opj_cparameters_t *parameters, - opj_image_t *image, - opj_event_mgr_t *p_manager); + opj_image_t *image, + opj_event_mgr_t *p_manager); /** * Checks for invalid number of tile-parts in SOT marker (TPsot==TNsot). See issue 254. @@ -1336,8 +1335,8 @@ static OPJ_BOOL opj_j2k_is_imf_compliant(opj_cparameters_t *parameters, * @return true if the function was successful, false else. */ static OPJ_BOOL opj_j2k_need_nb_tile_parts_correction(opj_stream_private_t - *p_stream, OPJ_UINT32 tile_no, OPJ_BOOL* p_correction_needed, - opj_event_mgr_t * p_manager); + *p_stream, OPJ_UINT32 tile_no, OPJ_BOOL *p_correction_needed, + opj_event_mgr_t *p_manager); /*@}*/ @@ -1368,8 +1367,8 @@ static const OPJ_UINT32 MCT_ELEMENT_SIZE [] = { 8 }; -typedef void (* opj_j2k_mct_function)(const void * p_src_data, - void * p_dest_data, OPJ_UINT32 p_nb_elem); +typedef void (* opj_j2k_mct_function)(const void *p_src_data, + void *p_dest_data, OPJ_UINT32 p_nb_elem); static const opj_j2k_mct_function j2k_mct_read_functions_to_float [] = { opj_j2k_read_int16_to_float, @@ -1399,14 +1398,13 @@ typedef struct opj_dec_memory_marker_handler { OPJ_UINT32 states; /** action linked to the marker */ OPJ_BOOL(*handler)(opj_j2k_t *p_j2k, - OPJ_BYTE * p_header_data, + OPJ_BYTE *p_header_data, OPJ_UINT32 p_header_size, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); } opj_dec_memory_marker_handler_t; -static const opj_dec_memory_marker_handler_t j2k_memory_marker_handler_tab [] = -{ +static const opj_dec_memory_marker_handler_t j2k_memory_marker_handler_tab [] = { {J2K_MS_SOT, J2K_STATE_MH | J2K_STATE_TPHSOT, opj_j2k_read_sot}, {J2K_MS_COD, J2K_STATE_MH | J2K_STATE_TPH, opj_j2k_read_cod}, {J2K_MS_COC, J2K_STATE_MH | J2K_STATE_TPH, opj_j2k_read_coc}, @@ -1444,11 +1442,10 @@ static const opj_dec_memory_marker_handler_t j2k_memory_marker_handler_tab [] = {J2K_MS_UNK, J2K_STATE_MH | J2K_STATE_TPH, 0}/*opj_j2k_read_unk is directly used*/ }; -static void opj_j2k_read_int16_to_float(const void * p_src_data, - void * p_dest_data, OPJ_UINT32 p_nb_elem) -{ - OPJ_BYTE * l_src_data = (OPJ_BYTE *) p_src_data; - OPJ_FLOAT32 * l_dest_data = (OPJ_FLOAT32 *) p_dest_data; +static void opj_j2k_read_int16_to_float(const void *p_src_data, + void *p_dest_data, OPJ_UINT32 p_nb_elem) { + OPJ_BYTE *l_src_data = (OPJ_BYTE *) p_src_data; + OPJ_FLOAT32 *l_dest_data = (OPJ_FLOAT32 *) p_dest_data; OPJ_UINT32 i; OPJ_UINT32 l_temp; @@ -1461,11 +1458,10 @@ static void opj_j2k_read_int16_to_float(const void * p_src_data, } } -static void opj_j2k_read_int32_to_float(const void * p_src_data, - void * p_dest_data, OPJ_UINT32 p_nb_elem) -{ - OPJ_BYTE * l_src_data = (OPJ_BYTE *) p_src_data; - OPJ_FLOAT32 * l_dest_data = (OPJ_FLOAT32 *) p_dest_data; +static void opj_j2k_read_int32_to_float(const void *p_src_data, + void *p_dest_data, OPJ_UINT32 p_nb_elem) { + OPJ_BYTE *l_src_data = (OPJ_BYTE *) p_src_data; + OPJ_FLOAT32 *l_dest_data = (OPJ_FLOAT32 *) p_dest_data; OPJ_UINT32 i; OPJ_UINT32 l_temp; @@ -1478,11 +1474,10 @@ static void opj_j2k_read_int32_to_float(const void * p_src_data, } } -static void opj_j2k_read_float32_to_float(const void * p_src_data, - void * p_dest_data, OPJ_UINT32 p_nb_elem) -{ - OPJ_BYTE * l_src_data = (OPJ_BYTE *) p_src_data; - OPJ_FLOAT32 * l_dest_data = (OPJ_FLOAT32 *) p_dest_data; +static void opj_j2k_read_float32_to_float(const void *p_src_data, + void *p_dest_data, OPJ_UINT32 p_nb_elem) { + OPJ_BYTE *l_src_data = (OPJ_BYTE *) p_src_data; + OPJ_FLOAT32 *l_dest_data = (OPJ_FLOAT32 *) p_dest_data; OPJ_UINT32 i; OPJ_FLOAT32 l_temp; @@ -1495,11 +1490,10 @@ static void opj_j2k_read_float32_to_float(const void * p_src_data, } } -static void opj_j2k_read_float64_to_float(const void * p_src_data, - void * p_dest_data, OPJ_UINT32 p_nb_elem) -{ - OPJ_BYTE * l_src_data = (OPJ_BYTE *) p_src_data; - OPJ_FLOAT32 * l_dest_data = (OPJ_FLOAT32 *) p_dest_data; +static void opj_j2k_read_float64_to_float(const void *p_src_data, + void *p_dest_data, OPJ_UINT32 p_nb_elem) { + OPJ_BYTE *l_src_data = (OPJ_BYTE *) p_src_data; + OPJ_FLOAT32 *l_dest_data = (OPJ_FLOAT32 *) p_dest_data; OPJ_UINT32 i; OPJ_FLOAT64 l_temp; @@ -1512,11 +1506,10 @@ static void opj_j2k_read_float64_to_float(const void * p_src_data, } } -static void opj_j2k_read_int16_to_int32(const void * p_src_data, - void * p_dest_data, OPJ_UINT32 p_nb_elem) -{ - OPJ_BYTE * l_src_data = (OPJ_BYTE *) p_src_data; - OPJ_INT32 * l_dest_data = (OPJ_INT32 *) p_dest_data; +static void opj_j2k_read_int16_to_int32(const void *p_src_data, + void *p_dest_data, OPJ_UINT32 p_nb_elem) { + OPJ_BYTE *l_src_data = (OPJ_BYTE *) p_src_data; + OPJ_INT32 *l_dest_data = (OPJ_INT32 *) p_dest_data; OPJ_UINT32 i; OPJ_UINT32 l_temp; @@ -1529,11 +1522,10 @@ static void opj_j2k_read_int16_to_int32(const void * p_src_data, } } -static void opj_j2k_read_int32_to_int32(const void * p_src_data, - void * p_dest_data, OPJ_UINT32 p_nb_elem) -{ - OPJ_BYTE * l_src_data = (OPJ_BYTE *) p_src_data; - OPJ_INT32 * l_dest_data = (OPJ_INT32 *) p_dest_data; +static void opj_j2k_read_int32_to_int32(const void *p_src_data, + void *p_dest_data, OPJ_UINT32 p_nb_elem) { + OPJ_BYTE *l_src_data = (OPJ_BYTE *) p_src_data; + OPJ_INT32 *l_dest_data = (OPJ_INT32 *) p_dest_data; OPJ_UINT32 i; OPJ_UINT32 l_temp; @@ -1546,11 +1538,10 @@ static void opj_j2k_read_int32_to_int32(const void * p_src_data, } } -static void opj_j2k_read_float32_to_int32(const void * p_src_data, - void * p_dest_data, OPJ_UINT32 p_nb_elem) -{ - OPJ_BYTE * l_src_data = (OPJ_BYTE *) p_src_data; - OPJ_INT32 * l_dest_data = (OPJ_INT32 *) p_dest_data; +static void opj_j2k_read_float32_to_int32(const void *p_src_data, + void *p_dest_data, OPJ_UINT32 p_nb_elem) { + OPJ_BYTE *l_src_data = (OPJ_BYTE *) p_src_data; + OPJ_INT32 *l_dest_data = (OPJ_INT32 *) p_dest_data; OPJ_UINT32 i; OPJ_FLOAT32 l_temp; @@ -1563,11 +1554,10 @@ static void opj_j2k_read_float32_to_int32(const void * p_src_data, } } -static void opj_j2k_read_float64_to_int32(const void * p_src_data, - void * p_dest_data, OPJ_UINT32 p_nb_elem) -{ - OPJ_BYTE * l_src_data = (OPJ_BYTE *) p_src_data; - OPJ_INT32 * l_dest_data = (OPJ_INT32 *) p_dest_data; +static void opj_j2k_read_float64_to_int32(const void *p_src_data, + void *p_dest_data, OPJ_UINT32 p_nb_elem) { + OPJ_BYTE *l_src_data = (OPJ_BYTE *) p_src_data; + OPJ_INT32 *l_dest_data = (OPJ_INT32 *) p_dest_data; OPJ_UINT32 i; OPJ_FLOAT64 l_temp; @@ -1580,11 +1570,10 @@ static void opj_j2k_read_float64_to_int32(const void * p_src_data, } } -static void opj_j2k_write_float_to_int16(const void * p_src_data, - void * p_dest_data, OPJ_UINT32 p_nb_elem) -{ - OPJ_BYTE * l_dest_data = (OPJ_BYTE *) p_dest_data; - OPJ_FLOAT32 * l_src_data = (OPJ_FLOAT32 *) p_src_data; +static void opj_j2k_write_float_to_int16(const void *p_src_data, + void *p_dest_data, OPJ_UINT32 p_nb_elem) { + OPJ_BYTE *l_dest_data = (OPJ_BYTE *) p_dest_data; + OPJ_FLOAT32 *l_src_data = (OPJ_FLOAT32 *) p_src_data; OPJ_UINT32 i; OPJ_UINT32 l_temp; @@ -1597,11 +1586,10 @@ static void opj_j2k_write_float_to_int16(const void * p_src_data, } } -static void opj_j2k_write_float_to_int32(const void * p_src_data, - void * p_dest_data, OPJ_UINT32 p_nb_elem) -{ - OPJ_BYTE * l_dest_data = (OPJ_BYTE *) p_dest_data; - OPJ_FLOAT32 * l_src_data = (OPJ_FLOAT32 *) p_src_data; +static void opj_j2k_write_float_to_int32(const void *p_src_data, + void *p_dest_data, OPJ_UINT32 p_nb_elem) { + OPJ_BYTE *l_dest_data = (OPJ_BYTE *) p_dest_data; + OPJ_FLOAT32 *l_src_data = (OPJ_FLOAT32 *) p_src_data; OPJ_UINT32 i; OPJ_UINT32 l_temp; @@ -1614,11 +1602,10 @@ static void opj_j2k_write_float_to_int32(const void * p_src_data, } } -static void opj_j2k_write_float_to_float(const void * p_src_data, - void * p_dest_data, OPJ_UINT32 p_nb_elem) -{ - OPJ_BYTE * l_dest_data = (OPJ_BYTE *) p_dest_data; - OPJ_FLOAT32 * l_src_data = (OPJ_FLOAT32 *) p_src_data; +static void opj_j2k_write_float_to_float(const void *p_src_data, + void *p_dest_data, OPJ_UINT32 p_nb_elem) { + OPJ_BYTE *l_dest_data = (OPJ_BYTE *) p_dest_data; + OPJ_FLOAT32 *l_src_data = (OPJ_FLOAT32 *) p_src_data; OPJ_UINT32 i; OPJ_FLOAT32 l_temp; @@ -1631,11 +1618,10 @@ static void opj_j2k_write_float_to_float(const void * p_src_data, } } -static void opj_j2k_write_float_to_float64(const void * p_src_data, - void * p_dest_data, OPJ_UINT32 p_nb_elem) -{ - OPJ_BYTE * l_dest_data = (OPJ_BYTE *) p_dest_data; - OPJ_FLOAT32 * l_src_data = (OPJ_FLOAT32 *) p_src_data; +static void opj_j2k_write_float_to_float64(const void *p_src_data, + void *p_dest_data, OPJ_UINT32 p_nb_elem) { + OPJ_BYTE *l_dest_data = (OPJ_BYTE *) p_dest_data; + OPJ_FLOAT32 *l_src_data = (OPJ_FLOAT32 *) p_src_data; OPJ_UINT32 i; OPJ_FLOAT64 l_temp; @@ -1648,8 +1634,7 @@ static void opj_j2k_write_float_to_float64(const void * p_src_data, } } -const char *opj_j2k_convert_progression_order(OPJ_PROG_ORDER prg_order) -{ +const char *opj_j2k_convert_progression_order(OPJ_PROG_ORDER prg_order) { const j2k_prog_order_t *po; for (po = j2k_prog_order_list; po->enum_prog != -1; po++) { if (po->enum_prog == prg_order) { @@ -1665,9 +1650,8 @@ static OPJ_BOOL opj_j2k_check_poc_val(const opj_poc_t *p_pocs, OPJ_UINT32 p_nb_resolutions, OPJ_UINT32 p_num_comps, OPJ_UINT32 p_num_layers, - opj_event_mgr_t * p_manager) -{ - OPJ_UINT32* packet_array; + opj_event_mgr_t *p_manager) { + OPJ_UINT32 *packet_array; OPJ_UINT32 index, resno, compno, layno; OPJ_UINT32 i; OPJ_UINT32 step_c = 1; @@ -1677,8 +1661,8 @@ static OPJ_BOOL opj_j2k_check_poc_val(const opj_poc_t *p_pocs, assert(p_nb_pocs > 0); - packet_array = (OPJ_UINT32*) opj_calloc((size_t)step_l * p_num_layers, - sizeof(OPJ_UINT32)); + packet_array = (OPJ_UINT32 *) opj_calloc((size_t)step_l * p_num_layers, + sizeof(OPJ_UINT32)); if (packet_array == 00) { opj_event_msg(p_manager, EVT_ERROR, "Not enough memory for checking the poc values.\n"); @@ -1747,13 +1731,12 @@ static OPJ_BOOL opj_j2k_check_poc_val(const opj_poc_t *p_pocs, /* ----------------------------------------------------------------------- */ static OPJ_UINT32 opj_j2k_get_num_tp(opj_cp_t *cp, OPJ_UINT32 pino, - OPJ_UINT32 tileno) -{ + OPJ_UINT32 tileno) { const OPJ_CHAR *prog = 00; OPJ_INT32 i; OPJ_UINT32 tpnum = 1; opj_tcp_t *tcp = 00; - opj_poc_t * l_current_poc = 00; + opj_poc_t *l_current_poc = 00; /* preconditions */ assert(tileno < (cp->tw * cp->th)); @@ -1773,22 +1756,22 @@ static OPJ_UINT32 opj_j2k_get_num_tp(opj_cp_t *cp, OPJ_UINT32 pino, if (cp->m_specific_param.m_enc.m_tp_on == 1) { for (i = 0; i < 4; ++i) { switch (prog[i]) { - /* component wise */ - case 'C': - tpnum *= l_current_poc->compE; - break; - /* resolution wise */ - case 'R': - tpnum *= l_current_poc->resE; - break; - /* precinct wise */ - case 'P': - tpnum *= l_current_poc->prcE; - break; - /* layer wise */ - case 'L': - tpnum *= l_current_poc->layE; - break; + /* component wise */ + case 'C': + tpnum *= l_current_poc->compE; + break; + /* resolution wise */ + case 'R': + tpnum *= l_current_poc->resE; + break; + /* precinct wise */ + case 'P': + tpnum *= l_current_poc->prcE; + break; + /* layer wise */ + case 'L': + tpnum *= l_current_poc->layE; + break; } /* would we split here ? */ if (cp->m_specific_param.m_enc.m_tp_flag == prog[i]) { @@ -1805,11 +1788,10 @@ static OPJ_UINT32 opj_j2k_get_num_tp(opj_cp_t *cp, OPJ_UINT32 pino, static OPJ_BOOL opj_j2k_calculate_tp(opj_j2k_t *p_j2k, opj_cp_t *cp, - OPJ_UINT32 * p_nb_tiles, + OPJ_UINT32 *p_nb_tiles, opj_image_t *image, - opj_event_mgr_t * p_manager - ) -{ + opj_event_mgr_t *p_manager + ) { OPJ_UINT32 pino, tileno; OPJ_UINT32 l_nb_tiles; opj_tcp_t *tcp; @@ -1886,10 +1868,9 @@ static OPJ_BOOL opj_j2k_calculate_tp(opj_j2k_t *p_j2k, static OPJ_BOOL opj_j2k_write_soc(opj_j2k_t *p_j2k, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager) -{ + opj_event_mgr_t *p_manager) { /* 2 bytes will be written */ - OPJ_BYTE * l_start_stream = 00; + OPJ_BYTE *l_start_stream = 00; /* preconditions */ assert(p_stream != 00); @@ -1926,9 +1907,8 @@ static OPJ_BOOL opj_j2k_write_soc(opj_j2k_t *p_j2k, */ static OPJ_BOOL opj_j2k_read_soc(opj_j2k_t *p_j2k, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager - ) -{ + opj_event_mgr_t *p_manager + ) { OPJ_BYTE l_data [2]; OPJ_UINT32 l_marker; @@ -1967,14 +1947,13 @@ static OPJ_BOOL opj_j2k_read_soc(opj_j2k_t *p_j2k, static OPJ_BOOL opj_j2k_write_siz(opj_j2k_t *p_j2k, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager) -{ + opj_event_mgr_t *p_manager) { OPJ_UINT32 i; OPJ_UINT32 l_size_len; - OPJ_BYTE * l_current_ptr; - opj_image_t * l_image = 00; + OPJ_BYTE *l_current_ptr; + opj_image_t *l_image = 00; opj_cp_t *cp = 00; - opj_image_comp_t * l_img_comp = 00; + opj_image_comp_t *l_img_comp = 00; /* preconditions */ assert(p_stream != 00); @@ -2072,11 +2051,10 @@ static OPJ_BOOL opj_j2k_write_siz(opj_j2k_t *p_j2k, * @param p_manager the user event manager. */ static OPJ_BOOL opj_j2k_read_siz(opj_j2k_t *p_j2k, - OPJ_BYTE * p_header_data, + OPJ_BYTE *p_header_data, OPJ_UINT32 p_header_size, - opj_event_mgr_t * p_manager - ) -{ + opj_event_mgr_t *p_manager + ) { OPJ_UINT32 i; OPJ_UINT32 l_nb_comp; OPJ_UINT32 l_nb_comp_remain; @@ -2086,8 +2064,8 @@ static OPJ_BOOL opj_j2k_read_siz(opj_j2k_t *p_j2k, OPJ_UINT32 l_prec0, l_sgnd0; opj_image_t *l_image = 00; opj_cp_t *l_cp = 00; - opj_image_comp_t * l_img_comp = 00; - opj_tcp_t * l_current_tile_param = 00; + opj_image_comp_t *l_img_comp = 00; + opj_tcp_t *l_current_tile_param = 00; /* preconditions */ assert(p_j2k != 00); @@ -2115,27 +2093,27 @@ static OPJ_BOOL opj_j2k_read_siz(opj_j2k_t *p_j2k, 2); /* Rsiz (capabilities) */ p_header_data += 2; l_cp->rsiz = (OPJ_UINT16) l_tmp; - opj_read_bytes(p_header_data, (OPJ_UINT32*) &l_image->x1, 4); /* Xsiz */ + opj_read_bytes(p_header_data, (OPJ_UINT32 *) &l_image->x1, 4); /* Xsiz */ p_header_data += 4; - opj_read_bytes(p_header_data, (OPJ_UINT32*) &l_image->y1, 4); /* Ysiz */ + opj_read_bytes(p_header_data, (OPJ_UINT32 *) &l_image->y1, 4); /* Ysiz */ p_header_data += 4; - opj_read_bytes(p_header_data, (OPJ_UINT32*) &l_image->x0, 4); /* X0siz */ + opj_read_bytes(p_header_data, (OPJ_UINT32 *) &l_image->x0, 4); /* X0siz */ p_header_data += 4; - opj_read_bytes(p_header_data, (OPJ_UINT32*) &l_image->y0, 4); /* Y0siz */ + opj_read_bytes(p_header_data, (OPJ_UINT32 *) &l_image->y0, 4); /* Y0siz */ p_header_data += 4; - opj_read_bytes(p_header_data, (OPJ_UINT32*) &l_cp->tdx, + opj_read_bytes(p_header_data, (OPJ_UINT32 *) &l_cp->tdx, 4); /* XTsiz */ p_header_data += 4; - opj_read_bytes(p_header_data, (OPJ_UINT32*) &l_cp->tdy, + opj_read_bytes(p_header_data, (OPJ_UINT32 *) &l_cp->tdy, 4); /* YTsiz */ p_header_data += 4; - opj_read_bytes(p_header_data, (OPJ_UINT32*) &l_cp->tx0, + opj_read_bytes(p_header_data, (OPJ_UINT32 *) &l_cp->tx0, 4); /* XT0siz */ p_header_data += 4; - opj_read_bytes(p_header_data, (OPJ_UINT32*) &l_cp->ty0, + opj_read_bytes(p_header_data, (OPJ_UINT32 *) &l_cp->ty0, 4); /* YT0siz */ p_header_data += 4; - opj_read_bytes(p_header_data, (OPJ_UINT32*) &l_tmp, + opj_read_bytes(p_header_data, (OPJ_UINT32 *) &l_tmp, 2); /* Csiz */ p_header_data += 2; if (l_tmp < 16385) { @@ -2236,8 +2214,8 @@ static OPJ_BOOL opj_j2k_read_siz(opj_j2k_t *p_j2k, #endif /* USE_JPWL */ /* Allocate the resulting image components */ - l_image->comps = (opj_image_comp_t*) opj_calloc(l_image->numcomps, - sizeof(opj_image_comp_t)); + l_image->comps = (opj_image_comp_t *) opj_calloc(l_image->numcomps, + sizeof(opj_image_comp_t)); if (l_image->comps == 00) { l_image->numcomps = 0; opj_event_msg(p_manager, EVT_ERROR, @@ -2352,11 +2330,11 @@ static OPJ_BOOL opj_j2k_read_siz(opj_j2k_t *p_j2k, p_j2k->m_specific_param.m_decoder.m_start_tile_y = (p_j2k->m_specific_param.m_decoder.m_start_tile_y - l_cp->ty0) / l_cp->tdy; p_j2k->m_specific_param.m_decoder.m_end_tile_x = opj_uint_ceildiv( - p_j2k->m_specific_param.m_decoder.m_end_tile_x - l_cp->tx0, - l_cp->tdx); + p_j2k->m_specific_param.m_decoder.m_end_tile_x - l_cp->tx0, + l_cp->tdx); p_j2k->m_specific_param.m_decoder.m_end_tile_y = opj_uint_ceildiv( - p_j2k->m_specific_param.m_decoder.m_end_tile_y - l_cp->ty0, - l_cp->tdy); + p_j2k->m_specific_param.m_decoder.m_end_tile_y - l_cp->ty0, + l_cp->tdy); } else { p_j2k->m_specific_param.m_decoder.m_start_tile_x = 0; p_j2k->m_specific_param.m_decoder.m_start_tile_y = 0; @@ -2410,7 +2388,7 @@ static OPJ_BOOL opj_j2k_read_siz(opj_j2k_t *p_j2k, #endif /* USE_JPWL */ /* memory allocations */ - l_cp->tcps = (opj_tcp_t*) opj_calloc(l_nb_tiles, sizeof(opj_tcp_t)); + l_cp->tcps = (opj_tcp_t *) opj_calloc(l_nb_tiles, sizeof(opj_tcp_t)); if (l_cp->tcps == 00) { opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to take in charge SIZ marker\n"); @@ -2431,7 +2409,7 @@ static OPJ_BOOL opj_j2k_read_siz(opj_j2k_t *p_j2k, #endif /* USE_JPWL */ p_j2k->m_specific_param.m_decoder.m_default_tcp->tccps = - (opj_tccp_t*) opj_calloc(l_image->numcomps, sizeof(opj_tccp_t)); + (opj_tccp_t *) opj_calloc(l_image->numcomps, sizeof(opj_tccp_t)); if (p_j2k->m_specific_param.m_decoder.m_default_tcp->tccps == 00) { opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to take in charge SIZ marker\n"); @@ -2439,8 +2417,8 @@ static OPJ_BOOL opj_j2k_read_siz(opj_j2k_t *p_j2k, } p_j2k->m_specific_param.m_decoder.m_default_tcp->m_mct_records = - (opj_mct_data_t*)opj_calloc(OPJ_J2K_MCT_DEFAULT_NB_RECORDS, - sizeof(opj_mct_data_t)); + (opj_mct_data_t *)opj_calloc(OPJ_J2K_MCT_DEFAULT_NB_RECORDS, + sizeof(opj_mct_data_t)); if (! p_j2k->m_specific_param.m_decoder.m_default_tcp->m_mct_records) { opj_event_msg(p_manager, EVT_ERROR, @@ -2451,7 +2429,7 @@ static OPJ_BOOL opj_j2k_read_siz(opj_j2k_t *p_j2k, OPJ_J2K_MCT_DEFAULT_NB_RECORDS; p_j2k->m_specific_param.m_decoder.m_default_tcp->m_mcc_records = - (opj_simple_mcc_decorrelation_data_t*) + (opj_simple_mcc_decorrelation_data_t *) opj_calloc(OPJ_J2K_MCC_DEFAULT_NB_RECORDS, sizeof(opj_simple_mcc_decorrelation_data_t)); @@ -2473,8 +2451,8 @@ static OPJ_BOOL opj_j2k_read_siz(opj_j2k_t *p_j2k, l_current_tile_param = l_cp->tcps; for (i = 0; i < l_nb_tiles; ++i) { - l_current_tile_param->tccps = (opj_tccp_t*) opj_calloc(l_image->numcomps, - sizeof(opj_tccp_t)); + l_current_tile_param->tccps = (opj_tccp_t *) opj_calloc(l_image->numcomps, + sizeof(opj_tccp_t)); if (l_current_tile_param->tccps == 00) { opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to take in charge SIZ marker\n"); @@ -2497,13 +2475,12 @@ static OPJ_BOOL opj_j2k_read_siz(opj_j2k_t *p_j2k, static OPJ_BOOL opj_j2k_write_com(opj_j2k_t *p_j2k, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager - ) -{ + opj_event_mgr_t *p_manager + ) { OPJ_UINT32 l_comment_size; OPJ_UINT32 l_total_com_size; const OPJ_CHAR *l_comment; - OPJ_BYTE * l_current_ptr = 00; + OPJ_BYTE *l_current_ptr = 00; /* preconditions */ assert(p_j2k != 00); @@ -2561,11 +2538,10 @@ static OPJ_BOOL opj_j2k_write_com(opj_j2k_t *p_j2k, * @param p_manager the user event manager. */ static OPJ_BOOL opj_j2k_read_com(opj_j2k_t *p_j2k, - OPJ_BYTE * p_header_data, + OPJ_BYTE *p_header_data, OPJ_UINT32 p_header_size, - opj_event_mgr_t * p_manager - ) -{ + opj_event_mgr_t *p_manager + ) { /* preconditions */ assert(p_j2k != 00); assert(p_manager != 00); @@ -2581,12 +2557,11 @@ static OPJ_BOOL opj_j2k_read_com(opj_j2k_t *p_j2k, static OPJ_BOOL opj_j2k_write_cod(opj_j2k_t *p_j2k, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager) -{ + opj_event_mgr_t *p_manager) { opj_cp_t *l_cp = 00; opj_tcp_t *l_tcp = 00; OPJ_UINT32 l_code_size, l_remaining_size; - OPJ_BYTE * l_current_data = 00; + OPJ_BYTE *l_current_data = 00; /* preconditions */ assert(p_j2k != 00); @@ -2596,7 +2571,7 @@ static OPJ_BOOL opj_j2k_write_cod(opj_j2k_t *p_j2k, l_cp = &(p_j2k->m_cp); l_tcp = &l_cp->tcps[p_j2k->m_current_tile_number]; l_code_size = 9 + opj_j2k_get_SPCod_SPCoc_size(p_j2k, - p_j2k->m_current_tile_number, 0); + p_j2k->m_current_tile_number, 0); l_remaining_size = l_code_size; if (l_code_size > p_j2k->m_specific_param.m_encoder.m_header_tile_data_size) { @@ -2663,11 +2638,10 @@ static OPJ_BOOL opj_j2k_write_cod(opj_j2k_t *p_j2k, * @param p_manager the user event manager. */ static OPJ_BOOL opj_j2k_read_cod(opj_j2k_t *p_j2k, - OPJ_BYTE * p_header_data, + OPJ_BYTE *p_header_data, OPJ_UINT32 p_header_size, - opj_event_mgr_t * p_manager - ) -{ + opj_event_mgr_t *p_manager + ) { /* loop */ OPJ_UINT32 i; OPJ_UINT32 l_tmp; @@ -2775,7 +2749,7 @@ static OPJ_BOOL opj_j2k_read_cod(opj_j2k_t *p_j2k, /*opj_codestream_info_t *l_cstr_info = p_j2k->cstr_info;*/ p_j2k->cstr_info->prog = l_tcp->prg; p_j2k->cstr_info->numlayers = l_tcp->numlayers; - p_j2k->cstr_info->numdecompos = (OPJ_INT32*) opj_malloc( + p_j2k->cstr_info->numdecompos = (OPJ_INT32 *) opj_malloc( l_image->numcomps * sizeof(OPJ_UINT32)); if (!p_j2k->cstr_info->numdecompos) { return OPJ_FALSE; @@ -2792,8 +2766,7 @@ static OPJ_BOOL opj_j2k_read_cod(opj_j2k_t *p_j2k, static OPJ_BOOL opj_j2k_write_coc(opj_j2k_t *p_j2k, OPJ_UINT32 p_comp_no, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager) -{ + opj_event_mgr_t *p_manager) { OPJ_UINT32 l_coc_size, l_remaining_size; OPJ_UINT32 l_comp_room; @@ -2805,7 +2778,7 @@ static OPJ_BOOL opj_j2k_write_coc(opj_j2k_t *p_j2k, l_comp_room = (p_j2k->m_private_image->numcomps <= 256) ? 1 : 2; l_coc_size = 5 + l_comp_room + opj_j2k_get_SPCod_SPCoc_size(p_j2k, - p_j2k->m_current_tile_number, p_comp_no); + p_j2k->m_current_tile_number, p_comp_no); if (l_coc_size > p_j2k->m_specific_param.m_encoder.m_header_tile_data_size) { OPJ_BYTE *new_header_tile_data; @@ -2841,8 +2814,7 @@ static OPJ_BOOL opj_j2k_write_coc(opj_j2k_t *p_j2k, } static OPJ_BOOL opj_j2k_compare_coc(opj_j2k_t *p_j2k, - OPJ_UINT32 p_first_comp_no, OPJ_UINT32 p_second_comp_no) -{ + OPJ_UINT32 p_first_comp_no, OPJ_UINT32 p_second_comp_no) { opj_cp_t *l_cp = NULL; opj_tcp_t *l_tcp = NULL; @@ -2863,15 +2835,14 @@ static OPJ_BOOL opj_j2k_compare_coc(opj_j2k_t *p_j2k, static void opj_j2k_write_coc_in_memory(opj_j2k_t *p_j2k, OPJ_UINT32 p_comp_no, - OPJ_BYTE * p_data, - OPJ_UINT32 * p_data_written, - opj_event_mgr_t * p_manager - ) -{ + OPJ_BYTE *p_data, + OPJ_UINT32 *p_data_written, + opj_event_mgr_t *p_manager + ) { opj_cp_t *l_cp = 00; opj_tcp_t *l_tcp = 00; OPJ_UINT32 l_coc_size, l_remaining_size; - OPJ_BYTE * l_current_data = 00; + OPJ_BYTE *l_current_data = 00; opj_image_t *l_image = 00; OPJ_UINT32 l_comp_room; @@ -2885,7 +2856,7 @@ static void opj_j2k_write_coc_in_memory(opj_j2k_t *p_j2k, l_comp_room = (l_image->numcomps <= 256) ? 1 : 2; l_coc_size = 5 + l_comp_room + opj_j2k_get_SPCod_SPCoc_size(p_j2k, - p_j2k->m_current_tile_number, p_comp_no); + p_j2k->m_current_tile_number, p_comp_no); l_remaining_size = l_coc_size; l_current_data = p_data; @@ -2911,8 +2882,7 @@ static void opj_j2k_write_coc_in_memory(opj_j2k_t *p_j2k, * p_data_written = l_coc_size; } -static OPJ_UINT32 opj_j2k_get_max_coc_size(opj_j2k_t *p_j2k) -{ +static OPJ_UINT32 opj_j2k_get_max_coc_size(opj_j2k_t *p_j2k) { OPJ_UINT32 i, j; OPJ_UINT32 l_nb_comp; OPJ_UINT32 l_nb_tiles; @@ -2940,11 +2910,10 @@ static OPJ_UINT32 opj_j2k_get_max_coc_size(opj_j2k_t *p_j2k) * @param p_manager the user event manager. */ static OPJ_BOOL opj_j2k_read_coc(opj_j2k_t *p_j2k, - OPJ_BYTE * p_header_data, + OPJ_BYTE *p_header_data, OPJ_UINT32 p_header_size, - opj_event_mgr_t * p_manager - ) -{ + opj_event_mgr_t *p_manager + ) { opj_cp_t *l_cp = NULL; opj_tcp_t *l_tcp = NULL; opj_image_t *l_image = NULL; @@ -3000,11 +2969,10 @@ static OPJ_BOOL opj_j2k_read_coc(opj_j2k_t *p_j2k, static OPJ_BOOL opj_j2k_write_qcd(opj_j2k_t *p_j2k, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager - ) -{ + opj_event_mgr_t *p_manager + ) { OPJ_UINT32 l_qcd_size, l_remaining_size; - OPJ_BYTE * l_current_data = 00; + OPJ_BYTE *l_current_data = 00; /* preconditions */ assert(p_j2k != 00); @@ -3012,7 +2980,7 @@ static OPJ_BOOL opj_j2k_write_qcd(opj_j2k_t *p_j2k, assert(p_stream != 00); l_qcd_size = 4 + opj_j2k_get_SQcd_SQcc_size(p_j2k, p_j2k->m_current_tile_number, - 0); + 0); l_remaining_size = l_qcd_size; if (l_qcd_size > p_j2k->m_specific_param.m_encoder.m_header_tile_data_size) { @@ -3067,11 +3035,10 @@ static OPJ_BOOL opj_j2k_write_qcd(opj_j2k_t *p_j2k, * @param p_manager the user event manager. */ static OPJ_BOOL opj_j2k_read_qcd(opj_j2k_t *p_j2k, - OPJ_BYTE * p_header_data, + OPJ_BYTE *p_header_data, OPJ_UINT32 p_header_size, - opj_event_mgr_t * p_manager - ) -{ + opj_event_mgr_t *p_manager + ) { /* preconditions */ assert(p_header_data != 00); assert(p_j2k != 00); @@ -3097,9 +3064,8 @@ static OPJ_BOOL opj_j2k_read_qcd(opj_j2k_t *p_j2k, static OPJ_BOOL opj_j2k_write_qcc(opj_j2k_t *p_j2k, OPJ_UINT32 p_comp_no, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager - ) -{ + opj_event_mgr_t *p_manager + ) { OPJ_UINT32 l_qcc_size, l_remaining_size; /* preconditions */ @@ -3108,7 +3074,7 @@ static OPJ_BOOL opj_j2k_write_qcc(opj_j2k_t *p_j2k, assert(p_stream != 00); l_qcc_size = 5 + opj_j2k_get_SQcd_SQcc_size(p_j2k, p_j2k->m_current_tile_number, - p_comp_no); + p_comp_no); l_qcc_size += p_j2k->m_private_image->numcomps <= 256 ? 0 : 1; l_remaining_size = l_qcc_size; @@ -3140,28 +3106,26 @@ static OPJ_BOOL opj_j2k_write_qcc(opj_j2k_t *p_j2k, } static OPJ_BOOL opj_j2k_compare_qcc(opj_j2k_t *p_j2k, - OPJ_UINT32 p_first_comp_no, OPJ_UINT32 p_second_comp_no) -{ + OPJ_UINT32 p_first_comp_no, OPJ_UINT32 p_second_comp_no) { return opj_j2k_compare_SQcd_SQcc(p_j2k, p_j2k->m_current_tile_number, p_first_comp_no, p_second_comp_no); } static void opj_j2k_write_qcc_in_memory(opj_j2k_t *p_j2k, OPJ_UINT32 p_comp_no, - OPJ_BYTE * p_data, - OPJ_UINT32 * p_data_written, - opj_event_mgr_t * p_manager - ) -{ + OPJ_BYTE *p_data, + OPJ_UINT32 *p_data_written, + opj_event_mgr_t *p_manager + ) { OPJ_UINT32 l_qcc_size, l_remaining_size; - OPJ_BYTE * l_current_data = 00; + OPJ_BYTE *l_current_data = 00; /* preconditions */ assert(p_j2k != 00); assert(p_manager != 00); l_qcc_size = 6 + opj_j2k_get_SQcd_SQcc_size(p_j2k, p_j2k->m_current_tile_number, - p_comp_no); + p_comp_no); l_remaining_size = l_qcc_size; l_current_data = p_data; @@ -3196,8 +3160,7 @@ static void opj_j2k_write_qcc_in_memory(opj_j2k_t *p_j2k, *p_data_written = l_qcc_size; } -static OPJ_UINT32 opj_j2k_get_max_qcc_size(opj_j2k_t *p_j2k) -{ +static OPJ_UINT32 opj_j2k_get_max_qcc_size(opj_j2k_t *p_j2k) { return opj_j2k_get_max_coc_size(p_j2k); } @@ -3209,11 +3172,10 @@ static OPJ_UINT32 opj_j2k_get_max_qcc_size(opj_j2k_t *p_j2k) * @param p_manager the user event manager. */ static OPJ_BOOL opj_j2k_read_qcc(opj_j2k_t *p_j2k, - OPJ_BYTE * p_header_data, + OPJ_BYTE *p_header_data, OPJ_UINT32 p_header_size, - opj_event_mgr_t * p_manager - ) -{ + opj_event_mgr_t *p_manager + ) { OPJ_UINT32 l_num_comp, l_comp_no; /* preconditions */ @@ -3290,9 +3252,8 @@ static OPJ_BOOL opj_j2k_read_qcc(opj_j2k_t *p_j2k, static OPJ_BOOL opj_j2k_write_poc(opj_j2k_t *p_j2k, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager - ) -{ + opj_event_mgr_t *p_manager + ) { OPJ_UINT32 l_nb_comp; OPJ_UINT32 l_nb_poc; OPJ_UINT32 l_poc_size; @@ -3344,13 +3305,12 @@ static OPJ_BOOL opj_j2k_write_poc(opj_j2k_t *p_j2k, } static void opj_j2k_write_poc_in_memory(opj_j2k_t *p_j2k, - OPJ_BYTE * p_data, - OPJ_UINT32 * p_data_written, - opj_event_mgr_t * p_manager - ) -{ + OPJ_BYTE *p_data, + OPJ_UINT32 *p_data_written, + opj_event_mgr_t *p_manager + ) { OPJ_UINT32 i; - OPJ_BYTE * l_current_data = 00; + OPJ_BYTE *l_current_data = 00; OPJ_UINT32 l_nb_comp; OPJ_UINT32 l_nb_poc; OPJ_UINT32 l_poc_size; @@ -3418,11 +3378,11 @@ static void opj_j2k_write_poc_in_memory(opj_j2k_t *p_j2k, /* change the value of the max layer according to the actual number of layers in the file, components and resolutions*/ l_current_poc->layno1 = (OPJ_UINT32)opj_int_min((OPJ_INT32) - l_current_poc->layno1, (OPJ_INT32)l_tcp->numlayers); + l_current_poc->layno1, (OPJ_INT32)l_tcp->numlayers); l_current_poc->resno1 = (OPJ_UINT32)opj_int_min((OPJ_INT32) - l_current_poc->resno1, (OPJ_INT32)l_tccp->numresolutions); + l_current_poc->resno1, (OPJ_INT32)l_tccp->numresolutions); l_current_poc->compno1 = (OPJ_UINT32)opj_int_min((OPJ_INT32) - l_current_poc->compno1, (OPJ_INT32)l_nb_comp); + l_current_poc->compno1, (OPJ_INT32)l_nb_comp); ++l_current_poc; } @@ -3430,9 +3390,8 @@ static void opj_j2k_write_poc_in_memory(opj_j2k_t *p_j2k, *p_data_written = l_poc_size; } -static OPJ_UINT32 opj_j2k_get_max_poc_size(opj_j2k_t *p_j2k) -{ - opj_tcp_t * l_tcp = 00; +static OPJ_UINT32 opj_j2k_get_max_poc_size(opj_j2k_t *p_j2k) { + opj_tcp_t *l_tcp = 00; OPJ_UINT32 l_nb_tiles = 0; OPJ_UINT32 l_max_poc = 0; OPJ_UINT32 i; @@ -3450,12 +3409,11 @@ static OPJ_UINT32 opj_j2k_get_max_poc_size(opj_j2k_t *p_j2k) return 4 + 9 * l_max_poc; } -static OPJ_UINT32 opj_j2k_get_max_toc_size(opj_j2k_t *p_j2k) -{ +static OPJ_UINT32 opj_j2k_get_max_toc_size(opj_j2k_t *p_j2k) { OPJ_UINT32 i; OPJ_UINT32 l_nb_tiles; OPJ_UINT32 l_max = 0; - opj_tcp_t * l_tcp = 00; + opj_tcp_t *l_tcp = 00; l_tcp = p_j2k->m_cp.tcps; l_nb_tiles = p_j2k->m_cp.tw * p_j2k->m_cp.th ; @@ -3469,8 +3427,7 @@ static OPJ_UINT32 opj_j2k_get_max_toc_size(opj_j2k_t *p_j2k) return 12 * l_max; } -static OPJ_UINT32 opj_j2k_get_specific_header_sizes(opj_j2k_t *p_j2k) -{ +static OPJ_UINT32 opj_j2k_get_specific_header_sizes(opj_j2k_t *p_j2k) { OPJ_UINT32 l_nb_bytes = 0; OPJ_UINT32 l_nb_comps; OPJ_UINT32 l_coc_bytes, l_qcc_bytes; @@ -3492,7 +3449,7 @@ static OPJ_UINT32 opj_j2k_get_specific_header_sizes(opj_j2k_t *p_j2k) /* Reserve space for PLT markers */ OPJ_UINT32 i; - const opj_cp_t * l_cp = &(p_j2k->m_cp); + const opj_cp_t *l_cp = &(p_j2k->m_cp); OPJ_UINT32 l_max_packet_count = 0; for (i = 0; i < l_cp->th * l_cp->tw; ++i) { l_max_packet_count = opj_uint_max(l_max_packet_count, @@ -3524,13 +3481,12 @@ static OPJ_UINT32 opj_j2k_get_specific_header_sizes(opj_j2k_t *p_j2k) * @param p_manager the user event manager. */ static OPJ_BOOL opj_j2k_read_poc(opj_j2k_t *p_j2k, - OPJ_BYTE * p_header_data, + OPJ_BYTE *p_header_data, OPJ_UINT32 p_header_size, - opj_event_mgr_t * p_manager - ) -{ + opj_event_mgr_t *p_manager + ) { OPJ_UINT32 i, l_nb_comp, l_tmp; - opj_image_t * l_image = 00; + opj_image_t *l_image = 00; OPJ_UINT32 l_old_poc_nb, l_current_poc_nb, l_current_poc_remaining; OPJ_UINT32 l_chunk_size, l_comp_room; @@ -3615,11 +3571,10 @@ static OPJ_BOOL opj_j2k_read_poc(opj_j2k_t *p_j2k, * @param p_manager the user event manager. */ static OPJ_BOOL opj_j2k_read_crg(opj_j2k_t *p_j2k, - OPJ_BYTE * p_header_data, + OPJ_BYTE *p_header_data, OPJ_UINT32 p_header_size, - opj_event_mgr_t * p_manager - ) -{ + opj_event_mgr_t *p_manager + ) { OPJ_UINT32 l_nb_comp; /* preconditions */ assert(p_header_data != 00); @@ -3657,16 +3612,15 @@ static OPJ_BOOL opj_j2k_read_crg(opj_j2k_t *p_j2k, * @param p_manager the user event manager. */ static OPJ_BOOL opj_j2k_read_tlm(opj_j2k_t *p_j2k, - OPJ_BYTE * p_header_data, + OPJ_BYTE *p_header_data, OPJ_UINT32 p_header_size, - opj_event_mgr_t * p_manager - ) -{ + opj_event_mgr_t *p_manager + ) { OPJ_UINT32 l_Ztlm, l_Stlm, l_ST, l_SP, l_Ptlm_size, l_entry_size, l_num_tileparts; OPJ_UINT32 i; - opj_j2k_tlm_tile_part_info_t* l_tile_part_infos; - opj_j2k_tlm_info_t* l_tlm; + opj_j2k_tlm_tile_part_info_t *l_tile_part_infos; + opj_j2k_tlm_info_t *l_tlm; /* preconditions */ assert(p_header_data != 00); @@ -3727,7 +3681,7 @@ static OPJ_BOOL opj_j2k_read_tlm(opj_j2k_t *p_j2k, return OPJ_TRUE; } - l_tile_part_infos = (opj_j2k_tlm_tile_part_info_t*)opj_realloc( + l_tile_part_infos = (opj_j2k_tlm_tile_part_info_t *)opj_realloc( l_tlm->m_tile_part_infos, (l_tlm->m_entries_count + l_num_tileparts) * sizeof( opj_j2k_tlm_tile_part_info_t)); @@ -3782,11 +3736,10 @@ static OPJ_BOOL opj_j2k_read_tlm(opj_j2k_t *p_j2k, * @param p_manager the user event manager. */ static OPJ_BOOL opj_j2k_read_plm(opj_j2k_t *p_j2k, - OPJ_BYTE * p_header_data, + OPJ_BYTE *p_header_data, OPJ_UINT32 p_header_size, - opj_event_mgr_t * p_manager - ) -{ + opj_event_mgr_t *p_manager + ) { /* preconditions */ assert(p_header_data != 00); assert(p_j2k != 00); @@ -3855,11 +3808,10 @@ static OPJ_BOOL opj_j2k_read_plm(opj_j2k_t *p_j2k, * @param p_manager the user event manager. */ static OPJ_BOOL opj_j2k_read_plt(opj_j2k_t *p_j2k, - OPJ_BYTE * p_header_data, + OPJ_BYTE *p_header_data, OPJ_UINT32 p_header_size, - opj_event_mgr_t * p_manager - ) -{ + opj_event_mgr_t *p_manager + ) { OPJ_UINT32 l_Zplt, l_tmp, l_packet_len = 0, i; /* preconditions */ @@ -3910,10 +3862,9 @@ static OPJ_BOOL opj_j2k_read_plt(opj_j2k_t *p_j2k, static OPJ_BOOL opj_j2k_read_ppm( opj_j2k_t *p_j2k, - OPJ_BYTE * p_header_data, + OPJ_BYTE *p_header_data, OPJ_UINT32 p_header_size, - opj_event_mgr_t * p_manager) -{ + opj_event_mgr_t *p_manager) { opj_cp_t *l_cp = 00; OPJ_UINT32 l_Z_ppm; @@ -3950,7 +3901,7 @@ static OPJ_BOOL opj_j2k_read_ppm( OPJ_UINT32 l_newCount = l_Z_ppm + 1U; /* can't overflow, l_Z_ppm is UINT8 */ opj_ppx *new_ppm_markers; new_ppm_markers = (opj_ppx *) opj_realloc(l_cp->ppm_markers, - l_newCount * sizeof(opj_ppx)); + l_newCount * sizeof(opj_ppx)); if (new_ppm_markers == NULL) { /* clean up to be done on l_cp destruction */ opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to read PPM marker\n"); @@ -3986,8 +3937,7 @@ static OPJ_BOOL opj_j2k_read_ppm( * @param p_cp main coding parameters. * @param p_manager the user event manager. */ -static OPJ_BOOL opj_j2k_merge_ppm(opj_cp_t *p_cp, opj_event_mgr_t * p_manager) -{ +static OPJ_BOOL opj_j2k_merge_ppm(opj_cp_t *p_cp, opj_event_mgr_t *p_manager) { OPJ_UINT32 i, l_ppm_data_size, l_N_ppm_remaining; /* preconditions */ @@ -4006,7 +3956,7 @@ static OPJ_BOOL opj_j2k_merge_ppm(opj_cp_t *p_cp, opj_event_mgr_t * p_manager) NULL) { /* standard doesn't seem to require contiguous Zppm */ OPJ_UINT32 l_N_ppm; OPJ_UINT32 l_data_size = p_cp->ppm_markers[i].m_data_size; - const OPJ_BYTE* l_data = p_cp->ppm_markers[i].m_data; + const OPJ_BYTE *l_data = p_cp->ppm_markers[i].m_data; if (l_N_ppm_remaining >= l_data_size) { l_N_ppm_remaining -= l_data_size; @@ -4065,7 +4015,7 @@ static OPJ_BOOL opj_j2k_merge_ppm(opj_cp_t *p_cp, opj_event_mgr_t * p_manager) NULL) { /* standard doesn't seem to require contiguous Zppm */ OPJ_UINT32 l_N_ppm; OPJ_UINT32 l_data_size = p_cp->ppm_markers[i].m_data_size; - const OPJ_BYTE* l_data = p_cp->ppm_markers[i].m_data; + const OPJ_BYTE *l_data = p_cp->ppm_markers[i].m_data; if (l_N_ppm_remaining >= l_data_size) { memcpy(p_cp->ppm_buffer + l_ppm_data_size, l_data, l_data_size); @@ -4130,11 +4080,10 @@ static OPJ_BOOL opj_j2k_merge_ppm(opj_cp_t *p_cp, opj_event_mgr_t * p_manager) * @param p_manager the user event manager. */ static OPJ_BOOL opj_j2k_read_ppt(opj_j2k_t *p_j2k, - OPJ_BYTE * p_header_data, + OPJ_BYTE *p_header_data, OPJ_UINT32 p_header_size, - opj_event_mgr_t * p_manager - ) -{ + opj_event_mgr_t *p_manager + ) { opj_cp_t *l_cp = 00; opj_tcp_t *l_tcp = 00; OPJ_UINT32 l_Z_ppt; @@ -4179,7 +4128,7 @@ static OPJ_BOOL opj_j2k_read_ppt(opj_j2k_t *p_j2k, OPJ_UINT32 l_newCount = l_Z_ppt + 1U; /* can't overflow, l_Z_ppt is UINT8 */ opj_ppx *new_ppt_markers; new_ppt_markers = (opj_ppx *) opj_realloc(l_tcp->ppt_markers, - l_newCount * sizeof(opj_ppx)); + l_newCount * sizeof(opj_ppx)); if (new_ppt_markers == NULL) { /* clean up to be done on l_tcp destruction */ opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to read PPT marker\n"); @@ -4214,8 +4163,7 @@ static OPJ_BOOL opj_j2k_read_ppt(opj_j2k_t *p_j2k, * @param p_tcp the tile. * @param p_manager the user event manager. */ -static OPJ_BOOL opj_j2k_merge_ppt(opj_tcp_t *p_tcp, opj_event_mgr_t * p_manager) -{ +static OPJ_BOOL opj_j2k_merge_ppt(opj_tcp_t *p_tcp, opj_event_mgr_t *p_manager) { OPJ_UINT32 i, l_ppt_data_size; /* preconditions */ assert(p_tcp != 00); @@ -4269,10 +4217,9 @@ static OPJ_BOOL opj_j2k_merge_ppt(opj_tcp_t *p_tcp, opj_event_mgr_t * p_manager) static OPJ_BOOL opj_j2k_write_tlm(opj_j2k_t *p_j2k, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager - ) -{ - OPJ_BYTE * l_current_data = 00; + opj_event_mgr_t *p_manager + ) { + OPJ_BYTE *l_current_data = 00; OPJ_UINT32 l_tlm_size; OPJ_UINT32 size_per_tile_part; @@ -4353,13 +4300,12 @@ static OPJ_BOOL opj_j2k_write_tlm(opj_j2k_t *p_j2k, } static OPJ_BOOL opj_j2k_write_sot(opj_j2k_t *p_j2k, - OPJ_BYTE * p_data, + OPJ_BYTE *p_data, OPJ_UINT32 total_data_size, - OPJ_UINT32 * p_data_written, + OPJ_UINT32 *p_data_written, const opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager - ) -{ + opj_event_mgr_t *p_manager + ) { /* preconditions */ assert(p_j2k != 00); assert(p_manager != 00); @@ -4412,14 +4358,13 @@ static OPJ_BOOL opj_j2k_write_sot(opj_j2k_t *p_j2k, return OPJ_TRUE; } -static OPJ_BOOL opj_j2k_get_sot_values(OPJ_BYTE * p_header_data, +static OPJ_BOOL opj_j2k_get_sot_values(OPJ_BYTE *p_header_data, OPJ_UINT32 p_header_size, - OPJ_UINT32* p_tile_no, - OPJ_UINT32* p_tot_len, - OPJ_UINT32* p_current_part, - OPJ_UINT32* p_num_parts, - opj_event_mgr_t * p_manager) -{ + OPJ_UINT32 *p_tile_no, + OPJ_UINT32 *p_tot_len, + OPJ_UINT32 *p_current_part, + OPJ_UINT32 *p_num_parts, + opj_event_mgr_t *p_manager) { /* preconditions */ assert(p_header_data != 00); assert(p_manager != 00); @@ -4442,10 +4387,9 @@ static OPJ_BOOL opj_j2k_get_sot_values(OPJ_BYTE * p_header_data, } static OPJ_BOOL opj_j2k_read_sot(opj_j2k_t *p_j2k, - OPJ_BYTE * p_header_data, + OPJ_BYTE *p_header_data, OPJ_UINT32 p_header_size, - opj_event_mgr_t * p_manager) -{ + opj_event_mgr_t *p_manager) { opj_cp_t *l_cp = 00; opj_tcp_t *l_tcp = 00; OPJ_UINT32 l_tot_len, l_num_parts = 0; @@ -4629,7 +4573,7 @@ static OPJ_BOOL opj_j2k_read_sot(opj_j2k_t *p_j2k, if (!p_j2k->m_specific_param.m_decoder.m_last_tile_part) { /* Keep the size of data to skip after this marker */ p_j2k->m_specific_param.m_decoder.m_sot_length = l_tot_len - - 12; /* SOT_marker_size = 12 */ + 12; /* SOT_marker_size = 12 */ } else { /* FIXME: need to be computed from the number of bytes remaining in the codestream */ p_j2k->m_specific_param.m_decoder.m_sot_length = 0; @@ -4679,7 +4623,7 @@ static OPJ_BOOL opj_j2k_read_sot(opj_j2k_t *p_j2k, if (!p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index) { p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index = - (opj_tp_index_t*)opj_calloc(l_num_parts, sizeof(opj_tp_index_t)); + (opj_tp_index_t *)opj_calloc(l_num_parts, sizeof(opj_tp_index_t)); if (!p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index) { opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to read SOT marker. Tile index allocation failed\n"); @@ -4705,7 +4649,7 @@ static OPJ_BOOL opj_j2k_read_sot(opj_j2k_t *p_j2k, if (!p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index) { p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].current_nb_tps = 10; p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index = - (opj_tp_index_t*)opj_calloc( + (opj_tp_index_t *)opj_calloc( p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].current_nb_tps, sizeof(opj_tp_index_t)); if (!p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index) { @@ -4749,15 +4693,14 @@ static OPJ_BOOL opj_j2k_read_sot(opj_j2k_t *p_j2k, * Write one or more PLT markers in the provided buffer */ static OPJ_BOOL opj_j2k_write_plt_in_memory(opj_j2k_t *p_j2k, - opj_tcd_marker_info_t* marker_info, - OPJ_BYTE * p_data, - OPJ_UINT32 * p_data_written, - opj_event_mgr_t * p_manager) -{ + opj_tcd_marker_info_t *marker_info, + OPJ_BYTE *p_data, + OPJ_UINT32 *p_data_written, + opj_event_mgr_t *p_manager) { OPJ_BYTE Zplt = 0; OPJ_UINT16 Lplt; - OPJ_BYTE* p_data_start = p_data; - OPJ_BYTE* p_data_Lplt = p_data + 2; + OPJ_BYTE *p_data_start = p_data; + OPJ_BYTE *p_data_Lplt = p_data + 2; OPJ_UINT32 i; OPJ_UNUSED(p_j2k); @@ -4833,17 +4776,16 @@ static OPJ_BOOL opj_j2k_write_plt_in_memory(opj_j2k_t *p_j2k, } static OPJ_BOOL opj_j2k_write_sod(opj_j2k_t *p_j2k, - opj_tcd_t * p_tile_coder, - OPJ_BYTE * p_data, - OPJ_UINT32 * p_data_written, + opj_tcd_t *p_tile_coder, + OPJ_BYTE *p_data, + OPJ_UINT32 *p_data_written, OPJ_UINT32 total_data_size, const opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager - ) -{ + opj_event_mgr_t *p_manager + ) { opj_codestream_info_t *l_cstr_info = 00; OPJ_UINT32 l_remaining_data; - opj_tcd_marker_info_t* marker_info = NULL; + opj_tcd_marker_info_t *marker_info = NULL; /* preconditions */ assert(p_j2k != 00); @@ -4943,7 +4885,7 @@ static OPJ_BOOL opj_j2k_write_sod(opj_j2k_t *p_j2k, if (p_j2k->m_specific_param.m_encoder.m_PLT) { OPJ_UINT32 l_data_written_PLT = 0; - OPJ_BYTE* p_PLT_buffer = (OPJ_BYTE*)opj_malloc( + OPJ_BYTE *p_PLT_buffer = (OPJ_BYTE *)opj_malloc( p_j2k->m_specific_param.m_encoder.m_reserved_bytes_for_PLT); if (!p_PLT_buffer) { opj_event_msg(p_manager, EVT_ERROR, "Cannot allocate memory\n"); @@ -4977,14 +4919,13 @@ static OPJ_BOOL opj_j2k_write_sod(opj_j2k_t *p_j2k, static OPJ_BOOL opj_j2k_read_sod(opj_j2k_t *p_j2k, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager - ) -{ + opj_event_mgr_t *p_manager + ) { OPJ_SIZE_T l_current_read_size; - opj_codestream_index_t * l_cstr_index = 00; - OPJ_BYTE ** l_current_data = 00; - opj_tcp_t * l_tcp = 00; - OPJ_UINT32 * l_tile_len = 00; + opj_codestream_index_t *l_cstr_index = 00; + OPJ_BYTE **l_current_data = 00; + opj_tcp_t *l_tcp = 00; + OPJ_UINT32 *l_tile_len = 00; OPJ_BOOL l_sot_length_pb_detected = OPJ_FALSE; /* preconditions */ @@ -5000,7 +4941,7 @@ static OPJ_BOOL opj_j2k_read_sod(opj_j2k_t *p_j2k, // so its result will fit on OPJ_UINT32 unless we find // a file with a single tile part of more than 4 GB...*/ p_j2k->m_specific_param.m_decoder.m_sot_length = (OPJ_UINT32)( - opj_stream_get_number_byte_left(p_stream) - 2); + opj_stream_get_number_byte_left(p_stream) - 2); } else { /* Check to avoid pass the limit of OPJ_UINT32 */ if (p_j2k->m_specific_param.m_decoder.m_sot_length >= 2) { @@ -5042,7 +4983,7 @@ static OPJ_BOOL opj_j2k_read_sod(opj_j2k_t *p_j2k, /* LH: oddly enough, in this path, l_tile_len!=0. * TODO: If this was consistent, we could simplify the code to only use realloc(), as realloc(0,...) default to malloc(0,...). */ - *l_current_data = (OPJ_BYTE*) opj_malloc( + *l_current_data = (OPJ_BYTE *) opj_malloc( p_j2k->m_specific_param.m_decoder.m_sot_length + OPJ_COMMON_CBLK_DATA_EXTRA); } else { OPJ_BYTE *l_new_current_data; @@ -5055,8 +4996,8 @@ static OPJ_BOOL opj_j2k_read_sod(opj_j2k_t *p_j2k, } l_new_current_data = (OPJ_BYTE *) opj_realloc(*l_current_data, - *l_tile_len + p_j2k->m_specific_param.m_decoder.m_sot_length + - OPJ_COMMON_CBLK_DATA_EXTRA); + *l_tile_len + p_j2k->m_specific_param.m_decoder.m_sot_length + + OPJ_COMMON_CBLK_DATA_EXTRA); if (! l_new_current_data) { opj_free(*l_current_data); /*nothing more is done as l_current_data will be set to null, and just @@ -5133,10 +5074,9 @@ static OPJ_BOOL opj_j2k_write_rgn(opj_j2k_t *p_j2k, OPJ_UINT32 p_comp_no, OPJ_UINT32 nb_comps, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager - ) -{ - OPJ_BYTE * l_current_data = 00; + opj_event_mgr_t *p_manager + ) { + OPJ_BYTE *l_current_data = 00; OPJ_UINT32 l_rgn_size; opj_cp_t *l_cp = 00; opj_tcp_t *l_tcp = 00; @@ -5193,9 +5133,8 @@ static OPJ_BOOL opj_j2k_write_rgn(opj_j2k_t *p_j2k, static OPJ_BOOL opj_j2k_write_eoc(opj_j2k_t *p_j2k, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager - ) -{ + opj_event_mgr_t *p_manager + ) { /* preconditions */ assert(p_j2k != 00); assert(p_manager != 00); @@ -5233,13 +5172,12 @@ static OPJ_BOOL opj_j2k_write_eoc(opj_j2k_t *p_j2k, * @param p_manager the user event manager. */ static OPJ_BOOL opj_j2k_read_rgn(opj_j2k_t *p_j2k, - OPJ_BYTE * p_header_data, + OPJ_BYTE *p_header_data, OPJ_UINT32 p_header_size, - opj_event_mgr_t * p_manager - ) -{ + opj_event_mgr_t *p_manager + ) { OPJ_UINT32 l_nb_comp; - opj_image_t * l_image = 00; + opj_image_t *l_image = 00; opj_cp_t *l_cp = 00; opj_tcp_t *l_tcp = 00; @@ -5306,29 +5244,26 @@ static OPJ_BOOL opj_j2k_read_rgn(opj_j2k_t *p_j2k, } -static OPJ_FLOAT32 opj_j2k_get_tp_stride(opj_tcp_t * p_tcp) -{ +static OPJ_FLOAT32 opj_j2k_get_tp_stride(opj_tcp_t *p_tcp) { return (OPJ_FLOAT32)((p_tcp->m_nb_tile_parts - 1) * 14); } -static OPJ_FLOAT32 opj_j2k_get_default_stride(opj_tcp_t * p_tcp) -{ +static OPJ_FLOAT32 opj_j2k_get_default_stride(opj_tcp_t *p_tcp) { (void)p_tcp; return 0; } static OPJ_BOOL opj_j2k_update_rates(opj_j2k_t *p_j2k, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager) -{ - opj_cp_t * l_cp = 00; - opj_image_t * l_image = 00; - opj_tcp_t * l_tcp = 00; - opj_image_comp_t * l_img_comp = 00; + opj_event_mgr_t *p_manager) { + opj_cp_t *l_cp = 00; + opj_image_t *l_image = 00; + opj_tcp_t *l_tcp = 00; + opj_image_comp_t *l_img_comp = 00; OPJ_UINT32 i, j, k; OPJ_INT32 l_x0, l_y0, l_x1, l_y1; - OPJ_FLOAT32 * l_rates = 0; + OPJ_FLOAT32 *l_rates = 0; OPJ_FLOAT32 l_sot_remove; OPJ_UINT32 l_bits_empty, l_size_pixel; OPJ_UINT64 l_tile_size = 0; @@ -5495,12 +5430,11 @@ static OPJ_BOOL opj_j2k_update_rates(opj_j2k_t *p_j2k, #if 0 static OPJ_BOOL opj_j2k_read_eoc(opj_j2k_t *p_j2k, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager) -{ + opj_event_mgr_t *p_manager) { OPJ_UINT32 i; - opj_tcd_t * l_tcd = 00; + opj_tcd_t *l_tcd = 00; OPJ_UINT32 l_nb_tiles; - opj_tcp_t * l_tcp = 00; + opj_tcp_t *l_tcp = 00; OPJ_BOOL l_success; /* preconditions */ @@ -5546,8 +5480,7 @@ static OPJ_BOOL opj_j2k_read_eoc(opj_j2k_t *p_j2k, static OPJ_BOOL opj_j2k_get_end_header(opj_j2k_t *p_j2k, struct opj_stream_private *p_stream, - struct opj_event_mgr * p_manager) -{ + struct opj_event_mgr *p_manager) { /* preconditions */ assert(p_j2k != 00); assert(p_manager != 00); @@ -5561,13 +5494,12 @@ static OPJ_BOOL opj_j2k_get_end_header(opj_j2k_t *p_j2k, } static OPJ_BOOL opj_j2k_write_mct_data_group(opj_j2k_t *p_j2k, - struct opj_stream_private *p_stream, - struct opj_event_mgr * p_manager) -{ + struct opj_stream_private *p_stream, + struct opj_event_mgr *p_manager) { OPJ_UINT32 i; - opj_simple_mcc_decorrelation_data_t * l_mcc_record; - opj_mct_data_t * l_mct_record; - opj_tcp_t * l_tcp; + opj_simple_mcc_decorrelation_data_t *l_mcc_record; + opj_mct_data_t *l_mct_record; + opj_tcp_t *l_tcp; /* preconditions */ assert(p_j2k != 00); @@ -5611,8 +5543,7 @@ static OPJ_BOOL opj_j2k_write_mct_data_group(opj_j2k_t *p_j2k, static OPJ_BOOL opj_j2k_write_all_coc( opj_j2k_t *p_j2k, struct opj_stream_private *p_stream, - struct opj_event_mgr * p_manager) -{ + struct opj_event_mgr *p_manager) { OPJ_UINT32 compno; /* preconditions */ @@ -5635,8 +5566,7 @@ static OPJ_BOOL opj_j2k_write_all_coc( static OPJ_BOOL opj_j2k_write_all_qcc( opj_j2k_t *p_j2k, struct opj_stream_private *p_stream, - struct opj_event_mgr * p_manager) -{ + struct opj_event_mgr *p_manager) { OPJ_UINT32 compno; /* preconditions */ @@ -5657,8 +5587,7 @@ static OPJ_BOOL opj_j2k_write_all_qcc( static OPJ_BOOL opj_j2k_write_regions(opj_j2k_t *p_j2k, struct opj_stream_private *p_stream, - struct opj_event_mgr * p_manager) -{ + struct opj_event_mgr *p_manager) { OPJ_UINT32 compno; const opj_tccp_t *l_tccp = 00; @@ -5686,9 +5615,8 @@ static OPJ_BOOL opj_j2k_write_regions(opj_j2k_t *p_j2k, static OPJ_BOOL opj_j2k_write_epc(opj_j2k_t *p_j2k, struct opj_stream_private *p_stream, - struct opj_event_mgr * p_manager) -{ - opj_codestream_index_t * l_cstr_index = 00; + struct opj_event_mgr *p_manager) { + opj_codestream_index_t *l_cstr_index = 00; /* preconditions */ assert(p_j2k != 00); @@ -5727,11 +5655,10 @@ static OPJ_BOOL opj_j2k_write_epc(opj_j2k_t *p_j2k, static OPJ_BOOL opj_j2k_read_unk(opj_j2k_t *p_j2k, opj_stream_private_t *p_stream, OPJ_UINT32 *output_marker, - opj_event_mgr_t * p_manager - ) -{ + opj_event_mgr_t *p_manager + ) { OPJ_UINT32 l_unknown_marker; - const opj_dec_memory_marker_handler_t * l_marker_handler; + const opj_dec_memory_marker_handler_t *l_marker_handler; OPJ_UINT32 l_size_unk = 2; /* preconditions*/ @@ -5788,12 +5715,11 @@ static OPJ_BOOL opj_j2k_read_unk(opj_j2k_t *p_j2k, } static OPJ_BOOL opj_j2k_write_mct_record(opj_j2k_t *p_j2k, - opj_mct_data_t * p_mct_record, - struct opj_stream_private *p_stream, - struct opj_event_mgr * p_manager) -{ + opj_mct_data_t *p_mct_record, + struct opj_stream_private *p_stream, + struct opj_event_mgr *p_manager) { OPJ_UINT32 l_mct_size; - OPJ_BYTE * l_current_data = 00; + OPJ_BYTE *l_current_data = 00; OPJ_UINT32 l_tmp; /* preconditions */ @@ -5862,16 +5788,15 @@ static OPJ_BOOL opj_j2k_write_mct_record(opj_j2k_t *p_j2k, * @param p_manager the user event manager. */ static OPJ_BOOL opj_j2k_read_mct(opj_j2k_t *p_j2k, - OPJ_BYTE * p_header_data, + OPJ_BYTE *p_header_data, OPJ_UINT32 p_header_size, - opj_event_mgr_t * p_manager - ) -{ + opj_event_mgr_t *p_manager + ) { OPJ_UINT32 i; opj_tcp_t *l_tcp = 00; OPJ_UINT32 l_tmp; OPJ_UINT32 l_indix; - opj_mct_data_t * l_mct_data; + opj_mct_data_t *l_mct_data; /* preconditions */ assert(p_header_data != 00); @@ -5921,7 +5846,7 @@ static OPJ_BOOL opj_j2k_read_mct(opj_j2k_t *p_j2k, l_tcp->m_nb_max_mct_records += OPJ_J2K_MCT_DEFAULT_NB_RECORDS; new_mct_records = (opj_mct_data_t *) opj_realloc(l_tcp->m_mct_records, - l_tcp->m_nb_max_mct_records * sizeof(opj_mct_data_t)); + l_tcp->m_nb_max_mct_records * sizeof(opj_mct_data_t)); if (! new_mct_records) { opj_free(l_tcp->m_mct_records); l_tcp->m_mct_records = NULL; @@ -5935,7 +5860,7 @@ static OPJ_BOOL opj_j2k_read_mct(opj_j2k_t *p_j2k, * to point to the new addresses */ if (new_mct_records != l_tcp->m_mct_records) { for (i = 0; i < l_tcp->m_nb_mcc_records; ++i) { - opj_simple_mcc_decorrelation_data_t* l_mcc_record = + opj_simple_mcc_decorrelation_data_t *l_mcc_record = &(l_tcp->m_mcc_records[i]); if (l_mcc_record->m_decorrelation_array) { l_mcc_record->m_decorrelation_array = @@ -5982,7 +5907,7 @@ static OPJ_BOOL opj_j2k_read_mct(opj_j2k_t *p_j2k, p_header_size -= 6; - l_mct_data->m_data = (OPJ_BYTE*)opj_malloc(p_header_size); + l_mct_data->m_data = (OPJ_BYTE *)opj_malloc(p_header_size); if (! l_mct_data->m_data) { opj_event_msg(p_manager, EVT_ERROR, "Error reading MCT marker\n"); return OPJ_FALSE; @@ -5995,13 +5920,12 @@ static OPJ_BOOL opj_j2k_read_mct(opj_j2k_t *p_j2k, } static OPJ_BOOL opj_j2k_write_mcc_record(opj_j2k_t *p_j2k, - struct opj_simple_mcc_decorrelation_data * p_mcc_record, - struct opj_stream_private *p_stream, - struct opj_event_mgr * p_manager) -{ + struct opj_simple_mcc_decorrelation_data *p_mcc_record, + struct opj_stream_private *p_stream, + struct opj_event_mgr *p_manager) { OPJ_UINT32 i; OPJ_UINT32 l_mcc_size; - OPJ_BYTE * l_current_data = 00; + OPJ_BYTE *l_current_data = 00; OPJ_UINT32 l_nb_bytes_for_comp; OPJ_UINT32 l_mask; OPJ_UINT32 l_tmcc; @@ -6110,16 +6034,15 @@ static OPJ_BOOL opj_j2k_write_mcc_record(opj_j2k_t *p_j2k, } static OPJ_BOOL opj_j2k_read_mcc(opj_j2k_t *p_j2k, - OPJ_BYTE * p_header_data, + OPJ_BYTE *p_header_data, OPJ_UINT32 p_header_size, - opj_event_mgr_t * p_manager) -{ + opj_event_mgr_t *p_manager) { OPJ_UINT32 i, j; OPJ_UINT32 l_tmp; OPJ_UINT32 l_indix; - opj_tcp_t * l_tcp; - opj_simple_mcc_decorrelation_data_t * l_mcc_record; - opj_mct_data_t * l_mct_data; + opj_tcp_t *l_tcp; + opj_simple_mcc_decorrelation_data_t *l_mcc_record; + opj_mct_data_t *l_mct_data; OPJ_UINT32 l_nb_collections; OPJ_UINT32 l_nb_comps; OPJ_UINT32 l_nb_bytes_by_comp; @@ -6344,13 +6267,12 @@ static OPJ_BOOL opj_j2k_read_mcc(opj_j2k_t *p_j2k, static OPJ_BOOL opj_j2k_write_mco(opj_j2k_t *p_j2k, struct opj_stream_private *p_stream, - struct opj_event_mgr * p_manager - ) -{ - OPJ_BYTE * l_current_data = 00; + struct opj_event_mgr *p_manager + ) { + OPJ_BYTE *l_current_data = 00; OPJ_UINT32 l_mco_size; - opj_tcp_t * l_tcp = 00; - opj_simple_mcc_decorrelation_data_t * l_mcc_record; + opj_tcp_t *l_tcp = 00; + opj_simple_mcc_decorrelation_data_t *l_mcc_record; OPJ_UINT32 i; /* preconditions */ @@ -6414,16 +6336,15 @@ static OPJ_BOOL opj_j2k_write_mco(opj_j2k_t *p_j2k, * @param p_manager the user event manager. */ static OPJ_BOOL opj_j2k_read_mco(opj_j2k_t *p_j2k, - OPJ_BYTE * p_header_data, + OPJ_BYTE *p_header_data, OPJ_UINT32 p_header_size, - opj_event_mgr_t * p_manager - ) -{ + opj_event_mgr_t *p_manager + ) { OPJ_UINT32 l_tmp, i; OPJ_UINT32 l_nb_stages; - opj_tcp_t * l_tcp; - opj_tccp_t * l_tccp; - opj_image_t * l_image; + opj_tcp_t *l_tcp; + opj_tccp_t *l_tccp; + opj_image_t *l_image; /* preconditions */ assert(p_header_data != 00); @@ -6479,16 +6400,15 @@ static OPJ_BOOL opj_j2k_read_mco(opj_j2k_t *p_j2k, return OPJ_TRUE; } -static OPJ_BOOL opj_j2k_add_mct(opj_tcp_t * p_tcp, opj_image_t * p_image, - OPJ_UINT32 p_index) -{ +static OPJ_BOOL opj_j2k_add_mct(opj_tcp_t *p_tcp, opj_image_t *p_image, + OPJ_UINT32 p_index) { OPJ_UINT32 i; - opj_simple_mcc_decorrelation_data_t * l_mcc_record; - opj_mct_data_t * l_deco_array, * l_offset_array; + opj_simple_mcc_decorrelation_data_t *l_mcc_record; + opj_mct_data_t *l_deco_array, * l_offset_array; OPJ_UINT32 l_data_size, l_mct_size, l_offset_size; OPJ_UINT32 l_nb_elem; - OPJ_UINT32 * l_offset_data, * l_current_offset_data; - opj_tccp_t * l_tccp; + OPJ_UINT32 *l_offset_data, * l_current_offset_data; + opj_tccp_t *l_tccp; /* preconditions */ assert(p_tcp != 00); @@ -6522,7 +6442,7 @@ static OPJ_BOOL opj_j2k_add_mct(opj_tcp_t * p_tcp, opj_image_t * p_image, l_nb_elem = p_image->numcomps * p_image->numcomps; l_mct_size = l_nb_elem * (OPJ_UINT32)sizeof(OPJ_FLOAT32); - p_tcp->m_mct_decoding_matrix = (OPJ_FLOAT32*)opj_malloc(l_mct_size); + p_tcp->m_mct_decoding_matrix = (OPJ_FLOAT32 *)opj_malloc(l_mct_size); if (! p_tcp->m_mct_decoding_matrix) { return OPJ_FALSE; @@ -6543,7 +6463,7 @@ static OPJ_BOOL opj_j2k_add_mct(opj_tcp_t * p_tcp, opj_image_t * p_image, l_nb_elem = p_image->numcomps; l_offset_size = l_nb_elem * (OPJ_UINT32)sizeof(OPJ_UINT32); - l_offset_data = (OPJ_UINT32*)opj_malloc(l_offset_size); + l_offset_data = (OPJ_UINT32 *)opj_malloc(l_offset_size); if (! l_offset_data) { return OPJ_FALSE; @@ -6568,13 +6488,12 @@ static OPJ_BOOL opj_j2k_add_mct(opj_tcp_t * p_tcp, opj_image_t * p_image, static OPJ_BOOL opj_j2k_write_cbd(opj_j2k_t *p_j2k, struct opj_stream_private *p_stream, - struct opj_event_mgr * p_manager) -{ + struct opj_event_mgr *p_manager) { OPJ_UINT32 i; OPJ_UINT32 l_cbd_size; - OPJ_BYTE * l_current_data = 00; + OPJ_BYTE *l_current_data = 00; opj_image_t *l_image = 00; - opj_image_comp_t * l_comp = 00; + opj_image_comp_t *l_comp = 00; /* preconditions */ assert(p_j2k != 00); @@ -6636,15 +6555,14 @@ static OPJ_BOOL opj_j2k_write_cbd(opj_j2k_t *p_j2k, * @param p_manager the user event manager. */ static OPJ_BOOL opj_j2k_read_cbd(opj_j2k_t *p_j2k, - OPJ_BYTE * p_header_data, + OPJ_BYTE *p_header_data, OPJ_UINT32 p_header_size, - opj_event_mgr_t * p_manager - ) -{ + opj_event_mgr_t *p_manager + ) { OPJ_UINT32 l_nb_comp, l_num_comp; OPJ_UINT32 l_comp_def; OPJ_UINT32 i; - opj_image_comp_t * l_comp = 00; + opj_image_comp_t *l_comp = 00; /* preconditions */ assert(p_header_data != 00); @@ -6697,11 +6615,10 @@ static OPJ_BOOL opj_j2k_read_cbd(opj_j2k_t *p_j2k, * @param p_manager the user event manager. */ static OPJ_BOOL opj_j2k_read_cap(opj_j2k_t *p_j2k, - OPJ_BYTE * p_header_data, + OPJ_BYTE *p_header_data, OPJ_UINT32 p_header_size, - opj_event_mgr_t * p_manager - ) -{ + opj_event_mgr_t *p_manager + ) { /* preconditions */ assert(p_header_data != 00); assert(p_j2k != 00); @@ -6723,11 +6640,10 @@ static OPJ_BOOL opj_j2k_read_cap(opj_j2k_t *p_j2k, * @param p_manager the user event manager. */ static OPJ_BOOL opj_j2k_read_cpf(opj_j2k_t *p_j2k, - OPJ_BYTE * p_header_data, + OPJ_BYTE *p_header_data, OPJ_UINT32 p_header_size, - opj_event_mgr_t * p_manager - ) -{ + opj_event_mgr_t *p_manager + ) { /* preconditions */ assert(p_header_data != 00); assert(p_j2k != 00); @@ -6745,8 +6661,7 @@ static OPJ_BOOL opj_j2k_read_cpf(opj_j2k_t *p_j2k, /* J2K / JPT decoder interface */ /* ----------------------------------------------------------------------- */ -void opj_j2k_setup_decoder(opj_j2k_t *j2k, opj_dparameters_t *parameters) -{ +void opj_j2k_setup_decoder(opj_j2k_t *j2k, opj_dparameters_t *parameters) { if (j2k && parameters) { j2k->m_cp.m_specific_param.m_dec.m_layer = parameters->cp_layer; j2k->m_cp.m_specific_param.m_dec.m_reduce = parameters->cp_reduce; @@ -6760,8 +6675,7 @@ void opj_j2k_setup_decoder(opj_j2k_t *j2k, opj_dparameters_t *parameters) } } -void opj_j2k_decoder_set_strict_mode(opj_j2k_t *j2k, OPJ_BOOL strict) -{ +void opj_j2k_decoder_set_strict_mode(opj_j2k_t *j2k, OPJ_BOOL strict) { if (j2k) { j2k->m_cp.strict = strict; if (strict) { @@ -6770,8 +6684,7 @@ void opj_j2k_decoder_set_strict_mode(opj_j2k_t *j2k, OPJ_BOOL strict) } } -OPJ_BOOL opj_j2k_set_threads(opj_j2k_t *j2k, OPJ_UINT32 num_threads) -{ +OPJ_BOOL opj_j2k_set_threads(opj_j2k_t *j2k, OPJ_UINT32 num_threads) { /* Currently we pass the thread-pool to the tcd, so we cannot re-set it */ /* afterwards */ if (opj_has_thread_support() && j2k->m_tcd == NULL) { @@ -6789,9 +6702,8 @@ OPJ_BOOL opj_j2k_set_threads(opj_j2k_t *j2k, OPJ_UINT32 num_threads) return OPJ_FALSE; } -static int opj_j2k_get_default_thread_count(void) -{ - const char* num_threads_str = getenv("OPJ_NUM_THREADS"); +static int opj_j2k_get_default_thread_count(void) { + const char *num_threads_str = getenv("OPJ_NUM_THREADS"); int num_cpus; int num_threads; @@ -6818,9 +6730,8 @@ static int opj_j2k_get_default_thread_count(void) /* J2K encoder interface */ /* ----------------------------------------------------------------------- */ -opj_j2k_t* opj_j2k_create_compress(void) -{ - opj_j2k_t *l_j2k = (opj_j2k_t*) opj_calloc(1, sizeof(opj_j2k_t)); +opj_j2k_t *opj_j2k_create_compress(void) { + opj_j2k_t *l_j2k = (opj_j2k_t *) opj_calloc(1, sizeof(opj_j2k_t)); if (!l_j2k) { return NULL; } @@ -6830,7 +6741,7 @@ opj_j2k_t* opj_j2k_create_compress(void) l_j2k->m_cp.m_is_decoder = 0; l_j2k->m_specific_param.m_encoder.m_header_tile_data = (OPJ_BYTE *) opj_malloc( - OPJ_J2K_DEFAULT_HEADER_SIZE); + OPJ_J2K_DEFAULT_HEADER_SIZE); if (! l_j2k->m_specific_param.m_encoder.m_header_tile_data) { opj_j2k_destroy(l_j2k); return NULL; @@ -6865,8 +6776,7 @@ opj_j2k_t* opj_j2k_create_compress(void) return l_j2k; } -static int opj_j2k_initialise_4K_poc(opj_poc_t *POC, int numres) -{ +static int opj_j2k_initialise_4K_poc(opj_poc_t *POC, int numres) { POC[0].tile = 1; POC[0].resno0 = 0; POC[0].compno0 = 0; @@ -6885,8 +6795,7 @@ static int opj_j2k_initialise_4K_poc(opj_poc_t *POC, int numres) } static void opj_j2k_set_cinema_parameters(opj_cparameters_t *parameters, - opj_image_t *image, opj_event_mgr_t *p_manager) -{ + opj_image_t *image, opj_event_mgr_t *p_manager) { /* Configure cinema parameters */ int i; @@ -6937,35 +6846,35 @@ static void opj_j2k_set_cinema_parameters(opj_cparameters_t *parameters, /* Resolution levels */ switch (parameters->rsiz) { - case OPJ_PROFILE_CINEMA_2K: - if (parameters->numresolution > 6) { - opj_event_msg(p_manager, EVT_WARNING, - "JPEG 2000 Profile-3 (2k dc profile) requires:\n" - "Number of decomposition levels <= 5\n" - "-> Number of decomposition levels forced to 5 (rather than %d)\n", - parameters->numresolution + 1); - parameters->numresolution = 6; - } - break; - case OPJ_PROFILE_CINEMA_4K: - if (parameters->numresolution < 2) { - opj_event_msg(p_manager, EVT_WARNING, - "JPEG 2000 Profile-4 (4k dc profile) requires:\n" - "Number of decomposition levels >= 1 && <= 6\n" - "-> Number of decomposition levels forced to 1 (rather than %d)\n", - parameters->numresolution + 1); - parameters->numresolution = 1; - } else if (parameters->numresolution > 7) { - opj_event_msg(p_manager, EVT_WARNING, - "JPEG 2000 Profile-4 (4k dc profile) requires:\n" - "Number of decomposition levels >= 1 && <= 6\n" - "-> Number of decomposition levels forced to 6 (rather than %d)\n", - parameters->numresolution + 1); - parameters->numresolution = 7; - } - break; - default : - break; + case OPJ_PROFILE_CINEMA_2K: + if (parameters->numresolution > 6) { + opj_event_msg(p_manager, EVT_WARNING, + "JPEG 2000 Profile-3 (2k dc profile) requires:\n" + "Number of decomposition levels <= 5\n" + "-> Number of decomposition levels forced to 5 (rather than %d)\n", + parameters->numresolution + 1); + parameters->numresolution = 6; + } + break; + case OPJ_PROFILE_CINEMA_4K: + if (parameters->numresolution < 2) { + opj_event_msg(p_manager, EVT_WARNING, + "JPEG 2000 Profile-4 (4k dc profile) requires:\n" + "Number of decomposition levels >= 1 && <= 6\n" + "-> Number of decomposition levels forced to 1 (rather than %d)\n", + parameters->numresolution + 1); + parameters->numresolution = 1; + } else if (parameters->numresolution > 7) { + opj_event_msg(p_manager, EVT_WARNING, + "JPEG 2000 Profile-4 (4k dc profile) requires:\n" + "Number of decomposition levels >= 1 && <= 6\n" + "-> Number of decomposition levels forced to 6 (rather than %d)\n", + parameters->numresolution + 1); + parameters->numresolution = 7; + } + break; + default : + break; } /* Precincts */ @@ -6988,7 +6897,7 @@ static void opj_j2k_set_cinema_parameters(opj_cparameters_t *parameters, /* Progression order changes for 4K, disallowed for 2K */ if (parameters->rsiz == OPJ_PROFILE_CINEMA_4K) { parameters->numpocs = (OPJ_UINT32)opj_j2k_initialise_4K_poc(parameters->POC, - parameters->numresolution); + parameters->numresolution); } else { parameters->numpocs = 0; } @@ -7026,15 +6935,14 @@ static void opj_j2k_set_cinema_parameters(opj_cparameters_t *parameters, } parameters->tcp_rates[0] = (OPJ_FLOAT32)(image->numcomps * image->comps[0].w * - image->comps[0].h * image->comps[0].prec) / + image->comps[0].h * image->comps[0].prec) / (OPJ_FLOAT32)(((OPJ_UINT32)parameters->max_cs_size) * 8 * image->comps[0].dx * - image->comps[0].dy); + image->comps[0].dy); } static OPJ_BOOL opj_j2k_is_cinema_compliant(opj_image_t *image, OPJ_UINT16 rsiz, - opj_event_mgr_t *p_manager) -{ + opj_event_mgr_t *p_manager) { OPJ_UINT32 i; /* Number of components */ @@ -7066,89 +6974,87 @@ static OPJ_BOOL opj_j2k_is_cinema_compliant(opj_image_t *image, OPJ_UINT16 rsiz, /* Image size */ switch (rsiz) { - case OPJ_PROFILE_CINEMA_2K: - if (((image->comps[0].w > 2048) | (image->comps[0].h > 1080))) { - opj_event_msg(p_manager, EVT_WARNING, - "JPEG 2000 Profile-3 (2k dc profile) requires:\n" - "width <= 2048 and height <= 1080\n" - "-> Input image size %d x %d is not compliant\n" - "-> Non-profile-3 codestream will be generated\n", - image->comps[0].w, image->comps[0].h); - return OPJ_FALSE; - } - break; - case OPJ_PROFILE_CINEMA_4K: - if (((image->comps[0].w > 4096) | (image->comps[0].h > 2160))) { - opj_event_msg(p_manager, EVT_WARNING, - "JPEG 2000 Profile-4 (4k dc profile) requires:\n" - "width <= 4096 and height <= 2160\n" - "-> Image size %d x %d is not compliant\n" - "-> Non-profile-4 codestream will be generated\n", - image->comps[0].w, image->comps[0].h); - return OPJ_FALSE; - } - break; - default : - break; + case OPJ_PROFILE_CINEMA_2K: + if (((image->comps[0].w > 2048) | (image->comps[0].h > 1080))) { + opj_event_msg(p_manager, EVT_WARNING, + "JPEG 2000 Profile-3 (2k dc profile) requires:\n" + "width <= 2048 and height <= 1080\n" + "-> Input image size %d x %d is not compliant\n" + "-> Non-profile-3 codestream will be generated\n", + image->comps[0].w, image->comps[0].h); + return OPJ_FALSE; + } + break; + case OPJ_PROFILE_CINEMA_4K: + if (((image->comps[0].w > 4096) | (image->comps[0].h > 2160))) { + opj_event_msg(p_manager, EVT_WARNING, + "JPEG 2000 Profile-4 (4k dc profile) requires:\n" + "width <= 4096 and height <= 2160\n" + "-> Image size %d x %d is not compliant\n" + "-> Non-profile-4 codestream will be generated\n", + image->comps[0].w, image->comps[0].h); + return OPJ_FALSE; + } + break; + default : + break; } return OPJ_TRUE; } static int opj_j2k_get_imf_max_NL(opj_cparameters_t *parameters, - opj_image_t *image) -{ + opj_image_t *image) { /* Decomposition levels */ const OPJ_UINT16 rsiz = parameters->rsiz; const OPJ_UINT16 profile = OPJ_GET_IMF_PROFILE(rsiz); const OPJ_UINT32 XTsiz = parameters->tile_size_on ? (OPJ_UINT32) parameters->cp_tdx : image->x1; switch (profile) { - case OPJ_PROFILE_IMF_2K: - return 5; - case OPJ_PROFILE_IMF_4K: - return 6; - case OPJ_PROFILE_IMF_8K: - return 7; - case OPJ_PROFILE_IMF_2K_R: { - if (XTsiz >= 2048) { + case OPJ_PROFILE_IMF_2K: return 5; - } else if (XTsiz >= 1024) { - return 4; - } - break; - } - case OPJ_PROFILE_IMF_4K_R: { - if (XTsiz >= 4096) { + case OPJ_PROFILE_IMF_4K: return 6; - } else if (XTsiz >= 2048) { - return 5; - } else if (XTsiz >= 1024) { - return 4; - } - break; - } - case OPJ_PROFILE_IMF_8K_R: { - if (XTsiz >= 8192) { + case OPJ_PROFILE_IMF_8K: return 7; - } else if (XTsiz >= 4096) { - return 6; - } else if (XTsiz >= 2048) { - return 5; - } else if (XTsiz >= 1024) { - return 4; + case OPJ_PROFILE_IMF_2K_R: { + if (XTsiz >= 2048) { + return 5; + } else if (XTsiz >= 1024) { + return 4; + } + break; } - break; - } - default: - break; + case OPJ_PROFILE_IMF_4K_R: { + if (XTsiz >= 4096) { + return 6; + } else if (XTsiz >= 2048) { + return 5; + } else if (XTsiz >= 1024) { + return 4; + } + break; + } + case OPJ_PROFILE_IMF_8K_R: { + if (XTsiz >= 8192) { + return 7; + } else if (XTsiz >= 4096) { + return 6; + } else if (XTsiz >= 2048) { + return 5; + } else if (XTsiz >= 1024) { + return 4; + } + break; + } + default: + break; } return -1; } static void opj_j2k_set_imf_parameters(opj_cparameters_t *parameters, - opj_image_t *image, opj_event_mgr_t *p_manager) -{ + opj_image_t *image, opj_event_mgr_t *p_manager) { const OPJ_UINT16 rsiz = parameters->rsiz; const OPJ_UINT16 profile = OPJ_GET_IMF_PROFILE(rsiz); @@ -7236,9 +7142,8 @@ static const OPJ_UINT16 tabMaxSubLevelFromMainLevel[] = { }; static OPJ_BOOL opj_j2k_is_imf_compliant(opj_cparameters_t *parameters, - opj_image_t *image, - opj_event_mgr_t *p_manager) -{ + opj_image_t *image, + opj_event_mgr_t *p_manager) { OPJ_UINT32 i; const OPJ_UINT16 rsiz = parameters->rsiz; const OPJ_UINT16 profile = OPJ_GET_IMF_PROFILE(rsiz); @@ -7400,45 +7305,45 @@ static OPJ_BOOL opj_j2k_is_imf_compliant(opj_cparameters_t *parameters, /* Image size */ switch (profile) { - case OPJ_PROFILE_IMF_2K: - case OPJ_PROFILE_IMF_2K_R: - if (((image->comps[0].w > 2048) | (image->comps[0].h > 1556))) { - opj_event_msg(p_manager, EVT_WARNING, - "IMF 2K/2K_R profile require:\n" - "width <= 2048 and height <= 1556\n" - "-> Input image size %d x %d is not compliant\n" - "-> Non-IMF codestream will be generated\n", - image->comps[0].w, image->comps[0].h); - ret = OPJ_FALSE; - } - break; - case OPJ_PROFILE_IMF_4K: - case OPJ_PROFILE_IMF_4K_R: - if (((image->comps[0].w > 4096) | (image->comps[0].h > 3112))) { - opj_event_msg(p_manager, EVT_WARNING, - "IMF 4K/4K_R profile require:\n" - "width <= 4096 and height <= 3112\n" - "-> Input image size %d x %d is not compliant\n" - "-> Non-IMF codestream will be generated\n", - image->comps[0].w, image->comps[0].h); - ret = OPJ_FALSE; - } - break; - case OPJ_PROFILE_IMF_8K: - case OPJ_PROFILE_IMF_8K_R: - if (((image->comps[0].w > 8192) | (image->comps[0].h > 6224))) { - opj_event_msg(p_manager, EVT_WARNING, - "IMF 8K/8K_R profile require:\n" - "width <= 8192 and height <= 6224\n" - "-> Input image size %d x %d is not compliant\n" - "-> Non-IMF codestream will be generated\n", - image->comps[0].w, image->comps[0].h); - ret = OPJ_FALSE; - } - break; - default : - assert(0); - return OPJ_FALSE; + case OPJ_PROFILE_IMF_2K: + case OPJ_PROFILE_IMF_2K_R: + if (((image->comps[0].w > 2048) | (image->comps[0].h > 1556))) { + opj_event_msg(p_manager, EVT_WARNING, + "IMF 2K/2K_R profile require:\n" + "width <= 2048 and height <= 1556\n" + "-> Input image size %d x %d is not compliant\n" + "-> Non-IMF codestream will be generated\n", + image->comps[0].w, image->comps[0].h); + ret = OPJ_FALSE; + } + break; + case OPJ_PROFILE_IMF_4K: + case OPJ_PROFILE_IMF_4K_R: + if (((image->comps[0].w > 4096) | (image->comps[0].h > 3112))) { + opj_event_msg(p_manager, EVT_WARNING, + "IMF 4K/4K_R profile require:\n" + "width <= 4096 and height <= 3112\n" + "-> Input image size %d x %d is not compliant\n" + "-> Non-IMF codestream will be generated\n", + image->comps[0].w, image->comps[0].h); + ret = OPJ_FALSE; + } + break; + case OPJ_PROFILE_IMF_8K: + case OPJ_PROFILE_IMF_8K_R: + if (((image->comps[0].w > 8192) | (image->comps[0].h > 6224))) { + opj_event_msg(p_manager, EVT_WARNING, + "IMF 8K/8K_R profile require:\n" + "width <= 8192 and height <= 6224\n" + "-> Input image size %d x %d is not compliant\n" + "-> Non-IMF codestream will be generated\n", + image->comps[0].w, image->comps[0].h); + ret = OPJ_FALSE; + } + break; + default : + assert(0); + return OPJ_FALSE; } if (parameters->roi_compno != -1) { @@ -7521,131 +7426,131 @@ static OPJ_BOOL opj_j2k_is_imf_compliant(opj_cparameters_t *parameters, /* Decomposition levels */ switch (profile) { - case OPJ_PROFILE_IMF_2K: - if (!(NL >= 1 && NL <= 5)) { - opj_event_msg(p_manager, EVT_WARNING, - "IMF 2K profile requires 1 <= NL <= 5:\n" - "-> Number of decomposition levels is %d.\n" - "-> Non-IMF codestream will be generated\n", - NL); - ret = OPJ_FALSE; - } - break; - case OPJ_PROFILE_IMF_4K: - if (!(NL >= 1 && NL <= 6)) { - opj_event_msg(p_manager, EVT_WARNING, - "IMF 4K profile requires 1 <= NL <= 6:\n" - "-> Number of decomposition levels is %d.\n" - "-> Non-IMF codestream will be generated\n", - NL); - ret = OPJ_FALSE; - } - break; - case OPJ_PROFILE_IMF_8K: - if (!(NL >= 1 && NL <= 7)) { - opj_event_msg(p_manager, EVT_WARNING, - "IMF 8K profile requires 1 <= NL <= 7:\n" - "-> Number of decomposition levels is %d.\n" - "-> Non-IMF codestream will be generated\n", - NL); - ret = OPJ_FALSE; - } - break; - case OPJ_PROFILE_IMF_2K_R: { - if (XTsiz >= 2048) { + case OPJ_PROFILE_IMF_2K: if (!(NL >= 1 && NL <= 5)) { opj_event_msg(p_manager, EVT_WARNING, - "IMF 2K_R profile requires 1 <= NL <= 5 for XTsiz >= 2048:\n" + "IMF 2K profile requires 1 <= NL <= 5:\n" "-> Number of decomposition levels is %d.\n" "-> Non-IMF codestream will be generated\n", NL); ret = OPJ_FALSE; } - } else if (XTsiz >= 1024) { - if (!(NL >= 1 && NL <= 4)) { - opj_event_msg(p_manager, EVT_WARNING, - "IMF 2K_R profile requires 1 <= NL <= 4 for XTsiz in [1024,2048[:\n" - "-> Number of decomposition levels is %d.\n" - "-> Non-IMF codestream will be generated\n", - NL); - ret = OPJ_FALSE; - } - } - break; - } - case OPJ_PROFILE_IMF_4K_R: { - if (XTsiz >= 4096) { + break; + case OPJ_PROFILE_IMF_4K: if (!(NL >= 1 && NL <= 6)) { opj_event_msg(p_manager, EVT_WARNING, - "IMF 4K_R profile requires 1 <= NL <= 6 for XTsiz >= 4096:\n" + "IMF 4K profile requires 1 <= NL <= 6:\n" "-> Number of decomposition levels is %d.\n" "-> Non-IMF codestream will be generated\n", NL); ret = OPJ_FALSE; } - } else if (XTsiz >= 2048) { - if (!(NL >= 1 && NL <= 5)) { - opj_event_msg(p_manager, EVT_WARNING, - "IMF 4K_R profile requires 1 <= NL <= 5 for XTsiz in [2048,4096[:\n" - "-> Number of decomposition levels is %d.\n" - "-> Non-IMF codestream will be generated\n", - NL); - ret = OPJ_FALSE; - } - } else if (XTsiz >= 1024) { - if (!(NL >= 1 && NL <= 4)) { - opj_event_msg(p_manager, EVT_WARNING, - "IMF 4K_R profile requires 1 <= NL <= 4 for XTsiz in [1024,2048[:\n" - "-> Number of decomposition levels is %d.\n" - "-> Non-IMF codestream will be generated\n", - NL); - ret = OPJ_FALSE; - } - } - break; - } - case OPJ_PROFILE_IMF_8K_R: { - if (XTsiz >= 8192) { + break; + case OPJ_PROFILE_IMF_8K: if (!(NL >= 1 && NL <= 7)) { opj_event_msg(p_manager, EVT_WARNING, - "IMF 4K_R profile requires 1 <= NL <= 7 for XTsiz >= 8192:\n" + "IMF 8K profile requires 1 <= NL <= 7:\n" "-> Number of decomposition levels is %d.\n" "-> Non-IMF codestream will be generated\n", NL); ret = OPJ_FALSE; } - } else if (XTsiz >= 4096) { - if (!(NL >= 1 && NL <= 6)) { - opj_event_msg(p_manager, EVT_WARNING, - "IMF 4K_R profile requires 1 <= NL <= 6 for XTsiz in [4096,8192[:\n" - "-> Number of decomposition levels is %d.\n" - "-> Non-IMF codestream will be generated\n", - NL); - ret = OPJ_FALSE; - } - } else if (XTsiz >= 2048) { - if (!(NL >= 1 && NL <= 5)) { - opj_event_msg(p_manager, EVT_WARNING, - "IMF 4K_R profile requires 1 <= NL <= 5 for XTsiz in [2048,4096[:\n" - "-> Number of decomposition levels is %d.\n" - "-> Non-IMF codestream will be generated\n", - NL); - ret = OPJ_FALSE; - } - } else if (XTsiz >= 1024) { - if (!(NL >= 1 && NL <= 4)) { - opj_event_msg(p_manager, EVT_WARNING, - "IMF 4K_R profile requires 1 <= NL <= 4 for XTsiz in [1024,2048[:\n" - "-> Number of decomposition levels is %d.\n" - "-> Non-IMF codestream will be generated\n", - NL); - ret = OPJ_FALSE; + break; + case OPJ_PROFILE_IMF_2K_R: { + if (XTsiz >= 2048) { + if (!(NL >= 1 && NL <= 5)) { + opj_event_msg(p_manager, EVT_WARNING, + "IMF 2K_R profile requires 1 <= NL <= 5 for XTsiz >= 2048:\n" + "-> Number of decomposition levels is %d.\n" + "-> Non-IMF codestream will be generated\n", + NL); + ret = OPJ_FALSE; + } + } else if (XTsiz >= 1024) { + if (!(NL >= 1 && NL <= 4)) { + opj_event_msg(p_manager, EVT_WARNING, + "IMF 2K_R profile requires 1 <= NL <= 4 for XTsiz in [1024,2048[:\n" + "-> Number of decomposition levels is %d.\n" + "-> Non-IMF codestream will be generated\n", + NL); + ret = OPJ_FALSE; + } } + break; } - break; - } - default: - break; + case OPJ_PROFILE_IMF_4K_R: { + if (XTsiz >= 4096) { + if (!(NL >= 1 && NL <= 6)) { + opj_event_msg(p_manager, EVT_WARNING, + "IMF 4K_R profile requires 1 <= NL <= 6 for XTsiz >= 4096:\n" + "-> Number of decomposition levels is %d.\n" + "-> Non-IMF codestream will be generated\n", + NL); + ret = OPJ_FALSE; + } + } else if (XTsiz >= 2048) { + if (!(NL >= 1 && NL <= 5)) { + opj_event_msg(p_manager, EVT_WARNING, + "IMF 4K_R profile requires 1 <= NL <= 5 for XTsiz in [2048,4096[:\n" + "-> Number of decomposition levels is %d.\n" + "-> Non-IMF codestream will be generated\n", + NL); + ret = OPJ_FALSE; + } + } else if (XTsiz >= 1024) { + if (!(NL >= 1 && NL <= 4)) { + opj_event_msg(p_manager, EVT_WARNING, + "IMF 4K_R profile requires 1 <= NL <= 4 for XTsiz in [1024,2048[:\n" + "-> Number of decomposition levels is %d.\n" + "-> Non-IMF codestream will be generated\n", + NL); + ret = OPJ_FALSE; + } + } + break; + } + case OPJ_PROFILE_IMF_8K_R: { + if (XTsiz >= 8192) { + if (!(NL >= 1 && NL <= 7)) { + opj_event_msg(p_manager, EVT_WARNING, + "IMF 4K_R profile requires 1 <= NL <= 7 for XTsiz >= 8192:\n" + "-> Number of decomposition levels is %d.\n" + "-> Non-IMF codestream will be generated\n", + NL); + ret = OPJ_FALSE; + } + } else if (XTsiz >= 4096) { + if (!(NL >= 1 && NL <= 6)) { + opj_event_msg(p_manager, EVT_WARNING, + "IMF 4K_R profile requires 1 <= NL <= 6 for XTsiz in [4096,8192[:\n" + "-> Number of decomposition levels is %d.\n" + "-> Non-IMF codestream will be generated\n", + NL); + ret = OPJ_FALSE; + } + } else if (XTsiz >= 2048) { + if (!(NL >= 1 && NL <= 5)) { + opj_event_msg(p_manager, EVT_WARNING, + "IMF 4K_R profile requires 1 <= NL <= 5 for XTsiz in [2048,4096[:\n" + "-> Number of decomposition levels is %d.\n" + "-> Non-IMF codestream will be generated\n", + NL); + ret = OPJ_FALSE; + } + } else if (XTsiz >= 1024) { + if (!(NL >= 1 && NL <= 4)) { + opj_event_msg(p_manager, EVT_WARNING, + "IMF 4K_R profile requires 1 <= NL <= 4 for XTsiz in [1024,2048[:\n" + "-> Number of decomposition levels is %d.\n" + "-> Non-IMF codestream will be generated\n", + NL); + ret = OPJ_FALSE; + } + } + break; + } + default: + break; } if (parameters->numresolution == 1) { @@ -7679,8 +7584,7 @@ static OPJ_BOOL opj_j2k_is_imf_compliant(opj_cparameters_t *parameters, OPJ_BOOL opj_j2k_setup_encoder(opj_j2k_t *p_j2k, opj_cparameters_t *parameters, opj_image_t *image, - opj_event_mgr_t * p_manager) -{ + opj_event_mgr_t *p_manager) { OPJ_UINT32 i, j, tileno, numpocs_tile; opj_cp_t *cp = 00; OPJ_UINT32 cblkw, cblkh; @@ -7764,43 +7668,43 @@ OPJ_BOOL opj_j2k_setup_encoder(opj_j2k_t *p_j2k, OPJ_PROFILE_NONE) { /* consider deprecated fields only if RSIZ has not been set */ OPJ_BOOL deprecated_used = OPJ_FALSE; switch (parameters->cp_cinema) { - case OPJ_CINEMA2K_24: - parameters->rsiz = OPJ_PROFILE_CINEMA_2K; - parameters->max_cs_size = OPJ_CINEMA_24_CS; - parameters->max_comp_size = OPJ_CINEMA_24_COMP; - deprecated_used = OPJ_TRUE; - break; - case OPJ_CINEMA2K_48: - parameters->rsiz = OPJ_PROFILE_CINEMA_2K; - parameters->max_cs_size = OPJ_CINEMA_48_CS; - parameters->max_comp_size = OPJ_CINEMA_48_COMP; - deprecated_used = OPJ_TRUE; - break; - case OPJ_CINEMA4K_24: - parameters->rsiz = OPJ_PROFILE_CINEMA_4K; - parameters->max_cs_size = OPJ_CINEMA_24_CS; - parameters->max_comp_size = OPJ_CINEMA_24_COMP; - deprecated_used = OPJ_TRUE; - break; - case OPJ_OFF: - default: - break; + case OPJ_CINEMA2K_24: + parameters->rsiz = OPJ_PROFILE_CINEMA_2K; + parameters->max_cs_size = OPJ_CINEMA_24_CS; + parameters->max_comp_size = OPJ_CINEMA_24_COMP; + deprecated_used = OPJ_TRUE; + break; + case OPJ_CINEMA2K_48: + parameters->rsiz = OPJ_PROFILE_CINEMA_2K; + parameters->max_cs_size = OPJ_CINEMA_48_CS; + parameters->max_comp_size = OPJ_CINEMA_48_COMP; + deprecated_used = OPJ_TRUE; + break; + case OPJ_CINEMA4K_24: + parameters->rsiz = OPJ_PROFILE_CINEMA_4K; + parameters->max_cs_size = OPJ_CINEMA_24_CS; + parameters->max_comp_size = OPJ_CINEMA_24_COMP; + deprecated_used = OPJ_TRUE; + break; + case OPJ_OFF: + default: + break; } switch (parameters->cp_rsiz) { - case OPJ_CINEMA2K: - parameters->rsiz = OPJ_PROFILE_CINEMA_2K; - deprecated_used = OPJ_TRUE; - break; - case OPJ_CINEMA4K: - parameters->rsiz = OPJ_PROFILE_CINEMA_4K; - deprecated_used = OPJ_TRUE; - break; - case OPJ_MCT: - parameters->rsiz = OPJ_PROFILE_PART2 | OPJ_EXTENSION_MCT; - deprecated_used = OPJ_TRUE; - case OPJ_STD_RSIZ: - default: - break; + case OPJ_CINEMA2K: + parameters->rsiz = OPJ_PROFILE_CINEMA_2K; + deprecated_used = OPJ_TRUE; + break; + case OPJ_CINEMA4K: + parameters->rsiz = OPJ_PROFILE_CINEMA_4K; + deprecated_used = OPJ_TRUE; + break; + case OPJ_MCT: + parameters->rsiz = OPJ_PROFILE_PART2 | OPJ_EXTENSION_MCT; + deprecated_used = OPJ_TRUE; + case OPJ_STD_RSIZ: + default: + break; } if (deprecated_used) { opj_event_msg(p_manager, EVT_WARNING, @@ -7895,9 +7799,9 @@ OPJ_BOOL opj_j2k_setup_encoder(opj_j2k_t *p_j2k, if (OPJ_IS_IMF(parameters->rsiz) && parameters->max_cs_size > 0 && parameters->tcp_numlayers == 1 && parameters->tcp_rates[0] == 0) { parameters->tcp_rates[0] = (OPJ_FLOAT32)(image->numcomps * image->comps[0].w * - image->comps[0].h * image->comps[0].prec) / + image->comps[0].h * image->comps[0].prec) / (OPJ_FLOAT32)(((OPJ_UINT32)parameters->max_cs_size) * 8 * image->comps[0].dx * - image->comps[0].dy); + image->comps[0].dy); } temp_rate = (OPJ_FLOAT32)(((double)image->numcomps * image->comps[0].w * @@ -7967,7 +7871,7 @@ OPJ_BOOL opj_j2k_setup_encoder(opj_j2k_t *p_j2k, copy user encoding parameters */ cp->m_specific_param.m_enc.m_max_comp_size = (OPJ_UINT32) - parameters->max_comp_size; + parameters->max_comp_size; cp->rsiz = parameters->rsiz; if (parameters->cp_fixed_alloc) { cp->m_specific_param.m_enc.m_quality_layer_alloc_strategy = FIXED_LAYER; @@ -8002,7 +7906,7 @@ OPJ_BOOL opj_j2k_setup_encoder(opj_j2k_t *p_j2k, /* comment string */ if (parameters->cp_comment) { - cp->comment = (char*)opj_malloc(strlen(parameters->cp_comment) + 1U); + cp->comment = (char *)opj_malloc(strlen(parameters->cp_comment) + 1U); if (!cp->comment) { opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to allocate copy of comment string\n"); @@ -8018,7 +7922,7 @@ OPJ_BOOL opj_j2k_setup_encoder(opj_j2k_t *p_j2k, /* UniPG>> */ #ifdef USE_JPWL const size_t cp_comment_buf_size = clen + strlen(version) + 11; - cp->comment = (char*)opj_malloc(cp_comment_buf_size); + cp->comment = (char *)opj_malloc(cp_comment_buf_size); if (!cp->comment) { opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to allocate comment string\n"); @@ -8028,7 +7932,7 @@ OPJ_BOOL opj_j2k_setup_encoder(opj_j2k_t *p_j2k, comment, version); #else const size_t cp_comment_buf_size = clen + strlen(version) + 1; - cp->comment = (char*)opj_malloc(cp_comment_buf_size); + cp->comment = (char *)opj_malloc(cp_comment_buf_size); if (!cp->comment) { opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to allocate comment string\n"); @@ -8130,7 +8034,7 @@ OPJ_BOOL opj_j2k_setup_encoder(opj_j2k_t *p_j2k, /* initialize the multiple tiles */ /* ---------------------------- */ const size_t num_tiles = (size_t)cp->tw * (size_t)cp->th; - cp->tcps = (opj_tcp_t*) opj_calloc(num_tiles, sizeof(opj_tcp_t)); + cp->tcps = (opj_tcp_t *) opj_calloc(num_tiles, sizeof(opj_tcp_t)); if (!cp->tcps) { opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to allocate tile coding parameters\n"); @@ -8209,7 +8113,7 @@ OPJ_BOOL opj_j2k_setup_encoder(opj_j2k_t *p_j2k, tcp->numpocs = 0; } - tcp->tccps = (opj_tccp_t*) opj_calloc(image->numcomps, sizeof(opj_tccp_t)); + tcp->tccps = (opj_tccp_t *) opj_calloc(image->numcomps, sizeof(opj_tccp_t)); if (!tcp->tccps) { opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to allocate tile component coding parameters\n"); @@ -8219,9 +8123,9 @@ OPJ_BOOL opj_j2k_setup_encoder(opj_j2k_t *p_j2k, OPJ_UINT32 lMctSize = image->numcomps * image->numcomps * (OPJ_UINT32)sizeof( OPJ_FLOAT32); - OPJ_FLOAT32 * lTmpBuf = (OPJ_FLOAT32*)opj_malloc(lMctSize); - OPJ_INT32 * l_dc_shift = (OPJ_INT32 *)((OPJ_BYTE *) parameters->mct_data + - lMctSize); + OPJ_FLOAT32 *lTmpBuf = (OPJ_FLOAT32 *)opj_malloc(lMctSize); + OPJ_INT32 *l_dc_shift = (OPJ_INT32 *)((OPJ_BYTE *) parameters->mct_data + + lMctSize); if (!lTmpBuf) { opj_event_msg(p_manager, EVT_ERROR, @@ -8230,7 +8134,7 @@ OPJ_BOOL opj_j2k_setup_encoder(opj_j2k_t *p_j2k, } tcp->mct = 2; - tcp->m_mct_coding_matrix = (OPJ_FLOAT32*)opj_malloc(lMctSize); + tcp->m_mct_coding_matrix = (OPJ_FLOAT32 *)opj_malloc(lMctSize); if (! tcp->m_mct_coding_matrix) { opj_free(lTmpBuf); lTmpBuf = NULL; @@ -8241,7 +8145,7 @@ OPJ_BOOL opj_j2k_setup_encoder(opj_j2k_t *p_j2k, memcpy(tcp->m_mct_coding_matrix, parameters->mct_data, lMctSize); memcpy(lTmpBuf, parameters->mct_data, lMctSize); - tcp->m_mct_decoding_matrix = (OPJ_FLOAT32*)opj_malloc(lMctSize); + tcp->m_mct_decoding_matrix = (OPJ_FLOAT32 *)opj_malloc(lMctSize); if (! tcp->m_mct_decoding_matrix) { opj_free(lTmpBuf); lTmpBuf = NULL; @@ -8258,7 +8162,7 @@ OPJ_BOOL opj_j2k_setup_encoder(opj_j2k_t *p_j2k, return OPJ_FALSE; } - tcp->mct_norms = (OPJ_FLOAT64*) + tcp->mct_norms = (OPJ_FLOAT64 *) opj_malloc(image->numcomps * sizeof(OPJ_FLOAT64)); if (! tcp->mct_norms) { opj_free(lTmpBuf); @@ -8294,7 +8198,7 @@ OPJ_BOOL opj_j2k_setup_encoder(opj_j2k_t *p_j2k, } for (i = 0; i < image->numcomps; i++) { opj_tccp_t *tccp = &tcp->tccps[i]; - opj_image_comp_t * l_comp = &(image->comps[i]); + opj_image_comp_t *l_comp = &(image->comps[i]); if (! l_comp->sgnd) { tccp->m_dc_level_shift = 1 << (l_comp->prec - 1); @@ -8391,8 +8295,7 @@ OPJ_BOOL opj_j2k_setup_encoder(opj_j2k_t *p_j2k, } static OPJ_BOOL opj_j2k_add_mhmarker(opj_codestream_index_t *cstr_index, - OPJ_UINT32 type, OPJ_OFF_T pos, OPJ_UINT32 len) -{ + OPJ_UINT32 type, OPJ_OFF_T pos, OPJ_UINT32 len) { assert(cstr_index != 00); /* expand the list? */ @@ -8401,7 +8304,7 @@ static OPJ_BOOL opj_j2k_add_mhmarker(opj_codestream_index_t *cstr_index, cstr_index->maxmarknum = (OPJ_UINT32)(100 + (OPJ_FLOAT32) cstr_index->maxmarknum); new_marker = (opj_marker_info_t *) opj_realloc(cstr_index->marker, - cstr_index->maxmarknum * sizeof(opj_marker_info_t)); + cstr_index->maxmarknum * sizeof(opj_marker_info_t)); if (! new_marker) { opj_free(cstr_index->marker); cstr_index->marker = NULL; @@ -8423,8 +8326,7 @@ static OPJ_BOOL opj_j2k_add_mhmarker(opj_codestream_index_t *cstr_index, static OPJ_BOOL opj_j2k_add_tlmarker(OPJ_UINT32 tileno, opj_codestream_index_t *cstr_index, OPJ_UINT32 type, OPJ_OFF_T pos, - OPJ_UINT32 len) -{ + OPJ_UINT32 len) { assert(cstr_index != 00); assert(cstr_index->tile_index != 00); @@ -8433,7 +8335,7 @@ static OPJ_BOOL opj_j2k_add_tlmarker(OPJ_UINT32 tileno, cstr_index->tile_index[tileno].maxmarknum) { opj_marker_info_t *new_marker; cstr_index->tile_index[tileno].maxmarknum = (OPJ_UINT32)(100 + - (OPJ_FLOAT32) cstr_index->tile_index[tileno].maxmarknum); + (OPJ_FLOAT32) cstr_index->tile_index[tileno].maxmarknum); new_marker = (opj_marker_info_t *) opj_realloc( cstr_index->tile_index[tileno].marker, cstr_index->tile_index[tileno].maxmarknum * sizeof(opj_marker_info_t)); @@ -8477,9 +8379,8 @@ static OPJ_BOOL opj_j2k_add_tlmarker(OPJ_UINT32 tileno, OPJ_BOOL opj_j2k_end_decompress(opj_j2k_t *p_j2k, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager - ) -{ + opj_event_mgr_t *p_manager + ) { (void)p_j2k; (void)p_stream; (void)p_manager; @@ -8487,10 +8388,9 @@ OPJ_BOOL opj_j2k_end_decompress(opj_j2k_t *p_j2k, } OPJ_BOOL opj_j2k_read_header(opj_stream_private_t *p_stream, - opj_j2k_t* p_j2k, - opj_image_t** p_image, - opj_event_mgr_t* p_manager) -{ + opj_j2k_t *p_j2k, + opj_image_t **p_image, + opj_event_mgr_t *p_manager) { /* preconditions */ assert(p_j2k != 00); assert(p_stream != 00); @@ -8542,8 +8442,7 @@ OPJ_BOOL opj_j2k_read_header(opj_stream_private_t *p_stream, } static OPJ_BOOL opj_j2k_setup_header_reading(opj_j2k_t *p_j2k, - opj_event_mgr_t * p_manager) -{ + opj_event_mgr_t *p_manager) { /* preconditions*/ assert(p_j2k != 00); assert(p_manager != 00); @@ -8563,8 +8462,7 @@ static OPJ_BOOL opj_j2k_setup_header_reading(opj_j2k_t *p_j2k, } static OPJ_BOOL opj_j2k_setup_decoding_validation(opj_j2k_t *p_j2k, - opj_event_mgr_t * p_manager) -{ + opj_event_mgr_t *p_manager) { /* preconditions*/ assert(p_j2k != 00); assert(p_manager != 00); @@ -8582,10 +8480,9 @@ static OPJ_BOOL opj_j2k_setup_decoding_validation(opj_j2k_t *p_j2k, return OPJ_TRUE; } -static OPJ_BOOL opj_j2k_mct_validation(opj_j2k_t * p_j2k, +static OPJ_BOOL opj_j2k_mct_validation(opj_j2k_t *p_j2k, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager) -{ + opj_event_mgr_t *p_manager) { OPJ_BOOL l_is_valid = OPJ_TRUE; OPJ_UINT32 i, j; @@ -8599,11 +8496,11 @@ static OPJ_BOOL opj_j2k_mct_validation(opj_j2k_t * p_j2k, if ((p_j2k->m_cp.rsiz & 0x8200) == 0x8200) { OPJ_UINT32 l_nb_tiles = p_j2k->m_cp.th * p_j2k->m_cp.tw; - opj_tcp_t * l_tcp = p_j2k->m_cp.tcps; + opj_tcp_t *l_tcp = p_j2k->m_cp.tcps; for (i = 0; i < l_nb_tiles; ++i) { if (l_tcp->mct == 2) { - opj_tccp_t * l_tccp = l_tcp->tccps; + opj_tccp_t *l_tccp = l_tcp->tccps; l_is_valid &= (l_tcp->m_mct_coding_matrix != 00); for (j = 0; j < p_j2k->m_private_image->numcomps; ++j) { @@ -8618,15 +8515,14 @@ static OPJ_BOOL opj_j2k_mct_validation(opj_j2k_t * p_j2k, return l_is_valid; } -OPJ_BOOL opj_j2k_setup_mct_encoding(opj_tcp_t * p_tcp, opj_image_t * p_image) -{ +OPJ_BOOL opj_j2k_setup_mct_encoding(opj_tcp_t *p_tcp, opj_image_t *p_image) { OPJ_UINT32 i; OPJ_UINT32 l_indix = 1; - opj_mct_data_t * l_mct_deco_data = 00, * l_mct_offset_data = 00; - opj_simple_mcc_decorrelation_data_t * l_mcc_data; + opj_mct_data_t *l_mct_deco_data = 00, * l_mct_offset_data = 00; + opj_simple_mcc_decorrelation_data_t *l_mcc_data; OPJ_UINT32 l_mct_size, l_nb_elem; - OPJ_FLOAT32 * l_data, * l_current_data; - opj_tccp_t * l_tccp; + OPJ_FLOAT32 *l_data, * l_current_data; + opj_tccp_t *l_tccp; /* preconditions */ assert(p_tcp != 00); @@ -8641,7 +8537,7 @@ OPJ_BOOL opj_j2k_setup_mct_encoding(opj_tcp_t * p_tcp, opj_image_t * p_image) p_tcp->m_nb_max_mct_records += OPJ_J2K_MCT_DEFAULT_NB_RECORDS; new_mct_records = (opj_mct_data_t *) opj_realloc(p_tcp->m_mct_records, - p_tcp->m_nb_max_mct_records * sizeof(opj_mct_data_t)); + p_tcp->m_nb_max_mct_records * sizeof(opj_mct_data_t)); if (! new_mct_records) { opj_free(p_tcp->m_mct_records); p_tcp->m_mct_records = NULL; @@ -8669,7 +8565,7 @@ OPJ_BOOL opj_j2k_setup_mct_encoding(opj_tcp_t * p_tcp, opj_image_t * p_image) l_mct_deco_data->m_element_type = MCT_TYPE_FLOAT; l_nb_elem = p_image->numcomps * p_image->numcomps; l_mct_size = l_nb_elem * MCT_ELEMENT_SIZE[l_mct_deco_data->m_element_type]; - l_mct_deco_data->m_data = (OPJ_BYTE*)opj_malloc(l_mct_size); + l_mct_deco_data->m_data = (OPJ_BYTE *)opj_malloc(l_mct_size); if (! l_mct_deco_data->m_data) { return OPJ_FALSE; @@ -8686,7 +8582,7 @@ OPJ_BOOL opj_j2k_setup_mct_encoding(opj_tcp_t * p_tcp, opj_image_t * p_image) opj_mct_data_t *new_mct_records; p_tcp->m_nb_max_mct_records += OPJ_J2K_MCT_DEFAULT_NB_RECORDS; new_mct_records = (opj_mct_data_t *) opj_realloc(p_tcp->m_mct_records, - p_tcp->m_nb_max_mct_records * sizeof(opj_mct_data_t)); + p_tcp->m_nb_max_mct_records * sizeof(opj_mct_data_t)); if (! new_mct_records) { opj_free(p_tcp->m_mct_records); p_tcp->m_mct_records = NULL; @@ -8719,13 +8615,13 @@ OPJ_BOOL opj_j2k_setup_mct_encoding(opj_tcp_t * p_tcp, opj_image_t * p_image) l_mct_offset_data->m_element_type = MCT_TYPE_FLOAT; l_nb_elem = p_image->numcomps; l_mct_size = l_nb_elem * MCT_ELEMENT_SIZE[l_mct_offset_data->m_element_type]; - l_mct_offset_data->m_data = (OPJ_BYTE*)opj_malloc(l_mct_size); + l_mct_offset_data->m_data = (OPJ_BYTE *)opj_malloc(l_mct_size); if (! l_mct_offset_data->m_data) { return OPJ_FALSE; } - l_data = (OPJ_FLOAT32*)opj_malloc(l_nb_elem * sizeof(OPJ_FLOAT32)); + l_data = (OPJ_FLOAT32 *)opj_malloc(l_nb_elem * sizeof(OPJ_FLOAT32)); if (! l_data) { opj_free(l_mct_offset_data->m_data); l_mct_offset_data->m_data = 00; @@ -8781,10 +8677,9 @@ OPJ_BOOL opj_j2k_setup_mct_encoding(opj_tcp_t * p_tcp, opj_image_t * p_image) return OPJ_TRUE; } -static OPJ_BOOL opj_j2k_build_decoder(opj_j2k_t * p_j2k, +static OPJ_BOOL opj_j2k_build_decoder(opj_j2k_t *p_j2k, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager) -{ + opj_event_mgr_t *p_manager) { /* add here initialization of cp copy paste of setup_decoder */ (void)p_j2k; @@ -8793,10 +8688,9 @@ static OPJ_BOOL opj_j2k_build_decoder(opj_j2k_t * p_j2k, return OPJ_TRUE; } -static OPJ_BOOL opj_j2k_build_encoder(opj_j2k_t * p_j2k, +static OPJ_BOOL opj_j2k_build_encoder(opj_j2k_t *p_j2k, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager) -{ + opj_event_mgr_t *p_manager) { /* add here initialization of cp copy paste of setup_encoder */ (void)p_j2k; @@ -8805,10 +8699,9 @@ static OPJ_BOOL opj_j2k_build_encoder(opj_j2k_t * p_j2k, return OPJ_TRUE; } -static OPJ_BOOL opj_j2k_encoding_validation(opj_j2k_t * p_j2k, - opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager) -{ +static OPJ_BOOL opj_j2k_encoding_validation(opj_j2k_t *p_j2k, + opj_stream_private_t *p_stream, + opj_event_mgr_t *p_manager) { OPJ_BOOL l_is_valid = OPJ_TRUE; /* preconditions */ @@ -8857,10 +8750,9 @@ static OPJ_BOOL opj_j2k_encoding_validation(opj_j2k_t * p_j2k, } static OPJ_BOOL opj_j2k_decoding_validation(opj_j2k_t *p_j2k, - opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager - ) -{ + opj_stream_private_t *p_stream, + opj_event_mgr_t *p_manager + ) { OPJ_BOOL l_is_valid = OPJ_TRUE; /* preconditions*/ @@ -8890,10 +8782,9 @@ static OPJ_BOOL opj_j2k_decoding_validation(opj_j2k_t *p_j2k, } /** Fill p_j2k->cstr_index->tp_index[].start_pos/end_pos fields from TLM marker segments */ -static void opj_j2k_build_tp_index_from_tlm(opj_j2k_t* p_j2k, - opj_event_mgr_t * p_manager) -{ - opj_j2k_tlm_info_t* l_tlm; +static void opj_j2k_build_tp_index_from_tlm(opj_j2k_t *p_j2k, + opj_event_mgr_t *p_manager) { + opj_j2k_tlm_info_t *l_tlm; OPJ_UINT32 i; OPJ_OFF_T l_cur_offset; @@ -8934,7 +8825,7 @@ static void opj_j2k_build_tp_index_from_tlm(opj_j2k_t* p_j2k, l_cur_offset = p_j2k->cstr_index->main_head_end; for (i = 0; i < l_tlm->m_entries_count; ++i) { OPJ_UINT32 l_tile_index_no = l_tlm->m_tile_part_infos[i].m_tile_index; - opj_tile_index_t* l_tile_index = & + opj_tile_index_t *l_tile_index = & (p_j2k->cstr_index->tile_index[l_tile_index_no]); if (!l_tile_index->tp_index) { l_tile_index->tp_index = (opj_tp_index_t *) opj_calloc( @@ -8952,7 +8843,7 @@ static void opj_j2k_build_tp_index_from_tlm(opj_j2k_t* p_j2k, /* If there would be no markers between SOT and SOD, that would be : */ /* l_tile_index->tp_index[l_tile_index->nb_tps].end_header = l_cur_offset + 12; */ l_tile_index->tp_index[l_tile_index->nb_tps].end_pos = l_cur_offset + - l_tlm->m_tile_part_infos[i].m_length; + l_tlm->m_tile_part_infos[i].m_length; ++l_tile_index->nb_tps; l_cur_offset += l_tlm->m_tile_part_infos[i].m_length; @@ -8971,12 +8862,11 @@ error: } static OPJ_BOOL opj_j2k_read_header_procedure(opj_j2k_t *p_j2k, - opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager) -{ + opj_stream_private_t *p_stream, + opj_event_mgr_t *p_manager) { OPJ_UINT32 l_current_marker; OPJ_UINT32 l_marker_size; - const opj_dec_memory_marker_handler_t * l_marker_handler = 00; + const opj_dec_memory_marker_handler_t *l_marker_handler = 00; OPJ_BOOL l_has_siz = 0; OPJ_BOOL l_has_cod = 0; OPJ_BOOL l_has_qcd = 0; @@ -9158,11 +9048,10 @@ static OPJ_BOOL opj_j2k_read_header_procedure(opj_j2k_t *p_j2k, return OPJ_TRUE; } -static OPJ_BOOL opj_j2k_exec(opj_j2k_t * p_j2k, - opj_procedure_list_t * p_procedure_list, +static OPJ_BOOL opj_j2k_exec(opj_j2k_t *p_j2k, + opj_procedure_list_t *p_procedure_list, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager) -{ + opj_event_mgr_t *p_manager) { OPJ_BOOL(** l_procedure)(opj_j2k_t *, opj_stream_private_t *, opj_event_mgr_t *) = 00; OPJ_BOOL l_result = OPJ_TRUE; @@ -9175,8 +9064,8 @@ static OPJ_BOOL opj_j2k_exec(opj_j2k_t * p_j2k, assert(p_manager != 00); l_nb_proc = opj_procedure_list_get_nb_procedures(p_procedure_list); - l_procedure = (OPJ_BOOL(**)(opj_j2k_t *, opj_stream_private_t *, - opj_event_mgr_t *)) opj_procedure_list_get_first_procedure(p_procedure_list); + l_procedure = (OPJ_BOOL(* *)(opj_j2k_t *, opj_stream_private_t *, + opj_event_mgr_t *)) opj_procedure_list_get_first_procedure(p_procedure_list); for (i = 0; i < l_nb_proc; ++i) { l_result = l_result && ((*l_procedure)(p_j2k, p_stream, p_manager)); @@ -9189,22 +9078,21 @@ static OPJ_BOOL opj_j2k_exec(opj_j2k_t * p_j2k, } /* FIXME DOC*/ -static OPJ_BOOL opj_j2k_copy_default_tcp_and_create_tcd(opj_j2k_t * p_j2k, - opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager - ) -{ - opj_tcp_t * l_tcp = 00; - opj_tcp_t * l_default_tcp = 00; +static OPJ_BOOL opj_j2k_copy_default_tcp_and_create_tcd(opj_j2k_t *p_j2k, + opj_stream_private_t *p_stream, + opj_event_mgr_t *p_manager + ) { + opj_tcp_t *l_tcp = 00; + opj_tcp_t *l_default_tcp = 00; OPJ_UINT32 l_nb_tiles; OPJ_UINT32 i, j; opj_tccp_t *l_current_tccp = 00; OPJ_UINT32 l_tccp_size; OPJ_UINT32 l_mct_size; - opj_image_t * l_image; + opj_image_t *l_image; OPJ_UINT32 l_mcc_records_size, l_mct_records_size; - opj_mct_data_t * l_src_mct_rec, *l_dest_mct_rec; - opj_simple_mcc_decorrelation_data_t * l_src_mcc_rec, *l_dest_mcc_rec; + opj_mct_data_t *l_src_mct_rec, *l_dest_mct_rec; + opj_simple_mcc_decorrelation_data_t *l_src_mcc_rec, *l_dest_mcc_rec; OPJ_UINT32 l_offset; /* preconditions */ @@ -9244,7 +9132,7 @@ static OPJ_BOOL opj_j2k_copy_default_tcp_and_create_tcd(opj_j2k_t * p_j2k, /* Get the mct_decoding_matrix of the dflt_tile_cp and copy them into the current tile cp*/ if (l_default_tcp->m_mct_decoding_matrix) { - l_tcp->m_mct_decoding_matrix = (OPJ_FLOAT32*)opj_malloc(l_mct_size); + l_tcp->m_mct_decoding_matrix = (OPJ_FLOAT32 *)opj_malloc(l_mct_size); if (! l_tcp->m_mct_decoding_matrix) { return OPJ_FALSE; } @@ -9255,7 +9143,7 @@ static OPJ_BOOL opj_j2k_copy_default_tcp_and_create_tcd(opj_j2k_t * p_j2k, /* Get the mct_record of the dflt_tile_cp and copy them into the current tile cp*/ l_mct_records_size = l_default_tcp->m_nb_max_mct_records * (OPJ_UINT32)sizeof( opj_mct_data_t); - l_tcp->m_mct_records = (opj_mct_data_t*)opj_malloc(l_mct_records_size); + l_tcp->m_mct_records = (opj_mct_data_t *)opj_malloc(l_mct_records_size); if (! l_tcp->m_mct_records) { return OPJ_FALSE; } @@ -9269,7 +9157,7 @@ static OPJ_BOOL opj_j2k_copy_default_tcp_and_create_tcd(opj_j2k_t * p_j2k, if (l_src_mct_rec->m_data) { - l_dest_mct_rec->m_data = (OPJ_BYTE*) opj_malloc(l_src_mct_rec->m_data_size); + l_dest_mct_rec->m_data = (OPJ_BYTE *) opj_malloc(l_src_mct_rec->m_data_size); if (! l_dest_mct_rec->m_data) { return OPJ_FALSE; } @@ -9286,7 +9174,7 @@ static OPJ_BOOL opj_j2k_copy_default_tcp_and_create_tcd(opj_j2k_t * p_j2k, /* Get the mcc_record of the dflt_tile_cp and copy them into the current tile cp*/ l_mcc_records_size = l_default_tcp->m_nb_max_mcc_records * (OPJ_UINT32)sizeof( opj_simple_mcc_decorrelation_data_t); - l_tcp->m_mcc_records = (opj_simple_mcc_decorrelation_data_t*) opj_malloc( + l_tcp->m_mcc_records = (opj_simple_mcc_decorrelation_data_t *) opj_malloc( l_mcc_records_size); if (! l_tcp->m_mcc_records) { return OPJ_FALSE; @@ -9339,9 +9227,8 @@ static OPJ_BOOL opj_j2k_copy_default_tcp_and_create_tcd(opj_j2k_t * p_j2k, return OPJ_TRUE; } -static const opj_dec_memory_marker_handler_t * opj_j2k_get_marker_handler( - OPJ_UINT32 p_id) -{ +static const opj_dec_memory_marker_handler_t *opj_j2k_get_marker_handler( + OPJ_UINT32 p_id) { const opj_dec_memory_marker_handler_t *e; for (e = j2k_memory_marker_handler_tab; e->id != 0; ++e) { if (e->id == p_id) { @@ -9351,8 +9238,7 @@ static const opj_dec_memory_marker_handler_t * opj_j2k_get_marker_handler( return e; } -void opj_j2k_destroy(opj_j2k_t *p_j2k) -{ +void opj_j2k_destroy(opj_j2k_t *p_j2k) { if (p_j2k == 00) { return; } @@ -9427,8 +9313,7 @@ void opj_j2k_destroy(opj_j2k_t *p_j2k) opj_free(p_j2k); } -void j2k_destroy_cstr_index(opj_codestream_index_t *p_cstr_ind) -{ +void j2k_destroy_cstr_index(opj_codestream_index_t *p_cstr_ind) { if (p_cstr_ind) { if (p_cstr_ind->marker) { @@ -9466,8 +9351,7 @@ void j2k_destroy_cstr_index(opj_codestream_index_t *p_cstr_ind) } } -static void opj_j2k_tcp_destroy(opj_tcp_t *p_tcp) -{ +static void opj_j2k_tcp_destroy(opj_tcp_t *p_tcp) { if (p_tcp == 00) { return; } @@ -9512,7 +9396,7 @@ static void opj_j2k_tcp_destroy(opj_tcp_t *p_tcp) } if (p_tcp->m_mct_records) { - opj_mct_data_t * l_mct_data = p_tcp->m_mct_records; + opj_mct_data_t *l_mct_data = p_tcp->m_mct_records; OPJ_UINT32 i; for (i = 0; i < p_tcp->m_nb_mct_records; ++i) { @@ -9537,8 +9421,7 @@ static void opj_j2k_tcp_destroy(opj_tcp_t *p_tcp) } -static void opj_j2k_tcp_data_destroy(opj_tcp_t *p_tcp) -{ +static void opj_j2k_tcp_data_destroy(opj_tcp_t *p_tcp) { if (p_tcp->m_data) { opj_free(p_tcp->m_data); p_tcp->m_data = NULL; @@ -9546,10 +9429,9 @@ static void opj_j2k_tcp_data_destroy(opj_tcp_t *p_tcp) } } -static void opj_j2k_cp_destroy(opj_cp_t *p_cp) -{ +static void opj_j2k_cp_destroy(opj_cp_t *p_cp) { OPJ_UINT32 l_nb_tiles; - opj_tcp_t * l_current_tile = 00; + opj_tcp_t *l_current_tile = 00; if (p_cp == 00) { return; @@ -9590,9 +9472,8 @@ static void opj_j2k_cp_destroy(opj_cp_t *p_cp) } static OPJ_BOOL opj_j2k_need_nb_tile_parts_correction(opj_stream_private_t - *p_stream, OPJ_UINT32 tile_no, OPJ_BOOL* p_correction_needed, - opj_event_mgr_t * p_manager) -{ + *p_stream, OPJ_UINT32 tile_no, OPJ_BOOL *p_correction_needed, + opj_event_mgr_t *p_manager) { OPJ_BYTE l_header_data[10]; OPJ_OFF_T l_stream_pos_backup; OPJ_UINT32 l_current_marker; @@ -9697,20 +9578,19 @@ static OPJ_BOOL opj_j2k_need_nb_tile_parts_correction(opj_stream_private_t return OPJ_TRUE; } -OPJ_BOOL opj_j2k_read_tile_header(opj_j2k_t * p_j2k, - OPJ_UINT32 * p_tile_index, - OPJ_UINT32 * p_data_size, - OPJ_INT32 * p_tile_x0, OPJ_INT32 * p_tile_y0, - OPJ_INT32 * p_tile_x1, OPJ_INT32 * p_tile_y1, - OPJ_UINT32 * p_nb_comps, - OPJ_BOOL * p_go_on, +OPJ_BOOL opj_j2k_read_tile_header(opj_j2k_t *p_j2k, + OPJ_UINT32 *p_tile_index, + OPJ_UINT32 *p_data_size, + OPJ_INT32 *p_tile_x0, OPJ_INT32 *p_tile_y0, + OPJ_INT32 *p_tile_x1, OPJ_INT32 *p_tile_y1, + OPJ_UINT32 *p_nb_comps, + OPJ_BOOL *p_go_on, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager) -{ + opj_event_mgr_t *p_manager) { OPJ_UINT32 l_current_marker = J2K_MS_SOT; OPJ_UINT32 l_marker_size; - const opj_dec_memory_marker_handler_t * l_marker_handler = 00; - opj_tcp_t * l_tcp = NULL; + const opj_dec_memory_marker_handler_t *l_marker_handler = 00; + opj_tcp_t *l_tcp = NULL; const OPJ_UINT32 l_nb_tiles = p_j2k->m_cp.tw * p_j2k->m_cp.th; /* preconditions */ @@ -9984,7 +9864,7 @@ OPJ_BOOL opj_j2k_read_tile_header(opj_j2k_t * p_j2k, * https://lists.osgeo.org/pipermail/gdal-dev/2024-November/059805.html */ } else if (!opj_j2k_need_nb_tile_parts_correction(p_stream, - p_j2k->m_current_tile_number, &l_correction_needed, p_manager)) { + p_j2k->m_current_tile_number, &l_correction_needed, p_manager)) { opj_event_msg(p_manager, EVT_ERROR, "opj_j2k_apply_nb_tile_parts_correction error\n"); return OPJ_FALSE; @@ -10109,17 +9989,16 @@ OPJ_BOOL opj_j2k_read_tile_header(opj_j2k_t * p_j2k, return OPJ_TRUE; } -OPJ_BOOL opj_j2k_decode_tile(opj_j2k_t * p_j2k, +OPJ_BOOL opj_j2k_decode_tile(opj_j2k_t *p_j2k, OPJ_UINT32 p_tile_index, - OPJ_BYTE * p_data, + OPJ_BYTE *p_data, OPJ_UINT32 p_data_size, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager) -{ + opj_event_mgr_t *p_manager) { OPJ_UINT32 l_current_marker; OPJ_BYTE l_data [2]; - opj_tcp_t * l_tcp; - opj_image_t* l_image_for_bounds; + opj_tcp_t *l_tcp; + opj_image_t *l_image_for_bounds; /* preconditions */ assert(p_stream != 00); @@ -10209,9 +10088,8 @@ OPJ_BOOL opj_j2k_decode_tile(opj_j2k_t * p_j2k, return OPJ_TRUE; } -static OPJ_BOOL opj_j2k_update_image_data(opj_tcd_t * p_tcd, - opj_image_t* p_output_image) -{ +static OPJ_BOOL opj_j2k_update_image_data(opj_tcd_t *p_tcd, + opj_image_t *p_output_image) { OPJ_UINT32 i, j; OPJ_UINT32 l_width_src, l_height_src; OPJ_UINT32 l_width_dest, l_height_dest; @@ -10221,12 +10099,12 @@ static OPJ_BOOL opj_j2k_update_image_data(opj_tcd_t * p_tcd, OPJ_UINT32 l_x0_dest, l_y0_dest, l_x1_dest, l_y1_dest; OPJ_SIZE_T l_start_offset_dest; - opj_image_comp_t * l_img_comp_src = 00; - opj_image_comp_t * l_img_comp_dest = 00; + opj_image_comp_t *l_img_comp_src = 00; + opj_image_comp_t *l_img_comp_dest = 00; - opj_tcd_tilecomp_t * l_tilec = 00; - opj_image_t * l_image_src = 00; - OPJ_INT32 * l_dest_ptr; + opj_tcd_tilecomp_t *l_tilec = 00; + opj_image_t *l_image_src = 00; + OPJ_INT32 *l_dest_ptr; l_tilec = p_tcd->tcd_image->tiles->comps; l_image_src = p_tcd->image; @@ -10238,13 +10116,13 @@ static OPJ_BOOL opj_j2k_update_image_data(opj_tcd_t * p_tcd, i++, ++l_img_comp_dest, ++l_img_comp_src, ++l_tilec) { OPJ_INT32 res_x0, res_x1, res_y0, res_y1; OPJ_UINT32 src_data_stride; - const OPJ_INT32* p_src_data; + const OPJ_INT32 *p_src_data; /* Copy info from decoded comp image to output image */ l_img_comp_dest->resno_decoded = l_img_comp_src->resno_decoded; if (p_tcd->whole_tile_decoding) { - opj_tcd_resolution_t* l_res = l_tilec->resolutions + + opj_tcd_resolution_t *l_res = l_tilec->resolutions + l_img_comp_src->resno_decoded; res_x0 = l_res->x0; res_y0 = l_res->y0; @@ -10255,7 +10133,7 @@ static OPJ_BOOL opj_j2k_update_image_data(opj_tcd_t * p_tcd, l_tilec->resolutions[l_tilec->minimum_num_resolutions - 1].x0); p_src_data = l_tilec->data; } else { - opj_tcd_resolution_t* l_res = l_tilec->resolutions + + opj_tcd_resolution_t *l_res = l_tilec->resolutions + l_img_comp_src->resno_decoded; res_x0 = (OPJ_INT32)l_res->win_x0; res_y0 = (OPJ_INT32)l_res->win_y0; @@ -10393,8 +10271,8 @@ static OPJ_BOOL opj_j2k_update_image_data(opj_tcd_t * p_tcd, /* would overflow */ return OPJ_FALSE; } - l_img_comp_dest->data = (OPJ_INT32*) opj_image_data_alloc(l_width * l_height * - sizeof(OPJ_INT32)); + l_img_comp_dest->data = (OPJ_INT32 *) opj_image_data_alloc(l_width * l_height * + sizeof(OPJ_INT32)); if (! l_img_comp_dest->data) { return OPJ_FALSE; } @@ -10410,7 +10288,7 @@ static OPJ_BOOL opj_j2k_update_image_data(opj_tcd_t * p_tcd, l_dest_ptr = l_img_comp_dest->data + l_start_offset_dest; { - const OPJ_INT32 * l_src_ptr = p_src_data; + const OPJ_INT32 *l_src_ptr = p_src_data; l_src_ptr += l_start_offset_src; for (j = 0; j < l_height_dest; ++j) { @@ -10426,12 +10304,11 @@ static OPJ_BOOL opj_j2k_update_image_data(opj_tcd_t * p_tcd, return OPJ_TRUE; } -static OPJ_BOOL opj_j2k_update_image_dimensions(opj_image_t* p_image, - opj_event_mgr_t * p_manager) -{ +static OPJ_BOOL opj_j2k_update_image_dimensions(opj_image_t *p_image, + opj_event_mgr_t *p_manager) { OPJ_UINT32 it_comp; OPJ_INT32 l_comp_x1, l_comp_y1; - opj_image_comp_t* l_img_comp = NULL; + opj_image_comp_t *l_img_comp = NULL; l_img_comp = p_image->comps; for (it_comp = 0; it_comp < p_image->numcomps; ++it_comp) { @@ -10478,11 +10355,10 @@ static OPJ_BOOL opj_j2k_update_image_dimensions(opj_image_t* p_image, OPJ_BOOL opj_j2k_set_decoded_components(opj_j2k_t *p_j2k, OPJ_UINT32 numcomps, - const OPJ_UINT32* comps_indices, - opj_event_mgr_t * p_manager) -{ + const OPJ_UINT32 *comps_indices, + opj_event_mgr_t *p_manager) { OPJ_UINT32 i; - OPJ_BOOL* already_mapped; + OPJ_BOOL *already_mapped; if (p_j2k->m_private_image == NULL) { opj_event_msg(p_manager, EVT_ERROR, @@ -10491,8 +10367,8 @@ OPJ_BOOL opj_j2k_set_decoded_components(opj_j2k_t *p_j2k, return OPJ_FALSE; } - already_mapped = (OPJ_BOOL*) opj_calloc(sizeof(OPJ_BOOL), - p_j2k->m_private_image->numcomps); + already_mapped = (OPJ_BOOL *) opj_calloc(sizeof(OPJ_BOOL), + p_j2k->m_private_image->numcomps); if (already_mapped == NULL) { return OPJ_FALSE; } @@ -10519,7 +10395,7 @@ OPJ_BOOL opj_j2k_set_decoded_components(opj_j2k_t *p_j2k, opj_free(p_j2k->m_specific_param.m_decoder.m_comps_indices_to_decode); if (numcomps) { p_j2k->m_specific_param.m_decoder.m_comps_indices_to_decode = - (OPJ_UINT32*) opj_malloc(numcomps * sizeof(OPJ_UINT32)); + (OPJ_UINT32 *) opj_malloc(numcomps * sizeof(OPJ_UINT32)); if (p_j2k->m_specific_param.m_decoder.m_comps_indices_to_decode == NULL) { p_j2k->m_specific_param.m_decoder.m_numcomps_to_decode = 0; return OPJ_FALSE; @@ -10537,13 +10413,12 @@ OPJ_BOOL opj_j2k_set_decoded_components(opj_j2k_t *p_j2k, OPJ_BOOL opj_j2k_set_decode_area(opj_j2k_t *p_j2k, - opj_image_t* p_image, + opj_image_t *p_image, OPJ_INT32 p_start_x, OPJ_INT32 p_start_y, OPJ_INT32 p_end_x, OPJ_INT32 p_end_y, - opj_event_mgr_t * p_manager) -{ - opj_cp_t * l_cp = &(p_j2k->m_cp); - opj_image_t * l_image = p_j2k->m_private_image; + opj_event_mgr_t *p_manager) { + opj_cp_t *l_cp = &(p_j2k->m_cp); + opj_image_t *l_image = p_j2k->m_private_image; OPJ_BOOL ret; OPJ_UINT32 it_comp; @@ -10604,7 +10479,7 @@ OPJ_BOOL opj_j2k_set_decode_area(opj_j2k_t *p_j2k, p_image->x0 = l_image->x0; } else { p_j2k->m_specific_param.m_decoder.m_start_tile_x = ((OPJ_UINT32)p_start_x - - l_cp->tx0) / l_cp->tdx; + l_cp->tx0) / l_cp->tdx; p_image->x0 = (OPJ_UINT32)p_start_x; } @@ -10627,7 +10502,7 @@ OPJ_BOOL opj_j2k_set_decode_area(opj_j2k_t *p_j2k, p_image->y0 = l_image->y0; } else { p_j2k->m_specific_param.m_decoder.m_start_tile_y = ((OPJ_UINT32)p_start_y - - l_cp->ty0) / l_cp->tdy; + l_cp->ty0) / l_cp->tdy; p_image->y0 = (OPJ_UINT32)p_start_y; } @@ -10650,7 +10525,7 @@ OPJ_BOOL opj_j2k_set_decode_area(opj_j2k_t *p_j2k, p_image->x1 = l_image->x1; } else { p_j2k->m_specific_param.m_decoder.m_end_tile_x = opj_uint_ceildiv(( - OPJ_UINT32)p_end_x - l_cp->tx0, l_cp->tdx); + OPJ_UINT32)p_end_x - l_cp->tx0, l_cp->tdx); p_image->x1 = (OPJ_UINT32)p_end_x; } @@ -10674,7 +10549,7 @@ OPJ_BOOL opj_j2k_set_decode_area(opj_j2k_t *p_j2k, p_image->y1 = l_image->y1; } else { p_j2k->m_specific_param.m_decoder.m_end_tile_y = opj_uint_ceildiv(( - OPJ_UINT32)p_end_y - l_cp->ty0, l_cp->tdy); + OPJ_UINT32)p_end_y - l_cp->ty0, l_cp->tdy); p_image->y1 = (OPJ_UINT32)p_end_y; } /* ----- */ @@ -10691,9 +10566,8 @@ OPJ_BOOL opj_j2k_set_decode_area(opj_j2k_t *p_j2k, return ret; } -opj_j2k_t* opj_j2k_create_decompress(void) -{ - opj_j2k_t *l_j2k = (opj_j2k_t*) opj_calloc(1, sizeof(opj_j2k_t)); +opj_j2k_t *opj_j2k_create_decompress(void) { + opj_j2k_t *l_j2k = (opj_j2k_t *) opj_calloc(1, sizeof(opj_j2k_t)); if (!l_j2k) { return 00; } @@ -10711,15 +10585,15 @@ opj_j2k_t* opj_j2k_create_decompress(void) l_j2k->m_specific_param.m_decoder.m_nb_tile_parts_correction_checked = 1; #endif - l_j2k->m_specific_param.m_decoder.m_default_tcp = (opj_tcp_t*) opj_calloc(1, - sizeof(opj_tcp_t)); + l_j2k->m_specific_param.m_decoder.m_default_tcp = (opj_tcp_t *) opj_calloc(1, + sizeof(opj_tcp_t)); if (!l_j2k->m_specific_param.m_decoder.m_default_tcp) { opj_j2k_destroy(l_j2k); return 00; } l_j2k->m_specific_param.m_decoder.m_header_data = (OPJ_BYTE *) opj_calloc(1, - OPJ_J2K_DEFAULT_HEADER_SIZE); + OPJ_J2K_DEFAULT_HEADER_SIZE); if (! l_j2k->m_specific_param.m_decoder.m_header_data) { opj_j2k_destroy(l_j2k); return 00; @@ -10765,9 +10639,8 @@ opj_j2k_t* opj_j2k_create_decompress(void) return l_j2k; } -static opj_codestream_index_t* opj_j2k_create_cstr_index(void) -{ - opj_codestream_index_t* cstr_index = (opj_codestream_index_t*) +static opj_codestream_index_t *opj_j2k_create_cstr_index(void) { + opj_codestream_index_t *cstr_index = (opj_codestream_index_t *) opj_calloc(1, sizeof(opj_codestream_index_t)); if (!cstr_index) { return NULL; @@ -10775,7 +10648,7 @@ static opj_codestream_index_t* opj_j2k_create_cstr_index(void) cstr_index->maxmarknum = 100; cstr_index->marknum = 0; - cstr_index->marker = (opj_marker_info_t*) + cstr_index->marker = (opj_marker_info_t *) opj_calloc(cstr_index->maxmarknum, sizeof(opj_marker_info_t)); if (!cstr_index-> marker) { opj_free(cstr_index); @@ -10788,9 +10661,8 @@ static opj_codestream_index_t* opj_j2k_create_cstr_index(void) } static OPJ_UINT32 opj_j2k_get_SPCod_SPCoc_size(opj_j2k_t *p_j2k, - OPJ_UINT32 p_tile_no, - OPJ_UINT32 p_comp_no) -{ + OPJ_UINT32 p_tile_no, + OPJ_UINT32 p_comp_no) { opj_cp_t *l_cp = 00; opj_tcp_t *l_tcp = 00; opj_tccp_t *l_tccp = 00; @@ -10814,8 +10686,7 @@ static OPJ_UINT32 opj_j2k_get_SPCod_SPCoc_size(opj_j2k_t *p_j2k, } static OPJ_BOOL opj_j2k_compare_SPCod_SPCoc(opj_j2k_t *p_j2k, - OPJ_UINT32 p_tile_no, OPJ_UINT32 p_first_comp_no, OPJ_UINT32 p_second_comp_no) -{ + OPJ_UINT32 p_tile_no, OPJ_UINT32 p_first_comp_no, OPJ_UINT32 p_second_comp_no) { OPJ_UINT32 i; opj_cp_t *l_cp = NULL; opj_tcp_t *l_tcp = NULL; @@ -10861,12 +10732,11 @@ static OPJ_BOOL opj_j2k_compare_SPCod_SPCoc(opj_j2k_t *p_j2k, } static OPJ_BOOL opj_j2k_write_SPCod_SPCoc(opj_j2k_t *p_j2k, - OPJ_UINT32 p_tile_no, - OPJ_UINT32 p_comp_no, - OPJ_BYTE * p_data, - OPJ_UINT32 * p_header_size, - struct opj_event_mgr * p_manager) -{ + OPJ_UINT32 p_tile_no, + OPJ_UINT32 p_comp_no, + OPJ_BYTE *p_data, + OPJ_UINT32 *p_header_size, + struct opj_event_mgr *p_manager) { OPJ_UINT32 i; opj_cp_t *l_cp = 00; opj_tcp_t *l_tcp = 00; @@ -10930,16 +10800,15 @@ static OPJ_BOOL opj_j2k_write_SPCod_SPCoc(opj_j2k_t *p_j2k, } static OPJ_BOOL opj_j2k_read_SPCod_SPCoc(opj_j2k_t *p_j2k, - OPJ_UINT32 compno, - OPJ_BYTE * p_header_data, - OPJ_UINT32 * p_header_size, - opj_event_mgr_t * p_manager) -{ + OPJ_UINT32 compno, + OPJ_BYTE *p_header_data, + OPJ_UINT32 *p_header_size, + opj_event_mgr_t *p_manager) { OPJ_UINT32 i, l_tmp; opj_cp_t *l_cp = NULL; opj_tcp_t *l_tcp = NULL; opj_tccp_t *l_tccp = NULL; - OPJ_BYTE * l_current_ptr = NULL; + OPJ_BYTE *l_current_ptr = NULL; /* preconditions */ assert(p_j2k != 00); @@ -11081,8 +10950,7 @@ static OPJ_BOOL opj_j2k_read_SPCod_SPCoc(opj_j2k_t *p_j2k, return OPJ_TRUE; } -static void opj_j2k_copy_tile_component_parameters(opj_j2k_t *p_j2k) -{ +static void opj_j2k_copy_tile_component_parameters(opj_j2k_t *p_j2k) { /* loop */ OPJ_UINT32 i; opj_cp_t *l_cp = NULL; @@ -11116,9 +10984,8 @@ static void opj_j2k_copy_tile_component_parameters(opj_j2k_t *p_j2k) } static OPJ_UINT32 opj_j2k_get_SQcd_SQcc_size(opj_j2k_t *p_j2k, - OPJ_UINT32 p_tile_no, - OPJ_UINT32 p_comp_no) -{ + OPJ_UINT32 p_tile_no, + OPJ_UINT32 p_comp_no) { OPJ_UINT32 l_num_bands; opj_cp_t *l_cp = 00; @@ -11147,8 +11014,7 @@ static OPJ_UINT32 opj_j2k_get_SQcd_SQcc_size(opj_j2k_t *p_j2k, } static OPJ_BOOL opj_j2k_compare_SQcd_SQcc(opj_j2k_t *p_j2k, - OPJ_UINT32 p_tile_no, OPJ_UINT32 p_first_comp_no, OPJ_UINT32 p_second_comp_no) -{ + OPJ_UINT32 p_tile_no, OPJ_UINT32 p_first_comp_no, OPJ_UINT32 p_second_comp_no) { opj_cp_t *l_cp = NULL; opj_tcp_t *l_tcp = NULL; opj_tccp_t *l_tccp0 = NULL; @@ -11197,10 +11063,9 @@ static OPJ_BOOL opj_j2k_compare_SQcd_SQcc(opj_j2k_t *p_j2k, static OPJ_BOOL opj_j2k_write_SQcd_SQcc(opj_j2k_t *p_j2k, OPJ_UINT32 p_tile_no, OPJ_UINT32 p_comp_no, - OPJ_BYTE * p_data, - OPJ_UINT32 * p_header_size, - struct opj_event_mgr * p_manager) -{ + OPJ_BYTE *p_data, + OPJ_UINT32 *p_header_size, + struct opj_event_mgr *p_manager) { OPJ_UINT32 l_header_size; OPJ_UINT32 l_band_no, l_num_bands; OPJ_UINT32 l_expn, l_mant; @@ -11271,17 +11136,16 @@ static OPJ_BOOL opj_j2k_write_SQcd_SQcc(opj_j2k_t *p_j2k, static OPJ_BOOL opj_j2k_read_SQcd_SQcc(opj_j2k_t *p_j2k, OPJ_UINT32 p_comp_no, - OPJ_BYTE* p_header_data, - OPJ_UINT32 * p_header_size, - opj_event_mgr_t * p_manager - ) -{ + OPJ_BYTE *p_header_data, + OPJ_UINT32 *p_header_size, + opj_event_mgr_t *p_manager + ) { /* loop*/ OPJ_UINT32 l_band_no; opj_cp_t *l_cp = 00; opj_tcp_t *l_tcp = 00; opj_tccp_t *l_tccp = 00; - OPJ_BYTE * l_current_ptr = 00; + OPJ_BYTE *l_current_ptr = 00; OPJ_UINT32 l_tmp, l_num_band; /* preconditions*/ @@ -11396,8 +11260,7 @@ static OPJ_BOOL opj_j2k_read_SQcd_SQcc(opj_j2k_t *p_j2k, return OPJ_TRUE; } -static void opj_j2k_copy_tile_quantization_parameters(opj_j2k_t *p_j2k) -{ +static void opj_j2k_copy_tile_quantization_parameters(opj_j2k_t *p_j2k) { OPJ_UINT32 i; opj_cp_t *l_cp = NULL; opj_tcp_t *l_tcp = NULL; @@ -11425,9 +11288,8 @@ static void opj_j2k_copy_tile_quantization_parameters(opj_j2k_t *p_j2k) } } -static void opj_j2k_dump_tile_info(opj_tcp_t * l_default_tile, - OPJ_INT32 numcomps, FILE* out_stream) -{ +static void opj_j2k_dump_tile_info(opj_tcp_t *l_default_tile, + OPJ_INT32 numcomps, FILE *out_stream) { if (l_default_tile) { OPJ_INT32 compno; @@ -11478,8 +11340,7 @@ static void opj_j2k_dump_tile_info(opj_tcp_t * l_default_tile, } } -void j2k_dump(opj_j2k_t* p_j2k, OPJ_INT32 flag, FILE* out_stream) -{ +void j2k_dump(opj_j2k_t *p_j2k, OPJ_INT32 flag, FILE *out_stream) { /* Check if the flag is compatible with j2k file*/ if ((flag & OPJ_JP2_INFO) || (flag & OPJ_JP2_IND)) { fprintf(out_stream, "Wrong flag\n"); @@ -11503,7 +11364,7 @@ void j2k_dump(opj_j2k_t* p_j2k, OPJ_INT32 flag, FILE* out_stream) if (flag & OPJ_J2K_TCH_INFO) { OPJ_UINT32 l_nb_tiles = p_j2k->m_cp.th * p_j2k->m_cp.tw; OPJ_UINT32 i; - opj_tcp_t * l_tcp = p_j2k->m_cp.tcps; + opj_tcp_t *l_tcp = p_j2k->m_cp.tcps; if (p_j2k->m_private_image) { for (i = 0; i < l_nb_tiles; ++i) { opj_j2k_dump_tile_info(l_tcp, (OPJ_INT32)p_j2k->m_private_image->numcomps, @@ -11530,9 +11391,8 @@ void j2k_dump(opj_j2k_t* p_j2k, OPJ_INT32 flag, FILE* out_stream) } -static void opj_j2k_dump_MH_index(opj_j2k_t* p_j2k, FILE* out_stream) -{ - opj_codestream_index_t* cstr_index = p_j2k->cstr_index; +static void opj_j2k_dump_MH_index(opj_j2k_t *p_j2k, FILE *out_stream) { + opj_codestream_index_t *cstr_index = p_j2k->cstr_index; OPJ_UINT32 it_marker, it_tile, it_tile_part; fprintf(out_stream, "Codestream index from main header: {\n"); @@ -11612,8 +11472,7 @@ static void opj_j2k_dump_MH_index(opj_j2k_t* p_j2k, FILE* out_stream) } -static void opj_j2k_dump_MH_info(opj_j2k_t* p_j2k, FILE* out_stream) -{ +static void opj_j2k_dump_MH_info(opj_j2k_t *p_j2k, FILE *out_stream) { fprintf(out_stream, "Codestream info from main header: {\n"); @@ -11628,9 +11487,8 @@ static void opj_j2k_dump_MH_info(opj_j2k_t* p_j2k, FILE* out_stream) fprintf(out_stream, "}\n"); } -void j2k_dump_image_header(opj_image_t* img_header, OPJ_BOOL dev_dump_flag, - FILE* out_stream) -{ +void j2k_dump_image_header(opj_image_t *img_header, OPJ_BOOL dev_dump_flag, + FILE *out_stream) { char tab[2]; if (dev_dump_flag) { @@ -11660,9 +11518,8 @@ void j2k_dump_image_header(opj_image_t* img_header, OPJ_BOOL dev_dump_flag, fprintf(out_stream, "}\n"); } -void j2k_dump_image_comp_header(opj_image_comp_t* comp_header, - OPJ_BOOL dev_dump_flag, FILE* out_stream) -{ +void j2k_dump_image_comp_header(opj_image_comp_t *comp_header, + OPJ_BOOL dev_dump_flag, FILE *out_stream) { char tab[3]; if (dev_dump_flag) { @@ -11683,12 +11540,11 @@ void j2k_dump_image_comp_header(opj_image_comp_t* comp_header, } } -opj_codestream_info_v2_t* j2k_get_cstr_info(opj_j2k_t* p_j2k) -{ +opj_codestream_info_v2_t *j2k_get_cstr_info(opj_j2k_t *p_j2k) { OPJ_UINT32 compno; OPJ_UINT32 numcomps = p_j2k->m_private_image->numcomps; opj_tcp_t *l_default_tile; - opj_codestream_info_v2_t* cstr_info = (opj_codestream_info_v2_t*) opj_calloc(1, + opj_codestream_info_v2_t *cstr_info = (opj_codestream_info_v2_t *) opj_calloc(1, sizeof(opj_codestream_info_v2_t)); if (!cstr_info) { return NULL; @@ -11712,8 +11568,8 @@ opj_codestream_info_v2_t* j2k_get_cstr_info(opj_j2k_t* p_j2k) cstr_info->m_default_tile_info.numlayers = l_default_tile->numlayers; cstr_info->m_default_tile_info.mct = l_default_tile->mct; - cstr_info->m_default_tile_info.tccp_info = (opj_tccp_info_t*) opj_calloc( - cstr_info->nbcomps, sizeof(opj_tccp_info_t)); + cstr_info->m_default_tile_info.tccp_info = (opj_tccp_info_t *) opj_calloc( + cstr_info->nbcomps, sizeof(opj_tccp_info_t)); if (!cstr_info->m_default_tile_info.tccp_info) { opj_destroy_cstr_info(&cstr_info); return NULL; @@ -11759,9 +11615,8 @@ opj_codestream_info_v2_t* j2k_get_cstr_info(opj_j2k_t* p_j2k) return cstr_info; } -opj_codestream_index_t* j2k_get_cstr_index(opj_j2k_t* p_j2k) -{ - opj_codestream_index_t* l_cstr_index = (opj_codestream_index_t*) +opj_codestream_index_t *j2k_get_cstr_index(opj_j2k_t *p_j2k) { + opj_codestream_index_t *l_cstr_index = (opj_codestream_index_t *) opj_calloc(1, sizeof(opj_codestream_index_t)); if (!l_cstr_index) { return NULL; @@ -11772,8 +11627,8 @@ opj_codestream_index_t* j2k_get_cstr_index(opj_j2k_t* p_j2k) l_cstr_index->codestream_size = p_j2k->cstr_index->codestream_size; l_cstr_index->marknum = p_j2k->cstr_index->marknum; - l_cstr_index->marker = (opj_marker_info_t*)opj_malloc(l_cstr_index->marknum * - sizeof(opj_marker_info_t)); + l_cstr_index->marker = (opj_marker_info_t *)opj_malloc(l_cstr_index->marknum * + sizeof(opj_marker_info_t)); if (!l_cstr_index->marker) { opj_free(l_cstr_index); return NULL; @@ -11788,7 +11643,7 @@ opj_codestream_index_t* j2k_get_cstr_index(opj_j2k_t* p_j2k) } l_cstr_index->nb_of_tiles = p_j2k->cstr_index->nb_of_tiles; - l_cstr_index->tile_index = (opj_tile_index_t*)opj_calloc( + l_cstr_index->tile_index = (opj_tile_index_t *)opj_calloc( l_cstr_index->nb_of_tiles, sizeof(opj_tile_index_t)); if (!l_cstr_index->tile_index) { opj_free(l_cstr_index->marker); @@ -11808,8 +11663,8 @@ opj_codestream_index_t* j2k_get_cstr_index(opj_j2k_t* p_j2k) p_j2k->cstr_index->tile_index[it_tile].marknum; l_cstr_index->tile_index[it_tile].marker = - (opj_marker_info_t*)opj_malloc(l_cstr_index->tile_index[it_tile].marknum * - sizeof(opj_marker_info_t)); + (opj_marker_info_t *)opj_malloc(l_cstr_index->tile_index[it_tile].marknum * + sizeof(opj_marker_info_t)); if (!l_cstr_index->tile_index[it_tile].marker) { OPJ_UINT32 it_tile_free; @@ -11838,8 +11693,8 @@ opj_codestream_index_t* j2k_get_cstr_index(opj_j2k_t* p_j2k) p_j2k->cstr_index->tile_index[it_tile].nb_tps; l_cstr_index->tile_index[it_tile].tp_index = - (opj_tp_index_t*)opj_malloc(l_cstr_index->tile_index[it_tile].nb_tps * sizeof( - opj_tp_index_t)); + (opj_tp_index_t *)opj_malloc(l_cstr_index->tile_index[it_tile].nb_tps * sizeof( + opj_tp_index_t)); if (!l_cstr_index->tile_index[it_tile].tp_index) { OPJ_UINT32 it_tile_free; @@ -11874,12 +11729,11 @@ opj_codestream_index_t* j2k_get_cstr_index(opj_j2k_t* p_j2k) return l_cstr_index; } -static OPJ_BOOL opj_j2k_allocate_tile_element_cstr_index(opj_j2k_t *p_j2k) -{ +static OPJ_BOOL opj_j2k_allocate_tile_element_cstr_index(opj_j2k_t *p_j2k) { OPJ_UINT32 it_tile = 0; p_j2k->cstr_index->nb_of_tiles = p_j2k->m_cp.tw * p_j2k->m_cp.th; - p_j2k->cstr_index->tile_index = (opj_tile_index_t*)opj_calloc( + p_j2k->cstr_index->tile_index = (opj_tile_index_t *)opj_calloc( p_j2k->cstr_index->nb_of_tiles, sizeof(opj_tile_index_t)); if (!p_j2k->cstr_index->tile_index) { return OPJ_FALSE; @@ -11888,9 +11742,9 @@ static OPJ_BOOL opj_j2k_allocate_tile_element_cstr_index(opj_j2k_t *p_j2k) for (it_tile = 0; it_tile < p_j2k->cstr_index->nb_of_tiles; it_tile++) { p_j2k->cstr_index->tile_index[it_tile].maxmarknum = 100; p_j2k->cstr_index->tile_index[it_tile].marknum = 0; - p_j2k->cstr_index->tile_index[it_tile].marker = (opj_marker_info_t*) - opj_calloc(p_j2k->cstr_index->tile_index[it_tile].maxmarknum, - sizeof(opj_marker_info_t)); + p_j2k->cstr_index->tile_index[it_tile].marker = (opj_marker_info_t *) + opj_calloc(p_j2k->cstr_index->tile_index[it_tile].maxmarknum, + sizeof(opj_marker_info_t)); if (!p_j2k->cstr_index->tile_index[it_tile].marker) { return OPJ_FALSE; } @@ -11900,8 +11754,7 @@ static OPJ_BOOL opj_j2k_allocate_tile_element_cstr_index(opj_j2k_t *p_j2k) } static OPJ_BOOL opj_j2k_are_all_used_components_decoded(opj_j2k_t *p_j2k, - opj_event_mgr_t * p_manager) -{ + opj_event_mgr_t *p_manager) { OPJ_UINT32 compno; OPJ_BOOL decoded_all_used_components = OPJ_TRUE; @@ -11934,10 +11787,9 @@ static OPJ_BOOL opj_j2k_are_all_used_components_decoded(opj_j2k_t *p_j2k, return OPJ_TRUE; } -static int CompareOffT(const void* a, const void* b) -{ - const OPJ_OFF_T offA = *(const OPJ_OFF_T*)a; - const OPJ_OFF_T offB = *(const OPJ_OFF_T*)b; +static int CompareOffT(const void *a, const void *b) { + const OPJ_OFF_T offA = *(const OPJ_OFF_T *)a; + const OPJ_OFF_T offB = *(const OPJ_OFF_T *)b; if (offA < offB) { return -1; } @@ -11949,8 +11801,7 @@ static int CompareOffT(const void* a, const void* b) static OPJ_BOOL opj_j2k_decode_tiles(opj_j2k_t *p_j2k, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager) -{ + opj_event_mgr_t *p_manager) { OPJ_BOOL l_go_on = OPJ_TRUE; OPJ_UINT32 l_current_tile_no; OPJ_INT32 l_tile_x0, l_tile_y0, l_tile_x1, l_tile_y1; @@ -12038,7 +11889,7 @@ static OPJ_BOOL opj_j2k_decode_tiles(opj_j2k_t *p_j2k, } p_j2k->m_specific_param.m_decoder.m_intersecting_tile_parts_offset = - (OPJ_OFF_T*) + (OPJ_OFF_T *) opj_malloc(m_num_intersecting_tile_parts * sizeof(OPJ_OFF_T)); if (m_num_intersecting_tile_parts > 0 && p_j2k->m_specific_param.m_decoder.m_intersecting_tile_parts_offset) { @@ -12148,8 +11999,7 @@ static OPJ_BOOL opj_j2k_decode_tiles(opj_j2k_t *p_j2k, * Sets up the procedures to do on decoding data. Developers wanting to extend the library can add their own reading procedures. */ static OPJ_BOOL opj_j2k_setup_decoding(opj_j2k_t *p_j2k, - opj_event_mgr_t * p_manager) -{ + opj_event_mgr_t *p_manager) { /* preconditions*/ assert(p_j2k != 00); assert(p_manager != 00); @@ -12168,8 +12018,7 @@ static OPJ_BOOL opj_j2k_setup_decoding(opj_j2k_t *p_j2k, */ static OPJ_BOOL opj_j2k_decode_one_tile(opj_j2k_t *p_j2k, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager) -{ + opj_event_mgr_t *p_manager) { OPJ_BOOL l_go_on = OPJ_TRUE; OPJ_UINT32 l_current_tile_no; OPJ_UINT32 l_tile_no_to_dec; @@ -12300,8 +12149,7 @@ static OPJ_BOOL opj_j2k_decode_one_tile(opj_j2k_t *p_j2k, * Sets up the procedures to do on decoding one tile. Developers wanting to extend the library can add their own reading procedures. */ static OPJ_BOOL opj_j2k_setup_decoding_tile(opj_j2k_t *p_j2k, - opj_event_mgr_t * p_manager) -{ + opj_event_mgr_t *p_manager) { /* preconditions*/ assert(p_j2k != 00); assert(p_manager != 00); @@ -12315,15 +12163,14 @@ static OPJ_BOOL opj_j2k_setup_decoding_tile(opj_j2k_t *p_j2k, return OPJ_TRUE; } -static OPJ_BOOL opj_j2k_move_data_from_codec_to_output_image(opj_j2k_t * p_j2k, - opj_image_t * p_image) -{ +static OPJ_BOOL opj_j2k_move_data_from_codec_to_output_image(opj_j2k_t *p_j2k, + opj_image_t *p_image) { OPJ_UINT32 compno; /* Move data and copy one information from codec to output image*/ if (p_j2k->m_specific_param.m_decoder.m_numcomps_to_decode > 0) { - opj_image_comp_t* newcomps = - (opj_image_comp_t*) opj_malloc( + opj_image_comp_t *newcomps = + (opj_image_comp_t *) opj_malloc( p_j2k->m_specific_param.m_decoder.m_numcomps_to_decode * sizeof(opj_image_comp_t)); if (newcomps == NULL) { @@ -12375,11 +12222,10 @@ static OPJ_BOOL opj_j2k_move_data_from_codec_to_output_image(opj_j2k_t * p_j2k, return OPJ_TRUE; } -OPJ_BOOL opj_j2k_decode(opj_j2k_t * p_j2k, - opj_stream_private_t * p_stream, - opj_image_t * p_image, - opj_event_mgr_t * p_manager) -{ +OPJ_BOOL opj_j2k_decode(opj_j2k_t *p_j2k, + opj_stream_private_t *p_stream, + opj_image_t *p_image, + opj_event_mgr_t *p_manager) { if (!p_image) { return OPJ_FALSE; } @@ -12435,13 +12281,12 @@ OPJ_BOOL opj_j2k_decode(opj_j2k_t * p_j2k, OPJ_BOOL opj_j2k_get_tile(opj_j2k_t *p_j2k, opj_stream_private_t *p_stream, - opj_image_t* p_image, - opj_event_mgr_t * p_manager, - OPJ_UINT32 tile_index) -{ + opj_image_t *p_image, + opj_event_mgr_t *p_manager, + OPJ_UINT32 tile_index) { OPJ_UINT32 compno; OPJ_UINT32 l_tile_x, l_tile_y; - opj_image_comp_t* l_img_comp; + opj_image_comp_t *l_img_comp; if (!p_image) { opj_event_msg(p_manager, EVT_ERROR, "We need an image previously created.\n"); @@ -12495,11 +12340,11 @@ OPJ_BOOL opj_j2k_get_tile(opj_j2k_t *p_j2k, l_comp_y1 = opj_int_ceildiv((OPJ_INT32)p_image->y1, (OPJ_INT32)l_img_comp->dy); l_img_comp->w = (OPJ_UINT32)(opj_int_ceildivpow2(l_comp_x1, - (OPJ_INT32)l_img_comp->factor) - opj_int_ceildivpow2((OPJ_INT32)l_img_comp->x0, - (OPJ_INT32)l_img_comp->factor)); + (OPJ_INT32)l_img_comp->factor) - opj_int_ceildivpow2((OPJ_INT32)l_img_comp->x0, + (OPJ_INT32)l_img_comp->factor)); l_img_comp->h = (OPJ_UINT32)(opj_int_ceildivpow2(l_comp_y1, - (OPJ_INT32)l_img_comp->factor) - opj_int_ceildivpow2((OPJ_INT32)l_img_comp->y0, - (OPJ_INT32)l_img_comp->factor)); + (OPJ_INT32)l_img_comp->factor) - opj_int_ceildivpow2((OPJ_INT32)l_img_comp->y0, + (OPJ_INT32)l_img_comp->factor)); l_img_comp++; } @@ -12547,9 +12392,8 @@ OPJ_BOOL opj_j2k_get_tile(opj_j2k_t *p_j2k, } OPJ_BOOL opj_j2k_set_decoded_resolution_factor(opj_j2k_t *p_j2k, - OPJ_UINT32 res_factor, - opj_event_mgr_t * p_manager) -{ + OPJ_UINT32 res_factor, + opj_event_mgr_t *p_manager) { OPJ_UINT32 it_comp; p_j2k->m_cp.m_specific_param.m_dec.m_reduce = res_factor; @@ -12581,10 +12425,9 @@ OPJ_BOOL opj_j2k_set_decoded_resolution_factor(opj_j2k_t *p_j2k, OPJ_BOOL opj_j2k_encoder_set_extra_options( opj_j2k_t *p_j2k, - const char* const* p_options, - opj_event_mgr_t * p_manager) -{ - const char* const* p_option_iter; + const char *const *p_options, + opj_event_mgr_t *p_manager) { + const char *const *p_option_iter; if (p_options == NULL) { return OPJ_TRUE; @@ -12642,16 +12485,15 @@ OPJ_BOOL opj_j2k_encoder_set_extra_options( /* ----------------------------------------------------------------------- */ -OPJ_BOOL opj_j2k_encode(opj_j2k_t * p_j2k, +OPJ_BOOL opj_j2k_encode(opj_j2k_t *p_j2k, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager) -{ + opj_event_mgr_t *p_manager) { OPJ_UINT32 i, j; OPJ_UINT32 l_nb_tiles; OPJ_SIZE_T l_max_tile_size = 0, l_current_tile_size; - OPJ_BYTE * l_current_data = 00; + OPJ_BYTE *l_current_data = 00; OPJ_BOOL l_reuse_data = OPJ_FALSE; - opj_tcd_t* p_tcd = 00; + opj_tcd_t *p_tcd = 00; /* preconditions */ assert(p_j2k != 00); @@ -12665,7 +12507,7 @@ OPJ_BOOL opj_j2k_encode(opj_j2k_t * p_j2k, l_reuse_data = OPJ_TRUE; #ifdef __SSE__ for (j = 0; j < p_j2k->m_tcd->image->numcomps; ++j) { - opj_image_comp_t * l_img_comp = p_tcd->image->comps + j; + opj_image_comp_t *l_img_comp = p_tcd->image->comps + j; if (((size_t)l_img_comp->data & 0xFU) != 0U) { /* tile data shall be aligned on 16 bytes */ l_reuse_data = OPJ_FALSE; @@ -12684,9 +12526,9 @@ OPJ_BOOL opj_j2k_encode(opj_j2k_t * p_j2k, /* if we only have one tile, then simply set tile component data equal to image component data */ /* otherwise, allocate the data */ for (j = 0; j < p_j2k->m_tcd->image->numcomps; ++j) { - opj_tcd_tilecomp_t* l_tilec = p_tcd->tcd_image->tiles->comps + j; + opj_tcd_tilecomp_t *l_tilec = p_tcd->tcd_image->tiles->comps + j; if (l_reuse_data) { - opj_image_comp_t * l_img_comp = p_tcd->image->comps + j; + opj_image_comp_t *l_img_comp = p_tcd->image->comps + j; l_tilec->data = l_img_comp->data; l_tilec->ownsData = OPJ_FALSE; } else { @@ -12703,7 +12545,7 @@ OPJ_BOOL opj_j2k_encode(opj_j2k_t * p_j2k, if (!l_reuse_data) { if (l_current_tile_size > l_max_tile_size) { OPJ_BYTE *l_new_current_data = (OPJ_BYTE *) opj_realloc(l_current_data, - l_current_tile_size); + l_current_tile_size); if (! l_new_current_data) { if (l_current_data) { opj_free(l_current_data); @@ -12752,8 +12594,7 @@ OPJ_BOOL opj_j2k_encode(opj_j2k_t * p_j2k, OPJ_BOOL opj_j2k_end_compress(opj_j2k_t *p_j2k, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager) -{ + opj_event_mgr_t *p_manager) { /* customization of the encoding */ if (! opj_j2k_setup_end_compress(p_j2k, p_manager)) { return OPJ_FALSE; @@ -12768,9 +12609,8 @@ OPJ_BOOL opj_j2k_end_compress(opj_j2k_t *p_j2k, OPJ_BOOL opj_j2k_start_compress(opj_j2k_t *p_j2k, opj_stream_private_t *p_stream, - opj_image_t * p_image, - opj_event_mgr_t * p_manager) -{ + opj_image_t *p_image, + opj_event_mgr_t *p_manager) { /* preconditions */ assert(p_j2k != 00); assert(p_stream != 00); @@ -12818,11 +12658,10 @@ OPJ_BOOL opj_j2k_start_compress(opj_j2k_t *p_j2k, return OPJ_TRUE; } -static OPJ_BOOL opj_j2k_pre_write_tile(opj_j2k_t * p_j2k, +static OPJ_BOOL opj_j2k_pre_write_tile(opj_j2k_t *p_j2k, OPJ_UINT32 p_tile_index, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager) -{ + opj_event_mgr_t *p_manager) { (void)p_stream; if (p_tile_index != p_j2k->m_current_tile_number) { opj_event_msg(p_manager, EVT_ERROR, "The given tile index does not match."); @@ -12845,18 +12684,17 @@ static OPJ_BOOL opj_j2k_pre_write_tile(opj_j2k_t * p_j2k, return OPJ_TRUE; } -static void opj_get_tile_dimensions(opj_image_t * l_image, - opj_tcd_tilecomp_t * l_tilec, - opj_image_comp_t * l_img_comp, - OPJ_UINT32* l_size_comp, - OPJ_UINT32* l_width, - OPJ_UINT32* l_height, - OPJ_UINT32* l_offset_x, - OPJ_UINT32* l_offset_y, - OPJ_UINT32* l_image_width, - OPJ_UINT32* l_stride, - OPJ_UINT32* l_tile_offset) -{ +static void opj_get_tile_dimensions(opj_image_t *l_image, + opj_tcd_tilecomp_t *l_tilec, + opj_image_comp_t *l_img_comp, + OPJ_UINT32 *l_size_comp, + OPJ_UINT32 *l_width, + OPJ_UINT32 *l_height, + OPJ_UINT32 *l_offset_x, + OPJ_UINT32 *l_offset_y, + OPJ_UINT32 *l_image_width, + OPJ_UINT32 *l_stride, + OPJ_UINT32 *l_tile_offset) { OPJ_UINT32 l_remaining; *l_size_comp = l_img_comp->prec >> 3; /* (/8) */ l_remaining = l_img_comp->prec & 7; /* (%8) */ @@ -12875,18 +12713,17 @@ static void opj_get_tile_dimensions(opj_image_t * l_image, *l_image_width = opj_uint_ceildiv(l_image->x1 - l_image->x0, l_img_comp->dx); *l_stride = *l_image_width - *l_width; *l_tile_offset = ((OPJ_UINT32)l_tilec->x0 - *l_offset_x) + (( - OPJ_UINT32)l_tilec->y0 - *l_offset_y) * *l_image_width; + OPJ_UINT32)l_tilec->y0 - *l_offset_y) * *l_image_width; } -static void opj_j2k_get_tile_data(opj_tcd_t * p_tcd, OPJ_BYTE * p_data) -{ +static void opj_j2k_get_tile_data(opj_tcd_t *p_tcd, OPJ_BYTE *p_data) { OPJ_UINT32 i, j, k = 0; for (i = 0; i < p_tcd->image->numcomps; ++i) { - opj_image_t * l_image = p_tcd->image; - OPJ_INT32 * l_src_ptr; - opj_tcd_tilecomp_t * l_tilec = p_tcd->tcd_image->tiles->comps + i; - opj_image_comp_t * l_img_comp = l_image->comps + i; + opj_image_t *l_image = p_tcd->image; + OPJ_INT32 *l_src_ptr; + opj_tcd_tilecomp_t *l_tilec = p_tcd->tcd_image->tiles->comps + i; + opj_image_comp_t *l_img_comp = l_image->comps + i; OPJ_UINT32 l_size_comp, l_width, l_height, l_offset_x, l_offset_y, l_image_width, l_stride, l_tile_offset; @@ -12905,74 +12742,73 @@ static void opj_j2k_get_tile_data(opj_tcd_t * p_tcd, OPJ_BYTE * p_data) l_src_ptr = l_img_comp->data + l_tile_offset; switch (l_size_comp) { - case 1: { - OPJ_CHAR * l_dest_ptr = (OPJ_CHAR*) p_data; - if (l_img_comp->sgnd) { - for (j = 0; j < l_height; ++j) { - for (k = 0; k < l_width; ++k) { - *(l_dest_ptr) = (OPJ_CHAR)(*l_src_ptr); - ++l_dest_ptr; - ++l_src_ptr; + case 1: { + OPJ_CHAR *l_dest_ptr = (OPJ_CHAR *) p_data; + if (l_img_comp->sgnd) { + for (j = 0; j < l_height; ++j) { + for (k = 0; k < l_width; ++k) { + *(l_dest_ptr) = (OPJ_CHAR)(*l_src_ptr); + ++l_dest_ptr; + ++l_src_ptr; + } + l_src_ptr += l_stride; } - l_src_ptr += l_stride; - } - } else { - for (j = 0; j < l_height; ++j) { - for (k = 0; k < l_width; ++k) { - *(l_dest_ptr) = (OPJ_CHAR)((*l_src_ptr) & 0xff); - ++l_dest_ptr; - ++l_src_ptr; + } else { + for (j = 0; j < l_height; ++j) { + for (k = 0; k < l_width; ++k) { + *(l_dest_ptr) = (OPJ_CHAR)((*l_src_ptr) & 0xff); + ++l_dest_ptr; + ++l_src_ptr; + } + l_src_ptr += l_stride; } - l_src_ptr += l_stride; } - } - p_data = (OPJ_BYTE*) l_dest_ptr; - } - break; - case 2: { - OPJ_INT16 * l_dest_ptr = (OPJ_INT16 *) p_data; - if (l_img_comp->sgnd) { + p_data = (OPJ_BYTE *) l_dest_ptr; + } + break; + case 2: { + OPJ_INT16 *l_dest_ptr = (OPJ_INT16 *) p_data; + if (l_img_comp->sgnd) { + for (j = 0; j < l_height; ++j) { + for (k = 0; k < l_width; ++k) { + *(l_dest_ptr++) = (OPJ_INT16)(*(l_src_ptr++)); + } + l_src_ptr += l_stride; + } + } else { + for (j = 0; j < l_height; ++j) { + for (k = 0; k < l_width; ++k) { + *(l_dest_ptr++) = (OPJ_INT16)((*(l_src_ptr++)) & 0xffff); + } + l_src_ptr += l_stride; + } + } + + p_data = (OPJ_BYTE *) l_dest_ptr; + } + break; + case 4: { + OPJ_INT32 *l_dest_ptr = (OPJ_INT32 *) p_data; for (j = 0; j < l_height; ++j) { for (k = 0; k < l_width; ++k) { - *(l_dest_ptr++) = (OPJ_INT16)(*(l_src_ptr++)); + *(l_dest_ptr++) = *(l_src_ptr++); } l_src_ptr += l_stride; } - } else { - for (j = 0; j < l_height; ++j) { - for (k = 0; k < l_width; ++k) { - *(l_dest_ptr++) = (OPJ_INT16)((*(l_src_ptr++)) & 0xffff); - } - l_src_ptr += l_stride; - } - } - p_data = (OPJ_BYTE*) l_dest_ptr; - } - break; - case 4: { - OPJ_INT32 * l_dest_ptr = (OPJ_INT32 *) p_data; - for (j = 0; j < l_height; ++j) { - for (k = 0; k < l_width; ++k) { - *(l_dest_ptr++) = *(l_src_ptr++); - } - l_src_ptr += l_stride; + p_data = (OPJ_BYTE *) l_dest_ptr; } - - p_data = (OPJ_BYTE*) l_dest_ptr; - } - break; + break; } } } -static OPJ_BOOL opj_j2k_post_write_tile(opj_j2k_t * p_j2k, +static OPJ_BOOL opj_j2k_post_write_tile(opj_j2k_t *p_j2k, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager) -{ + opj_event_mgr_t *p_manager) { OPJ_UINT32 l_nb_bytes_written; - OPJ_BYTE * l_current_data = 00; + OPJ_BYTE *l_current_data = 00; OPJ_UINT32 l_tile_size = 0; OPJ_UINT32 l_available_data; @@ -13012,8 +12848,7 @@ static OPJ_BOOL opj_j2k_post_write_tile(opj_j2k_t * p_j2k, } static OPJ_BOOL opj_j2k_setup_end_compress(opj_j2k_t *p_j2k, - opj_event_mgr_t * p_manager) -{ + opj_event_mgr_t *p_manager) { /* preconditions */ assert(p_j2k != 00); assert(p_manager != 00); @@ -13047,8 +12882,7 @@ static OPJ_BOOL opj_j2k_setup_end_compress(opj_j2k_t *p_j2k, } static OPJ_BOOL opj_j2k_setup_encoding_validation(opj_j2k_t *p_j2k, - opj_event_mgr_t * p_manager) -{ + opj_event_mgr_t *p_manager) { /* preconditions */ assert(p_j2k != 00); assert(p_manager != 00); @@ -13072,8 +12906,7 @@ static OPJ_BOOL opj_j2k_setup_encoding_validation(opj_j2k_t *p_j2k, } static OPJ_BOOL opj_j2k_setup_header_writing(opj_j2k_t *p_j2k, - opj_event_mgr_t * p_manager) -{ + opj_event_mgr_t *p_manager) { /* preconditions */ assert(p_j2k != 00); assert(p_manager != 00); @@ -13163,18 +12996,17 @@ static OPJ_BOOL opj_j2k_setup_header_writing(opj_j2k_t *p_j2k, } static OPJ_BOOL opj_j2k_write_first_tile_part(opj_j2k_t *p_j2k, - OPJ_BYTE * p_data, - OPJ_UINT32 * p_data_written, - OPJ_UINT32 total_data_size, - opj_stream_private_t *p_stream, - struct opj_event_mgr * p_manager) -{ + OPJ_BYTE *p_data, + OPJ_UINT32 *p_data_written, + OPJ_UINT32 total_data_size, + opj_stream_private_t *p_stream, + struct opj_event_mgr *p_manager) { OPJ_UINT32 l_nb_bytes_written = 0; OPJ_UINT32 l_current_nb_bytes_written; - OPJ_BYTE * l_begin_data = 00; + OPJ_BYTE *l_begin_data = 00; - opj_tcd_t * l_tcd = 00; - opj_cp_t * l_cp = 00; + opj_tcd_t *l_tcd = 00; + opj_cp_t *l_cp = 00; l_tcd = p_j2k->m_tcd; l_cp = &(p_j2k->m_cp); @@ -13248,13 +13080,12 @@ static OPJ_BOOL opj_j2k_write_first_tile_part(opj_j2k_t *p_j2k, } static OPJ_BOOL opj_j2k_write_all_tile_parts(opj_j2k_t *p_j2k, - OPJ_BYTE * p_data, - OPJ_UINT32 * p_data_written, - OPJ_UINT32 total_data_size, - opj_stream_private_t *p_stream, - struct opj_event_mgr * p_manager - ) -{ + OPJ_BYTE *p_data, + OPJ_UINT32 *p_data_written, + OPJ_UINT32 total_data_size, + opj_stream_private_t *p_stream, + struct opj_event_mgr *p_manager + ) { OPJ_UINT32 tilepartno = 0; OPJ_UINT32 l_nb_bytes_written = 0; OPJ_UINT32 l_current_nb_bytes_written; @@ -13262,10 +13093,10 @@ static OPJ_BOOL opj_j2k_write_all_tile_parts(opj_j2k_t *p_j2k, OPJ_UINT32 tot_num_tp; OPJ_UINT32 pino; - OPJ_BYTE * l_begin_data; + OPJ_BYTE *l_begin_data; opj_tcp_t *l_tcp = 00; - opj_tcd_t * l_tcd = 00; - opj_cp_t * l_cp = 00; + opj_tcd_t *l_tcd = 00; + opj_cp_t *l_cp = 00; l_tcd = p_j2k->m_tcd; l_cp = &(p_j2k->m_cp); @@ -13370,9 +13201,8 @@ static OPJ_BOOL opj_j2k_write_all_tile_parts(opj_j2k_t *p_j2k, } static OPJ_BOOL opj_j2k_write_updated_tlm(opj_j2k_t *p_j2k, - struct opj_stream_private *p_stream, - struct opj_event_mgr * p_manager) -{ + struct opj_stream_private *p_stream, + struct opj_event_mgr *p_manager) { OPJ_UINT32 l_tlm_size; OPJ_OFF_T l_tlm_position, l_current_position; OPJ_UINT32 size_per_tile_part; @@ -13407,8 +13237,7 @@ static OPJ_BOOL opj_j2k_write_updated_tlm(opj_j2k_t *p_j2k, static OPJ_BOOL opj_j2k_end_encoding(opj_j2k_t *p_j2k, struct opj_stream_private *p_stream, - struct opj_event_mgr * p_manager) -{ + struct opj_event_mgr *p_manager) { /* preconditions */ assert(p_j2k != 00); assert(p_manager != 00); @@ -13439,11 +13268,10 @@ static OPJ_BOOL opj_j2k_end_encoding(opj_j2k_t *p_j2k, /** * Destroys the memory associated with the decoding of headers. */ -static OPJ_BOOL opj_j2k_destroy_header_memory(opj_j2k_t * p_j2k, - opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager - ) -{ +static OPJ_BOOL opj_j2k_destroy_header_memory(opj_j2k_t *p_j2k, + opj_stream_private_t *p_stream, + opj_event_mgr_t *p_manager + ) { /* preconditions */ assert(p_j2k != 00); assert(p_stream != 00); @@ -13464,9 +13292,8 @@ static OPJ_BOOL opj_j2k_destroy_header_memory(opj_j2k_t * p_j2k, static OPJ_BOOL opj_j2k_init_info(opj_j2k_t *p_j2k, struct opj_stream_private *p_stream, - struct opj_event_mgr * p_manager) -{ - opj_codestream_info_t * l_cstr_info = 00; + struct opj_event_mgr *p_manager) { + opj_codestream_info_t *l_cstr_info = 00; /* preconditions */ assert(p_j2k != 00); @@ -13529,9 +13356,8 @@ static OPJ_BOOL opj_j2k_init_info(opj_j2k_t *p_j2k, */ static OPJ_BOOL opj_j2k_create_tcd(opj_j2k_t *p_j2k, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager - ) -{ + opj_event_mgr_t *p_manager + ) { /* preconditions */ assert(p_j2k != 00); assert(p_manager != 00); @@ -13556,13 +13382,12 @@ static OPJ_BOOL opj_j2k_create_tcd(opj_j2k_t *p_j2k, return OPJ_TRUE; } -OPJ_BOOL opj_j2k_write_tile(opj_j2k_t * p_j2k, +OPJ_BOOL opj_j2k_write_tile(opj_j2k_t *p_j2k, OPJ_UINT32 p_tile_index, - OPJ_BYTE * p_data, + OPJ_BYTE *p_data, OPJ_UINT32 p_data_size, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager) -{ + opj_event_mgr_t *p_manager) { if (! opj_j2k_pre_write_tile(p_j2k, p_tile_index, p_stream, p_manager)) { opj_event_msg(p_manager, EVT_ERROR, "Error while opj_j2k_pre_write_tile with tile index = %d\n", p_tile_index); @@ -13571,7 +13396,7 @@ OPJ_BOOL opj_j2k_write_tile(opj_j2k_t * p_j2k, OPJ_UINT32 j; /* Allocate data */ for (j = 0; j < p_j2k->m_tcd->image->numcomps; ++j) { - opj_tcd_tilecomp_t* l_tilec = p_j2k->m_tcd->tcd_image->tiles->comps + j; + opj_tcd_tilecomp_t *l_tilec = p_j2k->m_tcd->tcd_image->tiles->comps + j; if (! opj_alloc_tile_component_data(l_tilec)) { opj_event_msg(p_manager, EVT_ERROR, "Error allocating tile component data."); diff --git a/client/deps/openjpeg/j2k.h b/client/deps/openjpeg/j2k.h index bcf70a419..80f98088d 100644 --- a/client/deps/openjpeg/j2k.h +++ b/client/deps/openjpeg/j2k.h @@ -218,7 +218,7 @@ typedef struct opj_mct_data { J2K_MCT_ELEMENT_TYPE m_element_type; J2K_MCT_ARRAY_TYPE m_array_type; OPJ_UINT32 m_index; - OPJ_BYTE * m_data; + OPJ_BYTE *m_data; OPJ_UINT32 m_data_size; } opj_mct_data_t; @@ -229,14 +229,14 @@ opj_mct_data_t; typedef struct opj_simple_mcc_decorrelation_data { OPJ_UINT32 m_index; OPJ_UINT32 m_nb_comps; - opj_mct_data_t * m_decorrelation_array; - opj_mct_data_t * m_offset_array; + opj_mct_data_t *m_decorrelation_array; + opj_mct_data_t *m_offset_array; OPJ_BITFIELD m_is_irreversible : 1; } opj_simple_mcc_decorrelation_data_t; typedef struct opj_ppx_struct { - OPJ_BYTE* m_data; /* m_data == NULL => Zppx not read yet */ + OPJ_BYTE *m_data; /* m_data == NULL => Zppx not read yet */ OPJ_UINT32 m_data_size; } opj_ppx; @@ -265,7 +265,7 @@ typedef struct opj_tcp { /** number of ppt markers (reserved size) */ OPJ_UINT32 ppt_markers_count; /** ppt markers data (table indexed by Zppt) */ - opj_ppx* ppt_markers; + opj_ppx *ppt_markers; /** packet header store there for future use in t2_decode_packet */ OPJ_BYTE *ppt_data; @@ -284,23 +284,23 @@ typedef struct opj_tcp { /** number of tile parts for the tile. */ OPJ_UINT32 m_nb_tile_parts; /** data for the tile */ - OPJ_BYTE * m_data; + OPJ_BYTE *m_data; /** size of data */ OPJ_UINT32 m_data_size; /** encoding norms */ - OPJ_FLOAT64 * mct_norms; + OPJ_FLOAT64 *mct_norms; /** the mct decoding matrix */ - OPJ_FLOAT32 * m_mct_decoding_matrix; + OPJ_FLOAT32 *m_mct_decoding_matrix; /** the mct coding matrix */ - OPJ_FLOAT32 * m_mct_coding_matrix; + OPJ_FLOAT32 *m_mct_coding_matrix; /** mct records */ - opj_mct_data_t * m_mct_records; + opj_mct_data_t *m_mct_records; /** the number of mct records. */ OPJ_UINT32 m_nb_mct_records; /** the max number of mct records. */ OPJ_UINT32 m_nb_max_mct_records; /** mcc records */ - opj_simple_mcc_decorrelation_data_t * m_mcc_records; + opj_simple_mcc_decorrelation_data_t *m_mcc_records; /** the number of mct records. */ OPJ_UINT32 m_nb_mcc_records; /** the max number of mct records. */ @@ -378,7 +378,7 @@ typedef struct opj_cp { /** number of ppm markers (reserved size) */ OPJ_UINT32 ppm_markers_count; /** ppm markers data (table indexed by Zppm) */ - opj_ppx* ppm_markers; + opj_ppx *ppm_markers; /** packet header store there for future use in t2_decode_packet */ OPJ_BYTE *ppm_data; @@ -480,7 +480,7 @@ typedef struct opj_j2k_tlm_info { /** Number of entries in m_tile_part_infos. */ OPJ_UINT32 m_entries_count; /** Array of m_entries_count values. */ - opj_j2k_tlm_tile_part_info_t* m_tile_part_infos; + opj_j2k_tlm_tile_part_info_t *m_tile_part_infos; OPJ_BOOL m_is_invalid; } opj_j2k_tlm_info_t; @@ -527,7 +527,7 @@ typedef struct opj_j2k_dec { /* Number of elements of m_intersecting_tile_parts_offset[] */ OPJ_UINT32 m_num_intersecting_tile_parts; /* Start offset of contributing tile parts */ - OPJ_OFF_T* m_intersecting_tile_parts_offset; + OPJ_OFF_T *m_intersecting_tile_parts_offset; /** to tell that a tile can be decoded. */ OPJ_BITFIELD m_can_decode : 1; @@ -560,24 +560,24 @@ typedef struct opj_j2k_enc { /** * Stores the sizes of the tlm. */ - OPJ_BYTE * m_tlm_sot_offsets_buffer; + OPJ_BYTE *m_tlm_sot_offsets_buffer; /** * The current offset of the tlm buffer. */ - OPJ_BYTE * m_tlm_sot_offsets_current; + OPJ_BYTE *m_tlm_sot_offsets_current; /** Total num of tile parts in whole image = num tiles* num tileparts in each tile*/ /** used in TLMmarker*/ OPJ_UINT32 m_total_tile_parts; /* totnum_tp */ /* encoded data for a tile */ - OPJ_BYTE * m_encoded_tile_data; + OPJ_BYTE *m_encoded_tile_data; /* size of the encoded_data */ OPJ_UINT32 m_encoded_tile_size; /* encoded data for a tile */ - OPJ_BYTE * m_header_tile_data; + OPJ_BYTE *m_header_tile_data; /* size of the encoded_data */ @@ -612,19 +612,19 @@ typedef struct opj_j2k { m_specific_param; /** pointer to the internal/private encoded / decoded image */ - opj_image_t* m_private_image; + opj_image_t *m_private_image; /* pointer to the output image (decoded)*/ - opj_image_t* m_output_image; + opj_image_t *m_output_image; /** Coding parameters */ opj_cp_t m_cp; /** the list of procedures to exec **/ - opj_procedure_list_t * m_procedure_list; + opj_procedure_list_t *m_procedure_list; /** the list of validation procedures to follow to make sure the code is valid **/ - opj_procedure_list_t * m_validation_list; + opj_procedure_list_t *m_validation_list; /** helper used to write the index file */ opj_codestream_index_t *cstr_index; @@ -633,10 +633,10 @@ typedef struct opj_j2k { OPJ_UINT32 m_current_tile_number; /** the current tile coder/decoder **/ - struct opj_tcd * m_tcd; + struct opj_tcd *m_tcd; /** Thread pool */ - opj_thread_pool_t* m_tp; + opj_thread_pool_t *m_tp; /** Image width coming from JP2 IHDR box. 0 from a pure codestream */ OPJ_UINT32 ihdr_w; @@ -673,13 +673,13 @@ OPJ_BOOL opj_j2k_set_threads(opj_j2k_t *j2k, OPJ_UINT32 num_threads); * * @return Returns a handle to a J2K compressor if successful, returns NULL otherwise */ -opj_j2k_t* opj_j2k_create_compress(void); +opj_j2k_t *opj_j2k_create_compress(void); OPJ_BOOL opj_j2k_setup_encoder(opj_j2k_t *p_j2k, opj_cparameters_t *parameters, opj_image_t *image, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** Converts an enum type progression order to string type @@ -697,7 +697,7 @@ const char *opj_j2k_convert_progression_order(OPJ_PROG_ORDER prg_order); */ OPJ_BOOL opj_j2k_end_decompress(opj_j2k_t *j2k, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Reads a jpeg2000 codestream header structure. @@ -710,9 +710,9 @@ OPJ_BOOL opj_j2k_end_decompress(opj_j2k_t *j2k, * @return true if the box is valid. */ OPJ_BOOL opj_j2k_read_header(opj_stream_private_t *p_stream, - opj_j2k_t* p_j2k, - opj_image_t** p_image, - opj_event_mgr_t* p_manager); + opj_j2k_t *p_j2k, + opj_image_t **p_image, + opj_event_mgr_t *p_manager); /** @@ -738,12 +738,12 @@ void j2k_destroy_cstr_index(opj_codestream_index_t *p_cstr_ind); * @param p_stream the stream to write data to. * @param p_manager the user event manager. */ -OPJ_BOOL opj_j2k_decode_tile(opj_j2k_t * p_j2k, +OPJ_BOOL opj_j2k_decode_tile(opj_j2k_t *p_j2k, OPJ_UINT32 p_tile_index, - OPJ_BYTE * p_data, + OPJ_BYTE *p_data, OPJ_UINT32 p_data_size, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Reads a tile header. @@ -759,17 +759,17 @@ OPJ_BOOL opj_j2k_decode_tile(opj_j2k_t * p_j2k, * @param p_stream the stream to write data to. * @param p_manager the user event manager. */ -OPJ_BOOL opj_j2k_read_tile_header(opj_j2k_t * p_j2k, - OPJ_UINT32 * p_tile_index, - OPJ_UINT32 * p_data_size, - OPJ_INT32 * p_tile_x0, - OPJ_INT32 * p_tile_y0, - OPJ_INT32 * p_tile_x1, - OPJ_INT32 * p_tile_y1, - OPJ_UINT32 * p_nb_comps, - OPJ_BOOL * p_go_on, +OPJ_BOOL opj_j2k_read_tile_header(opj_j2k_t *p_j2k, + OPJ_UINT32 *p_tile_index, + OPJ_UINT32 *p_data_size, + OPJ_INT32 *p_tile_x0, + OPJ_INT32 *p_tile_y0, + OPJ_INT32 *p_tile_x1, + OPJ_INT32 *p_tile_y1, + OPJ_UINT32 *p_nb_comps, + OPJ_BOOL *p_go_on, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** Sets the indices of the components to decode. @@ -784,8 +784,8 @@ OPJ_BOOL opj_j2k_read_tile_header(opj_j2k_t * p_j2k, */ OPJ_BOOL opj_j2k_set_decoded_components(opj_j2k_t *p_j2k, OPJ_UINT32 numcomps, - const OPJ_UINT32* comps_indices, - opj_event_mgr_t * p_manager); + const OPJ_UINT32 *comps_indices, + opj_event_mgr_t *p_manager); /** * Sets the given area to be decoded. This function should be called right after opj_read_header and before any tile header reading. @@ -801,17 +801,17 @@ OPJ_BOOL opj_j2k_set_decoded_components(opj_j2k_t *p_j2k, * @return true if the area could be set. */ OPJ_BOOL opj_j2k_set_decode_area(opj_j2k_t *p_j2k, - opj_image_t* p_image, + opj_image_t *p_image, OPJ_INT32 p_start_x, OPJ_INT32 p_start_y, OPJ_INT32 p_end_x, OPJ_INT32 p_end_y, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Creates a J2K decompression structure. * * @return a handle to a J2K decompressor if successful, NULL otherwise. */ -opj_j2k_t* opj_j2k_create_decompress(void); +opj_j2k_t *opj_j2k_create_decompress(void); /** @@ -822,7 +822,7 @@ opj_j2k_t* opj_j2k_create_decompress(void); *@param out_stream output stream where dump the elements. * */ -void j2k_dump(opj_j2k_t* p_j2k, OPJ_INT32 flag, FILE* out_stream); +void j2k_dump(opj_j2k_t *p_j2k, OPJ_INT32 flag, FILE *out_stream); @@ -833,8 +833,8 @@ void j2k_dump(opj_j2k_t* p_j2k, OPJ_INT32 flag, FILE* out_stream); *@param dev_dump_flag flag to describe if we are in the case of this function is use outside j2k_dump function *@param out_stream output stream where dump the elements. */ -void j2k_dump_image_header(opj_image_t* image, OPJ_BOOL dev_dump_flag, - FILE* out_stream); +void j2k_dump_image_header(opj_image_t *image, OPJ_BOOL dev_dump_flag, + FILE *out_stream); /** * Dump a component image header structure. @@ -843,8 +843,8 @@ void j2k_dump_image_header(opj_image_t* image, OPJ_BOOL dev_dump_flag, *@param dev_dump_flag flag to describe if we are in the case of this function is use outside j2k_dump function *@param out_stream output stream where dump the elements. */ -void j2k_dump_image_comp_header(opj_image_comp_t* comp, OPJ_BOOL dev_dump_flag, - FILE* out_stream); +void j2k_dump_image_comp_header(opj_image_comp_t *comp, OPJ_BOOL dev_dump_flag, + FILE *out_stream); /** * Get the codestream info from a JPEG2000 codec. @@ -853,7 +853,7 @@ void j2k_dump_image_comp_header(opj_image_comp_t* comp, OPJ_BOOL dev_dump_flag, * *@return the codestream information extract from the jpg2000 codec */ -opj_codestream_info_v2_t* j2k_get_cstr_info(opj_j2k_t* p_j2k); +opj_codestream_info_v2_t *j2k_get_cstr_info(opj_j2k_t *p_j2k); /** * Get the codestream index from a JPEG2000 codec. @@ -862,7 +862,7 @@ opj_codestream_info_v2_t* j2k_get_cstr_info(opj_j2k_t* p_j2k); * *@return the codestream index extract from the jpg2000 codec */ -opj_codestream_index_t* j2k_get_cstr_index(opj_j2k_t* p_j2k); +opj_codestream_index_t *j2k_get_cstr_index(opj_j2k_t *p_j2k); /** * Decode an image from a JPEG-2000 codestream @@ -880,13 +880,13 @@ OPJ_BOOL opj_j2k_decode(opj_j2k_t *j2k, OPJ_BOOL opj_j2k_get_tile(opj_j2k_t *p_j2k, opj_stream_private_t *p_stream, - opj_image_t* p_image, - opj_event_mgr_t * p_manager, + opj_image_t *p_image, + opj_event_mgr_t *p_manager, OPJ_UINT32 tile_index); OPJ_BOOL opj_j2k_set_decoded_resolution_factor(opj_j2k_t *p_j2k, - OPJ_UINT32 res_factor, - opj_event_mgr_t * p_manager); + OPJ_UINT32 res_factor, + opj_event_mgr_t *p_manager); /** * Specify extra options for the encoder. @@ -899,8 +899,8 @@ OPJ_BOOL opj_j2k_set_decoded_resolution_factor(opj_j2k_t *p_j2k, */ OPJ_BOOL opj_j2k_encoder_set_extra_options( opj_j2k_t *p_j2k, - const char* const* p_options, - opj_event_mgr_t * p_manager); + const char *const *p_options, + opj_event_mgr_t *p_manager); /** * Writes a tile. @@ -911,19 +911,19 @@ OPJ_BOOL opj_j2k_encoder_set_extra_options( * @param p_stream the stream to write data to. * @param p_manager the user event manager. */ -OPJ_BOOL opj_j2k_write_tile(opj_j2k_t * p_j2k, +OPJ_BOOL opj_j2k_write_tile(opj_j2k_t *p_j2k, OPJ_UINT32 p_tile_index, - OPJ_BYTE * p_data, + OPJ_BYTE *p_data, OPJ_UINT32 p_data_size, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Encodes an image into a JPEG-2000 codestream */ -OPJ_BOOL opj_j2k_encode(opj_j2k_t * p_j2k, +OPJ_BOOL opj_j2k_encode(opj_j2k_t *p_j2k, opj_stream_private_t *cio, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Starts a compression scheme, i.e. validates the codec parameters, writes the header. @@ -937,8 +937,8 @@ OPJ_BOOL opj_j2k_encode(opj_j2k_t * p_j2k, */ OPJ_BOOL opj_j2k_start_compress(opj_j2k_t *p_j2k, opj_stream_private_t *p_stream, - opj_image_t * p_image, - opj_event_mgr_t * p_manager); + opj_image_t *p_image, + opj_event_mgr_t *p_manager); /** * Ends the compression procedures and possibiliy add data to be read after the @@ -946,9 +946,9 @@ OPJ_BOOL opj_j2k_start_compress(opj_j2k_t *p_j2k, */ OPJ_BOOL opj_j2k_end_compress(opj_j2k_t *p_j2k, opj_stream_private_t *cio, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); -OPJ_BOOL opj_j2k_setup_mct_encoding(opj_tcp_t * p_tcp, opj_image_t * p_image); +OPJ_BOOL opj_j2k_setup_mct_encoding(opj_tcp_t *p_tcp, opj_image_t *p_image); #endif /* OPJ_J2K_H */ diff --git a/client/deps/openjpeg/jp2.c b/client/deps/openjpeg/jp2.c index 3d16d1075..8e0fd6d2d 100644 --- a/client/deps/openjpeg/jp2.c +++ b/client/deps/openjpeg/jp2.c @@ -64,7 +64,7 @@ static OPJ_BOOL opj_jp2_read_ihdr(opj_jp2_t *jp2, OPJ_BYTE *p_image_header_data, OPJ_UINT32 p_image_header_size, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Writes the Image Header box - Image Header box. @@ -74,8 +74,8 @@ static OPJ_BOOL opj_jp2_read_ihdr(opj_jp2_t *jp2, * * @return the data being copied. */ -static OPJ_BYTE * opj_jp2_write_ihdr(opj_jp2_t *jp2, - OPJ_UINT32 * p_nb_bytes_written); +static OPJ_BYTE *opj_jp2_write_ihdr(opj_jp2_t *jp2, + OPJ_UINT32 *p_nb_bytes_written); /** * Writes the Bit per Component box. @@ -85,8 +85,8 @@ static OPJ_BYTE * opj_jp2_write_ihdr(opj_jp2_t *jp2, * * @return the data being copied. */ -static OPJ_BYTE * opj_jp2_write_bpcc(opj_jp2_t *jp2, - OPJ_UINT32 * p_nb_bytes_written); +static OPJ_BYTE *opj_jp2_write_bpcc(opj_jp2_t *jp2, + OPJ_UINT32 *p_nb_bytes_written); /** * Reads a Bit per Component box. @@ -99,14 +99,14 @@ static OPJ_BYTE * opj_jp2_write_bpcc(opj_jp2_t *jp2, * @return true if the bpc header is valid, false else. */ static OPJ_BOOL opj_jp2_read_bpcc(opj_jp2_t *jp2, - OPJ_BYTE * p_bpc_header_data, + OPJ_BYTE *p_bpc_header_data, OPJ_UINT32 p_bpc_header_size, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); -static OPJ_BOOL opj_jp2_read_cdef(opj_jp2_t * jp2, - OPJ_BYTE * p_cdef_header_data, +static OPJ_BOOL opj_jp2_read_cdef(opj_jp2_t *jp2, + OPJ_BYTE *p_cdef_header_data, OPJ_UINT32 p_cdef_header_size, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); static void opj_jp2_apply_cdef(opj_image_t *image, opj_jp2_color_t *color, opj_event_mgr_t *); @@ -119,8 +119,8 @@ static void opj_jp2_apply_cdef(opj_image_t *image, opj_jp2_color_t *color, * * @return the data being copied. */ -static OPJ_BYTE * opj_jp2_write_cdef(opj_jp2_t *jp2, - OPJ_UINT32 * p_nb_bytes_written); +static OPJ_BYTE *opj_jp2_write_cdef(opj_jp2_t *jp2, + OPJ_UINT32 *p_nb_bytes_written); /** * Writes the Colour Specification box. @@ -130,8 +130,8 @@ static OPJ_BYTE * opj_jp2_write_cdef(opj_jp2_t *jp2, * * @return the data being copied. */ -static OPJ_BYTE * opj_jp2_write_colr(opj_jp2_t *jp2, - OPJ_UINT32 * p_nb_bytes_written); +static OPJ_BYTE *opj_jp2_write_colr(opj_jp2_t *jp2, + OPJ_UINT32 *p_nb_bytes_written); /** * Writes a FTYP box - File type box @@ -144,7 +144,7 @@ static OPJ_BYTE * opj_jp2_write_colr(opj_jp2_t *jp2, */ static OPJ_BOOL opj_jp2_write_ftyp(opj_jp2_t *jp2, opj_stream_private_t *cio, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Reads a a FTYP box - File type box @@ -157,13 +157,13 @@ static OPJ_BOOL opj_jp2_write_ftyp(opj_jp2_t *jp2, * @return true if the FTYP box is valid. */ static OPJ_BOOL opj_jp2_read_ftyp(opj_jp2_t *jp2, - OPJ_BYTE * p_header_data, + OPJ_BYTE *p_header_data, OPJ_UINT32 p_header_size, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); static OPJ_BOOL opj_jp2_skip_jp2c(opj_jp2_t *jp2, opj_stream_private_t *stream, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Reads the Jpeg2000 file Header box - JP2 Header box (warning, this is a super box). @@ -178,7 +178,7 @@ static OPJ_BOOL opj_jp2_skip_jp2c(opj_jp2_t *jp2, static OPJ_BOOL opj_jp2_read_jp2h(opj_jp2_t *jp2, OPJ_BYTE *p_header_data, OPJ_UINT32 p_header_size, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Writes the Jpeg2000 file Header box - JP2 Header box (warning, this is a super box). @@ -191,7 +191,7 @@ static OPJ_BOOL opj_jp2_read_jp2h(opj_jp2_t *jp2, */ static OPJ_BOOL opj_jp2_write_jp2h(opj_jp2_t *jp2, opj_stream_private_t *stream, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Writes the Jpeg2000 codestream Header box - JP2C Header box. This function must be called AFTER the coding has been done. @@ -204,7 +204,7 @@ static OPJ_BOOL opj_jp2_write_jp2h(opj_jp2_t *jp2, */ static OPJ_BOOL opj_jp2_write_jp2c(opj_jp2_t *jp2, opj_stream_private_t *cio, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); #ifdef USE_JPIP /** @@ -215,7 +215,7 @@ static OPJ_BOOL opj_jp2_write_jp2c(opj_jp2_t *jp2, */ static OPJ_BOOL opj_jpip_write_iptr(opj_jp2_t *jp2, opj_stream_private_t *cio, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Write index Finder box @@ -225,7 +225,7 @@ static OPJ_BOOL opj_jpip_write_iptr(opj_jp2_t *jp2, */ static OPJ_BOOL opj_jpip_write_cidx(opj_jp2_t *jp2, opj_stream_private_t *cio, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Write file Index (superbox) @@ -235,7 +235,7 @@ static OPJ_BOOL opj_jpip_write_cidx(opj_jp2_t *jp2, */ static OPJ_BOOL opj_jpip_write_fidx(opj_jp2_t *jp2, opj_stream_private_t *cio, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); #endif /* USE_JPIP */ /** @@ -249,9 +249,9 @@ static OPJ_BOOL opj_jpip_write_fidx(opj_jp2_t *jp2, * @return true if the file signature box is valid. */ static OPJ_BOOL opj_jp2_read_jp(opj_jp2_t *jp2, - OPJ_BYTE * p_header_data, + OPJ_BYTE *p_header_data, OPJ_UINT32 p_header_size, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Writes a jpeg2000 file signature box. @@ -264,7 +264,7 @@ static OPJ_BOOL opj_jp2_read_jp(opj_jp2_t *jp2, */ static OPJ_BOOL opj_jp2_write_jp(opj_jp2_t *jp2, opj_stream_private_t *cio, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** Apply collected palette data @@ -275,7 +275,7 @@ Apply collected palette data */ static OPJ_BOOL opj_jp2_apply_pclr(opj_image_t *image, opj_jp2_color_t *color, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); static void opj_jp2_free_pclr(opj_jp2_color_t *color); @@ -290,9 +290,9 @@ static void opj_jp2_free_pclr(opj_jp2_color_t *color); * @return Returns true if successful, returns false otherwise */ static OPJ_BOOL opj_jp2_read_pclr(opj_jp2_t *jp2, - OPJ_BYTE * p_pclr_header_data, + OPJ_BYTE *p_pclr_header_data, OPJ_UINT32 p_pclr_header_size, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Collect component mapping data @@ -305,10 +305,10 @@ static OPJ_BOOL opj_jp2_read_pclr(opj_jp2_t *jp2, * @return Returns true if successful, returns false otherwise */ -static OPJ_BOOL opj_jp2_read_cmap(opj_jp2_t * jp2, - OPJ_BYTE * p_cmap_header_data, +static OPJ_BOOL opj_jp2_read_cmap(opj_jp2_t *jp2, + OPJ_BYTE *p_cmap_header_data, OPJ_UINT32 p_cmap_header_size, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Reads the Color Specification box. @@ -321,9 +321,9 @@ static OPJ_BOOL opj_jp2_read_cmap(opj_jp2_t * jp2, * @return true if the bpc header is valid, false else. */ static OPJ_BOOL opj_jp2_read_colr(opj_jp2_t *jp2, - OPJ_BYTE * p_colr_header_data, + OPJ_BYTE *p_colr_header_data, OPJ_UINT32 p_colr_header_size, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /*@}*/ @@ -334,14 +334,14 @@ static OPJ_BOOL opj_jp2_read_colr(opj_jp2_t *jp2, * Developers wanting to extend the library can add their own writing procedures. */ static OPJ_BOOL opj_jp2_setup_end_header_writing(opj_jp2_t *jp2, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Sets up the procedures to do on reading header after the codestream. * Developers wanting to extend the library can add their own writing procedures. */ static OPJ_BOOL opj_jp2_setup_end_header_reading(opj_jp2_t *jp2, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Reads a jpeg2000 file header structure. @@ -353,8 +353,8 @@ static OPJ_BOOL opj_jp2_setup_end_header_reading(opj_jp2_t *jp2, * @return true if the box is valid. */ static OPJ_BOOL opj_jp2_read_header_procedure(opj_jp2_t *jp2, - opj_stream_private_t *stream, - opj_event_mgr_t * p_manager); + opj_stream_private_t *stream, + opj_event_mgr_t *p_manager); /** * Executes the given procedures on the given codec. @@ -366,10 +366,10 @@ static OPJ_BOOL opj_jp2_read_header_procedure(opj_jp2_t *jp2, * * @return true if all the procedures were successfully executed. */ -static OPJ_BOOL opj_jp2_exec(opj_jp2_t * jp2, - opj_procedure_list_t * p_procedure_list, +static OPJ_BOOL opj_jp2_exec(opj_jp2_t *jp2, + opj_procedure_list_t *p_procedure_list, opj_stream_private_t *stream, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Reads a box header. The box is the way data is packed inside a jpeg2000 file structure. @@ -382,26 +382,26 @@ static OPJ_BOOL opj_jp2_exec(opj_jp2_t * jp2, * @return true if the box is recognized, false otherwise */ static OPJ_BOOL opj_jp2_read_boxhdr(opj_jp2_box_t *box, - OPJ_UINT32 * p_number_bytes_read, + OPJ_UINT32 *p_number_bytes_read, opj_stream_private_t *cio, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Sets up the validation ,i.e. adds the procedures to launch to make sure the codec parameters * are valid. Developers wanting to extend the library can add their own validation procedures. */ static OPJ_BOOL opj_jp2_setup_encoding_validation(opj_jp2_t *jp2, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Sets up the procedures to do on writing header. Developers wanting to extend the library can add their own writing procedures. */ static OPJ_BOOL opj_jp2_setup_header_writing(opj_jp2_t *jp2, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); -static OPJ_BOOL opj_jp2_default_validation(opj_jp2_t * jp2, - opj_stream_private_t *cio, - opj_event_mgr_t * p_manager); +static OPJ_BOOL opj_jp2_default_validation(opj_jp2_t *jp2, + opj_stream_private_t *cio, + opj_event_mgr_t *p_manager); /** * Finds the image execution function related to the given box id. @@ -410,7 +410,7 @@ static OPJ_BOOL opj_jp2_default_validation(opj_jp2_t * jp2, * * @return the given handler or NULL if it could not be found. */ -static const opj_jp2_header_handler_t * opj_jp2_img_find_handler( +static const opj_jp2_header_handler_t *opj_jp2_img_find_handler( OPJ_UINT32 p_id); /** @@ -420,7 +420,7 @@ static const opj_jp2_header_handler_t * opj_jp2_img_find_handler( * * @return the given handler or NULL if it could not be found. */ -static const opj_jp2_header_handler_t * opj_jp2_find_handler(OPJ_UINT32 p_id); +static const opj_jp2_header_handler_t *opj_jp2_find_handler(OPJ_UINT32 p_id); static const opj_jp2_header_handler_t jp2_header [] = { {JP2_JP, opj_jp2_read_jp}, @@ -450,31 +450,30 @@ static const opj_jp2_header_handler_t jp2_img_header [] = { * @return true if the box is recognized, false otherwise */ static OPJ_BOOL opj_jp2_read_boxhdr_char(opj_jp2_box_t *box, - OPJ_BYTE * p_data, - OPJ_UINT32 * p_number_bytes_read, - OPJ_UINT32 p_box_max_size, - opj_event_mgr_t * p_manager); + OPJ_BYTE *p_data, + OPJ_UINT32 *p_number_bytes_read, + OPJ_UINT32 p_box_max_size, + opj_event_mgr_t *p_manager); /** * Sets up the validation ,i.e. adds the procedures to launch to make sure the codec parameters * are valid. Developers wanting to extend the library can add their own validation procedures. */ static OPJ_BOOL opj_jp2_setup_decoding_validation(opj_jp2_t *jp2, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Sets up the procedures to do on reading header. * Developers wanting to extend the library can add their own writing procedures. */ static OPJ_BOOL opj_jp2_setup_header_reading(opj_jp2_t *jp2, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /* ----------------------------------------------------------------------- */ static OPJ_BOOL opj_jp2_read_boxhdr(opj_jp2_box_t *box, - OPJ_UINT32 * p_number_bytes_read, + OPJ_UINT32 *p_number_bytes_read, opj_stream_private_t *cio, - opj_event_mgr_t * p_manager) -{ + opj_event_mgr_t *p_manager) { /* read header from file */ OPJ_BYTE l_data_header [8]; @@ -485,7 +484,7 @@ static OPJ_BOOL opj_jp2_read_boxhdr(opj_jp2_box_t *box, assert(p_manager != 00); *p_number_bytes_read = (OPJ_UINT32)opj_stream_read_data(cio, l_data_header, 8, - p_manager); + p_manager); if (*p_number_bytes_read != 8) { return OPJ_FALSE; } @@ -534,8 +533,7 @@ static OPJ_BOOL opj_jp2_read_boxhdr(opj_jp2_box_t *box, } #if 0 -static void jp2_write_url(opj_cio_t *cio, char *Idx_file) -{ +static void jp2_write_url(opj_cio_t *cio, char *Idx_file) { OPJ_UINT32 i; opj_jp2_box_t box; @@ -561,8 +559,7 @@ static void jp2_write_url(opj_cio_t *cio, char *Idx_file) static OPJ_BOOL opj_jp2_read_ihdr(opj_jp2_t *jp2, OPJ_BYTE *p_image_header_data, OPJ_UINT32 p_image_header_size, - opj_event_mgr_t * p_manager) -{ + opj_event_mgr_t *p_manager) { /* preconditions */ assert(p_image_header_data != 00); assert(jp2 != 00); @@ -599,8 +596,8 @@ static OPJ_BOOL opj_jp2_read_ihdr(opj_jp2_t *jp2, } /* allocate memory for components */ - jp2->comps = (opj_jp2_comps_t*) opj_calloc(jp2->numcomps, - sizeof(opj_jp2_comps_t)); + jp2->comps = (opj_jp2_comps_t *) opj_calloc(jp2->numcomps, + sizeof(opj_jp2_comps_t)); if (jp2->comps == 0) { opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to handle image header (ihdr)\n"); @@ -633,11 +630,10 @@ static OPJ_BOOL opj_jp2_read_ihdr(opj_jp2_t *jp2, return OPJ_TRUE; } -static OPJ_BYTE * opj_jp2_write_ihdr(opj_jp2_t *jp2, - OPJ_UINT32 * p_nb_bytes_written - ) -{ - OPJ_BYTE * l_ihdr_data, * l_current_ihdr_ptr; +static OPJ_BYTE *opj_jp2_write_ihdr(opj_jp2_t *jp2, + OPJ_UINT32 *p_nb_bytes_written + ) { + OPJ_BYTE *l_ihdr_data, * l_current_ihdr_ptr; /* preconditions */ assert(jp2 != 00); @@ -685,14 +681,13 @@ static OPJ_BYTE * opj_jp2_write_ihdr(opj_jp2_t *jp2, return l_ihdr_data; } -static OPJ_BYTE * opj_jp2_write_bpcc(opj_jp2_t *jp2, - OPJ_UINT32 * p_nb_bytes_written - ) -{ +static OPJ_BYTE *opj_jp2_write_bpcc(opj_jp2_t *jp2, + OPJ_UINT32 *p_nb_bytes_written + ) { OPJ_UINT32 i; /* room for 8 bytes for box and 1 byte for each component */ OPJ_UINT32 l_bpcc_size; - OPJ_BYTE * l_bpcc_data, * l_current_bpcc_ptr; + OPJ_BYTE *l_bpcc_data, * l_current_bpcc_ptr; /* preconditions */ assert(jp2 != 00); @@ -725,11 +720,10 @@ static OPJ_BYTE * opj_jp2_write_bpcc(opj_jp2_t *jp2, } static OPJ_BOOL opj_jp2_read_bpcc(opj_jp2_t *jp2, - OPJ_BYTE * p_bpc_header_data, + OPJ_BYTE *p_bpc_header_data, OPJ_UINT32 p_bpc_header_size, - opj_event_mgr_t * p_manager - ) -{ + opj_event_mgr_t *p_manager + ) { OPJ_UINT32 i; /* preconditions */ @@ -759,12 +753,11 @@ static OPJ_BOOL opj_jp2_read_bpcc(opj_jp2_t *jp2, return OPJ_TRUE; } -static OPJ_BYTE * opj_jp2_write_cdef(opj_jp2_t *jp2, - OPJ_UINT32 * p_nb_bytes_written) -{ +static OPJ_BYTE *opj_jp2_write_cdef(opj_jp2_t *jp2, + OPJ_UINT32 *p_nb_bytes_written) { /* room for 8 bytes for box, 2 for n */ OPJ_UINT32 l_cdef_size = 10; - OPJ_BYTE * l_cdef_data, * l_current_cdef_ptr; + OPJ_BYTE *l_cdef_data, * l_current_cdef_ptr; OPJ_UINT32 l_value; OPJ_UINT16 i; @@ -810,13 +803,12 @@ static OPJ_BYTE * opj_jp2_write_cdef(opj_jp2_t *jp2, return l_cdef_data; } -static OPJ_BYTE * opj_jp2_write_colr(opj_jp2_t *jp2, - OPJ_UINT32 * p_nb_bytes_written - ) -{ +static OPJ_BYTE *opj_jp2_write_colr(opj_jp2_t *jp2, + OPJ_UINT32 *p_nb_bytes_written + ) { /* room for 8 bytes for box 3 for common data and variable upon profile*/ OPJ_UINT32 l_colr_size = 11; - OPJ_BYTE * l_colr_data, * l_current_colr_ptr; + OPJ_BYTE *l_colr_data, * l_current_colr_ptr; /* preconditions */ assert(jp2 != 00); @@ -824,15 +816,15 @@ static OPJ_BYTE * opj_jp2_write_colr(opj_jp2_t *jp2, assert(jp2->meth == 1 || jp2->meth == 2); switch (jp2->meth) { - case 1 : - l_colr_size += 4; /* EnumCS */ - break; - case 2 : - assert(jp2->color.icc_profile_len); /* ICC profile */ - l_colr_size += jp2->color.icc_profile_len; - break; - default : - return 00; + case 1 : + l_colr_size += 4; /* EnumCS */ + break; + case 2 : + assert(jp2->color.icc_profile_len); /* ICC profile */ + l_colr_size += jp2->color.icc_profile_len; + break; + default : + return 00; } l_colr_data = (OPJ_BYTE *) opj_calloc(1, l_colr_size); @@ -877,8 +869,7 @@ static OPJ_BYTE * opj_jp2_write_colr(opj_jp2_t *jp2, return l_colr_data; } -static void opj_jp2_free_pclr(opj_jp2_color_t *color) -{ +static void opj_jp2_free_pclr(opj_jp2_color_t *color) { opj_free(color->jp2_pclr->channel_sign); opj_free(color->jp2_pclr->channel_size); opj_free(color->jp2_pclr->entries); @@ -892,8 +883,7 @@ static void opj_jp2_free_pclr(opj_jp2_color_t *color) } static OPJ_BOOL opj_jp2_check_color(opj_image_t *image, opj_jp2_color_t *color, - opj_event_mgr_t *p_manager) -{ + opj_event_mgr_t *p_manager) { OPJ_UINT16 i; /* testcase 4149.pdf.SIGSEGV.cf7.3501 */ @@ -1035,8 +1025,7 @@ static OPJ_BOOL opj_jp2_check_color(opj_image_t *image, opj_jp2_color_t *color, /* file9.jp2 */ static OPJ_BOOL opj_jp2_apply_pclr(opj_image_t *image, opj_jp2_color_t *color, - opj_event_mgr_t * p_manager) -{ + opj_event_mgr_t *p_manager) { opj_image_comp_t *old_comps, *new_comps; OPJ_BYTE *channel_size, *channel_sign; OPJ_UINT32 *entries; @@ -1063,7 +1052,7 @@ static OPJ_BOOL opj_jp2_apply_pclr(opj_image_t *image, } old_comps = image->comps; - new_comps = (opj_image_comp_t*) + new_comps = (opj_image_comp_t *) opj_malloc(nr_channels * sizeof(opj_image_comp_t)); if (!new_comps) { opj_event_msg(p_manager, EVT_ERROR, @@ -1084,7 +1073,7 @@ static OPJ_BOOL opj_jp2_apply_pclr(opj_image_t *image, } /* Palette mapping: */ - new_comps[i].data = (OPJ_INT32*) + new_comps[i].data = (OPJ_INT32 *) opj_image_data_alloc(sizeof(OPJ_INT32) * old_comps[cmp].w * old_comps[cmp].h); if (!new_comps[i].data) { while (i > 0) { @@ -1150,11 +1139,10 @@ static OPJ_BOOL opj_jp2_apply_pclr(opj_image_t *image, }/* apply_pclr() */ static OPJ_BOOL opj_jp2_read_pclr(opj_jp2_t *jp2, - OPJ_BYTE * p_pclr_header_data, + OPJ_BYTE *p_pclr_header_data, OPJ_UINT32 p_pclr_header_size, - opj_event_mgr_t * p_manager - ) -{ + opj_event_mgr_t *p_manager + ) { opj_jp2_pclr_t *jp2_pclr; OPJ_BYTE *channel_size, *channel_sign; OPJ_UINT32 *entries; @@ -1199,24 +1187,24 @@ static OPJ_BOOL opj_jp2_read_pclr(opj_jp2_t *jp2, return OPJ_FALSE; } - entries = (OPJ_UINT32*) opj_malloc(sizeof(OPJ_UINT32) * nr_channels * - nr_entries); + entries = (OPJ_UINT32 *) opj_malloc(sizeof(OPJ_UINT32) * nr_channels * + nr_entries); if (!entries) { return OPJ_FALSE; } - channel_size = (OPJ_BYTE*) opj_malloc(nr_channels); + channel_size = (OPJ_BYTE *) opj_malloc(nr_channels); if (!channel_size) { opj_free(entries); return OPJ_FALSE; } - channel_sign = (OPJ_BYTE*) opj_malloc(nr_channels); + channel_sign = (OPJ_BYTE *) opj_malloc(nr_channels); if (!channel_sign) { opj_free(entries); opj_free(channel_size); return OPJ_FALSE; } - jp2_pclr = (opj_jp2_pclr_t*)opj_malloc(sizeof(opj_jp2_pclr_t)); + jp2_pclr = (opj_jp2_pclr_t *)opj_malloc(sizeof(opj_jp2_pclr_t)); if (!jp2_pclr) { opj_free(entries); opj_free(channel_size); @@ -1249,7 +1237,7 @@ static OPJ_BOOL opj_jp2_read_pclr(opj_jp2_t *jp2, bytes_to_read = sizeof(OPJ_UINT32); } if ((ptrdiff_t)p_pclr_header_size < (ptrdiff_t)(p_pclr_header_data - - orig_header_data) + (ptrdiff_t)bytes_to_read) { + orig_header_data) + (ptrdiff_t)bytes_to_read) { return OPJ_FALSE; } @@ -1263,12 +1251,11 @@ static OPJ_BOOL opj_jp2_read_pclr(opj_jp2_t *jp2, return OPJ_TRUE; } -static OPJ_BOOL opj_jp2_read_cmap(opj_jp2_t * jp2, - OPJ_BYTE * p_cmap_header_data, +static OPJ_BOOL opj_jp2_read_cmap(opj_jp2_t *jp2, + OPJ_BYTE *p_cmap_header_data, OPJ_UINT32 p_cmap_header_size, - opj_event_mgr_t * p_manager - ) -{ + opj_event_mgr_t *p_manager + ) { opj_jp2_cmap_comp_t *cmap; OPJ_BYTE i, nr_channels; OPJ_UINT32 l_value; @@ -1300,8 +1287,8 @@ static OPJ_BOOL opj_jp2_read_cmap(opj_jp2_t * jp2, return OPJ_FALSE; } - cmap = (opj_jp2_cmap_comp_t*) opj_malloc(nr_channels * sizeof( - opj_jp2_cmap_comp_t)); + cmap = (opj_jp2_cmap_comp_t *) opj_malloc(nr_channels * sizeof( + opj_jp2_cmap_comp_t)); if (!cmap) { return OPJ_FALSE; } @@ -1327,8 +1314,7 @@ static OPJ_BOOL opj_jp2_read_cmap(opj_jp2_t * jp2, } static void opj_jp2_apply_cdef(opj_image_t *image, opj_jp2_color_t *color, - opj_event_mgr_t *manager) -{ + opj_event_mgr_t *manager) { opj_jp2_cdef_info_t *info; OPJ_UINT16 i, n, cn, asoc, acn; @@ -1389,12 +1375,11 @@ static void opj_jp2_apply_cdef(opj_image_t *image, opj_jp2_color_t *color, }/* jp2_apply_cdef() */ -static OPJ_BOOL opj_jp2_read_cdef(opj_jp2_t * jp2, - OPJ_BYTE * p_cdef_header_data, +static OPJ_BOOL opj_jp2_read_cdef(opj_jp2_t *jp2, + OPJ_BYTE *p_cdef_header_data, OPJ_UINT32 p_cdef_header_size, - opj_event_mgr_t * p_manager - ) -{ + opj_event_mgr_t *p_manager + ) { opj_jp2_cdef_info_t *cdef_info; OPJ_UINT16 i; OPJ_UINT32 l_value; @@ -1430,13 +1415,13 @@ static OPJ_BOOL opj_jp2_read_cdef(opj_jp2_t * jp2, return OPJ_FALSE; } - cdef_info = (opj_jp2_cdef_info_t*) opj_malloc(l_value * sizeof( - opj_jp2_cdef_info_t)); + cdef_info = (opj_jp2_cdef_info_t *) opj_malloc(l_value * sizeof( + opj_jp2_cdef_info_t)); if (!cdef_info) { return OPJ_FALSE; } - jp2->color.jp2_cdef = (opj_jp2_cdef_t*)opj_malloc(sizeof(opj_jp2_cdef_t)); + jp2->color.jp2_cdef = (opj_jp2_cdef_t *)opj_malloc(sizeof(opj_jp2_cdef_t)); if (!jp2->color.jp2_cdef) { opj_free(cdef_info); return OPJ_FALSE; @@ -1462,11 +1447,10 @@ static OPJ_BOOL opj_jp2_read_cdef(opj_jp2_t * jp2, } static OPJ_BOOL opj_jp2_read_colr(opj_jp2_t *jp2, - OPJ_BYTE * p_colr_header_data, + OPJ_BYTE *p_colr_header_data, OPJ_UINT32 p_colr_header_size, - opj_event_mgr_t * p_manager - ) -{ + opj_event_mgr_t *p_manager + ) { OPJ_UINT32 l_value; /* preconditions */ @@ -1519,7 +1503,7 @@ static OPJ_BOOL opj_jp2_read_colr(opj_jp2_t *jp2, OPJ_UINT32 *cielab; OPJ_UINT32 rl, ol, ra, oa, rb, ob, il; - cielab = (OPJ_UINT32*)opj_malloc(9 * sizeof(OPJ_UINT32)); + cielab = (OPJ_UINT32 *)opj_malloc(9 * sizeof(OPJ_UINT32)); if (cielab == NULL) { opj_event_msg(p_manager, EVT_ERROR, "Not enough memory for cielab\n"); return OPJ_FALSE; @@ -1560,7 +1544,7 @@ static OPJ_BOOL opj_jp2_read_colr(opj_jp2_t *jp2, cielab[7] = ob; cielab[8] = il; - jp2->color.icc_profile_buf = (OPJ_BYTE*)cielab; + jp2->color.icc_profile_buf = (OPJ_BYTE *)cielab; jp2->color.icc_profile_len = 0; } jp2->color.jp2_has_colr = 1; @@ -1570,7 +1554,7 @@ static OPJ_BOOL opj_jp2_read_colr(opj_jp2_t *jp2, OPJ_INT32 icc_len = (OPJ_INT32)p_colr_header_size - 3; jp2->color.icc_profile_len = (OPJ_UINT32)icc_len; - jp2->color.icc_profile_buf = (OPJ_BYTE*) opj_calloc(1, (size_t)icc_len); + jp2->color.icc_profile_buf = (OPJ_BYTE *) opj_calloc(1, (size_t)icc_len); if (!jp2->color.icc_profile_buf) { jp2->color.icc_profile_len = 0; return OPJ_FALSE; @@ -1595,9 +1579,8 @@ static OPJ_BOOL opj_jp2_read_colr(opj_jp2_t *jp2, } static OPJ_BOOL opj_jp2_apply_color_postprocessing(opj_jp2_t *jp2, - opj_image_t* p_image, - opj_event_mgr_t * p_manager) -{ + opj_image_t *p_image, + opj_event_mgr_t *p_manager) { if (jp2->j2k->m_specific_param.m_decoder.m_numcomps_to_decode) { /* Bypass all JP2 component transforms */ return OPJ_TRUE; @@ -1630,9 +1613,8 @@ static OPJ_BOOL opj_jp2_apply_color_postprocessing(opj_jp2_t *jp2, OPJ_BOOL opj_jp2_decode(opj_jp2_t *jp2, opj_stream_private_t *p_stream, - opj_image_t* p_image, - opj_event_mgr_t * p_manager) -{ + opj_image_t *p_image, + opj_event_mgr_t *p_manager) { if (!p_image) { return OPJ_FALSE; } @@ -1649,11 +1631,10 @@ OPJ_BOOL opj_jp2_decode(opj_jp2_t *jp2, static OPJ_BOOL opj_jp2_write_jp2h(opj_jp2_t *jp2, opj_stream_private_t *stream, - opj_event_mgr_t * p_manager - ) -{ + opj_event_mgr_t *p_manager + ) { opj_jp2_img_header_writer_handler_t l_writers [4]; - opj_jp2_img_header_writer_handler_t * l_current_writer; + opj_jp2_img_header_writer_handler_t *l_current_writer; OPJ_INT32 i, l_nb_pass; /* size of data for super box*/ @@ -1693,7 +1674,7 @@ static OPJ_BOOL opj_jp2_write_jp2h(opj_jp2_t *jp2, l_current_writer = l_writers; for (i = 0; i < l_nb_pass; ++i) { l_current_writer->m_data = l_current_writer->handler(jp2, - &(l_current_writer->m_size)); + &(l_current_writer->m_size)); if (l_current_writer->m_data == 00) { opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to hold JP2 Header data\n"); @@ -1756,11 +1737,10 @@ static OPJ_BOOL opj_jp2_write_jp2h(opj_jp2_t *jp2, static OPJ_BOOL opj_jp2_write_ftyp(opj_jp2_t *jp2, opj_stream_private_t *cio, - opj_event_mgr_t * p_manager) -{ + opj_event_mgr_t *p_manager) { OPJ_UINT32 i; OPJ_UINT32 l_ftyp_size; - OPJ_BYTE * l_ftyp_data, * l_current_data_ptr; + OPJ_BYTE *l_ftyp_data, * l_current_data_ptr; OPJ_BOOL l_result; /* preconditions */ @@ -1808,8 +1788,7 @@ static OPJ_BOOL opj_jp2_write_ftyp(opj_jp2_t *jp2, static OPJ_BOOL opj_jp2_write_jp2c(opj_jp2_t *jp2, opj_stream_private_t *cio, - opj_event_mgr_t * p_manager) -{ + opj_event_mgr_t *p_manager) { OPJ_OFF_T j2k_codestream_exit; OPJ_BYTE l_data_header [8]; @@ -1846,8 +1825,7 @@ static OPJ_BOOL opj_jp2_write_jp2c(opj_jp2_t *jp2, static OPJ_BOOL opj_jp2_write_jp(opj_jp2_t *jp2, opj_stream_private_t *cio, - opj_event_mgr_t * p_manager) -{ + opj_event_mgr_t *p_manager) { /* 12 bytes will be read */ OPJ_BYTE l_signature_data [12]; @@ -1876,8 +1854,7 @@ static OPJ_BOOL opj_jp2_write_jp(opj_jp2_t *jp2, /* JP2 decoder interface */ /* ----------------------------------------------------------------------- */ -void opj_jp2_setup_decoder(opj_jp2_t *jp2, opj_dparameters_t *parameters) -{ +void opj_jp2_setup_decoder(opj_jp2_t *jp2, opj_dparameters_t *parameters) { /* setup the J2K codec */ opj_j2k_setup_decoder(jp2->j2k, parameters); @@ -1887,13 +1864,11 @@ void opj_jp2_setup_decoder(opj_jp2_t *jp2, opj_dparameters_t *parameters) OPJ_DPARAMETERS_IGNORE_PCLR_CMAP_CDEF_FLAG; } -void opj_jp2_decoder_set_strict_mode(opj_jp2_t *jp2, OPJ_BOOL strict) -{ +void opj_jp2_decoder_set_strict_mode(opj_jp2_t *jp2, OPJ_BOOL strict) { opj_j2k_decoder_set_strict_mode(jp2->j2k, strict); } -OPJ_BOOL opj_jp2_set_threads(opj_jp2_t *jp2, OPJ_UINT32 num_threads) -{ +OPJ_BOOL opj_jp2_set_threads(opj_jp2_t *jp2, OPJ_UINT32 num_threads) { return opj_j2k_set_threads(jp2->j2k, num_threads); } @@ -1904,8 +1879,7 @@ OPJ_BOOL opj_jp2_set_threads(opj_jp2_t *jp2, OPJ_UINT32 num_threads) OPJ_BOOL opj_jp2_setup_encoder(opj_jp2_t *jp2, opj_cparameters_t *parameters, opj_image_t *image, - opj_event_mgr_t * p_manager) -{ + opj_event_mgr_t *p_manager) { OPJ_UINT32 i; OPJ_UINT32 depth_0; OPJ_UINT32 sign; @@ -1941,7 +1915,7 @@ OPJ_BOOL opj_jp2_setup_encoder(opj_jp2_t *jp2, jp2->brand = JP2_JP2; /* BR */ jp2->minversion = 0; /* MinV */ jp2->numcl = 1; - jp2->cl = (OPJ_UINT32*) opj_malloc(jp2->numcl * sizeof(OPJ_UINT32)); + jp2->cl = (OPJ_UINT32 *) opj_malloc(jp2->numcl * sizeof(OPJ_UINT32)); if (!jp2->cl) { opj_event_msg(p_manager, EVT_ERROR, "Not enough memory when setup the JP2 encoder\n"); @@ -1952,8 +1926,8 @@ OPJ_BOOL opj_jp2_setup_encoder(opj_jp2_t *jp2, /* Image Header box */ jp2->numcomps = image->numcomps; /* NC */ - jp2->comps = (opj_jp2_comps_t*) opj_malloc(jp2->numcomps * sizeof( - opj_jp2_comps_t)); + jp2->comps = (opj_jp2_comps_t *) opj_malloc(jp2->numcomps * sizeof( + opj_jp2_comps_t)); if (!jp2->comps) { opj_event_msg(p_manager, EVT_ERROR, "Not enough memory when setup the JP2 encoder\n"); @@ -2020,16 +1994,16 @@ OPJ_BOOL opj_jp2_setup_encoder(opj_jp2_t *jp2, } if (alpha_count == 1U) { /* no way to deal with more than 1 alpha channel */ switch (jp2->enumcs) { - case 16: - case 18: - color_channels = 3; - break; - case 17: - color_channels = 1; - break; - default: - alpha_count = 0U; - break; + case 16: + case 18: + color_channels = 3; + break; + case 17: + color_channels = 1; + break; + default: + alpha_count = 0U; + break; } if (alpha_count == 0U) { opj_event_msg(p_manager, EVT_WARNING, @@ -2048,7 +2022,7 @@ OPJ_BOOL opj_jp2_setup_encoder(opj_jp2_t *jp2, "Multiple alpha channels specified. No cdef box will be created.\n"); } if (alpha_count == 1U) { /* if here, we know what we can do */ - jp2->color.jp2_cdef = (opj_jp2_cdef_t*)opj_malloc(sizeof(opj_jp2_cdef_t)); + jp2->color.jp2_cdef = (opj_jp2_cdef_t *)opj_malloc(sizeof(opj_jp2_cdef_t)); if (!jp2->color.jp2_cdef) { opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to setup the JP2 encoder\n"); @@ -2056,7 +2030,7 @@ OPJ_BOOL opj_jp2_setup_encoder(opj_jp2_t *jp2, } /* no memset needed, all values will be overwritten except if jp2->color.jp2_cdef->info allocation fails, */ /* in which case jp2->color.jp2_cdef->info will be NULL => valid for destruction */ - jp2->color.jp2_cdef->info = (opj_jp2_cdef_info_t*) opj_malloc( + jp2->color.jp2_cdef->info = (opj_jp2_cdef_info_t *) opj_malloc( image->numcomps * sizeof(opj_jp2_cdef_info_t)); if (!jp2->color.jp2_cdef->info) { /* memory will be freed by opj_jp2_destroy */ @@ -2071,7 +2045,7 @@ OPJ_BOOL opj_jp2_setup_encoder(opj_jp2_t *jp2, i; /* cast is valid : image->numcomps [1,16384] */ jp2->color.jp2_cdef->info[i].typ = 0U; jp2->color.jp2_cdef->info[i].asoc = (OPJ_UINT16)(i + - 1U); /* No overflow + cast is valid : image->numcomps [1,16384] */ + 1U); /* No overflow + cast is valid : image->numcomps [1,16384] */ } for (; i < image->numcomps; i++) { if (image->comps[i].alpha != 0) { /* we'll be here exactly once */ @@ -2100,16 +2074,14 @@ OPJ_BOOL opj_jp2_setup_encoder(opj_jp2_t *jp2, OPJ_BOOL opj_jp2_encode(opj_jp2_t *jp2, opj_stream_private_t *stream, - opj_event_mgr_t * p_manager) -{ + opj_event_mgr_t *p_manager) { return opj_j2k_encode(jp2->j2k, stream, p_manager); } OPJ_BOOL opj_jp2_end_decompress(opj_jp2_t *jp2, opj_stream_private_t *cio, - opj_event_mgr_t * p_manager - ) -{ + opj_event_mgr_t *p_manager + ) { /* preconditions */ assert(jp2 != 00); assert(cio != 00); @@ -2130,9 +2102,8 @@ OPJ_BOOL opj_jp2_end_decompress(opj_jp2_t *jp2, OPJ_BOOL opj_jp2_end_compress(opj_jp2_t *jp2, opj_stream_private_t *cio, - opj_event_mgr_t * p_manager - ) -{ + opj_event_mgr_t *p_manager + ) { /* preconditions */ assert(jp2 != 00); assert(cio != 00); @@ -2152,8 +2123,7 @@ OPJ_BOOL opj_jp2_end_compress(opj_jp2_t *jp2, } static OPJ_BOOL opj_jp2_setup_end_header_writing(opj_jp2_t *jp2, - opj_event_mgr_t * p_manager) -{ + opj_event_mgr_t *p_manager) { /* preconditions */ assert(jp2 != 00); assert(p_manager != 00); @@ -2187,8 +2157,7 @@ static OPJ_BOOL opj_jp2_setup_end_header_writing(opj_jp2_t *jp2, } static OPJ_BOOL opj_jp2_setup_end_header_reading(opj_jp2_t *jp2, - opj_event_mgr_t * p_manager) -{ + opj_event_mgr_t *p_manager) { /* preconditions */ assert(jp2 != 00); assert(p_manager != 00); @@ -2202,11 +2171,10 @@ static OPJ_BOOL opj_jp2_setup_end_header_reading(opj_jp2_t *jp2, return OPJ_TRUE; } -static OPJ_BOOL opj_jp2_default_validation(opj_jp2_t * jp2, - opj_stream_private_t *cio, - opj_event_mgr_t * p_manager - ) -{ +static OPJ_BOOL opj_jp2_default_validation(opj_jp2_t *jp2, + opj_stream_private_t *cio, + opj_event_mgr_t *p_manager + ) { OPJ_BOOL l_is_valid = OPJ_TRUE; OPJ_UINT32 i; @@ -2260,24 +2228,23 @@ static OPJ_BOOL opj_jp2_default_validation(opj_jp2_t * jp2, } static OPJ_BOOL opj_jp2_read_header_procedure(opj_jp2_t *jp2, - opj_stream_private_t *stream, - opj_event_mgr_t * p_manager - ) -{ + opj_stream_private_t *stream, + opj_event_mgr_t *p_manager + ) { opj_jp2_box_t box; OPJ_UINT32 l_nb_bytes_read; - const opj_jp2_header_handler_t * l_current_handler; - const opj_jp2_header_handler_t * l_current_handler_misplaced; + const opj_jp2_header_handler_t *l_current_handler; + const opj_jp2_header_handler_t *l_current_handler_misplaced; OPJ_UINT32 l_last_data_size = OPJ_BOX_SIZE; OPJ_UINT32 l_current_data_size; - OPJ_BYTE * l_current_data = 00; + OPJ_BYTE *l_current_data = 00; /* preconditions */ assert(stream != 00); assert(jp2 != 00); assert(p_manager != 00); - l_current_data = (OPJ_BYTE*)opj_calloc(1, l_last_data_size); + l_current_data = (OPJ_BYTE *)opj_calloc(1, l_last_data_size); if (l_current_data == 00) { opj_event_msg(p_manager, EVT_ERROR, @@ -2350,8 +2317,8 @@ static OPJ_BOOL opj_jp2_read_header_procedure(opj_jp2_t *jp2, return OPJ_FALSE; } if (l_current_data_size > l_last_data_size) { - OPJ_BYTE* new_current_data = (OPJ_BYTE*)opj_realloc(l_current_data, - l_current_data_size); + OPJ_BYTE *new_current_data = (OPJ_BYTE *)opj_realloc(l_current_data, + l_current_data_size); if (!new_current_data) { opj_free(l_current_data); opj_event_msg(p_manager, EVT_ERROR, @@ -2363,7 +2330,7 @@ static OPJ_BOOL opj_jp2_read_header_procedure(opj_jp2_t *jp2, } l_nb_bytes_read = (OPJ_UINT32)opj_stream_read_data(stream, l_current_data, - l_current_data_size, p_manager); + l_current_data_size, p_manager); if (l_nb_bytes_read != l_current_data_size) { opj_event_msg(p_manager, EVT_ERROR, "Problem with reading JPEG2000 box, stream error\n"); @@ -2424,14 +2391,14 @@ static OPJ_BOOL opj_jp2_read_header_procedure(opj_jp2_t *jp2, * * @return true if all the procedures were successfully executed. */ -static OPJ_BOOL opj_jp2_exec(opj_jp2_t * jp2, - opj_procedure_list_t * p_procedure_list, +static OPJ_BOOL opj_jp2_exec(opj_jp2_t *jp2, + opj_procedure_list_t *p_procedure_list, opj_stream_private_t *stream, - opj_event_mgr_t * p_manager + opj_event_mgr_t *p_manager ) { - OPJ_BOOL(** l_procedure)(opj_jp2_t * jp2, opj_stream_private_t *, + OPJ_BOOL(** l_procedure)(opj_jp2_t *jp2, opj_stream_private_t *, opj_event_mgr_t *) = 00; OPJ_BOOL l_result = OPJ_TRUE; OPJ_UINT32 l_nb_proc, i; @@ -2443,8 +2410,8 @@ static OPJ_BOOL opj_jp2_exec(opj_jp2_t * jp2, assert(p_manager != 00); l_nb_proc = opj_procedure_list_get_nb_procedures(p_procedure_list); - l_procedure = (OPJ_BOOL(**)(opj_jp2_t * jp2, opj_stream_private_t *, - opj_event_mgr_t *)) opj_procedure_list_get_first_procedure(p_procedure_list); + l_procedure = (OPJ_BOOL(* *)(opj_jp2_t *jp2, opj_stream_private_t *, + opj_event_mgr_t *)) opj_procedure_list_get_first_procedure(p_procedure_list); for (i = 0; i < l_nb_proc; ++i) { l_result = l_result && (*l_procedure)(jp2, stream, p_manager); @@ -2458,10 +2425,9 @@ static OPJ_BOOL opj_jp2_exec(opj_jp2_t * jp2, OPJ_BOOL opj_jp2_start_compress(opj_jp2_t *jp2, opj_stream_private_t *stream, - opj_image_t * p_image, - opj_event_mgr_t * p_manager - ) -{ + opj_image_t *p_image, + opj_event_mgr_t *p_manager + ) { /* preconditions */ assert(jp2 != 00); assert(stream != 00); @@ -2490,8 +2456,7 @@ OPJ_BOOL opj_jp2_start_compress(opj_jp2_t *jp2, return opj_j2k_start_compress(jp2->j2k, stream, p_image, p_manager); } -static const opj_jp2_header_handler_t * opj_jp2_find_handler(OPJ_UINT32 p_id) -{ +static const opj_jp2_header_handler_t *opj_jp2_find_handler(OPJ_UINT32 p_id) { OPJ_UINT32 i, l_handler_size = sizeof(jp2_header) / sizeof( opj_jp2_header_handler_t); @@ -2510,9 +2475,8 @@ static const opj_jp2_header_handler_t * opj_jp2_find_handler(OPJ_UINT32 p_id) * * @return the given handler or 00 if it could not be found. */ -static const opj_jp2_header_handler_t * opj_jp2_img_find_handler( - OPJ_UINT32 p_id) -{ +static const opj_jp2_header_handler_t *opj_jp2_img_find_handler( + OPJ_UINT32 p_id) { OPJ_UINT32 i, l_handler_size = sizeof(jp2_img_header) / sizeof( opj_jp2_header_handler_t); for (i = 0; i < l_handler_size; ++i) { @@ -2535,9 +2499,9 @@ static const opj_jp2_header_handler_t * opj_jp2_img_find_handler( * @return true if the file signature box is valid. */ static OPJ_BOOL opj_jp2_read_jp(opj_jp2_t *jp2, - OPJ_BYTE * p_header_data, + OPJ_BYTE *p_header_data, OPJ_UINT32 p_header_size, - opj_event_mgr_t * p_manager + opj_event_mgr_t *p_manager ) { @@ -2584,11 +2548,10 @@ static OPJ_BOOL opj_jp2_read_jp(opj_jp2_t *jp2, * @return true if the FTYP box is valid. */ static OPJ_BOOL opj_jp2_read_ftyp(opj_jp2_t *jp2, - OPJ_BYTE * p_header_data, + OPJ_BYTE *p_header_data, OPJ_UINT32 p_header_size, - opj_event_mgr_t * p_manager - ) -{ + opj_event_mgr_t *p_manager + ) { OPJ_UINT32 i, l_remaining_bytes; /* preconditions */ @@ -2644,8 +2607,7 @@ static OPJ_BOOL opj_jp2_read_ftyp(opj_jp2_t *jp2, static OPJ_BOOL opj_jp2_skip_jp2c(opj_jp2_t *jp2, opj_stream_private_t *stream, - opj_event_mgr_t * p_manager) -{ + opj_event_mgr_t *p_manager) { /* preconditions */ assert(jp2 != 00); assert(stream != 00); @@ -2662,8 +2624,7 @@ static OPJ_BOOL opj_jp2_skip_jp2c(opj_jp2_t *jp2, static OPJ_BOOL opj_jpip_skip_iptr(opj_jp2_t *jp2, opj_stream_private_t *stream, - opj_event_mgr_t * p_manager) -{ + opj_event_mgr_t *p_manager) { /* preconditions */ assert(jp2 != 00); assert(stream != 00); @@ -2691,12 +2652,11 @@ static OPJ_BOOL opj_jpip_skip_iptr(opj_jp2_t *jp2, static OPJ_BOOL opj_jp2_read_jp2h(opj_jp2_t *jp2, OPJ_BYTE *p_header_data, OPJ_UINT32 p_header_size, - opj_event_mgr_t * p_manager - ) -{ + opj_event_mgr_t *p_manager + ) { OPJ_UINT32 l_box_size = 0, l_current_data_size = 0; opj_jp2_box_t box; - const opj_jp2_header_handler_t * l_current_handler; + const opj_jp2_header_handler_t *l_current_handler; OPJ_BOOL l_has_ihdr = 0; /* preconditions */ @@ -2763,12 +2723,11 @@ static OPJ_BOOL opj_jp2_read_jp2h(opj_jp2_t *jp2, } static OPJ_BOOL opj_jp2_read_boxhdr_char(opj_jp2_box_t *box, - OPJ_BYTE * p_data, - OPJ_UINT32 * p_number_bytes_read, - OPJ_UINT32 p_box_max_size, - opj_event_mgr_t * p_manager - ) -{ + OPJ_BYTE *p_data, + OPJ_UINT32 *p_number_bytes_read, + OPJ_UINT32 p_box_max_size, + opj_event_mgr_t *p_manager + ) { OPJ_UINT32 l_value; /* preconditions */ @@ -2835,10 +2794,9 @@ static OPJ_BOOL opj_jp2_read_boxhdr_char(opj_jp2_box_t *box, OPJ_BOOL opj_jp2_read_header(opj_stream_private_t *p_stream, opj_jp2_t *jp2, - opj_image_t ** p_image, - opj_event_mgr_t * p_manager - ) -{ + opj_image_t **p_image, + opj_event_mgr_t *p_manager + ) { int ret; /* preconditions */ @@ -2905,8 +2863,7 @@ OPJ_BOOL opj_jp2_read_header(opj_stream_private_t *p_stream, } static OPJ_BOOL opj_jp2_setup_encoding_validation(opj_jp2_t *jp2, - opj_event_mgr_t * p_manager) -{ + opj_event_mgr_t *p_manager) { /* preconditions */ assert(jp2 != 00); assert(p_manager != 00); @@ -2921,8 +2878,7 @@ static OPJ_BOOL opj_jp2_setup_encoding_validation(opj_jp2_t *jp2, } static OPJ_BOOL opj_jp2_setup_decoding_validation(opj_jp2_t *jp2, - opj_event_mgr_t * p_manager) -{ + opj_event_mgr_t *p_manager) { /* preconditions */ assert(jp2 != 00); assert(p_manager != 00); @@ -2936,8 +2892,7 @@ static OPJ_BOOL opj_jp2_setup_decoding_validation(opj_jp2_t *jp2, } static OPJ_BOOL opj_jp2_setup_header_writing(opj_jp2_t *jp2, - opj_event_mgr_t * p_manager) -{ + opj_event_mgr_t *p_manager) { /* preconditions */ assert(jp2 != 00); assert(p_manager != 00); @@ -2971,8 +2926,7 @@ static OPJ_BOOL opj_jp2_setup_header_writing(opj_jp2_t *jp2, } static OPJ_BOOL opj_jp2_setup_header_reading(opj_jp2_t *jp2, - opj_event_mgr_t * p_manager) -{ + opj_event_mgr_t *p_manager) { /* preconditions */ assert(jp2 != 00); assert(p_manager != 00); @@ -2987,19 +2941,18 @@ static OPJ_BOOL opj_jp2_setup_header_reading(opj_jp2_t *jp2, return OPJ_TRUE; } -OPJ_BOOL opj_jp2_read_tile_header(opj_jp2_t * p_jp2, - OPJ_UINT32 * p_tile_index, - OPJ_UINT32 * p_data_size, - OPJ_INT32 * p_tile_x0, - OPJ_INT32 * p_tile_y0, - OPJ_INT32 * p_tile_x1, - OPJ_INT32 * p_tile_y1, - OPJ_UINT32 * p_nb_comps, - OPJ_BOOL * p_go_on, +OPJ_BOOL opj_jp2_read_tile_header(opj_jp2_t *p_jp2, + OPJ_UINT32 *p_tile_index, + OPJ_UINT32 *p_data_size, + OPJ_INT32 *p_tile_x0, + OPJ_INT32 *p_tile_y0, + OPJ_INT32 *p_tile_x1, + OPJ_INT32 *p_tile_y1, + OPJ_UINT32 *p_nb_comps, + OPJ_BOOL *p_go_on, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager - ) -{ + opj_event_mgr_t *p_manager + ) { return opj_j2k_read_tile_header(p_jp2->j2k, p_tile_index, p_data_size, @@ -3013,10 +2966,10 @@ OPJ_BOOL opj_jp2_read_tile_header(opj_jp2_t * p_jp2, OPJ_BOOL opj_jp2_write_tile(opj_jp2_t *p_jp2, OPJ_UINT32 p_tile_index, - OPJ_BYTE * p_data, + OPJ_BYTE *p_data, OPJ_UINT32 p_data_size, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager + opj_event_mgr_t *p_manager ) { @@ -3024,20 +2977,18 @@ OPJ_BOOL opj_jp2_write_tile(opj_jp2_t *p_jp2, p_stream, p_manager); } -OPJ_BOOL opj_jp2_decode_tile(opj_jp2_t * p_jp2, +OPJ_BOOL opj_jp2_decode_tile(opj_jp2_t *p_jp2, OPJ_UINT32 p_tile_index, - OPJ_BYTE * p_data, + OPJ_BYTE *p_data, OPJ_UINT32 p_data_size, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager - ) -{ + opj_event_mgr_t *p_manager + ) { return opj_j2k_decode_tile(p_jp2->j2k, p_tile_index, p_data, p_data_size, p_stream, p_manager); } -void opj_jp2_destroy(opj_jp2_t *jp2) -{ +void opj_jp2_destroy(opj_jp2_t *jp2) { if (jp2) { /* destroy the J2K codec */ opj_j2k_destroy(jp2->j2k); @@ -3106,32 +3057,29 @@ void opj_jp2_destroy(opj_jp2_t *jp2) OPJ_BOOL opj_jp2_set_decoded_components(opj_jp2_t *p_jp2, OPJ_UINT32 numcomps, - const OPJ_UINT32* comps_indices, - opj_event_mgr_t * p_manager) -{ + const OPJ_UINT32 *comps_indices, + opj_event_mgr_t *p_manager) { return opj_j2k_set_decoded_components(p_jp2->j2k, numcomps, comps_indices, p_manager); } OPJ_BOOL opj_jp2_set_decode_area(opj_jp2_t *p_jp2, - opj_image_t* p_image, + opj_image_t *p_image, OPJ_INT32 p_start_x, OPJ_INT32 p_start_y, OPJ_INT32 p_end_x, OPJ_INT32 p_end_y, - opj_event_mgr_t * p_manager - ) -{ + opj_event_mgr_t *p_manager + ) { return opj_j2k_set_decode_area(p_jp2->j2k, p_image, p_start_x, p_start_y, p_end_x, p_end_y, p_manager); } OPJ_BOOL opj_jp2_get_tile(opj_jp2_t *p_jp2, opj_stream_private_t *p_stream, - opj_image_t* p_image, - opj_event_mgr_t * p_manager, + opj_image_t *p_image, + opj_event_mgr_t *p_manager, OPJ_UINT32 tile_index - ) -{ + ) { if (!p_image) { return OPJ_FALSE; } @@ -3152,9 +3100,8 @@ OPJ_BOOL opj_jp2_get_tile(opj_jp2_t *p_jp2, /* JP2 encoder interface */ /* ----------------------------------------------------------------------- */ -opj_jp2_t* opj_jp2_create(OPJ_BOOL p_is_decoder) -{ - opj_jp2_t *jp2 = (opj_jp2_t*)opj_calloc(1, sizeof(opj_jp2_t)); +opj_jp2_t *opj_jp2_create(OPJ_BOOL p_is_decoder) { + opj_jp2_t *jp2 = (opj_jp2_t *)opj_calloc(1, sizeof(opj_jp2_t)); if (jp2) { /* create the J2K codec */ @@ -3194,8 +3141,7 @@ opj_jp2_t* opj_jp2_create(OPJ_BOOL p_is_decoder) return jp2; } -void jp2_dump(opj_jp2_t* p_jp2, OPJ_INT32 flag, FILE* out_stream) -{ +void jp2_dump(opj_jp2_t *p_jp2, OPJ_INT32 flag, FILE *out_stream) { /* preconditions */ assert(p_jp2 != 00); @@ -3204,20 +3150,17 @@ void jp2_dump(opj_jp2_t* p_jp2, OPJ_INT32 flag, FILE* out_stream) out_stream); } -opj_codestream_index_t* jp2_get_cstr_index(opj_jp2_t* p_jp2) -{ +opj_codestream_index_t *jp2_get_cstr_index(opj_jp2_t *p_jp2) { return j2k_get_cstr_index(p_jp2->j2k); } -opj_codestream_info_v2_t* jp2_get_cstr_info(opj_jp2_t* p_jp2) -{ +opj_codestream_info_v2_t *jp2_get_cstr_info(opj_jp2_t *p_jp2) { return j2k_get_cstr_info(p_jp2->j2k); } OPJ_BOOL opj_jp2_set_decoded_resolution_factor(opj_jp2_t *p_jp2, - OPJ_UINT32 res_factor, - opj_event_mgr_t * p_manager) -{ + OPJ_UINT32 res_factor, + opj_event_mgr_t *p_manager) { return opj_j2k_set_decoded_resolution_factor(p_jp2->j2k, res_factor, p_manager); } @@ -3225,9 +3168,8 @@ OPJ_BOOL opj_jp2_set_decoded_resolution_factor(opj_jp2_t *p_jp2, OPJ_BOOL opj_jp2_encoder_set_extra_options( opj_jp2_t *p_jp2, - const char* const* p_options, - opj_event_mgr_t * p_manager) -{ + const char *const *p_options, + opj_event_mgr_t *p_manager) { return opj_j2k_encoder_set_extra_options(p_jp2->j2k, p_options, p_manager); } @@ -3238,8 +3180,7 @@ OPJ_BOOL opj_jp2_encoder_set_extra_options( #ifdef USE_JPIP static OPJ_BOOL opj_jpip_write_iptr(opj_jp2_t *jp2, opj_stream_private_t *cio, - opj_event_mgr_t * p_manager) -{ + opj_event_mgr_t *p_manager) { OPJ_OFF_T j2k_codestream_exit; OPJ_BYTE l_data_header [24]; @@ -3281,8 +3222,7 @@ static OPJ_BOOL opj_jpip_write_iptr(opj_jp2_t *jp2, static OPJ_BOOL opj_jpip_write_fidx(opj_jp2_t *jp2, opj_stream_private_t *cio, - opj_event_mgr_t * p_manager) -{ + opj_event_mgr_t *p_manager) { OPJ_OFF_T j2k_codestream_exit; OPJ_BYTE l_data_header [24]; @@ -3316,8 +3256,7 @@ static OPJ_BOOL opj_jpip_write_fidx(opj_jp2_t *jp2, static OPJ_BOOL opj_jpip_write_cidx(opj_jp2_t *jp2, opj_stream_private_t *cio, - opj_event_mgr_t * p_manager) -{ + opj_event_mgr_t *p_manager) { OPJ_OFF_T j2k_codestream_exit; OPJ_BYTE l_data_header [24]; @@ -3363,8 +3302,7 @@ static OPJ_BOOL opj_jpip_write_cidx(opj_jp2_t *jp2, #if 0 static void write_prxy(int offset_jp2c, int length_jp2c, int offset_idx, int length_idx, opj_stream_private_t *cio, - opj_event_mgr_t * p_manager) -{ + opj_event_mgr_t *p_manager) { OPJ_BYTE l_data_header [8]; OPJ_OFF_T len, lenp; @@ -3400,8 +3338,7 @@ static void write_prxy(int offset_jp2c, int length_jp2c, int offset_idx, #if 0 static int write_fidx(int offset_jp2c, int length_jp2c, int offset_idx, int length_idx, opj_stream_private_t *cio, - opj_event_mgr_t * p_manager) -{ + opj_event_mgr_t *p_manager) { OPJ_BYTE l_data_header [4]; OPJ_OFF_T len, lenp; diff --git a/client/deps/openjpeg/jp2.h b/client/deps/openjpeg/jp2.h index 173f25119..9c11e8ef0 100644 --- a/client/deps/openjpeg/jp2.h +++ b/client/deps/openjpeg/jp2.h @@ -150,9 +150,9 @@ typedef struct opj_jp2 { /** handle to the J2K codec */ opj_j2k_t *j2k; /** list of validation procedures */ - struct opj_procedure_list * m_validation_list; + struct opj_procedure_list *m_validation_list; /** list of execution procedures */ - struct opj_procedure_list * m_procedure_list; + struct opj_procedure_list *m_procedure_list; /* width of image */ OPJ_UINT32 w; @@ -208,16 +208,16 @@ typedef struct opj_jp2_header_handler { OPJ_BOOL(*handler)(opj_jp2_t *jp2, OPJ_BYTE *p_header_data, OPJ_UINT32 p_header_size, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); } opj_jp2_header_handler_t; typedef struct opj_jp2_img_header_writer_handler { /* action to perform */ - OPJ_BYTE* (*handler)(opj_jp2_t *jp2, OPJ_UINT32 * p_data_size); + OPJ_BYTE *(*handler)(opj_jp2_t *jp2, OPJ_UINT32 *p_data_size); /* result of the action : data */ - OPJ_BYTE* m_data; + OPJ_BYTE *m_data; /* size of data */ OPJ_UINT32 m_size; } @@ -263,8 +263,8 @@ OPJ_BOOL opj_jp2_set_threads(opj_jp2_t *jp2, OPJ_UINT32 num_threads); */ OPJ_BOOL opj_jp2_decode(opj_jp2_t *jp2, opj_stream_private_t *p_stream, - opj_image_t* p_image, - opj_event_mgr_t * p_manager); + opj_image_t *p_image, + opj_event_mgr_t *p_manager); /** * Setup the encoder parameters using the current image and using user parameters. @@ -279,7 +279,7 @@ OPJ_BOOL opj_jp2_decode(opj_jp2_t *jp2, OPJ_BOOL opj_jp2_setup_encoder(opj_jp2_t *jp2, opj_cparameters_t *parameters, opj_image_t *image, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** Encode an image into a JPEG-2000 file stream @@ -290,7 +290,7 @@ Encode an image into a JPEG-2000 file stream */ OPJ_BOOL opj_jp2_encode(opj_jp2_t *jp2, opj_stream_private_t *stream, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** @@ -305,8 +305,8 @@ OPJ_BOOL opj_jp2_encode(opj_jp2_t *jp2, */ OPJ_BOOL opj_jp2_start_compress(opj_jp2_t *jp2, opj_stream_private_t *stream, - opj_image_t * p_image, - opj_event_mgr_t * p_manager); + opj_image_t *p_image, + opj_event_mgr_t *p_manager); /** @@ -315,7 +315,7 @@ OPJ_BOOL opj_jp2_start_compress(opj_jp2_t *jp2, */ OPJ_BOOL opj_jp2_end_compress(opj_jp2_t *jp2, opj_stream_private_t *cio, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /* ----------------------------------------------------------------------- */ @@ -325,7 +325,7 @@ OPJ_BOOL opj_jp2_end_compress(opj_jp2_t *jp2, */ OPJ_BOOL opj_jp2_end_decompress(opj_jp2_t *jp2, opj_stream_private_t *cio, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Reads a jpeg2000 file header structure. @@ -339,8 +339,8 @@ OPJ_BOOL opj_jp2_end_decompress(opj_jp2_t *jp2, */ OPJ_BOOL opj_jp2_read_header(opj_stream_private_t *p_stream, opj_jp2_t *jp2, - opj_image_t ** p_image, - opj_event_mgr_t * p_manager); + opj_image_t **p_image, + opj_event_mgr_t *p_manager); /** Sets the indices of the components to decode. * @@ -354,8 +354,8 @@ OPJ_BOOL opj_jp2_read_header(opj_stream_private_t *p_stream, */ OPJ_BOOL opj_jp2_set_decoded_components(opj_jp2_t *jp2, OPJ_UINT32 numcomps, - const OPJ_UINT32* comps_indices, - opj_event_mgr_t * p_manager); + const OPJ_UINT32 *comps_indices, + opj_event_mgr_t *p_manager); /** * Reads a tile header. @@ -371,17 +371,17 @@ OPJ_BOOL opj_jp2_set_decoded_components(opj_jp2_t *jp2, * @param p_stream the stream to write data to. * @param p_manager the user event manager. */ -OPJ_BOOL opj_jp2_read_tile_header(opj_jp2_t * p_jp2, - OPJ_UINT32 * p_tile_index, - OPJ_UINT32 * p_data_size, - OPJ_INT32 * p_tile_x0, - OPJ_INT32 * p_tile_y0, - OPJ_INT32 * p_tile_x1, - OPJ_INT32 * p_tile_y1, - OPJ_UINT32 * p_nb_comps, - OPJ_BOOL * p_go_on, +OPJ_BOOL opj_jp2_read_tile_header(opj_jp2_t *p_jp2, + OPJ_UINT32 *p_tile_index, + OPJ_UINT32 *p_data_size, + OPJ_INT32 *p_tile_x0, + OPJ_INT32 *p_tile_y0, + OPJ_INT32 *p_tile_x1, + OPJ_INT32 *p_tile_y1, + OPJ_UINT32 *p_nb_comps, + OPJ_BOOL *p_go_on, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Writes a tile. @@ -395,10 +395,10 @@ OPJ_BOOL opj_jp2_read_tile_header(opj_jp2_t * p_jp2, */ OPJ_BOOL opj_jp2_write_tile(opj_jp2_t *p_jp2, OPJ_UINT32 p_tile_index, - OPJ_BYTE * p_data, + OPJ_BYTE *p_data, OPJ_UINT32 p_data_size, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Decode tile data. @@ -411,19 +411,19 @@ OPJ_BOOL opj_jp2_write_tile(opj_jp2_t *p_jp2, * * @return FIXME DOC */ -OPJ_BOOL opj_jp2_decode_tile(opj_jp2_t * p_jp2, +OPJ_BOOL opj_jp2_decode_tile(opj_jp2_t *p_jp2, OPJ_UINT32 p_tile_index, - OPJ_BYTE * p_data, + OPJ_BYTE *p_data, OPJ_UINT32 p_data_size, opj_stream_private_t *p_stream, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * Creates a jpeg2000 file decompressor. * * @return an empty jpeg2000 file codec. */ -opj_jp2_t* opj_jp2_create(OPJ_BOOL p_is_decoder); +opj_jp2_t *opj_jp2_create(OPJ_BOOL p_is_decoder); /** Destroy a JP2 decompressor handle @@ -446,18 +446,18 @@ void opj_jp2_destroy(opj_jp2_t *jp2); * @return true if the area could be set. */ OPJ_BOOL opj_jp2_set_decode_area(opj_jp2_t *p_jp2, - opj_image_t* p_image, + opj_image_t *p_image, OPJ_INT32 p_start_x, OPJ_INT32 p_start_y, OPJ_INT32 p_end_x, OPJ_INT32 p_end_y, - opj_event_mgr_t * p_manager); + opj_event_mgr_t *p_manager); /** * */ OPJ_BOOL opj_jp2_get_tile(opj_jp2_t *p_jp2, opj_stream_private_t *p_stream, - opj_image_t* p_image, - opj_event_mgr_t * p_manager, + opj_image_t *p_image, + opj_event_mgr_t *p_manager, OPJ_UINT32 tile_index); @@ -465,8 +465,8 @@ OPJ_BOOL opj_jp2_get_tile(opj_jp2_t *p_jp2, * */ OPJ_BOOL opj_jp2_set_decoded_resolution_factor(opj_jp2_t *p_jp2, - OPJ_UINT32 res_factor, - opj_event_mgr_t * p_manager); + OPJ_UINT32 res_factor, + opj_event_mgr_t *p_manager); /** * Specify extra options for the encoder. @@ -479,8 +479,8 @@ OPJ_BOOL opj_jp2_set_decoded_resolution_factor(opj_jp2_t *p_jp2, */ OPJ_BOOL opj_jp2_encoder_set_extra_options( opj_jp2_t *p_jp2, - const char* const* p_options, - opj_event_mgr_t * p_manager); + const char *const *p_options, + opj_event_mgr_t *p_manager); /* TODO MSD: clean these 3 functions */ @@ -492,7 +492,7 @@ OPJ_BOOL opj_jp2_encoder_set_extra_options( *@param out_stream output stream where dump the elements. * */ -void jp2_dump(opj_jp2_t* p_jp2, OPJ_INT32 flag, FILE* out_stream); +void jp2_dump(opj_jp2_t *p_jp2, OPJ_INT32 flag, FILE *out_stream); /** * Get the codestream info from a JPEG2000 codec. @@ -501,7 +501,7 @@ void jp2_dump(opj_jp2_t* p_jp2, OPJ_INT32 flag, FILE* out_stream); * *@return the codestream information extract from the jpg2000 codec */ -opj_codestream_info_v2_t* jp2_get_cstr_info(opj_jp2_t* p_jp2); +opj_codestream_info_v2_t *jp2_get_cstr_info(opj_jp2_t *p_jp2); /** * Get the codestream index from a JPEG2000 codec. @@ -510,7 +510,7 @@ opj_codestream_info_v2_t* jp2_get_cstr_info(opj_jp2_t* p_jp2); * *@return the codestream index extract from the jpg2000 codec */ -opj_codestream_index_t* jp2_get_cstr_index(opj_jp2_t* p_jp2); +opj_codestream_index_t *jp2_get_cstr_index(opj_jp2_t *p_jp2); /*@}*/ diff --git a/client/deps/openjpeg/mct.c b/client/deps/openjpeg/mct.c index 780581280..c671c6b90 100644 --- a/client/deps/openjpeg/mct.c +++ b/client/deps/openjpeg/mct.c @@ -59,13 +59,11 @@ static const OPJ_FLOAT64 opj_mct_norms[3] = { 1.732, .8292, .8292 }; /* */ static const OPJ_FLOAT64 opj_mct_norms_real[3] = { 1.732, 1.805, 1.573 }; -const OPJ_FLOAT64 * opj_mct_get_mct_norms() -{ +const OPJ_FLOAT64 *opj_mct_get_mct_norms() { return opj_mct_norms; } -const OPJ_FLOAT64 * opj_mct_get_mct_norms_real() -{ +const OPJ_FLOAT64 *opj_mct_get_mct_norms_real() { return opj_mct_norms_real; } @@ -74,11 +72,10 @@ const OPJ_FLOAT64 * opj_mct_get_mct_norms_real() /* */ #ifdef __SSE2__ void opj_mct_encode( - OPJ_INT32* OPJ_RESTRICT c0, - OPJ_INT32* OPJ_RESTRICT c1, - OPJ_INT32* OPJ_RESTRICT c2, - OPJ_SIZE_T n) -{ + OPJ_INT32 *OPJ_RESTRICT c0, + OPJ_INT32 *OPJ_RESTRICT c1, + OPJ_INT32 *OPJ_RESTRICT c2, + OPJ_SIZE_T n) { OPJ_SIZE_T i; const OPJ_SIZE_T len = n; /* buffer are aligned on 16 bytes */ @@ -116,11 +113,10 @@ void opj_mct_encode( } #else void opj_mct_encode( - OPJ_INT32* OPJ_RESTRICT c0, - OPJ_INT32* OPJ_RESTRICT c1, - OPJ_INT32* OPJ_RESTRICT c2, - OPJ_SIZE_T n) -{ + OPJ_INT32 *OPJ_RESTRICT c0, + OPJ_INT32 *OPJ_RESTRICT c1, + OPJ_INT32 *OPJ_RESTRICT c2, + OPJ_SIZE_T n) { OPJ_SIZE_T i; const OPJ_SIZE_T len = n; @@ -143,11 +139,10 @@ void opj_mct_encode( /* */ #ifdef __SSE2__ void opj_mct_decode( - OPJ_INT32* OPJ_RESTRICT c0, - OPJ_INT32* OPJ_RESTRICT c1, - OPJ_INT32* OPJ_RESTRICT c2, - OPJ_SIZE_T n) -{ + OPJ_INT32 *OPJ_RESTRICT c0, + OPJ_INT32 *OPJ_RESTRICT c1, + OPJ_INT32 *OPJ_RESTRICT c2, + OPJ_SIZE_T n) { OPJ_SIZE_T i; const OPJ_SIZE_T len = n; @@ -178,11 +173,10 @@ void opj_mct_decode( } #else void opj_mct_decode( - OPJ_INT32* OPJ_RESTRICT c0, - OPJ_INT32* OPJ_RESTRICT c1, - OPJ_INT32* OPJ_RESTRICT c2, - OPJ_SIZE_T n) -{ + OPJ_INT32 *OPJ_RESTRICT c0, + OPJ_INT32 *OPJ_RESTRICT c1, + OPJ_INT32 *OPJ_RESTRICT c2, + OPJ_SIZE_T n) { OPJ_SIZE_T i; for (i = 0; i < n; ++i) { OPJ_INT32 y = c0[i]; @@ -201,8 +195,7 @@ void opj_mct_decode( /* */ /* Get norm of basis function of reversible MCT. */ /* */ -OPJ_FLOAT64 opj_mct_getnorm(OPJ_UINT32 compno) -{ +OPJ_FLOAT64 opj_mct_getnorm(OPJ_UINT32 compno) { return opj_mct_norms[compno]; } @@ -210,11 +203,10 @@ OPJ_FLOAT64 opj_mct_getnorm(OPJ_UINT32 compno) /* Forward irreversible MCT. */ /* */ void opj_mct_encode_real( - OPJ_FLOAT32* OPJ_RESTRICT c0, - OPJ_FLOAT32* OPJ_RESTRICT c1, - OPJ_FLOAT32* OPJ_RESTRICT c2, - OPJ_SIZE_T n) -{ + OPJ_FLOAT32 *OPJ_RESTRICT c0, + OPJ_FLOAT32 *OPJ_RESTRICT c1, + OPJ_FLOAT32 *OPJ_RESTRICT c2, + OPJ_SIZE_T n) { OPJ_SIZE_T i; #ifdef __SSE__ const __m128 YR = _mm_set1_ps(0.299f); @@ -280,11 +272,10 @@ void opj_mct_encode_real( /* Inverse irreversible MCT. */ /* */ void opj_mct_decode_real( - OPJ_FLOAT32* OPJ_RESTRICT c0, - OPJ_FLOAT32* OPJ_RESTRICT c1, - OPJ_FLOAT32* OPJ_RESTRICT c2, - OPJ_SIZE_T n) -{ + OPJ_FLOAT32 *OPJ_RESTRICT c0, + OPJ_FLOAT32 *OPJ_RESTRICT c1, + OPJ_FLOAT32 *OPJ_RESTRICT c2, + OPJ_SIZE_T n) { OPJ_SIZE_T i; #ifdef __SSE__ __m128 vrv, vgu, vgv, vbu; @@ -340,34 +331,32 @@ void opj_mct_decode_real( /* */ /* Get norm of basis function of irreversible MCT. */ /* */ -OPJ_FLOAT64 opj_mct_getnorm_real(OPJ_UINT32 compno) -{ +OPJ_FLOAT64 opj_mct_getnorm_real(OPJ_UINT32 compno) { return opj_mct_norms_real[compno]; } OPJ_BOOL opj_mct_encode_custom( - OPJ_BYTE * pCodingdata, + OPJ_BYTE *pCodingdata, OPJ_SIZE_T n, - OPJ_BYTE ** pData, + OPJ_BYTE **pData, OPJ_UINT32 pNbComp, - OPJ_UINT32 isSigned) -{ - OPJ_FLOAT32 * lMct = (OPJ_FLOAT32 *) pCodingdata; + OPJ_UINT32 isSigned) { + OPJ_FLOAT32 *lMct = (OPJ_FLOAT32 *) pCodingdata; OPJ_SIZE_T i; OPJ_UINT32 j; OPJ_UINT32 k; OPJ_UINT32 lNbMatCoeff = pNbComp * pNbComp; - OPJ_INT32 * lCurrentData = 00; - OPJ_INT32 * lCurrentMatrix = 00; - OPJ_INT32 ** lData = (OPJ_INT32 **) pData; + OPJ_INT32 *lCurrentData = 00; + OPJ_INT32 *lCurrentMatrix = 00; + OPJ_INT32 **lData = (OPJ_INT32 **) pData; OPJ_UINT32 lMultiplicator = 1 << 13; - OPJ_INT32 * lMctPtr; + OPJ_INT32 *lMctPtr; OPJ_ARG_NOT_USED(isSigned); lCurrentData = (OPJ_INT32 *) opj_malloc((pNbComp + lNbMatCoeff) * sizeof( - OPJ_INT32)); + OPJ_INT32)); if (! lCurrentData) { return OPJ_FALSE; } @@ -401,20 +390,19 @@ OPJ_BOOL opj_mct_encode_custom( } OPJ_BOOL opj_mct_decode_custom( - OPJ_BYTE * pDecodingData, + OPJ_BYTE *pDecodingData, OPJ_SIZE_T n, - OPJ_BYTE ** pData, + OPJ_BYTE **pData, OPJ_UINT32 pNbComp, - OPJ_UINT32 isSigned) -{ - OPJ_FLOAT32 * lMct; + OPJ_UINT32 isSigned) { + OPJ_FLOAT32 *lMct; OPJ_SIZE_T i; OPJ_UINT32 j; OPJ_UINT32 k; - OPJ_FLOAT32 * lCurrentData = 00; - OPJ_FLOAT32 * lCurrentResult = 00; - OPJ_FLOAT32 ** lData = (OPJ_FLOAT32 **) pData; + OPJ_FLOAT32 *lCurrentData = 00; + OPJ_FLOAT32 *lCurrentResult = 00; + OPJ_FLOAT32 **lData = (OPJ_FLOAT32 **) pData; OPJ_ARG_NOT_USED(isSigned); @@ -441,14 +429,13 @@ OPJ_BOOL opj_mct_decode_custom( return OPJ_TRUE; } -void opj_calculate_norms(OPJ_FLOAT64 * pNorms, +void opj_calculate_norms(OPJ_FLOAT64 *pNorms, OPJ_UINT32 pNbComps, - OPJ_FLOAT32 * pMatrix) -{ + OPJ_FLOAT32 *pMatrix) { OPJ_UINT32 i, j, lIndex; OPJ_FLOAT32 lCurrentValue; - OPJ_FLOAT64 * lNorms = (OPJ_FLOAT64 *) pNorms; - OPJ_FLOAT32 * lMatrix = (OPJ_FLOAT32 *) pMatrix; + OPJ_FLOAT64 *lNorms = (OPJ_FLOAT64 *) pNorms; + OPJ_FLOAT32 *lMatrix = (OPJ_FLOAT32 *) pMatrix; for (i = 0; i < pNbComps; ++i) { lNorms[i] = 0; diff --git a/client/deps/openjpeg/mct.h b/client/deps/openjpeg/mct.h index 3e1f5e494..2e95426a7 100644 --- a/client/deps/openjpeg/mct.h +++ b/client/deps/openjpeg/mct.h @@ -60,8 +60,8 @@ Apply a reversible multi-component transform to an image @param c2 Samples blue component @param n Number of samples for each component */ -void opj_mct_encode(OPJ_INT32* OPJ_RESTRICT c0, OPJ_INT32* OPJ_RESTRICT c1, - OPJ_INT32* OPJ_RESTRICT c2, OPJ_SIZE_T n); +void opj_mct_encode(OPJ_INT32 *OPJ_RESTRICT c0, OPJ_INT32 *OPJ_RESTRICT c1, + OPJ_INT32 *OPJ_RESTRICT c2, OPJ_SIZE_T n); /** Apply a reversible multi-component inverse transform to an image @param c0 Samples for luminance component @@ -69,8 +69,8 @@ Apply a reversible multi-component inverse transform to an image @param c2 Samples for blue chrominance component @param n Number of samples for each component */ -void opj_mct_decode(OPJ_INT32* OPJ_RESTRICT c0, OPJ_INT32* OPJ_RESTRICT c1, - OPJ_INT32* OPJ_RESTRICT c2, OPJ_SIZE_T n); +void opj_mct_decode(OPJ_INT32 *OPJ_RESTRICT c0, OPJ_INT32 *OPJ_RESTRICT c1, + OPJ_INT32 *OPJ_RESTRICT c2, OPJ_SIZE_T n); /** Get norm of the basis function used for the reversible multi-component transform @param compno Number of the component (0->Y, 1->U, 2->V) @@ -85,9 +85,9 @@ Apply an irreversible multi-component transform to an image @param c2 Samples blue component @param n Number of samples for each component */ -void opj_mct_encode_real(OPJ_FLOAT32* OPJ_RESTRICT c0, - OPJ_FLOAT32* OPJ_RESTRICT c1, - OPJ_FLOAT32* OPJ_RESTRICT c2, OPJ_SIZE_T n); +void opj_mct_encode_real(OPJ_FLOAT32 *OPJ_RESTRICT c0, + OPJ_FLOAT32 *OPJ_RESTRICT c1, + OPJ_FLOAT32 *OPJ_RESTRICT c2, OPJ_SIZE_T n); /** Apply an irreversible multi-component inverse transform to an image @param c0 Samples for luminance component @@ -95,8 +95,8 @@ Apply an irreversible multi-component inverse transform to an image @param c2 Samples for blue chrominance component @param n Number of samples for each component */ -void opj_mct_decode_real(OPJ_FLOAT32* OPJ_RESTRICT c0, - OPJ_FLOAT32* OPJ_RESTRICT c1, OPJ_FLOAT32* OPJ_RESTRICT c2, OPJ_SIZE_T n); +void opj_mct_decode_real(OPJ_FLOAT32 *OPJ_RESTRICT c0, + OPJ_FLOAT32 *OPJ_RESTRICT c1, OPJ_FLOAT32 *OPJ_RESTRICT c2, OPJ_SIZE_T n); /** Get norm of the basis function used for the irreversible multi-component transform @param compno Number of the component (0->Y, 1->U, 2->V) @@ -114,9 +114,9 @@ FIXME DOC @return OPJ_FALSE if function encounter a problem, OPJ_TRUE otherwise */ OPJ_BOOL opj_mct_encode_custom( - OPJ_BYTE * p_coding_data, + OPJ_BYTE *p_coding_data, OPJ_SIZE_T n, - OPJ_BYTE ** p_data, + OPJ_BYTE **p_data, OPJ_UINT32 p_nb_comp, OPJ_UINT32 is_signed); /** @@ -129,9 +129,9 @@ FIXME DOC @return OPJ_FALSE if function encounter a problem, OPJ_TRUE otherwise */ OPJ_BOOL opj_mct_decode_custom( - OPJ_BYTE * pDecodingData, + OPJ_BYTE *pDecodingData, OPJ_SIZE_T n, - OPJ_BYTE ** pData, + OPJ_BYTE **pData, OPJ_UINT32 pNbComp, OPJ_UINT32 isSigned); /** @@ -141,17 +141,17 @@ FIXME DOC @param pMatrix components @return */ -void opj_calculate_norms(OPJ_FLOAT64 * pNorms, +void opj_calculate_norms(OPJ_FLOAT64 *pNorms, OPJ_UINT32 p_nb_comps, - OPJ_FLOAT32 * pMatrix); + OPJ_FLOAT32 *pMatrix); /** FIXME DOC */ -const OPJ_FLOAT64 * opj_mct_get_mct_norms(void); +const OPJ_FLOAT64 *opj_mct_get_mct_norms(void); /** FIXME DOC */ -const OPJ_FLOAT64 * opj_mct_get_mct_norms_real(void); +const OPJ_FLOAT64 *opj_mct_get_mct_norms_real(void); /* ----------------------------------------------------------------------- */ /*@}*/ diff --git a/client/deps/openjpeg/mqc.c b/client/deps/openjpeg/mqc.c index 4cbfabd03..d4bb33ec4 100644 --- a/client/deps/openjpeg/mqc.c +++ b/client/deps/openjpeg/mqc.c @@ -161,8 +161,7 @@ static const opj_mqc_state_t mqc_states[47 * 2] = { ========================================================== */ -static void opj_mqc_setbits(opj_mqc_t *mqc) -{ +static void opj_mqc_setbits(opj_mqc_t *mqc) { OPJ_UINT32 tempc = mqc->c + mqc->a; mqc->c |= 0xffff; if (mqc->c >= tempc) { @@ -176,8 +175,7 @@ static void opj_mqc_setbits(opj_mqc_t *mqc) ========================================================== */ -OPJ_UINT32 opj_mqc_numbytes(opj_mqc_t *mqc) -{ +OPJ_UINT32 opj_mqc_numbytes(opj_mqc_t *mqc) { const ptrdiff_t diff = mqc->bp - mqc->start; #if 0 assert(diff <= 0xffffffff && diff >= 0); /* UINT32_MAX */ @@ -185,8 +183,7 @@ OPJ_UINT32 opj_mqc_numbytes(opj_mqc_t *mqc) return (OPJ_UINT32)diff; } -void opj_mqc_init_enc(opj_mqc_t *mqc, OPJ_BYTE *bp) -{ +void opj_mqc_init_enc(opj_mqc_t *mqc, OPJ_BYTE *bp) { /* To avoid the curctx pointer to be dangling, but not strictly */ /* required as the current context is always set before encoding */ opj_mqc_setcurctx(mqc, 0); @@ -209,8 +206,7 @@ void opj_mqc_init_enc(opj_mqc_t *mqc, OPJ_BYTE *bp) } -void opj_mqc_flush(opj_mqc_t *mqc) -{ +void opj_mqc_flush(opj_mqc_t *mqc) { /* C.2.9 Termination of coding (FLUSH) */ /* Figure C.11 – FLUSH procedure */ opj_mqc_setbits(mqc); @@ -226,8 +222,7 @@ void opj_mqc_flush(opj_mqc_t *mqc) } } -void opj_mqc_bypass_init_enc(opj_mqc_t *mqc) -{ +void opj_mqc_bypass_init_enc(opj_mqc_t *mqc) { /* This function is normally called after at least one opj_mqc_flush() */ /* which will have advance mqc->bp by at least 2 bytes beyond its */ /* initial position */ @@ -244,8 +239,7 @@ void opj_mqc_bypass_init_enc(opj_mqc_t *mqc) assert(mqc->bp[-1] != 0xff); } -void opj_mqc_bypass_enc(opj_mqc_t *mqc, OPJ_UINT32 d) -{ +void opj_mqc_bypass_enc(opj_mqc_t *mqc, OPJ_UINT32 d) { if (mqc->ct == BYPASS_CT_INIT) { mqc->ct = 8; } @@ -263,14 +257,12 @@ void opj_mqc_bypass_enc(opj_mqc_t *mqc, OPJ_UINT32 d) } } -OPJ_UINT32 opj_mqc_bypass_get_extra_bytes(opj_mqc_t *mqc, OPJ_BOOL erterm) -{ +OPJ_UINT32 opj_mqc_bypass_get_extra_bytes(opj_mqc_t *mqc, OPJ_BOOL erterm) { return (mqc->ct < 7 || (mqc->ct == 7 && (erterm || mqc->bp[-1] != 0xff))) ? 1 : 0; } -void opj_mqc_bypass_flush_enc(opj_mqc_t *mqc, OPJ_BOOL erterm) -{ +void opj_mqc_bypass_flush_enc(opj_mqc_t *mqc, OPJ_BOOL erterm) { /* Is there any bit remaining to be flushed ? */ /* If the last output byte is 0xff, we can discard it, unless */ /* erterm is required (I'm not completely sure why in erterm */ @@ -307,8 +299,7 @@ void opj_mqc_bypass_flush_enc(opj_mqc_t *mqc, OPJ_BOOL erterm) assert(mqc->bp[-1] != 0xff); } -void opj_mqc_reset_enc(opj_mqc_t *mqc) -{ +void opj_mqc_reset_enc(opj_mqc_t *mqc) { opj_mqc_resetstates(mqc); opj_mqc_setstate(mqc, T1_CTXNO_UNI, 0, 46); opj_mqc_setstate(mqc, T1_CTXNO_AGG, 0, 3); @@ -316,8 +307,7 @@ void opj_mqc_reset_enc(opj_mqc_t *mqc) } #ifdef notdef -OPJ_UINT32 opj_mqc_restart_enc(opj_mqc_t *mqc) -{ +OPJ_UINT32 opj_mqc_restart_enc(opj_mqc_t *mqc) { OPJ_UINT32 correction = 1; /* */ @@ -334,8 +324,7 @@ OPJ_UINT32 opj_mqc_restart_enc(opj_mqc_t *mqc) } #endif -void opj_mqc_restart_init_enc(opj_mqc_t *mqc) -{ +void opj_mqc_restart_init_enc(opj_mqc_t *mqc) { /* */ /* As specified in Figure C.10 - Initialization of the encoder */ @@ -354,8 +343,7 @@ void opj_mqc_restart_init_enc(opj_mqc_t *mqc) } } -void opj_mqc_erterm_enc(opj_mqc_t *mqc) -{ +void opj_mqc_erterm_enc(opj_mqc_t *mqc) { OPJ_INT32 k = (OPJ_INT32)(11 - mqc->ct + 1); while (k > 0) { @@ -370,8 +358,7 @@ void opj_mqc_erterm_enc(opj_mqc_t *mqc) } } -static INLINE void opj_mqc_renorme(opj_mqc_t *mqc) -{ +static INLINE void opj_mqc_renorme(opj_mqc_t *mqc) { opj_mqc_renorme_macro(mqc, mqc->a, mqc->c, mqc->ct); } @@ -379,8 +366,7 @@ static INLINE void opj_mqc_renorme(opj_mqc_t *mqc) Encode the most probable symbol @param mqc MQC handle */ -static INLINE void opj_mqc_codemps(opj_mqc_t *mqc) -{ +static INLINE void opj_mqc_codemps(opj_mqc_t *mqc) { opj_mqc_codemps_macro(mqc, mqc->curctx, mqc->a, mqc->c, mqc->ct); } @@ -388,8 +374,7 @@ static INLINE void opj_mqc_codemps(opj_mqc_t *mqc) Encode the most least symbol @param mqc MQC handle */ -static INLINE void opj_mqc_codelps(opj_mqc_t *mqc) -{ +static INLINE void opj_mqc_codelps(opj_mqc_t *mqc) { opj_mqc_codelps_macro(mqc, mqc->curctx, mqc->a, mqc->c, mqc->ct); } @@ -398,8 +383,7 @@ Encode a symbol using the MQ-coder @param mqc MQC handle @param d The symbol to be encoded (0 or 1) */ -static INLINE void opj_mqc_encode(opj_mqc_t *mqc, OPJ_UINT32 d) -{ +static INLINE void opj_mqc_encode(opj_mqc_t *mqc, OPJ_UINT32 d) { if ((*mqc->curctx)->mps == d) { opj_mqc_codemps(mqc); } else { @@ -407,8 +391,7 @@ static INLINE void opj_mqc_encode(opj_mqc_t *mqc, OPJ_UINT32 d) } } -void opj_mqc_segmark_enc(opj_mqc_t *mqc) -{ +void opj_mqc_segmark_enc(opj_mqc_t *mqc) { OPJ_UINT32 i; opj_mqc_setcurctx(mqc, 18); @@ -420,8 +403,7 @@ void opj_mqc_segmark_enc(opj_mqc_t *mqc) static void opj_mqc_init_dec_common(opj_mqc_t *mqc, OPJ_BYTE *bp, OPJ_UINT32 len, - OPJ_UINT32 extra_writable_bytes) -{ + OPJ_UINT32 extra_writable_bytes) { (void)extra_writable_bytes; assert(extra_writable_bytes >= OPJ_COMMON_CBLK_DATA_EXTRA); @@ -437,8 +419,7 @@ static void opj_mqc_init_dec_common(opj_mqc_t *mqc, mqc->bp = bp; } void opj_mqc_init_dec(opj_mqc_t *mqc, OPJ_BYTE *bp, OPJ_UINT32 len, - OPJ_UINT32 extra_writable_bytes) -{ + OPJ_UINT32 extra_writable_bytes) { /* Implements ISO 15444-1 C.3.5 Initialization of the decoder (INITDEC) */ /* Note: alternate "J.1 - Initialization of the software-conventions */ /* decoder" has been tried, but does */ @@ -461,22 +442,19 @@ void opj_mqc_init_dec(opj_mqc_t *mqc, OPJ_BYTE *bp, OPJ_UINT32 len, void opj_mqc_raw_init_dec(opj_mqc_t *mqc, OPJ_BYTE *bp, OPJ_UINT32 len, - OPJ_UINT32 extra_writable_bytes) -{ + OPJ_UINT32 extra_writable_bytes) { opj_mqc_init_dec_common(mqc, bp, len, extra_writable_bytes); mqc->c = 0; mqc->ct = 0; } -void opq_mqc_finish_dec(opj_mqc_t *mqc) -{ +void opq_mqc_finish_dec(opj_mqc_t *mqc) { /* Restore the bytes overwritten by opj_mqc_init_dec_common() */ memcpy(mqc->end, mqc->backup, OPJ_COMMON_CBLK_DATA_EXTRA); } -void opj_mqc_resetstates(opj_mqc_t *mqc) -{ +void opj_mqc_resetstates(opj_mqc_t *mqc) { OPJ_UINT32 i; for (i = 0; i < MQC_NUMCTXS; i++) { mqc->ctxs[i] = mqc_states; @@ -484,13 +462,11 @@ void opj_mqc_resetstates(opj_mqc_t *mqc) } void opj_mqc_setstate(opj_mqc_t *mqc, OPJ_UINT32 ctxno, OPJ_UINT32 msb, - OPJ_INT32 prob) -{ + OPJ_INT32 prob) { mqc->ctxs[ctxno] = &mqc_states[msb + (OPJ_UINT32)(prob << 1)]; } -void opj_mqc_byteout(opj_mqc_t *mqc) -{ +void opj_mqc_byteout(opj_mqc_t *mqc) { /* bp is initialized to start - 1 in opj_mqc_init_enc() */ /* but this is safe, see opj_tcd_code_block_enc_allocate_data() */ assert(mqc->bp >= mqc->start - 1); @@ -521,4 +497,4 @@ void opj_mqc_byteout(opj_mqc_t *mqc) } } } -} \ No newline at end of file +} diff --git a/client/deps/openjpeg/mqc.h b/client/deps/openjpeg/mqc.h index 9850fed03..a5db006b1 100644 --- a/client/deps/openjpeg/mqc.h +++ b/client/deps/openjpeg/mqc.h @@ -91,7 +91,7 @@ typedef struct opj_mqc { /** Active context */ const opj_mqc_state_t **curctx; /* lut_ctxno_zc shifted by (1 << 9) * bandno */ - const OPJ_BYTE* lut_ctxno_zc_orient; + const OPJ_BYTE *lut_ctxno_zc_orient; /** Original value of the 2 bytes at end[0] and end[1] */ OPJ_BYTE backup[OPJ_COMMON_CBLK_DATA_EXTRA]; } opj_mqc_t; diff --git a/client/deps/openjpeg/mqc_inl.h b/client/deps/openjpeg/mqc_inl.h index 0031b94be..ffbe96524 100644 --- a/client/deps/openjpeg/mqc_inl.h +++ b/client/deps/openjpeg/mqc_inl.h @@ -71,8 +71,7 @@ Decode a symbol using raw-decoder. Cfr p.506 TAUBMAN @param mqc MQC handle @return Returns the decoded symbol (0 or 1) */ -static INLINE OPJ_UINT32 opj_mqc_raw_decode(opj_mqc_t *mqc) -{ +static INLINE OPJ_UINT32 opj_mqc_raw_decode(opj_mqc_t *mqc) { OPJ_UINT32 d; if (mqc->ct == 0) { /* Given opj_mqc_raw_init_dec() we know that at some point we will */ @@ -172,8 +171,7 @@ static INLINE OPJ_UINT32 opj_mqc_raw_decode(opj_mqc_t *mqc) Input a byte @param mqc MQC handle */ -static INLINE void opj_mqc_bytein(opj_mqc_t *const mqc) -{ +static INLINE void opj_mqc_bytein(opj_mqc_t *const mqc) { opj_mqc_bytein_macro(mqc, mqc->c, mqc->ct); } diff --git a/client/deps/openjpeg/openjpeg.c b/client/deps/openjpeg/openjpeg.c index 382d8f4f0..767e006cd 100644 --- a/client/deps/openjpeg/openjpeg.c +++ b/client/deps/openjpeg/openjpeg.c @@ -41,11 +41,10 @@ /* ---------------------------------------------------------------------- */ /* Functions to set the message handlers */ -OPJ_BOOL OPJ_CALLCONV opj_set_info_handler(opj_codec_t * p_codec, - opj_msg_callback p_callback, - void * p_user_data) -{ - opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec; +OPJ_BOOL OPJ_CALLCONV opj_set_info_handler(opj_codec_t *p_codec, + opj_msg_callback p_callback, + void *p_user_data) { + opj_codec_private_t *l_codec = (opj_codec_private_t *) p_codec; if (! l_codec) { return OPJ_FALSE; } @@ -56,11 +55,10 @@ OPJ_BOOL OPJ_CALLCONV opj_set_info_handler(opj_codec_t * p_codec, return OPJ_TRUE; } -OPJ_BOOL OPJ_CALLCONV opj_set_warning_handler(opj_codec_t * p_codec, - opj_msg_callback p_callback, - void * p_user_data) -{ - opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec; +OPJ_BOOL OPJ_CALLCONV opj_set_warning_handler(opj_codec_t *p_codec, + opj_msg_callback p_callback, + void *p_user_data) { + opj_codec_private_t *l_codec = (opj_codec_private_t *) p_codec; if (! l_codec) { return OPJ_FALSE; } @@ -71,11 +69,10 @@ OPJ_BOOL OPJ_CALLCONV opj_set_warning_handler(opj_codec_t * p_codec, return OPJ_TRUE; } -OPJ_BOOL OPJ_CALLCONV opj_set_error_handler(opj_codec_t * p_codec, - opj_msg_callback p_callback, - void * p_user_data) -{ - opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec; +OPJ_BOOL OPJ_CALLCONV opj_set_error_handler(opj_codec_t *p_codec, + opj_msg_callback p_callback, + void *p_user_data) { + opj_codec_private_t *l_codec = (opj_codec_private_t *) p_codec; if (! l_codec) { return OPJ_FALSE; } @@ -88,17 +85,15 @@ OPJ_BOOL OPJ_CALLCONV opj_set_error_handler(opj_codec_t * p_codec, /* ---------------------------------------------------------------------- */ -static OPJ_SIZE_T opj_read_from_file(void * p_buffer, OPJ_SIZE_T p_nb_bytes, - void * p_user_data) -{ - FILE* p_file = (FILE*)p_user_data; - OPJ_SIZE_T l_nb_read = fread(p_buffer, 1, p_nb_bytes, (FILE*)p_file); +static OPJ_SIZE_T opj_read_from_file(void *p_buffer, OPJ_SIZE_T p_nb_bytes, + void *p_user_data) { + FILE *p_file = (FILE *)p_user_data; + OPJ_SIZE_T l_nb_read = fread(p_buffer, 1, p_nb_bytes, (FILE *)p_file); return l_nb_read ? l_nb_read : (OPJ_SIZE_T) - 1; } -static OPJ_UINT64 opj_get_data_length_from_file(void * p_user_data) -{ - FILE* p_file = (FILE*)p_user_data; +static OPJ_UINT64 opj_get_data_length_from_file(void *p_user_data) { + FILE *p_file = (FILE *)p_user_data; OPJ_OFF_T file_length = 0; OPJ_FSEEK(p_file, 0, SEEK_END); @@ -108,16 +103,14 @@ static OPJ_UINT64 opj_get_data_length_from_file(void * p_user_data) return (OPJ_UINT64)file_length; } -static OPJ_SIZE_T opj_write_from_file(void * p_buffer, OPJ_SIZE_T p_nb_bytes, - void * p_user_data) -{ - FILE* p_file = (FILE*)p_user_data; +static OPJ_SIZE_T opj_write_from_file(void *p_buffer, OPJ_SIZE_T p_nb_bytes, + void *p_user_data) { + FILE *p_file = (FILE *)p_user_data; return fwrite(p_buffer, 1, p_nb_bytes, p_file); } -static OPJ_OFF_T opj_skip_from_file(OPJ_OFF_T p_nb_bytes, void * p_user_data) -{ - FILE* p_file = (FILE*)p_user_data; +static OPJ_OFF_T opj_skip_from_file(OPJ_OFF_T p_nb_bytes, void *p_user_data) { + FILE *p_file = (FILE *)p_user_data; if (OPJ_FSEEK(p_file, p_nb_bytes, SEEK_CUR)) { return -1; } @@ -125,9 +118,8 @@ static OPJ_OFF_T opj_skip_from_file(OPJ_OFF_T p_nb_bytes, void * p_user_data) return p_nb_bytes; } -static OPJ_BOOL opj_seek_from_file(OPJ_OFF_T p_nb_bytes, void * p_user_data) -{ - FILE* p_file = (FILE*)p_user_data; +static OPJ_BOOL opj_seek_from_file(OPJ_OFF_T p_nb_bytes, void *p_user_data) { + FILE *p_file = (FILE *)p_user_data; if (OPJ_FSEEK(p_file, p_nb_bytes, SEEK_SET)) { return OPJ_FALSE; } @@ -135,9 +127,8 @@ static OPJ_BOOL opj_seek_from_file(OPJ_OFF_T p_nb_bytes, void * p_user_data) return OPJ_TRUE; } -static void opj_close_from_file(void* p_user_data) -{ - FILE* p_file = (FILE*)p_user_data; +static void opj_close_from_file(void *p_user_data) { + FILE *p_file = (FILE *)p_user_data; fclose(p_file); } @@ -150,20 +141,19 @@ BOOL APIENTRY DllMain(HINSTANCE hModule, DWORD ul_reason_for_call, LPVOID lpReserved); BOOL APIENTRY -DllMain(HINSTANCE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) -{ +DllMain(HINSTANCE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { OPJ_ARG_NOT_USED(lpReserved); OPJ_ARG_NOT_USED(hModule); switch (ul_reason_for_call) { - case DLL_PROCESS_ATTACH : - break; - case DLL_PROCESS_DETACH : - break; - case DLL_THREAD_ATTACH : - case DLL_THREAD_DETACH : - break; + case DLL_PROCESS_ATTACH : + break; + case DLL_PROCESS_DETACH : + break; + case DLL_THREAD_ATTACH : + case DLL_THREAD_DETACH : + break; } return TRUE; @@ -173,19 +163,17 @@ DllMain(HINSTANCE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) /* ---------------------------------------------------------------------- */ -const char* OPJ_CALLCONV opj_version(void) -{ +const char *OPJ_CALLCONV opj_version(void) { return OPJ_PACKAGE_VERSION; } /* ---------------------------------------------------------------------- */ /* DECOMPRESSION FUNCTIONS*/ -opj_codec_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT p_format) -{ +opj_codec_t *OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT p_format) { opj_codec_private_t *l_codec = 00; - l_codec = (opj_codec_private_t*) opj_calloc(1, sizeof(opj_codec_private_t)); + l_codec = (opj_codec_private_t *) opj_calloc(1, sizeof(opj_codec_private_t)); if (!l_codec) { return 00; } @@ -193,200 +181,199 @@ opj_codec_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT p_format) l_codec->is_decompressor = 1; switch (p_format) { - case OPJ_CODEC_J2K: - l_codec->opj_dump_codec = (void (*)(void*, OPJ_INT32, FILE*)) j2k_dump; + case OPJ_CODEC_J2K: + l_codec->opj_dump_codec = (void (*)(void *, OPJ_INT32, FILE *)) j2k_dump; - l_codec->opj_get_codec_info = (opj_codestream_info_v2_t* (*)( - void*)) j2k_get_cstr_info; + l_codec->opj_get_codec_info = (opj_codestream_info_v2_t *(*)( + void *)) j2k_get_cstr_info; - l_codec->opj_get_codec_index = (opj_codestream_index_t* (*)( - void*)) j2k_get_cstr_index; + l_codec->opj_get_codec_index = (opj_codestream_index_t *(*)( + void *)) j2k_get_cstr_index; - l_codec->m_codec_data.m_decompression.opj_decode = - (OPJ_BOOL(*)(void *, - struct opj_stream_private *, - opj_image_t*, struct opj_event_mgr *)) opj_j2k_decode; + l_codec->m_codec_data.m_decompression.opj_decode = + (OPJ_BOOL(*)(void *, + struct opj_stream_private *, + opj_image_t *, struct opj_event_mgr *)) opj_j2k_decode; - l_codec->m_codec_data.m_decompression.opj_end_decompress = - (OPJ_BOOL(*)(void *, - struct opj_stream_private *, - struct opj_event_mgr *)) opj_j2k_end_decompress; + l_codec->m_codec_data.m_decompression.opj_end_decompress = + (OPJ_BOOL(*)(void *, + struct opj_stream_private *, + struct opj_event_mgr *)) opj_j2k_end_decompress; - l_codec->m_codec_data.m_decompression.opj_read_header = - (OPJ_BOOL(*)(struct opj_stream_private *, - void *, - opj_image_t **, - struct opj_event_mgr *)) opj_j2k_read_header; + l_codec->m_codec_data.m_decompression.opj_read_header = + (OPJ_BOOL(*)(struct opj_stream_private *, + void *, + opj_image_t **, + struct opj_event_mgr *)) opj_j2k_read_header; - l_codec->m_codec_data.m_decompression.opj_destroy = - (void (*)(void *))opj_j2k_destroy; + l_codec->m_codec_data.m_decompression.opj_destroy = + (void (*)(void *))opj_j2k_destroy; - l_codec->m_codec_data.m_decompression.opj_setup_decoder = - (void (*)(void *, opj_dparameters_t *)) opj_j2k_setup_decoder; + l_codec->m_codec_data.m_decompression.opj_setup_decoder = + (void (*)(void *, opj_dparameters_t *)) opj_j2k_setup_decoder; - l_codec->m_codec_data.m_decompression.opj_decoder_set_strict_mode = - (void (*)(void *, OPJ_BOOL)) opj_j2k_decoder_set_strict_mode; + l_codec->m_codec_data.m_decompression.opj_decoder_set_strict_mode = + (void (*)(void *, OPJ_BOOL)) opj_j2k_decoder_set_strict_mode; - l_codec->m_codec_data.m_decompression.opj_read_tile_header = - (OPJ_BOOL(*)(void *, - OPJ_UINT32*, - OPJ_UINT32*, - OPJ_INT32*, OPJ_INT32*, - OPJ_INT32*, OPJ_INT32*, - OPJ_UINT32*, - OPJ_BOOL*, - struct opj_stream_private *, - struct opj_event_mgr *)) opj_j2k_read_tile_header; + l_codec->m_codec_data.m_decompression.opj_read_tile_header = + (OPJ_BOOL(*)(void *, + OPJ_UINT32 *, + OPJ_UINT32 *, + OPJ_INT32 *, OPJ_INT32 *, + OPJ_INT32 *, OPJ_INT32 *, + OPJ_UINT32 *, + OPJ_BOOL *, + struct opj_stream_private *, + struct opj_event_mgr *)) opj_j2k_read_tile_header; - l_codec->m_codec_data.m_decompression.opj_decode_tile_data = - (OPJ_BOOL(*)(void *, - OPJ_UINT32, - OPJ_BYTE*, - OPJ_UINT32, - struct opj_stream_private *, - struct opj_event_mgr *)) opj_j2k_decode_tile; + l_codec->m_codec_data.m_decompression.opj_decode_tile_data = + (OPJ_BOOL(*)(void *, + OPJ_UINT32, + OPJ_BYTE *, + OPJ_UINT32, + struct opj_stream_private *, + struct opj_event_mgr *)) opj_j2k_decode_tile; - l_codec->m_codec_data.m_decompression.opj_set_decode_area = - (OPJ_BOOL(*)(void *, - opj_image_t*, - OPJ_INT32, OPJ_INT32, OPJ_INT32, OPJ_INT32, - struct opj_event_mgr *)) opj_j2k_set_decode_area; + l_codec->m_codec_data.m_decompression.opj_set_decode_area = + (OPJ_BOOL(*)(void *, + opj_image_t *, + OPJ_INT32, OPJ_INT32, OPJ_INT32, OPJ_INT32, + struct opj_event_mgr *)) opj_j2k_set_decode_area; - l_codec->m_codec_data.m_decompression.opj_get_decoded_tile = - (OPJ_BOOL(*)(void *p_codec, - opj_stream_private_t *p_cio, - opj_image_t *p_image, - struct opj_event_mgr * p_manager, - OPJ_UINT32 tile_index)) opj_j2k_get_tile; + l_codec->m_codec_data.m_decompression.opj_get_decoded_tile = + (OPJ_BOOL(*)(void *p_codec, + opj_stream_private_t *p_cio, + opj_image_t *p_image, + struct opj_event_mgr * p_manager, + OPJ_UINT32 tile_index)) opj_j2k_get_tile; - l_codec->m_codec_data.m_decompression.opj_set_decoded_resolution_factor = - (OPJ_BOOL(*)(void * p_codec, - OPJ_UINT32 res_factor, - struct opj_event_mgr * p_manager)) opj_j2k_set_decoded_resolution_factor; + l_codec->m_codec_data.m_decompression.opj_set_decoded_resolution_factor = + (OPJ_BOOL(*)(void *p_codec, + OPJ_UINT32 res_factor, + struct opj_event_mgr * p_manager)) opj_j2k_set_decoded_resolution_factor; - l_codec->m_codec_data.m_decompression.opj_set_decoded_components = - (OPJ_BOOL(*)(void * p_codec, - OPJ_UINT32 numcomps, - const OPJ_UINT32 * comps_indices, - struct opj_event_mgr * p_manager)) opj_j2k_set_decoded_components; + l_codec->m_codec_data.m_decompression.opj_set_decoded_components = + (OPJ_BOOL(*)(void *p_codec, + OPJ_UINT32 numcomps, + const OPJ_UINT32 * comps_indices, + struct opj_event_mgr * p_manager)) opj_j2k_set_decoded_components; - l_codec->opj_set_threads = - (OPJ_BOOL(*)(void * p_codec, OPJ_UINT32 num_threads)) opj_j2k_set_threads; + l_codec->opj_set_threads = + (OPJ_BOOL(*)(void *p_codec, OPJ_UINT32 num_threads)) opj_j2k_set_threads; - l_codec->m_codec = opj_j2k_create_decompress(); + l_codec->m_codec = opj_j2k_create_decompress(); - if (! l_codec->m_codec) { - opj_free(l_codec); - return NULL; - } + if (! l_codec->m_codec) { + opj_free(l_codec); + return NULL; + } - break; + break; - case OPJ_CODEC_JP2: - /* get a JP2 decoder handle */ - l_codec->opj_dump_codec = (void (*)(void*, OPJ_INT32, FILE*)) jp2_dump; + case OPJ_CODEC_JP2: + /* get a JP2 decoder handle */ + l_codec->opj_dump_codec = (void (*)(void *, OPJ_INT32, FILE *)) jp2_dump; - l_codec->opj_get_codec_info = (opj_codestream_info_v2_t* (*)( - void*)) jp2_get_cstr_info; + l_codec->opj_get_codec_info = (opj_codestream_info_v2_t *(*)( + void *)) jp2_get_cstr_info; - l_codec->opj_get_codec_index = (opj_codestream_index_t* (*)( - void*)) jp2_get_cstr_index; + l_codec->opj_get_codec_index = (opj_codestream_index_t *(*)( + void *)) jp2_get_cstr_index; - l_codec->m_codec_data.m_decompression.opj_decode = - (OPJ_BOOL(*)(void *, - struct opj_stream_private *, - opj_image_t*, - struct opj_event_mgr *)) opj_jp2_decode; + l_codec->m_codec_data.m_decompression.opj_decode = + (OPJ_BOOL(*)(void *, + struct opj_stream_private *, + opj_image_t *, + struct opj_event_mgr *)) opj_jp2_decode; - l_codec->m_codec_data.m_decompression.opj_end_decompress = - (OPJ_BOOL(*)(void *, - struct opj_stream_private *, - struct opj_event_mgr *)) opj_jp2_end_decompress; + l_codec->m_codec_data.m_decompression.opj_end_decompress = + (OPJ_BOOL(*)(void *, + struct opj_stream_private *, + struct opj_event_mgr *)) opj_jp2_end_decompress; - l_codec->m_codec_data.m_decompression.opj_read_header = - (OPJ_BOOL(*)(struct opj_stream_private *, - void *, - opj_image_t **, - struct opj_event_mgr *)) opj_jp2_read_header; + l_codec->m_codec_data.m_decompression.opj_read_header = + (OPJ_BOOL(*)(struct opj_stream_private *, + void *, + opj_image_t **, + struct opj_event_mgr *)) opj_jp2_read_header; - l_codec->m_codec_data.m_decompression.opj_read_tile_header = - (OPJ_BOOL(*)(void *, - OPJ_UINT32*, - OPJ_UINT32*, - OPJ_INT32*, - OPJ_INT32*, - OPJ_INT32 *, - OPJ_INT32 *, - OPJ_UINT32 *, - OPJ_BOOL *, - struct opj_stream_private *, - struct opj_event_mgr *)) opj_jp2_read_tile_header; + l_codec->m_codec_data.m_decompression.opj_read_tile_header = + (OPJ_BOOL(*)(void *, + OPJ_UINT32 *, + OPJ_UINT32 *, + OPJ_INT32 *, + OPJ_INT32 *, + OPJ_INT32 *, + OPJ_INT32 *, + OPJ_UINT32 *, + OPJ_BOOL *, + struct opj_stream_private *, + struct opj_event_mgr *)) opj_jp2_read_tile_header; - l_codec->m_codec_data.m_decompression.opj_decode_tile_data = - (OPJ_BOOL(*)(void *, - OPJ_UINT32, OPJ_BYTE*, OPJ_UINT32, - struct opj_stream_private *, - struct opj_event_mgr *)) opj_jp2_decode_tile; + l_codec->m_codec_data.m_decompression.opj_decode_tile_data = + (OPJ_BOOL(*)(void *, + OPJ_UINT32, OPJ_BYTE *, OPJ_UINT32, + struct opj_stream_private *, + struct opj_event_mgr *)) opj_jp2_decode_tile; - l_codec->m_codec_data.m_decompression.opj_destroy = (void (*)( - void *))opj_jp2_destroy; + l_codec->m_codec_data.m_decompression.opj_destroy = (void (*)( + void *))opj_jp2_destroy; - l_codec->m_codec_data.m_decompression.opj_setup_decoder = - (void (*)(void *, opj_dparameters_t *)) opj_jp2_setup_decoder; + l_codec->m_codec_data.m_decompression.opj_setup_decoder = + (void (*)(void *, opj_dparameters_t *)) opj_jp2_setup_decoder; - l_codec->m_codec_data.m_decompression.opj_decoder_set_strict_mode = - (void (*)(void *, OPJ_BOOL)) opj_jp2_decoder_set_strict_mode; + l_codec->m_codec_data.m_decompression.opj_decoder_set_strict_mode = + (void (*)(void *, OPJ_BOOL)) opj_jp2_decoder_set_strict_mode; - l_codec->m_codec_data.m_decompression.opj_set_decode_area = - (OPJ_BOOL(*)(void *, - opj_image_t*, - OPJ_INT32, OPJ_INT32, OPJ_INT32, OPJ_INT32, - struct opj_event_mgr *)) opj_jp2_set_decode_area; + l_codec->m_codec_data.m_decompression.opj_set_decode_area = + (OPJ_BOOL(*)(void *, + opj_image_t *, + OPJ_INT32, OPJ_INT32, OPJ_INT32, OPJ_INT32, + struct opj_event_mgr *)) opj_jp2_set_decode_area; - l_codec->m_codec_data.m_decompression.opj_get_decoded_tile = - (OPJ_BOOL(*)(void *p_codec, - opj_stream_private_t *p_cio, - opj_image_t *p_image, - struct opj_event_mgr * p_manager, - OPJ_UINT32 tile_index)) opj_jp2_get_tile; + l_codec->m_codec_data.m_decompression.opj_get_decoded_tile = + (OPJ_BOOL(*)(void *p_codec, + opj_stream_private_t *p_cio, + opj_image_t *p_image, + struct opj_event_mgr * p_manager, + OPJ_UINT32 tile_index)) opj_jp2_get_tile; - l_codec->m_codec_data.m_decompression.opj_set_decoded_resolution_factor = - (OPJ_BOOL(*)(void * p_codec, - OPJ_UINT32 res_factor, - opj_event_mgr_t * p_manager)) opj_jp2_set_decoded_resolution_factor; + l_codec->m_codec_data.m_decompression.opj_set_decoded_resolution_factor = + (OPJ_BOOL(*)(void *p_codec, + OPJ_UINT32 res_factor, + opj_event_mgr_t *p_manager)) opj_jp2_set_decoded_resolution_factor; - l_codec->m_codec_data.m_decompression.opj_set_decoded_components = - (OPJ_BOOL(*)(void * p_codec, - OPJ_UINT32 numcomps, - const OPJ_UINT32 * comps_indices, - struct opj_event_mgr * p_manager)) opj_jp2_set_decoded_components; + l_codec->m_codec_data.m_decompression.opj_set_decoded_components = + (OPJ_BOOL(*)(void *p_codec, + OPJ_UINT32 numcomps, + const OPJ_UINT32 * comps_indices, + struct opj_event_mgr * p_manager)) opj_jp2_set_decoded_components; - l_codec->opj_set_threads = - (OPJ_BOOL(*)(void * p_codec, OPJ_UINT32 num_threads)) opj_jp2_set_threads; + l_codec->opj_set_threads = + (OPJ_BOOL(*)(void *p_codec, OPJ_UINT32 num_threads)) opj_jp2_set_threads; - l_codec->m_codec = opj_jp2_create(OPJ_TRUE); + l_codec->m_codec = opj_jp2_create(OPJ_TRUE); - if (! l_codec->m_codec) { + if (! l_codec->m_codec) { + opj_free(l_codec); + return 00; + } + + break; + case OPJ_CODEC_UNKNOWN: + case OPJ_CODEC_JPT: + default: opj_free(l_codec); return 00; - } - - break; - case OPJ_CODEC_UNKNOWN: - case OPJ_CODEC_JPT: - default: - opj_free(l_codec); - return 00; } opj_set_default_event_handler(&(l_codec->m_event_mgr)); - return (opj_codec_t*) l_codec; + return (opj_codec_t *) l_codec; } void OPJ_CALLCONV opj_set_default_decoder_parameters(opj_dparameters_t - *parameters) -{ + *parameters) { if (parameters) { memset(parameters, 0, sizeof(opj_dparameters_t)); /* default decoding parameters */ @@ -408,10 +395,9 @@ void OPJ_CALLCONV opj_set_default_decoder_parameters(opj_dparameters_t OPJ_BOOL OPJ_CALLCONV opj_codec_set_threads(opj_codec_t *p_codec, - int num_threads) -{ + int num_threads) { if (p_codec && (num_threads >= 0)) { - opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec; + opj_codec_private_t *l_codec = (opj_codec_private_t *) p_codec; return l_codec->opj_set_threads(l_codec->m_codec, (OPJ_UINT32)num_threads); } @@ -420,10 +406,9 @@ OPJ_BOOL OPJ_CALLCONV opj_codec_set_threads(opj_codec_t *p_codec, OPJ_BOOL OPJ_CALLCONV opj_setup_decoder(opj_codec_t *p_codec, opj_dparameters_t *parameters - ) -{ + ) { if (p_codec && parameters) { - opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec; + opj_codec_private_t *l_codec = (opj_codec_private_t *) p_codec; if (! l_codec->is_decompressor) { opj_event_msg(&(l_codec->m_event_mgr), EVT_ERROR, @@ -432,17 +417,16 @@ OPJ_BOOL OPJ_CALLCONV opj_setup_decoder(opj_codec_t *p_codec, } l_codec->m_codec_data.m_decompression.opj_setup_decoder(l_codec->m_codec, - parameters); + parameters); return OPJ_TRUE; } return OPJ_FALSE; } OPJ_BOOL OPJ_CALLCONV opj_decoder_set_strict_mode(opj_codec_t *p_codec, - OPJ_BOOL strict) -{ + OPJ_BOOL strict) { if (p_codec) { - opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec; + opj_codec_private_t *l_codec = (opj_codec_private_t *) p_codec; if (! l_codec->is_decompressor) { opj_event_msg(&(l_codec->m_event_mgr), EVT_ERROR, @@ -460,11 +444,10 @@ OPJ_BOOL OPJ_CALLCONV opj_decoder_set_strict_mode(opj_codec_t *p_codec, OPJ_BOOL OPJ_CALLCONV opj_read_header(opj_stream_t *p_stream, opj_codec_t *p_codec, - opj_image_t **p_image) -{ + opj_image_t **p_image) { if (p_codec && p_stream) { - opj_codec_private_t* l_codec = (opj_codec_private_t*) p_codec; - opj_stream_private_t* l_stream = (opj_stream_private_t*) p_stream; + opj_codec_private_t *l_codec = (opj_codec_private_t *) p_codec; + opj_stream_private_t *l_stream = (opj_stream_private_t *) p_stream; if (! l_codec->is_decompressor) { opj_event_msg(&(l_codec->m_event_mgr), EVT_ERROR, @@ -483,12 +466,11 @@ OPJ_BOOL OPJ_CALLCONV opj_read_header(opj_stream_t *p_stream, OPJ_BOOL OPJ_CALLCONV opj_set_decoded_components(opj_codec_t *p_codec, - OPJ_UINT32 numcomps, - const OPJ_UINT32* comps_indices, - OPJ_BOOL apply_color_transforms) -{ + OPJ_UINT32 numcomps, + const OPJ_UINT32 *comps_indices, + OPJ_BOOL apply_color_transforms) { if (p_codec) { - opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec; + opj_codec_private_t *l_codec = (opj_codec_private_t *) p_codec; if (! l_codec->is_decompressor) { opj_event_msg(&(l_codec->m_event_mgr), EVT_ERROR, @@ -513,33 +495,31 @@ OPJ_BOOL OPJ_CALLCONV opj_set_decoded_components(opj_codec_t *p_codec, OPJ_BOOL OPJ_CALLCONV opj_decode(opj_codec_t *p_codec, opj_stream_t *p_stream, - opj_image_t* p_image) -{ + opj_image_t *p_image) { if (p_codec && p_stream) { - opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec; - opj_stream_private_t * l_stream = (opj_stream_private_t *) p_stream; + opj_codec_private_t *l_codec = (opj_codec_private_t *) p_codec; + opj_stream_private_t *l_stream = (opj_stream_private_t *) p_stream; if (! l_codec->is_decompressor) { return OPJ_FALSE; } return l_codec->m_codec_data.m_decompression.opj_decode(l_codec->m_codec, - l_stream, - p_image, - &(l_codec->m_event_mgr)); + l_stream, + p_image, + &(l_codec->m_event_mgr)); } return OPJ_FALSE; } OPJ_BOOL OPJ_CALLCONV opj_set_decode_area(opj_codec_t *p_codec, - opj_image_t* p_image, - OPJ_INT32 p_start_x, OPJ_INT32 p_start_y, - OPJ_INT32 p_end_x, OPJ_INT32 p_end_y - ) -{ + opj_image_t *p_image, + OPJ_INT32 p_start_x, OPJ_INT32 p_start_y, + OPJ_INT32 p_end_x, OPJ_INT32 p_end_y + ) { if (p_codec) { - opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec; + opj_codec_private_t *l_codec = (opj_codec_private_t *) p_codec; if (! l_codec->is_decompressor) { return OPJ_FALSE; @@ -556,17 +536,16 @@ OPJ_BOOL OPJ_CALLCONV opj_set_decode_area(opj_codec_t *p_codec, } OPJ_BOOL OPJ_CALLCONV opj_read_tile_header(opj_codec_t *p_codec, - opj_stream_t * p_stream, - OPJ_UINT32 * p_tile_index, - OPJ_UINT32 * p_data_size, - OPJ_INT32 * p_tile_x0, OPJ_INT32 * p_tile_y0, - OPJ_INT32 * p_tile_x1, OPJ_INT32 * p_tile_y1, - OPJ_UINT32 * p_nb_comps, - OPJ_BOOL * p_should_go_on) -{ + opj_stream_t *p_stream, + OPJ_UINT32 *p_tile_index, + OPJ_UINT32 *p_data_size, + OPJ_INT32 *p_tile_x0, OPJ_INT32 *p_tile_y0, + OPJ_INT32 *p_tile_x1, OPJ_INT32 *p_tile_y1, + OPJ_UINT32 *p_nb_comps, + OPJ_BOOL *p_should_go_on) { if (p_codec && p_stream && p_data_size && p_tile_index) { - opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec; - opj_stream_private_t * l_stream = (opj_stream_private_t *) p_stream; + opj_codec_private_t *l_codec = (opj_codec_private_t *) p_codec; + opj_stream_private_t *l_stream = (opj_stream_private_t *) p_stream; if (! l_codec->is_decompressor) { return OPJ_FALSE; @@ -587,15 +566,14 @@ OPJ_BOOL OPJ_CALLCONV opj_read_tile_header(opj_codec_t *p_codec, } OPJ_BOOL OPJ_CALLCONV opj_decode_tile_data(opj_codec_t *p_codec, - OPJ_UINT32 p_tile_index, - OPJ_BYTE * p_data, - OPJ_UINT32 p_data_size, - opj_stream_t *p_stream - ) -{ + OPJ_UINT32 p_tile_index, + OPJ_BYTE *p_data, + OPJ_UINT32 p_data_size, + opj_stream_t *p_stream + ) { if (p_codec && p_data && p_stream) { - opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec; - opj_stream_private_t * l_stream = (opj_stream_private_t *) p_stream; + opj_codec_private_t *l_codec = (opj_codec_private_t *) p_codec; + opj_stream_private_t *l_stream = (opj_stream_private_t *) p_stream; if (! l_codec->is_decompressor) { return OPJ_FALSE; @@ -613,13 +591,12 @@ OPJ_BOOL OPJ_CALLCONV opj_decode_tile_data(opj_codec_t *p_codec, } OPJ_BOOL OPJ_CALLCONV opj_get_decoded_tile(opj_codec_t *p_codec, - opj_stream_t *p_stream, - opj_image_t *p_image, - OPJ_UINT32 tile_index) -{ + opj_stream_t *p_stream, + opj_image_t *p_image, + OPJ_UINT32 tile_index) { if (p_codec && p_stream) { - opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec; - opj_stream_private_t * l_stream = (opj_stream_private_t *) p_stream; + opj_codec_private_t *l_codec = (opj_codec_private_t *) p_codec; + opj_stream_private_t *l_stream = (opj_stream_private_t *) p_stream; if (! l_codec->is_decompressor) { return OPJ_FALSE; @@ -637,9 +614,8 @@ OPJ_BOOL OPJ_CALLCONV opj_get_decoded_tile(opj_codec_t *p_codec, } OPJ_BOOL OPJ_CALLCONV opj_set_decoded_resolution_factor(opj_codec_t *p_codec, - OPJ_UINT32 res_factor) -{ - opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec; + OPJ_UINT32 res_factor) { + opj_codec_private_t *l_codec = (opj_codec_private_t *) p_codec; if (!l_codec) { return OPJ_FALSE; @@ -654,11 +630,10 @@ OPJ_BOOL OPJ_CALLCONV opj_set_decoded_resolution_factor(opj_codec_t *p_codec, /* ---------------------------------------------------------------------- */ /* COMPRESSION FUNCTIONS*/ -opj_codec_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT p_format) -{ +opj_codec_t *OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT p_format) { opj_codec_private_t *l_codec = 00; - l_codec = (opj_codec_private_t*)opj_calloc(1, sizeof(opj_codec_private_t)); + l_codec = (opj_codec_private_t *)opj_calloc(1, sizeof(opj_codec_private_t)); if (!l_codec) { return 00; } @@ -666,111 +641,110 @@ opj_codec_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT p_format) l_codec->is_decompressor = 0; switch (p_format) { - case OPJ_CODEC_J2K: - l_codec->m_codec_data.m_compression.opj_encode = (OPJ_BOOL(*)(void *, - struct opj_stream_private *, - struct opj_event_mgr *)) opj_j2k_encode; + case OPJ_CODEC_J2K: + l_codec->m_codec_data.m_compression.opj_encode = (OPJ_BOOL(*)(void *, + struct opj_stream_private *, + struct opj_event_mgr *)) opj_j2k_encode; - l_codec->m_codec_data.m_compression.opj_end_compress = (OPJ_BOOL(*)(void *, - struct opj_stream_private *, - struct opj_event_mgr *)) opj_j2k_end_compress; + l_codec->m_codec_data.m_compression.opj_end_compress = (OPJ_BOOL(*)(void *, + struct opj_stream_private *, + struct opj_event_mgr *)) opj_j2k_end_compress; - l_codec->m_codec_data.m_compression.opj_start_compress = (OPJ_BOOL(*)(void *, - struct opj_stream_private *, - struct opj_image *, - struct opj_event_mgr *)) opj_j2k_start_compress; + l_codec->m_codec_data.m_compression.opj_start_compress = (OPJ_BOOL(*)(void *, + struct opj_stream_private *, + struct opj_image *, + struct opj_event_mgr *)) opj_j2k_start_compress; - l_codec->m_codec_data.m_compression.opj_write_tile = (OPJ_BOOL(*)(void *, - OPJ_UINT32, - OPJ_BYTE*, - OPJ_UINT32, - struct opj_stream_private *, - struct opj_event_mgr *)) opj_j2k_write_tile; + l_codec->m_codec_data.m_compression.opj_write_tile = (OPJ_BOOL(*)(void *, + OPJ_UINT32, + OPJ_BYTE *, + OPJ_UINT32, + struct opj_stream_private *, + struct opj_event_mgr *)) opj_j2k_write_tile; - l_codec->m_codec_data.m_compression.opj_destroy = (void (*)( - void *)) opj_j2k_destroy; + l_codec->m_codec_data.m_compression.opj_destroy = (void (*)( + void *)) opj_j2k_destroy; - l_codec->m_codec_data.m_compression.opj_setup_encoder = (OPJ_BOOL(*)(void *, - opj_cparameters_t *, - struct opj_image *, - struct opj_event_mgr *)) opj_j2k_setup_encoder; + l_codec->m_codec_data.m_compression.opj_setup_encoder = (OPJ_BOOL(*)(void *, + opj_cparameters_t *, + struct opj_image *, + struct opj_event_mgr *)) opj_j2k_setup_encoder; - l_codec->m_codec_data.m_compression.opj_encoder_set_extra_options = (OPJ_BOOL( - *)(void *, - const char* const*, - struct opj_event_mgr *)) opj_j2k_encoder_set_extra_options; + l_codec->m_codec_data.m_compression.opj_encoder_set_extra_options = (OPJ_BOOL( + *)(void *, + const char *const *, + struct opj_event_mgr *)) opj_j2k_encoder_set_extra_options; - l_codec->opj_set_threads = - (OPJ_BOOL(*)(void * p_codec, OPJ_UINT32 num_threads)) opj_j2k_set_threads; + l_codec->opj_set_threads = + (OPJ_BOOL(*)(void *p_codec, OPJ_UINT32 num_threads)) opj_j2k_set_threads; - l_codec->m_codec = opj_j2k_create_compress(); - if (! l_codec->m_codec) { + l_codec->m_codec = opj_j2k_create_compress(); + if (! l_codec->m_codec) { + opj_free(l_codec); + return 00; + } + + break; + + case OPJ_CODEC_JP2: + /* get a JP2 decoder handle */ + l_codec->m_codec_data.m_compression.opj_encode = (OPJ_BOOL(*)(void *, + struct opj_stream_private *, + struct opj_event_mgr *)) opj_jp2_encode; + + l_codec->m_codec_data.m_compression.opj_end_compress = (OPJ_BOOL(*)(void *, + struct opj_stream_private *, + struct opj_event_mgr *)) opj_jp2_end_compress; + + l_codec->m_codec_data.m_compression.opj_start_compress = (OPJ_BOOL(*)(void *, + struct opj_stream_private *, + struct opj_image *, + struct opj_event_mgr *)) opj_jp2_start_compress; + + l_codec->m_codec_data.m_compression.opj_write_tile = (OPJ_BOOL(*)(void *, + OPJ_UINT32, + OPJ_BYTE *, + OPJ_UINT32, + struct opj_stream_private *, + struct opj_event_mgr *)) opj_jp2_write_tile; + + l_codec->m_codec_data.m_compression.opj_destroy = (void (*)( + void *)) opj_jp2_destroy; + + l_codec->m_codec_data.m_compression.opj_setup_encoder = (OPJ_BOOL(*)(void *, + opj_cparameters_t *, + struct opj_image *, + struct opj_event_mgr *)) opj_jp2_setup_encoder; + + l_codec->m_codec_data.m_compression.opj_encoder_set_extra_options = (OPJ_BOOL( + *)(void *, + const char *const *, + struct opj_event_mgr *)) opj_jp2_encoder_set_extra_options; + + l_codec->opj_set_threads = + (OPJ_BOOL(*)(void *p_codec, OPJ_UINT32 num_threads)) opj_jp2_set_threads; + + l_codec->m_codec = opj_jp2_create(OPJ_FALSE); + if (! l_codec->m_codec) { + opj_free(l_codec); + return 00; + } + + break; + + case OPJ_CODEC_UNKNOWN: + case OPJ_CODEC_JPT: + default: opj_free(l_codec); return 00; - } - - break; - - case OPJ_CODEC_JP2: - /* get a JP2 decoder handle */ - l_codec->m_codec_data.m_compression.opj_encode = (OPJ_BOOL(*)(void *, - struct opj_stream_private *, - struct opj_event_mgr *)) opj_jp2_encode; - - l_codec->m_codec_data.m_compression.opj_end_compress = (OPJ_BOOL(*)(void *, - struct opj_stream_private *, - struct opj_event_mgr *)) opj_jp2_end_compress; - - l_codec->m_codec_data.m_compression.opj_start_compress = (OPJ_BOOL(*)(void *, - struct opj_stream_private *, - struct opj_image *, - struct opj_event_mgr *)) opj_jp2_start_compress; - - l_codec->m_codec_data.m_compression.opj_write_tile = (OPJ_BOOL(*)(void *, - OPJ_UINT32, - OPJ_BYTE*, - OPJ_UINT32, - struct opj_stream_private *, - struct opj_event_mgr *)) opj_jp2_write_tile; - - l_codec->m_codec_data.m_compression.opj_destroy = (void (*)( - void *)) opj_jp2_destroy; - - l_codec->m_codec_data.m_compression.opj_setup_encoder = (OPJ_BOOL(*)(void *, - opj_cparameters_t *, - struct opj_image *, - struct opj_event_mgr *)) opj_jp2_setup_encoder; - - l_codec->m_codec_data.m_compression.opj_encoder_set_extra_options = (OPJ_BOOL( - *)(void *, - const char* const*, - struct opj_event_mgr *)) opj_jp2_encoder_set_extra_options; - - l_codec->opj_set_threads = - (OPJ_BOOL(*)(void * p_codec, OPJ_UINT32 num_threads)) opj_jp2_set_threads; - - l_codec->m_codec = opj_jp2_create(OPJ_FALSE); - if (! l_codec->m_codec) { - opj_free(l_codec); - return 00; - } - - break; - - case OPJ_CODEC_UNKNOWN: - case OPJ_CODEC_JPT: - default: - opj_free(l_codec); - return 00; } opj_set_default_event_handler(&(l_codec->m_event_mgr)); - return (opj_codec_t*) l_codec; + return (opj_codec_t *) l_codec; } void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t - *parameters) -{ + *parameters) { if (parameters) { memset(parameters, 0, sizeof(opj_cparameters_t)); /* default coding parameters */ @@ -831,10 +805,9 @@ void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t OPJ_BOOL OPJ_CALLCONV opj_setup_encoder(opj_codec_t *p_codec, opj_cparameters_t *parameters, - opj_image_t *p_image) -{ + opj_image_t *p_image) { if (p_codec && parameters && p_image) { - opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec; + opj_codec_private_t *l_codec = (opj_codec_private_t *) p_codec; if (! l_codec->is_decompressor) { return l_codec->m_codec_data.m_compression.opj_setup_encoder(l_codec->m_codec, @@ -850,10 +823,9 @@ OPJ_BOOL OPJ_CALLCONV opj_setup_encoder(opj_codec_t *p_codec, /* ----------------------------------------------------------------------- */ OPJ_BOOL OPJ_CALLCONV opj_encoder_set_extra_options(opj_codec_t *p_codec, - const char* const* options) -{ + const char *const *options) { if (p_codec) { - opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec; + opj_codec_private_t *l_codec = (opj_codec_private_t *) p_codec; if (! l_codec->is_decompressor) { return l_codec->m_codec_data.m_compression.opj_encoder_set_extra_options( @@ -869,12 +841,11 @@ OPJ_BOOL OPJ_CALLCONV opj_encoder_set_extra_options(opj_codec_t *p_codec, /* ----------------------------------------------------------------------- */ OPJ_BOOL OPJ_CALLCONV opj_start_compress(opj_codec_t *p_codec, - opj_image_t * p_image, - opj_stream_t *p_stream) -{ + opj_image_t *p_image, + opj_stream_t *p_stream) { if (p_codec && p_stream) { - opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec; - opj_stream_private_t * l_stream = (opj_stream_private_t *) p_stream; + opj_codec_private_t *l_codec = (opj_codec_private_t *) p_codec; + opj_stream_private_t *l_stream = (opj_stream_private_t *) p_stream; if (! l_codec->is_decompressor) { return l_codec->m_codec_data.m_compression.opj_start_compress(l_codec->m_codec, @@ -887,16 +858,15 @@ OPJ_BOOL OPJ_CALLCONV opj_start_compress(opj_codec_t *p_codec, return OPJ_FALSE; } -OPJ_BOOL OPJ_CALLCONV opj_encode(opj_codec_t *p_info, opj_stream_t *p_stream) -{ +OPJ_BOOL OPJ_CALLCONV opj_encode(opj_codec_t *p_info, opj_stream_t *p_stream) { if (p_info && p_stream) { - opj_codec_private_t * l_codec = (opj_codec_private_t *) p_info; - opj_stream_private_t * l_stream = (opj_stream_private_t *) p_stream; + opj_codec_private_t *l_codec = (opj_codec_private_t *) p_info; + opj_stream_private_t *l_stream = (opj_stream_private_t *) p_stream; if (! l_codec->is_decompressor) { return l_codec->m_codec_data.m_compression.opj_encode(l_codec->m_codec, - l_stream, - &(l_codec->m_event_mgr)); + l_stream, + &(l_codec->m_event_mgr)); } } @@ -905,16 +875,15 @@ OPJ_BOOL OPJ_CALLCONV opj_encode(opj_codec_t *p_info, opj_stream_t *p_stream) } OPJ_BOOL OPJ_CALLCONV opj_end_compress(opj_codec_t *p_codec, - opj_stream_t *p_stream) -{ + opj_stream_t *p_stream) { if (p_codec && p_stream) { - opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec; - opj_stream_private_t * l_stream = (opj_stream_private_t *) p_stream; + opj_codec_private_t *l_codec = (opj_codec_private_t *) p_codec; + opj_stream_private_t *l_stream = (opj_stream_private_t *) p_stream; if (! l_codec->is_decompressor) { return l_codec->m_codec_data.m_compression.opj_end_compress(l_codec->m_codec, - l_stream, - &(l_codec->m_event_mgr)); + l_stream, + &(l_codec->m_event_mgr)); } } return OPJ_FALSE; @@ -922,11 +891,10 @@ OPJ_BOOL OPJ_CALLCONV opj_end_compress(opj_codec_t *p_codec, } OPJ_BOOL OPJ_CALLCONV opj_end_decompress(opj_codec_t *p_codec, - opj_stream_t *p_stream) -{ + opj_stream_t *p_stream) { if (p_codec && p_stream) { - opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec; - opj_stream_private_t * l_stream = (opj_stream_private_t *) p_stream; + opj_codec_private_t *l_codec = (opj_codec_private_t *) p_codec; + opj_stream_private_t *l_stream = (opj_stream_private_t *) p_stream; if (! l_codec->is_decompressor) { return OPJ_FALSE; @@ -942,9 +910,8 @@ OPJ_BOOL OPJ_CALLCONV opj_end_decompress(opj_codec_t *p_codec, } OPJ_BOOL OPJ_CALLCONV opj_set_MCT(opj_cparameters_t *parameters, - OPJ_FLOAT32 * pEncodingMatrix, - OPJ_INT32 * p_dc_shift, OPJ_UINT32 pNbComp) -{ + OPJ_FLOAT32 *pEncodingMatrix, + OPJ_INT32 *p_dc_shift, OPJ_UINT32 pNbComp) { OPJ_UINT32 l_matrix_size = pNbComp * pNbComp * (OPJ_UINT32)sizeof(OPJ_FLOAT32); OPJ_UINT32 l_dc_shift_size = pNbComp * (OPJ_UINT32)sizeof(OPJ_INT32); OPJ_UINT32 l_mct_total_size = l_matrix_size + l_dc_shift_size; @@ -973,24 +940,23 @@ OPJ_BOOL OPJ_CALLCONV opj_set_MCT(opj_cparameters_t *parameters, OPJ_BOOL OPJ_CALLCONV opj_write_tile(opj_codec_t *p_codec, OPJ_UINT32 p_tile_index, - OPJ_BYTE * p_data, + OPJ_BYTE *p_data, OPJ_UINT32 p_data_size, - opj_stream_t *p_stream) -{ + opj_stream_t *p_stream) { if (p_codec && p_stream && p_data) { - opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec; - opj_stream_private_t * l_stream = (opj_stream_private_t *) p_stream; + opj_codec_private_t *l_codec = (opj_codec_private_t *) p_codec; + opj_stream_private_t *l_stream = (opj_stream_private_t *) p_stream; if (l_codec->is_decompressor) { return OPJ_FALSE; } return l_codec->m_codec_data.m_compression.opj_write_tile(l_codec->m_codec, - p_tile_index, - p_data, - p_data_size, - l_stream, - &(l_codec->m_event_mgr)); + p_tile_index, + p_data, + p_data_size, + l_stream, + &(l_codec->m_event_mgr)); } return OPJ_FALSE; @@ -998,10 +964,9 @@ OPJ_BOOL OPJ_CALLCONV opj_write_tile(opj_codec_t *p_codec, /* ---------------------------------------------------------------------- */ -void OPJ_CALLCONV opj_destroy_codec(opj_codec_t *p_codec) -{ +void OPJ_CALLCONV opj_destroy_codec(opj_codec_t *p_codec) { if (p_codec) { - opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec; + opj_codec_private_t *l_codec = (opj_codec_private_t *) p_codec; if (l_codec->is_decompressor) { l_codec->m_codec_data.m_decompression.opj_destroy(l_codec->m_codec); @@ -1018,10 +983,9 @@ void OPJ_CALLCONV opj_destroy_codec(opj_codec_t *p_codec) void OPJ_CALLCONV opj_dump_codec(opj_codec_t *p_codec, OPJ_INT32 info_flag, - FILE* output_stream) -{ + FILE *output_stream) { if (p_codec) { - opj_codec_private_t* l_codec = (opj_codec_private_t*) p_codec; + opj_codec_private_t *l_codec = (opj_codec_private_t *) p_codec; l_codec->opj_dump_codec(l_codec->m_codec, info_flag, output_stream); return; @@ -1032,10 +996,9 @@ void OPJ_CALLCONV opj_dump_codec(opj_codec_t *p_codec, return; } -opj_codestream_info_v2_t* OPJ_CALLCONV opj_get_cstr_info(opj_codec_t *p_codec) -{ +opj_codestream_info_v2_t *OPJ_CALLCONV opj_get_cstr_info(opj_codec_t *p_codec) { if (p_codec) { - opj_codec_private_t* l_codec = (opj_codec_private_t*) p_codec; + opj_codec_private_t *l_codec = (opj_codec_private_t *) p_codec; return l_codec->opj_get_codec_info(l_codec->m_codec); } @@ -1043,8 +1006,7 @@ opj_codestream_info_v2_t* OPJ_CALLCONV opj_get_cstr_info(opj_codec_t *p_codec) return NULL; } -void OPJ_CALLCONV opj_destroy_cstr_info(opj_codestream_info_v2_t **cstr_info) -{ +void OPJ_CALLCONV opj_destroy_cstr_info(opj_codestream_info_v2_t **cstr_info) { if (cstr_info) { if ((*cstr_info)->m_default_tile_info.tccp_info) { @@ -1060,10 +1022,9 @@ void OPJ_CALLCONV opj_destroy_cstr_info(opj_codestream_info_v2_t **cstr_info) } } -opj_codestream_index_t * OPJ_CALLCONV opj_get_cstr_index(opj_codec_t *p_codec) -{ +opj_codestream_index_t *OPJ_CALLCONV opj_get_cstr_index(opj_codec_t *p_codec) { if (p_codec) { - opj_codec_private_t* l_codec = (opj_codec_private_t*) p_codec; + opj_codec_private_t *l_codec = (opj_codec_private_t *) p_codec; return l_codec->opj_get_codec_index(l_codec->m_codec); } @@ -1071,27 +1032,24 @@ opj_codestream_index_t * OPJ_CALLCONV opj_get_cstr_index(opj_codec_t *p_codec) return NULL; } -void OPJ_CALLCONV opj_destroy_cstr_index(opj_codestream_index_t **p_cstr_index) -{ +void OPJ_CALLCONV opj_destroy_cstr_index(opj_codestream_index_t **p_cstr_index) { if (*p_cstr_index) { j2k_destroy_cstr_index(*p_cstr_index); (*p_cstr_index) = NULL; } } -opj_stream_t* OPJ_CALLCONV opj_stream_create_default_file_stream( - const char *fname, OPJ_BOOL p_is_read_stream) -{ +opj_stream_t *OPJ_CALLCONV opj_stream_create_default_file_stream( + const char *fname, OPJ_BOOL p_is_read_stream) { return opj_stream_create_file_stream(fname, OPJ_J2K_STREAM_CHUNK_SIZE, p_is_read_stream); } -opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream( +opj_stream_t *OPJ_CALLCONV opj_stream_create_file_stream( const char *fname, OPJ_SIZE_T p_size, - OPJ_BOOL p_is_read_stream) -{ - opj_stream_t* l_stream = 00; + OPJ_BOOL p_is_read_stream) { + opj_stream_t *l_stream = 00; FILE *p_file; const char *mode; @@ -1130,15 +1088,13 @@ opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream( } -void* OPJ_CALLCONV opj_image_data_alloc(OPJ_SIZE_T size) -{ - void* ret = opj_aligned_malloc(size); +void *OPJ_CALLCONV opj_image_data_alloc(OPJ_SIZE_T size) { + void *ret = opj_aligned_malloc(size); /* printf("opj_image_data_alloc %p\n", ret); */ return ret; } -void OPJ_CALLCONV opj_image_data_free(void* ptr) -{ +void OPJ_CALLCONV opj_image_data_free(void *ptr) { /* printf("opj_image_data_free %p\n", ptr); */ opj_aligned_free(ptr); } diff --git a/client/deps/openjpeg/openjpeg.h b/client/deps/openjpeg/openjpeg.h index fe2f1ee0c..814a61e29 100644 --- a/client/deps/openjpeg/openjpeg.h +++ b/client/deps/openjpeg/openjpeg.h @@ -532,7 +532,7 @@ typedef struct opj_cparameters { OPJ_BOOL jpip_on; /** Naive implementation of MCT restricted to a single reversible array based encoding without offset concerning all the components. */ - void * mct_data; + void *mct_data; /** * Maximum size (in bytes) for the whole codestream. * If == 0, codestream size limitation is not considered @@ -617,7 +617,7 @@ typedef struct opj_dparameters { /** * JPEG2000 codec V2. * */ -typedef void * opj_codec_t; +typedef void *opj_codec_t; /* ========================================================== @@ -638,36 +638,36 @@ typedef void * opj_codec_t; * @return returns The number of bytes delivered into * \a p_buffer. -1 signals end of stream. */ -typedef OPJ_SIZE_T(* opj_stream_read_fn)(void * p_buffer, OPJ_SIZE_T p_nb_bytes, - void * p_user_data) ; +typedef OPJ_SIZE_T(* opj_stream_read_fn)(void *p_buffer, OPJ_SIZE_T p_nb_bytes, + void *p_user_data) ; /* * Callback function prototype for write function */ -typedef OPJ_SIZE_T(* opj_stream_write_fn)(void * p_buffer, - OPJ_SIZE_T p_nb_bytes, void * p_user_data) ; +typedef OPJ_SIZE_T(* opj_stream_write_fn)(void *p_buffer, + OPJ_SIZE_T p_nb_bytes, void *p_user_data) ; /* * Callback function prototype for skip function */ typedef OPJ_OFF_T(* opj_stream_skip_fn)(OPJ_OFF_T p_nb_bytes, - void * p_user_data) ; + void *p_user_data) ; /* * Callback function prototype for seek function */ typedef OPJ_BOOL(* opj_stream_seek_fn)(OPJ_OFF_T p_nb_bytes, - void * p_user_data) ; + void *p_user_data) ; /* * Callback function prototype for free user data function */ -typedef void (* opj_stream_free_user_data_fn)(void * p_user_data) ; +typedef void (* opj_stream_free_user_data_fn)(void *p_user_data) ; /* * JPEG2000 Stream. */ -typedef void * opj_stream_t; +typedef void *opj_stream_t; /* ========================================================== @@ -1103,7 +1103,7 @@ extern "C" { */ /* Get the version of the openjpeg library*/ -OPJ_API const char * OPJ_CALLCONV opj_version(void); +OPJ_API const char *OPJ_CALLCONV opj_version(void); /* ========================================================== @@ -1119,8 +1119,8 @@ OPJ_API const char * OPJ_CALLCONV opj_version(void); * @param clrspc image color space * @return returns a new image structure if successful, returns NULL otherwise * */ -OPJ_API opj_image_t* OPJ_CALLCONV opj_image_create(OPJ_UINT32 numcmpts, - opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc); +OPJ_API opj_image_t *OPJ_CALLCONV opj_image_create(OPJ_UINT32 numcmpts, + opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc); /** * Deallocate any resources associated with an image @@ -1138,8 +1138,8 @@ OPJ_API void OPJ_CALLCONV opj_image_destroy(opj_image_t *image); * * @return a new image structure if successful, NULL otherwise. */ -OPJ_API opj_image_t* OPJ_CALLCONV opj_image_tile_create(OPJ_UINT32 numcmpts, - opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc); +OPJ_API opj_image_t *OPJ_CALLCONV opj_image_tile_create(OPJ_UINT32 numcmpts, + opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc); /** * Allocator for opj_image_t->comps[].data @@ -1150,7 +1150,7 @@ OPJ_API opj_image_t* OPJ_CALLCONV opj_image_tile_create(OPJ_UINT32 numcmpts, * @return a new pointer if successful, NULL otherwise. * @since 2.2.0 */ -OPJ_API void* OPJ_CALLCONV opj_image_data_alloc(OPJ_SIZE_T size); +OPJ_API void *OPJ_CALLCONV opj_image_data_alloc(OPJ_SIZE_T size); /** * Destructor for opj_image_t->comps[].data @@ -1160,7 +1160,7 @@ OPJ_API void* OPJ_CALLCONV opj_image_data_alloc(OPJ_SIZE_T size); * * @since 2.2.0 */ -OPJ_API void OPJ_CALLCONV opj_image_data_free(void* ptr); +OPJ_API void OPJ_CALLCONV opj_image_data_free(void *ptr); /* ========================================================== @@ -1175,7 +1175,7 @@ OPJ_API void OPJ_CALLCONV opj_image_data_free(void* ptr); * * @return a stream object. */ -OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_default_create( +OPJ_API opj_stream_t *OPJ_CALLCONV opj_stream_default_create( OPJ_BOOL p_is_input); /** @@ -1186,8 +1186,8 @@ OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_default_create( * * @return a stream object. */ -OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create(OPJ_SIZE_T p_buffer_size, - OPJ_BOOL p_is_input); +OPJ_API opj_stream_t *OPJ_CALLCONV opj_stream_create(OPJ_SIZE_T p_buffer_size, + OPJ_BOOL p_is_input); /** * Destroys a stream created by opj_create_stream. This function does NOT close the abstract stream. If needed the user must @@ -1195,31 +1195,31 @@ OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create(OPJ_SIZE_T p_buffer_size, * * @param p_stream the stream to destroy. */ -OPJ_API void OPJ_CALLCONV opj_stream_destroy(opj_stream_t* p_stream); +OPJ_API void OPJ_CALLCONV opj_stream_destroy(opj_stream_t *p_stream); /** * Sets the given function to be used as a read function. * @param p_stream the stream to modify * @param p_function the function to use a read function. */ -OPJ_API void OPJ_CALLCONV opj_stream_set_read_function(opj_stream_t* p_stream, - opj_stream_read_fn p_function); +OPJ_API void OPJ_CALLCONV opj_stream_set_read_function(opj_stream_t *p_stream, + opj_stream_read_fn p_function); /** * Sets the given function to be used as a write function. * @param p_stream the stream to modify * @param p_function the function to use a write function. */ -OPJ_API void OPJ_CALLCONV opj_stream_set_write_function(opj_stream_t* p_stream, - opj_stream_write_fn p_function); +OPJ_API void OPJ_CALLCONV opj_stream_set_write_function(opj_stream_t *p_stream, + opj_stream_write_fn p_function); /** * Sets the given function to be used as a skip function. * @param p_stream the stream to modify * @param p_function the function to use a skip function. */ -OPJ_API void OPJ_CALLCONV opj_stream_set_skip_function(opj_stream_t* p_stream, - opj_stream_skip_fn p_function); +OPJ_API void OPJ_CALLCONV opj_stream_set_skip_function(opj_stream_t *p_stream, + opj_stream_skip_fn p_function); /** * Sets the given function to be used as a seek function, the stream is then seekable, @@ -1227,8 +1227,8 @@ OPJ_API void OPJ_CALLCONV opj_stream_set_skip_function(opj_stream_t* p_stream, * @param p_stream the stream to modify * @param p_function the function to use a skip function. */ -OPJ_API void OPJ_CALLCONV opj_stream_set_seek_function(opj_stream_t* p_stream, - opj_stream_seek_fn p_function); +OPJ_API void OPJ_CALLCONV opj_stream_set_seek_function(opj_stream_t *p_stream, + opj_stream_seek_fn p_function); /** * Sets the given data to be used as a user data for the stream. @@ -1236,8 +1236,8 @@ OPJ_API void OPJ_CALLCONV opj_stream_set_seek_function(opj_stream_t* p_stream, * @param p_data the data to set. * @param p_function the function to free p_data when opj_stream_destroy() is called. */ -OPJ_API void OPJ_CALLCONV opj_stream_set_user_data(opj_stream_t* p_stream, - void * p_data, opj_stream_free_user_data_fn p_function); +OPJ_API void OPJ_CALLCONV opj_stream_set_user_data(opj_stream_t *p_stream, + void *p_data, opj_stream_free_user_data_fn p_function); /** * Sets the length of the user data for the stream. @@ -1245,14 +1245,14 @@ OPJ_API void OPJ_CALLCONV opj_stream_set_user_data(opj_stream_t* p_stream, * @param data_length length of the user_data. */ OPJ_API void OPJ_CALLCONV opj_stream_set_user_data_length( - opj_stream_t* p_stream, OPJ_UINT64 data_length); + opj_stream_t *p_stream, OPJ_UINT64 data_length); /** * Create a stream from a file identified with its filename with default parameters (helper function) * @param fname the filename of the file to stream * @param p_is_read_stream whether the stream is a read stream (true) or not (false) */ -OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_default_file_stream( +OPJ_API opj_stream_t *OPJ_CALLCONV opj_stream_create_default_file_stream( const char *fname, OPJ_BOOL p_is_read_stream); /** Create a stream from a file identified with its filename with a specific buffer size @@ -1260,7 +1260,7 @@ OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_default_file_stream( * @param p_buffer_size size of the chunk used to stream * @param p_is_read_stream whether the stream is a read stream (true) or not (false) */ -OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream( +OPJ_API opj_stream_t *OPJ_CALLCONV opj_stream_create_file_stream( const char *fname, OPJ_SIZE_T p_buffer_size, OPJ_BOOL p_is_read_stream); @@ -1276,27 +1276,27 @@ OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream( * @param p_callback the callback function which will be used * @param p_user_data client object where will be returned the message */ -OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_info_handler(opj_codec_t * p_codec, - opj_msg_callback p_callback, - void * p_user_data); +OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_info_handler(opj_codec_t *p_codec, + opj_msg_callback p_callback, + void *p_user_data); /** * Set the warning handler use by openjpeg. * @param p_codec the codec previously initialise * @param p_callback the callback function which will be used * @param p_user_data client object where will be returned the message */ -OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_warning_handler(opj_codec_t * p_codec, - opj_msg_callback p_callback, - void * p_user_data); +OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_warning_handler(opj_codec_t *p_codec, + opj_msg_callback p_callback, + void *p_user_data); /** * Set the error handler use by openjpeg. * @param p_codec the codec previously initialise * @param p_callback the callback function which will be used * @param p_user_data client object where will be returned the message */ -OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_error_handler(opj_codec_t * p_codec, - opj_msg_callback p_callback, - void * p_user_data); +OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_error_handler(opj_codec_t *p_codec, + opj_msg_callback p_callback, + void *p_user_data); /* ========================================================== @@ -1310,7 +1310,7 @@ OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_error_handler(opj_codec_t * p_codec, * * @return Returns a handle to a decompressor if successful, returns NULL otherwise * */ -OPJ_API opj_codec_t* OPJ_CALLCONV opj_create_decompress( +OPJ_API opj_codec_t *OPJ_CALLCONV opj_create_decompress( OPJ_CODEC_FORMAT format); /** @@ -1318,7 +1318,7 @@ OPJ_API opj_codec_t* OPJ_CALLCONV opj_create_decompress( * * @param p_codec decompressor handle to destroy */ -OPJ_API void OPJ_CALLCONV opj_destroy_codec(opj_codec_t * p_codec); +OPJ_API void OPJ_CALLCONV opj_destroy_codec(opj_codec_t *p_codec); /** * Read after the codestream if necessary @@ -1326,7 +1326,7 @@ OPJ_API void OPJ_CALLCONV opj_destroy_codec(opj_codec_t * p_codec); * @param p_stream the JPEG2000 stream. */ OPJ_API OPJ_BOOL OPJ_CALLCONV opj_end_decompress(opj_codec_t *p_codec, - opj_stream_t *p_stream); + opj_stream_t *p_stream); /** @@ -1346,7 +1346,7 @@ OPJ_API void OPJ_CALLCONV opj_set_default_decoder_parameters( * @return true if the decoder is correctly set */ OPJ_API OPJ_BOOL OPJ_CALLCONV opj_setup_decoder(opj_codec_t *p_codec, - opj_dparameters_t *parameters); + opj_dparameters_t *parameters); /** * Set strict decoding parameter for this decoder. @@ -1364,7 +1364,7 @@ OPJ_API OPJ_BOOL OPJ_CALLCONV opj_setup_decoder(opj_codec_t *p_codec, */ OPJ_API OPJ_BOOL OPJ_CALLCONV opj_decoder_set_strict_mode(opj_codec_t *p_codec, - OPJ_BOOL strict); + OPJ_BOOL strict); /** * Allocates worker threads for the compressor/decompressor. @@ -1385,7 +1385,7 @@ OPJ_API OPJ_BOOL OPJ_CALLCONV opj_decoder_set_strict_mode(opj_codec_t *p_codec, * @return OPJ_TRUE if the function is successful. */ OPJ_API OPJ_BOOL OPJ_CALLCONV opj_codec_set_threads(opj_codec_t *p_codec, - int num_threads); + int num_threads); /** * Decodes an image header. @@ -1397,8 +1397,8 @@ OPJ_API OPJ_BOOL OPJ_CALLCONV opj_codec_set_threads(opj_codec_t *p_codec, * @return true if the main header of the codestream and the JP2 header is correctly read. */ OPJ_API OPJ_BOOL OPJ_CALLCONV opj_read_header(opj_stream_t *p_stream, - opj_codec_t *p_codec, - opj_image_t **p_image); + opj_codec_t *p_codec, + opj_image_t **p_image); /** Restrict the number of components to decode. @@ -1427,9 +1427,9 @@ OPJ_API OPJ_BOOL OPJ_CALLCONV opj_read_header(opj_stream_t *p_stream, * @return OPJ_TRUE in case of success. */ OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_decoded_components(opj_codec_t *p_codec, - OPJ_UINT32 numcomps, - const OPJ_UINT32* comps_indices, - OPJ_BOOL apply_color_transforms); + OPJ_UINT32 numcomps, + const OPJ_UINT32 *comps_indices, + OPJ_BOOL apply_color_transforms); /** * Sets the given area to be decoded. This function should be called right after opj_read_header and before any tile header reading. @@ -1456,9 +1456,9 @@ OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_decoded_components(opj_codec_t *p_codec, * @return true if the area could be set. */ OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_decode_area(opj_codec_t *p_codec, - opj_image_t* p_image, - OPJ_INT32 p_start_x, OPJ_INT32 p_start_y, - OPJ_INT32 p_end_x, OPJ_INT32 p_end_y); + opj_image_t *p_image, + OPJ_INT32 p_start_x, OPJ_INT32 p_start_y, + OPJ_INT32 p_end_x, OPJ_INT32 p_end_y); /** * Decode an image from a JPEG-2000 codestream @@ -1469,8 +1469,8 @@ OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_decode_area(opj_codec_t *p_codec, * @return true if success, otherwise false * */ OPJ_API OPJ_BOOL OPJ_CALLCONV opj_decode(opj_codec_t *p_decompressor, - opj_stream_t *p_stream, - opj_image_t *p_image); + opj_stream_t *p_stream, + opj_image_t *p_image); /** * Get the decoded tile from the codec @@ -1483,9 +1483,9 @@ OPJ_API OPJ_BOOL OPJ_CALLCONV opj_decode(opj_codec_t *p_decompressor, * @return true if success, otherwise false */ OPJ_API OPJ_BOOL OPJ_CALLCONV opj_get_decoded_tile(opj_codec_t *p_codec, - opj_stream_t *p_stream, - opj_image_t *p_image, - OPJ_UINT32 tile_index); + opj_stream_t *p_stream, + opj_image_t *p_image, + OPJ_UINT32 tile_index); /** * Set the resolution factor of the decoded image @@ -1510,10 +1510,10 @@ OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_decoded_resolution_factor( * @return true if the data could be written. */ OPJ_API OPJ_BOOL OPJ_CALLCONV opj_write_tile(opj_codec_t *p_codec, - OPJ_UINT32 p_tile_index, - OPJ_BYTE * p_data, - OPJ_UINT32 p_data_size, - opj_stream_t *p_stream); + OPJ_UINT32 p_tile_index, + OPJ_BYTE *p_data, + OPJ_UINT32 p_data_size, + opj_stream_t *p_stream); /** * Reads a tile header. This function is compulsory and allows one to know the size of the tile that will be decoded. @@ -1537,13 +1537,13 @@ OPJ_API OPJ_BOOL OPJ_CALLCONV opj_write_tile(opj_codec_t *p_codec, * returning false may be the result of a shortage of memory or an internal error. */ OPJ_API OPJ_BOOL OPJ_CALLCONV opj_read_tile_header(opj_codec_t *p_codec, - opj_stream_t * p_stream, - OPJ_UINT32 * p_tile_index, - OPJ_UINT32 * p_data_size, - OPJ_INT32 * p_tile_x0, OPJ_INT32 * p_tile_y0, - OPJ_INT32 * p_tile_x1, OPJ_INT32 * p_tile_y1, - OPJ_UINT32 * p_nb_comps, - OPJ_BOOL * p_should_go_on); + opj_stream_t *p_stream, + OPJ_UINT32 *p_tile_index, + OPJ_UINT32 *p_data_size, + OPJ_INT32 *p_tile_x0, OPJ_INT32 *p_tile_y0, + OPJ_INT32 *p_tile_x1, OPJ_INT32 *p_tile_y1, + OPJ_UINT32 *p_nb_comps, + OPJ_BOOL *p_should_go_on); /** * Reads a tile data. This function is compulsory and allows one to decode tile data. opj_read_tile_header should be called before. @@ -1560,10 +1560,10 @@ OPJ_API OPJ_BOOL OPJ_CALLCONV opj_read_tile_header(opj_codec_t *p_codec, * @return true if the data could be decoded. */ OPJ_API OPJ_BOOL OPJ_CALLCONV opj_decode_tile_data(opj_codec_t *p_codec, - OPJ_UINT32 p_tile_index, - OPJ_BYTE * p_data, - OPJ_UINT32 p_data_size, - opj_stream_t *p_stream); + OPJ_UINT32 p_tile_index, + OPJ_BYTE *p_data, + OPJ_UINT32 p_data_size, + opj_stream_t *p_stream); /* COMPRESSION FUNCTIONS*/ @@ -1572,7 +1572,7 @@ OPJ_API OPJ_BOOL OPJ_CALLCONV opj_decode_tile_data(opj_codec_t *p_codec, * @param format Coder to select * @return Returns a handle to a compressor if successful, returns NULL otherwise */ -OPJ_API opj_codec_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT format); +OPJ_API opj_codec_t *OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT format); /** Set encoding parameters to default values, that means : @@ -1605,8 +1605,8 @@ OPJ_API void OPJ_CALLCONV opj_set_default_encoder_parameters( * @param image Input filled image */ OPJ_API OPJ_BOOL OPJ_CALLCONV opj_setup_encoder(opj_codec_t *p_codec, - opj_cparameters_t *parameters, - opj_image_t *image); + opj_cparameters_t *parameters, + opj_image_t *image); /** @@ -1639,7 +1639,7 @@ OPJ_API OPJ_BOOL OPJ_CALLCONV opj_setup_encoder(opj_codec_t *p_codec, */ OPJ_API OPJ_BOOL OPJ_CALLCONV opj_encoder_set_extra_options( opj_codec_t *p_codec, - const char* const* p_options); + const char *const *p_options); /** * Start to compress the current image. @@ -1648,8 +1648,8 @@ OPJ_API OPJ_BOOL OPJ_CALLCONV opj_encoder_set_extra_options( * @param p_stream Input stgream */ OPJ_API OPJ_BOOL OPJ_CALLCONV opj_start_compress(opj_codec_t *p_codec, - opj_image_t * p_image, - opj_stream_t *p_stream); + opj_image_t *p_image, + opj_stream_t *p_stream); /** * End to compress the current image. @@ -1657,7 +1657,7 @@ OPJ_API OPJ_BOOL OPJ_CALLCONV opj_start_compress(opj_codec_t *p_codec, * @param p_stream Input stgream */ OPJ_API OPJ_BOOL OPJ_CALLCONV opj_end_compress(opj_codec_t *p_codec, - opj_stream_t *p_stream); + opj_stream_t *p_stream); /** * Encode an image into a JPEG-2000 codestream @@ -1667,7 +1667,7 @@ OPJ_API OPJ_BOOL OPJ_CALLCONV opj_end_compress(opj_codec_t *p_codec, * @return Returns true if successful, returns false otherwise */ OPJ_API OPJ_BOOL OPJ_CALLCONV opj_encode(opj_codec_t *p_codec, - opj_stream_t *p_stream); + opj_stream_t *p_stream); /* ========================================================== codec output functions definitions @@ -1680,7 +1680,7 @@ Destroy Codestream information after compression or decompression @param cstr_info Codestream information structure */ OPJ_API void OPJ_CALLCONV opj_destroy_cstr_info(opj_codestream_info_v2_t - **cstr_info); + **cstr_info); /** @@ -1692,8 +1692,8 @@ OPJ_API void OPJ_CALLCONV opj_destroy_cstr_info(opj_codestream_info_v2_t * */ OPJ_API void OPJ_CALLCONV opj_dump_codec(opj_codec_t *p_codec, - OPJ_INT32 info_flag, - FILE* output_stream); + OPJ_INT32 info_flag, + FILE *output_stream); /** * Get the codestream information from the codec @@ -1703,7 +1703,7 @@ OPJ_API void OPJ_CALLCONV opj_dump_codec(opj_codec_t *p_codec, * @return a pointer to a codestream information structure. * */ -OPJ_API opj_codestream_info_v2_t* OPJ_CALLCONV opj_get_cstr_info( +OPJ_API opj_codestream_info_v2_t *OPJ_CALLCONV opj_get_cstr_info( opj_codec_t *p_codec); /** @@ -1714,11 +1714,11 @@ OPJ_API opj_codestream_info_v2_t* OPJ_CALLCONV opj_get_cstr_info( * @return a pointer to a codestream index structure. * */ -OPJ_API opj_codestream_index_t * OPJ_CALLCONV opj_get_cstr_index( +OPJ_API opj_codestream_index_t *OPJ_CALLCONV opj_get_cstr_index( opj_codec_t *p_codec); OPJ_API void OPJ_CALLCONV opj_destroy_cstr_index(opj_codestream_index_t - **p_cstr_index); + **p_cstr_index); /** @@ -1729,7 +1729,7 @@ OPJ_API void OPJ_CALLCONV opj_destroy_cstr_index(opj_codestream_index_t * @return a pointer to a JP2 metadata structure. * */ -OPJ_API opj_jp2_metadata_t* OPJ_CALLCONV opj_get_jp2_metadata( +OPJ_API opj_jp2_metadata_t *OPJ_CALLCONV opj_get_jp2_metadata( opj_codec_t *p_codec); /** @@ -1740,7 +1740,7 @@ OPJ_API opj_jp2_metadata_t* OPJ_CALLCONV opj_get_jp2_metadata( * @return a pointer to a JP2 index structure. * */ -OPJ_API opj_jp2_index_t* OPJ_CALLCONV opj_get_jp2_index(opj_codec_t *p_codec); +OPJ_API opj_jp2_index_t *OPJ_CALLCONV opj_get_jp2_index(opj_codec_t *p_codec); /* @@ -1760,9 +1760,9 @@ OPJ_API opj_jp2_index_t* OPJ_CALLCONV opj_get_jp2_index(opj_codec_t *p_codec); * @return true if the parameters could be set. */ OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_MCT(opj_cparameters_t *parameters, - OPJ_FLOAT32 * pEncodingMatrix, - OPJ_INT32 * p_dc_shift, - OPJ_UINT32 pNbComp); + OPJ_FLOAT32 *pEncodingMatrix, + OPJ_INT32 *p_dc_shift, + OPJ_UINT32 pNbComp); /* ========================================================== diff --git a/client/deps/openjpeg/opj_clock.c b/client/deps/openjpeg/opj_clock.c index 24f79a9ae..bf4be9722 100644 --- a/client/deps/openjpeg/opj_clock.c +++ b/client/deps/openjpeg/opj_clock.c @@ -39,8 +39,7 @@ #include #endif /* _WIN32 */ -OPJ_FLOAT64 opj_clock(void) -{ +OPJ_FLOAT64 opj_clock(void) { #ifdef _WIN32 /* _WIN32: use QueryPerformance (very accurate) */ LARGE_INTEGER freq, t ; diff --git a/client/deps/openjpeg/opj_codec.h b/client/deps/openjpeg/opj_codec.h index 7cff67082..728bc6448 100644 --- a/client/deps/openjpeg/opj_codec.h +++ b/client/deps/openjpeg/opj_codec.h @@ -47,78 +47,78 @@ typedef struct opj_codec_private { */ struct opj_decompression { /** Main header reading function handler */ - OPJ_BOOL(*opj_read_header)(struct opj_stream_private * cio, - void * p_codec, + OPJ_BOOL(*opj_read_header)(struct opj_stream_private *cio, + void *p_codec, opj_image_t **p_image, - struct opj_event_mgr * p_manager); + struct opj_event_mgr *p_manager); /** Decoding function */ - OPJ_BOOL(*opj_decode)(void * p_codec, - struct opj_stream_private * p_cio, - opj_image_t * p_image, - struct opj_event_mgr * p_manager); + OPJ_BOOL(*opj_decode)(void *p_codec, + struct opj_stream_private *p_cio, + opj_image_t *p_image, + struct opj_event_mgr *p_manager); /** FIXME DOC */ - OPJ_BOOL(*opj_read_tile_header)(void * p_codec, - OPJ_UINT32 * p_tile_index, - OPJ_UINT32 * p_data_size, - OPJ_INT32 * p_tile_x0, - OPJ_INT32 * p_tile_y0, - OPJ_INT32 * p_tile_x1, - OPJ_INT32 * p_tile_y1, - OPJ_UINT32 * p_nb_comps, - OPJ_BOOL * p_should_go_on, - struct opj_stream_private * p_cio, - struct opj_event_mgr * p_manager); + OPJ_BOOL(*opj_read_tile_header)(void *p_codec, + OPJ_UINT32 *p_tile_index, + OPJ_UINT32 *p_data_size, + OPJ_INT32 *p_tile_x0, + OPJ_INT32 *p_tile_y0, + OPJ_INT32 *p_tile_x1, + OPJ_INT32 *p_tile_y1, + OPJ_UINT32 *p_nb_comps, + OPJ_BOOL *p_should_go_on, + struct opj_stream_private *p_cio, + struct opj_event_mgr *p_manager); /** FIXME DOC */ - OPJ_BOOL(*opj_decode_tile_data)(void * p_codec, + OPJ_BOOL(*opj_decode_tile_data)(void *p_codec, OPJ_UINT32 p_tile_index, - OPJ_BYTE * p_data, + OPJ_BYTE *p_data, OPJ_UINT32 p_data_size, - struct opj_stream_private * p_cio, - struct opj_event_mgr * p_manager); + struct opj_stream_private *p_cio, + struct opj_event_mgr *p_manager); /** Reading function used after codestream if necessary */ OPJ_BOOL(* opj_end_decompress)(void *p_codec, - struct opj_stream_private * cio, - struct opj_event_mgr * p_manager); + struct opj_stream_private *cio, + struct opj_event_mgr *p_manager); /** Codec destroy function handler */ - void (*opj_destroy)(void * p_codec); + void (*opj_destroy)(void *p_codec); /** Setup decoder function handler */ - void (*opj_setup_decoder)(void * p_codec, opj_dparameters_t * p_param); + void (*opj_setup_decoder)(void *p_codec, opj_dparameters_t *p_param); /** Strict mode function handler */ - void (*opj_decoder_set_strict_mode)(void * p_codec, OPJ_BOOL strict); + void (*opj_decoder_set_strict_mode)(void *p_codec, OPJ_BOOL strict); /** Set decode area function handler */ - OPJ_BOOL(*opj_set_decode_area)(void * p_codec, - opj_image_t * p_image, + OPJ_BOOL(*opj_set_decode_area)(void *p_codec, + opj_image_t *p_image, OPJ_INT32 p_start_x, OPJ_INT32 p_end_x, OPJ_INT32 p_start_y, OPJ_INT32 p_end_y, - struct opj_event_mgr * p_manager); + struct opj_event_mgr *p_manager); /** Get tile function */ OPJ_BOOL(*opj_get_decoded_tile)(void *p_codec, - opj_stream_private_t * p_cio, + opj_stream_private_t *p_cio, opj_image_t *p_image, - struct opj_event_mgr * p_manager, + struct opj_event_mgr *p_manager, OPJ_UINT32 tile_index); /** Set the decoded resolution factor */ - OPJ_BOOL(*opj_set_decoded_resolution_factor)(void * p_codec, - OPJ_UINT32 res_factor, - opj_event_mgr_t * p_manager); + OPJ_BOOL(*opj_set_decoded_resolution_factor)(void *p_codec, + OPJ_UINT32 res_factor, + opj_event_mgr_t *p_manager); /** Set the decoded components */ - OPJ_BOOL(*opj_set_decoded_components)(void * p_codec, + OPJ_BOOL(*opj_set_decoded_components)(void *p_codec, OPJ_UINT32 num_comps, - const OPJ_UINT32* comps_indices, - opj_event_mgr_t * p_manager); + const OPJ_UINT32 *comps_indices, + opj_event_mgr_t *p_manager); } m_decompression; /** @@ -126,51 +126,51 @@ typedef struct opj_codec_private { */ struct opj_compression { OPJ_BOOL(* opj_start_compress)(void *p_codec, - struct opj_stream_private * cio, - struct opj_image * p_image, - struct opj_event_mgr * p_manager); + struct opj_stream_private *cio, + struct opj_image *p_image, + struct opj_event_mgr *p_manager); - OPJ_BOOL(* opj_encode)(void * p_codec, + OPJ_BOOL(* opj_encode)(void *p_codec, struct opj_stream_private *p_cio, - struct opj_event_mgr * p_manager); + struct opj_event_mgr *p_manager); - OPJ_BOOL(* opj_write_tile)(void * p_codec, + OPJ_BOOL(* opj_write_tile)(void *p_codec, OPJ_UINT32 p_tile_index, - OPJ_BYTE * p_data, + OPJ_BYTE *p_data, OPJ_UINT32 p_data_size, - struct opj_stream_private * p_cio, - struct opj_event_mgr * p_manager); + struct opj_stream_private *p_cio, + struct opj_event_mgr *p_manager); - OPJ_BOOL(* opj_end_compress)(void * p_codec, - struct opj_stream_private * p_cio, - struct opj_event_mgr * p_manager); + OPJ_BOOL(* opj_end_compress)(void *p_codec, + struct opj_stream_private *p_cio, + struct opj_event_mgr *p_manager); - void (* opj_destroy)(void * p_codec); + void (* opj_destroy)(void *p_codec); - OPJ_BOOL(* opj_setup_encoder)(void * p_codec, - opj_cparameters_t * p_param, - struct opj_image * p_image, - struct opj_event_mgr * p_manager); + OPJ_BOOL(* opj_setup_encoder)(void *p_codec, + opj_cparameters_t *p_param, + struct opj_image *p_image, + struct opj_event_mgr *p_manager); - OPJ_BOOL(* opj_encoder_set_extra_options)(void * p_codec, - const char* const* p_options, - struct opj_event_mgr * p_manager); + OPJ_BOOL(* opj_encoder_set_extra_options)(void *p_codec, + const char *const *p_options, + struct opj_event_mgr *p_manager); } m_compression; } m_codec_data; /** FIXME DOC*/ - void * m_codec; + void *m_codec; /** Event handler */ opj_event_mgr_t m_event_mgr; /** Flag to indicate if the codec is used to decode or encode*/ OPJ_BOOL is_decompressor; - void (*opj_dump_codec)(void * p_codec, OPJ_INT32 info_flag, - FILE* output_stream); - opj_codestream_info_v2_t* (*opj_get_codec_info)(void* p_codec); - opj_codestream_index_t* (*opj_get_codec_index)(void* p_codec); + void (*opj_dump_codec)(void *p_codec, OPJ_INT32 info_flag, + FILE *output_stream); + opj_codestream_info_v2_t *(*opj_get_codec_info)(void *p_codec); + opj_codestream_index_t *(*opj_get_codec_index)(void *p_codec); /** Set number of threads */ - OPJ_BOOL(*opj_set_threads)(void * p_codec, OPJ_UINT32 num_threads); + OPJ_BOOL(*opj_set_threads)(void *p_codec, OPJ_UINT32 num_threads); } opj_codec_private_t; diff --git a/client/deps/openjpeg/opj_includes.h b/client/deps/openjpeg/opj_includes.h index 13613ce52..957d18402 100644 --- a/client/deps/openjpeg/opj_includes.h +++ b/client/deps/openjpeg/opj_includes.h @@ -137,8 +137,7 @@ /* MSVC before 2013 and Borland C do not have lrintf */ #if defined(_MSC_VER) #include -static INLINE long opj_lrintf(float f) -{ +static INLINE long opj_lrintf(float f) { #ifdef _M_X64 return _mm_cvt_ss2si(_mm_load_ss(&f)); @@ -157,8 +156,7 @@ static INLINE long opj_lrintf(float f) #endif } #elif defined(__BORLANDC__) -static INLINE long opj_lrintf(float f) -{ +static INLINE long opj_lrintf(float f) { #ifdef _M_X64 return (long)((f > 0.0f) ? (f + 0.5f) : (f - 0.5f)); #else @@ -173,8 +171,7 @@ static INLINE long opj_lrintf(float f) #endif } #else -static INLINE long opj_lrintf(float f) -{ +static INLINE long opj_lrintf(float f) { return lrintf(f); } #endif diff --git a/client/deps/openjpeg/opj_intmath.h b/client/deps/openjpeg/opj_intmath.h index cce7a3caf..201a8bbab 100644 --- a/client/deps/openjpeg/opj_intmath.h +++ b/client/deps/openjpeg/opj_intmath.h @@ -53,8 +53,7 @@ The functions in OPJ_INTMATH.H have for goal to realize operations on integers. Get the minimum of two integers @return Returns a if a < b else b */ -static INLINE OPJ_INT32 opj_int_min(OPJ_INT32 a, OPJ_INT32 b) -{ +static INLINE OPJ_INT32 opj_int_min(OPJ_INT32 a, OPJ_INT32 b) { return a < b ? a : b; } @@ -62,8 +61,7 @@ static INLINE OPJ_INT32 opj_int_min(OPJ_INT32 a, OPJ_INT32 b) Get the minimum of two integers @return Returns a if a < b else b */ -static INLINE OPJ_UINT32 opj_uint_min(OPJ_UINT32 a, OPJ_UINT32 b) -{ +static INLINE OPJ_UINT32 opj_uint_min(OPJ_UINT32 a, OPJ_UINT32 b) { return a < b ? a : b; } @@ -71,8 +69,7 @@ static INLINE OPJ_UINT32 opj_uint_min(OPJ_UINT32 a, OPJ_UINT32 b) Get the maximum of two integers @return Returns a if a > b else b */ -static INLINE OPJ_INT32 opj_int_max(OPJ_INT32 a, OPJ_INT32 b) -{ +static INLINE OPJ_INT32 opj_int_max(OPJ_INT32 a, OPJ_INT32 b) { return (a > b) ? a : b; } @@ -80,8 +77,7 @@ static INLINE OPJ_INT32 opj_int_max(OPJ_INT32 a, OPJ_INT32 b) Get the maximum of two integers @return Returns a if a > b else b */ -static INLINE OPJ_UINT32 opj_uint_max(OPJ_UINT32 a, OPJ_UINT32 b) -{ +static INLINE OPJ_UINT32 opj_uint_max(OPJ_UINT32 a, OPJ_UINT32 b) { return (a > b) ? a : b; } @@ -89,8 +85,7 @@ static INLINE OPJ_UINT32 opj_uint_max(OPJ_UINT32 a, OPJ_UINT32 b) Get the saturated sum of two unsigned integers @return Returns saturated sum of a+b */ -static INLINE OPJ_UINT32 opj_uint_adds(OPJ_UINT32 a, OPJ_UINT32 b) -{ +static INLINE OPJ_UINT32 opj_uint_adds(OPJ_UINT32 a, OPJ_UINT32 b) { OPJ_UINT64 sum = (OPJ_UINT64)a + (OPJ_UINT64)b; return (OPJ_UINT32)(-(OPJ_INT32)(sum >> 32)) | (OPJ_UINT32)sum; } @@ -99,8 +94,7 @@ static INLINE OPJ_UINT32 opj_uint_adds(OPJ_UINT32 a, OPJ_UINT32 b) Get the saturated difference of two unsigned integers @return Returns saturated sum of a-b */ -static INLINE OPJ_UINT32 opj_uint_subs(OPJ_UINT32 a, OPJ_UINT32 b) -{ +static INLINE OPJ_UINT32 opj_uint_subs(OPJ_UINT32 a, OPJ_UINT32 b) { return (a >= b) ? a - b : 0; } @@ -114,8 +108,7 @@ Clamp an integer inside an interval */ static INLINE OPJ_INT32 opj_int_clamp(OPJ_INT32 a, OPJ_INT32 min, - OPJ_INT32 max) -{ + OPJ_INT32 max) { if (a < min) { return min; } @@ -135,8 +128,7 @@ Clamp an integer inside an interval */ static INLINE OPJ_INT64 opj_int64_clamp(OPJ_INT64 a, OPJ_INT64 min, - OPJ_INT64 max) -{ + OPJ_INT64 max) { if (a < min) { return min; } @@ -149,16 +141,14 @@ static INLINE OPJ_INT64 opj_int64_clamp(OPJ_INT64 a, OPJ_INT64 min, /** @return Get absolute value of integer */ -static INLINE OPJ_INT32 opj_int_abs(OPJ_INT32 a) -{ +static INLINE OPJ_INT32 opj_int_abs(OPJ_INT32 a) { return a < 0 ? -a : a; } /** Divide an integer and round upwards @return Returns a divided by b */ -static INLINE OPJ_INT32 opj_int_ceildiv(OPJ_INT32 a, OPJ_INT32 b) -{ +static INLINE OPJ_INT32 opj_int_ceildiv(OPJ_INT32 a, OPJ_INT32 b) { assert(b); return (OPJ_INT32)(((OPJ_INT64)a + b - 1) / b); } @@ -167,8 +157,7 @@ static INLINE OPJ_INT32 opj_int_ceildiv(OPJ_INT32 a, OPJ_INT32 b) Divide an integer and round upwards @return Returns a divided by b */ -static INLINE OPJ_UINT32 opj_uint_ceildiv(OPJ_UINT32 a, OPJ_UINT32 b) -{ +static INLINE OPJ_UINT32 opj_uint_ceildiv(OPJ_UINT32 a, OPJ_UINT32 b) { assert(b); return (OPJ_UINT32)(((OPJ_UINT64)a + b - 1) / b); } @@ -178,8 +167,7 @@ Divide an integer and round upwards @return Returns a divided by b */ static INLINE OPJ_UINT32 opj_uint64_ceildiv_res_uint32(OPJ_UINT64 a, - OPJ_UINT64 b) -{ + OPJ_UINT64 b) { assert(b); return (OPJ_UINT32)((a + b - 1) / b); } @@ -188,8 +176,7 @@ static INLINE OPJ_UINT32 opj_uint64_ceildiv_res_uint32(OPJ_UINT64 a, Divide an integer by a power of 2 and round upwards @return Returns a divided by 2^b */ -static INLINE OPJ_INT32 opj_int_ceildivpow2(OPJ_INT32 a, OPJ_INT32 b) -{ +static INLINE OPJ_INT32 opj_int_ceildivpow2(OPJ_INT32 a, OPJ_INT32 b) { return (OPJ_INT32)((a + ((OPJ_INT64)1 << b) - 1) >> b); } @@ -197,8 +184,7 @@ static INLINE OPJ_INT32 opj_int_ceildivpow2(OPJ_INT32 a, OPJ_INT32 b) Divide a 64bits integer by a power of 2 and round upwards @return Returns a divided by 2^b */ -static INLINE OPJ_INT32 opj_int64_ceildivpow2(OPJ_INT64 a, OPJ_INT32 b) -{ +static INLINE OPJ_INT32 opj_int64_ceildivpow2(OPJ_INT64 a, OPJ_INT32 b) { return (OPJ_INT32)((a + ((OPJ_INT64)1 << b) - 1) >> b); } @@ -206,8 +192,7 @@ static INLINE OPJ_INT32 opj_int64_ceildivpow2(OPJ_INT64 a, OPJ_INT32 b) Divide an integer by a power of 2 and round upwards @return Returns a divided by 2^b */ -static INLINE OPJ_UINT32 opj_uint_ceildivpow2(OPJ_UINT32 a, OPJ_UINT32 b) -{ +static INLINE OPJ_UINT32 opj_uint_ceildivpow2(OPJ_UINT32 a, OPJ_UINT32 b) { return (OPJ_UINT32)((a + ((OPJ_UINT64)1U << b) - 1U) >> b); } @@ -215,8 +200,7 @@ static INLINE OPJ_UINT32 opj_uint_ceildivpow2(OPJ_UINT32 a, OPJ_UINT32 b) Divide an integer by a power of 2 and round downwards @return Returns a divided by 2^b */ -static INLINE OPJ_INT32 opj_int_floordivpow2(OPJ_INT32 a, OPJ_INT32 b) -{ +static INLINE OPJ_INT32 opj_int_floordivpow2(OPJ_INT32 a, OPJ_INT32 b) { return a >> b; } @@ -224,8 +208,7 @@ static INLINE OPJ_INT32 opj_int_floordivpow2(OPJ_INT32 a, OPJ_INT32 b) Divide an integer by a power of 2 and round downwards @return Returns a divided by 2^b */ -static INLINE OPJ_UINT32 opj_uint_floordivpow2(OPJ_UINT32 a, OPJ_UINT32 b) -{ +static INLINE OPJ_UINT32 opj_uint_floordivpow2(OPJ_UINT32 a, OPJ_UINT32 b) { return a >> b; } @@ -233,8 +216,7 @@ static INLINE OPJ_UINT32 opj_uint_floordivpow2(OPJ_UINT32 a, OPJ_UINT32 b) Get logarithm of an integer and round downwards @return Returns log2(a) */ -static INLINE OPJ_INT32 opj_int_floorlog2(OPJ_INT32 a) -{ +static INLINE OPJ_INT32 opj_int_floorlog2(OPJ_INT32 a) { OPJ_INT32 l; for (l = 0; a > 1; l++) { a >>= 1; @@ -245,8 +227,7 @@ static INLINE OPJ_INT32 opj_int_floorlog2(OPJ_INT32 a) Get logarithm of an integer and round downwards @return Returns log2(a) */ -static INLINE OPJ_UINT32 opj_uint_floorlog2(OPJ_UINT32 a) -{ +static INLINE OPJ_UINT32 opj_uint_floorlog2(OPJ_UINT32 a) { OPJ_UINT32 l; for (l = 0; a > 1; ++l) { a >>= 1; @@ -260,8 +241,7 @@ Multiply two fixed-precision rational numbers. @param b @return Returns a * b */ -static INLINE OPJ_INT32 opj_int_fix_mul(OPJ_INT32 a, OPJ_INT32 b) -{ +static INLINE OPJ_INT32 opj_int_fix_mul(OPJ_INT32 a, OPJ_INT32 b) { #if defined(_MSC_VER) && (_MSC_VER >= 1400) && !defined(__INTEL_COMPILER) && defined(_M_IX86) OPJ_INT64 temp = __emul(a, b); #else @@ -273,8 +253,7 @@ static INLINE OPJ_INT32 opj_int_fix_mul(OPJ_INT32 a, OPJ_INT32 b) return (OPJ_INT32)(temp >> 13); } -static INLINE OPJ_INT32 opj_int_fix_mul_t1(OPJ_INT32 a, OPJ_INT32 b) -{ +static INLINE OPJ_INT32 opj_int_fix_mul_t1(OPJ_INT32 a, OPJ_INT32 b) { #if defined(_MSC_VER) && (_MSC_VER >= 1400) && !defined(__INTEL_COMPILER) && defined(_M_IX86) OPJ_INT64 temp = __emul(a, b); #else @@ -283,7 +262,7 @@ static INLINE OPJ_INT32 opj_int_fix_mul_t1(OPJ_INT32 a, OPJ_INT32 b) temp += 4096; assert((temp >> (13 + 11 - T1_NMSEDEC_FRACBITS)) <= (OPJ_INT64)0x7FFFFFFF); assert((temp >> (13 + 11 - T1_NMSEDEC_FRACBITS)) >= (-(OPJ_INT64)0x7FFFFFFF - - (OPJ_INT64)1)); + (OPJ_INT64)1)); return (OPJ_INT32)(temp >> (13 + 11 - T1_NMSEDEC_FRACBITS)) ; } @@ -294,15 +273,14 @@ Assumes complement-to-two signed integers. @param b @return Returns a + b */ -static INLINE OPJ_INT32 opj_int_add_no_overflow(OPJ_INT32 a, OPJ_INT32 b) -{ - void* pa = &a; - void* pb = &b; - OPJ_UINT32* upa = (OPJ_UINT32*)pa; - OPJ_UINT32* upb = (OPJ_UINT32*)pb; +static INLINE OPJ_INT32 opj_int_add_no_overflow(OPJ_INT32 a, OPJ_INT32 b) { + void *pa = &a; + void *pb = &b; + OPJ_UINT32 *upa = (OPJ_UINT32 *)pa; + OPJ_UINT32 *upb = (OPJ_UINT32 *)pb; OPJ_UINT32 ures = *upa + *upb; - void* pures = &ures; - OPJ_INT32* ipres = (OPJ_INT32*)pures; + void *pures = &ures; + OPJ_INT32 *ipres = (OPJ_INT32 *)pures; return *ipres; } @@ -313,15 +291,14 @@ Assumes complement-to-two signed integers. @param b @return Returns a - b */ -static INLINE OPJ_INT32 opj_int_sub_no_overflow(OPJ_INT32 a, OPJ_INT32 b) -{ - void* pa = &a; - void* pb = &b; - OPJ_UINT32* upa = (OPJ_UINT32*)pa; - OPJ_UINT32* upb = (OPJ_UINT32*)pb; +static INLINE OPJ_INT32 opj_int_sub_no_overflow(OPJ_INT32 a, OPJ_INT32 b) { + void *pa = &a; + void *pb = &b; + OPJ_UINT32 *upa = (OPJ_UINT32 *)pa; + OPJ_UINT32 *upb = (OPJ_UINT32 *)pb; OPJ_UINT32 ures = *upa - *upb; - void* pures = &ures; - OPJ_INT32* ipres = (OPJ_INT32*)pures; + void *pures = &ures; + OPJ_INT32 *ipres = (OPJ_INT32 *)pures; return *ipres; } diff --git a/client/deps/openjpeg/opj_malloc.c b/client/deps/openjpeg/opj_malloc.c index dca91bfcb..1ae861c83 100644 --- a/client/deps/openjpeg/opj_malloc.c +++ b/client/deps/openjpeg/opj_malloc.c @@ -40,14 +40,13 @@ # define SIZE_MAX ((size_t) -1) #endif -static INLINE void *opj_aligned_alloc_n(size_t alignment, size_t size) -{ - void* ptr; +static INLINE void *opj_aligned_alloc_n(size_t alignment, size_t size) { + void *ptr; /* alignment shall be power of 2 */ assert((alignment != 0U) && ((alignment & (alignment - 1U)) == 0U)); /* alignment shall be at least sizeof(void*) */ - assert(alignment >= sizeof(void*)); + assert(alignment >= sizeof(void *)); if (size == 0U) { /* prevent implementation defined behavior of realloc */ return NULL; @@ -90,29 +89,28 @@ static INLINE void *opj_aligned_alloc_n(size_t alignment, size_t size) return NULL; } - mem = (OPJ_UINT8*)malloc(size + overhead); + mem = (OPJ_UINT8 *)malloc(size + overhead); if (mem == NULL) { return mem; } /* offset = ((alignment + 1U) - ((size_t)(mem + sizeof(void*)) & alignment)) & alignment; */ /* Use the fact that alignment + 1U is a power of 2 */ - offset = ((alignment ^ ((size_t)(mem + sizeof(void*)) & alignment)) + 1U) & + offset = ((alignment ^ ((size_t)(mem + sizeof(void *)) & alignment)) + 1U) & alignment; - ptr = (void *)(mem + sizeof(void*) + offset); - ((void**) ptr)[-1] = mem; + ptr = (void *)(mem + sizeof(void *) + offset); + ((void **) ptr)[-1] = mem; } #endif return ptr; } static INLINE void *opj_aligned_realloc_n(void *ptr, size_t alignment, - size_t new_size) -{ + size_t new_size) { void *r_ptr; /* alignment shall be power of 2 */ assert((alignment != 0U) && ((alignment & (alignment - 1U)) == 0U)); /* alignment shall be at least sizeof(void*) */ - assert(alignment >= sizeof(void*)); + assert(alignment >= sizeof(void *)); if (new_size == 0U) { /* prevent implementation defined behavior of realloc */ return NULL; @@ -157,8 +155,8 @@ static INLINE void *opj_aligned_realloc_n(void *ptr, size_t alignment, return NULL; } - oldmem = ((void**) ptr)[-1]; - newmem = (OPJ_UINT8*)realloc(oldmem, new_size + overhead); + oldmem = ((void **) ptr)[-1]; + newmem = (OPJ_UINT8 *)realloc(oldmem, new_size + overhead); if (newmem == NULL) { return newmem; } @@ -170,33 +168,31 @@ static INLINE void *opj_aligned_realloc_n(void *ptr, size_t alignment, size_t new_offset; /* realloc created a new copy, realign the copied memory block */ - old_offset = (size_t)((OPJ_UINT8*)ptr - (OPJ_UINT8*)oldmem); + old_offset = (size_t)((OPJ_UINT8 *)ptr - (OPJ_UINT8 *)oldmem); /* offset = ((alignment + 1U) - ((size_t)(mem + sizeof(void*)) & alignment)) & alignment; */ /* Use the fact that alignment + 1U is a power of 2 */ - new_offset = ((alignment ^ ((size_t)(newmem + sizeof(void*)) & alignment)) + + new_offset = ((alignment ^ ((size_t)(newmem + sizeof(void *)) & alignment)) + 1U) & alignment; - new_offset += sizeof(void*); + new_offset += sizeof(void *); r_ptr = (void *)(newmem + new_offset); if (new_offset != old_offset) { memmove(newmem + new_offset, newmem + old_offset, new_size); } - ((void**) r_ptr)[-1] = newmem; + ((void **) r_ptr)[-1] = newmem; } } #endif return r_ptr; } -void * opj_malloc(size_t size) -{ +void *opj_malloc(size_t size) { if (size == 0U) { /* prevent implementation defined behavior of realloc */ return NULL; } return malloc(size); } -void * opj_calloc(size_t num, size_t size) -{ +void *opj_calloc(size_t num, size_t size) { if (num == 0 || size == 0) { /* prevent implementation defined behavior of realloc */ return NULL; @@ -204,26 +200,21 @@ void * opj_calloc(size_t num, size_t size) return calloc(num, size); } -void *opj_aligned_malloc(size_t size) -{ +void *opj_aligned_malloc(size_t size) { return opj_aligned_alloc_n(16U, size); } -void * opj_aligned_realloc(void *ptr, size_t size) -{ +void *opj_aligned_realloc(void *ptr, size_t size) { return opj_aligned_realloc_n(ptr, 16U, size); } -void *opj_aligned_32_malloc(size_t size) -{ +void *opj_aligned_32_malloc(size_t size) { return opj_aligned_alloc_n(32U, size); } -void * opj_aligned_32_realloc(void *ptr, size_t size) -{ +void *opj_aligned_32_realloc(void *ptr, size_t size) { return opj_aligned_realloc_n(ptr, 32U, size); } -void opj_aligned_free(void* ptr) -{ +void opj_aligned_free(void *ptr) { #if defined(OPJ_HAVE_POSIX_MEMALIGN) || defined(OPJ_HAVE_MEMALIGN) free(ptr); #elif defined(OPJ_HAVE__ALIGNED_MALLOC) @@ -231,19 +222,17 @@ void opj_aligned_free(void* ptr) #else /* Generic implementation has malloced pointer stored in front of used area */ if (ptr != NULL) { - free(((void**) ptr)[-1]); + free(((void **) ptr)[-1]); } #endif } -void * opj_realloc(void *ptr, size_t new_size) -{ +void *opj_realloc(void *ptr, size_t new_size) { if (new_size == 0U) { /* prevent implementation defined behavior of realloc */ return NULL; } return realloc(ptr, new_size); } -void opj_free(void *ptr) -{ +void opj_free(void *ptr) { free(ptr); } diff --git a/client/deps/openjpeg/opj_malloc.h b/client/deps/openjpeg/opj_malloc.h index cbc4106c7..e66876fe3 100644 --- a/client/deps/openjpeg/opj_malloc.h +++ b/client/deps/openjpeg/opj_malloc.h @@ -52,7 +52,7 @@ Allocate an uninitialized memory block @param size Bytes to allocate @return Returns a void pointer to the allocated space, or NULL if there is insufficient memory available */ -void * opj_malloc(size_t size); +void *opj_malloc(size_t size); /** Allocate a memory block with elements initialized to 0 @@ -60,24 +60,24 @@ Allocate a memory block with elements initialized to 0 @param sizeOfElements Bytes per block to allocate @return Returns a void pointer to the allocated space, or NULL if there is insufficient memory available */ -void * opj_calloc(size_t numOfElements, size_t sizeOfElements); +void *opj_calloc(size_t numOfElements, size_t sizeOfElements); /** Allocate memory aligned to a 16 byte boundary @param size Bytes to allocate @return Returns a void pointer to the allocated space, or NULL if there is insufficient memory available */ -void * opj_aligned_malloc(size_t size); -void * opj_aligned_realloc(void *ptr, size_t size); -void opj_aligned_free(void* ptr); +void *opj_aligned_malloc(size_t size); +void *opj_aligned_realloc(void *ptr, size_t size); +void opj_aligned_free(void *ptr); /** Allocate memory aligned to a 32 byte boundary @param size Bytes to allocate @return Returns a void pointer to the allocated space, or NULL if there is insufficient memory available */ -void * opj_aligned_32_malloc(size_t size); -void * opj_aligned_32_realloc(void *ptr, size_t size); +void *opj_aligned_32_malloc(size_t size); +void *opj_aligned_32_realloc(void *ptr, size_t size); /** Reallocate memory blocks. @@ -85,13 +85,13 @@ Reallocate memory blocks. @param s New size in bytes @return Returns a void pointer to the reallocated (and possibly moved) memory block */ -void * opj_realloc(void * m, size_t s); +void *opj_realloc(void *m, size_t s); /** Deallocates or frees a memory block. @param m Previously allocated memory block to be freed */ -void opj_free(void * m); +void opj_free(void *m); #if defined(__GNUC__) && !defined(OPJ_SKIP_POISON) #pragma GCC poison malloc calloc realloc free diff --git a/client/deps/openjpeg/pi.c b/client/deps/openjpeg/pi.c index 15ac33142..91fc87f9a 100644 --- a/client/deps/openjpeg/pi.c +++ b/client/deps/openjpeg/pi.c @@ -51,31 +51,31 @@ Get next packet in layer-resolution-component-precinct order. @param pi packet iterator to modify @return returns false if pi pointed to the last packet or else returns true */ -static OPJ_BOOL opj_pi_next_lrcp(opj_pi_iterator_t * pi); +static OPJ_BOOL opj_pi_next_lrcp(opj_pi_iterator_t *pi); /** Get next packet in resolution-layer-component-precinct order. @param pi packet iterator to modify @return returns false if pi pointed to the last packet or else returns true */ -static OPJ_BOOL opj_pi_next_rlcp(opj_pi_iterator_t * pi); +static OPJ_BOOL opj_pi_next_rlcp(opj_pi_iterator_t *pi); /** Get next packet in resolution-precinct-component-layer order. @param pi packet iterator to modify @return returns false if pi pointed to the last packet or else returns true */ -static OPJ_BOOL opj_pi_next_rpcl(opj_pi_iterator_t * pi); +static OPJ_BOOL opj_pi_next_rpcl(opj_pi_iterator_t *pi); /** Get next packet in precinct-component-resolution-layer order. @param pi packet iterator to modify @return returns false if pi pointed to the last packet or else returns true */ -static OPJ_BOOL opj_pi_next_pcrl(opj_pi_iterator_t * pi); +static OPJ_BOOL opj_pi_next_pcrl(opj_pi_iterator_t *pi); /** Get next packet in component-precinct-resolution-layer order. @param pi packet iterator to modify @return returns false if pi pointed to the last packet or else returns true */ -static OPJ_BOOL opj_pi_next_cprl(opj_pi_iterator_t * pi); +static OPJ_BOOL opj_pi_next_cprl(opj_pi_iterator_t *pi); /** * Updates the coding parameters if the encoding is used with Progression order changes and final (or cinema parameters are used). @@ -92,15 +92,15 @@ static OPJ_BOOL opj_pi_next_cprl(opj_pi_iterator_t * pi); * @param p_dy_min the minimum dy of all the components of all the resolutions for the tile. */ static void opj_pi_update_encode_poc_and_final(opj_cp_t *p_cp, - OPJ_UINT32 p_tileno, - OPJ_UINT32 p_tx0, - OPJ_UINT32 p_tx1, - OPJ_UINT32 p_ty0, - OPJ_UINT32 p_ty1, - OPJ_UINT32 p_max_prec, - OPJ_UINT32 p_max_res, - OPJ_UINT32 p_dx_min, - OPJ_UINT32 p_dy_min); + OPJ_UINT32 p_tileno, + OPJ_UINT32 p_tx0, + OPJ_UINT32 p_tx1, + OPJ_UINT32 p_ty0, + OPJ_UINT32 p_ty1, + OPJ_UINT32 p_max_prec, + OPJ_UINT32 p_max_res, + OPJ_UINT32 p_dx_min, + OPJ_UINT32 p_dy_min); /** * Updates the coding parameters if the encoding is not used with Progression order changes and final (and cinema parameters are used). @@ -118,16 +118,16 @@ static void opj_pi_update_encode_poc_and_final(opj_cp_t *p_cp, * @param p_dy_min the minimum dy of all the components of all the resolutions for the tile. */ static void opj_pi_update_encode_not_poc(opj_cp_t *p_cp, - OPJ_UINT32 p_num_comps, - OPJ_UINT32 p_tileno, - OPJ_UINT32 p_tx0, - OPJ_UINT32 p_tx1, - OPJ_UINT32 p_ty0, - OPJ_UINT32 p_ty1, - OPJ_UINT32 p_max_prec, - OPJ_UINT32 p_max_res, - OPJ_UINT32 p_dx_min, - OPJ_UINT32 p_dy_min); + OPJ_UINT32 p_num_comps, + OPJ_UINT32 p_tileno, + OPJ_UINT32 p_tx0, + OPJ_UINT32 p_tx1, + OPJ_UINT32 p_ty0, + OPJ_UINT32 p_ty1, + OPJ_UINT32 p_max_prec, + OPJ_UINT32 p_max_res, + OPJ_UINT32 p_dx_min, + OPJ_UINT32 p_dy_min); /** * Gets the encoding parameters needed to update the coding parameters and all the pocs. * @@ -146,14 +146,14 @@ static void opj_pi_update_encode_not_poc(opj_cp_t *p_cp, static void opj_get_encoding_parameters(const opj_image_t *p_image, const opj_cp_t *p_cp, OPJ_UINT32 tileno, - OPJ_UINT32 * p_tx0, - OPJ_UINT32 * p_tx1, - OPJ_UINT32 * p_ty0, - OPJ_UINT32 * p_ty1, - OPJ_UINT32 * p_dx_min, - OPJ_UINT32 * p_dy_min, - OPJ_UINT32 * p_max_prec, - OPJ_UINT32 * p_max_res); + OPJ_UINT32 *p_tx0, + OPJ_UINT32 *p_tx1, + OPJ_UINT32 *p_ty0, + OPJ_UINT32 *p_ty1, + OPJ_UINT32 *p_dx_min, + OPJ_UINT32 *p_dy_min, + OPJ_UINT32 *p_max_prec, + OPJ_UINT32 *p_max_res); /** * Gets the encoding parameters needed to update the coding parameters and all the pocs. @@ -176,17 +176,17 @@ static void opj_get_encoding_parameters(const opj_image_t *p_image, * @param p_resolutions pointer to an area corresponding to the one described above. */ static void opj_get_all_encoding_parameters(const opj_image_t *p_image, - const opj_cp_t *p_cp, - OPJ_UINT32 tileno, - OPJ_UINT32 * p_tx0, - OPJ_UINT32 * p_tx1, - OPJ_UINT32 * p_ty0, - OPJ_UINT32 * p_ty1, - OPJ_UINT32 * p_dx_min, - OPJ_UINT32 * p_dy_min, - OPJ_UINT32 * p_max_prec, - OPJ_UINT32 * p_max_res, - OPJ_UINT32 ** p_resolutions); + const opj_cp_t *p_cp, + OPJ_UINT32 tileno, + OPJ_UINT32 *p_tx0, + OPJ_UINT32 *p_tx1, + OPJ_UINT32 *p_ty0, + OPJ_UINT32 *p_ty1, + OPJ_UINT32 *p_dx_min, + OPJ_UINT32 *p_dy_min, + OPJ_UINT32 *p_max_prec, + OPJ_UINT32 *p_max_res, + OPJ_UINT32 **p_resolutions); /** * Allocates memory for a packet iterator. Data and data sizes are set by this operation. * No other data is set. The include section of the packet iterator is not allocated. @@ -196,22 +196,22 @@ static void opj_get_all_encoding_parameters(const opj_image_t *p_image, * @param tileno the index of the tile from which creating the packet iterator. * @param manager Event manager */ -static opj_pi_iterator_t * opj_pi_create(const opj_image_t *p_image, - const opj_cp_t *p_cp, - OPJ_UINT32 tileno, - opj_event_mgr_t* manager); +static opj_pi_iterator_t *opj_pi_create(const opj_image_t *p_image, + const opj_cp_t *p_cp, + OPJ_UINT32 tileno, + opj_event_mgr_t *manager); /** * FIXME DOC */ -static void opj_pi_update_decode_not_poc(opj_pi_iterator_t * p_pi, - opj_tcp_t * p_tcp, - OPJ_UINT32 p_max_precision, - OPJ_UINT32 p_max_res); +static void opj_pi_update_decode_not_poc(opj_pi_iterator_t *p_pi, + opj_tcp_t *p_tcp, + OPJ_UINT32 p_max_precision, + OPJ_UINT32 p_max_res); /** * FIXME DOC */ -static void opj_pi_update_decode_poc(opj_pi_iterator_t * p_pi, - opj_tcp_t * p_tcp, +static void opj_pi_update_decode_poc(opj_pi_iterator_t *p_pi, + opj_tcp_t *p_tcp, OPJ_UINT32 p_max_precision, OPJ_UINT32 p_max_res); @@ -234,8 +234,7 @@ static OPJ_BOOL opj_pi_check_next_level(OPJ_INT32 pos, ========================================================== */ -static OPJ_BOOL opj_pi_next_lrcp(opj_pi_iterator_t * pi) -{ +static OPJ_BOOL opj_pi_next_lrcp(opj_pi_iterator_t *pi) { opj_pi_comp_t *comp = NULL; opj_pi_resolution_t *res = NULL; OPJ_UINT32 index = 0; @@ -294,8 +293,7 @@ LABEL_SKIP: return OPJ_FALSE; } -static OPJ_BOOL opj_pi_next_rlcp(opj_pi_iterator_t * pi) -{ +static OPJ_BOOL opj_pi_next_rlcp(opj_pi_iterator_t *pi) { opj_pi_comp_t *comp = NULL; opj_pi_resolution_t *res = NULL; OPJ_UINT32 index = 0; @@ -347,8 +345,7 @@ LABEL_SKIP: return OPJ_FALSE; } -static OPJ_BOOL opj_pi_next_rpcl(opj_pi_iterator_t * pi) -{ +static OPJ_BOOL opj_pi_next_rpcl(opj_pi_iterator_t *pi) { opj_pi_comp_t *comp = NULL; opj_pi_resolution_t *res = NULL; OPJ_UINT32 index = 0; @@ -454,10 +451,10 @@ static OPJ_BOOL opj_pi_next_rpcl(opj_pi_iterator_t * pi) } prci = opj_uint_floordivpow2(opj_uint64_ceildiv_res_uint32((OPJ_UINT64)pi->x, - ((OPJ_UINT64)comp->dx << levelno)), res->pdx) + ((OPJ_UINT64)comp->dx << levelno)), res->pdx) - opj_uint_floordivpow2(trx0, res->pdx); prcj = opj_uint_floordivpow2(opj_uint64_ceildiv_res_uint32((OPJ_UINT64)pi->y, - ((OPJ_UINT64)comp->dy << levelno)), res->pdy) + ((OPJ_UINT64)comp->dy << levelno)), res->pdy) - opj_uint_floordivpow2(try0, res->pdy); pi->precno = prci + prcj * res->pw; for (pi->layno = pi->poc.layno0; pi->layno < pi->poc.layno1; pi->layno++) { @@ -482,8 +479,7 @@ LABEL_SKIP: return OPJ_FALSE; } -static OPJ_BOOL opj_pi_next_pcrl(opj_pi_iterator_t * pi) -{ +static OPJ_BOOL opj_pi_next_pcrl(opj_pi_iterator_t *pi) { opj_pi_comp_t *comp = NULL; opj_pi_resolution_t *res = NULL; OPJ_UINT32 index = 0; @@ -588,10 +584,10 @@ static OPJ_BOOL opj_pi_next_pcrl(opj_pi_iterator_t * pi) } prci = opj_uint_floordivpow2(opj_uint64_ceildiv_res_uint32((OPJ_UINT64)pi->x, - ((OPJ_UINT64)comp->dx << levelno)), res->pdx) + ((OPJ_UINT64)comp->dx << levelno)), res->pdx) - opj_uint_floordivpow2(trx0, res->pdx); prcj = opj_uint_floordivpow2(opj_uint64_ceildiv_res_uint32((OPJ_UINT64)pi->y, - ((OPJ_UINT64)comp->dy << levelno)), res->pdy) + ((OPJ_UINT64)comp->dy << levelno)), res->pdy) - opj_uint_floordivpow2(try0, res->pdy); pi->precno = prci + prcj * res->pw; for (pi->layno = pi->poc.layno0; pi->layno < pi->poc.layno1; pi->layno++) { @@ -616,8 +612,7 @@ LABEL_SKIP: return OPJ_FALSE; } -static OPJ_BOOL opj_pi_next_cprl(opj_pi_iterator_t * pi) -{ +static OPJ_BOOL opj_pi_next_cprl(opj_pi_iterator_t *pi) { opj_pi_comp_t *comp = NULL; opj_pi_resolution_t *res = NULL; OPJ_UINT32 index = 0; @@ -720,10 +715,10 @@ static OPJ_BOOL opj_pi_next_cprl(opj_pi_iterator_t * pi) } prci = opj_uint_floordivpow2(opj_uint64_ceildiv_res_uint32((OPJ_UINT64)pi->x, - ((OPJ_UINT64)comp->dx << levelno)), res->pdx) + ((OPJ_UINT64)comp->dx << levelno)), res->pdx) - opj_uint_floordivpow2(trx0, res->pdx); prcj = opj_uint_floordivpow2(opj_uint64_ceildiv_res_uint32((OPJ_UINT64)pi->y, - ((OPJ_UINT64)comp->dy << levelno)), res->pdy) + ((OPJ_UINT64)comp->dy << levelno)), res->pdy) - opj_uint_floordivpow2(try0, res->pdy); pi->precno = (OPJ_UINT32)(prci + prcj * res->pw); for (pi->layno = pi->poc.layno0; pi->layno < pi->poc.layno1; pi->layno++) { @@ -751,21 +746,20 @@ LABEL_SKIP: static void opj_get_encoding_parameters(const opj_image_t *p_image, const opj_cp_t *p_cp, OPJ_UINT32 p_tileno, - OPJ_UINT32 * p_tx0, - OPJ_UINT32 * p_tx1, - OPJ_UINT32 * p_ty0, - OPJ_UINT32 * p_ty1, - OPJ_UINT32 * p_dx_min, - OPJ_UINT32 * p_dy_min, - OPJ_UINT32 * p_max_prec, - OPJ_UINT32 * p_max_res) -{ + OPJ_UINT32 *p_tx0, + OPJ_UINT32 *p_tx1, + OPJ_UINT32 *p_ty0, + OPJ_UINT32 *p_ty1, + OPJ_UINT32 *p_dx_min, + OPJ_UINT32 *p_dy_min, + OPJ_UINT32 *p_max_prec, + OPJ_UINT32 *p_max_res) { /* loop */ OPJ_UINT32 compno, resno; /* pointers */ const opj_tcp_t *l_tcp = 00; - const opj_tccp_t * l_tccp = 00; - const opj_image_comp_t * l_img_comp = 00; + const opj_tccp_t *l_tccp = 00; + const opj_image_comp_t *l_img_comp = 00; /* position in x and y of tile */ OPJ_UINT32 p, q; @@ -833,9 +827,9 @@ static void opj_get_encoding_parameters(const opj_image_t *p_image, l_pdy = l_tccp->prch[resno]; l_dx = l_img_comp->dx * ((OPJ_UINT64)1u << (l_pdx + l_tccp->numresolutions - 1 - - resno)); + resno)); l_dy = l_img_comp->dy * ((OPJ_UINT64)1u << (l_pdy + l_tccp->numresolutions - 1 - - resno)); + resno)); /* take the minimum size for dx for each comp and resolution */ if (l_dx <= UINT_MAX) { @@ -876,28 +870,27 @@ static void opj_get_encoding_parameters(const opj_image_t *p_image, static void opj_get_all_encoding_parameters(const opj_image_t *p_image, - const opj_cp_t *p_cp, - OPJ_UINT32 tileno, - OPJ_UINT32 * p_tx0, - OPJ_UINT32 * p_tx1, - OPJ_UINT32 * p_ty0, - OPJ_UINT32 * p_ty1, - OPJ_UINT32 * p_dx_min, - OPJ_UINT32 * p_dy_min, - OPJ_UINT32 * p_max_prec, - OPJ_UINT32 * p_max_res, - OPJ_UINT32 ** p_resolutions) -{ + const opj_cp_t *p_cp, + OPJ_UINT32 tileno, + OPJ_UINT32 *p_tx0, + OPJ_UINT32 *p_tx1, + OPJ_UINT32 *p_ty0, + OPJ_UINT32 *p_ty1, + OPJ_UINT32 *p_dx_min, + OPJ_UINT32 *p_dy_min, + OPJ_UINT32 *p_max_prec, + OPJ_UINT32 *p_max_res, + OPJ_UINT32 **p_resolutions) { /* loop*/ OPJ_UINT32 compno, resno; /* pointers*/ const opj_tcp_t *tcp = 00; - const opj_tccp_t * l_tccp = 00; - const opj_image_comp_t * l_img_comp = 00; + const opj_tccp_t *l_tccp = 00; + const opj_image_comp_t *l_img_comp = 00; /* to store l_dx, l_dy, w and h for each resolution and component.*/ - OPJ_UINT32 * lResolutionPtr; + OPJ_UINT32 *lResolutionPtr; /* position in x and y of tile*/ OPJ_UINT32 p, q; @@ -1011,11 +1004,10 @@ static void opj_get_all_encoding_parameters(const opj_image_t *p_image, } } -static opj_pi_iterator_t * opj_pi_create(const opj_image_t *image, - const opj_cp_t *cp, - OPJ_UINT32 tileno, - opj_event_mgr_t* manager) -{ +static opj_pi_iterator_t *opj_pi_create(const opj_image_t *image, + const opj_cp_t *cp, + OPJ_UINT32 tileno, + opj_event_mgr_t *manager) { /* loop*/ OPJ_UINT32 pino, compno; /* number of poc in the p_pi*/ @@ -1039,8 +1031,8 @@ static opj_pi_iterator_t * opj_pi_create(const opj_image_t *image, l_poc_bound = tcp->numpocs + 1; /* memory allocations*/ - l_pi = (opj_pi_iterator_t*) opj_calloc((l_poc_bound), - sizeof(opj_pi_iterator_t)); + l_pi = (opj_pi_iterator_t *) opj_calloc((l_poc_bound), + sizeof(opj_pi_iterator_t)); if (!l_pi) { return NULL; } @@ -1050,8 +1042,8 @@ static opj_pi_iterator_t * opj_pi_create(const opj_image_t *image, l_current_pi->manager = manager; - l_current_pi->comps = (opj_pi_comp_t*) opj_calloc(image->numcomps, - sizeof(opj_pi_comp_t)); + l_current_pi->comps = (opj_pi_comp_t *) opj_calloc(image->numcomps, + sizeof(opj_pi_comp_t)); if (! l_current_pi->comps) { opj_pi_destroy(l_pi, l_poc_bound); return NULL; @@ -1064,8 +1056,8 @@ static opj_pi_iterator_t * opj_pi_create(const opj_image_t *image, tccp = &tcp->tccps[compno]; - comp->resolutions = (opj_pi_resolution_t*) opj_calloc(tccp->numresolutions, - sizeof(opj_pi_resolution_t)); + comp->resolutions = (opj_pi_resolution_t *) opj_calloc(tccp->numresolutions, + sizeof(opj_pi_resolution_t)); if (!comp->resolutions) { opj_pi_destroy(l_pi, l_poc_bound); return 00; @@ -1079,22 +1071,21 @@ static opj_pi_iterator_t * opj_pi_create(const opj_image_t *image, } static void opj_pi_update_encode_poc_and_final(opj_cp_t *p_cp, - OPJ_UINT32 p_tileno, - OPJ_UINT32 p_tx0, - OPJ_UINT32 p_tx1, - OPJ_UINT32 p_ty0, - OPJ_UINT32 p_ty1, - OPJ_UINT32 p_max_prec, - OPJ_UINT32 p_max_res, - OPJ_UINT32 p_dx_min, - OPJ_UINT32 p_dy_min) -{ + OPJ_UINT32 p_tileno, + OPJ_UINT32 p_tx0, + OPJ_UINT32 p_tx1, + OPJ_UINT32 p_ty0, + OPJ_UINT32 p_ty1, + OPJ_UINT32 p_max_prec, + OPJ_UINT32 p_max_res, + OPJ_UINT32 p_dx_min, + OPJ_UINT32 p_dy_min) { /* loop*/ OPJ_UINT32 pino; /* tile coding parameter*/ opj_tcp_t *l_tcp = 00; /* current poc being updated*/ - opj_poc_t * l_current_poc = 00; + opj_poc_t *l_current_poc = 00; /* number of pocs*/ OPJ_UINT32 l_poc_bound; @@ -1158,23 +1149,22 @@ static void opj_pi_update_encode_poc_and_final(opj_cp_t *p_cp, } static void opj_pi_update_encode_not_poc(opj_cp_t *p_cp, - OPJ_UINT32 p_num_comps, - OPJ_UINT32 p_tileno, - OPJ_UINT32 p_tx0, - OPJ_UINT32 p_tx1, - OPJ_UINT32 p_ty0, - OPJ_UINT32 p_ty1, - OPJ_UINT32 p_max_prec, - OPJ_UINT32 p_max_res, - OPJ_UINT32 p_dx_min, - OPJ_UINT32 p_dy_min) -{ + OPJ_UINT32 p_num_comps, + OPJ_UINT32 p_tileno, + OPJ_UINT32 p_tx0, + OPJ_UINT32 p_tx1, + OPJ_UINT32 p_ty0, + OPJ_UINT32 p_ty1, + OPJ_UINT32 p_max_prec, + OPJ_UINT32 p_max_res, + OPJ_UINT32 p_dx_min, + OPJ_UINT32 p_dy_min) { /* loop*/ OPJ_UINT32 pino; /* tile coding parameter*/ opj_tcp_t *l_tcp = 00; /* current poc being updated*/ - opj_poc_t * l_current_poc = 00; + opj_poc_t *l_current_poc = 00; /* number of pocs*/ OPJ_UINT32 l_poc_bound; @@ -1212,19 +1202,18 @@ static void opj_pi_update_encode_not_poc(opj_cp_t *p_cp, } } -static void opj_pi_update_decode_poc(opj_pi_iterator_t * p_pi, - opj_tcp_t * p_tcp, +static void opj_pi_update_decode_poc(opj_pi_iterator_t *p_pi, + opj_tcp_t *p_tcp, OPJ_UINT32 p_max_precision, - OPJ_UINT32 p_max_res) -{ + OPJ_UINT32 p_max_res) { /* loop*/ OPJ_UINT32 pino; /* encoding parameters to set*/ OPJ_UINT32 l_bound; - opj_pi_iterator_t * l_current_pi = 00; - opj_poc_t* l_current_poc = 0; + opj_pi_iterator_t *l_current_pi = 00; + opj_poc_t *l_current_poc = 0; OPJ_ARG_NOT_USED(p_max_res); @@ -1259,18 +1248,17 @@ static void opj_pi_update_decode_poc(opj_pi_iterator_t * p_pi, } } -static void opj_pi_update_decode_not_poc(opj_pi_iterator_t * p_pi, - opj_tcp_t * p_tcp, - OPJ_UINT32 p_max_precision, - OPJ_UINT32 p_max_res) -{ +static void opj_pi_update_decode_not_poc(opj_pi_iterator_t *p_pi, + opj_tcp_t *p_tcp, + OPJ_UINT32 p_max_precision, + OPJ_UINT32 p_max_res) { /* loop*/ OPJ_UINT32 pino; /* encoding parameters to set*/ OPJ_UINT32 l_bound; - opj_pi_iterator_t * l_current_pi = 00; + opj_pi_iterator_t *l_current_pi = 00; /* preconditions in debug*/ assert(p_tcp != 00); assert(p_pi != 00); @@ -1300,8 +1288,7 @@ static OPJ_BOOL opj_pi_check_next_level(OPJ_INT32 pos, opj_cp_t *cp, OPJ_UINT32 tileno, OPJ_UINT32 pino, - const OPJ_CHAR *prog) -{ + const OPJ_CHAR *prog) { OPJ_INT32 i; opj_tcp_t *tcps = &cp->tcps[tileno]; opj_poc_t *tcp = &tcps->pocs[pino]; @@ -1309,45 +1296,9 @@ static OPJ_BOOL opj_pi_check_next_level(OPJ_INT32 pos, if (pos >= 0) { for (i = pos; i >= 0; i--) { switch (prog[i]) { - case 'R': - if (tcp->res_t == tcp->resE) { - if (opj_pi_check_next_level(pos - 1, cp, tileno, pino, prog)) { - return OPJ_TRUE; - } else { - return OPJ_FALSE; - } - } else { - return OPJ_TRUE; - } - break; - case 'C': - if (tcp->comp_t == tcp->compE) { - if (opj_pi_check_next_level(pos - 1, cp, tileno, pino, prog)) { - return OPJ_TRUE; - } else { - return OPJ_FALSE; - } - } else { - return OPJ_TRUE; - } - break; - case 'L': - if (tcp->lay_t == tcp->layE) { - if (opj_pi_check_next_level(pos - 1, cp, tileno, pino, prog)) { - return OPJ_TRUE; - } else { - return OPJ_FALSE; - } - } else { - return OPJ_TRUE; - } - break; - case 'P': - switch (tcp->prg) { - case OPJ_LRCP: /* fall through */ - case OPJ_RLCP: - if (tcp->prc_t == tcp->prcE) { - if (opj_pi_check_next_level(i - 1, cp, tileno, pino, prog)) { + case 'R': + if (tcp->res_t == tcp->resE) { + if (opj_pi_check_next_level(pos - 1, cp, tileno, pino, prog)) { return OPJ_TRUE; } else { return OPJ_FALSE; @@ -1356,23 +1307,59 @@ static OPJ_BOOL opj_pi_check_next_level(OPJ_INT32 pos, return OPJ_TRUE; } break; - default: - if (tcp->tx0_t == tcp->txE) { - /*TY*/ - if (tcp->ty0_t == tcp->tyE) { - if (opj_pi_check_next_level(i - 1, cp, tileno, pino, prog)) { - return OPJ_TRUE; - } else { - return OPJ_FALSE; - } - } else { + case 'C': + if (tcp->comp_t == tcp->compE) { + if (opj_pi_check_next_level(pos - 1, cp, tileno, pino, prog)) { return OPJ_TRUE; - }/*TY*/ + } else { + return OPJ_FALSE; + } } else { return OPJ_TRUE; } break; - }/*end case P*/ + case 'L': + if (tcp->lay_t == tcp->layE) { + if (opj_pi_check_next_level(pos - 1, cp, tileno, pino, prog)) { + return OPJ_TRUE; + } else { + return OPJ_FALSE; + } + } else { + return OPJ_TRUE; + } + break; + case 'P': + switch (tcp->prg) { + case OPJ_LRCP: /* fall through */ + case OPJ_RLCP: + if (tcp->prc_t == tcp->prcE) { + if (opj_pi_check_next_level(i - 1, cp, tileno, pino, prog)) { + return OPJ_TRUE; + } else { + return OPJ_FALSE; + } + } else { + return OPJ_TRUE; + } + break; + default: + if (tcp->tx0_t == tcp->txE) { + /*TY*/ + if (tcp->ty0_t == tcp->tyE) { + if (opj_pi_check_next_level(i - 1, cp, tileno, pino, prog)) { + return OPJ_TRUE; + } else { + return OPJ_FALSE; + } + } else { + return OPJ_TRUE; + }/*TY*/ + } else { + return OPJ_TRUE; + } + break; + }/*end case P*/ }/*end switch*/ }/*end for*/ }/*end if*/ @@ -1388,8 +1375,7 @@ static OPJ_BOOL opj_pi_check_next_level(OPJ_INT32 pos, opj_pi_iterator_t *opj_pi_create_decode(opj_image_t *p_image, opj_cp_t *p_cp, OPJ_UINT32 p_tile_no, - opj_event_mgr_t* manager) -{ + opj_event_mgr_t *manager) { OPJ_UINT32 numcomps = p_image->numcomps; /* loop */ @@ -1397,8 +1383,8 @@ opj_pi_iterator_t *opj_pi_create_decode(opj_image_t *p_image, OPJ_UINT32 compno, resno; /* to store w, h, dx and dy for all components and resolutions */ - OPJ_UINT32 * l_tmp_data; - OPJ_UINT32 ** l_tmp_ptr; + OPJ_UINT32 *l_tmp_data; + OPJ_UINT32 **l_tmp_ptr; /* encoding parameters to set */ OPJ_UINT32 l_max_res; @@ -1414,9 +1400,9 @@ opj_pi_iterator_t *opj_pi_create_decode(opj_image_t *p_image, opj_tcp_t *l_tcp = 00; const opj_tccp_t *l_tccp = 00; opj_pi_comp_t *l_current_comp = 00; - opj_image_comp_t * l_img_comp = 00; - opj_pi_iterator_t * l_current_pi = 00; - OPJ_UINT32 * l_encoding_value_ptr = 00; + opj_image_comp_t *l_img_comp = 00; + opj_pi_iterator_t *l_current_pi = 00; + OPJ_UINT32 *l_encoding_value_ptr = 00; /* preconditions in debug */ assert(p_cp != 00); @@ -1428,13 +1414,13 @@ opj_pi_iterator_t *opj_pi_create_decode(opj_image_t *p_image, l_bound = l_tcp->numpocs + 1; l_data_stride = 4 * OPJ_J2K_MAXRLVLS; - l_tmp_data = (OPJ_UINT32*)opj_malloc( + l_tmp_data = (OPJ_UINT32 *)opj_malloc( l_data_stride * numcomps * sizeof(OPJ_UINT32)); if (! l_tmp_data) { return 00; } - l_tmp_ptr = (OPJ_UINT32**)opj_malloc( + l_tmp_ptr = (OPJ_UINT32 **)opj_malloc( numcomps * sizeof(OPJ_UINT32 *)); if (! l_tmp_ptr) { @@ -1476,7 +1462,7 @@ opj_pi_iterator_t *opj_pi_create_decode(opj_image_t *p_image, l_current_pi->include = 00; if (l_step_l <= (UINT_MAX / (l_tcp->numlayers + 1U))) { l_current_pi->include_size = (l_tcp->numlayers + 1U) * l_step_l; - l_current_pi->include = (OPJ_INT16*) opj_calloc( + l_current_pi->include = (OPJ_INT16 *) opj_calloc( l_current_pi->include_size, sizeof(OPJ_INT16)); } @@ -1585,9 +1571,8 @@ opj_pi_iterator_t *opj_pi_create_decode(opj_image_t *p_image, OPJ_UINT32 opj_get_encoding_packet_count(const opj_image_t *p_image, - const opj_cp_t *p_cp, - OPJ_UINT32 p_tile_no) -{ + const opj_cp_t *p_cp, + OPJ_UINT32 p_tile_no) { OPJ_UINT32 l_max_res; OPJ_UINT32 l_max_prec; OPJ_UINT32 l_tx0, l_tx1, l_ty0, l_ty1; @@ -1608,11 +1593,10 @@ OPJ_UINT32 opj_get_encoding_packet_count(const opj_image_t *p_image, opj_pi_iterator_t *opj_pi_initialise_encode(const opj_image_t *p_image, - opj_cp_t *p_cp, - OPJ_UINT32 p_tile_no, - J2K_T2_MODE p_t2_mode, - opj_event_mgr_t* manager) -{ + opj_cp_t *p_cp, + OPJ_UINT32 p_tile_no, + J2K_T2_MODE p_t2_mode, + opj_event_mgr_t *manager) { OPJ_UINT32 numcomps = p_image->numcomps; /* loop*/ @@ -1620,8 +1604,8 @@ opj_pi_iterator_t *opj_pi_initialise_encode(const opj_image_t *p_image, OPJ_UINT32 compno, resno; /* to store w, h, dx and dy for all components and resolutions*/ - OPJ_UINT32 * l_tmp_data; - OPJ_UINT32 ** l_tmp_ptr; + OPJ_UINT32 *l_tmp_data; + OPJ_UINT32 **l_tmp_ptr; /* encoding parameters to set*/ OPJ_UINT32 l_max_res; @@ -1637,9 +1621,9 @@ opj_pi_iterator_t *opj_pi_initialise_encode(const opj_image_t *p_image, opj_tcp_t *l_tcp = 00; const opj_tccp_t *l_tccp = 00; opj_pi_comp_t *l_current_comp = 00; - opj_image_comp_t * l_img_comp = 00; - opj_pi_iterator_t * l_current_pi = 00; - OPJ_UINT32 * l_encoding_value_ptr = 00; + opj_image_comp_t *l_img_comp = 00; + opj_pi_iterator_t *l_current_pi = 00; + OPJ_UINT32 *l_encoding_value_ptr = 00; /* preconditions in debug*/ assert(p_cp != 00); @@ -1651,13 +1635,13 @@ opj_pi_iterator_t *opj_pi_initialise_encode(const opj_image_t *p_image, l_bound = l_tcp->numpocs + 1; l_data_stride = 4 * OPJ_J2K_MAXRLVLS; - l_tmp_data = (OPJ_UINT32*)opj_malloc( + l_tmp_data = (OPJ_UINT32 *)opj_malloc( l_data_stride * numcomps * sizeof(OPJ_UINT32)); if (! l_tmp_data) { return 00; } - l_tmp_ptr = (OPJ_UINT32**)opj_malloc( + l_tmp_ptr = (OPJ_UINT32 **)opj_malloc( numcomps * sizeof(OPJ_UINT32 *)); if (! l_tmp_ptr) { opj_free(l_tmp_data); @@ -1695,8 +1679,8 @@ opj_pi_iterator_t *opj_pi_initialise_encode(const opj_image_t *p_image, /* memory allocation for include*/ l_current_pi->include_size = l_tcp->numlayers * l_step_l; - l_current_pi->include = (OPJ_INT16*) opj_calloc(l_current_pi->include_size, - sizeof(OPJ_INT16)); + l_current_pi->include = (OPJ_INT16 *) opj_calloc(l_current_pi->include_size, + sizeof(OPJ_INT16)); if (!l_current_pi->include) { opj_free(l_tmp_data); opj_free(l_tmp_ptr); @@ -1806,8 +1790,7 @@ void opj_pi_create_encode(opj_pi_iterator_t *pi, OPJ_UINT32 pino, OPJ_UINT32 tpnum, OPJ_INT32 tppos, - J2K_T2_MODE t2_mode) -{ + J2K_T2_MODE t2_mode) { const OPJ_CHAR *prog; OPJ_INT32 i; OPJ_UINT32 incr_top = 1, resetX = 0; @@ -1820,8 +1803,8 @@ void opj_pi_create_encode(opj_pi_iterator_t *pi, pi[pino].poc.prg = tcp->prg; if (!(cp->m_specific_param.m_enc.m_tp_on && ((!OPJ_IS_CINEMA(cp->rsiz) && - !OPJ_IS_IMF(cp->rsiz) && - (t2_mode == FINAL_PASS)) || OPJ_IS_CINEMA(cp->rsiz) || OPJ_IS_IMF(cp->rsiz)))) { + !OPJ_IS_IMF(cp->rsiz) && + (t2_mode == FINAL_PASS)) || OPJ_IS_CINEMA(cp->rsiz) || OPJ_IS_IMF(cp->rsiz)))) { pi[pino].poc.resno0 = tcp->resS; pi[pino].poc.resno1 = tcp->resE; pi[pino].poc.compno0 = tcp->compS; @@ -1837,225 +1820,225 @@ void opj_pi_create_encode(opj_pi_iterator_t *pi, } else { for (i = tppos + 1; i < 4; i++) { switch (prog[i]) { - case 'R': - pi[pino].poc.resno0 = tcp->resS; - pi[pino].poc.resno1 = tcp->resE; - break; - case 'C': - pi[pino].poc.compno0 = tcp->compS; - pi[pino].poc.compno1 = tcp->compE; - break; - case 'L': - pi[pino].poc.layno0 = tcp->layS; - pi[pino].poc.layno1 = tcp->layE; - break; - case 'P': - switch (tcp->prg) { - case OPJ_LRCP: - case OPJ_RLCP: - pi[pino].poc.precno0 = tcp->prcS; - pi[pino].poc.precno1 = tcp->prcE; + case 'R': + pi[pino].poc.resno0 = tcp->resS; + pi[pino].poc.resno1 = tcp->resE; break; - default: - pi[pino].poc.tx0 = tcp->txS; - pi[pino].poc.ty0 = tcp->tyS; - pi[pino].poc.tx1 = tcp->txE; - pi[pino].poc.ty1 = tcp->tyE; + case 'C': + pi[pino].poc.compno0 = tcp->compS; + pi[pino].poc.compno1 = tcp->compE; + break; + case 'L': + pi[pino].poc.layno0 = tcp->layS; + pi[pino].poc.layno1 = tcp->layE; + break; + case 'P': + switch (tcp->prg) { + case OPJ_LRCP: + case OPJ_RLCP: + pi[pino].poc.precno0 = tcp->prcS; + pi[pino].poc.precno1 = tcp->prcE; + break; + default: + pi[pino].poc.tx0 = tcp->txS; + pi[pino].poc.ty0 = tcp->tyS; + pi[pino].poc.tx1 = tcp->txE; + pi[pino].poc.ty1 = tcp->tyE; + break; + } break; - } - break; } } if (tpnum == 0) { for (i = tppos; i >= 0; i--) { switch (prog[i]) { - case 'C': - tcp->comp_t = tcp->compS; - pi[pino].poc.compno0 = tcp->comp_t; - pi[pino].poc.compno1 = tcp->comp_t + 1; - tcp->comp_t += 1; - break; - case 'R': - tcp->res_t = tcp->resS; - pi[pino].poc.resno0 = tcp->res_t; - pi[pino].poc.resno1 = tcp->res_t + 1; - tcp->res_t += 1; - break; - case 'L': - tcp->lay_t = tcp->layS; - pi[pino].poc.layno0 = tcp->lay_t; - pi[pino].poc.layno1 = tcp->lay_t + 1; - tcp->lay_t += 1; - break; - case 'P': - switch (tcp->prg) { - case OPJ_LRCP: - case OPJ_RLCP: - tcp->prc_t = tcp->prcS; - pi[pino].poc.precno0 = tcp->prc_t; - pi[pino].poc.precno1 = tcp->prc_t + 1; - tcp->prc_t += 1; + case 'C': + tcp->comp_t = tcp->compS; + pi[pino].poc.compno0 = tcp->comp_t; + pi[pino].poc.compno1 = tcp->comp_t + 1; + tcp->comp_t += 1; break; - default: - tcp->tx0_t = tcp->txS; - tcp->ty0_t = tcp->tyS; - pi[pino].poc.tx0 = tcp->tx0_t; - pi[pino].poc.tx1 = tcp->tx0_t + tcp->dx - (tcp->tx0_t % tcp->dx); - pi[pino].poc.ty0 = tcp->ty0_t; - pi[pino].poc.ty1 = tcp->ty0_t + tcp->dy - (tcp->ty0_t % tcp->dy); - tcp->tx0_t = (OPJ_UINT32)pi[pino].poc.tx1; - tcp->ty0_t = (OPJ_UINT32)pi[pino].poc.ty1; + case 'R': + tcp->res_t = tcp->resS; + pi[pino].poc.resno0 = tcp->res_t; + pi[pino].poc.resno1 = tcp->res_t + 1; + tcp->res_t += 1; + break; + case 'L': + tcp->lay_t = tcp->layS; + pi[pino].poc.layno0 = tcp->lay_t; + pi[pino].poc.layno1 = tcp->lay_t + 1; + tcp->lay_t += 1; + break; + case 'P': + switch (tcp->prg) { + case OPJ_LRCP: + case OPJ_RLCP: + tcp->prc_t = tcp->prcS; + pi[pino].poc.precno0 = tcp->prc_t; + pi[pino].poc.precno1 = tcp->prc_t + 1; + tcp->prc_t += 1; + break; + default: + tcp->tx0_t = tcp->txS; + tcp->ty0_t = tcp->tyS; + pi[pino].poc.tx0 = tcp->tx0_t; + pi[pino].poc.tx1 = tcp->tx0_t + tcp->dx - (tcp->tx0_t % tcp->dx); + pi[pino].poc.ty0 = tcp->ty0_t; + pi[pino].poc.ty1 = tcp->ty0_t + tcp->dy - (tcp->ty0_t % tcp->dy); + tcp->tx0_t = (OPJ_UINT32)pi[pino].poc.tx1; + tcp->ty0_t = (OPJ_UINT32)pi[pino].poc.ty1; + break; + } break; - } - break; } } incr_top = 1; } else { for (i = tppos; i >= 0; i--) { switch (prog[i]) { - case 'C': - pi[pino].poc.compno0 = tcp->comp_t - 1; - pi[pino].poc.compno1 = tcp->comp_t; - break; - case 'R': - pi[pino].poc.resno0 = tcp->res_t - 1; - pi[pino].poc.resno1 = tcp->res_t; - break; - case 'L': - pi[pino].poc.layno0 = tcp->lay_t - 1; - pi[pino].poc.layno1 = tcp->lay_t; - break; - case 'P': - switch (tcp->prg) { - case OPJ_LRCP: - case OPJ_RLCP: - pi[pino].poc.precno0 = tcp->prc_t - 1; - pi[pino].poc.precno1 = tcp->prc_t; - break; - default: - pi[pino].poc.tx0 = tcp->tx0_t - tcp->dx - (tcp->tx0_t % tcp->dx); - pi[pino].poc.tx1 = tcp->tx0_t ; - pi[pino].poc.ty0 = tcp->ty0_t - tcp->dy - (tcp->ty0_t % tcp->dy); - pi[pino].poc.ty1 = tcp->ty0_t ; - break; - } - break; - } - if (incr_top == 1) { - switch (prog[i]) { - case 'R': - if (tcp->res_t == tcp->resE) { - if (opj_pi_check_next_level(i - 1, cp, tileno, pino, prog)) { - tcp->res_t = tcp->resS; - pi[pino].poc.resno0 = tcp->res_t; - pi[pino].poc.resno1 = tcp->res_t + 1; - tcp->res_t += 1; - incr_top = 1; - } else { - incr_top = 0; - } - } else { - pi[pino].poc.resno0 = tcp->res_t; - pi[pino].poc.resno1 = tcp->res_t + 1; - tcp->res_t += 1; - incr_top = 0; - } - break; case 'C': - if (tcp->comp_t == tcp->compE) { - if (opj_pi_check_next_level(i - 1, cp, tileno, pino, prog)) { - tcp->comp_t = tcp->compS; - pi[pino].poc.compno0 = tcp->comp_t; - pi[pino].poc.compno1 = tcp->comp_t + 1; - tcp->comp_t += 1; - incr_top = 1; - } else { - incr_top = 0; - } - } else { - pi[pino].poc.compno0 = tcp->comp_t; - pi[pino].poc.compno1 = tcp->comp_t + 1; - tcp->comp_t += 1; - incr_top = 0; - } + pi[pino].poc.compno0 = tcp->comp_t - 1; + pi[pino].poc.compno1 = tcp->comp_t; + break; + case 'R': + pi[pino].poc.resno0 = tcp->res_t - 1; + pi[pino].poc.resno1 = tcp->res_t; break; case 'L': - if (tcp->lay_t == tcp->layE) { - if (opj_pi_check_next_level(i - 1, cp, tileno, pino, prog)) { - tcp->lay_t = tcp->layS; - pi[pino].poc.layno0 = tcp->lay_t; - pi[pino].poc.layno1 = tcp->lay_t + 1; - tcp->lay_t += 1; - incr_top = 1; - } else { - incr_top = 0; - } - } else { - pi[pino].poc.layno0 = tcp->lay_t; - pi[pino].poc.layno1 = tcp->lay_t + 1; - tcp->lay_t += 1; - incr_top = 0; - } + pi[pino].poc.layno0 = tcp->lay_t - 1; + pi[pino].poc.layno1 = tcp->lay_t; break; case 'P': switch (tcp->prg) { - case OPJ_LRCP: - case OPJ_RLCP: - if (tcp->prc_t == tcp->prcE) { + case OPJ_LRCP: + case OPJ_RLCP: + pi[pino].poc.precno0 = tcp->prc_t - 1; + pi[pino].poc.precno1 = tcp->prc_t; + break; + default: + pi[pino].poc.tx0 = tcp->tx0_t - tcp->dx - (tcp->tx0_t % tcp->dx); + pi[pino].poc.tx1 = tcp->tx0_t ; + pi[pino].poc.ty0 = tcp->ty0_t - tcp->dy - (tcp->ty0_t % tcp->dy); + pi[pino].poc.ty1 = tcp->ty0_t ; + break; + } + break; + } + if (incr_top == 1) { + switch (prog[i]) { + case 'R': + if (tcp->res_t == tcp->resE) { if (opj_pi_check_next_level(i - 1, cp, tileno, pino, prog)) { - tcp->prc_t = tcp->prcS; - pi[pino].poc.precno0 = tcp->prc_t; - pi[pino].poc.precno1 = tcp->prc_t + 1; - tcp->prc_t += 1; + tcp->res_t = tcp->resS; + pi[pino].poc.resno0 = tcp->res_t; + pi[pino].poc.resno1 = tcp->res_t + 1; + tcp->res_t += 1; incr_top = 1; } else { incr_top = 0; } } else { - pi[pino].poc.precno0 = tcp->prc_t; - pi[pino].poc.precno1 = tcp->prc_t + 1; - tcp->prc_t += 1; + pi[pino].poc.resno0 = tcp->res_t; + pi[pino].poc.resno1 = tcp->res_t + 1; + tcp->res_t += 1; incr_top = 0; } break; - default: - if (tcp->tx0_t >= tcp->txE) { - if (tcp->ty0_t >= tcp->tyE) { - if (opj_pi_check_next_level(i - 1, cp, tileno, pino, prog)) { - tcp->ty0_t = tcp->tyS; - pi[pino].poc.ty0 = tcp->ty0_t; - pi[pino].poc.ty1 = tcp->ty0_t + tcp->dy - (tcp->ty0_t % tcp->dy); - tcp->ty0_t = (OPJ_UINT32)pi[pino].poc.ty1; - incr_top = 1; - resetX = 1; - } else { - incr_top = 0; - resetX = 0; - } + case 'C': + if (tcp->comp_t == tcp->compE) { + if (opj_pi_check_next_level(i - 1, cp, tileno, pino, prog)) { + tcp->comp_t = tcp->compS; + pi[pino].poc.compno0 = tcp->comp_t; + pi[pino].poc.compno1 = tcp->comp_t + 1; + tcp->comp_t += 1; + incr_top = 1; } else { - pi[pino].poc.ty0 = tcp->ty0_t; - pi[pino].poc.ty1 = tcp->ty0_t + tcp->dy - (tcp->ty0_t % tcp->dy); - tcp->ty0_t = (OPJ_UINT32)pi[pino].poc.ty1; incr_top = 0; - resetX = 1; - } - if (resetX == 1) { - tcp->tx0_t = tcp->txS; - pi[pino].poc.tx0 = tcp->tx0_t; - pi[pino].poc.tx1 = tcp->tx0_t + tcp->dx - (tcp->tx0_t % tcp->dx); - tcp->tx0_t = (OPJ_UINT32)pi[pino].poc.tx1; } } else { - pi[pino].poc.tx0 = tcp->tx0_t; - pi[pino].poc.tx1 = tcp->tx0_t + tcp->dx - (tcp->tx0_t % tcp->dx); - tcp->tx0_t = (OPJ_UINT32)pi[pino].poc.tx1; + pi[pino].poc.compno0 = tcp->comp_t; + pi[pino].poc.compno1 = tcp->comp_t + 1; + tcp->comp_t += 1; incr_top = 0; } break; - } - break; + case 'L': + if (tcp->lay_t == tcp->layE) { + if (opj_pi_check_next_level(i - 1, cp, tileno, pino, prog)) { + tcp->lay_t = tcp->layS; + pi[pino].poc.layno0 = tcp->lay_t; + pi[pino].poc.layno1 = tcp->lay_t + 1; + tcp->lay_t += 1; + incr_top = 1; + } else { + incr_top = 0; + } + } else { + pi[pino].poc.layno0 = tcp->lay_t; + pi[pino].poc.layno1 = tcp->lay_t + 1; + tcp->lay_t += 1; + incr_top = 0; + } + break; + case 'P': + switch (tcp->prg) { + case OPJ_LRCP: + case OPJ_RLCP: + if (tcp->prc_t == tcp->prcE) { + if (opj_pi_check_next_level(i - 1, cp, tileno, pino, prog)) { + tcp->prc_t = tcp->prcS; + pi[pino].poc.precno0 = tcp->prc_t; + pi[pino].poc.precno1 = tcp->prc_t + 1; + tcp->prc_t += 1; + incr_top = 1; + } else { + incr_top = 0; + } + } else { + pi[pino].poc.precno0 = tcp->prc_t; + pi[pino].poc.precno1 = tcp->prc_t + 1; + tcp->prc_t += 1; + incr_top = 0; + } + break; + default: + if (tcp->tx0_t >= tcp->txE) { + if (tcp->ty0_t >= tcp->tyE) { + if (opj_pi_check_next_level(i - 1, cp, tileno, pino, prog)) { + tcp->ty0_t = tcp->tyS; + pi[pino].poc.ty0 = tcp->ty0_t; + pi[pino].poc.ty1 = tcp->ty0_t + tcp->dy - (tcp->ty0_t % tcp->dy); + tcp->ty0_t = (OPJ_UINT32)pi[pino].poc.ty1; + incr_top = 1; + resetX = 1; + } else { + incr_top = 0; + resetX = 0; + } + } else { + pi[pino].poc.ty0 = tcp->ty0_t; + pi[pino].poc.ty1 = tcp->ty0_t + tcp->dy - (tcp->ty0_t % tcp->dy); + tcp->ty0_t = (OPJ_UINT32)pi[pino].poc.ty1; + incr_top = 0; + resetX = 1; + } + if (resetX == 1) { + tcp->tx0_t = tcp->txS; + pi[pino].poc.tx0 = tcp->tx0_t; + pi[pino].poc.tx1 = tcp->tx0_t + tcp->dx - (tcp->tx0_t % tcp->dx); + tcp->tx0_t = (OPJ_UINT32)pi[pino].poc.tx1; + } + } else { + pi[pino].poc.tx0 = tcp->tx0_t; + pi[pino].poc.tx1 = tcp->tx0_t + tcp->dx - (tcp->tx0_t % tcp->dx); + tcp->tx0_t = (OPJ_UINT32)pi[pino].poc.tx1; + incr_top = 0; + } + break; + } + break; } } } @@ -2064,8 +2047,7 @@ void opj_pi_create_encode(opj_pi_iterator_t *pi, } void opj_pi_destroy(opj_pi_iterator_t *p_pi, - OPJ_UINT32 p_nb_elements) -{ + OPJ_UINT32 p_nb_elements) { OPJ_UINT32 compno, pino; opj_pi_iterator_t *l_current_pi = p_pi; if (p_pi) { @@ -2097,8 +2079,7 @@ void opj_pi_destroy(opj_pi_iterator_t *p_pi, void opj_pi_update_encoding_parameters(const opj_image_t *p_image, opj_cp_t *p_cp, - OPJ_UINT32 p_tile_no) -{ + OPJ_UINT32 p_tile_no) { /* encoding parameters to set */ OPJ_UINT32 l_max_res; OPJ_UINT32 l_max_prec; @@ -2128,21 +2109,20 @@ void opj_pi_update_encoding_parameters(const opj_image_t *p_image, } } -OPJ_BOOL opj_pi_next(opj_pi_iterator_t * pi) -{ +OPJ_BOOL opj_pi_next(opj_pi_iterator_t *pi) { switch (pi->poc.prg) { - case OPJ_LRCP: - return opj_pi_next_lrcp(pi); - case OPJ_RLCP: - return opj_pi_next_rlcp(pi); - case OPJ_RPCL: - return opj_pi_next_rpcl(pi); - case OPJ_PCRL: - return opj_pi_next_pcrl(pi); - case OPJ_CPRL: - return opj_pi_next_cprl(pi); - case OPJ_PROG_UNKNOWN: - return OPJ_FALSE; + case OPJ_LRCP: + return opj_pi_next_lrcp(pi); + case OPJ_RLCP: + return opj_pi_next_rlcp(pi); + case OPJ_RPCL: + return opj_pi_next_rpcl(pi); + case OPJ_PCRL: + return opj_pi_next_pcrl(pi); + case OPJ_CPRL: + return opj_pi_next_cprl(pi); + case OPJ_PROG_UNKNOWN: + return OPJ_FALSE; } return OPJ_FALSE; diff --git a/client/deps/openjpeg/pi.h b/client/deps/openjpeg/pi.h index 0320523b7..736db89f2 100644 --- a/client/deps/openjpeg/pi.h +++ b/client/deps/openjpeg/pi.h @@ -108,7 +108,7 @@ typedef struct opj_pi_iterator { /** FIXME DOC*/ OPJ_UINT32 dx, dy; /** event manager */ - opj_event_mgr_t* manager; + opj_event_mgr_t *manager; } opj_pi_iterator_t; /** @name Exported functions */ @@ -126,10 +126,10 @@ typedef struct opj_pi_iterator { * @return a list of packet iterator that points to the first packet of the tile (not true). */ opj_pi_iterator_t *opj_pi_initialise_encode(const opj_image_t *image, - opj_cp_t *cp, - OPJ_UINT32 tileno, - J2K_T2_MODE t2_mode, - opj_event_mgr_t* manager); + opj_cp_t *cp, + OPJ_UINT32 tileno, + J2K_T2_MODE t2_mode, + opj_event_mgr_t *manager); /** * Updates the encoding parameters of the codec. @@ -169,10 +169,10 @@ Create a packet iterator for Decoder @return Returns a packet iterator that points to the first packet of the tile @see opj_pi_destroy */ -opj_pi_iterator_t *opj_pi_create_decode(opj_image_t * image, - opj_cp_t * cp, +opj_pi_iterator_t *opj_pi_create_decode(opj_image_t *image, + opj_cp_t *cp, OPJ_UINT32 tileno, - opj_event_mgr_t* manager); + opj_event_mgr_t *manager); /** * Destroys a packet iterator array. * @@ -187,7 +187,7 @@ Modify the packet iterator to point to the next packet @param pi Packet iterator to modify @return Returns false if pi pointed to the last packet or else returns true */ -OPJ_BOOL opj_pi_next(opj_pi_iterator_t * pi); +OPJ_BOOL opj_pi_next(opj_pi_iterator_t *pi); /** * Return the number of packets in the tile. @@ -196,8 +196,8 @@ OPJ_BOOL opj_pi_next(opj_pi_iterator_t * pi); * @param tileno Number that identifies the tile. */ OPJ_UINT32 opj_get_encoding_packet_count(const opj_image_t *p_image, - const opj_cp_t *p_cp, - OPJ_UINT32 p_tile_no); + const opj_cp_t *p_cp, + OPJ_UINT32 p_tile_no); /* ----------------------------------------------------------------------- */ /*@}*/ diff --git a/client/deps/openjpeg/sparse_array.c b/client/deps/openjpeg/sparse_array.c index 50d1a9041..ec0f25374 100644 --- a/client/deps/openjpeg/sparse_array.c +++ b/client/deps/openjpeg/sparse_array.c @@ -39,15 +39,14 @@ struct opj_sparse_array_int32 { OPJ_UINT32 block_height; OPJ_UINT32 block_count_hor; OPJ_UINT32 block_count_ver; - OPJ_INT32** data_blocks; + OPJ_INT32 **data_blocks; }; -opj_sparse_array_int32_t* opj_sparse_array_int32_create(OPJ_UINT32 width, - OPJ_UINT32 height, - OPJ_UINT32 block_width, - OPJ_UINT32 block_height) -{ - opj_sparse_array_int32_t* sa; +opj_sparse_array_int32_t *opj_sparse_array_int32_create(OPJ_UINT32 width, + OPJ_UINT32 height, + OPJ_UINT32 block_width, + OPJ_UINT32 block_height) { + opj_sparse_array_int32_t *sa; if (width == 0 || height == 0 || block_width == 0 || block_height == 0) { return NULL; @@ -56,8 +55,8 @@ opj_sparse_array_int32_t* opj_sparse_array_int32_create(OPJ_UINT32 width, return NULL; } - sa = (opj_sparse_array_int32_t*) opj_calloc(1, - sizeof(opj_sparse_array_int32_t)); + sa = (opj_sparse_array_int32_t *) opj_calloc(1, + sizeof(opj_sparse_array_int32_t)); sa->width = width; sa->height = height; sa->block_width = block_width; @@ -68,8 +67,8 @@ opj_sparse_array_int32_t* opj_sparse_array_int32_create(OPJ_UINT32 width, opj_free(sa); return NULL; } - sa->data_blocks = (OPJ_INT32**) opj_calloc(sizeof(OPJ_INT32*), - (size_t) sa->block_count_hor * sa->block_count_ver); + sa->data_blocks = (OPJ_INT32 **) opj_calloc(sizeof(OPJ_INT32 *), + (size_t) sa->block_count_hor * sa->block_count_ver); if (sa->data_blocks == NULL) { opj_free(sa); return NULL; @@ -78,8 +77,7 @@ opj_sparse_array_int32_t* opj_sparse_array_int32_create(OPJ_UINT32 width, return sa; } -void opj_sparse_array_int32_free(opj_sparse_array_int32_t* sa) -{ +void opj_sparse_array_int32_free(opj_sparse_array_int32_t *sa) { if (sa) { OPJ_UINT32 i; for (i = 0; i < sa->block_count_hor * sa->block_count_ver; i++) { @@ -92,28 +90,26 @@ void opj_sparse_array_int32_free(opj_sparse_array_int32_t* sa) } } -OPJ_BOOL opj_sparse_array_is_region_valid(const opj_sparse_array_int32_t* sa, - OPJ_UINT32 x0, - OPJ_UINT32 y0, - OPJ_UINT32 x1, - OPJ_UINT32 y1) -{ +OPJ_BOOL opj_sparse_array_is_region_valid(const opj_sparse_array_int32_t *sa, + OPJ_UINT32 x0, + OPJ_UINT32 y0, + OPJ_UINT32 x1, + OPJ_UINT32 y1) { return !(x0 >= sa->width || x1 <= x0 || x1 > sa->width || y0 >= sa->height || y1 <= y0 || y1 > sa->height); } static OPJ_BOOL opj_sparse_array_int32_read_or_write( - const opj_sparse_array_int32_t* sa, + const opj_sparse_array_int32_t *sa, OPJ_UINT32 x0, OPJ_UINT32 y0, OPJ_UINT32 x1, OPJ_UINT32 y1, - OPJ_INT32* buf, + OPJ_INT32 *buf, OPJ_UINT32 buf_col_stride, OPJ_UINT32 buf_line_stride, OPJ_BOOL forgiving, - OPJ_BOOL is_read_op) -{ + OPJ_BOOL is_read_op) { OPJ_UINT32 y, block_y; OPJ_UINT32 y_incr = 0; const OPJ_UINT32 block_width = sa->block_width; @@ -135,7 +131,7 @@ static OPJ_BOOL opj_sparse_array_int32_read_or_write( for (x = x0; x < x1; block_x ++, x += x_incr) { OPJ_UINT32 j; OPJ_UINT32 block_x_offset; - OPJ_INT32* src_block; + OPJ_INT32 *src_block; x_incr = (x == x0) ? block_width - (x0 % block_width) : block_width; block_x_offset = block_width - x_incr; x_incr = opj_uint_min(x_incr, x1 - x); @@ -143,14 +139,14 @@ static OPJ_BOOL opj_sparse_array_int32_read_or_write( if (is_read_op) { if (src_block == NULL) { if (buf_col_stride == 1) { - OPJ_INT32* dest_ptr = buf + (y - y0) * (OPJ_SIZE_T)buf_line_stride + + OPJ_INT32 *dest_ptr = buf + (y - y0) * (OPJ_SIZE_T)buf_line_stride + (x - x0) * buf_col_stride; for (j = 0; j < y_incr; j++) { memset(dest_ptr, 0, sizeof(OPJ_INT32) * x_incr); dest_ptr += buf_line_stride; } } else { - OPJ_INT32* dest_ptr = buf + (y - y0) * (OPJ_SIZE_T)buf_line_stride + + OPJ_INT32 *dest_ptr = buf + (y - y0) * (OPJ_SIZE_T)buf_line_stride + (x - x0) * buf_col_stride; for (j = 0; j < y_incr; j++) { OPJ_UINT32 k; @@ -161,10 +157,10 @@ static OPJ_BOOL opj_sparse_array_int32_read_or_write( } } } else { - const OPJ_INT32* OPJ_RESTRICT src_ptr = src_block + block_y_offset * + const OPJ_INT32 *OPJ_RESTRICT src_ptr = src_block + block_y_offset * (OPJ_SIZE_T)block_width + block_x_offset; if (buf_col_stride == 1) { - OPJ_INT32* OPJ_RESTRICT dest_ptr = buf + (y - y0) * (OPJ_SIZE_T)buf_line_stride + OPJ_INT32 *OPJ_RESTRICT dest_ptr = buf + (y - y0) * (OPJ_SIZE_T)buf_line_stride + (x - x0) * buf_col_stride; if (x_incr == 4) { @@ -184,7 +180,7 @@ static OPJ_BOOL opj_sparse_array_int32_read_or_write( } } } else { - OPJ_INT32* OPJ_RESTRICT dest_ptr = buf + (y - y0) * (OPJ_SIZE_T)buf_line_stride + OPJ_INT32 *OPJ_RESTRICT dest_ptr = buf + (y - y0) * (OPJ_SIZE_T)buf_line_stride + (x - x0) * buf_col_stride; if (x_incr == 1) { @@ -234,8 +230,8 @@ static OPJ_BOOL opj_sparse_array_int32_read_or_write( } } else { if (src_block == NULL) { - src_block = (OPJ_INT32*) opj_calloc(1, - (size_t) sa->block_width * sa->block_height * sizeof(OPJ_INT32)); + src_block = (OPJ_INT32 *) opj_calloc(1, + (size_t) sa->block_width * sa->block_height * sizeof(OPJ_INT32)); if (src_block == NULL) { return OPJ_FALSE; } @@ -243,9 +239,9 @@ static OPJ_BOOL opj_sparse_array_int32_read_or_write( } if (buf_col_stride == 1) { - OPJ_INT32* OPJ_RESTRICT dest_ptr = src_block + block_y_offset * + OPJ_INT32 *OPJ_RESTRICT dest_ptr = src_block + block_y_offset * (OPJ_SIZE_T)block_width + block_x_offset; - const OPJ_INT32* OPJ_RESTRICT src_ptr = buf + (y - y0) * + const OPJ_INT32 *OPJ_RESTRICT src_ptr = buf + (y - y0) * (OPJ_SIZE_T)buf_line_stride + (x - x0) * buf_col_stride; if (x_incr == 4) { /* Same code as general branch, but the compiler */ @@ -264,9 +260,9 @@ static OPJ_BOOL opj_sparse_array_int32_read_or_write( } } } else { - OPJ_INT32* OPJ_RESTRICT dest_ptr = src_block + block_y_offset * + OPJ_INT32 *OPJ_RESTRICT dest_ptr = src_block + block_y_offset * (OPJ_SIZE_T)block_width + block_x_offset; - const OPJ_INT32* OPJ_RESTRICT src_ptr = buf + (y - y0) * + const OPJ_INT32 *OPJ_RESTRICT src_ptr = buf + (y - y0) * (OPJ_SIZE_T)buf_line_stride + (x - x0) * buf_col_stride; if (x_incr == 1) { for (j = 0; j < y_incr; j++) { @@ -308,18 +304,17 @@ static OPJ_BOOL opj_sparse_array_int32_read_or_write( return OPJ_TRUE; } -OPJ_BOOL opj_sparse_array_int32_read(const opj_sparse_array_int32_t* sa, +OPJ_BOOL opj_sparse_array_int32_read(const opj_sparse_array_int32_t *sa, OPJ_UINT32 x0, OPJ_UINT32 y0, OPJ_UINT32 x1, OPJ_UINT32 y1, - OPJ_INT32* dest, + OPJ_INT32 *dest, OPJ_UINT32 dest_col_stride, OPJ_UINT32 dest_line_stride, - OPJ_BOOL forgiving) -{ + OPJ_BOOL forgiving) { return opj_sparse_array_int32_read_or_write( - (opj_sparse_array_int32_t*)sa, x0, y0, x1, y1, + (opj_sparse_array_int32_t *)sa, x0, y0, x1, y1, dest, dest_col_stride, dest_line_stride, @@ -327,20 +322,19 @@ OPJ_BOOL opj_sparse_array_int32_read(const opj_sparse_array_int32_t* sa, OPJ_TRUE); } -OPJ_BOOL opj_sparse_array_int32_write(opj_sparse_array_int32_t* sa, +OPJ_BOOL opj_sparse_array_int32_write(opj_sparse_array_int32_t *sa, OPJ_UINT32 x0, OPJ_UINT32 y0, OPJ_UINT32 x1, OPJ_UINT32 y1, - const OPJ_INT32* src, + const OPJ_INT32 *src, OPJ_UINT32 src_col_stride, OPJ_UINT32 src_line_stride, - OPJ_BOOL forgiving) -{ + OPJ_BOOL forgiving) { return opj_sparse_array_int32_read_or_write(sa, x0, y0, x1, y1, - (OPJ_INT32*)src, - src_col_stride, - src_line_stride, - forgiving, - OPJ_FALSE); + (OPJ_INT32 *)src, + src_col_stride, + src_line_stride, + forgiving, + OPJ_FALSE); } diff --git a/client/deps/openjpeg/sparse_array.h b/client/deps/openjpeg/sparse_array.h index fd927eaa0..04f537255 100644 --- a/client/deps/openjpeg/sparse_array.h +++ b/client/deps/openjpeg/sparse_array.h @@ -59,15 +59,15 @@ typedef struct opj_sparse_array_int32 opj_sparse_array_int32_t; * @param block_height height of a block. * @return a new sparse array instance, or NULL in case of failure. */ -opj_sparse_array_int32_t* opj_sparse_array_int32_create(OPJ_UINT32 width, - OPJ_UINT32 height, - OPJ_UINT32 block_width, - OPJ_UINT32 block_height); +opj_sparse_array_int32_t *opj_sparse_array_int32_create(OPJ_UINT32 width, + OPJ_UINT32 height, + OPJ_UINT32 block_width, + OPJ_UINT32 block_height); /** Frees a sparse array. * @param sa sparse array instance. */ -void opj_sparse_array_int32_free(opj_sparse_array_int32_t* sa); +void opj_sparse_array_int32_free(opj_sparse_array_int32_t *sa); /** Returns whether region bounds are valid (non empty and within array bounds) * @param sa sparse array instance. @@ -77,11 +77,11 @@ void opj_sparse_array_int32_free(opj_sparse_array_int32_t* sa); * @param y1 bottom y coordinate (not included) of the region. Must be greater than y0. * @return OPJ_TRUE or OPJ_FALSE. */ -OPJ_BOOL opj_sparse_array_is_region_valid(const opj_sparse_array_int32_t* sa, - OPJ_UINT32 x0, - OPJ_UINT32 y0, - OPJ_UINT32 x1, - OPJ_UINT32 y1); +OPJ_BOOL opj_sparse_array_is_region_valid(const opj_sparse_array_int32_t *sa, + OPJ_UINT32 x0, + OPJ_UINT32 y0, + OPJ_UINT32 x1, + OPJ_UINT32 y1); /** Read the content of a rectangular region of the sparse array into a * user buffer. @@ -99,12 +99,12 @@ OPJ_BOOL opj_sparse_array_is_region_valid(const opj_sparse_array_int32_t* sa, * @param forgiving if set to TRUE and the region is invalid, OPJ_TRUE will still be returned. * @return OPJ_TRUE in case of success. */ -OPJ_BOOL opj_sparse_array_int32_read(const opj_sparse_array_int32_t* sa, +OPJ_BOOL opj_sparse_array_int32_read(const opj_sparse_array_int32_t *sa, OPJ_UINT32 x0, OPJ_UINT32 y0, OPJ_UINT32 x1, OPJ_UINT32 y1, - OPJ_INT32* dest, + OPJ_INT32 *dest, OPJ_UINT32 dest_col_stride, OPJ_UINT32 dest_line_stride, OPJ_BOOL forgiving); @@ -126,12 +126,12 @@ OPJ_BOOL opj_sparse_array_int32_read(const opj_sparse_array_int32_t* sa, * @param forgiving if set to TRUE and the region is invalid, OPJ_TRUE will still be returned. * @return OPJ_TRUE in case of success. */ -OPJ_BOOL opj_sparse_array_int32_write(opj_sparse_array_int32_t* sa, +OPJ_BOOL opj_sparse_array_int32_write(opj_sparse_array_int32_t *sa, OPJ_UINT32 x0, OPJ_UINT32 y0, OPJ_UINT32 x1, OPJ_UINT32 y1, - const OPJ_INT32* src, + const OPJ_INT32 *src, OPJ_UINT32 src_col_stride, OPJ_UINT32 src_line_stride, OPJ_BOOL forgiving); diff --git a/client/deps/openjpeg/t1.c b/client/deps/openjpeg/t1.c index 98dce47f5..d7b233af2 100644 --- a/client/deps/openjpeg/t1.c +++ b/client/deps/openjpeg/t1.c @@ -184,12 +184,12 @@ static OPJ_FLOAT64 opj_t1_getwmsedec( OPJ_UINT32 qmfbid, OPJ_FLOAT64 stepsize, OPJ_UINT32 numcomps, - const OPJ_FLOAT64 * mct_norms, + const OPJ_FLOAT64 *mct_norms, OPJ_UINT32 mct_numcomps); /** Return "cumwmsedec" that should be used to increase tile->distotile */ static double opj_t1_encode_cblk(opj_t1_t *t1, - opj_tcd_cblk_enc_t* cblk, + opj_tcd_cblk_enc_t *cblk, OPJ_UINT32 orient, OPJ_UINT32 compno, OPJ_UINT32 level, @@ -197,7 +197,7 @@ static double opj_t1_encode_cblk(opj_t1_t *t1, OPJ_FLOAT64 stepsize, OPJ_UINT32 cblksty, OPJ_UINT32 numcomps, - const OPJ_FLOAT64 * mct_norms, + const OPJ_FLOAT64 *mct_norms, OPJ_UINT32 mct_numcomps); /** @@ -212,12 +212,12 @@ Decode 1 code-block @param check_pterm whether PTERM correct termination should be checked */ static OPJ_BOOL opj_t1_decode_cblk(opj_t1_t *t1, - opj_tcd_cblk_dec_t* cblk, + opj_tcd_cblk_dec_t *cblk, OPJ_UINT32 orient, OPJ_UINT32 roishift, OPJ_UINT32 cblksty, opj_event_mgr_t *p_manager, - opj_mutex_t* p_manager_mutex, + opj_mutex_t *p_manager_mutex, OPJ_BOOL check_pterm); /** @@ -232,12 +232,12 @@ Decode 1 HT code-block @param check_pterm whether PTERM correct termination should be checked */ OPJ_BOOL opj_t1_ht_decode_cblk(opj_t1_t *t1, - opj_tcd_cblk_dec_t* cblk, + opj_tcd_cblk_dec_t *cblk, OPJ_UINT32 orient, OPJ_UINT32 roishift, OPJ_UINT32 cblksty, opj_event_mgr_t *p_manager, - opj_mutex_t* p_manager_mutex, + opj_mutex_t *p_manager_mutex, OPJ_BOOL check_pterm); @@ -251,16 +251,14 @@ static OPJ_BOOL opj_t1_allocate_buffers(opj_t1_t *t1, /* ----------------------------------------------------------------------- */ -static INLINE OPJ_BYTE opj_t1_getctxno_zc(opj_mqc_t *mqc, OPJ_UINT32 f) -{ +static INLINE OPJ_BYTE opj_t1_getctxno_zc(opj_mqc_t *mqc, OPJ_UINT32 f) { return mqc->lut_ctxno_zc_orient[(f & T1_SIGMA_NEIGHBOURS)]; } static INLINE OPJ_UINT32 opj_t1_getctxtno_sc_or_spb_index(OPJ_UINT32 fX, - OPJ_UINT32 pfX, - OPJ_UINT32 nfX, - OPJ_UINT32 ci) -{ + OPJ_UINT32 pfX, + OPJ_UINT32 nfX, + OPJ_UINT32 ci) { /* 0 pfX T1_CHI_THIS T1_LUT_SGN_W 1 tfX T1_SIGMA_1 T1_LUT_SIG_N @@ -286,25 +284,21 @@ static INLINE OPJ_UINT32 opj_t1_getctxtno_sc_or_spb_index(OPJ_UINT32 fX, return lu; } -static INLINE OPJ_BYTE opj_t1_getctxno_sc(OPJ_UINT32 lu) -{ +static INLINE OPJ_BYTE opj_t1_getctxno_sc(OPJ_UINT32 lu) { return lut_ctxno_sc[lu]; } -static INLINE OPJ_UINT32 opj_t1_getctxno_mag(OPJ_UINT32 f) -{ +static INLINE OPJ_UINT32 opj_t1_getctxno_mag(OPJ_UINT32 f) { OPJ_UINT32 tmp = (f & T1_SIGMA_NEIGHBOURS) ? T1_CTXNO_MAG + 1 : T1_CTXNO_MAG; OPJ_UINT32 tmp2 = (f & T1_MU_0) ? T1_CTXNO_MAG + 2 : tmp; return tmp2; } -static INLINE OPJ_BYTE opj_t1_getspb(OPJ_UINT32 lu) -{ +static INLINE OPJ_BYTE opj_t1_getspb(OPJ_UINT32 lu) { return lut_spb[lu]; } -static OPJ_INT16 opj_t1_getnmsedec_sig(OPJ_UINT32 x, OPJ_UINT32 bitpos) -{ +static OPJ_INT16 opj_t1_getnmsedec_sig(OPJ_UINT32 x, OPJ_UINT32 bitpos) { if (bitpos > 0) { return lut_nmsedec_sig[(x >> (bitpos)) & ((1 << T1_NMSEDEC_BITS) - 1)]; } @@ -312,8 +306,7 @@ static OPJ_INT16 opj_t1_getnmsedec_sig(OPJ_UINT32 x, OPJ_UINT32 bitpos) return lut_nmsedec_sig0[x & ((1 << T1_NMSEDEC_BITS) - 1)]; } -static OPJ_INT16 opj_t1_getnmsedec_ref(OPJ_UINT32 x, OPJ_UINT32 bitpos) -{ +static OPJ_INT16 opj_t1_getnmsedec_ref(OPJ_UINT32 x, OPJ_UINT32 bitpos) { if (bitpos > 0) { return lut_nmsedec_ref[(x >> (bitpos)) & ((1 << T1_NMSEDEC_BITS) - 1)]; } @@ -352,8 +345,7 @@ static OPJ_INT16 opj_t1_getnmsedec_ref(OPJ_UINT32 x, OPJ_UINT32 bitpos) static INLINE void opj_t1_update_flags(opj_flag_t *flagsp, OPJ_UINT32 ci, OPJ_UINT32 s, OPJ_UINT32 stride, - OPJ_UINT32 vsc) -{ + OPJ_UINT32 vsc) { opj_t1_update_flags_macro(*flagsp, flagsp, ci, s, stride, vsc); } @@ -415,8 +407,7 @@ static INLINE void opj_t1_dec_sigpass_step_raw( OPJ_INT32 *datap, OPJ_INT32 oneplushalf, OPJ_UINT32 vsc, - OPJ_UINT32 ci) -{ + OPJ_UINT32 ci) { OPJ_UINT32 v; opj_mqc_t *mqc = &(t1->mqc); /* RAW component */ @@ -466,8 +457,7 @@ static INLINE void opj_t1_dec_sigpass_step_mqc( OPJ_INT32 oneplushalf, OPJ_UINT32 ci, OPJ_UINT32 flags_stride, - OPJ_UINT32 vsc) -{ + OPJ_UINT32 vsc) { OPJ_UINT32 v; opj_mqc_t *mqc = &(t1->mqc); /* MQC component */ @@ -481,15 +471,14 @@ static void opj_t1_enc_sigpass(opj_t1_t *t1, OPJ_INT32 *nmsedec, OPJ_BYTE type, OPJ_UINT32 cblksty - ) -{ + ) { OPJ_UINT32 i, k; OPJ_INT32 const one = 1 << (bpno + T1_NMSEDEC_FRACBITS); - opj_flag_t* f = &T1_FLAGS(0, 0); + opj_flag_t *f = &T1_FLAGS(0, 0); OPJ_UINT32 const extra = 2; - opj_mqc_t* mqc = &(t1->mqc); + opj_mqc_t *mqc = &(t1->mqc); DOWNLOAD_MQC_VARIABLES(mqc, curctx, a, c, ct); - const OPJ_INT32* datap = t1->data; + const OPJ_INT32 *datap = t1->data; *nmsedec = 0; #ifdef DEBUG_ENC_SIG @@ -582,8 +571,7 @@ static void opj_t1_enc_sigpass(opj_t1_t *t1, static void opj_t1_dec_sigpass_raw( opj_t1_t *t1, OPJ_INT32 bpno, - OPJ_INT32 cblksty) -{ + OPJ_INT32 cblksty) { OPJ_INT32 one, half, oneplushalf; OPJ_UINT32 i, j, k; OPJ_INT32 *data = t1->data; @@ -689,30 +677,26 @@ static void opj_t1_dec_sigpass_raw( static void opj_t1_dec_sigpass_mqc_64x64_novsc( opj_t1_t *t1, - OPJ_INT32 bpno) -{ + OPJ_INT32 bpno) { opj_t1_dec_sigpass_mqc_internal(t1, bpno, OPJ_FALSE, 64, 64, 66); } static void opj_t1_dec_sigpass_mqc_64x64_vsc( opj_t1_t *t1, - OPJ_INT32 bpno) -{ + OPJ_INT32 bpno) { opj_t1_dec_sigpass_mqc_internal(t1, bpno, OPJ_TRUE, 64, 64, 66); } static void opj_t1_dec_sigpass_mqc_generic_novsc( opj_t1_t *t1, - OPJ_INT32 bpno) -{ + OPJ_INT32 bpno) { opj_t1_dec_sigpass_mqc_internal(t1, bpno, OPJ_FALSE, t1->w, t1->h, t1->w + 2U); } static void opj_t1_dec_sigpass_mqc_generic_vsc( opj_t1_t *t1, - OPJ_INT32 bpno) -{ + OPJ_INT32 bpno) { opj_t1_dec_sigpass_mqc_internal(t1, bpno, OPJ_TRUE, t1->w, t1->h, t1->w + 2U); } @@ -720,8 +704,7 @@ static void opj_t1_dec_sigpass_mqc_generic_vsc( static void opj_t1_dec_sigpass_mqc( opj_t1_t *t1, OPJ_INT32 bpno, - OPJ_INT32 cblksty) -{ + OPJ_INT32 cblksty) { if (t1->w == 64 && t1->h == 64) { if (cblksty & J2K_CCP_CBLKSTY_VSC) { opj_t1_dec_sigpass_mqc_64x64_vsc(t1, bpno); @@ -769,8 +752,7 @@ static INLINE void opj_t1_dec_refpass_step_raw( opj_flag_t *flagsp, OPJ_INT32 *datap, OPJ_INT32 poshalf, - OPJ_UINT32 ci) -{ + OPJ_UINT32 ci) { OPJ_UINT32 v; opj_mqc_t *mqc = &(t1->mqc); /* RAW component */ @@ -801,8 +783,7 @@ static INLINE void opj_t1_dec_refpass_step_mqc( opj_flag_t *flagsp, OPJ_INT32 *datap, OPJ_INT32 poshalf, - OPJ_UINT32 ci) -{ + OPJ_UINT32 ci) { OPJ_UINT32 v; opj_mqc_t *mqc = &(t1->mqc); /* MQC component */ @@ -815,15 +796,14 @@ static void opj_t1_enc_refpass( opj_t1_t *t1, OPJ_INT32 bpno, OPJ_INT32 *nmsedec, - OPJ_BYTE type) -{ + OPJ_BYTE type) { OPJ_UINT32 i, k; const OPJ_INT32 one = 1 << (bpno + T1_NMSEDEC_FRACBITS); - opj_flag_t* f = &T1_FLAGS(0, 0); + opj_flag_t *f = &T1_FLAGS(0, 0); const OPJ_UINT32 extra = 2U; - opj_mqc_t* mqc = &(t1->mqc); + opj_mqc_t *mqc = &(t1->mqc); DOWNLOAD_MQC_VARIABLES(mqc, curctx, a, c, ct); - const OPJ_INT32* datap = t1->data; + const OPJ_INT32 *datap = t1->data; *nmsedec = 0; #ifdef DEBUG_ENC_REF @@ -924,8 +904,7 @@ static void opj_t1_enc_refpass( static void opj_t1_dec_refpass_raw( opj_t1_t *t1, - OPJ_INT32 bpno) -{ + OPJ_INT32 bpno) { OPJ_INT32 one, poshalf; OPJ_UINT32 i, j, k; OPJ_INT32 *data = t1->data; @@ -1022,22 +1001,19 @@ static void opj_t1_dec_refpass_raw( static void opj_t1_dec_refpass_mqc_64x64( opj_t1_t *t1, - OPJ_INT32 bpno) -{ + OPJ_INT32 bpno) { opj_t1_dec_refpass_mqc_internal(t1, bpno, 64, 64, 66); } static void opj_t1_dec_refpass_mqc_generic( opj_t1_t *t1, - OPJ_INT32 bpno) -{ + OPJ_INT32 bpno) { opj_t1_dec_refpass_mqc_internal(t1, bpno, t1->w, t1->h, t1->w + 2U); } static void opj_t1_dec_refpass_mqc( opj_t1_t *t1, - OPJ_INT32 bpno) -{ + OPJ_INT32 bpno) { if (t1->w == 64 && t1->h == 64) { opj_t1_dec_refpass_mqc_64x64(t1, bpno); } else { @@ -1149,8 +1125,7 @@ static void opj_t1_dec_clnpass_step( OPJ_INT32 *datap, OPJ_INT32 oneplushalf, OPJ_UINT32 ci, - OPJ_UINT32 vsc) -{ + OPJ_UINT32 vsc) { OPJ_UINT32 v; opj_mqc_t *mqc = &(t1->mqc); /* MQC component */ @@ -1164,13 +1139,12 @@ static void opj_t1_enc_clnpass( opj_t1_t *t1, OPJ_INT32 bpno, OPJ_INT32 *nmsedec, - OPJ_UINT32 cblksty) -{ + OPJ_UINT32 cblksty) { OPJ_UINT32 i, k; const OPJ_INT32 one = 1 << (bpno + T1_NMSEDEC_FRACBITS); - opj_mqc_t* mqc = &(t1->mqc); + opj_mqc_t *mqc = &(t1->mqc); DOWNLOAD_MQC_VARIABLES(mqc, curctx, a, c, ct); - const OPJ_INT32* datap = t1->data; + const OPJ_INT32 *datap = t1->data; opj_flag_t *f = &T1_FLAGS(0, 0); const OPJ_UINT32 extra = 2U; @@ -1340,10 +1314,9 @@ static void opj_t1_enc_clnpass( } \ } -static void opj_t1_dec_clnpass_check_segsym(opj_t1_t *t1, OPJ_INT32 cblksty) -{ +static void opj_t1_dec_clnpass_check_segsym(opj_t1_t *t1, OPJ_INT32 cblksty) { if (cblksty & J2K_CCP_CBLKSTY_SEGSYM) { - opj_mqc_t* mqc = &(t1->mqc); + opj_mqc_t *mqc = &(t1->mqc); OPJ_UINT32 v, v2; opj_mqc_setcurctx(mqc, T1_CTXNO_UNI); opj_mqc_decode(v, mqc); @@ -1363,30 +1336,26 @@ static void opj_t1_dec_clnpass_check_segsym(opj_t1_t *t1, OPJ_INT32 cblksty) static void opj_t1_dec_clnpass_64x64_novsc( opj_t1_t *t1, - OPJ_INT32 bpno) -{ + OPJ_INT32 bpno) { opj_t1_dec_clnpass_internal(t1, bpno, OPJ_FALSE, 64, 64, 66); } static void opj_t1_dec_clnpass_64x64_vsc( opj_t1_t *t1, - OPJ_INT32 bpno) -{ + OPJ_INT32 bpno) { opj_t1_dec_clnpass_internal(t1, bpno, OPJ_TRUE, 64, 64, 66); } static void opj_t1_dec_clnpass_generic_novsc( opj_t1_t *t1, - OPJ_INT32 bpno) -{ + OPJ_INT32 bpno) { opj_t1_dec_clnpass_internal(t1, bpno, OPJ_FALSE, t1->w, t1->h, t1->w + 2U); } static void opj_t1_dec_clnpass_generic_vsc( opj_t1_t *t1, - OPJ_INT32 bpno) -{ + OPJ_INT32 bpno) { opj_t1_dec_clnpass_internal(t1, bpno, OPJ_TRUE, t1->w, t1->h, t1->w + 2U); } @@ -1394,8 +1363,7 @@ static void opj_t1_dec_clnpass_generic_vsc( static void opj_t1_dec_clnpass( opj_t1_t *t1, OPJ_INT32 bpno, - OPJ_INT32 cblksty) -{ + OPJ_INT32 cblksty) { if (t1->w == 64 && t1->h == 64) { if (cblksty & J2K_CCP_CBLKSTY_VSC) { opj_t1_dec_clnpass_64x64_vsc(t1, bpno); @@ -1422,9 +1390,8 @@ static OPJ_FLOAT64 opj_t1_getwmsedec( OPJ_UINT32 qmfbid, OPJ_FLOAT64 stepsize, OPJ_UINT32 numcomps, - const OPJ_FLOAT64 * mct_norms, - OPJ_UINT32 mct_numcomps) -{ + const OPJ_FLOAT64 *mct_norms, + OPJ_UINT32 mct_numcomps) { OPJ_FLOAT64 w1 = 1, w2, wmsedec; OPJ_ARG_NOT_USED(numcomps); @@ -1451,8 +1418,7 @@ static OPJ_FLOAT64 opj_t1_getwmsedec( static OPJ_BOOL opj_t1_allocate_buffers( opj_t1_t *t1, OPJ_UINT32 w, - OPJ_UINT32 h) -{ + OPJ_UINT32 h) { OPJ_UINT32 flagssize; OPJ_UINT32 flags_stride; @@ -1468,7 +1434,7 @@ static OPJ_BOOL opj_t1_allocate_buffers( if (datasize > t1->datasize) { opj_aligned_free(t1->data); - t1->data = (OPJ_INT32*) opj_aligned_malloc(datasize * sizeof(OPJ_INT32)); + t1->data = (OPJ_INT32 *) opj_aligned_malloc(datasize * sizeof(OPJ_INT32)); if (!t1->data) { /* FIXME event manager error callback */ return OPJ_FALSE; @@ -1487,15 +1453,15 @@ static OPJ_BOOL opj_t1_allocate_buffers( flagssize *= flags_stride; { - opj_flag_t* p; + opj_flag_t *p; OPJ_UINT32 x; OPJ_UINT32 flags_height = (h + 3U) / 4U; if (flagssize > t1->flagssize) { opj_aligned_free(t1->flags); - t1->flags = (opj_flag_t*) opj_aligned_malloc(flagssize * sizeof( - opj_flag_t)); + t1->flags = (opj_flag_t *) opj_aligned_malloc(flagssize * sizeof( + opj_flag_t)); if (!t1->flags) { /* FIXME event manager error callback */ return OPJ_FALSE; @@ -1547,11 +1513,10 @@ static OPJ_BOOL opj_t1_allocate_buffers( * and initializes the look-up tables of the Tier-1 coder/decoder * @return a new T1 handle if successful, returns NULL otherwise */ -opj_t1_t* opj_t1_create(OPJ_BOOL isEncoder) -{ +opj_t1_t *opj_t1_create(OPJ_BOOL isEncoder) { opj_t1_t *l_t1 = 00; - l_t1 = (opj_t1_t*) opj_calloc(1, sizeof(opj_t1_t)); + l_t1 = (opj_t1_t *) opj_calloc(1, sizeof(opj_t1_t)); if (!l_t1) { return 00; } @@ -1567,8 +1532,7 @@ opj_t1_t* opj_t1_create(OPJ_BOOL isEncoder) * * @param p_t1 Tier 1 handle to destroy */ -void opj_t1_destroy(opj_t1_t *p_t1) -{ +void opj_t1_destroy(opj_t1_t *p_t1) { if (! p_t1) { return; } @@ -1591,38 +1555,36 @@ void opj_t1_destroy(opj_t1_t *p_t1) typedef struct { OPJ_BOOL whole_tile_decoding; OPJ_UINT32 resno; - opj_tcd_cblk_dec_t* cblk; - opj_tcd_band_t* band; - opj_tcd_tilecomp_t* tilec; - opj_tccp_t* tccp; + opj_tcd_cblk_dec_t *cblk; + opj_tcd_band_t *band; + opj_tcd_tilecomp_t *tilec; + opj_tccp_t *tccp; OPJ_BOOL mustuse_cblkdatabuffer; - volatile OPJ_BOOL* pret; + volatile OPJ_BOOL *pret; opj_event_mgr_t *p_manager; - opj_mutex_t* p_manager_mutex; + opj_mutex_t *p_manager_mutex; OPJ_BOOL check_pterm; } opj_t1_cblk_decode_processing_job_t; -static void opj_t1_destroy_wrapper(void* t1) -{ - opj_t1_destroy((opj_t1_t*) t1); +static void opj_t1_destroy_wrapper(void *t1) { + opj_t1_destroy((opj_t1_t *) t1); } -static void opj_t1_clbl_decode_processor(void* user_data, opj_tls_t* tls) -{ - opj_tcd_cblk_dec_t* cblk; - opj_tcd_band_t* band; - opj_tcd_tilecomp_t* tilec; - opj_tccp_t* tccp; - OPJ_INT32* OPJ_RESTRICT datap; +static void opj_t1_clbl_decode_processor(void *user_data, opj_tls_t *tls) { + opj_tcd_cblk_dec_t *cblk; + opj_tcd_band_t *band; + opj_tcd_tilecomp_t *tilec; + opj_tccp_t *tccp; + OPJ_INT32 *OPJ_RESTRICT datap; OPJ_UINT32 cblk_w, cblk_h; OPJ_INT32 x, y; OPJ_UINT32 i, j; - opj_t1_cblk_decode_processing_job_t* job; - opj_t1_t* t1; + opj_t1_cblk_decode_processing_job_t *job; + opj_t1_t *t1; OPJ_UINT32 resno; OPJ_UINT32 tile_w; - job = (opj_t1_cblk_decode_processing_job_t*) user_data; + job = (opj_t1_cblk_decode_processing_job_t *) user_data; cblk = job->cblk; @@ -1630,8 +1592,8 @@ static void opj_t1_clbl_decode_processor(void* user_data, opj_tls_t* tls) cblk_w = (OPJ_UINT32)(cblk->x1 - cblk->x0); cblk_h = (OPJ_UINT32)(cblk->y1 - cblk->y0); - cblk->decoded_data = (OPJ_INT32*)opj_aligned_malloc(sizeof(OPJ_INT32) * - cblk_w * cblk_h); + cblk->decoded_data = (OPJ_INT32 *)opj_aligned_malloc(sizeof(OPJ_INT32) * + cblk_w * cblk_h); if (cblk->decoded_data == NULL) { if (job->p_manager_mutex) { opj_mutex_lock(job->p_manager_mutex); @@ -1667,7 +1629,7 @@ static void opj_t1_clbl_decode_processor(void* user_data, opj_tls_t* tls) return; } - t1 = (opj_t1_t*) opj_tls_get(tls, OPJ_TLS_KEY_T1); + t1 = (opj_t1_t *) opj_tls_get(tls, OPJ_TLS_KEY_T1); if (t1 == NULL) { t1 = opj_t1_create(OPJ_FALSE); if (t1 == NULL) { @@ -1721,11 +1683,11 @@ static void opj_t1_clbl_decode_processor(void* user_data, opj_tls_t* tls) x = cblk->x0 - band->x0; y = cblk->y0 - band->y0; if (band->bandno & 1) { - opj_tcd_resolution_t* pres = &tilec->resolutions[resno - 1]; + opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; x += pres->x1 - pres->x0; } if (band->bandno & 2) { - opj_tcd_resolution_t* pres = &tilec->resolutions[resno - 1]; + opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; y += pres->y1 - pres->y0; } @@ -1774,17 +1736,17 @@ static void opj_t1_clbl_decode_processor(void* user_data, opj_tls_t* tls) const __m128 xmm_stepsize = _mm_set1_ps(stepsize); for (; i < (cblk_size & ~15U); i += 16) { __m128 xmm0_data = _mm_cvtepi32_ps(_mm_load_si128((__m128i * const)( - datap + 0))); + datap + 0))); __m128 xmm1_data = _mm_cvtepi32_ps(_mm_load_si128((__m128i * const)( - datap + 4))); + datap + 4))); __m128 xmm2_data = _mm_cvtepi32_ps(_mm_load_si128((__m128i * const)( - datap + 8))); + datap + 8))); __m128 xmm3_data = _mm_cvtepi32_ps(_mm_load_si128((__m128i * const)( - datap + 12))); - _mm_store_ps((float*)(datap + 0), _mm_mul_ps(xmm0_data, xmm_stepsize)); - _mm_store_ps((float*)(datap + 4), _mm_mul_ps(xmm1_data, xmm_stepsize)); - _mm_store_ps((float*)(datap + 8), _mm_mul_ps(xmm2_data, xmm_stepsize)); - _mm_store_ps((float*)(datap + 12), _mm_mul_ps(xmm3_data, xmm_stepsize)); + datap + 12))); + _mm_store_ps((float *)(datap + 0), _mm_mul_ps(xmm0_data, xmm_stepsize)); + _mm_store_ps((float *)(datap + 4), _mm_mul_ps(xmm1_data, xmm_stepsize)); + _mm_store_ps((float *)(datap + 8), _mm_mul_ps(xmm2_data, xmm_stepsize)); + _mm_store_ps((float *)(datap + 12), _mm_mul_ps(xmm3_data, xmm_stepsize)); datap += 16; } } @@ -1796,19 +1758,19 @@ static void opj_t1_clbl_decode_processor(void* user_data, opj_tls_t* tls) } } } else if (tccp->qmfbid == 1) { - OPJ_INT32* OPJ_RESTRICT tiledp = &tilec->data[(OPJ_SIZE_T)y * tile_w + - (OPJ_SIZE_T)x]; + OPJ_INT32 *OPJ_RESTRICT tiledp = &tilec->data[(OPJ_SIZE_T)y * tile_w + + (OPJ_SIZE_T)x]; for (j = 0; j < cblk_h; ++j) { //positive -> round down aka. (83)/2 = 41.5 -> 41 //negative -> round up aka. (-83)/2 = -41.5 -> -41 #if defined(__AVX512F__) - OPJ_INT32* ptr_in = datap + (j * cblk_w); - OPJ_INT32* ptr_out = tiledp + (j * (OPJ_SIZE_T)tile_w); + OPJ_INT32 *ptr_in = datap + (j * cblk_w); + OPJ_INT32 *ptr_out = tiledp + (j * (OPJ_SIZE_T)tile_w); for (i = 0; i < cblk_w / 16; ++i) { - __m512i in_avx = _mm512_loadu_si512((__m512i*)(ptr_in)); + __m512i in_avx = _mm512_loadu_si512((__m512i *)(ptr_in)); const __m512i add_avx = _mm512_srli_epi32(in_avx, 31); in_avx = _mm512_add_epi32(in_avx, add_avx); - _mm512_storeu_si512((__m512i*)(ptr_out), _mm512_srai_epi32(in_avx, 1)); + _mm512_storeu_si512((__m512i *)(ptr_out), _mm512_srai_epi32(in_avx, 1)); ptr_in += 16; ptr_out += 16; } @@ -1817,13 +1779,13 @@ static void opj_t1_clbl_decode_processor(void* user_data, opj_tls_t* tls) ptr_out[i] = ptr_in[i] / 2; } #elif defined(__AVX2__) - OPJ_INT32* ptr_in = datap + (j * cblk_w); - OPJ_INT32* ptr_out = tiledp + (j * (OPJ_SIZE_T)tile_w); + OPJ_INT32 *ptr_in = datap + (j * cblk_w); + OPJ_INT32 *ptr_out = tiledp + (j * (OPJ_SIZE_T)tile_w); for (i = 0; i < cblk_w / 8; ++i) { - __m256i in_avx = _mm256_loadu_si256((__m256i*)(ptr_in)); + __m256i in_avx = _mm256_loadu_si256((__m256i *)(ptr_in)); const __m256i add_avx = _mm256_srli_epi32(in_avx, 31); in_avx = _mm256_add_epi32(in_avx, add_avx); - _mm256_storeu_si256((__m256i*)(ptr_out), _mm256_srai_epi32(in_avx, 1)); + _mm256_storeu_si256((__m256i *)(ptr_out), _mm256_srai_epi32(in_avx, 1)); ptr_in += 8; ptr_out += 8; } @@ -1838,23 +1800,23 @@ static void opj_t1_clbl_decode_processor(void* user_data, opj_tls_t* tls) OPJ_INT32 tmp1 = datap[(j * cblk_w) + i + 1U]; OPJ_INT32 tmp2 = datap[(j * cblk_w) + i + 2U]; OPJ_INT32 tmp3 = datap[(j * cblk_w) + i + 3U]; - ((OPJ_INT32*)tiledp)[(j * (OPJ_SIZE_T)tile_w) + i + 0U] = tmp0 / 2; - ((OPJ_INT32*)tiledp)[(j * (OPJ_SIZE_T)tile_w) + i + 1U] = tmp1 / 2; - ((OPJ_INT32*)tiledp)[(j * (OPJ_SIZE_T)tile_w) + i + 2U] = tmp2 / 2; - ((OPJ_INT32*)tiledp)[(j * (OPJ_SIZE_T)tile_w) + i + 3U] = tmp3 / 2; + ((OPJ_INT32 *)tiledp)[(j * (OPJ_SIZE_T)tile_w) + i + 0U] = tmp0 / 2; + ((OPJ_INT32 *)tiledp)[(j * (OPJ_SIZE_T)tile_w) + i + 1U] = tmp1 / 2; + ((OPJ_INT32 *)tiledp)[(j * (OPJ_SIZE_T)tile_w) + i + 2U] = tmp2 / 2; + ((OPJ_INT32 *)tiledp)[(j * (OPJ_SIZE_T)tile_w) + i + 3U] = tmp3 / 2; } for (; i < cblk_w; ++i) { OPJ_INT32 tmp = datap[(j * cblk_w) + i]; - ((OPJ_INT32*)tiledp)[(j * (OPJ_SIZE_T)tile_w) + i] = tmp / 2; + ((OPJ_INT32 *)tiledp)[(j * (OPJ_SIZE_T)tile_w) + i] = tmp / 2; } #endif } } else { /* if (tccp->qmfbid == 0) */ const float stepsize = 0.5f * band->stepsize; - OPJ_FLOAT32* OPJ_RESTRICT tiledp = (OPJ_FLOAT32*) &tilec->data[(OPJ_SIZE_T)y * + OPJ_FLOAT32 *OPJ_RESTRICT tiledp = (OPJ_FLOAT32 *) &tilec->data[(OPJ_SIZE_T)y * tile_w + (OPJ_SIZE_T)x]; for (j = 0; j < cblk_h; ++j) { - OPJ_FLOAT32* OPJ_RESTRICT tiledp2 = tiledp; + OPJ_FLOAT32 *OPJ_RESTRICT tiledp2 = tiledp; for (i = 0; i < cblk_w; ++i) { OPJ_FLOAT32 tmp = (OPJ_FLOAT32) * datap * stepsize; *tiledp2 = tmp; @@ -1869,16 +1831,15 @@ static void opj_t1_clbl_decode_processor(void* user_data, opj_tls_t* tls) } -void opj_t1_decode_cblks(opj_tcd_t* tcd, - volatile OPJ_BOOL* pret, - opj_tcd_tilecomp_t* tilec, - opj_tccp_t* tccp, +void opj_t1_decode_cblks(opj_tcd_t *tcd, + volatile OPJ_BOOL *pret, + opj_tcd_tilecomp_t *tilec, + opj_tccp_t *tccp, opj_event_mgr_t *p_manager, - opj_mutex_t* p_manager_mutex, + opj_mutex_t *p_manager_mutex, OPJ_BOOL check_pterm - ) -{ - opj_thread_pool_t* tp = tcd->thread_pool; + ) { + opj_thread_pool_t *tp = tcd->thread_pool; OPJ_UINT32 resno, bandno, precno, cblkno; #ifdef DEBUG_VERBOSE @@ -1887,24 +1848,24 @@ void opj_t1_decode_cblks(opj_tcd_t* tcd, #endif for (resno = 0; resno < tilec->minimum_num_resolutions; ++resno) { - opj_tcd_resolution_t* res = &tilec->resolutions[resno]; + opj_tcd_resolution_t *res = &tilec->resolutions[resno]; for (bandno = 0; bandno < res->numbands; ++bandno) { - opj_tcd_band_t* OPJ_RESTRICT band = &res->bands[bandno]; + opj_tcd_band_t *OPJ_RESTRICT band = &res->bands[bandno]; for (precno = 0; precno < res->pw * res->ph; ++precno) { - opj_tcd_precinct_t* precinct = &band->precincts[precno]; + opj_tcd_precinct_t *precinct = &band->precincts[precno]; if (!opj_tcd_is_subband_area_of_interest(tcd, - tilec->compno, - resno, - band->bandno, - (OPJ_UINT32)precinct->x0, - (OPJ_UINT32)precinct->y0, - (OPJ_UINT32)precinct->x1, - (OPJ_UINT32)precinct->y1)) { + tilec->compno, + resno, + band->bandno, + (OPJ_UINT32)precinct->x0, + (OPJ_UINT32)precinct->y0, + (OPJ_UINT32)precinct->x1, + (OPJ_UINT32)precinct->y1)) { for (cblkno = 0; cblkno < precinct->cw * precinct->ch; ++cblkno) { - opj_tcd_cblk_dec_t* cblk = &precinct->cblks.dec[cblkno]; + opj_tcd_cblk_dec_t *cblk = &precinct->cblks.dec[cblkno]; if (cblk->decoded_data) { #ifdef DEBUG_VERBOSE printf("Discarding codeblock %d,%d at resno=%d, bandno=%d\n", @@ -1918,17 +1879,17 @@ void opj_t1_decode_cblks(opj_tcd_t* tcd, } for (cblkno = 0; cblkno < precinct->cw * precinct->ch; ++cblkno) { - opj_tcd_cblk_dec_t* cblk = &precinct->cblks.dec[cblkno]; - opj_t1_cblk_decode_processing_job_t* job; + opj_tcd_cblk_dec_t *cblk = &precinct->cblks.dec[cblkno]; + opj_t1_cblk_decode_processing_job_t *job; if (!opj_tcd_is_subband_area_of_interest(tcd, - tilec->compno, - resno, - band->bandno, - (OPJ_UINT32)cblk->x0, - (OPJ_UINT32)cblk->y0, - (OPJ_UINT32)cblk->x1, - (OPJ_UINT32)cblk->y1)) { + tilec->compno, + resno, + band->bandno, + (OPJ_UINT32)cblk->x0, + (OPJ_UINT32)cblk->y0, + (OPJ_UINT32)cblk->x1, + (OPJ_UINT32)cblk->y1)) { if (cblk->decoded_data) { #ifdef DEBUG_VERBOSE printf("Discarding codeblock %d,%d at resno=%d, bandno=%d\n", @@ -1959,8 +1920,8 @@ void opj_t1_decode_cblks(opj_tcd_t* tcd, #endif } - job = (opj_t1_cblk_decode_processing_job_t*) opj_calloc(1, - sizeof(opj_t1_cblk_decode_processing_job_t)); + job = (opj_t1_cblk_decode_processing_job_t *) opj_calloc(1, + sizeof(opj_t1_cblk_decode_processing_job_t)); if (!job) { *pret = OPJ_FALSE; return; @@ -1996,23 +1957,22 @@ void opj_t1_decode_cblks(opj_tcd_t* tcd, static OPJ_BOOL opj_t1_decode_cblk(opj_t1_t *t1, - opj_tcd_cblk_dec_t* cblk, + opj_tcd_cblk_dec_t *cblk, OPJ_UINT32 orient, OPJ_UINT32 roishift, OPJ_UINT32 cblksty, opj_event_mgr_t *p_manager, - opj_mutex_t* p_manager_mutex, - OPJ_BOOL check_pterm) -{ + opj_mutex_t *p_manager_mutex, + OPJ_BOOL check_pterm) { opj_mqc_t *mqc = &(t1->mqc); /* MQC component */ OPJ_INT32 bpno_plus_one; OPJ_UINT32 passtype; OPJ_UINT32 segno, passno; - OPJ_BYTE* cblkdata = NULL; + OPJ_BYTE *cblkdata = NULL; OPJ_UINT32 cblkdataindex = 0; OPJ_BYTE type = T1_TYPE_MQ; /* BYPASS mode */ - OPJ_INT32* original_t1_data = NULL; + OPJ_INT32 *original_t1_data = NULL; mqc->lut_ctxno_zc_orient = lut_ctxno_zc + (orient << 9); @@ -2064,8 +2024,8 @@ static OPJ_BOOL opj_t1_decode_cblk(opj_t1_t *t1, /* Allocate temporary memory if needed */ if (cblk_len + OPJ_COMMON_CBLK_DATA_EXTRA > t1->cblkdatabuffersize) { - cblkdata = (OPJ_BYTE*)opj_realloc(t1->cblkdatabuffer, - cblk_len + OPJ_COMMON_CBLK_DATA_EXTRA); + cblkdata = (OPJ_BYTE *)opj_realloc(t1->cblkdatabuffer, + cblk_len + OPJ_COMMON_CBLK_DATA_EXTRA); if (cblkdata == NULL) { return OPJ_FALSE; } @@ -2115,23 +2075,23 @@ static OPJ_BOOL opj_t1_decode_cblk(opj_t1_t *t1, for (passno = 0; (passno < seg->real_num_passes) && (bpno_plus_one >= 1); ++passno) { switch (passtype) { - case 0: - if (type == T1_TYPE_RAW) { - opj_t1_dec_sigpass_raw(t1, bpno_plus_one, (OPJ_INT32)cblksty); - } else { - opj_t1_dec_sigpass_mqc(t1, bpno_plus_one, (OPJ_INT32)cblksty); - } - break; - case 1: - if (type == T1_TYPE_RAW) { - opj_t1_dec_refpass_raw(t1, bpno_plus_one); - } else { - opj_t1_dec_refpass_mqc(t1, bpno_plus_one); - } - break; - case 2: - opj_t1_dec_clnpass(t1, bpno_plus_one, (OPJ_INT32)cblksty); - break; + case 0: + if (type == T1_TYPE_RAW) { + opj_t1_dec_sigpass_raw(t1, bpno_plus_one, (OPJ_INT32)cblksty); + } else { + opj_t1_dec_sigpass_mqc(t1, bpno_plus_one, (OPJ_INT32)cblksty); + } + break; + case 1: + if (type == T1_TYPE_RAW) { + opj_t1_dec_refpass_raw(t1, bpno_plus_one); + } else { + opj_t1_dec_refpass_mqc(t1, bpno_plus_one); + } + break; + case 2: + opj_t1_dec_clnpass(t1, bpno_plus_one, (OPJ_INT32)cblksty); + break; } if ((cblksty & J2K_CCP_CBLKSTY_RESET) && type == T1_TYPE_MQ) { @@ -2187,15 +2147,15 @@ static OPJ_BOOL opj_t1_decode_cblk(opj_t1_t *t1, typedef struct { OPJ_UINT32 compno; OPJ_UINT32 resno; - opj_tcd_cblk_enc_t* cblk; + opj_tcd_cblk_enc_t *cblk; opj_tcd_tile_t *tile; - opj_tcd_band_t* band; - opj_tcd_tilecomp_t* tilec; - opj_tccp_t* tccp; - const OPJ_FLOAT64 * mct_norms; + opj_tcd_band_t *band; + opj_tcd_tilecomp_t *tilec; + opj_tccp_t *tccp; + const OPJ_FLOAT64 *mct_norms; OPJ_UINT32 mct_numcomps; - volatile OPJ_BOOL* pret; - opj_mutex_t* mutex; + volatile OPJ_BOOL *pret; + opj_mutex_t *mutex; } opj_t1_cblk_encode_processing_job_t; /** Procedure to deal with a asynchronous code-block encoding job. @@ -2203,19 +2163,18 @@ typedef struct { * @param user_data Pointer to a opj_t1_cblk_encode_processing_job_t* structure * @param tls TLS handle. */ -static void opj_t1_cblk_encode_processor(void* user_data, opj_tls_t* tls) -{ - opj_t1_cblk_encode_processing_job_t* job = - (opj_t1_cblk_encode_processing_job_t*)user_data; - opj_tcd_cblk_enc_t* cblk = job->cblk; - const opj_tcd_band_t* band = job->band; - const opj_tcd_tilecomp_t* tilec = job->tilec; - const opj_tccp_t* tccp = job->tccp; +static void opj_t1_cblk_encode_processor(void *user_data, opj_tls_t *tls) { + opj_t1_cblk_encode_processing_job_t *job = + (opj_t1_cblk_encode_processing_job_t *)user_data; + opj_tcd_cblk_enc_t *cblk = job->cblk; + const opj_tcd_band_t *band = job->band; + const opj_tcd_tilecomp_t *tilec = job->tilec; + const opj_tccp_t *tccp = job->tccp; const OPJ_UINT32 resno = job->resno; - opj_t1_t* t1; + opj_t1_t *t1; const OPJ_UINT32 tile_w = (OPJ_UINT32)(tilec->x1 - tilec->x0); - OPJ_INT32* OPJ_RESTRICT tiledp; + OPJ_INT32 *OPJ_RESTRICT tiledp; OPJ_UINT32 cblk_w; OPJ_UINT32 cblk_h; OPJ_UINT32 i, j; @@ -2228,7 +2187,7 @@ static void opj_t1_cblk_encode_processor(void* user_data, opj_tls_t* tls) return; } - t1 = (opj_t1_t*) opj_tls_get(tls, OPJ_TLS_KEY_T1); + t1 = (opj_t1_t *) opj_tls_get(tls, OPJ_TLS_KEY_T1); if (t1 == NULL) { t1 = opj_t1_create(OPJ_TRUE); /* OPJ_TRUE == T1 for encoding */ opj_tls_set(tls, OPJ_TLS_KEY_T1, t1, opj_t1_destroy_wrapper); @@ -2266,28 +2225,28 @@ static void opj_t1_cblk_encode_processor(void* user_data, opj_tls_t* tls) * representation * Fixes https://github.com/uclouvain/openjpeg/issues/1053 */ - OPJ_UINT32* OPJ_RESTRICT tiledp_u = (OPJ_UINT32*) tiledp; - OPJ_UINT32* OPJ_RESTRICT t1data = (OPJ_UINT32*) t1->data; + OPJ_UINT32 *OPJ_RESTRICT tiledp_u = (OPJ_UINT32 *) tiledp; + OPJ_UINT32 *OPJ_RESTRICT t1data = (OPJ_UINT32 *) t1->data; /* Change from "natural" order to "zigzag" order of T1 passes */ for (j = 0; j < (cblk_h & ~3U); j += 4) { #if defined(__AVX512F__) const __m512i perm1 = _mm512_setr_epi64(2, 3, 10, 11, 4, 5, 12, 13); const __m512i perm2 = _mm512_setr_epi64(6, 7, 14, 15, 0, 0, 0, 0); - OPJ_UINT32* ptr = tiledp_u; + OPJ_UINT32 *ptr = tiledp_u; for (i = 0; i < cblk_w / 16; ++i) { // INPUT OUTPUT // 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 00 10 20 30 01 11 21 31 02 12 22 32 03 13 23 33 // 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 04 14 24 34 05 15 25 35 06 16 26 36 07 17 27 37 // 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F 08 18 28 38 09 19 29 39 0A 1A 2A 3A 0B 1B 2B 3B // 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F 0C 1C 2C 3C 0D 1D 2D 3D 0E 1E 2E 3E 0F 1F 2F 3F - __m512i in1 = _mm512_slli_epi32(_mm512_loadu_si512((__m512i*)(ptr + - (j + 0) * tile_w)), T1_NMSEDEC_FRACBITS); - __m512i in2 = _mm512_slli_epi32(_mm512_loadu_si512((__m512i*)(ptr + - (j + 1) * tile_w)), T1_NMSEDEC_FRACBITS); - __m512i in3 = _mm512_slli_epi32(_mm512_loadu_si512((__m512i*)(ptr + - (j + 2) * tile_w)), T1_NMSEDEC_FRACBITS); - __m512i in4 = _mm512_slli_epi32(_mm512_loadu_si512((__m512i*)(ptr + - (j + 3) * tile_w)), T1_NMSEDEC_FRACBITS); + __m512i in1 = _mm512_slli_epi32(_mm512_loadu_si512((__m512i *)(ptr + + (j + 0) * tile_w)), T1_NMSEDEC_FRACBITS); + __m512i in2 = _mm512_slli_epi32(_mm512_loadu_si512((__m512i *)(ptr + + (j + 1) * tile_w)), T1_NMSEDEC_FRACBITS); + __m512i in3 = _mm512_slli_epi32(_mm512_loadu_si512((__m512i *)(ptr + + (j + 2) * tile_w)), T1_NMSEDEC_FRACBITS); + __m512i in4 = _mm512_slli_epi32(_mm512_loadu_si512((__m512i *)(ptr + + (j + 3) * tile_w)), T1_NMSEDEC_FRACBITS); __m512i tmp1 = _mm512_unpacklo_epi32(in1, in2); __m512i tmp2 = _mm512_unpacklo_epi32(in3, in4); @@ -2299,23 +2258,23 @@ static void opj_t1_cblk_encode_processor(void* user_data, opj_tls_t* tls) in3 = _mm512_unpackhi_epi64(tmp1, tmp2); in4 = _mm512_unpackhi_epi64(tmp3, tmp4); - _mm_storeu_si128((__m128i*)(t1data + 0), _mm512_castsi512_si128(in1)); - _mm_storeu_si128((__m128i*)(t1data + 4), _mm512_castsi512_si128(in3)); - _mm_storeu_si128((__m128i*)(t1data + 8), _mm512_castsi512_si128(in2)); - _mm_storeu_si128((__m128i*)(t1data + 12), _mm512_castsi512_si128(in4)); + _mm_storeu_si128((__m128i *)(t1data + 0), _mm512_castsi512_si128(in1)); + _mm_storeu_si128((__m128i *)(t1data + 4), _mm512_castsi512_si128(in3)); + _mm_storeu_si128((__m128i *)(t1data + 8), _mm512_castsi512_si128(in2)); + _mm_storeu_si128((__m128i *)(t1data + 12), _mm512_castsi512_si128(in4)); tmp1 = _mm512_permutex2var_epi64(in1, perm1, in3); tmp2 = _mm512_permutex2var_epi64(in2, perm1, in4); - _mm256_storeu_si256((__m256i*)(t1data + 16), _mm512_castsi512_si256(tmp1)); - _mm256_storeu_si256((__m256i*)(t1data + 24), _mm512_castsi512_si256(tmp2)); - _mm256_storeu_si256((__m256i*)(t1data + 32), _mm512_extracti64x4_epi64(tmp1, + _mm256_storeu_si256((__m256i *)(t1data + 16), _mm512_castsi512_si256(tmp1)); + _mm256_storeu_si256((__m256i *)(t1data + 24), _mm512_castsi512_si256(tmp2)); + _mm256_storeu_si256((__m256i *)(t1data + 32), _mm512_extracti64x4_epi64(tmp1, 0x1)); - _mm256_storeu_si256((__m256i*)(t1data + 40), _mm512_extracti64x4_epi64(tmp2, + _mm256_storeu_si256((__m256i *)(t1data + 40), _mm512_extracti64x4_epi64(tmp2, 0x1)); - _mm256_storeu_si256((__m256i*)(t1data + 48), + _mm256_storeu_si256((__m256i *)(t1data + 48), _mm512_castsi512_si256(_mm512_permutex2var_epi64(in1, perm2, in3))); - _mm256_storeu_si256((__m256i*)(t1data + 56), + _mm256_storeu_si256((__m256i *)(t1data + 56), _mm512_castsi512_si256(_mm512_permutex2var_epi64(in2, perm2, in4))); t1data += 64; ptr += 16; @@ -2329,21 +2288,21 @@ static void opj_t1_cblk_encode_processor(void* user_data, opj_tls_t* tls) ptr += 1; } #elif defined(__AVX2__) - OPJ_UINT32* ptr = tiledp_u; + OPJ_UINT32 *ptr = tiledp_u; for (i = 0; i < cblk_w / 8; ++i) { // INPUT OUTPUT // 00 01 02 03 04 05 06 07 00 10 20 30 01 11 21 31 // 10 11 12 13 14 15 16 17 02 12 22 32 03 13 23 33 // 20 21 22 23 24 25 26 27 04 14 24 34 05 15 25 35 // 30 31 32 33 34 35 36 37 06 16 26 36 07 17 27 37 - __m256i in1 = _mm256_slli_epi32(_mm256_loadu_si256((__m256i*)(ptr + - (j + 0) * tile_w)), T1_NMSEDEC_FRACBITS); - __m256i in2 = _mm256_slli_epi32(_mm256_loadu_si256((__m256i*)(ptr + - (j + 1) * tile_w)), T1_NMSEDEC_FRACBITS); - __m256i in3 = _mm256_slli_epi32(_mm256_loadu_si256((__m256i*)(ptr + - (j + 2) * tile_w)), T1_NMSEDEC_FRACBITS); - __m256i in4 = _mm256_slli_epi32(_mm256_loadu_si256((__m256i*)(ptr + - (j + 3) * tile_w)), T1_NMSEDEC_FRACBITS); + __m256i in1 = _mm256_slli_epi32(_mm256_loadu_si256((__m256i *)(ptr + + (j + 0) * tile_w)), T1_NMSEDEC_FRACBITS); + __m256i in2 = _mm256_slli_epi32(_mm256_loadu_si256((__m256i *)(ptr + + (j + 1) * tile_w)), T1_NMSEDEC_FRACBITS); + __m256i in3 = _mm256_slli_epi32(_mm256_loadu_si256((__m256i *)(ptr + + (j + 2) * tile_w)), T1_NMSEDEC_FRACBITS); + __m256i in4 = _mm256_slli_epi32(_mm256_loadu_si256((__m256i *)(ptr + + (j + 3) * tile_w)), T1_NMSEDEC_FRACBITS); __m256i tmp1 = _mm256_unpacklo_epi32(in1, in2); __m256i tmp2 = _mm256_unpacklo_epi32(in3, in4); @@ -2355,13 +2314,13 @@ static void opj_t1_cblk_encode_processor(void* user_data, opj_tls_t* tls) in3 = _mm256_unpackhi_epi64(tmp1, tmp2); in4 = _mm256_unpackhi_epi64(tmp3, tmp4); - _mm_storeu_si128((__m128i*)(t1data + 0), _mm256_castsi256_si128(in1)); - _mm_storeu_si128((__m128i*)(t1data + 4), _mm256_castsi256_si128(in3)); - _mm_storeu_si128((__m128i*)(t1data + 8), _mm256_castsi256_si128(in2)); - _mm_storeu_si128((__m128i*)(t1data + 12), _mm256_castsi256_si128(in4)); - _mm256_storeu_si256((__m256i*)(t1data + 16), _mm256_permute2x128_si256(in1, in3, + _mm_storeu_si128((__m128i *)(t1data + 0), _mm256_castsi256_si128(in1)); + _mm_storeu_si128((__m128i *)(t1data + 4), _mm256_castsi256_si128(in3)); + _mm_storeu_si128((__m128i *)(t1data + 8), _mm256_castsi256_si128(in2)); + _mm_storeu_si128((__m128i *)(t1data + 12), _mm256_castsi256_si128(in4)); + _mm256_storeu_si256((__m256i *)(t1data + 16), _mm256_permute2x128_si256(in1, in3, 0x31)); - _mm256_storeu_si256((__m256i*)(t1data + 24), _mm256_permute2x128_si256(in2, in4, + _mm256_storeu_si256((__m256i *)(t1data + 24), _mm256_permute2x128_si256(in2, in4, 0x31)); t1data += 32; ptr += 8; @@ -2394,8 +2353,8 @@ static void opj_t1_cblk_encode_processor(void* user_data, opj_tls_t* tls) } } } else { /* if (tccp->qmfbid == 0) */ - OPJ_FLOAT32* OPJ_RESTRICT tiledp_f = (OPJ_FLOAT32*) tiledp; - OPJ_INT32* OPJ_RESTRICT t1data = t1->data; + OPJ_FLOAT32 *OPJ_RESTRICT tiledp_f = (OPJ_FLOAT32 *) tiledp; + OPJ_INT32 *OPJ_RESTRICT t1data = t1->data; /* Change from "natural" order to "zigzag" order of T1 passes */ for (j = 0; j < (cblk_h & ~3U); j += 4) { for (i = 0; i < cblk_w; ++i) { @@ -2449,29 +2408,28 @@ static void opj_t1_cblk_encode_processor(void* user_data, opj_tls_t* tls) } -OPJ_BOOL opj_t1_encode_cblks(opj_tcd_t* tcd, +OPJ_BOOL opj_t1_encode_cblks(opj_tcd_t *tcd, opj_tcd_tile_t *tile, opj_tcp_t *tcp, - const OPJ_FLOAT64 * mct_norms, + const OPJ_FLOAT64 *mct_norms, OPJ_UINT32 mct_numcomps - ) -{ + ) { volatile OPJ_BOOL ret = OPJ_TRUE; - opj_thread_pool_t* tp = tcd->thread_pool; + opj_thread_pool_t *tp = tcd->thread_pool; OPJ_UINT32 compno, resno, bandno, precno, cblkno; - opj_mutex_t* mutex = opj_mutex_create(); + opj_mutex_t *mutex = opj_mutex_create(); tile->distotile = 0; for (compno = 0; compno < tile->numcomps; ++compno) { - opj_tcd_tilecomp_t* tilec = &tile->comps[compno]; - opj_tccp_t* tccp = &tcp->tccps[compno]; + opj_tcd_tilecomp_t *tilec = &tile->comps[compno]; + opj_tccp_t *tccp = &tcp->tccps[compno]; for (resno = 0; resno < tilec->numresolutions; ++resno) { opj_tcd_resolution_t *res = &tilec->resolutions[resno]; for (bandno = 0; bandno < res->numbands; ++bandno) { - opj_tcd_band_t* OPJ_RESTRICT band = &res->bands[bandno]; + opj_tcd_band_t *OPJ_RESTRICT band = &res->bands[bandno]; /* Skip empty bands */ if (opj_tcd_is_band_empty(band)) { @@ -2481,11 +2439,11 @@ OPJ_BOOL opj_t1_encode_cblks(opj_tcd_t* tcd, opj_tcd_precinct_t *prc = &band->precincts[precno]; for (cblkno = 0; cblkno < prc->cw * prc->ch; ++cblkno) { - opj_tcd_cblk_enc_t* cblk = &prc->cblks.enc[cblkno]; + opj_tcd_cblk_enc_t *cblk = &prc->cblks.enc[cblkno]; - opj_t1_cblk_encode_processing_job_t* job = - (opj_t1_cblk_encode_processing_job_t*) opj_calloc(1, - sizeof(opj_t1_cblk_encode_processing_job_t)); + opj_t1_cblk_encode_processing_job_t *job = + (opj_t1_cblk_encode_processing_job_t *) opj_calloc(1, + sizeof(opj_t1_cblk_encode_processing_job_t)); if (!job) { ret = OPJ_FALSE; goto end; @@ -2519,11 +2477,10 @@ end: } /* Returns whether the pass (bpno, passtype) is terminated */ -static int opj_t1_enc_is_term_pass(opj_tcd_cblk_enc_t* cblk, +static int opj_t1_enc_is_term_pass(opj_tcd_cblk_enc_t *cblk, OPJ_UINT32 cblksty, OPJ_INT32 bpno, - OPJ_UINT32 passtype) -{ + OPJ_UINT32 passtype) { /* Is it the last cleanup pass ? */ if (passtype == 2 && bpno == 0) { return OPJ_TRUE; @@ -2550,7 +2507,7 @@ static int opj_t1_enc_is_term_pass(opj_tcd_cblk_enc_t* cblk, static OPJ_FLOAT64 opj_t1_encode_cblk(opj_t1_t *t1, - opj_tcd_cblk_enc_t* cblk, + opj_tcd_cblk_enc_t *cblk, OPJ_UINT32 orient, OPJ_UINT32 compno, OPJ_UINT32 level, @@ -2558,9 +2515,8 @@ static OPJ_FLOAT64 opj_t1_encode_cblk(opj_t1_t *t1, OPJ_FLOAT64 stepsize, OPJ_UINT32 cblksty, OPJ_UINT32 numcomps, - const OPJ_FLOAT64 * mct_norms, - OPJ_UINT32 mct_numcomps) -{ + const OPJ_FLOAT64 *mct_norms, + OPJ_UINT32 mct_numcomps) { OPJ_FLOAT64 cumwmsedec = 0.0; opj_mqc_t *mqc = &(t1->mqc); /* MQC component */ @@ -2573,7 +2529,7 @@ static OPJ_FLOAT64 opj_t1_encode_cblk(opj_t1_t *t1, OPJ_UINT32 i, j; OPJ_BYTE type = T1_TYPE_MQ; OPJ_FLOAT64 tempwmsedec; - OPJ_INT32* datap; + OPJ_INT32 *datap; #ifdef EXTRA_DEBUG printf("encode_cblk(x=%d,y=%d,x1=%d,y1=%d,orient=%d,compno=%d,level=%d\n", @@ -2637,19 +2593,19 @@ static OPJ_FLOAT64 opj_t1_encode_cblk(opj_t1_t *t1, } switch (passtype) { - case 0: - opj_t1_enc_sigpass(t1, bpno, &nmsedec, type, cblksty); - break; - case 1: - opj_t1_enc_refpass(t1, bpno, &nmsedec, type); - break; - case 2: - opj_t1_enc_clnpass(t1, bpno, &nmsedec, cblksty); - /* code switch SEGMARK (i.e. SEGSYM) */ - if (cblksty & J2K_CCP_CBLKSTY_SEGSYM) { - opj_mqc_segmark_enc(mqc); - } - break; + case 0: + opj_t1_enc_sigpass(t1, bpno, &nmsedec, type, cblksty); + break; + case 1: + opj_t1_enc_refpass(t1, bpno, &nmsedec, type); + break; + case 2: + opj_t1_enc_clnpass(t1, bpno, &nmsedec, cblksty); + /* code switch SEGMARK (i.e. SEGSYM) */ + if (cblksty & J2K_CCP_CBLKSTY_SEGSYM) { + opj_mqc_segmark_enc(mqc); + } + break; } tempwmsedec = opj_t1_getwmsedec(nmsedec, compno, level, orient, bpno, qmfbid, diff --git a/client/deps/openjpeg/t1.h b/client/deps/openjpeg/t1.h index ce43658ba..2817994d2 100644 --- a/client/deps/openjpeg/t1.h +++ b/client/deps/openjpeg/t1.h @@ -221,10 +221,10 @@ Encode the code-blocks of a tile @param mct_norms FIXME DOC @param mct_numcomps Number of components used for MCT */ -OPJ_BOOL opj_t1_encode_cblks(opj_tcd_t* tcd, +OPJ_BOOL opj_t1_encode_cblks(opj_tcd_t *tcd, opj_tcd_tile_t *tile, opj_tcp_t *tcp, - const OPJ_FLOAT64 * mct_norms, + const OPJ_FLOAT64 *mct_norms, OPJ_UINT32 mct_numcomps); /** @@ -237,12 +237,12 @@ Decode the code-blocks of a tile @param p_manager_mutex mutex for the event manager @param check_pterm whether PTERM correct termination should be checked */ -void opj_t1_decode_cblks(opj_tcd_t* tcd, - volatile OPJ_BOOL* pret, - opj_tcd_tilecomp_t* tilec, - opj_tccp_t* tccp, +void opj_t1_decode_cblks(opj_tcd_t *tcd, + volatile OPJ_BOOL *pret, + opj_tcd_tilecomp_t *tilec, + opj_tccp_t *tccp, opj_event_mgr_t *p_manager, - opj_mutex_t* p_manager_mutex, + opj_mutex_t *p_manager_mutex, OPJ_BOOL check_pterm); @@ -252,7 +252,7 @@ void opj_t1_decode_cblks(opj_tcd_t* tcd, * and initializes the look-up tables of the Tier-1 coder/decoder * @return a new T1 handle if successful, returns NULL otherwise */ -opj_t1_t* opj_t1_create(OPJ_BOOL isEncoder); +opj_t1_t *opj_t1_create(OPJ_BOOL isEncoder); /** * Destroys a previously created T1 handle diff --git a/client/deps/openjpeg/t1_ht_luts.h b/client/deps/openjpeg/t1_ht_luts.h index f39d5d057..393a987b0 100644 --- a/client/deps/openjpeg/t1_ht_luts.h +++ b/client/deps/openjpeg/t1_ht_luts.h @@ -258,4 +258,4 @@ static const OPJ_UINT16 vlc_tbl1[1024] = { 0x00f3, 0x00ae, 0xf2fd, 0xffff, 0x00d5, 0x0046, 0xf5fe, 0x323f, 0x00f3, 0x00e6, 0xf8fd, 0x0016, 0x0004, 0x0086, 0x0055, 0x006f, 0x00f3, 0x00c6, 0x00b5, 0xb8bf, 0xf4fd, 0x115e, 0xa8ee, 0x222f -}; \ No newline at end of file +}; diff --git a/client/deps/openjpeg/t2.c b/client/deps/openjpeg/t2.c index 4e8cf6018..25808e811 100644 --- a/client/deps/openjpeg/t2.c +++ b/client/deps/openjpeg/t2.c @@ -78,7 +78,7 @@ static OPJ_BOOL opj_t2_encode_packet(OPJ_UINT32 tileno, opj_tcp_t *tcp, opj_pi_iterator_t *pi, OPJ_BYTE *dest, - OPJ_UINT32 * p_data_written, + OPJ_UINT32 *p_data_written, OPJ_UINT32 len, opj_codestream_info_t *cstr_info, J2K_T2_MODE p_t2_mode, @@ -98,50 +98,50 @@ Decode a packet of a tile from a source buffer @return FIXME DOC */ -static OPJ_BOOL opj_t2_decode_packet(opj_t2_t* t2, +static OPJ_BOOL opj_t2_decode_packet(opj_t2_t *t2, opj_tcd_tile_t *tile, opj_tcp_t *tcp, opj_pi_iterator_t *pi, OPJ_BYTE *src, - OPJ_UINT32 * data_read, + OPJ_UINT32 *data_read, OPJ_UINT32 max_length, opj_packet_info_t *pack_info, opj_event_mgr_t *p_manager); -static OPJ_BOOL opj_t2_skip_packet(opj_t2_t* p_t2, +static OPJ_BOOL opj_t2_skip_packet(opj_t2_t *p_t2, opj_tcd_tile_t *p_tile, opj_tcp_t *p_tcp, opj_pi_iterator_t *p_pi, OPJ_BYTE *p_src, - OPJ_UINT32 * p_data_read, + OPJ_UINT32 *p_data_read, OPJ_UINT32 p_max_length, opj_packet_info_t *p_pack_info, opj_event_mgr_t *p_manager); -static OPJ_BOOL opj_t2_read_packet_header(opj_t2_t* p_t2, - opj_tcd_tile_t *p_tile, - opj_tcp_t *p_tcp, - opj_pi_iterator_t *p_pi, - OPJ_BOOL * p_is_data_present, - OPJ_BYTE *p_src_data, - OPJ_UINT32 * p_data_read, - OPJ_UINT32 p_max_length, - opj_packet_info_t *p_pack_info, - opj_event_mgr_t *p_manager); +static OPJ_BOOL opj_t2_read_packet_header(opj_t2_t *p_t2, + opj_tcd_tile_t *p_tile, + opj_tcp_t *p_tcp, + opj_pi_iterator_t *p_pi, + OPJ_BOOL *p_is_data_present, + OPJ_BYTE *p_src_data, + OPJ_UINT32 *p_data_read, + OPJ_UINT32 p_max_length, + opj_packet_info_t *p_pack_info, + opj_event_mgr_t *p_manager); -static OPJ_BOOL opj_t2_read_packet_data(opj_t2_t* p_t2, +static OPJ_BOOL opj_t2_read_packet_data(opj_t2_t *p_t2, opj_tcd_tile_t *p_tile, opj_pi_iterator_t *p_pi, OPJ_BYTE *p_src_data, - OPJ_UINT32 * p_data_read, + OPJ_UINT32 *p_data_read, OPJ_UINT32 p_max_length, opj_packet_info_t *pack_info, opj_event_mgr_t *p_manager); -static OPJ_BOOL opj_t2_skip_packet_data(opj_t2_t* p_t2, +static OPJ_BOOL opj_t2_skip_packet_data(opj_t2_t *p_t2, opj_tcd_tile_t *p_tile, opj_pi_iterator_t *p_pi, - OPJ_UINT32 * p_data_read, + OPJ_UINT32 *p_data_read, OPJ_UINT32 p_max_length, opj_packet_info_t *pack_info, opj_event_mgr_t *p_manager); @@ -152,7 +152,7 @@ static OPJ_BOOL opj_t2_skip_packet_data(opj_t2_t* p_t2, @param cblksty @param first */ -static OPJ_BOOL opj_t2_init_seg(opj_tcd_cblk_dec_t* cblk, +static OPJ_BOOL opj_t2_init_seg(opj_tcd_cblk_dec_t *cblk, OPJ_UINT32 index, OPJ_UINT32 cblksty, OPJ_UINT32 first); @@ -164,16 +164,14 @@ static OPJ_BOOL opj_t2_init_seg(opj_tcd_cblk_dec_t* cblk, /* ----------------------------------------------------------------------- */ /* #define RESTART 0x04 */ -static void opj_t2_putcommacode(opj_bio_t *bio, OPJ_INT32 n) -{ +static void opj_t2_putcommacode(opj_bio_t *bio, OPJ_INT32 n) { while (--n >= 0) { opj_bio_putbit(bio, 1); } opj_bio_putbit(bio, 0); } -static OPJ_UINT32 opj_t2_getcommacode(opj_bio_t *bio) -{ +static OPJ_UINT32 opj_t2_getcommacode(opj_bio_t *bio) { OPJ_UINT32 n = 0; while (opj_bio_read(bio, 1)) { ++n; @@ -181,8 +179,7 @@ static OPJ_UINT32 opj_t2_getcommacode(opj_bio_t *bio) return n; } -static void opj_t2_putnumpasses(opj_bio_t *bio, OPJ_UINT32 n) -{ +static void opj_t2_putnumpasses(opj_bio_t *bio, OPJ_UINT32 n) { if (n == 1) { opj_bio_putbit(bio, 0); } else if (n == 2) { @@ -196,8 +193,7 @@ static void opj_t2_putnumpasses(opj_bio_t *bio, OPJ_UINT32 n) } } -static OPJ_UINT32 opj_t2_getnumpasses(opj_bio_t *bio) -{ +static OPJ_UINT32 opj_t2_getnumpasses(opj_bio_t *bio) { OPJ_UINT32 n; if (!opj_bio_read(bio, 1)) { return 1; @@ -216,21 +212,20 @@ static OPJ_UINT32 opj_t2_getnumpasses(opj_bio_t *bio) /* ----------------------------------------------------------------------- */ -OPJ_BOOL opj_t2_encode_packets(opj_t2_t* p_t2, +OPJ_BOOL opj_t2_encode_packets(opj_t2_t *p_t2, OPJ_UINT32 p_tile_no, opj_tcd_tile_t *p_tile, OPJ_UINT32 p_maxlayers, OPJ_BYTE *p_dest, - OPJ_UINT32 * p_data_written, + OPJ_UINT32 *p_data_written, OPJ_UINT32 p_max_len, opj_codestream_info_t *cstr_info, - opj_tcd_marker_info_t* p_marker_info, + opj_tcd_marker_info_t *p_marker_info, OPJ_UINT32 p_tp_num, OPJ_INT32 p_tp_pos, OPJ_UINT32 p_pino, J2K_T2_MODE p_t2_mode, - opj_event_mgr_t *p_manager) -{ + opj_event_mgr_t *p_manager) { OPJ_BYTE *l_current_data = p_dest; OPJ_UINT32 l_nb_bytes = 0; OPJ_UINT32 compno; @@ -317,7 +312,7 @@ OPJ_BOOL opj_t2_encode_packets(opj_t2_t* p_t2, assert(p_marker_info->packet_count == 0); assert(p_marker_info->p_packet_size == NULL); - p_marker_info->p_packet_size = (OPJ_UINT32*) opj_malloc( + p_marker_info->p_packet_size = (OPJ_UINT32 *) opj_malloc( opj_get_encoding_packet_count(l_image, l_cp, p_tile_no) * sizeof(OPJ_UINT32)); if (p_marker_info->p_packet_size == NULL) { opj_pi_destroy(l_pi, l_nb_pocs); @@ -382,24 +377,22 @@ OPJ_BOOL opj_t2_encode_packets(opj_t2_t* p_t2, #define JAS_FPRINTF fprintf #else /* issue 290 */ -static void opj_null_jas_fprintf(FILE* file, const char * format, ...) -{ +static void opj_null_jas_fprintf(FILE *file, const char *format, ...) { (void)file; (void)format; } #define JAS_FPRINTF opj_null_jas_fprintf #endif -OPJ_BOOL opj_t2_decode_packets(opj_tcd_t* tcd, +OPJ_BOOL opj_t2_decode_packets(opj_tcd_t *tcd, opj_t2_t *p_t2, OPJ_UINT32 p_tile_no, opj_tcd_tile_t *p_tile, OPJ_BYTE *p_src, - OPJ_UINT32 * p_data_read, + OPJ_UINT32 *p_data_read, OPJ_UINT32 p_max_len, opj_codestream_index_t *p_cstr_index, - opj_event_mgr_t *p_manager) -{ + opj_event_mgr_t *p_manager) { OPJ_BYTE *l_current_data = p_src; opj_pi_iterator_t *l_pi = 00; OPJ_UINT32 pino; @@ -414,7 +407,7 @@ OPJ_BOOL opj_t2_decode_packets(opj_tcd_t* tcd, OPJ_UINT32 tp_start_packno; #endif opj_packet_info_t *l_pack_info = 00; - opj_image_comp_t* l_img_comp = 00; + opj_image_comp_t *l_img_comp = 00; OPJ_ARG_NOT_USED(p_cstr_index); @@ -440,7 +433,7 @@ OPJ_BOOL opj_t2_decode_packets(opj_tcd_t* tcd, * l_current_pi->resno is always >= p_tile->comps[l_current_pi->compno].minimum_num_resolutions * and no l_img_comp->resno_decoded are computed */ - OPJ_BOOL* first_pass_failed = NULL; + OPJ_BOOL *first_pass_failed = NULL; if (l_current_pi->poc.prg == OPJ_PROG_UNKNOWN) { /* TODO ADE : add an error */ @@ -448,7 +441,7 @@ OPJ_BOOL opj_t2_decode_packets(opj_tcd_t* tcd, return OPJ_FALSE; } - first_pass_failed = (OPJ_BOOL*)opj_malloc(l_image->numcomps * sizeof(OPJ_BOOL)); + first_pass_failed = (OPJ_BOOL *)opj_malloc(l_image->numcomps * sizeof(OPJ_BOOL)); if (!first_pass_failed) { opj_pi_destroy(l_pi, l_nb_pocs); return OPJ_FALSE; @@ -481,8 +474,8 @@ OPJ_BOOL opj_t2_decode_packets(opj_tcd_t* tcd, skip_packet = OPJ_TRUE; for (bandno = 0; bandno < res->numbands; ++bandno) { - opj_tcd_band_t* band = &res->bands[bandno]; - opj_tcd_precinct_t* prec = &band->precincts[l_current_pi->precno]; + opj_tcd_band_t *band = &res->bands[bandno]; + opj_tcd_precinct_t *prec = &band->precincts[l_current_pi->precno]; if (opj_tcd_is_subband_area_of_interest(tcd, l_current_pi->compno, @@ -516,7 +509,7 @@ OPJ_BOOL opj_t2_decode_packets(opj_tcd_t* tcd, l_img_comp = &(l_image->comps[l_current_pi->compno]); l_img_comp->resno_decoded = opj_uint_max(l_current_pi->resno, - l_img_comp->resno_decoded); + l_img_comp->resno_decoded); } else { l_nb_bytes_read = 0; if (! opj_t2_skip_packet(p_t2, p_tile, l_tcp, l_current_pi, l_current_data, @@ -576,7 +569,7 @@ OPJ_BOOL opj_t2_decode_packets(opj_tcd_t* tcd, if (p_cstr_info) { p_cstr_info->tile[p_tile_no].tp[curtp].tp_numpacks = p_cstr_info->packno - - tp_start_packno; /* Number of packets in last tile-part */ + tp_start_packno; /* Number of packets in last tile-part */ } #endif /* << INDEX */ @@ -596,10 +589,9 @@ OPJ_BOOL opj_t2_decode_packets(opj_tcd_t* tcd, * @param p_cp Image coding parameters. * @return a new T2 handle if successful, NULL otherwise. */ -opj_t2_t* opj_t2_create(opj_image_t *p_image, opj_cp_t *p_cp) -{ +opj_t2_t *opj_t2_create(opj_image_t *p_image, opj_cp_t *p_cp) { /* create the t2 structure */ - opj_t2_t *l_t2 = (opj_t2_t*)opj_calloc(1, sizeof(opj_t2_t)); + opj_t2_t *l_t2 = (opj_t2_t *)opj_calloc(1, sizeof(opj_t2_t)); if (!l_t2) { return NULL; } @@ -610,23 +602,21 @@ opj_t2_t* opj_t2_create(opj_image_t *p_image, opj_cp_t *p_cp) return l_t2; } -void opj_t2_destroy(opj_t2_t *t2) -{ +void opj_t2_destroy(opj_t2_t *t2) { if (t2) { opj_free(t2); } } -static OPJ_BOOL opj_t2_decode_packet(opj_t2_t* p_t2, +static OPJ_BOOL opj_t2_decode_packet(opj_t2_t *p_t2, opj_tcd_tile_t *p_tile, opj_tcp_t *p_tcp, opj_pi_iterator_t *p_pi, OPJ_BYTE *p_src, - OPJ_UINT32 * p_data_read, + OPJ_UINT32 *p_data_read, OPJ_UINT32 p_max_length, opj_packet_info_t *p_pack_info, - opj_event_mgr_t *p_manager) -{ + opj_event_mgr_t *p_manager) { OPJ_BOOL l_read_data; OPJ_UINT32 l_nb_bytes_read = 0; OPJ_UINT32 l_nb_total_bytes_read = 0; @@ -660,18 +650,17 @@ static OPJ_BOOL opj_t2_decode_packet(opj_t2_t* p_t2, } static OPJ_BOOL opj_t2_encode_packet(OPJ_UINT32 tileno, - opj_tcd_tile_t * tile, - opj_tcp_t * tcp, + opj_tcd_tile_t *tile, + opj_tcp_t *tcp, opj_pi_iterator_t *pi, OPJ_BYTE *dest, - OPJ_UINT32 * p_data_written, + OPJ_UINT32 *p_data_written, OPJ_UINT32 length, opj_codestream_info_t *cstr_info, J2K_T2_MODE p_t2_mode, - opj_event_mgr_t *p_manager) -{ + opj_event_mgr_t *p_manager) { OPJ_UINT32 bandno, cblkno; - OPJ_BYTE* c = dest; + OPJ_BYTE *c = dest; OPJ_UINT32 l_nb_bytes; OPJ_UINT32 compno = pi->compno; /* component value */ OPJ_UINT32 resno = pi->resno; /* resolution level value */ @@ -679,7 +668,7 @@ static OPJ_BOOL opj_t2_encode_packet(OPJ_UINT32 tileno, OPJ_UINT32 layno = pi->layno; /* quality layer value */ OPJ_UINT32 l_nb_blocks; opj_tcd_band_t *band = 00; - opj_tcd_cblk_enc_t* cblk = 00; + opj_tcd_cblk_enc_t *cblk = 00; opj_tcd_pass_t *pass = 00; opj_tcd_tilecomp_t *tilec = &tile->comps[compno]; @@ -1005,16 +994,15 @@ static OPJ_BOOL opj_t2_encode_packet(OPJ_UINT32 tileno, return OPJ_TRUE; } -static OPJ_BOOL opj_t2_skip_packet(opj_t2_t* p_t2, +static OPJ_BOOL opj_t2_skip_packet(opj_t2_t *p_t2, opj_tcd_tile_t *p_tile, opj_tcp_t *p_tcp, opj_pi_iterator_t *p_pi, OPJ_BYTE *p_src, - OPJ_UINT32 * p_data_read, + OPJ_UINT32 *p_data_read, OPJ_UINT32 p_max_length, opj_packet_info_t *p_pack_info, - opj_event_mgr_t *p_manager) -{ + opj_event_mgr_t *p_manager) { OPJ_BOOL l_read_data; OPJ_UINT32 l_nb_bytes_read = 0; OPJ_UINT32 l_nb_total_bytes_read = 0; @@ -1047,16 +1035,16 @@ static OPJ_BOOL opj_t2_skip_packet(opj_t2_t* p_t2, } -static OPJ_BOOL opj_t2_read_packet_header(opj_t2_t* p_t2, - opj_tcd_tile_t *p_tile, - opj_tcp_t *p_tcp, - opj_pi_iterator_t *p_pi, - OPJ_BOOL * p_is_data_present, - OPJ_BYTE *p_src_data, - OPJ_UINT32 * p_data_read, - OPJ_UINT32 p_max_length, - opj_packet_info_t *p_pack_info, - opj_event_mgr_t *p_manager) +static OPJ_BOOL opj_t2_read_packet_header(opj_t2_t *p_t2, + opj_tcd_tile_t *p_tile, + opj_tcp_t *p_tcp, + opj_pi_iterator_t *p_pi, + OPJ_BOOL *p_is_data_present, + OPJ_BYTE *p_src_data, + OPJ_UINT32 *p_data_read, + OPJ_UINT32 p_max_length, + opj_packet_info_t *p_pack_info, + opj_event_mgr_t *p_manager) { /* loop */ @@ -1064,13 +1052,13 @@ static OPJ_BOOL opj_t2_read_packet_header(opj_t2_t* p_t2, OPJ_UINT32 l_nb_code_blocks; OPJ_UINT32 l_remaining_length; OPJ_UINT32 l_header_length; - OPJ_UINT32 * l_modified_length_ptr = 00; + OPJ_UINT32 *l_modified_length_ptr = 00; OPJ_BYTE *l_current_data = p_src_data; opj_cp_t *l_cp = p_t2->cp; opj_bio_t *l_bio = 00; /* BIO component */ opj_tcd_band_t *l_band = 00; - opj_tcd_cblk_dec_t* l_cblk = 00; - opj_tcd_resolution_t* l_res = + opj_tcd_cblk_dec_t *l_cblk = 00; + opj_tcd_resolution_t *l_res = &p_tile->comps[p_pi->compno].resolutions[p_pi->resno]; OPJ_BYTE *l_header_data = 00; @@ -1166,7 +1154,7 @@ static OPJ_BOOL opj_t2_read_packet_header(opj_t2_t* p_t2, if (p_tcp->csty & J2K_CP_CSTY_EPH) { /* EPH markers are required */ if ((*l_modified_length_ptr - (OPJ_UINT32)(l_header_data - - *l_header_data_start)) < 2U) { + *l_header_data_start)) < 2U) { opj_event_msg(p_manager, EVT_ERROR, "Not enough space for required EPH marker\n"); return OPJ_FALSE; @@ -1304,7 +1292,7 @@ static OPJ_BOOL opj_t2_read_packet_header(opj_t2_t* p_t2, do { OPJ_UINT32 bit_number; l_cblk->segs[l_segno].numnewpasses = (OPJ_UINT32)opj_int_min((OPJ_INT32)( - l_cblk->segs[l_segno].maxpasses - l_cblk->segs[l_segno].numpasses), n); + l_cblk->segs[l_segno].maxpasses - l_cblk->segs[l_segno].numpasses), n); bit_number = l_cblk->numlenbits + opj_uint_floorlog2( l_cblk->segs[l_segno].numnewpasses); if (bit_number > 32) { @@ -1346,7 +1334,7 @@ static OPJ_BOOL opj_t2_read_packet_header(opj_t2_t* p_t2, if (p_tcp->csty & J2K_CP_CSTY_EPH) { /* EPH markers are required */ if ((*l_modified_length_ptr - (OPJ_UINT32)(l_header_data - - *l_header_data_start)) < 2U) { + *l_header_data_start)) < 2U) { opj_event_msg(p_manager, EVT_ERROR, "Not enough space for required EPH marker\n"); return OPJ_FALSE; @@ -1381,21 +1369,20 @@ static OPJ_BOOL opj_t2_read_packet_header(opj_t2_t* p_t2, return OPJ_TRUE; } -static OPJ_BOOL opj_t2_read_packet_data(opj_t2_t* p_t2, +static OPJ_BOOL opj_t2_read_packet_data(opj_t2_t *p_t2, opj_tcd_tile_t *p_tile, opj_pi_iterator_t *p_pi, OPJ_BYTE *p_src_data, - OPJ_UINT32 * p_data_read, + OPJ_UINT32 *p_data_read, OPJ_UINT32 p_max_length, opj_packet_info_t *pack_info, - opj_event_mgr_t* p_manager) -{ + opj_event_mgr_t *p_manager) { OPJ_UINT32 bandno, cblkno; OPJ_UINT32 l_nb_code_blocks; OPJ_BYTE *l_current_data = p_src_data; opj_tcd_band_t *l_band = 00; - opj_tcd_cblk_dec_t* l_cblk = 00; - opj_tcd_resolution_t* l_res = + opj_tcd_cblk_dec_t *l_cblk = 00; + opj_tcd_resolution_t *l_res = &p_tile->comps[p_pi->compno].resolutions[p_pi->resno]; OPJ_BOOL partial_buffer = OPJ_FALSE; @@ -1494,9 +1481,9 @@ static OPJ_BOOL opj_t2_read_packet_data(opj_t2_t* p_t2, if (l_cblk->numchunks == l_cblk->numchunksalloc) { OPJ_UINT32 l_numchunksalloc = l_cblk->numchunksalloc * 2 + 1; - opj_tcd_seg_data_chunk_t* l_chunks = - (opj_tcd_seg_data_chunk_t*)opj_realloc(l_cblk->chunks, - l_numchunksalloc * sizeof(opj_tcd_seg_data_chunk_t)); + opj_tcd_seg_data_chunk_t *l_chunks = + (opj_tcd_seg_data_chunk_t *)opj_realloc(l_cblk->chunks, + l_numchunksalloc * sizeof(opj_tcd_seg_data_chunk_t)); if (l_chunks == NULL) { opj_event_msg(p_manager, EVT_ERROR, "cannot allocate opj_tcd_seg_data_chunk_t* array"); @@ -1540,19 +1527,18 @@ static OPJ_BOOL opj_t2_read_packet_data(opj_t2_t* p_t2, return OPJ_TRUE; } -static OPJ_BOOL opj_t2_skip_packet_data(opj_t2_t* p_t2, +static OPJ_BOOL opj_t2_skip_packet_data(opj_t2_t *p_t2, opj_tcd_tile_t *p_tile, opj_pi_iterator_t *p_pi, - OPJ_UINT32 * p_data_read, + OPJ_UINT32 *p_data_read, OPJ_UINT32 p_max_length, opj_packet_info_t *pack_info, - opj_event_mgr_t *p_manager) -{ + opj_event_mgr_t *p_manager) { OPJ_UINT32 bandno, cblkno; OPJ_UINT32 l_nb_code_blocks; opj_tcd_band_t *l_band = 00; - opj_tcd_cblk_dec_t* l_cblk = 00; - opj_tcd_resolution_t* l_res = + opj_tcd_cblk_dec_t *l_cblk = 00; + opj_tcd_resolution_t *l_res = &p_tile->comps[p_pi->compno].resolutions[p_pi->resno]; OPJ_ARG_NOT_USED(p_t2); @@ -1656,21 +1642,20 @@ static OPJ_BOOL opj_t2_skip_packet_data(opj_t2_t* p_t2, } -static OPJ_BOOL opj_t2_init_seg(opj_tcd_cblk_dec_t* cblk, +static OPJ_BOOL opj_t2_init_seg(opj_tcd_cblk_dec_t *cblk, OPJ_UINT32 index, OPJ_UINT32 cblksty, - OPJ_UINT32 first) -{ - opj_tcd_seg_t* seg = 00; + OPJ_UINT32 first) { + opj_tcd_seg_t *seg = 00; OPJ_UINT32 l_nb_segs = index + 1; if (l_nb_segs > cblk->m_current_max_segs) { - opj_tcd_seg_t* new_segs; + opj_tcd_seg_t *new_segs; OPJ_UINT32 l_m_current_max_segs = cblk->m_current_max_segs + OPJ_J2K_DEFAULT_NB_SEGS; - new_segs = (opj_tcd_seg_t*) opj_realloc(cblk->segs, - l_m_current_max_segs * sizeof(opj_tcd_seg_t)); + new_segs = (opj_tcd_seg_t *) opj_realloc(cblk->segs, + l_m_current_max_segs * sizeof(opj_tcd_seg_t)); if (! new_segs) { /* opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to initialize segment %d\n", l_nb_segs); */ return OPJ_FALSE; diff --git a/client/deps/openjpeg/t2.h b/client/deps/openjpeg/t2.h index becfa91a4..58dff5047 100644 --- a/client/deps/openjpeg/t2.h +++ b/client/deps/openjpeg/t2.h @@ -80,15 +80,15 @@ Encode the packets of a tile to a destination buffer @param t2_mode If == THRESH_CALC In Threshold calculation ,If == FINAL_PASS Final pass @param p_manager the user event manager */ -OPJ_BOOL opj_t2_encode_packets(opj_t2_t* t2, +OPJ_BOOL opj_t2_encode_packets(opj_t2_t *t2, OPJ_UINT32 tileno, opj_tcd_tile_t *tile, OPJ_UINT32 maxlayers, OPJ_BYTE *dest, - OPJ_UINT32 * p_data_written, + OPJ_UINT32 *p_data_written, OPJ_UINT32 len, opj_codestream_info_t *cstr_info, - opj_tcd_marker_info_t* p_marker_info, + opj_tcd_marker_info_t *p_marker_info, OPJ_UINT32 tpnum, OPJ_INT32 tppos, OPJ_UINT32 pino, @@ -109,12 +109,12 @@ Decode the packets of a tile from a source buffer @return FIXME DOC */ -OPJ_BOOL opj_t2_decode_packets(opj_tcd_t* tcd, +OPJ_BOOL opj_t2_decode_packets(opj_tcd_t *tcd, opj_t2_t *t2, OPJ_UINT32 tileno, opj_tcd_tile_t *tile, OPJ_BYTE *src, - OPJ_UINT32 * p_data_read, + OPJ_UINT32 *p_data_read, OPJ_UINT32 len, opj_codestream_index_t *cstr_info, opj_event_mgr_t *p_manager); @@ -126,7 +126,7 @@ OPJ_BOOL opj_t2_decode_packets(opj_tcd_t* tcd, * @param p_cp Image coding parameters. * @return a new T2 handle if successful, NULL otherwise. */ -opj_t2_t* opj_t2_create(opj_image_t *p_image, opj_cp_t *p_cp); +opj_t2_t *opj_t2_create(opj_image_t *p_image, opj_cp_t *p_cp); /** Destroy a T2 handle diff --git a/client/deps/openjpeg/tcd.c b/client/deps/openjpeg/tcd.c index 8ca259b71..423e6a791 100644 --- a/client/deps/openjpeg/tcd.c +++ b/client/deps/openjpeg/tcd.c @@ -48,8 +48,7 @@ /* TODO MSD: */ #ifdef TODO_MSD -void tcd_dump(FILE *fd, opj_tcd_t *tcd, opj_tcd_image_t * img) -{ +void tcd_dump(FILE *fd, opj_tcd_t *tcd, opj_tcd_image_t *img) { int tileno, compno, resno, bandno, precno;/*, cblkno;*/ fprintf(fd, "image {\n"); @@ -114,36 +113,36 @@ void tcd_dump(FILE *fd, opj_tcd_t *tcd, opj_tcd_image_t * img) * Initializes tile coding/decoding */ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no, - OPJ_BOOL isEncoder, OPJ_SIZE_T sizeof_block, - opj_event_mgr_t* manager); + OPJ_BOOL isEncoder, OPJ_SIZE_T sizeof_block, + opj_event_mgr_t *manager); /** * Allocates memory for a decoding code block. */ static OPJ_BOOL opj_tcd_code_block_dec_allocate(opj_tcd_cblk_dec_t * - p_code_block); + p_code_block); /** * Deallocates the decoding data of the given precinct. */ -static void opj_tcd_code_block_dec_deallocate(opj_tcd_precinct_t * p_precinct); +static void opj_tcd_code_block_dec_deallocate(opj_tcd_precinct_t *p_precinct); /** * Allocates memory for an encoding code block (but not data). */ static OPJ_BOOL opj_tcd_code_block_enc_allocate(opj_tcd_cblk_enc_t * - p_code_block); + p_code_block); /** * Allocates data for an encoding code block */ static OPJ_BOOL opj_tcd_code_block_enc_allocate_data(opj_tcd_cblk_enc_t * - p_code_block); + p_code_block); /** * Deallocates the encoding data of the given precinct. */ -static void opj_tcd_code_block_enc_deallocate(opj_tcd_precinct_t * p_precinct); +static void opj_tcd_code_block_enc_deallocate(opj_tcd_precinct_t *p_precinct); static void opj_tcd_makelayer_fixed(opj_tcd_t *tcd, OPJ_UINT32 layno, @@ -157,8 +156,8 @@ static void opj_tcd_free_tile(opj_tcd_t *tcd); static OPJ_BOOL opj_tcd_t2_decode(opj_tcd_t *p_tcd, - OPJ_BYTE * p_src_data, - OPJ_UINT32 * p_data_read, + OPJ_BYTE *p_src_data, + OPJ_UINT32 *p_data_read, OPJ_UINT32 p_max_src_size, opj_codestream_index_t *p_cstr_index, opj_event_mgr_t *p_manager); @@ -183,41 +182,40 @@ static OPJ_BOOL opj_tcd_dwt_encode(opj_tcd_t *p_tcd); static OPJ_BOOL opj_tcd_t1_encode(opj_tcd_t *p_tcd); static OPJ_BOOL opj_tcd_t2_encode(opj_tcd_t *p_tcd, - OPJ_BYTE * p_dest_data, - OPJ_UINT32 * p_data_written, + OPJ_BYTE *p_dest_data, + OPJ_UINT32 *p_data_written, OPJ_UINT32 p_max_dest_size, opj_codestream_info_t *p_cstr_info, - opj_tcd_marker_info_t* p_marker_info, + opj_tcd_marker_info_t *p_marker_info, opj_event_mgr_t *p_manager); static OPJ_BOOL opj_tcd_rate_allocate_encode(opj_tcd_t *p_tcd, - OPJ_BYTE * p_dest_data, - OPJ_UINT32 p_max_dest_size, - opj_codestream_info_t *p_cstr_info, - opj_event_mgr_t *p_manager); + OPJ_BYTE *p_dest_data, + OPJ_UINT32 p_max_dest_size, + opj_codestream_info_t *p_cstr_info, + opj_event_mgr_t *p_manager); static OPJ_BOOL opj_tcd_is_whole_tilecomp_decoding(opj_tcd_t *tcd, - OPJ_UINT32 compno); + OPJ_UINT32 compno); /* ----------------------------------------------------------------------- */ /** Create a new TCD handle */ -opj_tcd_t* opj_tcd_create(OPJ_BOOL p_is_decoder) -{ +opj_tcd_t *opj_tcd_create(OPJ_BOOL p_is_decoder) { opj_tcd_t *l_tcd = 00; /* create the tcd structure */ - l_tcd = (opj_tcd_t*) opj_calloc(1, sizeof(opj_tcd_t)); + l_tcd = (opj_tcd_t *) opj_calloc(1, sizeof(opj_tcd_t)); if (!l_tcd) { return 00; } l_tcd->m_is_decoder = p_is_decoder ? 1 : 0; - l_tcd->tcd_image = (opj_tcd_image_t*)opj_calloc(1, sizeof(opj_tcd_image_t)); + l_tcd->tcd_image = (opj_tcd_image_t *)opj_calloc(1, sizeof(opj_tcd_image_t)); if (!l_tcd->tcd_image) { opj_free(l_tcd); return 00; @@ -230,8 +228,7 @@ opj_tcd_t* opj_tcd_create(OPJ_BOOL p_is_decoder) /* ----------------------------------------------------------------------- */ static -void opj_tcd_rateallocate_fixed(opj_tcd_t *tcd) -{ +void opj_tcd_rateallocate_fixed(opj_tcd_t *tcd) { OPJ_UINT32 layno; for (layno = 0; layno < tcd->tcp->numlayers; layno++) { @@ -248,8 +245,7 @@ static OPJ_BOOL opj_tcd_makelayer(opj_tcd_t *tcd, OPJ_UINT32 layno, OPJ_FLOAT64 thresh, - OPJ_UINT32 final) -{ + OPJ_UINT32 final) { OPJ_UINT32 compno, resno, bandno, precno, cblkno; OPJ_UINT32 passno; @@ -332,7 +328,7 @@ OPJ_BOOL opj_tcd_makelayer(opj_tcd_t *tcd, layer->disto = cblk->passes[n - 1].distortiondec; } else { layer->len = cblk->passes[n - 1].rate - cblk->passes[cblk->numpassesinlayers - - 1].rate; + 1].rate; layer->data = cblk->data + cblk->passes[cblk->numpassesinlayers - 1].rate; layer->disto = cblk->passes[n - 1].distortiondec - cblk->passes[cblk->numpassesinlayers - 1].distortiondec; @@ -354,8 +350,7 @@ OPJ_BOOL opj_tcd_makelayer(opj_tcd_t *tcd, /** For m_quality_layer_alloc_strategy == FIXED_LAYER */ static void opj_tcd_makelayer_fixed(opj_tcd_t *tcd, OPJ_UINT32 layno, - OPJ_UINT32 final) -{ + OPJ_UINT32 final) { OPJ_UINT32 compno, resno, bandno, precno, cblkno; OPJ_INT32 value; /*, matrice[tcd_tcp->numlayers][tcd_tile->comps[0].numresolutions][3]; */ OPJ_INT32 matrice[J2K_TCD_MATRIX_MAX_LAYER_COUNT][J2K_TCD_MATRIX_MAX_RESOLUTION_COUNT][3]; @@ -444,7 +439,7 @@ void opj_tcd_makelayer_fixed(opj_tcd_t *tcd, OPJ_UINT32 layno, layer->data = cblk->data; } else { layer->len = cblk->passes[n - 1].rate - cblk->passes[cblk->numpassesinlayers - - 1].rate; + 1].rate; layer->data = cblk->data + cblk->passes[cblk->numpassesinlayers - 1].rate; } @@ -465,11 +460,10 @@ void opj_tcd_makelayer_fixed(opj_tcd_t *tcd, OPJ_UINT32 layno, static OPJ_BOOL opj_tcd_rateallocate(opj_tcd_t *tcd, OPJ_BYTE *dest, - OPJ_UINT32 * p_data_written, + OPJ_UINT32 *p_data_written, OPJ_UINT32 len, opj_codestream_info_t *cstr_info, - opj_event_mgr_t *p_manager) -{ + opj_event_mgr_t *p_manager) { OPJ_UINT32 compno, resno, bandno, precno, cblkno, layno; OPJ_UINT32 passno; OPJ_FLOAT64 min, max; @@ -536,7 +530,7 @@ OPJ_BOOL opj_tcd_rateallocate(opj_tcd_t *tcd, { const OPJ_SIZE_T cblk_pix_count = (OPJ_SIZE_T)((cblk->x1 - cblk->x0) * - (cblk->y1 - cblk->y0)); + (cblk->y1 - cblk->y0)); tcd_tile->numpix += cblk_pix_count; tilec->numpix += cblk_pix_count; } @@ -556,7 +550,7 @@ OPJ_BOOL opj_tcd_rateallocate(opj_tcd_t *tcd, tile_info->numpix = (int)tcd_tile->numpix; tile_info->distotile = (int)tcd_tile->distotile; tile_info->thresh = (OPJ_FLOAT64 *) opj_malloc(tcd_tcp->numlayers * sizeof( - OPJ_FLOAT64)); + OPJ_FLOAT64)); if (!tile_info->thresh) { /* FIXME event manager error callback */ return OPJ_FALSE; @@ -574,7 +568,7 @@ OPJ_BOOL opj_tcd_rateallocate(opj_tcd_t *tcd, OPJ_FLOAT64 distotarget; distotarget = tcd_tile->distotile - ((K * maxSE) / pow((OPJ_FLOAT32)10, - tcd_tcp->distoratio[layno] / 10)); + tcd_tcp->distoratio[layno] / 10)); /* Don't try to find an optimal threshold but rather take everything not included yet, if -r xx,yy,zz,0 (m_quality_layer_alloc_strategy == RATE_DISTORTION_RATIO and rates == NULL) @@ -586,7 +580,7 @@ OPJ_BOOL opj_tcd_rateallocate(opj_tcd_t *tcd, ((cp->m_specific_param.m_enc.m_quality_layer_alloc_strategy == FIXED_DISTORTION_RATIO) && (tcd_tcp->distoratio[layno] > 0.0))) { - opj_t2_t*t2 = opj_t2_create(tcd->image, cp); + opj_t2_t *t2 = opj_t2_create(tcd->image, cp); OPJ_FLOAT64 thresh = 0; OPJ_BOOL last_layer_allocation_ok = OPJ_FALSE; @@ -712,15 +706,14 @@ OPJ_BOOL opj_tcd_rateallocate(opj_tcd_t *tcd, } OPJ_BOOL opj_tcd_init(opj_tcd_t *p_tcd, - opj_image_t * p_image, - opj_cp_t * p_cp, - opj_thread_pool_t* p_tp) -{ + opj_image_t *p_image, + opj_cp_t *p_cp, + opj_thread_pool_t *p_tp) { p_tcd->image = p_image; p_tcd->cp = p_cp; p_tcd->tcd_image->tiles = (opj_tcd_tile_t *) opj_calloc(1, - sizeof(opj_tcd_tile_t)); + sizeof(opj_tcd_tile_t)); if (! p_tcd->tcd_image->tiles) { return OPJ_FALSE; } @@ -741,8 +734,7 @@ OPJ_BOOL opj_tcd_init(opj_tcd_t *p_tcd, /** Destroy a previously created TCD handle */ -void opj_tcd_destroy(opj_tcd_t *tcd) -{ +void opj_tcd_destroy(opj_tcd_t *tcd) { if (tcd) { opj_tcd_free_tile(tcd); @@ -757,8 +749,7 @@ void opj_tcd_destroy(opj_tcd_t *tcd) } } -OPJ_BOOL opj_alloc_tile_component_data(opj_tcd_tilecomp_t *l_tilec) -{ +OPJ_BOOL opj_alloc_tile_component_data(opj_tcd_tilecomp_t *l_tilec) { if ((l_tilec->data == 00) || ((l_tilec->data_size_needed > l_tilec->data_size) && (l_tilec->ownsData == OPJ_FALSE))) { @@ -789,19 +780,18 @@ OPJ_BOOL opj_alloc_tile_component_data(opj_tcd_tilecomp_t *l_tilec) /* ----------------------------------------------------------------------- */ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no, - OPJ_BOOL isEncoder, OPJ_SIZE_T sizeof_block, - opj_event_mgr_t* manager) -{ + OPJ_BOOL isEncoder, OPJ_SIZE_T sizeof_block, + opj_event_mgr_t *manager) { OPJ_UINT32 compno, resno, bandno, precno, cblkno; - opj_tcp_t * l_tcp = 00; - opj_cp_t * l_cp = 00; - opj_tcd_tile_t * l_tile = 00; + opj_tcp_t *l_tcp = 00; + opj_cp_t *l_cp = 00; + opj_tcd_tile_t *l_tile = 00; opj_tccp_t *l_tccp = 00; opj_tcd_tilecomp_t *l_tilec = 00; - opj_image_comp_t * l_image_comp = 00; + opj_image_comp_t *l_image_comp = 00; opj_tcd_resolution_t *l_res = 00; opj_tcd_band_t *l_band = 00; - opj_stepsize_t * l_step_size = 00; + opj_stepsize_t *l_step_size = 00; opj_tcd_precinct_t *l_current_precinct = 00; opj_image_t *l_image = 00; OPJ_UINT32 p, q; @@ -926,8 +916,8 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no, l_tilec->resolutions_size = l_data_size; memset(l_tilec->resolutions, 0, l_data_size); } else if (l_data_size > l_tilec->resolutions_size) { - opj_tcd_resolution_t* new_resolutions = (opj_tcd_resolution_t *) opj_realloc( - l_tilec->resolutions, l_data_size); + opj_tcd_resolution_t *new_resolutions = (opj_tcd_resolution_t *) opj_realloc( + l_tilec->resolutions, l_data_size); if (! new_resolutions) { opj_event_msg(manager, EVT_ERROR, "Not enough memory for tile resolutions\n"); opj_free(l_tilec->resolutions); @@ -937,7 +927,7 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no, } l_tilec->resolutions = new_resolutions; /*fprintf(stderr, "\tReallocate data of tilec (int): from %d to %d x OPJ_UINT32\n", l_tilec->resolutions_size, l_data_size);*/ - memset(((OPJ_BYTE*) l_tilec->resolutions) + l_tilec->resolutions_size, 0, + memset(((OPJ_BYTE *) l_tilec->resolutions) + l_tilec->resolutions_size, 0, l_data_size - l_tilec->resolutions_size); l_tilec->resolutions_size = l_data_size; } @@ -971,7 +961,7 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no, l_tl_prc_y_start = opj_int_floordivpow2(l_res->y0, (OPJ_INT32)l_pdy) << l_pdy; { OPJ_UINT32 tmp = ((OPJ_UINT32)opj_int_ceildivpow2(l_res->x1, - (OPJ_INT32)l_pdx)) << l_pdx; + (OPJ_INT32)l_pdx)) << l_pdx; if (tmp > (OPJ_UINT32)INT_MAX) { opj_event_msg(manager, EVT_ERROR, "Integer overflow\n"); return OPJ_FALSE; @@ -980,7 +970,7 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no, } { OPJ_UINT32 tmp = ((OPJ_UINT32)opj_int_ceildivpow2(l_res->y1, - (OPJ_INT32)l_pdy)) << l_pdy; + (OPJ_INT32)l_pdy)) << l_pdy; if (tmp > (OPJ_UINT32)INT_MAX) { opj_event_msg(manager, EVT_ERROR, "Integer overflow\n"); return OPJ_FALSE; @@ -990,9 +980,9 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no, /*fprintf(stderr, "\t\t\tprc_x_start=%d, prc_y_start=%d, br_prc_x_end=%d, br_prc_y_end=%d \n", l_tl_prc_x_start, l_tl_prc_y_start, l_br_prc_x_end ,l_br_prc_y_end );*/ l_res->pw = (l_res->x0 == l_res->x1) ? 0U : (OPJ_UINT32)(( - l_br_prc_x_end - l_tl_prc_x_start) >> l_pdx); + l_br_prc_x_end - l_tl_prc_x_start) >> l_pdx); l_res->ph = (l_res->y0 == l_res->y1) ? 0U : (OPJ_UINT32)(( - l_br_prc_y_end - l_tl_prc_y_start) >> l_pdy); + l_br_prc_y_end - l_tl_prc_y_start) >> l_pdy); /*fprintf(stderr, "\t\t\tres_pw=%d, res_ph=%d\n", l_res->pw, l_res->ph );*/ if ((l_res->pw != 0U) && ((((OPJ_UINT32) - 1) / l_res->pw) < l_res->ph)) { @@ -1047,13 +1037,13 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no, l_y0b = (OPJ_INT32)((l_band->bandno) >> 1); /* l_band border (global) */ l_band->x0 = opj_int64_ceildivpow2(l_tilec->x0 - ((OPJ_INT64)l_x0b << - l_level_no), (OPJ_INT32)(l_level_no + 1)); + l_level_no), (OPJ_INT32)(l_level_no + 1)); l_band->y0 = opj_int64_ceildivpow2(l_tilec->y0 - ((OPJ_INT64)l_y0b << - l_level_no), (OPJ_INT32)(l_level_no + 1)); + l_level_no), (OPJ_INT32)(l_level_no + 1)); l_band->x1 = opj_int64_ceildivpow2(l_tilec->x1 - ((OPJ_INT64)l_x0b << - l_level_no), (OPJ_INT32)(l_level_no + 1)); + l_level_no), (OPJ_INT32)(l_level_no + 1)); l_band->y1 = opj_int64_ceildivpow2(l_tilec->y1 - ((OPJ_INT64)l_y0b << - l_level_no), (OPJ_INT32)(l_level_no + 1)); + l_level_no), (OPJ_INT32)(l_level_no + 1)); } if (isEncoder) { @@ -1102,8 +1092,8 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no, l_band->precincts_data_size = l_nb_precinct_size; } else if (l_band->precincts_data_size < l_nb_precinct_size) { - opj_tcd_precinct_t * new_precincts = (opj_tcd_precinct_t *) opj_realloc( - l_band->precincts,/*3 * */ l_nb_precinct_size); + opj_tcd_precinct_t *new_precincts = (opj_tcd_precinct_t *) opj_realloc( + l_band->precincts,/*3 * */ l_nb_precinct_size); if (! new_precincts) { opj_event_msg(manager, EVT_ERROR, "Not enough memory to handle band precints\n"); @@ -1201,30 +1191,30 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no, if (! l_current_precinct->incltree) { l_current_precinct->incltree = opj_tgt_create(l_current_precinct->cw, - l_current_precinct->ch, manager); + l_current_precinct->ch, manager); } else { l_current_precinct->incltree = opj_tgt_init(l_current_precinct->incltree, - l_current_precinct->cw, l_current_precinct->ch, manager); + l_current_precinct->cw, l_current_precinct->ch, manager); } if (! l_current_precinct->imsbtree) { l_current_precinct->imsbtree = opj_tgt_create(l_current_precinct->cw, - l_current_precinct->ch, manager); + l_current_precinct->ch, manager); } else { l_current_precinct->imsbtree = opj_tgt_init(l_current_precinct->imsbtree, - l_current_precinct->cw, l_current_precinct->ch, manager); + l_current_precinct->cw, l_current_precinct->ch, manager); } for (cblkno = 0; cblkno < l_nb_code_blocks; ++cblkno) { OPJ_INT32 cblkxstart = tlcblkxstart + (OPJ_INT32)(cblkno % - l_current_precinct->cw) * (1 << cblkwidthexpn); + l_current_precinct->cw) * (1 << cblkwidthexpn); OPJ_INT32 cblkystart = tlcblkystart + (OPJ_INT32)(cblkno / - l_current_precinct->cw) * (1 << cblkheightexpn); + l_current_precinct->cw) * (1 << cblkheightexpn); OPJ_INT32 cblkxend = cblkxstart + (1 << cblkwidthexpn); OPJ_INT32 cblkyend = cblkystart + (1 << cblkheightexpn); if (isEncoder) { - opj_tcd_cblk_enc_t* l_code_block = l_current_precinct->cblks.enc + cblkno; + opj_tcd_cblk_enc_t *l_code_block = l_current_precinct->cblks.enc + cblkno; if (! opj_tcd_code_block_enc_allocate(l_code_block)) { return OPJ_FALSE; @@ -1239,7 +1229,7 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no, return OPJ_FALSE; } } else { - opj_tcd_cblk_dec_t* l_code_block = l_current_precinct->cblks.dec + cblkno; + opj_tcd_cblk_dec_t *l_code_block = l_current_precinct->cblks.dec + cblkno; if (! opj_tcd_code_block_dec_allocate(l_code_block)) { return OPJ_FALSE; @@ -1264,15 +1254,13 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no, } OPJ_BOOL opj_tcd_init_encode_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no, - opj_event_mgr_t* p_manager) -{ + opj_event_mgr_t *p_manager) { return opj_tcd_init_tile(p_tcd, p_tile_no, OPJ_TRUE, sizeof(opj_tcd_cblk_enc_t), p_manager); } OPJ_BOOL opj_tcd_init_decode_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no, - opj_event_mgr_t* p_manager) -{ + opj_event_mgr_t *p_manager) { return opj_tcd_init_tile(p_tcd, p_tile_no, OPJ_FALSE, sizeof(opj_tcd_cblk_dec_t), p_manager); } @@ -1281,19 +1269,18 @@ OPJ_BOOL opj_tcd_init_decode_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no, * Allocates memory for an encoding code block (but not data memory). */ static OPJ_BOOL opj_tcd_code_block_enc_allocate(opj_tcd_cblk_enc_t * - p_code_block) -{ + p_code_block) { if (! p_code_block->layers) { /* no memset since data */ - p_code_block->layers = (opj_tcd_layer_t*) opj_calloc(100, - sizeof(opj_tcd_layer_t)); + p_code_block->layers = (opj_tcd_layer_t *) opj_calloc(100, + sizeof(opj_tcd_layer_t)); if (! p_code_block->layers) { return OPJ_FALSE; } } if (! p_code_block->passes) { - p_code_block->passes = (opj_tcd_pass_t*) opj_calloc(100, - sizeof(opj_tcd_pass_t)); + p_code_block->passes = (opj_tcd_pass_t *) opj_calloc(100, + sizeof(opj_tcd_pass_t)); if (! p_code_block->passes) { return OPJ_FALSE; } @@ -1305,8 +1292,7 @@ static OPJ_BOOL opj_tcd_code_block_enc_allocate(opj_tcd_cblk_enc_t * * Allocates data memory for an encoding code block. */ static OPJ_BOOL opj_tcd_code_block_enc_allocate_data(opj_tcd_cblk_enc_t * - p_code_block) -{ + p_code_block) { OPJ_UINT32 l_data_size; /* +1 is needed for https://github.com/uclouvain/openjpeg/issues/835 */ @@ -1327,7 +1313,7 @@ static OPJ_BOOL opj_tcd_code_block_enc_allocate_data(opj_tcd_cblk_enc_t * /* We refer to data - 1 since below we incremented it */ opj_free(p_code_block->data - 1); } - p_code_block->data = (OPJ_BYTE*) opj_malloc(l_data_size + 1); + p_code_block->data = (OPJ_BYTE *) opj_malloc(l_data_size + 1); if (! p_code_block->data) { p_code_block->data_size = 0U; return OPJ_FALSE; @@ -1345,8 +1331,7 @@ static OPJ_BOOL opj_tcd_code_block_enc_allocate_data(opj_tcd_cblk_enc_t * } -void opj_tcd_reinit_segment(opj_tcd_seg_t* seg) -{ +void opj_tcd_reinit_segment(opj_tcd_seg_t *seg) { memset(seg, 0, sizeof(opj_tcd_seg_t)); } @@ -1354,12 +1339,11 @@ void opj_tcd_reinit_segment(opj_tcd_seg_t* seg) * Allocates memory for a decoding code block. */ static OPJ_BOOL opj_tcd_code_block_dec_allocate(opj_tcd_cblk_dec_t * - p_code_block) -{ + p_code_block) { if (! p_code_block->segs) { p_code_block->segs = (opj_tcd_seg_t *) opj_calloc(OPJ_J2K_DEFAULT_NB_SEGS, - sizeof(opj_tcd_seg_t)); + sizeof(opj_tcd_seg_t)); if (! p_code_block->segs) { return OPJ_FALSE; } @@ -1369,9 +1353,9 @@ static OPJ_BOOL opj_tcd_code_block_dec_allocate(opj_tcd_cblk_dec_t * /*fprintf(stderr, "m_current_max_segs of code_block->data = %d\n", p_code_block->m_current_max_segs);*/ } else { /* sanitize */ - opj_tcd_seg_t * l_segs = p_code_block->segs; + opj_tcd_seg_t *l_segs = p_code_block->segs; OPJ_UINT32 l_current_max_segs = p_code_block->m_current_max_segs; - opj_tcd_seg_data_chunk_t* l_chunks = p_code_block->chunks; + opj_tcd_seg_data_chunk_t *l_chunks = p_code_block->chunks; OPJ_UINT32 l_numchunksalloc = p_code_block->numchunksalloc; OPJ_UINT32 i; @@ -1392,13 +1376,12 @@ static OPJ_BOOL opj_tcd_code_block_dec_allocate(opj_tcd_cblk_dec_t * } OPJ_UINT32 opj_tcd_get_decoded_tile_size(opj_tcd_t *p_tcd, - OPJ_BOOL take_into_account_partial_decoding) -{ + OPJ_BOOL take_into_account_partial_decoding) { OPJ_UINT32 i; OPJ_UINT32 l_data_size = 0; - opj_image_comp_t * l_img_comp = 00; - opj_tcd_tilecomp_t * l_tile_comp = 00; - opj_tcd_resolution_t * l_res = 00; + opj_image_comp_t *l_img_comp = 00; + opj_tcd_tilecomp_t *l_tile_comp = 00; + opj_tcd_resolution_t *l_res = 00; OPJ_UINT32 l_size_comp, l_remaining; OPJ_UINT32 l_temp; @@ -1449,12 +1432,11 @@ OPJ_UINT32 opj_tcd_get_decoded_tile_size(opj_tcd_t *p_tcd, OPJ_BOOL opj_tcd_encode_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no, OPJ_BYTE *p_dest, - OPJ_UINT32 * p_data_written, + OPJ_UINT32 *p_data_written, OPJ_UINT32 p_max_length, opj_codestream_info_t *p_cstr_info, - opj_tcd_marker_info_t* p_marker_info, - opj_event_mgr_t *p_manager) -{ + opj_tcd_marker_info_t *p_marker_info, + opj_event_mgr_t *p_manager) { if (p_tcd->cur_tp_num == 0) { @@ -1479,8 +1461,8 @@ OPJ_BOOL opj_tcd_encode_tile(opj_tcd_t *p_tcd, p_cstr_info->tile[p_tile_no].pdx[i] = (int)l_tccp->prcw[i]; p_cstr_info->tile[p_tile_no].pdy[i] = (int)l_tccp->prch[i]; } - p_cstr_info->tile[p_tile_no].packet = (opj_packet_info_t*) opj_calloc(( - OPJ_SIZE_T)p_cstr_info->numcomps * (OPJ_SIZE_T)p_cstr_info->numlayers * + p_cstr_info->tile[p_tile_no].packet = (opj_packet_info_t *) opj_calloc(( + OPJ_SIZE_T)p_cstr_info->numcomps * (OPJ_SIZE_T)p_cstr_info->numlayers * l_num_packs, sizeof(opj_packet_info_t)); if (!p_cstr_info->tile[p_tile_no].packet) { @@ -1554,8 +1536,7 @@ OPJ_BOOL opj_tcd_decode_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no, opj_codestream_index_t *p_cstr_index, opj_event_mgr_t *p_manager - ) -{ + ) { OPJ_UINT32 l_data_read; OPJ_UINT32 compno; @@ -1571,8 +1552,8 @@ OPJ_BOOL opj_tcd_decode_tile(opj_tcd_t *p_tcd, p_tcd->used_component = NULL; if (numcomps_to_decode) { - OPJ_BOOL* used_component = (OPJ_BOOL*) opj_calloc(sizeof(OPJ_BOOL), - p_tcd->image->numcomps); + OPJ_BOOL *used_component = (OPJ_BOOL *) opj_calloc(sizeof(OPJ_BOOL), + p_tcd->image->numcomps); if (used_component == NULL) { return OPJ_FALSE; } @@ -1596,7 +1577,7 @@ OPJ_BOOL opj_tcd_decode_tile(opj_tcd_t *p_tcd, if (p_tcd->whole_tile_decoding) { for (compno = 0; compno < p_tcd->image->numcomps; compno++) { - opj_tcd_tilecomp_t* tilec = &(p_tcd->tcd_image->tiles->comps[compno]); + opj_tcd_tilecomp_t *tilec = &(p_tcd->tcd_image->tiles->comps[compno]); opj_tcd_resolution_t *l_res = & (tilec->resolutions[tilec->minimum_num_resolutions - 1]); OPJ_SIZE_T l_data_size; @@ -1638,8 +1619,8 @@ OPJ_BOOL opj_tcd_decode_tile(opj_tcd_t *p_tcd, /* we know the resno_decoded */ for (compno = 0; compno < p_tcd->image->numcomps; compno++) { OPJ_UINT32 resno; - opj_tcd_tilecomp_t* tilec = &(p_tcd->tcd_image->tiles->comps[compno]); - opj_image_comp_t* image_comp = &(p_tcd->image->comps[compno]); + opj_tcd_tilecomp_t *tilec = &(p_tcd->tcd_image->tiles->comps[compno]); + opj_image_comp_t *image_comp = &(p_tcd->image->comps[compno]); if (p_tcd->used_component != NULL && !p_tcd->used_component[compno]) { continue; @@ -1701,7 +1682,7 @@ OPJ_BOOL opj_tcd_decode_tile(opj_tcd_t *p_tcd, } } p_cstr_info->tile[p_tile_no].packet = (opj_packet_info_t *) opj_malloc( - p_cstr_info->numlayers * numprec * sizeof(opj_packet_info_t)); + p_cstr_info->numlayers * numprec * sizeof(opj_packet_info_t)); p_cstr_info->packno = 0; } /* << INDEX */ @@ -1729,8 +1710,8 @@ OPJ_BOOL opj_tcd_decode_tile(opj_tcd_t *p_tcd, /* the tile data buffer */ if (!p_tcd->whole_tile_decoding) { for (compno = 0; compno < p_tcd->image->numcomps; compno++) { - opj_tcd_tilecomp_t* tilec = &(p_tcd->tcd_image->tiles->comps[compno]); - opj_image_comp_t* image_comp = &(p_tcd->image->comps[compno]); + opj_tcd_tilecomp_t *tilec = &(p_tcd->tcd_image->tiles->comps[compno]); + opj_image_comp_t *image_comp = &(p_tcd->image->comps[compno]); opj_tcd_resolution_t *res = tilec->resolutions + image_comp->resno_decoded; OPJ_SIZE_T w = res->win_x1 - res->win_x0; OPJ_SIZE_T h = res->win_y1 - res->win_y0; @@ -1757,7 +1738,7 @@ OPJ_BOOL opj_tcd_decode_tile(opj_tcd_t *p_tcd, } l_data_size *= sizeof(OPJ_INT32); - tilec->data_win = (OPJ_INT32*) opj_image_data_alloc(l_data_size); + tilec->data_win = (OPJ_INT32 *) opj_image_data_alloc(l_data_size); if (tilec->data_win == NULL) { opj_event_msg(p_manager, EVT_ERROR, "Size of tile data exceeds system limits\n"); @@ -1797,14 +1778,13 @@ OPJ_BOOL opj_tcd_decode_tile(opj_tcd_t *p_tcd, } OPJ_BOOL opj_tcd_update_tile_data(opj_tcd_t *p_tcd, - OPJ_BYTE * p_dest, + OPJ_BYTE *p_dest, OPJ_UINT32 p_dest_length - ) -{ + ) { OPJ_UINT32 i, j, k, l_data_size = 0; - opj_image_comp_t * l_img_comp = 00; - opj_tcd_tilecomp_t * l_tilec = 00; - opj_tcd_resolution_t * l_res; + opj_image_comp_t *l_img_comp = 00; + opj_tcd_tilecomp_t *l_tilec = 00; + opj_tcd_resolution_t *l_res; OPJ_UINT32 l_size_comp, l_remaining; OPJ_UINT32 l_stride, l_width, l_height; @@ -1817,7 +1797,7 @@ OPJ_BOOL opj_tcd_update_tile_data(opj_tcd_t *p_tcd, l_img_comp = p_tcd->image->comps; for (i = 0; i < p_tcd->image->numcomps; ++i) { - const OPJ_INT32* l_src_data; + const OPJ_INT32 *l_src_data; l_size_comp = l_img_comp->prec >> 3; /*(/ 8)*/ l_remaining = l_img_comp->prec & 7; /* (%8) */ l_res = l_tilec->resolutions + l_img_comp->resno_decoded; @@ -1825,7 +1805,7 @@ OPJ_BOOL opj_tcd_update_tile_data(opj_tcd_t *p_tcd, l_width = (OPJ_UINT32)(l_res->x1 - l_res->x0); l_height = (OPJ_UINT32)(l_res->y1 - l_res->y0); l_stride = (OPJ_UINT32)(l_tilec->resolutions[l_tilec->minimum_num_resolutions - - 1].x1 - + 1].x1 - l_tilec->resolutions[l_tilec->minimum_num_resolutions - 1].x0) - l_width; l_src_data = l_tilec->data; } else { @@ -1844,69 +1824,69 @@ OPJ_BOOL opj_tcd_update_tile_data(opj_tcd_t *p_tcd, } switch (l_size_comp) { - case 1: { - OPJ_CHAR * l_dest_ptr = (OPJ_CHAR *) p_dest; - const OPJ_INT32 * l_src_ptr = l_src_data; + case 1: { + OPJ_CHAR *l_dest_ptr = (OPJ_CHAR *) p_dest; + const OPJ_INT32 *l_src_ptr = l_src_data; - if (l_img_comp->sgnd) { - for (j = 0; j < l_height; ++j) { - for (k = 0; k < l_width; ++k) { - *(l_dest_ptr++) = (OPJ_CHAR)(*(l_src_ptr++)); + if (l_img_comp->sgnd) { + for (j = 0; j < l_height; ++j) { + for (k = 0; k < l_width; ++k) { + *(l_dest_ptr++) = (OPJ_CHAR)(*(l_src_ptr++)); + } + l_src_ptr += l_stride; } - l_src_ptr += l_stride; - } - } else { - for (j = 0; j < l_height; ++j) { - for (k = 0; k < l_width; ++k) { - *(l_dest_ptr++) = (OPJ_CHAR)((*(l_src_ptr++)) & 0xff); + } else { + for (j = 0; j < l_height; ++j) { + for (k = 0; k < l_width; ++k) { + *(l_dest_ptr++) = (OPJ_CHAR)((*(l_src_ptr++)) & 0xff); + } + l_src_ptr += l_stride; } - l_src_ptr += l_stride; } + + p_dest = (OPJ_BYTE *)l_dest_ptr; } + break; + case 2: { + const OPJ_INT32 *l_src_ptr = l_src_data; + OPJ_INT16 *l_dest_ptr = (OPJ_INT16 *) p_dest; - p_dest = (OPJ_BYTE *)l_dest_ptr; - } - break; - case 2: { - const OPJ_INT32 * l_src_ptr = l_src_data; - OPJ_INT16 * l_dest_ptr = (OPJ_INT16 *) p_dest; - - if (l_img_comp->sgnd) { - for (j = 0; j < l_height; ++j) { - for (k = 0; k < l_width; ++k) { - OPJ_INT16 val = (OPJ_INT16)(*(l_src_ptr++)); - memcpy(l_dest_ptr, &val, sizeof(val)); - l_dest_ptr ++; + if (l_img_comp->sgnd) { + for (j = 0; j < l_height; ++j) { + for (k = 0; k < l_width; ++k) { + OPJ_INT16 val = (OPJ_INT16)(*(l_src_ptr++)); + memcpy(l_dest_ptr, &val, sizeof(val)); + l_dest_ptr ++; + } + l_src_ptr += l_stride; } - l_src_ptr += l_stride; - } - } else { - for (j = 0; j < l_height; ++j) { - for (k = 0; k < l_width; ++k) { - OPJ_INT16 val = (OPJ_INT16)((*(l_src_ptr++)) & 0xffff); - memcpy(l_dest_ptr, &val, sizeof(val)); - l_dest_ptr ++; + } else { + for (j = 0; j < l_height; ++j) { + for (k = 0; k < l_width; ++k) { + OPJ_INT16 val = (OPJ_INT16)((*(l_src_ptr++)) & 0xffff); + memcpy(l_dest_ptr, &val, sizeof(val)); + l_dest_ptr ++; + } + l_src_ptr += l_stride; } - l_src_ptr += l_stride; } + + p_dest = (OPJ_BYTE *) l_dest_ptr; } + break; + case 4: { + OPJ_INT32 *l_dest_ptr = (OPJ_INT32 *) p_dest; + const OPJ_INT32 *l_src_ptr = l_src_data; - p_dest = (OPJ_BYTE*) l_dest_ptr; - } - break; - case 4: { - OPJ_INT32 * l_dest_ptr = (OPJ_INT32 *) p_dest; - const OPJ_INT32 * l_src_ptr = l_src_data; + for (j = 0; j < l_height; ++j) { + memcpy(l_dest_ptr, l_src_ptr, l_width * sizeof(OPJ_INT32)); + l_dest_ptr += l_width; + l_src_ptr += l_width + l_stride; + } - for (j = 0; j < l_height; ++j) { - memcpy(l_dest_ptr, l_src_ptr, l_width * sizeof(OPJ_INT32)); - l_dest_ptr += l_width; - l_src_ptr += l_width + l_stride; + p_dest = (OPJ_BYTE *) l_dest_ptr; } - - p_dest = (OPJ_BYTE*) l_dest_ptr; - } - break; + break; } ++l_img_comp; @@ -1919,8 +1899,7 @@ OPJ_BOOL opj_tcd_update_tile_data(opj_tcd_t *p_tcd, -static void opj_tcd_free_tile(opj_tcd_t *p_tcd) -{ +static void opj_tcd_free_tile(opj_tcd_t *p_tcd) { OPJ_UINT32 compno, resno, bandno, precno; opj_tcd_tile_t *l_tile = 00; opj_tcd_tilecomp_t *l_tile_comp = 00; @@ -2007,14 +1986,13 @@ static void opj_tcd_free_tile(opj_tcd_t *p_tcd) static OPJ_BOOL opj_tcd_t2_decode(opj_tcd_t *p_tcd, - OPJ_BYTE * p_src_data, - OPJ_UINT32 * p_data_read, + OPJ_BYTE *p_src_data, + OPJ_UINT32 *p_data_read, OPJ_UINT32 p_max_src_size, opj_codestream_index_t *p_cstr_index, opj_event_mgr_t *p_manager - ) -{ - opj_t2_t * l_t2; + ) { + opj_t2_t *l_t2; l_t2 = opj_t2_create(p_tcd->image, p_tcd->cp); if (l_t2 == 00) { @@ -2041,15 +2019,14 @@ static OPJ_BOOL opj_tcd_t2_decode(opj_tcd_t *p_tcd, return OPJ_TRUE; } -static OPJ_BOOL opj_tcd_t1_decode(opj_tcd_t *p_tcd, opj_event_mgr_t *p_manager) -{ +static OPJ_BOOL opj_tcd_t1_decode(opj_tcd_t *p_tcd, opj_event_mgr_t *p_manager) { OPJ_UINT32 compno; - opj_tcd_tile_t * l_tile = p_tcd->tcd_image->tiles; - opj_tcd_tilecomp_t* l_tile_comp = l_tile->comps; - opj_tccp_t * l_tccp = p_tcd->tcp->tccps; + opj_tcd_tile_t *l_tile = p_tcd->tcd_image->tiles; + opj_tcd_tilecomp_t *l_tile_comp = l_tile->comps; + opj_tccp_t *l_tccp = p_tcd->tcp->tccps; volatile OPJ_BOOL ret = OPJ_TRUE; OPJ_BOOL check_pterm = OPJ_FALSE; - opj_mutex_t* p_manager_mutex = NULL; + opj_mutex_t *p_manager_mutex = NULL; p_manager_mutex = opj_mutex_create(); @@ -2080,13 +2057,12 @@ static OPJ_BOOL opj_tcd_t1_decode(opj_tcd_t *p_tcd, opj_event_mgr_t *p_manager) } -static OPJ_BOOL opj_tcd_dwt_decode(opj_tcd_t *p_tcd) -{ +static OPJ_BOOL opj_tcd_dwt_decode(opj_tcd_t *p_tcd) { OPJ_UINT32 compno; - opj_tcd_tile_t * l_tile = p_tcd->tcd_image->tiles; - opj_tcd_tilecomp_t * l_tile_comp = l_tile->comps; - opj_tccp_t * l_tccp = p_tcd->tcp->tccps; - opj_image_comp_t * l_img_comp = p_tcd->image->comps; + opj_tcd_tile_t *l_tile = p_tcd->tcd_image->tiles; + opj_tcd_tilecomp_t *l_tile_comp = l_tile->comps; + opj_tccp_t *l_tccp = p_tcd->tcp->tccps; + opj_image_comp_t *l_img_comp = p_tcd->image->comps; for (compno = 0; compno < l_tile->numcomps; compno++, ++l_tile_comp, ++l_img_comp, ++l_tccp) { @@ -2111,11 +2087,10 @@ static OPJ_BOOL opj_tcd_dwt_decode(opj_tcd_t *p_tcd) return OPJ_TRUE; } -static OPJ_BOOL opj_tcd_mct_decode(opj_tcd_t *p_tcd, opj_event_mgr_t *p_manager) -{ - opj_tcd_tile_t * l_tile = p_tcd->tcd_image->tiles; - opj_tcp_t * l_tcp = p_tcd->tcp; - opj_tcd_tilecomp_t * l_tile_comp = l_tile->comps; +static OPJ_BOOL opj_tcd_mct_decode(opj_tcd_t *p_tcd, opj_event_mgr_t *p_manager) { + opj_tcd_tile_t *l_tile = p_tcd->tcd_image->tiles; + opj_tcp_t *l_tcp = p_tcd->tcp; + opj_tcd_tilecomp_t *l_tile_comp = l_tile->comps; OPJ_SIZE_T l_samples; OPJ_UINT32 i; @@ -2124,7 +2099,7 @@ static OPJ_BOOL opj_tcd_mct_decode(opj_tcd_t *p_tcd, opj_event_mgr_t *p_manager) } if (p_tcd->whole_tile_decoding) { - opj_tcd_resolution_t* res_comp0 = l_tile->comps[0].resolutions + + opj_tcd_resolution_t *res_comp0 = l_tile->comps[0].resolutions + l_tile_comp->minimum_num_resolutions - 1; /* A bit inefficient: we process more data than needed if */ @@ -2143,9 +2118,9 @@ static OPJ_BOOL opj_tcd_mct_decode(opj_tcd_t *p_tcd, opj_event_mgr_t *p_manager) } } if (l_tile->numcomps >= 3) { - opj_tcd_resolution_t* res_comp1 = l_tile->comps[1].resolutions + + opj_tcd_resolution_t *res_comp1 = l_tile->comps[1].resolutions + l_tile_comp->minimum_num_resolutions - 1; - opj_tcd_resolution_t* res_comp2 = l_tile->comps[2].resolutions + + opj_tcd_resolution_t *res_comp2 = l_tile->comps[2].resolutions + l_tile_comp->minimum_num_resolutions - 1; /* testcase 1336.pdf.asan.47.376 */ if (p_tcd->image->comps[0].resno_decoded != @@ -2162,15 +2137,15 @@ static OPJ_BOOL opj_tcd_mct_decode(opj_tcd_t *p_tcd, opj_event_mgr_t *p_manager) } } } else { - opj_tcd_resolution_t* res_comp0 = l_tile->comps[0].resolutions + + opj_tcd_resolution_t *res_comp0 = l_tile->comps[0].resolutions + p_tcd->image->comps[0].resno_decoded; l_samples = (OPJ_SIZE_T)(res_comp0->win_x1 - res_comp0->win_x0) * (OPJ_SIZE_T)(res_comp0->win_y1 - res_comp0->win_y0); if (l_tile->numcomps >= 3) { - opj_tcd_resolution_t* res_comp1 = l_tile->comps[1].resolutions + + opj_tcd_resolution_t *res_comp1 = l_tile->comps[1].resolutions + p_tcd->image->comps[1].resno_decoded; - opj_tcd_resolution_t* res_comp2 = l_tile->comps[2].resolutions + + opj_tcd_resolution_t *res_comp2 = l_tile->comps[2].resolutions + p_tcd->image->comps[2].resno_decoded; /* testcase 1336.pdf.asan.47.376 */ if (p_tcd->image->comps[0].resno_decoded != @@ -2190,28 +2165,28 @@ static OPJ_BOOL opj_tcd_mct_decode(opj_tcd_t *p_tcd, opj_event_mgr_t *p_manager) if (l_tile->numcomps >= 3) { if (l_tcp->mct == 2) { - OPJ_BYTE ** l_data; + OPJ_BYTE **l_data; if (! l_tcp->m_mct_decoding_matrix) { return OPJ_TRUE; } - l_data = (OPJ_BYTE **) opj_malloc(l_tile->numcomps * sizeof(OPJ_BYTE*)); + l_data = (OPJ_BYTE **) opj_malloc(l_tile->numcomps * sizeof(OPJ_BYTE *)); if (! l_data) { return OPJ_FALSE; } for (i = 0; i < l_tile->numcomps; ++i) { if (p_tcd->whole_tile_decoding) { - l_data[i] = (OPJ_BYTE*) l_tile_comp->data; + l_data[i] = (OPJ_BYTE *) l_tile_comp->data; } else { - l_data[i] = (OPJ_BYTE*) l_tile_comp->data_win; + l_data[i] = (OPJ_BYTE *) l_tile_comp->data_win; } ++l_tile_comp; } if (! opj_mct_decode_custom(/* MCT data */ - (OPJ_BYTE*) l_tcp->m_mct_decoding_matrix, + (OPJ_BYTE *) l_tcp->m_mct_decoding_matrix, /* size of components */ l_samples, /* components */ @@ -2240,14 +2215,14 @@ static OPJ_BOOL opj_tcd_mct_decode(opj_tcd_t *p_tcd, opj_event_mgr_t *p_manager) } } else { if (p_tcd->whole_tile_decoding) { - opj_mct_decode_real((OPJ_FLOAT32*)l_tile->comps[0].data, - (OPJ_FLOAT32*)l_tile->comps[1].data, - (OPJ_FLOAT32*)l_tile->comps[2].data, + opj_mct_decode_real((OPJ_FLOAT32 *)l_tile->comps[0].data, + (OPJ_FLOAT32 *)l_tile->comps[1].data, + (OPJ_FLOAT32 *)l_tile->comps[2].data, l_samples); } else { - opj_mct_decode_real((OPJ_FLOAT32*)l_tile->comps[0].data_win, - (OPJ_FLOAT32*)l_tile->comps[1].data_win, - (OPJ_FLOAT32*)l_tile->comps[2].data_win, + opj_mct_decode_real((OPJ_FLOAT32 *)l_tile->comps[0].data_win, + (OPJ_FLOAT32 *)l_tile->comps[1].data_win, + (OPJ_FLOAT32 *)l_tile->comps[2].data_win, l_samples); } } @@ -2262,16 +2237,15 @@ static OPJ_BOOL opj_tcd_mct_decode(opj_tcd_t *p_tcd, opj_event_mgr_t *p_manager) } -static OPJ_BOOL opj_tcd_dc_level_shift_decode(opj_tcd_t *p_tcd) -{ +static OPJ_BOOL opj_tcd_dc_level_shift_decode(opj_tcd_t *p_tcd) { OPJ_UINT32 compno; - opj_tcd_tilecomp_t * l_tile_comp = 00; - opj_tccp_t * l_tccp = 00; - opj_image_comp_t * l_img_comp = 00; - opj_tcd_resolution_t* l_res = 00; - opj_tcd_tile_t * l_tile; + opj_tcd_tilecomp_t *l_tile_comp = 00; + opj_tccp_t *l_tccp = 00; + opj_image_comp_t *l_img_comp = 00; + opj_tcd_resolution_t *l_res = 00; + opj_tcd_tile_t *l_tile; OPJ_UINT32 l_width, l_height, i, j; - OPJ_INT32 * l_current_ptr; + OPJ_INT32 *l_current_ptr; OPJ_INT32 l_min, l_max; OPJ_UINT32 l_stride; @@ -2358,11 +2332,10 @@ static OPJ_BOOL opj_tcd_dc_level_shift_decode(opj_tcd_t *p_tcd) /** * Deallocates the encoding data of the given precinct. */ -static void opj_tcd_code_block_dec_deallocate(opj_tcd_precinct_t * p_precinct) -{ +static void opj_tcd_code_block_dec_deallocate(opj_tcd_precinct_t *p_precinct) { OPJ_UINT32 cblkno, l_nb_code_blocks; - opj_tcd_cblk_dec_t * l_code_block = p_precinct->cblks.dec; + opj_tcd_cblk_dec_t *l_code_block = p_precinct->cblks.dec; if (l_code_block) { /*fprintf(stderr,"deallocate codeblock:{\n");*/ /*fprintf(stderr,"\t x0=%d, y0=%d, x1=%d, y1=%d\n",l_code_block->x0, l_code_block->y0, l_code_block->x1, l_code_block->y1);*/ @@ -2400,11 +2373,10 @@ static void opj_tcd_code_block_dec_deallocate(opj_tcd_precinct_t * p_precinct) /** * Deallocates the encoding data of the given precinct. */ -static void opj_tcd_code_block_enc_deallocate(opj_tcd_precinct_t * p_precinct) -{ +static void opj_tcd_code_block_enc_deallocate(opj_tcd_precinct_t *p_precinct) { OPJ_UINT32 cblkno, l_nb_code_blocks; - opj_tcd_cblk_enc_t * l_code_block = p_precinct->cblks.enc; + opj_tcd_cblk_enc_t *l_code_block = p_precinct->cblks.enc; if (l_code_block) { l_nb_code_blocks = p_precinct->block_size / (OPJ_UINT32)sizeof( opj_tcd_cblk_enc_t); @@ -2435,12 +2407,11 @@ static void opj_tcd_code_block_enc_deallocate(opj_tcd_precinct_t * p_precinct) } } -OPJ_SIZE_T opj_tcd_get_encoder_input_buffer_size(opj_tcd_t *p_tcd) -{ +OPJ_SIZE_T opj_tcd_get_encoder_input_buffer_size(opj_tcd_t *p_tcd) { OPJ_UINT32 i; OPJ_SIZE_T l_data_size = 0; - opj_image_comp_t * l_img_comp = 00; - opj_tcd_tilecomp_t * l_tilec = 00; + opj_image_comp_t *l_img_comp = 00; + opj_tcd_tilecomp_t *l_tilec = 00; OPJ_UINT32 l_size_comp, l_remaining; l_tilec = p_tcd->tcd_image->tiles->comps; @@ -2466,15 +2437,14 @@ OPJ_SIZE_T opj_tcd_get_encoder_input_buffer_size(opj_tcd_t *p_tcd) return l_data_size; } -static OPJ_BOOL opj_tcd_dc_level_shift_encode(opj_tcd_t *p_tcd) -{ +static OPJ_BOOL opj_tcd_dc_level_shift_encode(opj_tcd_t *p_tcd) { OPJ_UINT32 compno; - opj_tcd_tilecomp_t * l_tile_comp = 00; - opj_tccp_t * l_tccp = 00; - opj_image_comp_t * l_img_comp = 00; - opj_tcd_tile_t * l_tile; + opj_tcd_tilecomp_t *l_tile_comp = 00; + opj_tccp_t *l_tccp = 00; + opj_image_comp_t *l_img_comp = 00; + opj_tcd_tile_t *l_tile; OPJ_SIZE_T l_nb_elem, i; - OPJ_INT32 * l_current_ptr; + OPJ_INT32 *l_current_ptr; l_tile = p_tcd->tcd_image->tiles; l_tile_comp = l_tile->comps; @@ -2494,7 +2464,7 @@ static OPJ_BOOL opj_tcd_dc_level_shift_encode(opj_tcd_t *p_tcd) } else { for (i = 0; i < l_nb_elem; ++i) { *((OPJ_FLOAT32 *) l_current_ptr) = (OPJ_FLOAT32)(*l_current_ptr - - l_tccp->m_dc_level_shift); + l_tccp->m_dc_level_shift); ++l_current_ptr; } } @@ -2507,15 +2477,14 @@ static OPJ_BOOL opj_tcd_dc_level_shift_encode(opj_tcd_t *p_tcd) return OPJ_TRUE; } -static OPJ_BOOL opj_tcd_mct_encode(opj_tcd_t *p_tcd) -{ - opj_tcd_tile_t * l_tile = p_tcd->tcd_image->tiles; - opj_tcd_tilecomp_t * l_tile_comp = p_tcd->tcd_image->tiles->comps; +static OPJ_BOOL opj_tcd_mct_encode(opj_tcd_t *p_tcd) { + opj_tcd_tile_t *l_tile = p_tcd->tcd_image->tiles; + opj_tcd_tilecomp_t *l_tile_comp = p_tcd->tcd_image->tiles->comps; OPJ_SIZE_T samples = (OPJ_SIZE_T)(l_tile_comp->x1 - l_tile_comp->x0) * (OPJ_SIZE_T)(l_tile_comp->y1 - l_tile_comp->y0); OPJ_UINT32 i; - OPJ_BYTE ** l_data = 00; - opj_tcp_t * l_tcp = p_tcd->tcp; + OPJ_BYTE **l_data = 00; + opj_tcp_t *l_tcp = p_tcd->tcp; if (!p_tcd->tcp->mct) { return OPJ_TRUE; @@ -2526,18 +2495,18 @@ static OPJ_BOOL opj_tcd_mct_encode(opj_tcd_t *p_tcd) return OPJ_TRUE; } - l_data = (OPJ_BYTE **) opj_malloc(l_tile->numcomps * sizeof(OPJ_BYTE*)); + l_data = (OPJ_BYTE **) opj_malloc(l_tile->numcomps * sizeof(OPJ_BYTE *)); if (! l_data) { return OPJ_FALSE; } for (i = 0; i < l_tile->numcomps; ++i) { - l_data[i] = (OPJ_BYTE*) l_tile_comp->data; + l_data[i] = (OPJ_BYTE *) l_tile_comp->data; ++l_tile_comp; } if (! opj_mct_encode_custom(/* MCT data */ - (OPJ_BYTE*) p_tcd->tcp->m_mct_coding_matrix, + (OPJ_BYTE *) p_tcd->tcp->m_mct_coding_matrix, /* size of components */ samples, /* components */ @@ -2553,9 +2522,9 @@ static OPJ_BOOL opj_tcd_mct_encode(opj_tcd_t *p_tcd) opj_free(l_data); } else if (l_tcp->tccps->qmfbid == 0) { opj_mct_encode_real( - (OPJ_FLOAT32*)l_tile->comps[0].data, - (OPJ_FLOAT32*)l_tile->comps[1].data, - (OPJ_FLOAT32*)l_tile->comps[2].data, + (OPJ_FLOAT32 *)l_tile->comps[0].data, + (OPJ_FLOAT32 *)l_tile->comps[1].data, + (OPJ_FLOAT32 *)l_tile->comps[2].data, samples); } else { opj_mct_encode(l_tile->comps[0].data, l_tile->comps[1].data, @@ -2565,11 +2534,10 @@ static OPJ_BOOL opj_tcd_mct_encode(opj_tcd_t *p_tcd) return OPJ_TRUE; } -static OPJ_BOOL opj_tcd_dwt_encode(opj_tcd_t *p_tcd) -{ - opj_tcd_tile_t * l_tile = p_tcd->tcd_image->tiles; - opj_tcd_tilecomp_t * l_tile_comp = p_tcd->tcd_image->tiles->comps; - opj_tccp_t * l_tccp = p_tcd->tcp->tccps; +static OPJ_BOOL opj_tcd_dwt_encode(opj_tcd_t *p_tcd) { + opj_tcd_tile_t *l_tile = p_tcd->tcd_image->tiles; + opj_tcd_tilecomp_t *l_tile_comp = p_tcd->tcd_image->tiles->comps; + opj_tccp_t *l_tccp = p_tcd->tcp->tccps; OPJ_UINT32 compno; for (compno = 0; compno < l_tile->numcomps; ++compno) { @@ -2590,11 +2558,10 @@ static OPJ_BOOL opj_tcd_dwt_encode(opj_tcd_t *p_tcd) return OPJ_TRUE; } -static OPJ_BOOL opj_tcd_t1_encode(opj_tcd_t *p_tcd) -{ - const OPJ_FLOAT64 * l_mct_norms; +static OPJ_BOOL opj_tcd_t1_encode(opj_tcd_t *p_tcd) { + const OPJ_FLOAT64 *l_mct_norms; OPJ_UINT32 l_mct_numcomps = 0U; - opj_tcp_t * l_tcp = p_tcd->tcp; + opj_tcp_t *l_tcp = p_tcd->tcp; if (l_tcp->mct == 1) { l_mct_numcomps = 3U; @@ -2617,14 +2584,13 @@ static OPJ_BOOL opj_tcd_t1_encode(opj_tcd_t *p_tcd) } static OPJ_BOOL opj_tcd_t2_encode(opj_tcd_t *p_tcd, - OPJ_BYTE * p_dest_data, - OPJ_UINT32 * p_data_written, + OPJ_BYTE *p_dest_data, + OPJ_UINT32 *p_data_written, OPJ_UINT32 p_max_dest_size, opj_codestream_info_t *p_cstr_info, - opj_tcd_marker_info_t* p_marker_info, - opj_event_mgr_t *p_manager) -{ - opj_t2_t * l_t2; + opj_tcd_marker_info_t *p_marker_info, + opj_event_mgr_t *p_manager) { + opj_t2_t *l_t2; l_t2 = opj_t2_create(p_tcd->image, p_tcd->cp); if (l_t2 == 00) { @@ -2658,12 +2624,11 @@ static OPJ_BOOL opj_tcd_t2_encode(opj_tcd_t *p_tcd, static OPJ_BOOL opj_tcd_rate_allocate_encode(opj_tcd_t *p_tcd, - OPJ_BYTE * p_dest_data, - OPJ_UINT32 p_max_dest_size, - opj_codestream_info_t *p_cstr_info, - opj_event_mgr_t *p_manager) -{ - opj_cp_t * l_cp = p_tcd->cp; + OPJ_BYTE *p_dest_data, + OPJ_UINT32 p_max_dest_size, + opj_codestream_info_t *p_cstr_info, + opj_event_mgr_t *p_manager) { + opj_cp_t *l_cp = p_tcd->cp; OPJ_UINT32 l_nb_written = 0; if (p_cstr_info) { @@ -2688,14 +2653,13 @@ static OPJ_BOOL opj_tcd_rate_allocate_encode(opj_tcd_t *p_tcd, OPJ_BOOL opj_tcd_copy_tile_data(opj_tcd_t *p_tcd, - OPJ_BYTE * p_src, - OPJ_SIZE_T p_src_length) -{ + OPJ_BYTE *p_src, + OPJ_SIZE_T p_src_length) { OPJ_UINT32 i; OPJ_SIZE_T j; OPJ_SIZE_T l_data_size = 0; - opj_image_comp_t * l_img_comp = 00; - opj_tcd_tilecomp_t * l_tilec = 00; + opj_image_comp_t *l_img_comp = 00; + opj_tcd_tilecomp_t *l_tilec = 00; OPJ_UINT32 l_size_comp, l_remaining; OPJ_SIZE_T l_nb_elem; @@ -2721,51 +2685,51 @@ OPJ_BOOL opj_tcd_copy_tile_data(opj_tcd_t *p_tcd, } switch (l_size_comp) { - case 1: { - OPJ_CHAR * l_src_ptr = (OPJ_CHAR *) p_src; - OPJ_INT32 * l_dest_ptr = l_tilec->data; + case 1: { + OPJ_CHAR *l_src_ptr = (OPJ_CHAR *) p_src; + OPJ_INT32 *l_dest_ptr = l_tilec->data; + + if (l_img_comp->sgnd) { + for (j = 0; j < l_nb_elem; ++j) { + *(l_dest_ptr++) = (OPJ_INT32)(*(l_src_ptr++)); + } + } else { + for (j = 0; j < l_nb_elem; ++j) { + *(l_dest_ptr++) = (*(l_src_ptr++)) & 0xff; + } + } + + p_src = (OPJ_BYTE *) l_src_ptr; + } + break; + case 2: { + OPJ_INT32 *l_dest_ptr = l_tilec->data; + OPJ_INT16 *l_src_ptr = (OPJ_INT16 *) p_src; + + if (l_img_comp->sgnd) { + for (j = 0; j < l_nb_elem; ++j) { + *(l_dest_ptr++) = (OPJ_INT32)(*(l_src_ptr++)); + } + } else { + for (j = 0; j < l_nb_elem; ++j) { + *(l_dest_ptr++) = (*(l_src_ptr++)) & 0xffff; + } + } + + p_src = (OPJ_BYTE *) l_src_ptr; + } + break; + case 4: { + OPJ_INT32 *l_src_ptr = (OPJ_INT32 *) p_src; + OPJ_INT32 *l_dest_ptr = l_tilec->data; - if (l_img_comp->sgnd) { for (j = 0; j < l_nb_elem; ++j) { *(l_dest_ptr++) = (OPJ_INT32)(*(l_src_ptr++)); } - } else { - for (j = 0; j < l_nb_elem; ++j) { - *(l_dest_ptr++) = (*(l_src_ptr++)) & 0xff; - } + + p_src = (OPJ_BYTE *) l_src_ptr; } - - p_src = (OPJ_BYTE*) l_src_ptr; - } - break; - case 2: { - OPJ_INT32 * l_dest_ptr = l_tilec->data; - OPJ_INT16 * l_src_ptr = (OPJ_INT16 *) p_src; - - if (l_img_comp->sgnd) { - for (j = 0; j < l_nb_elem; ++j) { - *(l_dest_ptr++) = (OPJ_INT32)(*(l_src_ptr++)); - } - } else { - for (j = 0; j < l_nb_elem; ++j) { - *(l_dest_ptr++) = (*(l_src_ptr++)) & 0xffff; - } - } - - p_src = (OPJ_BYTE*) l_src_ptr; - } - break; - case 4: { - OPJ_INT32 * l_src_ptr = (OPJ_INT32 *) p_src; - OPJ_INT32 * l_dest_ptr = l_tilec->data; - - for (j = 0; j < l_nb_elem; ++j) { - *(l_dest_ptr++) = (OPJ_INT32)(*(l_src_ptr++)); - } - - p_src = (OPJ_BYTE*) l_src_ptr; - } - break; + break; } ++l_img_comp; @@ -2775,20 +2739,18 @@ OPJ_BOOL opj_tcd_copy_tile_data(opj_tcd_t *p_tcd, return OPJ_TRUE; } -OPJ_BOOL opj_tcd_is_band_empty(opj_tcd_band_t* band) -{ +OPJ_BOOL opj_tcd_is_band_empty(opj_tcd_band_t *band) { return (band->x1 - band->x0 == 0) || (band->y1 - band->y0 == 0); } OPJ_BOOL opj_tcd_is_subband_area_of_interest(opj_tcd_t *tcd, - OPJ_UINT32 compno, - OPJ_UINT32 resno, - OPJ_UINT32 bandno, - OPJ_UINT32 band_x0, - OPJ_UINT32 band_y0, - OPJ_UINT32 band_x1, - OPJ_UINT32 band_y1) -{ + OPJ_UINT32 compno, + OPJ_UINT32 resno, + OPJ_UINT32 bandno, + OPJ_UINT32 band_x0, + OPJ_UINT32 band_y0, + OPJ_UINT32 band_x1, + OPJ_UINT32 band_y1) { /* Note: those values for filter_margin are in part the result of */ /* experimentation. The value 2 for QMFBID=1 (5x3 filter) can be linked */ /* to the maximum left/right extension given in tables F.2 and F.3 of the */ @@ -2799,7 +2761,7 @@ OPJ_BOOL opj_tcd_is_subband_area_of_interest(opj_tcd_t *tcd, /* See opj_dwt_decode_partial_53 and opj_dwt_decode_partial_97 as well */ OPJ_UINT32 filter_margin = (tcd->tcp->tccps[compno].qmfbid == 1) ? 2 : 3; opj_tcd_tilecomp_t *tilec = &(tcd->tcd_image->tiles->comps[compno]); - opj_image_comp_t* image_comp = &(tcd->image->comps[compno]); + opj_image_comp_t *image_comp = &(tcd->image->comps[compno]); /* Compute the intersection of the area of interest, expressed in tile coordinates */ /* with the tile coordinates */ OPJ_UINT32 tcx0 = opj_uint_max( @@ -2869,10 +2831,9 @@ OPJ_BOOL opj_tcd_is_subband_area_of_interest(opj_tcd_t *tcd, * @return OPJ_TRUE whether the tile component is fully decoded */ static OPJ_BOOL opj_tcd_is_whole_tilecomp_decoding(opj_tcd_t *p_tcd, - OPJ_UINT32 compno) -{ - opj_tcd_tilecomp_t* tilec = &(p_tcd->tcd_image->tiles->comps[compno]); - opj_image_comp_t* image_comp = &(p_tcd->image->comps[compno]); + OPJ_UINT32 compno) { + opj_tcd_tilecomp_t *tilec = &(p_tcd->tcd_image->tiles->comps[compno]); + opj_image_comp_t *image_comp = &(p_tcd->image->comps[compno]); /* Compute the intersection of the area of interest, expressed in tile coordinates */ /* with the tile coordinates */ OPJ_UINT32 tcx0 = opj_uint_max( @@ -2904,10 +2865,9 @@ static OPJ_BOOL opj_tcd_is_whole_tilecomp_decoding(opj_tcd_t *p_tcd, /* ----------------------------------------------------------------------- */ -opj_tcd_marker_info_t* opj_tcd_marker_info_create(OPJ_BOOL need_PLT) -{ +opj_tcd_marker_info_t *opj_tcd_marker_info_create(OPJ_BOOL need_PLT) { opj_tcd_marker_info_t *l_tcd_marker_info = - (opj_tcd_marker_info_t*) opj_calloc(1, sizeof(opj_tcd_marker_info_t)); + (opj_tcd_marker_info_t *) opj_calloc(1, sizeof(opj_tcd_marker_info_t)); if (!l_tcd_marker_info) { return NULL; } @@ -2919,8 +2879,7 @@ opj_tcd_marker_info_t* opj_tcd_marker_info_create(OPJ_BOOL need_PLT) /* ----------------------------------------------------------------------- */ -void opj_tcd_marker_info_destroy(opj_tcd_marker_info_t *p_tcd_marker_info) -{ +void opj_tcd_marker_info_destroy(opj_tcd_marker_info_t *p_tcd_marker_info) { if (p_tcd_marker_info) { opj_free(p_tcd_marker_info->p_packet_size); opj_free(p_tcd_marker_info); diff --git a/client/deps/openjpeg/tcd.h b/client/deps/openjpeg/tcd.h index 3371b08cb..c36b0e73f 100644 --- a/client/deps/openjpeg/tcd.h +++ b/client/deps/openjpeg/tcd.h @@ -75,9 +75,9 @@ typedef struct opj_tcd_layer { FIXME DOC */ typedef struct opj_tcd_cblk_enc { - OPJ_BYTE* data; /* Data */ - opj_tcd_layer_t* layers; /* layer information */ - opj_tcd_pass_t* passes; /* information about the passes */ + OPJ_BYTE *data; /* Data */ + opj_tcd_layer_t *layers; /* layer information */ + opj_tcd_pass_t *passes; /* information about the passes */ OPJ_INT32 x0, y0, x1, y1; /* dimension of the code-blocks : left upper corner (x0, y0) right low corner (x1,y1) */ OPJ_UINT32 numbps; @@ -95,7 +95,7 @@ typedef struct opj_tcd_seg_data_chunk { /* Point to tilepart buffer. We don't make a copy ! So the tilepart buffer must be kept alive as long as we need to decode the codeblocks */ - OPJ_BYTE * data; + OPJ_BYTE *data; OPJ_UINT32 len; /* Usable length of data */ } opj_tcd_seg_data_chunk_t; @@ -118,8 +118,8 @@ typedef struct opj_tcd_seg { /** Code-block for decoding */ typedef struct opj_tcd_cblk_dec { - opj_tcd_seg_t* segs; /* segments information */ - opj_tcd_seg_data_chunk_t* chunks; /* Array of chunks */ + opj_tcd_seg_t *segs; /* segments information */ + opj_tcd_seg_data_chunk_t *chunks; /* Array of chunks */ /* position of the code-blocks : left upper corner (x0, y0) right low corner (x1,y1) */ OPJ_INT32 x0, y0, x1, y1; /* Mb is The maximum number of bit-planes available for the representation of @@ -140,7 +140,7 @@ typedef struct opj_tcd_cblk_dec { OPJ_UINT32 numchunks; /* Number of valid chunks items */ OPJ_UINT32 numchunksalloc; /* Number of chunks item allocated */ /* Decoded code-block. Only used for subtile decoding. Otherwise tilec->data is directly updated */ - OPJ_INT32* decoded_data; + OPJ_INT32 *decoded_data; OPJ_BOOL corrupted; /* whether the code block data is corrupted */ } opj_tcd_cblk_dec_t; @@ -150,9 +150,9 @@ typedef struct opj_tcd_precinct { OPJ_INT32 x0, y0, x1, y1; OPJ_UINT32 cw, ch; /* number of code-blocks, in width and height */ union { /* code-blocks information */ - opj_tcd_cblk_enc_t* enc; - opj_tcd_cblk_dec_t* dec; - void* blocks; + opj_tcd_cblk_enc_t *enc; + opj_tcd_cblk_dec_t *dec; + void *blocks; } cblks; OPJ_UINT32 block_size; /* size taken by cblks (in bytes) */ opj_tgt_tree_t *incltree; /* inclusion tree */ @@ -278,7 +278,7 @@ typedef struct opj_tcd { /** tell if the tcd is a decoder. */ OPJ_BITFIELD m_is_decoder : 1; /** Thread pool */ - opj_thread_pool_t* thread_pool; + opj_thread_pool_t *thread_pool; /** Coordinates of the window of interest, in grid reference space */ OPJ_UINT32 win_x0; OPJ_UINT32 win_y0; @@ -287,7 +287,7 @@ typedef struct opj_tcd { /** Only valid for decoding. Whether the whole tile is decoded, or just the region in win_x0/win_y0/win_x1/win_y1 */ OPJ_BOOL whole_tile_decoding; /* Array of size image->numcomps indicating if a component must be decoded. NULL if all components must be decoded */ - OPJ_BOOL* used_component; + OPJ_BOOL *used_component; } opj_tcd_t; /** @@ -303,7 +303,7 @@ typedef struct opj_tcd_marker_info { /** OUT: Array of size packet_count, such that p_packet_size[i] is * the size in bytes of the ith packet */ - OPJ_UINT32* p_packet_size; + OPJ_UINT32 *p_packet_size; } opj_tcd_marker_info_t; /** @name Exported functions */ @@ -320,7 +320,7 @@ Create a new TCD handle @param p_is_decoder FIXME DOC @return Returns a new TCD handle if successful returns NULL otherwise */ -opj_tcd_t* opj_tcd_create(OPJ_BOOL p_is_decoder); +opj_tcd_t *opj_tcd_create(OPJ_BOOL p_is_decoder); /** Destroy a previously created TCD handle @@ -333,7 +333,7 @@ void opj_tcd_destroy(opj_tcd_t *tcd); * Create a new opj_tcd_marker_info_t* structure * @param need_PLT Whether information is needed to generate PLT markers. */ -opj_tcd_marker_info_t* opj_tcd_marker_info_create(OPJ_BOOL need_PLT); +opj_tcd_marker_info_t *opj_tcd_marker_info_create(OPJ_BOOL need_PLT); /** @@ -353,9 +353,9 @@ void opj_tcd_marker_info_destroy(opj_tcd_marker_info_t *p_tcd_marker_info); * @return true if the encoding values could be set (false otherwise). */ OPJ_BOOL opj_tcd_init(opj_tcd_t *p_tcd, - opj_image_t * p_image, - opj_cp_t * p_cp, - opj_thread_pool_t* p_tp); + opj_image_t *p_image, + opj_cp_t *p_cp, + opj_thread_pool_t *p_tp); /** * Allocates memory for decoding a specific tile. @@ -368,13 +368,13 @@ OPJ_BOOL opj_tcd_init(opj_tcd_t *p_tcd, * @return true if the remaining data is sufficient. */ OPJ_BOOL opj_tcd_init_decode_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no, - opj_event_mgr_t* p_manager); + opj_event_mgr_t *p_manager); /** * Gets the maximum tile size that will be taken by the tile once decoded. */ OPJ_UINT32 opj_tcd_get_decoded_tile_size(opj_tcd_t *p_tcd, - OPJ_BOOL take_into_account_partial_decoding); + OPJ_BOOL take_into_account_partial_decoding); /** * Encodes a tile from the raw image into the given buffer. @@ -391,10 +391,10 @@ OPJ_UINT32 opj_tcd_get_decoded_tile_size(opj_tcd_t *p_tcd, OPJ_BOOL opj_tcd_encode_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no, OPJ_BYTE *p_dest, - OPJ_UINT32 * p_data_written, + OPJ_UINT32 *p_data_written, OPJ_UINT32 p_len, struct opj_codestream_info *p_cstr_info, - opj_tcd_marker_info_t* p_marker_info, + opj_tcd_marker_info_t *p_marker_info, opj_event_mgr_t *p_manager); @@ -433,7 +433,7 @@ OPJ_BOOL opj_tcd_decode_tile(opj_tcd_t *tcd, * Copies tile data from the system onto the given memory block. */ OPJ_BOOL opj_tcd_update_tile_data(opj_tcd_t *p_tcd, - OPJ_BYTE * p_dest, + OPJ_BYTE *p_dest, OPJ_UINT32 p_dest_length); /** @@ -453,7 +453,7 @@ OPJ_SIZE_T opj_tcd_get_encoder_input_buffer_size(opj_tcd_t *p_tcd); * @return true if the encoding values could be set (false otherwise). */ OPJ_BOOL opj_tcd_init_encode_tile(opj_tcd_t *p_tcd, - OPJ_UINT32 p_tile_no, opj_event_mgr_t* p_manager); + OPJ_UINT32 p_tile_no, opj_event_mgr_t *p_manager); /** * Copies tile data from the given memory block onto the system. @@ -461,7 +461,7 @@ OPJ_BOOL opj_tcd_init_encode_tile(opj_tcd_t *p_tcd, * p_src_length must be equal to opj_tcd_get_encoder_input_buffer_size() */ OPJ_BOOL opj_tcd_copy_tile_data(opj_tcd_t *p_tcd, - OPJ_BYTE * p_src, + OPJ_BYTE *p_src, OPJ_SIZE_T p_src_length); /** @@ -475,10 +475,10 @@ OPJ_BOOL opj_alloc_tile_component_data(opj_tcd_tilecomp_t *l_tilec); * @param band Sub-band handle. * @return OPJ_TRUE whether the sub-band is empty. */ -OPJ_BOOL opj_tcd_is_band_empty(opj_tcd_band_t* band); +OPJ_BOOL opj_tcd_is_band_empty(opj_tcd_band_t *band); /** Reinitialize a segment */ -void opj_tcd_reinit_segment(opj_tcd_seg_t* seg); +void opj_tcd_reinit_segment(opj_tcd_seg_t *seg); /** Returns whether a sub-band region contributes to the area of interest @@ -496,13 +496,13 @@ void opj_tcd_reinit_segment(opj_tcd_seg_t* seg); * interest. */ OPJ_BOOL opj_tcd_is_subband_area_of_interest(opj_tcd_t *tcd, - OPJ_UINT32 compno, - OPJ_UINT32 resno, - OPJ_UINT32 bandno, - OPJ_UINT32 x0, - OPJ_UINT32 y0, - OPJ_UINT32 x1, - OPJ_UINT32 y1); + OPJ_UINT32 compno, + OPJ_UINT32 resno, + OPJ_UINT32 bandno, + OPJ_UINT32 x0, + OPJ_UINT32 y0, + OPJ_UINT32 x1, + OPJ_UINT32 y1); /* ----------------------------------------------------------------------- */ /*@}*/ diff --git a/client/deps/openjpeg/tgt.c b/client/deps/openjpeg/tgt.c index 711d753f4..e8741e497 100644 --- a/client/deps/openjpeg/tgt.c +++ b/client/deps/openjpeg/tgt.c @@ -46,8 +46,7 @@ */ opj_tgt_tree_t *opj_tgt_create(OPJ_UINT32 numleafsh, OPJ_UINT32 numleafsv, - opj_event_mgr_t *p_manager) -{ + opj_event_mgr_t *p_manager) { OPJ_INT32 nplh[32]; OPJ_INT32 nplv[32]; opj_tgt_node_t *node = 00; @@ -86,8 +85,8 @@ opj_tgt_tree_t *opj_tgt_create(OPJ_UINT32 numleafsh, OPJ_UINT32 numleafsv, return 00; } - tree->nodes = (opj_tgt_node_t*) opj_calloc(tree->numnodes, - sizeof(opj_tgt_node_t)); + tree->nodes = (opj_tgt_node_t *) opj_calloc(tree->numnodes, + sizeof(opj_tgt_node_t)); if (!tree->nodes) { opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to create Tag-tree nodes\n"); @@ -133,9 +132,8 @@ opj_tgt_tree_t *opj_tgt_create(OPJ_UINT32 numleafsh, OPJ_UINT32 numleafsv, * @param p_num_leafs_v the height of the array of leafs of the tree * @return a new tag-tree if successful, NULL otherwise */ -opj_tgt_tree_t *opj_tgt_init(opj_tgt_tree_t * p_tree, OPJ_UINT32 p_num_leafs_h, - OPJ_UINT32 p_num_leafs_v, opj_event_mgr_t *p_manager) -{ +opj_tgt_tree_t *opj_tgt_init(opj_tgt_tree_t *p_tree, OPJ_UINT32 p_num_leafs_h, + OPJ_UINT32 p_num_leafs_v, opj_event_mgr_t *p_manager) { OPJ_INT32 l_nplh[32]; OPJ_INT32 l_nplv[32]; opj_tgt_node_t *l_node = 00; @@ -176,8 +174,8 @@ opj_tgt_tree_t *opj_tgt_init(opj_tgt_tree_t * p_tree, OPJ_UINT32 p_num_leafs_h, l_node_size = p_tree->numnodes * (OPJ_UINT32)sizeof(opj_tgt_node_t); if (l_node_size > p_tree->nodes_size) { - opj_tgt_node_t* new_nodes = (opj_tgt_node_t*) opj_realloc(p_tree->nodes, - l_node_size); + opj_tgt_node_t *new_nodes = (opj_tgt_node_t *) opj_realloc(p_tree->nodes, + l_node_size); if (! new_nodes) { opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to reinitialize the tag tree\n"); @@ -220,8 +218,7 @@ opj_tgt_tree_t *opj_tgt_init(opj_tgt_tree_t * p_tree, OPJ_UINT32 p_num_leafs_h, return p_tree; } -void opj_tgt_destroy(opj_tgt_tree_t *p_tree) -{ +void opj_tgt_destroy(opj_tgt_tree_t *p_tree) { if (! p_tree) { return; } @@ -233,10 +230,9 @@ void opj_tgt_destroy(opj_tgt_tree_t *p_tree) opj_free(p_tree); } -void opj_tgt_reset(opj_tgt_tree_t *p_tree) -{ +void opj_tgt_reset(opj_tgt_tree_t *p_tree) { OPJ_UINT32 i; - opj_tgt_node_t * l_current_node = 00;; + opj_tgt_node_t *l_current_node = 00;; if (! p_tree) { return; @@ -251,8 +247,7 @@ void opj_tgt_reset(opj_tgt_tree_t *p_tree) } } -void opj_tgt_setvalue(opj_tgt_tree_t *tree, OPJ_UINT32 leafno, OPJ_INT32 value) -{ +void opj_tgt_setvalue(opj_tgt_tree_t *tree, OPJ_UINT32 leafno, OPJ_INT32 value) { opj_tgt_node_t *node; node = &tree->nodes[leafno]; while (node && node->value > value) { @@ -262,8 +257,7 @@ void opj_tgt_setvalue(opj_tgt_tree_t *tree, OPJ_UINT32 leafno, OPJ_INT32 value) } void opj_tgt_encode(opj_bio_t *bio, opj_tgt_tree_t *tree, OPJ_UINT32 leafno, - OPJ_INT32 threshold) -{ + OPJ_INT32 threshold) { opj_tgt_node_t *stk[31]; opj_tgt_node_t **stkptr; opj_tgt_node_t *node; @@ -305,8 +299,7 @@ void opj_tgt_encode(opj_bio_t *bio, opj_tgt_tree_t *tree, OPJ_UINT32 leafno, } OPJ_UINT32 opj_tgt_decode(opj_bio_t *bio, opj_tgt_tree_t *tree, - OPJ_UINT32 leafno, OPJ_INT32 threshold) -{ + OPJ_UINT32 leafno, OPJ_INT32 threshold) { opj_tgt_node_t *stk[31]; opj_tgt_node_t **stkptr; opj_tgt_node_t *node; diff --git a/client/deps/openjpeg/tgt.h b/client/deps/openjpeg/tgt.h index 9818208b8..41224f6f6 100644 --- a/client/deps/openjpeg/tgt.h +++ b/client/deps/openjpeg/tgt.h @@ -95,7 +95,7 @@ opj_tgt_tree_t *opj_tgt_create(OPJ_UINT32 numleafsh, OPJ_UINT32 numleafsv, * @param p_manager the event manager * @return a new tag-tree if successful, NULL otherwise */ -opj_tgt_tree_t *opj_tgt_init(opj_tgt_tree_t * p_tree, +opj_tgt_tree_t *opj_tgt_init(opj_tgt_tree_t *p_tree, OPJ_UINT32 p_num_leafs_h, OPJ_UINT32 p_num_leafs_v, opj_event_mgr_t *p_manager); /** diff --git a/client/deps/openjpeg/thread.c b/client/deps/openjpeg/thread.c index 240810b1c..e4c5a0457 100644 --- a/client/deps/openjpeg/thread.c +++ b/client/deps/openjpeg/thread.c @@ -45,13 +45,11 @@ #include "opj_includes.h" -OPJ_BOOL OPJ_CALLCONV opj_has_thread_support(void) -{ +OPJ_BOOL OPJ_CALLCONV opj_has_thread_support(void) { return OPJ_TRUE; } -int OPJ_CALLCONV opj_get_num_cpus(void) -{ +int OPJ_CALLCONV opj_get_num_cpus(void) { SYSTEM_INFO info; DWORD dwNum; GetSystemInfo(&info); @@ -66,9 +64,8 @@ struct opj_mutex_t { CRITICAL_SECTION cs; }; -opj_mutex_t* opj_mutex_create(void) -{ - opj_mutex_t* mutex = (opj_mutex_t*) opj_malloc(sizeof(opj_mutex_t)); +opj_mutex_t *opj_mutex_create(void) { + opj_mutex_t *mutex = (opj_mutex_t *) opj_malloc(sizeof(opj_mutex_t)); if (!mutex) { return NULL; } @@ -76,18 +73,15 @@ opj_mutex_t* opj_mutex_create(void) return mutex; } -void opj_mutex_lock(opj_mutex_t* mutex) -{ +void opj_mutex_lock(opj_mutex_t *mutex) { EnterCriticalSection(&(mutex->cs)); } -void opj_mutex_unlock(opj_mutex_t* mutex) -{ +void opj_mutex_unlock(opj_mutex_t *mutex) { LeaveCriticalSection(&(mutex->cs)); } -void opj_mutex_destroy(opj_mutex_t* mutex) -{ +void opj_mutex_destroy(opj_mutex_t *mutex) { if (!mutex) { return; } @@ -97,7 +91,7 @@ void opj_mutex_destroy(opj_mutex_t* mutex) struct opj_cond_waiter_list_t { HANDLE hEvent; - struct opj_cond_waiter_list_t* next; + struct opj_cond_waiter_list_t *next; }; typedef struct opj_cond_waiter_list_t opj_cond_waiter_list_t; @@ -110,9 +104,8 @@ static DWORD TLSKey = 0; static volatile LONG inTLSLockedSection = 0; static volatile int TLSKeyInit = OPJ_FALSE; -opj_cond_t* opj_cond_create(void) -{ - opj_cond_t* cond = (opj_cond_t*) opj_malloc(sizeof(opj_cond_t)); +opj_cond_t *opj_cond_create(void) { + opj_cond_t *cond = (opj_cond_t *) opj_malloc(sizeof(opj_cond_t)); if (!cond) { return NULL; } @@ -150,9 +143,8 @@ opj_cond_t* opj_cond_create(void) return cond; } -void opj_cond_wait(opj_cond_t* cond, opj_mutex_t* mutex) -{ - opj_cond_waiter_list_t* item; +void opj_cond_wait(opj_cond_t *cond, opj_mutex_t *mutex) { + opj_cond_waiter_list_t *item; HANDLE hEvent = (HANDLE) TlsGetValue(TLSKey); if (hEvent == NULL) { hEvent = CreateEvent(NULL, /* security attributes */ @@ -167,7 +159,7 @@ void opj_cond_wait(opj_cond_t* cond, opj_mutex_t* mutex) /* Insert the waiter into the waiter list of the condition */ opj_mutex_lock(cond->internal_mutex); - item = (opj_cond_waiter_list_t*)opj_malloc(sizeof(opj_cond_waiter_list_t)); + item = (opj_cond_waiter_list_t *)opj_malloc(sizeof(opj_cond_waiter_list_t)); assert(item != NULL); item->hEvent = hEvent; @@ -188,9 +180,8 @@ void opj_cond_wait(opj_cond_t* cond, opj_mutex_t* mutex) opj_mutex_lock(mutex); } -void opj_cond_signal(opj_cond_t* cond) -{ - opj_cond_waiter_list_t* psIter; +void opj_cond_signal(opj_cond_t *cond) { + opj_cond_waiter_list_t *psIter; /* Signal the first registered event, and remove it from the list */ opj_mutex_lock(cond->internal_mutex); @@ -205,8 +196,7 @@ void opj_cond_signal(opj_cond_t* cond) opj_mutex_unlock(cond->internal_mutex); } -void opj_cond_destroy(opj_cond_t* cond) -{ +void opj_cond_destroy(opj_cond_t *cond) { if (!cond) { return; } @@ -217,13 +207,12 @@ void opj_cond_destroy(opj_cond_t* cond) struct opj_thread_t { opj_thread_fn thread_fn; - void* user_data; + void *user_data; HANDLE hThread; }; -static unsigned int __stdcall opj_thread_callback_adapter(void *info) -{ - opj_thread_t* thread = (opj_thread_t*) info; +static unsigned int __stdcall opj_thread_callback_adapter(void *info) { + opj_thread_t *thread = (opj_thread_t *) info; HANDLE hEvent = NULL; thread->thread_fn(thread->user_data); @@ -251,13 +240,12 @@ static unsigned int __stdcall opj_thread_callback_adapter(void *info) return 0; } -opj_thread_t* opj_thread_create(opj_thread_fn thread_fn, void* user_data) -{ - opj_thread_t* thread; +opj_thread_t *opj_thread_create(opj_thread_fn thread_fn, void *user_data) { + opj_thread_t *thread; assert(thread_fn); - thread = (opj_thread_t*) opj_malloc(sizeof(opj_thread_t)); + thread = (opj_thread_t *) opj_malloc(sizeof(opj_thread_t)); if (!thread) { return NULL; } @@ -265,7 +253,7 @@ opj_thread_t* opj_thread_create(opj_thread_fn thread_fn, void* user_data) thread->user_data = user_data; thread->hThread = (HANDLE)_beginthreadex(NULL, 0, - opj_thread_callback_adapter, thread, 0, NULL); + opj_thread_callback_adapter, thread, 0, NULL); if (thread->hThread == NULL) { opj_free(thread); @@ -274,8 +262,7 @@ opj_thread_t* opj_thread_create(opj_thread_fn thread_fn, void* user_data) return thread; } -void opj_thread_join(opj_thread_t* thread) -{ +void opj_thread_join(opj_thread_t *thread) { WaitForSingleObject(thread->hThread, INFINITE); CloseHandle(thread->hThread); @@ -292,13 +279,11 @@ void opj_thread_join(opj_thread_t* thread) /* avoid poisoning issuing with malloc() use in pthread.h with ulibc (#1013) */ #include "opj_includes.h" -OPJ_BOOL OPJ_CALLCONV opj_has_thread_support(void) -{ +OPJ_BOOL OPJ_CALLCONV opj_has_thread_support(void) { return OPJ_TRUE; } -int OPJ_CALLCONV opj_get_num_cpus(void) -{ +int OPJ_CALLCONV opj_get_num_cpus(void) { #ifdef _SC_NPROCESSORS_ONLN return (int)sysconf(_SC_NPROCESSORS_ONLN); #else @@ -310,9 +295,8 @@ struct opj_mutex_t { pthread_mutex_t mutex; }; -opj_mutex_t* opj_mutex_create(void) -{ - opj_mutex_t* mutex = (opj_mutex_t*) opj_calloc(1U, sizeof(opj_mutex_t)); +opj_mutex_t *opj_mutex_create(void) { + opj_mutex_t *mutex = (opj_mutex_t *) opj_calloc(1U, sizeof(opj_mutex_t)); if (mutex != NULL) { if (pthread_mutex_init(&mutex->mutex, NULL) != 0) { opj_free(mutex); @@ -322,18 +306,15 @@ opj_mutex_t* opj_mutex_create(void) return mutex; } -void opj_mutex_lock(opj_mutex_t* mutex) -{ +void opj_mutex_lock(opj_mutex_t *mutex) { pthread_mutex_lock(&(mutex->mutex)); } -void opj_mutex_unlock(opj_mutex_t* mutex) -{ +void opj_mutex_unlock(opj_mutex_t *mutex) { pthread_mutex_unlock(&(mutex->mutex)); } -void opj_mutex_destroy(opj_mutex_t* mutex) -{ +void opj_mutex_destroy(opj_mutex_t *mutex) { if (!mutex) { return; } @@ -345,9 +326,8 @@ struct opj_cond_t { pthread_cond_t cond; }; -opj_cond_t* opj_cond_create(void) -{ - opj_cond_t* cond = (opj_cond_t*) opj_malloc(sizeof(opj_cond_t)); +opj_cond_t *opj_cond_create(void) { + opj_cond_t *cond = (opj_cond_t *) opj_malloc(sizeof(opj_cond_t)); if (!cond) { return NULL; } @@ -358,20 +338,17 @@ opj_cond_t* opj_cond_create(void) return cond; } -void opj_cond_wait(opj_cond_t* cond, opj_mutex_t* mutex) -{ +void opj_cond_wait(opj_cond_t *cond, opj_mutex_t *mutex) { pthread_cond_wait(&(cond->cond), &(mutex->mutex)); } -void opj_cond_signal(opj_cond_t* cond) -{ +void opj_cond_signal(opj_cond_t *cond) { int ret = pthread_cond_signal(&(cond->cond)); (void)ret; assert(ret == 0); } -void opj_cond_destroy(opj_cond_t* cond) -{ +void opj_cond_destroy(opj_cond_t *cond) { if (!cond) { return; } @@ -382,25 +359,23 @@ void opj_cond_destroy(opj_cond_t* cond) struct opj_thread_t { opj_thread_fn thread_fn; - void* user_data; + void *user_data; pthread_t thread; }; -static void* opj_thread_callback_adapter(void* info) -{ - opj_thread_t* thread = (opj_thread_t*) info; +static void *opj_thread_callback_adapter(void *info) { + opj_thread_t *thread = (opj_thread_t *) info; thread->thread_fn(thread->user_data); return NULL; } -opj_thread_t* opj_thread_create(opj_thread_fn thread_fn, void* user_data) -{ +opj_thread_t *opj_thread_create(opj_thread_fn thread_fn, void *user_data) { pthread_attr_t attr; - opj_thread_t* thread; + opj_thread_t *thread; assert(thread_fn); - thread = (opj_thread_t*) opj_malloc(sizeof(opj_thread_t)); + thread = (opj_thread_t *) opj_malloc(sizeof(opj_thread_t)); if (!thread) { return NULL; } @@ -417,9 +392,8 @@ opj_thread_t* opj_thread_create(opj_thread_fn thread_fn, void* user_data) return thread; } -void opj_thread_join(opj_thread_t* thread) -{ - void* status; +void opj_thread_join(opj_thread_t *thread) { + void *status; pthread_join(thread->thread, &status); opj_free(thread); @@ -430,66 +404,54 @@ void opj_thread_join(opj_thread_t* thread) #include "opj_includes.h" -OPJ_BOOL OPJ_CALLCONV opj_has_thread_support(void) -{ +OPJ_BOOL OPJ_CALLCONV opj_has_thread_support(void) { return OPJ_FALSE; } -int OPJ_CALLCONV opj_get_num_cpus(void) -{ +int OPJ_CALLCONV opj_get_num_cpus(void) { return 1; } -opj_mutex_t* opj_mutex_create(void) -{ +opj_mutex_t *opj_mutex_create(void) { return NULL; } -void opj_mutex_lock(opj_mutex_t* mutex) -{ +void opj_mutex_lock(opj_mutex_t *mutex) { (void) mutex; } -void opj_mutex_unlock(opj_mutex_t* mutex) -{ +void opj_mutex_unlock(opj_mutex_t *mutex) { (void) mutex; } -void opj_mutex_destroy(opj_mutex_t* mutex) -{ +void opj_mutex_destroy(opj_mutex_t *mutex) { (void) mutex; } -opj_cond_t* opj_cond_create(void) -{ +opj_cond_t *opj_cond_create(void) { return NULL; } -void opj_cond_wait(opj_cond_t* cond, opj_mutex_t* mutex) -{ +void opj_cond_wait(opj_cond_t *cond, opj_mutex_t *mutex) { (void) cond; (void) mutex; } -void opj_cond_signal(opj_cond_t* cond) -{ +void opj_cond_signal(opj_cond_t *cond) { (void) cond; } -void opj_cond_destroy(opj_cond_t* cond) -{ +void opj_cond_destroy(opj_cond_t *cond) { (void) cond; } -opj_thread_t* opj_thread_create(opj_thread_fn thread_fn, void* user_data) -{ +opj_thread_t *opj_thread_create(opj_thread_fn thread_fn, void *user_data) { (void) thread_fn; (void) user_data; return NULL; } -void opj_thread_join(opj_thread_t* thread) -{ +void opj_thread_join(opj_thread_t *thread) { (void) thread; } @@ -497,22 +459,20 @@ void opj_thread_join(opj_thread_t* thread) typedef struct { int key; - void* value; + void *value; opj_tls_free_func opj_free_func; } opj_tls_key_val_t; struct opj_tls_t { - opj_tls_key_val_t* key_val; + opj_tls_key_val_t *key_val; int key_val_count; }; -static opj_tls_t* opj_tls_new(void) -{ - return (opj_tls_t*) opj_calloc(1, sizeof(opj_tls_t)); +static opj_tls_t *opj_tls_new(void) { + return (opj_tls_t *) opj_calloc(1, sizeof(opj_tls_t)); } -static void opj_tls_destroy(opj_tls_t* tls) -{ +static void opj_tls_destroy(opj_tls_t *tls) { int i; if (!tls) { return; @@ -526,8 +486,7 @@ static void opj_tls_destroy(opj_tls_t* tls) opj_free(tls); } -void* opj_tls_get(opj_tls_t* tls, int key) -{ +void *opj_tls_get(opj_tls_t *tls, int key) { int i; for (i = 0; i < tls->key_val_count; i++) { if (tls->key_val[i].key == key) { @@ -537,10 +496,9 @@ void* opj_tls_get(opj_tls_t* tls, int key) return NULL; } -OPJ_BOOL opj_tls_set(opj_tls_t* tls, int key, void* value, - opj_tls_free_func opj_free_func) -{ - opj_tls_key_val_t* new_key_val; +OPJ_BOOL opj_tls_set(opj_tls_t *tls, int key, void *value, + opj_tls_free_func opj_free_func) { + opj_tls_key_val_t *new_key_val; int i; if (tls->key_val_count == INT_MAX) { @@ -556,8 +514,8 @@ OPJ_BOOL opj_tls_set(opj_tls_t* tls, int key, void* value, return OPJ_TRUE; } } - new_key_val = (opj_tls_key_val_t*) opj_realloc(tls->key_val, - ((size_t)tls->key_val_count + 1U) * sizeof(opj_tls_key_val_t)); + new_key_val = (opj_tls_key_val_t *) opj_realloc(tls->key_val, + ((size_t)tls->key_val_count + 1U) * sizeof(opj_tls_key_val_t)); if (!new_key_val) { return OPJ_FALSE; } @@ -591,42 +549,41 @@ typedef enum { } opj_worker_thread_state; struct opj_job_list_t { - opj_worker_thread_job_t* job; - struct opj_job_list_t* next; + opj_worker_thread_job_t *job; + struct opj_job_list_t *next; }; typedef struct opj_job_list_t opj_job_list_t; struct opj_worker_thread_list_t { - opj_worker_thread_t* worker_thread; - struct opj_worker_thread_list_t* next; + opj_worker_thread_t *worker_thread; + struct opj_worker_thread_list_t *next; }; typedef struct opj_worker_thread_list_t opj_worker_thread_list_t; struct opj_thread_pool_t { - opj_worker_thread_t* worker_threads; + opj_worker_thread_t *worker_threads; int worker_threads_count; - opj_cond_t* cond; - opj_mutex_t* mutex; + opj_cond_t *cond; + opj_mutex_t *mutex; volatile opj_worker_thread_state state; - opj_job_list_t* job_queue; + opj_job_list_t *job_queue; volatile int pending_jobs_count; - opj_worker_thread_list_t* waiting_worker_thread_list; + opj_worker_thread_list_t *waiting_worker_thread_list; int waiting_worker_thread_count; - opj_tls_t* tls; + opj_tls_t *tls; int signaling_threshold; }; -static OPJ_BOOL opj_thread_pool_setup(opj_thread_pool_t* tp, int num_threads); -static opj_worker_thread_job_t* opj_thread_pool_get_next_job( - opj_thread_pool_t* tp, - opj_worker_thread_t* worker_thread, +static OPJ_BOOL opj_thread_pool_setup(opj_thread_pool_t *tp, int num_threads); +static opj_worker_thread_job_t *opj_thread_pool_get_next_job( + opj_thread_pool_t *tp, + opj_worker_thread_t *worker_thread, OPJ_BOOL signal_job_finished); -opj_thread_pool_t* opj_thread_pool_create(int num_threads) -{ - opj_thread_pool_t* tp; +opj_thread_pool_t *opj_thread_pool_create(int num_threads) { + opj_thread_pool_t *tp; - tp = (opj_thread_pool_t*) opj_calloc(1, sizeof(opj_thread_pool_t)); + tp = (opj_thread_pool_t *) opj_calloc(1, sizeof(opj_thread_pool_t)); if (!tp) { return NULL; } @@ -653,20 +610,19 @@ opj_thread_pool_t* opj_thread_pool_create(int num_threads) return tp; } -static void opj_worker_thread_function(void* user_data) -{ - opj_worker_thread_t* worker_thread; - opj_thread_pool_t* tp; - opj_tls_t* tls; +static void opj_worker_thread_function(void *user_data) { + opj_worker_thread_t *worker_thread; + opj_thread_pool_t *tp; + opj_tls_t *tls; OPJ_BOOL job_finished = OPJ_FALSE; - worker_thread = (opj_worker_thread_t*) user_data; + worker_thread = (opj_worker_thread_t *) user_data; tp = worker_thread->tp; tls = opj_tls_new(); while (OPJ_TRUE) { - opj_worker_thread_job_t* job = opj_thread_pool_get_next_job(tp, worker_thread, - job_finished); + opj_worker_thread_job_t *job = opj_thread_pool_get_next_job(tp, worker_thread, + job_finished); if (job == NULL) { break; } @@ -681,8 +637,7 @@ static void opj_worker_thread_function(void* user_data) opj_tls_destroy(tls); } -static OPJ_BOOL opj_thread_pool_setup(opj_thread_pool_t* tp, int num_threads) -{ +static OPJ_BOOL opj_thread_pool_setup(opj_thread_pool_t *tp, int num_threads) { int i; OPJ_BOOL bRet = OPJ_TRUE; @@ -693,8 +648,8 @@ static OPJ_BOOL opj_thread_pool_setup(opj_thread_pool_t* tp, int num_threads) return OPJ_FALSE; } - tp->worker_threads = (opj_worker_thread_t*) opj_calloc((size_t)num_threads, - sizeof(opj_worker_thread_t)); + tp->worker_threads = (opj_worker_thread_t *) opj_calloc((size_t)num_threads, + sizeof(opj_worker_thread_t)); if (tp->worker_threads == NULL) { return OPJ_FALSE; } @@ -721,7 +676,7 @@ static OPJ_BOOL opj_thread_pool_setup(opj_thread_pool_t* tp, int num_threads) tp->worker_threads[i].marked_as_waiting = OPJ_FALSE; tp->worker_threads[i].thread = opj_thread_create(opj_worker_thread_function, - &(tp->worker_threads[i])); + &(tp->worker_threads[i])); if (tp->worker_threads[i].thread == NULL) { opj_mutex_destroy(tp->worker_threads[i].mutex); opj_cond_destroy(tp->worker_threads[i].cond); @@ -754,13 +709,12 @@ void opj_waiting() } */ -static opj_worker_thread_job_t* opj_thread_pool_get_next_job( - opj_thread_pool_t* tp, - opj_worker_thread_t* worker_thread, - OPJ_BOOL signal_job_finished) -{ +static opj_worker_thread_job_t *opj_thread_pool_get_next_job( + opj_thread_pool_t *tp, + opj_worker_thread_t *worker_thread, + OPJ_BOOL signal_job_finished) { while (OPJ_TRUE) { - opj_job_list_t* top_job_iter; + opj_job_list_t *top_job_iter; opj_mutex_lock(tp->mutex); @@ -779,7 +733,7 @@ static opj_worker_thread_job_t* opj_thread_pool_get_next_job( } top_job_iter = tp->job_queue; if (top_job_iter) { - opj_worker_thread_job_t* job; + opj_worker_thread_job_t *job; tp->job_queue = top_job_iter->next; job = top_job_iter->job; @@ -790,13 +744,13 @@ static opj_worker_thread_job_t* opj_thread_pool_get_next_job( /* opj_waiting(); */ if (!worker_thread->marked_as_waiting) { - opj_worker_thread_list_t* item; + opj_worker_thread_list_t *item; worker_thread->marked_as_waiting = OPJ_TRUE; tp->waiting_worker_thread_count ++; assert(tp->waiting_worker_thread_count <= tp->worker_threads_count); - item = (opj_worker_thread_list_t*) opj_malloc(sizeof(opj_worker_thread_list_t)); + item = (opj_worker_thread_list_t *) opj_malloc(sizeof(opj_worker_thread_list_t)); if (item == NULL) { tp->state = OPJWTS_ERROR; opj_cond_signal(tp->cond); @@ -824,26 +778,25 @@ static opj_worker_thread_job_t* opj_thread_pool_get_next_job( } } -OPJ_BOOL opj_thread_pool_submit_job(opj_thread_pool_t* tp, +OPJ_BOOL opj_thread_pool_submit_job(opj_thread_pool_t *tp, opj_job_fn job_fn, - void* user_data) -{ - opj_worker_thread_job_t* job; - opj_job_list_t* item; + void *user_data) { + opj_worker_thread_job_t *job; + opj_job_list_t *item; if (tp->mutex == NULL) { job_fn(user_data, tp->tls); return OPJ_TRUE; } - job = (opj_worker_thread_job_t*)opj_malloc(sizeof(opj_worker_thread_job_t)); + job = (opj_worker_thread_job_t *)opj_malloc(sizeof(opj_worker_thread_job_t)); if (job == NULL) { return OPJ_FALSE; } job->job_fn = job_fn; job->user_data = user_data; - item = (opj_job_list_t*) opj_malloc(sizeof(opj_job_list_t)); + item = (opj_job_list_t *) opj_malloc(sizeof(opj_job_list_t)); if (item == NULL) { opj_free(job); return OPJ_FALSE; @@ -864,9 +817,9 @@ OPJ_BOOL opj_thread_pool_submit_job(opj_thread_pool_t* tp, tp->pending_jobs_count ++; if (tp->waiting_worker_thread_list) { - opj_worker_thread_t* worker_thread; - opj_worker_thread_list_t* next; - opj_worker_thread_list_t* to_opj_free; + opj_worker_thread_t *worker_thread; + opj_worker_thread_list_t *next; + opj_worker_thread_list_t *to_opj_free; worker_thread = tp->waiting_worker_thread_list->worker_thread; @@ -891,9 +844,8 @@ OPJ_BOOL opj_thread_pool_submit_job(opj_thread_pool_t* tp, return OPJ_TRUE; } -void opj_thread_pool_wait_completion(opj_thread_pool_t* tp, - int max_remaining_jobs) -{ +void opj_thread_pool_wait_completion(opj_thread_pool_t *tp, + int max_remaining_jobs) { if (tp->mutex == NULL) { return; } @@ -911,13 +863,11 @@ void opj_thread_pool_wait_completion(opj_thread_pool_t* tp, opj_mutex_unlock(tp->mutex); } -int opj_thread_pool_get_thread_count(opj_thread_pool_t* tp) -{ +int opj_thread_pool_get_thread_count(opj_thread_pool_t *tp) { return tp->worker_threads_count; } -void opj_thread_pool_destroy(opj_thread_pool_t* tp) -{ +void opj_thread_pool_destroy(opj_thread_pool_t *tp) { if (!tp) { return; } @@ -941,7 +891,7 @@ void opj_thread_pool_destroy(opj_thread_pool_t* tp) opj_free(tp->worker_threads); while (tp->waiting_worker_thread_list != NULL) { - opj_worker_thread_list_t* next = tp->waiting_worker_thread_list->next; + opj_worker_thread_list_t *next = tp->waiting_worker_thread_list->next; opj_free(tp->waiting_worker_thread_list); tp->waiting_worker_thread_list = next; } diff --git a/client/deps/openjpeg/thread.h b/client/deps/openjpeg/thread.h index c89e19b4a..395843072 100644 --- a/client/deps/openjpeg/thread.h +++ b/client/deps/openjpeg/thread.h @@ -55,22 +55,22 @@ typedef struct opj_mutex_t opj_mutex_t; * @return the mutex or NULL in case of error (can for example happen if the library * is built without thread support) */ -opj_mutex_t* opj_mutex_create(void); +opj_mutex_t *opj_mutex_create(void); /** Lock/acquire the mutex. * @param mutex the mutex to acquire. */ -void opj_mutex_lock(opj_mutex_t* mutex); +void opj_mutex_lock(opj_mutex_t *mutex); /** Unlock/release the mutex. * @param mutex the mutex to release. */ -void opj_mutex_unlock(opj_mutex_t* mutex); +void opj_mutex_unlock(opj_mutex_t *mutex); /** Destroy a mutex * @param mutex the mutex to destroy. */ -void opj_mutex_destroy(opj_mutex_t* mutex); +void opj_mutex_destroy(opj_mutex_t *mutex); /*@}*/ @@ -84,7 +84,7 @@ typedef struct opj_cond_t opj_cond_t; * @return the condition or NULL in case of error (can for example happen if the library * is built without thread support) */ -opj_cond_t* opj_cond_create(void); +opj_cond_t *opj_cond_create(void); /** Wait for the condition to be signaled. * The semantics is the same as the POSIX pthread_cond_wait. @@ -117,7 +117,7 @@ opj_cond_t* opj_cond_create(void); * @param cond the condition to wait. * @param mutex the mutex (in acquired state before calling this function) */ -void opj_cond_wait(opj_cond_t* cond, opj_mutex_t* mutex); +void opj_cond_wait(opj_cond_t *cond, opj_mutex_t *mutex); /** Signal waiting threads on a condition. * One of the thread waiting with opj_cond_wait() will be waken up. @@ -125,12 +125,12 @@ void opj_cond_wait(opj_cond_t* cond, opj_mutex_t* mutex); * by opj_cond_wait(), in a acquired state. * @param cond the condition to signal. */ -void opj_cond_signal(opj_cond_t* cond); +void opj_cond_signal(opj_cond_t *cond); /** Destroy a condition * @param cond the condition to destroy. */ -void opj_cond_destroy(opj_cond_t* cond); +void opj_cond_destroy(opj_cond_t *cond); /*@}*/ @@ -143,7 +143,7 @@ typedef struct opj_thread_t opj_thread_t; /** User function to execute in a thread * @param user_data user data provided with opj_thread_create() */ -typedef void (*opj_thread_fn)(void* user_data); +typedef void (*opj_thread_fn)(void *user_data); /** Creates a new thread. * @param thread_fn Function to run in the new thread. @@ -151,13 +151,13 @@ typedef void (*opj_thread_fn)(void* user_data); * @return a thread handle or NULL in case of failure (can for example happen if the library * is built without thread support) */ -opj_thread_t* opj_thread_create(opj_thread_fn thread_fn, void* user_data); +opj_thread_t *opj_thread_create(opj_thread_fn thread_fn, void *user_data); /** Wait for a thread to be finished and release associated resources to the * thread handle. * @param thread the thread to wait for being finished. */ -void opj_thread_join(opj_thread_t* thread); +void opj_thread_join(opj_thread_t *thread); /*@}*/ @@ -171,10 +171,10 @@ typedef struct opj_tls_t opj_tls_t; * @param key key whose value to retrieve. * @return value associated with the key, or NULL is missing. */ -void* opj_tls_get(opj_tls_t* tls, int key); +void *opj_tls_get(opj_tls_t *tls, int key); /** Type of the function used to free a TLS value */ -typedef void (*opj_tls_free_func)(void* value); +typedef void (*opj_tls_free_func)(void *value); /** Set a thread local value corresponding to the provided key. * @param tls thread local storage handle @@ -183,7 +183,7 @@ typedef void (*opj_tls_free_func)(void* value); * @param free_func function to call currently installed value. * @return OPJ_TRUE if successful. */ -OPJ_BOOL opj_tls_set(opj_tls_t* tls, int key, void* value, +OPJ_BOOL opj_tls_set(opj_tls_t *tls, int key, void *value, opj_tls_free_func free_func); /*@}*/ @@ -204,13 +204,13 @@ typedef struct opj_thread_pool_t opj_thread_pool_t; * @return a thread pool handle, or NULL in case of failure (can for example happen if the library * is built without thread support) */ -opj_thread_pool_t* opj_thread_pool_create(int num_threads); +opj_thread_pool_t *opj_thread_pool_create(int num_threads); /** User function to execute in a thread * @param user_data user data provided with opj_thread_create() * @param tls handle to thread local storage */ -typedef void (*opj_job_fn)(void* user_data, opj_tls_t* tls); +typedef void (*opj_job_fn)(void *user_data, opj_tls_t *tls); /** Submit a new job to be run by one of the thread in the thread pool. @@ -222,8 +222,8 @@ typedef void (*opj_job_fn)(void* user_data, opj_tls_t* tls); * @param user_data User data provided to thread_fn. * @return OPJ_TRUE if the job was successfully submitted. */ -OPJ_BOOL opj_thread_pool_submit_job(opj_thread_pool_t* tp, opj_job_fn job_fn, - void* user_data); +OPJ_BOOL opj_thread_pool_submit_job(opj_thread_pool_t *tp, opj_job_fn job_fn, + void *user_data); /** Wait that no more than max_remaining_jobs jobs are remaining in the queue of * the thread pool. The aim of this function is to avoid submitting too many @@ -234,7 +234,7 @@ OPJ_BOOL opj_thread_pool_submit_job(opj_thread_pool_t* tp, opj_job_fn job_fn, * @param tp the thread pool handle * @param max_remaining_jobs maximum number of jobs allowed to be queued without waiting. */ -void opj_thread_pool_wait_completion(opj_thread_pool_t* tp, +void opj_thread_pool_wait_completion(opj_thread_pool_t *tp, int max_remaining_jobs); /** Return the number of threads associated with the thread pool. @@ -242,12 +242,12 @@ void opj_thread_pool_wait_completion(opj_thread_pool_t* tp, * @param tp the thread pool handle. * @return number of threads associated with the thread pool. */ -int opj_thread_pool_get_thread_count(opj_thread_pool_t* tp); +int opj_thread_pool_get_thread_count(opj_thread_pool_t *tp); /** Destroy a thread pool. * @param tp the thread pool handle. */ -void opj_thread_pool_destroy(opj_thread_pool_t* tp); +void opj_thread_pool_destroy(opj_thread_pool_t *tp); /*@}*/ diff --git a/client/pyscripts/dc34.py b/client/pyscripts/dc34.py index cb3a719f4..f36e0756a 100644 --- a/client/pyscripts/dc34.py +++ b/client/pyscripts/dc34.py @@ -191,7 +191,7 @@ if True: # Data classes if result is None: raise ValueError(f"cell value must be one of {list(TicTacToe_CellValue._value2member_map_.keys())}, got 0x{value:02x}.") return TicTacToe_CellValue(value) - + @classmethod def _validate_game_status(cls, value: int) -> TicTacToe_GameStatus: if not isinstance(value, int): @@ -276,14 +276,14 @@ if True: # Data classes if not re.fullmatch(r"^[A-Z_]{0,8}$", value): raise ValueError(f"word mask string must match regex r'^[A-Z_]{{0,8}}$', got '{value}'.") return value - + @classmethod def _validate_guessed_letter_bitmask(cls, value: bytes | bytearray | int) -> int: if not isinstance(value, (bytes, bytearray, int)): raise ValueError("guessed letter bitmask must be int, bytes or bytearray.") if isinstance(value, int): result = value - else: + else: if len(value) != 4: raise ValueError(f"guessed letter bitmask must be an int or exactly 4 bytes, got {len(value)} bytes.") result = int.from_bytes(value, byteorder="little") @@ -494,7 +494,7 @@ if True: # Commands ... HF14CommandBase and SelectApplet classes status = int.from_bytes(data[-2:], byteorder="big") data = data[:-2] return HF14aCommandResult(status = status, cmd = bytes(cmd), data = bytes(data)) - + # Classes to select a different applet on the card. class Cmd_SelectApplet_Base(HF14aCommandBase): @@ -563,7 +563,7 @@ if True: # TicTacToe applet commands super().__init__(ins = 0x08, p1 = 0x00, p2 = 0x00, expect_data_length = 2) if True: # Hangman applet commands - + class Cmd_Hangman_Base(HF14aCommandBase): def __init__(self, ins : int, p1 : int = 0x00, expect_data_length : int = 0): super().__init__(cla = 0x80, ins = ins, p1 = p1, p2 = 0x00, send_buffer = None, expect_data_length = expect_data_length) diff --git a/client/src/cmdfpga.c b/client/src/cmdfpga.c index 9981d1dd9..1b74c176d 100644 --- a/client/src/cmdfpga.c +++ b/client/src/cmdfpga.c @@ -139,8 +139,8 @@ static int CmdFpgaSetPowerPWM(const char *Cmd) { arg_param_begin, arg_lit0("l", "lf", "Set the driver voltage for LF. When not specified as LF, default setting for HF."), arg_int0("c", "count", "", "PWM output low level counting used to control the voltage of the driver. " - "The larger the value, the higher the voltage; " - "the smaller the value, the lower the voltage."), + "The larger the value, the higher the voltage; " + "the smaller the value, the lower the voltage."), arg_param_end }; CLIExecWithReturn(ctx, Cmd, argtable, false); @@ -199,4 +199,4 @@ static int CmdHelp(const char *Cmd) { int CmdFPGA(const char *Cmd) { clearCommandBuffer(); return CmdsParse(CommandTable, Cmd); -} \ No newline at end of file +} diff --git a/client/src/cmdfpga.h b/client/src/cmdfpga.h index ecb51099f..52e7ab63a 100644 --- a/client/src/cmdfpga.h +++ b/client/src/cmdfpga.h @@ -3,4 +3,4 @@ int CmdFPGA(const char *Cmd); -#endif // CMD_FPGA_H \ No newline at end of file +#endif // CMD_FPGA_H diff --git a/client/src/cmdhf15.c b/client/src/cmdhf15.c index 89f3749d4..e81fa2eae 100644 --- a/client/src/cmdhf15.c +++ b/client/src/cmdhf15.c @@ -3466,7 +3466,7 @@ static int CmdHF15CSetUID(const char *Cmd) { [=] 16 | 77 66 55 44 | 0 | wfUD [=] 17 | 33 22 11 E0 | 0 | 3".. */ - uint8_t blk_lo[4] = {0}; + uint8_t blk_lo[4] = {0}; uint8_t blk_hi[4] = {0}; reverse_array_copy(payload.uid + 4, 4, blk_lo); reverse_array_copy(payload.uid, 4, blk_hi); diff --git a/client/src/cmdhfcalypso.c b/client/src/cmdhfcalypso.c index 42729eed6..1ec6ef141 100644 --- a/client/src/cmdhfcalypso.c +++ b/client/src/cmdhfcalypso.c @@ -626,7 +626,7 @@ static bool calypso_parse_fcp_value(const uint8_t *value, size_t value_len, caly if (value_len >= 0x16) { uint16_t tail = ((uint16_t)value[value_len - 2] << 8) | value[value_len - 1]; - if (tail == 0x3F3F) { + if (tail == 0x3F3F) { return true; } @@ -1420,7 +1420,7 @@ static int calypso_exchange_once(sAPDU_t apdu, bool include_le, uint16_t le, cal response->len = 0; response->sw = 0; int res = Iso7816ExchangeEx(CC_CONTACTLESS, false, true, apdu, include_le, le, - response->data, sizeof(response->data), &response->len, &response->sw); + response->data, sizeof(response->data), &response->len, &response->sw); // Iso7816ExchangeEx currently returns a positive status for a valid error // R-APDU only when APDU logging is enabled. A received SW is transport diff --git a/client/src/cmdhfcryptorf.c b/client/src/cmdhfcryptorf.c index e551f986d..ace0a26ea 100644 --- a/client/src/cmdhfcryptorf.c +++ b/client/src/cmdhfcryptorf.c @@ -455,11 +455,11 @@ static int CmdHFCryptoRFELoad(const char *Cmd) { return PM3_EFILE; } - // ICEMAN: Once we have CryptoRF dump files, we can implement an upload + // ICEMAN: Once we have CryptoRF dump files, we can implement an upload PrintAndLogEx(INFO, "to be implemented"); //PrintAndLogEx(SUCCESS, "Uploading to emulator memory"); //uint32_t bytes_sent = 0; - + free(data); //PrintAndLogEx(SUCCESS, "sent " _YELLOW_("%d") " bytes of data to device emulator memory", bytes_sent); return PM3_SUCCESS; diff --git a/client/src/cmdhffelica.c b/client/src/cmdhffelica.c index 12c1d3460..d4f54abbe 100644 --- a/client/src/cmdhffelica.c +++ b/client/src/cmdhffelica.c @@ -398,7 +398,7 @@ static void felica_auth_collect_codes(const felica_auth_key_store_t *store, uint uint16_t *codes, size_t *count); static void felica_auth_add_unique_code(uint16_t *codes, size_t *count, uint16_t code); static const felica_node_t *felica_find_node(const felica_node_t *versions, - size_t version_count, uint16_t code_be); + size_t version_count, uint16_t code_be); static bool felica_node_present(const felica_node_t *node); static int felica_collect_key_versions(uint8_t flags, const uint8_t *idm, const uint16_t *codes_be, size_t code_count, @@ -919,7 +919,7 @@ static bool felica_date_is_acceptable(int year, int month, int day) { int current_year = 9999; const time_t now = time(NULL); - if (now != (time_t)-1) { + if (now != (time_t) -1) { const struct tm *tm_now = gmtime(&now); if (tm_now != NULL) { current_year = tm_now->tm_year + 1900; @@ -1131,7 +1131,7 @@ static json_t *felica_get_container_issue_list(void) { } static bool felica_container_issue_matches(const felica_get_container_issue_info_response_t *response, - const json_t *entry) { + const json_t *entry) { if (response == NULL || json_is_object(entry) == false) { return false; } @@ -2089,9 +2089,9 @@ static void felica_info_process_system(int level, uint8_t flags, felica_discover have_versions = true; for (size_t i = 0; i < combined_code_count; i++) { if (verbose) PrintAndLogEx(INFO, "[auth] card: node %04X -> DES %u AES %u%s", - versions[i].code_be, - versions[i].des_key_version.value, versions[i].aes_key_version.value, - felica_node_present(&versions[i]) ? "" : " (absent)"); + versions[i].code_be, + versions[i].des_key_version.value, versions[i].aes_key_version.value, + felica_node_present(&versions[i]) ? "" : " (absent)"); } } } @@ -2957,8 +2957,8 @@ static int info_felica(bool verbose, bool no_ic_optimizations) { felica_auth_key_store_t auth_keys = {0}; felica_auth_key_store_load(&auth_keys, verbose); if (verbose) PrintAndLogEx(INFO, "[auth] loaded " _YELLOW_("%zu") " node key(s), " _YELLOW_("%zu") " group/user keyset(s)", - json_array_size(json_object_get_ci(auth_keys.node_root, "keys")), - json_array_size(json_object_get_ci(auth_keys.group_user_root, "keysets"))); + json_array_size(json_object_get_ci(auth_keys.node_root, "keys")), + json_array_size(json_object_get_ci(auth_keys.group_user_root, "keysets"))); PrintAndLogEx(NORMAL, ""); PrintAndLogEx(INFO, "--- " _CYAN_("Tag Information") " ---------------------------"); PrintAndLogEx(INFO, "Primary IDm.... " _YELLOW_("%s"), sprint_hex_inrow(card.IDm, sizeof(card.IDm))); @@ -2974,7 +2974,7 @@ static int info_felica(bool verbose, bool no_ic_optimizations) { const int16_t days_since_2000 = (int16_t)(((uint16_t)card.IDm[5] << 8) | card.IDm[4]); const time_t felica_epoch = (time_t)946684800; // 2000-01-01 UTC const time_t now = time(NULL); - if (days_since_2000 >= 0 && now != (time_t)-1 && now >= felica_epoch && + if (days_since_2000 >= 0 && now != (time_t) -1 && now >= felica_epoch && (time_t)days_since_2000 <= (now - felica_epoch) / 86400) { const time_t manufacturing_time = felica_epoch + ((time_t)days_since_2000 * 86400); const struct tm *date = gmtime(&manufacturing_time); @@ -3008,10 +3008,10 @@ static int info_felica(bool verbose, bool no_ic_optimizations) { size_t platform_information_data_len = 0; if (caps.supports_request_product_information != FELICA_CAP_UNSUPPORTED && send_get_platform_information(optional_flags, - sizeof(platform_info_request), (uint8_t *)&platform_info_request, - false, &platform_status_flags, platform_information_data, - sizeof(platform_information_data), - &platform_information_data_len) == PM3_SUCCESS && + sizeof(platform_info_request), (uint8_t *)&platform_info_request, + false, &platform_status_flags, platform_information_data, + sizeof(platform_information_data), + &platform_information_data_len) == PM3_SUCCESS && platform_information_data_len > 0) { print_platform_information(platform_information_data, platform_information_data_len); } @@ -3025,10 +3025,10 @@ static int info_felica(bool verbose, bool no_ic_optimizations) { felica_request_specification_version_info_t specification_version_info; if (caps.supports_request_specification_version != FELICA_CAP_UNSUPPORTED && send_request_specification_version(optional_flags, sizeof(request_specification_version_request), - (uint8_t *)&request_specification_version_request, false, - false, FELICA_OPTIONAL_CMD_TIMEOUT_MS, - felica_capability_attempts(caps.supports_request_specification_version) - 1U, - &specification_version_info) == PM3_SUCCESS && + (uint8_t *)&request_specification_version_request, false, + false, FELICA_OPTIONAL_CMD_TIMEOUT_MS, + felica_capability_attempts(caps.supports_request_specification_version) - 1U, + &specification_version_info) == PM3_SUCCESS && specification_version_info.has_specification_version) { print_specification_versions(INFO, &specification_version_info, true); } @@ -3041,8 +3041,8 @@ static int info_felica(bool verbose, bool no_ic_optimizations) { felica_get_container_id_response_t container_id_response; if (caps.supports_get_container_id != FELICA_CAP_UNSUPPORTED && send_get_container_id(optional_flags, sizeof(container_id_request), - (uint8_t *)&container_id_request, false, - &container_id_response) == PM3_SUCCESS) { + (uint8_t *)&container_id_request, false, + &container_id_response) == PM3_SUCCESS) { PrintAndLogEx(INFO, "Container IDm.. " _YELLOW_("%s"), sprint_hex_inrow(container_id_response.container_idm, sizeof(container_id_response.container_idm))); } @@ -3056,15 +3056,15 @@ static int info_felica(bool verbose, bool no_ic_optimizations) { felica_get_container_issue_info_response_t container_issue_info_response; if (caps.supports_get_container_issue_information != FELICA_CAP_UNSUPPORTED && send_get_container_issue_information(optional_flags, - sizeof(container_issue_info_request), (uint8_t *)&container_issue_info_request, false, - &container_issue_info_response) == PM3_SUCCESS) { + sizeof(container_issue_info_request), (uint8_t *)&container_issue_info_request, false, + &container_issue_info_response) == PM3_SUCCESS) { char model_ascii[sizeof(container_issue_info_response.mobile_phone_model_information) + 1] = {0}; bool model_is_ascii = decode_zero_padded_ascii( container_issue_info_response.mobile_phone_model_information, sizeof(container_issue_info_response.mobile_phone_model_information), model_ascii, sizeof(model_ascii) - ); + ); PrintAndLogEx(INFO, "Container issue info:"); PrintAndLogEx(INFO, " Format/Carrier info... " _YELLOW_("%s"), sprint_hex_inrow(container_issue_info_response.format_version_carrier_information, @@ -3954,8 +3954,8 @@ static void felica_auth_collect_codes(const felica_auth_key_store_t *store, uint } static int felica_collect_key_versions_v2(uint8_t flags, const uint8_t *idm, - const uint16_t *codes_be, size_t code_count, - felica_node_t *versions, uint32_t retries) { + const uint16_t *codes_be, size_t code_count, + felica_node_t *versions, uint32_t retries) { bool encryption_identifier_set = false; uint8_t encryption_identifier = 0; @@ -3968,7 +3968,7 @@ static int felica_collect_key_versions_v2(uint8_t flags, const uint8_t *idm, felica_request_service_v2_key_versions_t response; int result = felica_request_service_v2_key_versions(flags, idm, batch_codes_le, batch_count, - retries, &response); + retries, &response); if (result != PM3_SUCCESS || felica_encryption_identifier_get_info(response.encryption_identifier) == NULL) { return PM3_ERFTRANS; } @@ -3992,8 +3992,8 @@ static int felica_collect_key_versions_v2(uint8_t flags, const uint8_t *idm, } static int felica_collect_key_versions_v1(uint8_t flags, const uint8_t *idm, - const uint16_t *codes_be, size_t code_count, - felica_node_t *versions) { + const uint16_t *codes_be, size_t code_count, + felica_node_t *versions) { for (size_t processed = 0; processed < code_count;) { const size_t batch_count = MIN(FELICA_REQUEST_SERVICE_DISCOVERY_BATCH_SIZE, code_count - processed); uint16_t batch_codes_le[FELICA_REQUEST_SERVICE_DISCOVERY_BATCH_SIZE] = {0}; @@ -4004,7 +4004,7 @@ static int felica_collect_key_versions_v1(uint8_t flags, const uint8_t *idm, size_t returned_nodes = 0; int result = felica_request_service_key_versions(flags, idm, batch_codes_le, batch_count, - FELICA_OPTIONAL_CMD_RETRIES, key_versions, &returned_nodes); + FELICA_OPTIONAL_CMD_RETRIES, key_versions, &returned_nodes); if (result != PM3_SUCCESS || returned_nodes != batch_count) { return PM3_ERFTRANS; } @@ -4105,9 +4105,9 @@ static int felica_auth_send_authentication1(uint8_t flags, const uint8_t idm[8], PacketResponseNG packet; int result = send_felica_payload_with_retries(flags, (uint16_t)frame_length, frame, false, - FELICA_AUTHENTICATION1_RES, - FELICA_DEFAULT_TIMEOUT_MS, 2U, 0, false, - &packet, "authentication1"); + FELICA_AUTHENTICATION1_RES, + FELICA_DEFAULT_TIMEOUT_MS, 2U, 0, false, + &packet, "authentication1"); mbedtls_platform_zeroize(frame, sizeof(frame)); if (result != PM3_SUCCESS || packet.length < sizeof(*response)) { return PM3_ERFTRANS; @@ -4131,9 +4131,9 @@ static int felica_auth_send_authentication2_once(uint8_t flags, const uint8_t id PacketResponseNG packet; int result = send_felica_payload_with_retries(flags, sizeof(frame), frame, false, - FELICA_AUTHENTICATION2_RES, - FELICA_DEFAULT_TIMEOUT_MS, 2U, 0, false, - &packet, "authentication2"); + FELICA_AUTHENTICATION2_RES, + FELICA_DEFAULT_TIMEOUT_MS, 2U, 0, false, + &packet, "authentication2"); mbedtls_platform_zeroize(frame, sizeof(frame)); const size_t ciphertext_offset = sizeof(felica_frame_response_noidm_t); if (result != PM3_SUCCESS || packet.length < ciphertext_offset + FELICA_AUTH2_CIPHERTEXT_LEN) { @@ -4188,10 +4188,10 @@ cleanup: } static felica_auth_candidate_result_t felica_auth_try_candidate(uint8_t flags, const uint8_t idm[8], - const uint16_t *areas_be, size_t area_count, - const uint16_t *nodes_be, size_t node_count, - const uint8_t group_key[8], const uint8_t user_key[8], - uint8_t idi[8], uint8_t pmi[8], bool verbose) { + const uint16_t *areas_be, size_t area_count, + const uint16_t *nodes_be, size_t node_count, + const uint8_t group_key[8], const uint8_t user_key[8], + uint8_t idi[8], uint8_t pmi[8], bool verbose) { uint8_t random1[8] = {0}; uint8_t l[8] = {0}; uint8_t alpha[8] = {0}; @@ -4294,9 +4294,9 @@ static void felica_auth_collect_matching_node_keys(const felica_auth_key_store_t } static felica_auth_candidate_result_t felica_auth_try_node_pair(uint8_t flags, const uint8_t idm[8], - const felica_auth_node_key_t *keys, size_t key_count, - uint16_t left_code, uint16_t right_code, - bool *attempted, uint8_t idi[8], uint8_t pmi[8], bool verbose) { + const felica_auth_node_key_t *keys, size_t key_count, + uint16_t left_code, uint16_t right_code, + bool *attempted, uint8_t idi[8], uint8_t pmi[8], bool verbose) { const uint16_t areas[] = {left_code}; const uint16_t nodes[] = {right_code}; @@ -4335,8 +4335,8 @@ static felica_auth_candidate_result_t felica_auth_try_node_pair(uint8_t flags, c } static felica_auth_candidate_result_t felica_auth_try_node_keys(uint8_t flags, const uint8_t idm[8], - const felica_auth_node_key_t *keys, size_t key_count, - bool *attempted, uint8_t idi[8], uint8_t pmi[8], bool verbose) { + const felica_auth_node_key_t *keys, size_t key_count, + bool *attempted, uint8_t idi[8], uint8_t pmi[8], bool verbose) { bool has_system_key = false; uint16_t areas[FELICA_AUTH_MAX_NODES]; size_t area_count = 0; @@ -4392,7 +4392,7 @@ static bool felica_auth_group_versions_match(const json_t *versions_json, if (felica_code_from_hex(code_hex, &code) == false || felica_auth_parse_key_version(wanted_version_json, &wanted_version) == false) { if (verbose) PrintAndLogEx(INFO, "[auth] versions entry `%s` unparsable (code must be 4 hex chars, version a number)", - code_hex ? code_hex : "(null)"); + code_hex ? code_hex : "(null)"); return false; } const felica_node_t *card_node = felica_find_node(versions, version_count, code); @@ -4406,7 +4406,7 @@ static bool felica_auth_group_versions_match(const json_t *versions_json, } if (card_node->des_key_version.value != wanted_version) { if (verbose) PrintAndLogEx(INFO, "[auth] node %04X: version mismatch, file %u vs card %u", - code, wanted_version, card_node->des_key_version.value); + code, wanted_version, card_node->des_key_version.value); return false; } } @@ -4426,11 +4426,11 @@ static bool felica_auth_json_code_array_contains(const json_t *array, uint16_t w } static felica_auth_candidate_result_t felica_auth_try_group_user_keys(const felica_auth_key_store_t *store, - uint8_t flags, uint16_t system_code, - const uint8_t idm[8], - const felica_node_t *versions, - size_t version_count, bool *attempted, - uint8_t idi[8], uint8_t pmi[8], bool verbose) { + uint8_t flags, uint16_t system_code, + const uint8_t idm[8], + const felica_node_t *versions, + size_t version_count, bool *attempted, + uint8_t idi[8], uint8_t pmi[8], bool verbose) { json_t *keysets = json_object_get_ci(store->group_user_root, FELICA_AUTH_GROUP_USER_KEY_FILE.records_key); for (int root_preference = 1; root_preference >= 0; root_preference--) { size_t index = 0; @@ -4446,7 +4446,7 @@ static felica_auth_candidate_result_t felica_auth_try_group_user_keys(const feli continue; } if (verbose) PrintAndLogEx(INFO, "[auth] keyset #%zu (%s root): checking versions", - index, contains_root ? "contains" : "no"); + index, contains_root ? "contains" : "no"); json_t *versions_json = json_object_get_ci(record, "versions"); if (felica_auth_group_versions_match(versions_json, versions, version_count, verbose) == false) { if (verbose) PrintAndLogEx(INFO, "[auth] keyset #%zu: version check FAILED, skipped", index); @@ -4470,7 +4470,7 @@ static felica_auth_candidate_result_t felica_auth_try_group_user_keys(const feli } if (verbose) PrintAndLogEx(INFO, "[auth] keyset #%zu: ATTEMPTING auth, %zu area(s) + %zu node(s)", - index, area_count, node_count); + index, area_count, node_count); *attempted = true; const felica_auth_candidate_result_t result = felica_auth_try_candidate(flags, idm, areas, area_count, nodes, node_count, diff --git a/client/src/cmdhflist.c b/client/src/cmdhflist.c index 90e7648b6..74461eecb 100644 --- a/client/src/cmdhflist.c +++ b/client/src/cmdhflist.c @@ -863,15 +863,33 @@ void annotateIso7816(char *exp, size_t size, uint8_t *cmd, uint8_t cmdsize, bool (pcb & 0x0F) ? " error" : ""); } else { switch (pcb & 0x3F) { - case 0x00: snprintf(exp, size, "S-block RESYNCH req"); break; - case 0x20: snprintf(exp, size, "S-block RESYNCH resp"); break; - case 0x01: snprintf(exp, size, "S-block IFS req"); break; - case 0x21: snprintf(exp, size, "S-block IFS resp"); break; - case 0x02: snprintf(exp, size, "S-block ABORT req"); break; - case 0x22: snprintf(exp, size, "S-block ABORT resp"); break; - case 0x03: snprintf(exp, size, "S-block WTX req"); break; - case 0x23: snprintf(exp, size, "S-block WTX resp"); break; - default: snprintf(exp, size, "S-block"); break; + case 0x00: + snprintf(exp, size, "S-block RESYNCH req"); + break; + case 0x20: + snprintf(exp, size, "S-block RESYNCH resp"); + break; + case 0x01: + snprintf(exp, size, "S-block IFS req"); + break; + case 0x21: + snprintf(exp, size, "S-block IFS resp"); + break; + case 0x02: + snprintf(exp, size, "S-block ABORT req"); + break; + case 0x22: + snprintf(exp, size, "S-block ABORT resp"); + break; + case 0x03: + snprintf(exp, size, "S-block WTX req"); + break; + case 0x23: + snprintf(exp, size, "S-block WTX resp"); + break; + default: + snprintf(exp, size, "S-block"); + break; } } return; diff --git a/client/src/cmdhfmfdes.c b/client/src/cmdhfmfdes.c index 0603c2afd..c4d9f2739 100644 --- a/client/src/cmdhfmfdes.c +++ b/client/src/cmdhfmfdes.c @@ -1674,131 +1674,131 @@ static int CmdHF14aDesChk(const char *Cmd) { app_ids_len = 3; } - { - uint32_t deskeyCountTotal = 0; - uint32_t aeskeyCountTotal = 0; - uint32_t k3kkeyCountTotal = 0; + { + uint32_t deskeyCountTotal = 0; + uint32_t aeskeyCountTotal = 0; + uint32_t k3kkeyCountTotal = 0; - if (pattern1b) { - deskeyCountTotal = deskeyListLen; - aeskeyCountTotal = aeskeyListLen; - k3kkeyCountTotal = k3kkeyListLen; - } else if (pattern2b) { - deskeyCountTotal = 0x10000 - startPattern; - aeskeyCountTotal = 0x10000 - startPattern; - k3kkeyCountTotal = 0x10000 - startPattern; - } else if (dict_filenamelen) { - size_t readStart = 0; - size_t readEnd = 1; - uint32_t n = 0; + if (pattern1b) { + deskeyCountTotal = deskeyListLen; + aeskeyCountTotal = aeskeyListLen; + k3kkeyCountTotal = k3kkeyListLen; + } else if (pattern2b) { + deskeyCountTotal = 0x10000 - startPattern; + aeskeyCountTotal = 0x10000 - startPattern; + k3kkeyCountTotal = 0x10000 - startPattern; + } else if (dict_filenamelen) { + size_t readStart = 0; + size_t readEnd = 1; + uint32_t n = 0; - while (readEnd != 0) { - loadFileDICTIONARYEx((char *)dict_filename, deskeyList, sizeof(deskeyList), NULL, 8, &n, readStart, &readEnd, false); - readStart = readEnd; - deskeyCountTotal += n; - } + while (readEnd != 0) { + loadFileDICTIONARYEx((char *)dict_filename, deskeyList, sizeof(deskeyList), NULL, 8, &n, readStart, &readEnd, false); + readStart = readEnd; + deskeyCountTotal += n; + } - readStart = 0; - readEnd = 1; - while (readEnd != 0) { - loadFileDICTIONARYEx((char *)dict_filename, aeskeyList, sizeof(aeskeyList), NULL, 16, &n, readStart, &readEnd, false); - readStart = readEnd; - aeskeyCountTotal += n; - } + readStart = 0; + readEnd = 1; + while (readEnd != 0) { + loadFileDICTIONARYEx((char *)dict_filename, aeskeyList, sizeof(aeskeyList), NULL, 16, &n, readStart, &readEnd, false); + readStart = readEnd; + aeskeyCountTotal += n; + } - readStart = 0; - readEnd = 1; - while (readEnd != 0) { - loadFileDICTIONARYEx((char *)dict_filename, k3kkeyList, sizeof(k3kkeyList), NULL, 24, &n, readStart, &readEnd, false); - readStart = readEnd; - k3kkeyCountTotal += n; - } - } + readStart = 0; + readEnd = 1; + while (readEnd != 0) { + loadFileDICTIONARYEx((char *)dict_filename, k3kkeyList, sizeof(k3kkeyList), NULL, 24, &n, readStart, &readEnd, false); + readStart = readEnd; + k3kkeyCountTotal += n; + } + } - if (deskeyCountTotal > 0) - PrintAndLogEx(INFO, "Loaded " _YELLOW_("%"PRIu32) " des keys", deskeyCountTotal); - if (aeskeyCountTotal > 0) - PrintAndLogEx(INFO, "Loaded " _YELLOW_("%"PRIu32) " aes keys", aeskeyCountTotal); - if (k3kkeyCountTotal > 0) - PrintAndLogEx(INFO, "Loaded " _YELLOW_("%"PRIu32) " k3kdes keys", k3kkeyCountTotal); + if (deskeyCountTotal > 0) + PrintAndLogEx(INFO, "Loaded " _YELLOW_("%"PRIu32) " des keys", deskeyCountTotal); + if (aeskeyCountTotal > 0) + PrintAndLogEx(INFO, "Loaded " _YELLOW_("%"PRIu32) " aes keys", aeskeyCountTotal); + if (k3kkeyCountTotal > 0) + PrintAndLogEx(INFO, "Loaded " _YELLOW_("%"PRIu32) " k3kdes keys", k3kkeyCountTotal); - if (deskeyCountTotal + aeskeyCountTotal + k3kkeyCountTotal == 0) { - PrintAndLogEx(ERR, "No keys provided. Nothing to check."); - return PM3_EINVARG; - } - } + if (deskeyCountTotal + aeskeyCountTotal + k3kkeyCountTotal == 0) { + PrintAndLogEx(ERR, "No keys provided. Nothing to check."); + return PM3_EINVARG; + } + } for (uint32_t x = 0; x < app_ids_len / 3; x++) { uint32_t curaid = (app_ids[x * 3] & 0xFF) + ((app_ids[(x * 3) + 1] & 0xFF) << 8) + ((app_ids[(x * 3) + 2] & 0xFF) << 16); PrintAndLogEx(ERR, "Checking aid 0x%06X...", curaid); - bool loadedAllKeys = false; - size_t desReadStart = 0; - size_t desReadEnd = 1; - size_t aesReadStart = 0; - size_t aesReadEnd = 1; - size_t k3kReadStart = 0; - size_t k3kReadEnd = 1; - uint32_t pattern2bOffset = startPattern; + bool loadedAllKeys = false; + size_t desReadStart = 0; + size_t desReadEnd = 1; + size_t aesReadStart = 0; + size_t aesReadEnd = 1; + size_t k3kReadStart = 0; + size_t k3kReadEnd = 1; + uint32_t pattern2bOffset = startPattern; - while (!loadedAllKeys) { - bool foundKeyThisRound = false; + while (!loadedAllKeys) { + bool foundKeyThisRound = false; - if (pattern1b) { - loadedAllKeys = true; - } else if (pattern2b) { - if (pattern2bOffset < 0x10000) { - aeskeyListLen = 0; - deskeyListLen = 0; - k3kkeyListLen = 0; - DesFill2bPattern(deskeyList, &deskeyListLen, aeskeyList, &aeskeyListLen, k3kkeyList, &k3kkeyListLen, &pattern2bOffset); - } else { - loadedAllKeys = true; - } - } else if (dict_filenamelen) { - deskeyListLen = 0; - if (desReadEnd != 0) { - res = loadFileDICTIONARYEx((char *)dict_filename, deskeyList, sizeof(deskeyList), NULL, 8, &deskeyListLen, desReadStart, &desReadEnd, false); - if (res != PM3_SUCCESS) - desReadStart = desReadEnd; - } else { - // Every 16 byte or 24 byte key also gets read as a valid des key, so when desReadEnd == 0 there are absolutely no more keys of any kind left in the dictionary - loadedAllKeys = true; - } + if (pattern1b) { + loadedAllKeys = true; + } else if (pattern2b) { + if (pattern2bOffset < 0x10000) { + aeskeyListLen = 0; + deskeyListLen = 0; + k3kkeyListLen = 0; + DesFill2bPattern(deskeyList, &deskeyListLen, aeskeyList, &aeskeyListLen, k3kkeyList, &k3kkeyListLen, &pattern2bOffset); + } else { + loadedAllKeys = true; + } + } else if (dict_filenamelen) { + deskeyListLen = 0; + if (desReadEnd != 0) { + res = loadFileDICTIONARYEx((char *)dict_filename, deskeyList, sizeof(deskeyList), NULL, 8, &deskeyListLen, desReadStart, &desReadEnd, false); + if (res != PM3_SUCCESS) + desReadStart = desReadEnd; + } else { + // Every 16 byte or 24 byte key also gets read as a valid des key, so when desReadEnd == 0 there are absolutely no more keys of any kind left in the dictionary + loadedAllKeys = true; + } - aeskeyListLen = 0; - if (aesReadEnd != 0) { - res = loadFileDICTIONARYEx((char *)dict_filename, aeskeyList, sizeof(aeskeyList), NULL, 16, &aeskeyListLen, aesReadStart, &aesReadEnd, false); - if (res != PM3_SUCCESS) - aesReadStart = aesReadEnd; - } + aeskeyListLen = 0; + if (aesReadEnd != 0) { + res = loadFileDICTIONARYEx((char *)dict_filename, aeskeyList, sizeof(aeskeyList), NULL, 16, &aeskeyListLen, aesReadStart, &aesReadEnd, false); + if (res != PM3_SUCCESS) + aesReadStart = aesReadEnd; + } - k3kkeyListLen = 0; - if (k3kReadEnd != 0) { - res = loadFileDICTIONARYEx((char *)dict_filename, k3kkeyList, sizeof(k3kkeyList), NULL, 24, &k3kkeyListLen, k3kReadStart, &k3kReadEnd, false); - if (res != PM3_SUCCESS) - k3kReadStart = k3kReadEnd; - } - } + k3kkeyListLen = 0; + if (k3kReadEnd != 0) { + res = loadFileDICTIONARYEx((char *)dict_filename, k3kkeyList, sizeof(k3kkeyList), NULL, 24, &k3kkeyListLen, k3kReadStart, &k3kReadEnd, false); + if (res != PM3_SUCCESS) + k3kReadStart = k3kReadEnd; + } + } - res = AuthCheckDesfire(&dctx, secureChannel, &app_ids[x * 3], deskeyList, deskeyListLen, aeskeyList, aeskeyListLen, k3kkeyList, k3kkeyListLen, cmdKDFAlgo, kdfInputLen, kdfInput, foundKeys, &foundKeyThisRound, verbose); - if (res == PM3_EOPABORTED) { - break; - } + res = AuthCheckDesfire(&dctx, secureChannel, &app_ids[x * 3], deskeyList, deskeyListLen, aeskeyList, aeskeyListLen, k3kkeyList, k3kkeyListLen, cmdKDFAlgo, kdfInputLen, kdfInput, foundKeys, &foundKeyThisRound, verbose); + if (res == PM3_EOPABORTED) { + break; + } - result = result || foundKeyThisRound; + result = result || foundKeyThisRound; - if (foundKeyThisRound == true && verbose == false) { - if (pattern1b || pattern2b) - PrintAndLogEx(NORMAL, "p" NOLF); - else if (dict_filenamelen) - PrintAndLogEx(NORMAL, "d" NOLF); - } - } + if (foundKeyThisRound == true && verbose == false) { + if (pattern1b || pattern2b) + PrintAndLogEx(NORMAL, "p" NOLF); + else if (dict_filenamelen) + PrintAndLogEx(NORMAL, "d" NOLF); + } + } - if (!loadedAllKeys) - break; + if (!loadedAllKeys) + break; } if (verbose == false) { PrintAndLogEx(NORMAL, ""); diff --git a/client/src/cmdhw.c b/client/src/cmdhw.c index 6380d68f2..f47e54dd0 100644 --- a/client/src/cmdhw.c +++ b/client/src/cmdhw.c @@ -1510,13 +1510,13 @@ static int CmdTearoff(const char *Cmd) { static int CmdBwmAutoOff(const char *Cmd) { CLIParserContext *ctx; CLIParserInit(&ctx, "hw bwmautooff", - "Toggle automatic power-off when the PM5 is unplugged from USB (BWM only).\n" - "Default is " _GREEN_("on") ". When on, the board powers itself down ~10s after\n" - "USB is removed, so a BWM-equipped PM5 doesn't silently drain the battery.\n" - "Button power-on is unaffected. Disable for standalone/BLE use on battery.\n" - _YELLOW_("Runtime only:") " resets to on at each boot.", - "hw bwmautooff --off --> disable auto power-off\n" - "hw bwmautooff --on --> re-enable auto power-off"); + "Toggle automatic power-off when the PM5 is unplugged from USB (BWM only).\n" + "Default is " _GREEN_("on") ". When on, the board powers itself down ~10s after\n" + "USB is removed, so a BWM-equipped PM5 doesn't silently drain the battery.\n" + "Button power-on is unaffected. Disable for standalone/BLE use on battery.\n" + _YELLOW_("Runtime only:") " resets to on at each boot.", + "hw bwmautooff --off --> disable auto power-off\n" + "hw bwmautooff --on --> re-enable auto power-off"); void *argtable[] = { arg_param_begin, @@ -1625,9 +1625,15 @@ static int CmdBWMWifi(const char *Cmd) { data[n++] = BWM_WIFI_ACTION_START; data[n++] = (uint8_t)(port & 0xFF); data[n++] = (uint8_t)((port >> 8) & 0xFF); - memcpy(&data[n], ssid, ssid_len); n += ssid_len; data[n++] = 0; - memcpy(&data[n], pwd, pwd_len); n += pwd_len; data[n++] = 0; - memcpy(&data[n], host, host_len); n += host_len; data[n++] = 0; + memcpy(&data[n], ssid, ssid_len); + n += ssid_len; + data[n++] = 0; + memcpy(&data[n], pwd, pwd_len); + n += pwd_len; + data[n++] = 0; + memcpy(&data[n], host, host_len); + n += host_len; + data[n++] = 0; PrintAndLogEx(INFO, "Bringing up BWM WiFi (SSID \"%s\", port %d)... this can take ~15s", ssid, port); @@ -2000,7 +2006,7 @@ static int CmdPM5Ant(const char *Cmd) { .reg_type = rw_map ? 1 : 0, }; clearCommandBuffer(); - SendCommandNG(CMD_ANT_CONTROL_READ, (uint8_t*)&payload_read, sizeof(payload_read)); + SendCommandNG(CMD_ANT_CONTROL_READ, (uint8_t *)&payload_read, sizeof(payload_read)); if (WaitForResponseTimeout(CMD_ANT_CONTROL_READ, &resp, 1000) == false) { PrintAndLogEx(WARNING, "command execution time out"); return PM3_ETIMEOUT; @@ -2012,7 +2018,7 @@ static int CmdPM5Ant(const char *Cmd) { PrintAndLogEx(INFO, "PM5 antenna register read: 0x%02X", resp.data.asBytes[0]); // Write the new value to the register(If need) - if (io != (uint64_t)-1) { + if (io != (uint64_t) -1) { struct { uint8_t data; uint8_t reg_type; // 0 is io reg, 1 is map reg. @@ -2021,7 +2027,7 @@ static int CmdPM5Ant(const char *Cmd) { .data = io & 0xFF, }; clearCommandBuffer(); - SendCommandNG(CMD_ANT_CONTROL_WRITE, (uint8_t*)&payload_write, sizeof(payload_write)); + SendCommandNG(CMD_ANT_CONTROL_WRITE, (uint8_t *)&payload_write, sizeof(payload_write)); if (WaitForResponseTimeout(CMD_ANT_CONTROL_WRITE, &resp, 1000) == false) { PrintAndLogEx(WARNING, "command execution time out"); return PM3_ETIMEOUT; @@ -2077,14 +2083,14 @@ static int CmdDeviceFactoryData(const char *Cmd) { PrintAndLogEx(INFO, " - Data raw(hex) : 0x%s", sprint_hex_inrow(resp.data.asBytes, resp.length)); PrintAndLogEx(INFO, " - Version : %d", factory->factory_info_version); PrintAndLogEx(INFO, " - Signature : %s", - sprint_hex_inrow(factory->ecdsa_secp256k1_signature, sizeof(factory->ecdsa_secp256k1_signature))); + sprint_hex_inrow(factory->ecdsa_secp256k1_signature, sizeof(factory->ecdsa_secp256k1_signature))); PrintAndLogEx(INFO, " - Timestamp : %" PRIu64, factory->info.unix_timestamp); PrintAndLogEx(INFO, " - Chip Unique ID : %s", - sprint_hex_inrow(factory->info.chip_unique_id, sizeof(factory->info.chip_unique_id))); + sprint_hex_inrow(factory->info.chip_unique_id, sizeof(factory->info.chip_unique_id))); PrintAndLogEx(INFO, " - Production ID : %" PRIu32, factory->info.production_id); PrintAndLogEx(INFO, " - Hardware Version : %" PRIu32, factory->info.hardware_version); PrintAndLogEx(INFO, " - AES key : %s", - sprint_hex_inrow(factory->info.aes_key, sizeof(factory->info.aes_key))); + sprint_hex_inrow(factory->info.aes_key, sizeof(factory->info.aes_key))); } // If data is provided, it needs to be written @@ -2100,7 +2106,7 @@ static int CmdDeviceFactoryData(const char *Cmd) { if (datalen != resp.length) { PrintAndLogEx(WARNING, _RED_("The length of the data to write (%zu) does not match the length " - "of the factory data read from device (%u)."), datalen, (unsigned int)resp.length); + "of the factory data read from device (%u)."), datalen, (unsigned int)resp.length); free(data); return PM3_EINVARG; } @@ -2550,7 +2556,7 @@ void pm3_version(bool verbose, bool oneliner) { SendCommandNG(CMD_MAIN_CHIP_UNIQUEID, NULL, 0); if (WaitForResponseTimeout(CMD_MAIN_CHIP_UNIQUEID, &resp, 1000)) { if (resp.length) { // Some processor maybe no unique id. - char* uniqueid_hex = sprint_hex_inrow(resp.data.asBytes, resp.length); + char *uniqueid_hex = sprint_hex_inrow(resp.data.asBytes, resp.length); PrintAndLogEx(NORMAL, " --= Processor Unique ID: " _YELLOW_("0x%s"), uniqueid_hex); } } diff --git a/client/src/cmdsmartcard.c b/client/src/cmdsmartcard.c index bc3834ef8..a0faf1533 100644 --- a/client/src/cmdsmartcard.c +++ b/client/src/cmdsmartcard.c @@ -910,11 +910,11 @@ static int CmdSmartReader(const char *Cmd) { // ISO/IEC 7816-3 tables 7 and 8, so the negotiated rate can be printed back. static const uint16_t pps_fi_table[16] = { 372, 372, 558, 744, 1116, 1488, 1860, 0, - 0, 512, 768, 1024, 1536, 2048, 0, 0 + 0, 512, 768, 1024, 1536, 2048, 0, 0 }; static const uint8_t pps_di_table[16] = { - 0, 1, 2, 4, 8, 16, 32, 64, - 12, 20, 0, 0, 0, 0, 0, 0 + 0, 1, 2, 4, 8, 16, 32, 64, + 12, 20, 0, 0, 0, 0, 0, 0 }; static int CmdSmartPPS(const char *Cmd) { diff --git a/client/src/fileutils.c b/client/src/fileutils.c index b7f6e6bad..b5bfe0db8 100644 --- a/client/src/fileutils.c +++ b/client/src/fileutils.c @@ -2354,9 +2354,9 @@ int loadFileJSONex(const char *preferredName, void *data, size_t maxdatalen, siz } hdr[] = { { "$.Card.uid", tag->uid, sizeof(tag->uid), true }, { "$.Card.dsfid", &tag->dsfid, 1, false }, - { "$.Card.dsfidlock", (uint8_t *)&tag->dsfidLock, 1, false }, + { "$.Card.dsfidlock", (uint8_t *) &tag->dsfidLock, 1, false }, { "$.Card.afi", &tag->afi, 1, false }, - { "$.Card.afilock", (uint8_t *)&tag->afiLock, 1, false }, + { "$.Card.afilock", (uint8_t *) &tag->afiLock, 1, false }, { "$.Card.bytesperpage", &tag->bytesPerPage, 1, true }, { "$.Card.pagescount", pagescount, is_v5 ? 2 : 1, true }, }; @@ -2393,7 +2393,7 @@ int loadFileJSONex(const char *preferredName, void *data, size_t maxdatalen, siz { "$.Card.locks", tag->locks, tag->pagesCount }, { "$.Card.random", tag->random, sizeof(tag->random) }, { "$.Card.privacypasswd", tag->privacyPasswd, sizeof(tag->privacyPasswd) }, - { "$.Card.state", (uint8_t *)&tag->state, 1 }, + { "$.Card.state", (uint8_t *) &tag->state, 1 }, }; for (size_t n = 0; n < ARRAYLEN(rest); n++) { diff --git a/client/src/flash.c b/client/src/flash.c index c52421b54..7b2baf00e 100644 --- a/client/src/flash.c +++ b/client/src/flash.c @@ -288,7 +288,7 @@ static int check_segs(flash_file_t *ctx, int can_write_bl, flash_dev_t *flash_de static int print_and_validate_version(flash_file_t *ctx) { if (!CheckValidInformationMagic(ctx->ver_info)) { PrintAndLogEx(ERR, _RED_("ELF file does not contain valid version information" - "(magic = 0x%08x)"), ctx->ver_info->magic); + "(magic = 0x%08x)"), ctx->ver_info->magic); return PM3_EFILE; } @@ -733,7 +733,7 @@ int flash_start_flashing(int enable_bl_writes, char *serial_port_name, flash_dev PrintAndLogEx(ERR, _RED_("Bootloader does not support CMD_CHIP_TYPE, assuming AT91 platform")); flash_dev->chiptype = MAIN_CHIP_TYPE_AT91; flash_suggest_update_bootloader(bl_targeted); - // break; -> Don't break !!! We want to execute the code for MAIN_CHIP_TYPE_AT91 as well to initialize flash_dev with correct values. + // break; -> Don't break !!! We want to execute the code for MAIN_CHIP_TYPE_AT91 as well to initialize flash_dev with correct values. case MAIN_CHIP_TYPE_AT91: default: diff --git a/client/src/loclass/ikeys.c b/client/src/loclass/ikeys.c index cd1266342..cc879f77a 100644 --- a/client/src/loclass/ikeys.c +++ b/client/src/loclass/ikeys.c @@ -622,130 +622,130 @@ void invert_hash0(uint8_t k[8]) { for (int zp_i = 0; zp_i < zP_count; zp_i++) { - uint64_t zP = zP_list[zp_i]; - if (g_debugMode > 0) printState("0|0|z'", zP); + uint64_t zP = zP_list[zp_i]; + if (g_debugMode > 0) printState("0|0|z'", zP); - // reverse the modulo transformation in the hash0 function for the six-bit chunks + // reverse the modulo transformation in the hash0 function for the six-bit chunks - uint64_t c = 0; + uint64_t c = 0; - for (int n = 0; n < 4; n++) { - uint8_t _zn = getSixBitByte(zP, n); - uint8_t _zn4 = getSixBitByte(zP, n + 4); + for (int n = 0; n < 4; n++) { + uint8_t _zn = getSixBitByte(zP, n); + uint8_t _zn4 = getSixBitByte(zP, n + 4); - uint8_t zn = (_zn + (63 - 2 * n)) % (63 - n); - uint8_t zn4 = (_zn4 + (64 - 2 * n)) % (64 - n); - - pushbackSixBitByte(&c, zn, n); - pushbackSixBitByte(&c, zn4, n + 4); - } - - // The Hydra: hash0() reduces every six-bit z chunk modulo a value that - // depends on the chunk position: - // - // _zn = (zn % (63 - n)) + n for n = 0..3 - // _zn4 = (zn4 % (64 - n)) + n for n = 0..3 (chunks 4..7) - // - // Since the modulus is smaller than 0x40 the reduction is lossy, so a - // recovered residue r has a second pre-image at r + modulus whenever - // that value still fits in six bits. Each such chunk forks the search. - - // Initialize an array of pointers to uint64_t (start with one value, initialized to 0) - uint64_t *hydra_heads = (uint64_t *)calloc(sizeof(uint64_t), 1); // Start with one uint64_t - if (hydra_heads == NULL) { - PrintAndLogEx(WARNING, "Failed to allocate memory"); - return; - } - hydra_heads[0] = 0; // Initialize first value to 0 - int heads_count = 1; // Track number of forks - - for (int n = 0; n < 8; n++) { - - uint8_t hydra_head = getSixBitByte(c, n); - - // the modulus hash0() applied to this chunk, mirroring the loop there - uint8_t modulus = (n < 4) ? (63 - n) : (64 - (n - 4)); - - // the only other value that reduces to the same residue - uint8_t alt_head = hydra_head + modulus; - - if (alt_head <= 0x3F) { - - // Create new forks by duplicating existing uint64_t values - int new_head = heads_count * 2; - - // proper realloc pattern - uint64_t *ptmp = (uint64_t *)realloc(hydra_heads, new_head * sizeof(uint64_t)); - if (ptmp == NULL) { - PrintAndLogEx(WARNING, "Failed to allocate memory"); - free(hydra_heads); - return; - } - hydra_heads = ptmp; - - // keep the residue in the existing branch, the alternative in the copy - for (int i = 0; i < heads_count; i++) { - hydra_heads[heads_count + i] = hydra_heads[i]; - pushbackSixBitByte(&hydra_heads[i], hydra_head, n); - pushbackSixBitByte(&hydra_heads[heads_count + i], alt_head, n); - } - // Update the count of total values - heads_count = new_head; - } else { - // no hydra head spawns - for (int i = 0; i < heads_count; i++) { - pushbackSixBitByte(&hydra_heads[i], hydra_head, n); - } - } - } - - for (int i = 0; i < heads_count; i++) { - - // restore the two most significant bytes (x and y) - hydra_heads[i] |= ((uint64_t)x_array[img] << 56); - hydra_heads[i] |= ((uint64_t)y << 48); - - if (g_debugMode > 0) { - PrintAndLogEx(DEBUG, " | x| y|z0|z1|z2|z3|z4|z5|z6|z7|"); - printState("origin_r1", hydra_heads[i]); - } - // reverse the swapZbalues function to get the original six-bit byte order - uint64_t original_z = swapZvalues(hydra_heads[i]); - - if (g_debugMode > 0) { - PrintAndLogEx(DEBUG, " | x| y|z0|z1|z2|z3|z4|z5|z6|z7|"); - printState("origin_r2", original_z); - PrintAndLogEx(INFO, "--------------------------"); - } - // run pre-image through hash0 - uint8_t img_div_key[8] = {0}; - hash0(original_z, img_div_key); // commented to avoid log spam - - // verify result, if it matches add it to the list as a valid pre-image - bool image_match = true; - for (int v = 0; v < 8; v++) { - - // compare against input key k - if (img_div_key[v] != k[v]) { - image_match = false; - } + uint8_t zn = (_zn + (63 - 2 * n)) % (63 - n); + uint8_t zn4 = (_zn4 + (64 - 2 * n)) % (64 - n); + pushbackSixBitByte(&c, zn, n); + pushbackSixBitByte(&c, zn4, n + 4); } - uint8_t des_pre_image[8] = {0}; - x_num_to_bytes(original_z, sizeof(original_z), des_pre_image); + // The Hydra: hash0() reduces every six-bit z chunk modulo a value that + // depends on the chunk position: + // + // _zn = (zn % (63 - n)) + n for n = 0..3 + // _zn4 = (zn4 % (64 - n)) + n for n = 0..3 (chunks 4..7) + // + // Since the modulus is smaller than 0x40 the reduction is lossy, so a + // recovered residue r has a second pre-image at r + modulus whenever + // that value still fits in six bits. Each such chunk forks the search. - if (image_match) { - PrintAndLogEx(INFO, "Pre-image......... " _YELLOW_("%s") " ( "_GREEN_("ok") " )", sprint_hex_inrow(des_pre_image, sizeof(des_pre_image))); - } else { + // Initialize an array of pointers to uint64_t (start with one value, initialized to 0) + uint64_t *hydra_heads = (uint64_t *)calloc(sizeof(uint64_t), 1); // Start with one uint64_t + if (hydra_heads == NULL) { + PrintAndLogEx(WARNING, "Failed to allocate memory"); + return; + } + hydra_heads[0] = 0; // Initialize first value to 0 + int heads_count = 1; // Track number of forks + + for (int n = 0; n < 8; n++) { + + uint8_t hydra_head = getSixBitByte(c, n); + + // the modulus hash0() applied to this chunk, mirroring the loop there + uint8_t modulus = (n < 4) ? (63 - n) : (64 - (n - 4)); + + // the only other value that reduces to the same residue + uint8_t alt_head = hydra_head + modulus; + + if (alt_head <= 0x3F) { + + // Create new forks by duplicating existing uint64_t values + int new_head = heads_count * 2; + + // proper realloc pattern + uint64_t *ptmp = (uint64_t *)realloc(hydra_heads, new_head * sizeof(uint64_t)); + if (ptmp == NULL) { + PrintAndLogEx(WARNING, "Failed to allocate memory"); + free(hydra_heads); + return; + } + hydra_heads = ptmp; + + // keep the residue in the existing branch, the alternative in the copy + for (int i = 0; i < heads_count; i++) { + hydra_heads[heads_count + i] = hydra_heads[i]; + pushbackSixBitByte(&hydra_heads[i], hydra_head, n); + pushbackSixBitByte(&hydra_heads[heads_count + i], alt_head, n); + } + // Update the count of total values + heads_count = new_head; + } else { + // no hydra head spawns + for (int i = 0; i < heads_count; i++) { + pushbackSixBitByte(&hydra_heads[i], hydra_head, n); + } + } + } + + for (int i = 0; i < heads_count; i++) { + + // restore the two most significant bytes (x and y) + hydra_heads[i] |= ((uint64_t)x_array[img] << 56); + hydra_heads[i] |= ((uint64_t)y << 48); if (g_debugMode > 0) { - PrintAndLogEx(INFO, "Pre-image......... " _YELLOW_("%s") " ( "_RED_("invalid") " )", sprint_hex_inrow(des_pre_image, sizeof(des_pre_image))); + PrintAndLogEx(DEBUG, " | x| y|z0|z1|z2|z3|z4|z5|z6|z7|"); + printState("origin_r1", hydra_heads[i]); + } + // reverse the swapZbalues function to get the original six-bit byte order + uint64_t original_z = swapZvalues(hydra_heads[i]); + + if (g_debugMode > 0) { + PrintAndLogEx(DEBUG, " | x| y|z0|z1|z2|z3|z4|z5|z6|z7|"); + printState("origin_r2", original_z); + PrintAndLogEx(INFO, "--------------------------"); + } + // run pre-image through hash0 + uint8_t img_div_key[8] = {0}; + hash0(original_z, img_div_key); // commented to avoid log spam + + // verify result, if it matches add it to the list as a valid pre-image + bool image_match = true; + for (int v = 0; v < 8; v++) { + + // compare against input key k + if (img_div_key[v] != k[v]) { + image_match = false; + } + + } + + uint8_t des_pre_image[8] = {0}; + x_num_to_bytes(original_z, sizeof(original_z), des_pre_image); + + if (image_match) { + PrintAndLogEx(INFO, "Pre-image......... " _YELLOW_("%s") " ( "_GREEN_("ok") " )", sprint_hex_inrow(des_pre_image, sizeof(des_pre_image))); + } else { + + if (g_debugMode > 0) { + PrintAndLogEx(INFO, "Pre-image......... " _YELLOW_("%s") " ( "_RED_("invalid") " )", sprint_hex_inrow(des_pre_image, sizeof(des_pre_image))); + } } } - } - // Free allocated memory - free(hydra_heads); + // Free allocated memory + free(hydra_heads); } // for each zP candidate } diff --git a/common_arm/flash_code/flash_code_hw_at32.c b/common_arm/flash_code/flash_code_hw_at32.c index 199ba7c46..577921260 100644 --- a/common_arm/flash_code/flash_code_hw_at32.c +++ b/common_arm/flash_code/flash_code_hw_at32.c @@ -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; } } diff --git a/common_arm/flash_data/flashmem_core.c b/common_arm/flash_data/flashmem_core.c index 3a59c6e80..beb1e90e6 100644 --- a/common_arm/flash_data/flashmem_core.c +++ b/common_arm/flash_data/flashmem_core.c @@ -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; } diff --git a/common_arm/flash_data/flashmem_hw_at91.c b/common_arm/flash_data/flashmem_hw_at91.c index 65c1ed6e6..45df17443 100644 --- a/common_arm/flash_data/flashmem_hw_at91.c +++ b/common_arm/flash_data/flashmem_hw_at91.c @@ -373,4 +373,4 @@ bool Flash_ReadStat2(uint8_t *status) { FlashSendByte(READSTAT2); *status = FlashSendLastByte(0xFF); return true; -} \ No newline at end of file +} diff --git a/common_arm/fpga/fpga_apis.h b/common_arm/fpga/fpga_apis.h index d00e8e401..9897708db 100644 --- a/common_arm/fpga/fpga_apis.h +++ b/common_arm/fpga/fpga_apis.h @@ -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. diff --git a/common_arm/fpga/fpga_gw_jtag.c b/common_arm/fpga/fpga_gw_jtag.c index 80161f2ab..f7eae3d98 100644 --- a/common_arm/fpga/fpga_gw_jtag.c +++ b/common_arm/fpga/fpga_gw_jtag.c @@ -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) { diff --git a/common_arm/fpga/fpga_gw_jtag.h b/common_arm/fpga/fpga_gw_jtag.h index 93e844ce0..3fe97c23f 100644 --- a/common_arm/fpga/fpga_gw_jtag.h +++ b/common_arm/fpga/fpga_gw_jtag.h @@ -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; diff --git a/common_arm/fpga/fpga_hw_at32.c b/common_arm/fpga/fpga_hw_at32.c index d464abb9f..7ab507a38 100644 --- a/common_arm/fpga/fpga_hw_at32.c +++ b/common_arm/fpga/fpga_hw_at32.c @@ -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 } diff --git a/common_arm/fpga/fpga_hw_at32.h b/common_arm/fpga/fpga_hw_at32.h index 7b3bd9874..b36c46c0d 100644 --- a/common_arm/fpga/fpga_hw_at32.h +++ b/common_arm/fpga/fpga_hw_at32.h @@ -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 \ No newline at end of file +#endif diff --git a/common_arm/fpga/fpga_hw_at91.c b/common_arm/fpga/fpga_hw_at91.c index d9d1a20bf..e25f012fc 100644 --- a/common_arm/fpga/fpga_hw_at91.c +++ b/common_arm/fpga/fpga_hw_at91.c @@ -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; diff --git a/common_arm/fpga/fpga_hw_at91.h b/common_arm/fpga/fpga_hw_at91.h index f93e338f8..8435e4c97 100644 --- a/common_arm/fpga/fpga_hw_at91.h +++ b/common_arm/fpga/fpga_hw_at91.h @@ -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 \ No newline at end of file +#endif diff --git a/common_arm/fpga/fpga_loader.c b/common_arm/fpga/fpga_loader.c index 11d4e4f41..4f6ac6f9d 100644 --- a/common_arm/fpga/fpga_loader.c +++ b/common_arm/fpga/fpga_loader.c @@ -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; } diff --git a/common_arm/fpga/fpga_loader.h b/common_arm/fpga/fpga_loader.h index c85c35792..f4944bc74 100644 --- a/common_arm/fpga/fpga_loader.h +++ b/common_arm/fpga/fpga_loader.h @@ -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); diff --git a/common_arm/gpio/gpio_hw_at91.c b/common_arm/gpio/gpio_hw_at91.c index 72ede14b8..d4d871eeb 100644 --- a/common_arm/gpio/gpio_hw_at91.c +++ b/common_arm/gpio/gpio_hw_at91.c @@ -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) { diff --git a/common_arm/rssi/rssi_hw_at32.c b/common_arm/rssi/rssi_hw_at32.c index 064f4a4fa..65c5c39ed 100644 --- a/common_arm/rssi/rssi_hw_at32.c +++ b/common_arm/rssi/rssi_hw_at32.c @@ -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); diff --git a/common_arm/rssi/rssi_hw_at91.c b/common_arm/rssi/rssi_hw_at91.c index 67a55ba25..569215c8c 100644 --- a/common_arm/rssi/rssi_hw_at91.c +++ b/common_arm/rssi/rssi_hw_at91.c @@ -26,4 +26,4 @@ void AdcSetupRssiChannel(adc_rssi_ch_t ch) { } AdcRssiConversionStart(); -} \ No newline at end of file +} diff --git a/common_arm/sys/sys_apis.h b/common_arm/sys/sys_apis.h index 275babb02..ce1269af0 100644 --- a/common_arm/sys/sys_apis.h +++ b/common_arm/sys/sys_apis.h @@ -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 diff --git a/common_arm/sys/sys_hw_at32.c b/common_arm/sys/sys_hw_at32.c index 316913395..38ecc6138 100644 --- a/common_arm/sys/sys_hw_at32.c +++ b/common_arm/sys/sys_hw_at32.c @@ -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 diff --git a/common_arm/sys/sys_hw_at91.h b/common_arm/sys/sys_hw_at91.h index cc628a4c2..a48ec9f41 100644 --- a/common_arm/sys/sys_hw_at91.h +++ b/common_arm/sys/sys_hw_at91.h @@ -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; diff --git a/common_arm/ticks/ticks_hw_at32.c b/common_arm/ticks/ticks_hw_at32.c index 4784cb8df..91b7e769b 100644 --- a/common_arm/ticks/ticks_hw_at32.c +++ b/common_arm/ticks/ticks_hw_at32.c @@ -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 } // ------------------------------------------------------------------------- diff --git a/common_arm/usb/usb_cdc_at32.c b/common_arm/usb/usb_cdc_at32.c index 8f3416158..f4a6087c2 100644 --- a/common_arm/usb/usb_cdc_at32.c +++ b/common_arm/usb/usb_cdc_at32.c @@ -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; diff --git a/common_arm/usb/usb_cdc_at91.c b/common_arm/usb/usb_cdc_at91.c index 086394568..3e80b36a9 100644 --- a/common_arm/usb/usb_cdc_at91.c +++ b/common_arm/usb/usb_cdc_at91.c @@ -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; -} \ No newline at end of file +} diff --git a/common_arm/usb/usb_read_ng.c b/common_arm/usb/usb_read_ng.c index d0bbdd0f0..b8400bf48 100644 --- a/common_arm/usb/usb_read_ng.c +++ b/common_arm/usb/usb_read_ng.c @@ -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++; diff --git a/common_arm/usb/usb_read_ng.h b/common_arm/usb/usb_read_ng.h index d9d625f5e..cc34393f0 100644 --- a/common_arm/usb/usb_read_ng.h +++ b/common_arm/usb/usb_read_ng.h @@ -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 \ No newline at end of file +#endif diff --git a/common_arm/wdt/wdt_hw_at32.h b/common_arm/wdt/wdt_hw_at32.h index 0a575a9f2..b43fc3f58 100644 --- a/common_arm/wdt/wdt_hw_at32.h +++ b/common_arm/wdt/wdt_hw_at32.h @@ -7,4 +7,4 @@ STATIC_FORCE_INLINE void WDT_HIT(void) { // TODO 待实现喂狗 } -#endif \ No newline at end of file +#endif diff --git a/common_arm/wdt/wdt_hw_at91.h b/common_arm/wdt/wdt_hw_at91.h index be9054282..df853fe0e 100644 --- a/common_arm/wdt/wdt_hw_at91.h +++ b/common_arm/wdt/wdt_hw_at91.h @@ -8,4 +8,4 @@ STATIC_FORCE_INLINE void WDT_HIT(void) { AT91C_BASE_WDTC->WDTC_WDCR = 0xa5000001; } -#endif \ No newline at end of file +#endif diff --git a/doc/commands.json b/doc/commands.json index 034d60691..5efcfc956 100644 --- a/doc/commands.json +++ b/doc/commands.json @@ -1532,6 +1532,7 @@ "description": "Act as a ISO-14443a reader to identify tag. Look for ISO-14443a tags until Enter or the pm3 button is pressed", "notes": [ "hf 14a reader", + "hf 14a reader -n 100 -> Polls 100 times", "hf 14a reader -@ -> Continuous mode" ], "offline": false, @@ -1541,10 +1542,11 @@ "-s, --silent silent (no messages)", "--drop just drop the signal field", "--skip ISO14443-3 select only (skip RATS)", + "-n, --num number of times to poll", "-@ continuous reader mode", "-w, --wait wait for card" ], - "usage": "hf 14a reader [-hks@w] [--drop] [--skip]" + "usage": "hf 14a reader [-hks@w] [--drop] [--skip] [-n ]" }, "hf 14a sim": { "command": "hf 14a sim", @@ -1961,11 +1963,11 @@ }, "hf 15 dump": { "command": "hf 15 dump", - "description": "This command dumps the contents of a ISO-15693 tag and save to file (bin/json)", + "description": "This command dumps the contents of a ISO-15693 tag and saves it to a JSON file. Writing .bin is no longer supported, the raw struct carries no layout information. Reading .bin/.eml/.json all still work.", "notes": [ "hf 15 dump", "hf 15 dump -*", - "hf 15 dump -u E011223344556677 -f hf-15-my-dump.bin" + "hf 15 dump -u E011223344556677 -f hf-15-my-dump" ], "offline": false, "options": [ @@ -3171,7 +3173,8 @@ "description": "Send raw hex data to tag", "notes": [ "hf felica raw -cs 20", - "hf felica raw -cs 2008" + "hf felica raw -cs 2008", + "hw dbg -4; hf felica raw -acp 00ffff0000 -> measure antenna envelope, for reading distance" ], "offline": false, "options": [ @@ -3180,11 +3183,12 @@ "-c calculate and append CRC", "-k keep signal field ON after receive", "-n number of bits", + "-p, --probe report antenna envelope instead of decoding (needs `hw dbg -4`)", "-r do not read response", "-s active signal field ON with select", " raw bytes to send" ], - "usage": "hf felica raw [-hackrs] [-n ] " + "usage": "hf felica raw [-hackprs] [-n ] " }, "hf felica rdbl": { "command": "hf felica rdbl", @@ -4424,7 +4428,7 @@ "-k, --key Access key as 8 hex bytes", "--ki Key index to select key from memory 'hf iclass managekeys'", "--credit key is assumed to be the credit key", - "-s tearoff delay start (in us) must be between 1 and 43000 (43ms). Precision is about 1/3 us", + "-s tearoff delay start (in us) must be between 1 and 65535 (65ms). Precision is about 1/3 us", "-i tearoff delay increment (in us) - default 5", "-e tearoff delay end (in us) must be a higher value than the start delay", "-o, --otp Custom OTP value as 2 hex bytes", @@ -5022,7 +5026,7 @@ "--nr replay of NR/MAC", "-v, --verbose verbose output", "--shallow use shallow (ASK) reader modulation instead of OOK", - "-s tearoff delay start (in us) must be between 1 and 43000 (43ms). Precision is about 1/3 us", + "-s tearoff delay start (in us) must be between 1 and 65535 (65ms). Precision is about 1/3 us", "-i tearoff delay increment (in us) - default 10", "-e tearoff delay end (in us) must be a higher value than the start delay", "--loop number of times to loop per tearoff time", @@ -10843,15 +10847,16 @@ "command": "hw bwmcharge", "description": "Enable or disable BWM battery charging by clearing/setting the AW32001E charge-enable bit (CEB, REG01[3]). PM5 only. One-shot: the charger watchdog reverts this after ~160 s unless serviced, so charging may stop on its own. Use to nudge a top-up.", "notes": [ - "hw bwmcharge -> enable charging", + "hw bwmcharge -on -> enable charging", "hw bwmcharge --off -> disable charging" ], "offline": false, "options": [ "-h, --help This help", - "--off disable charging (default is enable)" + "--on enable charging (default)", + "--off disable charging" ], - "usage": "hw bwmcharge [-h] [--off]" + "usage": "hw bwmcharge [-h] [--on] [--off]" }, "hw bwmsetcap": { "command": "hw bwmsetcap", @@ -10877,12 +10882,13 @@ "offline": false, "options": [ "-h, --help This help", - "--ssid WiFi SSID to join", + "--ssid WiFi SSID to join (omit with --stop)", "--pwd WiFi password (omit for open network)", "--port TCP server listen port (default 7777)", - "--hostname DHCP hostname (default Proxmark5)" + "--hostname DHCP hostname (default Proxmark5)", + "--stop tear down WiFi and return to BLE-only" ], - "usage": "hw bwmwifi [-h] --ssid [--pwd ] [--port ] [--hostname ]" + "usage": "hw bwmwifi [-h] [--ssid ] [--pwd ] [--port ] [--hostname ] [--stop]" }, "hw connect": { "command": "hw connect", @@ -11133,7 +11139,7 @@ }, "hw tearoff": { "command": "hw tearoff", - "description": "Configure a tear-off hook for the next write command supporting tear-off After having been triggered by a write command, the tear-off hook is deactivated Delay (in us) must be between 1 and 43000 (43ms). Precision is about 1/3us.", + "description": "Configure a tear-off hook for the next write command supporting tear-off After having been triggered by a write command, the tear-off hook is deactivated Delay (in us) must be between 1 and 65535 (65ms). Precision is about 1/3us.", "notes": [ "hw tearoff --delay 1200 -> define delay of 1200us", "hw tearoff --on -> (re)activate a previously defined delay", @@ -11143,7 +11149,7 @@ "offline": false, "options": [ "-h, --help This help", - "--delay Delay in us before triggering tear-off, must be between 1 and 43000", + "--delay Delay in us before triggering tear-off, must be between 1 and 65535", "--on Activate tear-off hook", "--off Deactivate tear-off hook", "--skip Skip N triggers before activating the hook", @@ -14016,18 +14022,6 @@ ], "usage": "lf simask [-hiv] [-c ] [--bi] [--am] [--ar] [--stt] [-d ]" }, - "lf simbidir": { - "command": "lf simbidir", - "description": "Simulate LF tag with bidirectional data transmission between reader and tag", - "notes": [ - "lf simbidir" - ], - "offline": false, - "options": [ - "-h, --help This help" - ], - "usage": "lf simbidir [-h]" - }, "lf simfsk": { "command": "lf simfsk", "description": "Simulate FSK tag from DemodBuffer or input. There are about four FSK modulations to know of. FSK1 - where fc/8 = high and fc/5 = low FSK1a - is inverted FSK1, ie: fc/5 = high and fc/8 = low FSK2 - where fc/10 = high and fc/8 = low FSK2a - is inverted FSK2, ie: fc/10 = high and fc/8 = low NOTE: if you set one clock manually set them all manually", @@ -16335,8 +16329,8 @@ } }, "metadata": { - "commands_extracted": 910, + "commands_extracted": 909, "extracted_by": "PM3Help2JSON v1.00", - "extracted_on": "2026-08-27T23:06:33+00:00" + "extracted_on": "2026-08-29T15:40:14+00:00" } } diff --git a/doc/commands.md b/doc/commands.md index a19c0ff3f..888a6b837 100644 --- a/doc/commands.md +++ b/doc/commands.md @@ -1049,7 +1049,6 @@ Check column "offline" for their availability. |`lf simask `|N |`Simulate ASK tag` |`lf simfsk `|N |`Simulate FSK tag` |`lf simpsk `|N |`Simulate PSK tag` -|`lf simbidir `|N |`Simulate LF tag (with bidirectional data transmission between reader and tag)` |`lf sniff `|N |`Sniff LF traffic between reader and tag` |`lf tune `|N |`Continuously measure LF antenna tuning`