Skip to content

Commit

Permalink
Merge pull request zephyrproject-rtos#7 from ccli8/nvt_m467_patch_v3.…
Browse files Browse the repository at this point in the history
…2.0_upgrade

NuMaker: Update following v3.2.0 upgrade
  • Loading branch information
cyliangtw authored Dec 29, 2022
2 parents 4863c1c + ecea3ab commit 37ce081
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 48 deletions.
7 changes: 5 additions & 2 deletions drivers/can/can_numaker.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ static int can_numaker_init(const struct device *dev)
}

static const struct can_driver_api can_numaker_driver_api = {
.get_capabilities = can_mcan_get_capabilities,
.start = can_mcan_start,
.stop = can_mcan_stop,
.set_mode = can_mcan_set_mode,
.set_timing = can_mcan_set_timing,
.send = can_mcan_send,
Expand All @@ -192,7 +195,7 @@ static const struct can_driver_api can_numaker_driver_api = {
/* Nominal bit timing limits
*
* NUMAKER MCAN timing limits are specified in the "Nominal bit timing and
* prescaler register (NBTP)" table in the SoC reference manual.
* prescaler register (NBTP)" table in the SoC reference manual.
*
* NOTE: The values here are the "physical" timing limits, whereas the register
* field limits are physical values minus 1 (which is handled by the
Expand All @@ -217,7 +220,7 @@ static const struct can_driver_api can_numaker_driver_api = {
/* Data bit timing limits
*
* NUMAKER MCAN timing limits are specified in the "Data bit timing and
* prescaler register (DBTP)" table in the SoC reference manual.
* prescaler register (DBTP)" table in the SoC reference manual.
*
* NOTE: Same "minus one" concern as above.
*/
Expand Down
44 changes: 22 additions & 22 deletions drivers/i2c/i2c_numaker.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ static int nu_int_i2c_poll_tran_heatbeat_timeout(const struct device *dev, uint3
static int nu_int_i2c_is_trsn_done(const struct device *dev);
static int nu_int_i2c_is_tran_started(const struct device *dev);
static int nu_int_i2c_addr2data(int address, int read);
#ifdef CONFIG_I2C_SLAVE
#ifdef CONFIG_I2C_TARGET
/* Convert zephyr address to BSP address. */
static int nu_int_i2c_addr2bspaddr(int address);
static void nu_int_i2c_enable_slave_if_registered(const struct device *dev);
Expand All @@ -76,7 +76,7 @@ static int nu_int_i2c_set_int(const struct device *dev, int inten);
#define TRANCTRL_LASTDATANAKED (1 << 2) // Last data NACKed
#define TRANCTRL_RECVDATA (1 << 3) // Receive data available

#ifdef CONFIG_I2C_SLAVE
#ifdef CONFIG_I2C_TARGET
#define NoData 0 // the slave has not been addressed
#define ReadAddressed 1 // the master has requested a read from this slave (slave = transmitter)
#define WriteGeneral 2 // the master is writing to all slave
Expand Down Expand Up @@ -110,8 +110,8 @@ struct i2c_numaker_data {
struct k_sem lock;
struct k_sem xfer_sync;
uint32_t dev_config;
#ifdef CONFIG_I2C_SLAVE
struct i2c_slave_config * slave_config;
#ifdef CONFIG_I2C_TARGET
struct i2c_target_config * slave_config;
#endif

struct {
Expand All @@ -120,7 +120,7 @@ struct i2c_numaker_data {
char * tran_pos;
char * tran_end;
int inten;
#ifdef CONFIG_I2C_SLAVE
#ifdef CONFIG_I2C_TARGET
int slaveaddr_state;
#endif
} i2c;
Expand Down Expand Up @@ -165,7 +165,7 @@ static int i2c_numaker_configure(const struct device *dev,
k_sem_take(&data->lock, K_FOREVER);
nu_int_i2c_disable_int(dev);

#ifdef CONFIG_I2C_SLAVE
#ifdef CONFIG_I2C_TARGET
if (nu_int_i2c_is_slave_busy(dev)) {
LOG_ERR("Reconfigure with slave being busy");
err = -EBUSY;
Expand Down Expand Up @@ -286,7 +286,7 @@ static int i2c_numaker_transfer(const struct device *dev, struct i2c_msg *msgs,
/* Do I2C stop to release bus ownership */
nu_int_i2c_stop(dev);

#ifdef CONFIG_I2C_SLAVE
#ifdef CONFIG_I2C_TARGET
/* Enable slave mode if any slave registered */
nu_int_i2c_enable_slave_if_registered(dev);
#endif
Expand All @@ -299,15 +299,15 @@ static int i2c_numaker_transfer(const struct device *dev, struct i2c_msg *msgs,
return err;
}

#ifdef CONFIG_I2C_SLAVE
#ifdef CONFIG_I2C_TARGET
static int i2c_numaker_slave_register(const struct device *dev,
struct i2c_slave_config *slave_config)
struct i2c_target_config *slave_config)
{
if (!slave_config) {
return -EINVAL;
}

if (slave_config->flags & I2C_SLAVE_FLAGS_ADDR_10_BITS) {
if (slave_config->flags & I2C_ADDR_10_BITS) {
LOG_ERR("10-bits address not supported");
return -ENOTSUP;
}
Expand Down Expand Up @@ -347,7 +347,7 @@ static int i2c_numaker_slave_register(const struct device *dev,
}

static int i2c_numaker_slave_unregister(const struct device *dev,
struct i2c_slave_config *slave_config)
struct i2c_target_config *slave_config)
{
if (!slave_config) {
return -EINVAL;
Expand Down Expand Up @@ -411,9 +411,9 @@ static void i2c_numaker_isr(const struct device *dev)
const struct i2c_numaker_config *config = dev->config;
struct i2c_numaker_data *data = dev->data;
I2C_T *i2c_base = config->i2c_base;
#ifdef CONFIG_I2C_SLAVE
struct i2c_slave_config *slave_config = data->slave_config;
const struct i2c_slave_callbacks *slave_callbacks = slave_config ? slave_config->callbacks : NULL;
#ifdef CONFIG_I2C_TARGET
struct i2c_target_config *slave_config = data->slave_config;
const struct i2c_target_callbacks *slave_callbacks = slave_config ? slave_config->callbacks : NULL;
int err = 0;
uint8_t data_tran;
#endif
Expand Down Expand Up @@ -501,7 +501,7 @@ static void i2c_numaker_isr(const struct device *dev)

//case 0x00: // Bus error

#ifdef CONFIG_I2C_SLAVE
#ifdef CONFIG_I2C_TARGET
// Slave Transmit
case 0xB8: // Slave Transmit Data ACK
case 0xA8: // Slave Transmit Address ACK
Expand Down Expand Up @@ -671,7 +671,7 @@ static void i2c_numaker_isr(const struct device *dev)
nu_int_i2c_disable_int(dev);
}
break;
#endif /* CONFIG_I2C_SLAVE */
#endif /* CONFIG_I2C_TARGET */

case 0xF8: // Bus Released
break;
Expand Down Expand Up @@ -739,7 +739,7 @@ static int i2c_numaker_init(const struct device *dev)

SYS_ResetModule(config->id_rst);

err = i2c_numaker_configure(dev, I2C_MODE_MASTER | i2c_map_dt_bitrate(config->bitrate));
err = i2c_numaker_configure(dev, I2C_MODE_CONTROLLER | i2c_map_dt_bitrate(config->bitrate));
if (err != 0) {
goto cleanup;
}
Expand All @@ -756,9 +756,9 @@ static const struct i2c_driver_api i2c_numaker_driver_api = {
.configure = i2c_numaker_configure,
.get_config = i2c_numaker_get_config,
.transfer = i2c_numaker_transfer,
#ifdef CONFIG_I2C_SLAVE
.slave_register = i2c_numaker_slave_register,
.slave_unregister = i2c_numaker_slave_unregister,
#ifdef CONFIG_I2C_TARGET
.target_register = i2c_numaker_slave_register,
.target_unregister = i2c_numaker_slave_unregister,
#endif
.recover_bus = i2c_numaker_recover_bus,
};
Expand Down Expand Up @@ -831,7 +831,7 @@ static void nu_int_i2c_fsm_reset(const struct device *dev, uint32_t i2c_ctl)
data->i2c.tran_ctrl = 0;

I2C_SET_CONTROL_REG(i2c_base, i2c_ctl);
#ifdef CONFIG_I2C_SLAVE
#ifdef CONFIG_I2C_TARGET
data->i2c.slaveaddr_state = NoData;
#endif
}
Expand Down Expand Up @@ -1014,7 +1014,7 @@ static int nu_int_i2c_addr2data(int address, int read)
return read ? ((address << 1) | 1) : (address << 1);
}

#ifdef CONFIG_I2C_SLAVE
#ifdef CONFIG_I2C_TARGET
static int nu_int_i2c_addr2bspaddr(int address)
{
return address;
Expand Down
42 changes: 21 additions & 21 deletions drivers/usb/device/usb_dc_numaker.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,14 @@ struct nu_usb_dc_ep {
uint32_t usbd_hw_ep_cfg; // Saved for easy control with BSP driver
#endif

bool FIFO_need_own; // For USBD, FIFO cannot access simultaneously by CPU and H/W, and needs ownership management
bool fifo_need_own; // For USBD, FIFO cannot access simultaneously by CPU and H/W, and needs ownership management

usb_dc_ep_callback cb; // Endpoint callback function

uint32_t zero_end; // Mark the end of fields which can initialize to zero

bool FIFO_own_sem_valid; // FIFO ownership semaphore valid
struct k_sem FIFO_own_sem; // FIFO ownership semaphore
bool fifo_own_sem_valid; // FIFO ownership semaphore valid
struct k_sem fifo_own_sem; // FIFO ownership semaphore
};

/* Endpoint management context */
Expand Down Expand Up @@ -695,8 +695,8 @@ int usb_dc_ep_write(const uint8_t ep_addr, const uint8_t *const data_buf,
}

/* Try to acquire EP DMA buffer ownership on behalf of H/W */
if (ep_cur->FIFO_need_own) {
rc = k_sem_take(&ep_cur->FIFO_own_sem, K_NO_WAIT);
if (ep_cur->fifo_need_own) {
rc = k_sem_take(&ep_cur->fifo_own_sem, K_NO_WAIT);
if (rc < 0) {
LOG_WRN("ep_addr 0x%02x busy", ep_addr);
rc = -EAGAIN;
Expand Down Expand Up @@ -824,8 +824,8 @@ int usb_dc_ep_read_wait(uint8_t ep_addr, uint8_t *data_buf, uint32_t max_data_le
}

/* We cannot read on FIFO being owned by H/W */
if (ep_cur->FIFO_need_own) {
if (!k_sem_count_get(&ep_cur->FIFO_own_sem)) {
if (ep_cur->fifo_need_own) {
if (!k_sem_count_get(&ep_cur->fifo_own_sem)) {
LOG_WRN("ep_addr 0x%02x busy", ep_addr);
rc = -EAGAIN;
goto cleanup;
Expand Down Expand Up @@ -891,8 +891,8 @@ int usb_dc_ep_read_continue(uint8_t ep_addr)
}

/* Try to acquire EP FIFO ownership on behalf of H/W */
if (ep_cur->FIFO_need_own) {
rc = k_sem_take(&ep_cur->FIFO_own_sem, K_NO_WAIT);
if (ep_cur->fifo_need_own) {
rc = k_sem_take(&ep_cur->fifo_own_sem, K_NO_WAIT);
if (rc < 0) {
LOG_DBG("ep_addr 0x%02x has triggered", ep_addr);
rc = 0;
Expand Down Expand Up @@ -1602,15 +1602,15 @@ static void nu_usb_dc_ep_mgmt_init(struct usb_dc_numaker_device *dev)

/* FIFO needs ownership or not */
#if DT_HAS_COMPAT_STATUS_OKAY(nuvoton_numaker_usbd) && defined(CONFIG_USB_DC_NUMAKER_USBD)
ep_cur->FIFO_need_own = true;
ep_cur->fifo_need_own = true;
#endif

/* Initialize FIFO ownership semaphore if not yet, and signal H/W doesn't own it */
if (!ep_cur->FIFO_own_sem_valid) {
k_sem_init(&ep_cur->FIFO_own_sem, 1, 1);
ep_cur->FIFO_own_sem_valid = true;
if (!ep_cur->fifo_own_sem_valid) {
k_sem_init(&ep_cur->fifo_own_sem, 1, 1);
ep_cur->fifo_own_sem_valid = true;
} else {
k_sem_give(&ep_cur->FIFO_own_sem);
k_sem_give(&ep_cur->fifo_own_sem);
}
}

Expand Down Expand Up @@ -1821,8 +1821,8 @@ static void nu_usb_dc_ep_bh(struct nu_usb_dc_ep *ep_cur, enum usb_dc_ep_cb_statu
nu_usb_dc_ep_fifo_update(ep_cur);

/* Relinquish EP FIFO ownership on behalf of H/W */
if (ep_cur->FIFO_need_own) {
k_sem_give(&ep_cur->FIFO_own_sem);
if (ep_cur->fifo_need_own) {
k_sem_give(&ep_cur->fifo_own_sem);
}
} else if (status_code == USB_DC_EP_DATA_IN) {
__ASSERT_NO_MSG(USB_EP_DIR_IS_IN(ep_cur->ep_addr));
Expand All @@ -1831,8 +1831,8 @@ static void nu_usb_dc_ep_bh(struct nu_usb_dc_ep *ep_cur, enum usb_dc_ep_cb_statu
nu_usb_dc_ep_fifo_update(ep_cur);

/* Relinquish EP FIFO ownership on behalf of H/W */
if (ep_cur->FIFO_need_own) {
k_sem_give(&ep_cur->FIFO_own_sem);
if (ep_cur->fifo_need_own) {
k_sem_give(&ep_cur->fifo_own_sem);
}
}
}
Expand Down Expand Up @@ -2180,9 +2180,9 @@ static void nu_usb_dc_ep_abort(struct nu_usb_dc_ep *ep_cur)
#endif

/* Relinquish EP FIFO ownership on behalf of H/W */
if (ep_cur->FIFO_need_own) {
if (ep_cur->FIFO_own_sem_valid) {
k_sem_give(&ep_cur->FIFO_own_sem);
if (ep_cur->fifo_need_own) {
if (ep_cur->fifo_own_sem_valid) {
k_sem_give(&ep_cur->fifo_own_sem);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
CONFIG_I2C=y
CONFIG_I2C_SLAVE=y
CONFIG_I2C_TARGET=y
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
eeprom0: eeprom@54 {
compatible = "atmel,at24";
reg = <0x54>;
label = "EEPROM_0";
size = <1024>;
pagesize = <16>;
address-width = <8>;
Expand All @@ -36,7 +35,6 @@
eeprom1: eeprom@56 {
compatible = "atmel,at24";
reg = <0x56>;
label = "EEPROM_1";
size = <1024>;
pagesize = <16>;
address-width = <8>;
Expand Down

0 comments on commit 37ce081

Please sign in to comment.