Skip to content

Commit

Permalink
Update Zephyr MSDK Hal based on MSDK PR: analogdevicesinc/msdk#1109
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user authored and ozersa committed Sep 11, 2024
1 parent e24fafd commit 1854aaf
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 11 deletions.
22 changes: 22 additions & 0 deletions MAX/Libraries/PeriphDrivers/Include/MAX32665/dma.h
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,28 @@ int MXC_DMA_Stop(int ch);
*/
mxc_dma_ch_regs_t *MXC_DMA_GetCHRegs(int ch);

typedef void (*dma_handler_t)(void);
/**
* @brief Get the appropriate "hard" DMA handler for the specified DMA instance.
* @ref MXC_DMA_DMA0_Handler or @ref MXC_DMA_DMA1_Handler.
* Mostly used by internal drivers.
*/
dma_handler_t MXC_DMA_Get_DMA_Handler(mxc_dma_regs_t *dma);

/**
* @brief Interrupt handler function for DMA0
* @details Used by some internal drivers that automatically assign DMA handlers.
* This is equivalent to "MXC_DMA_Handler(MXC_DMA0);"
*/
void MXC_DMA_DMA0_Handler(void);

/**
* @brief Interrupt handler function for DMA0
* @details Used by some internal drivers that automatically assign DMA handlers.
* This is equivalent to "MXC_DMA_Handler(MXC_DMA1);"
*/
void MXC_DMA_DMA1_Handler(void);

/**
* @brief Interrupt handler function
* @param dma Pointer to DMA registers.
Expand Down
20 changes: 20 additions & 0 deletions MAX/Libraries/PeriphDrivers/Source/DMA/dma_me14.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,26 @@ mxc_dma_ch_regs_t *MXC_DMA_GetCHRegs(int ch)
return MXC_DMA_RevA_GetCHRegs(ch);
}

dma_handler_t MXC_DMA_Get_DMA_Handler(mxc_dma_regs_t *dma)
{
if (dma == MXC_DMA0)
return MXC_DMA_DMA0_Handler;
else if (dma == MXC_DMA1)
return MXC_DMA_DMA1_Handler;
else
return NULL;
}

void MXC_DMA_DMA0_Handler(void)
{
MXC_DMA_RevA_Handler((mxc_dma_reva_regs_t *)MXC_DMA0);
}

void MXC_DMA_DMA1_Handler(void)
{
MXC_DMA_RevA_Handler((mxc_dma_reva_regs_t *)MXC_DMA1);
}

void MXC_DMA_Handler(mxc_dma_regs_t *dma)
{
if (MXC_DMA_GET_IDX(dma) != -1) {
Expand Down
53 changes: 43 additions & 10 deletions MAX/Libraries/PeriphDrivers/Source/I2C/i2c_reva.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "i2c_reva.h"
#include "dma.h"
#include "dma_reva.h"
#include "nvic_table.h"

/* **** Variable Declaration **** */
typedef struct {
Expand Down Expand Up @@ -297,8 +298,8 @@ int MXC_I2C_RevA_DMA_Init(mxc_i2c_reva_regs_t *i2c, mxc_dma_reva_regs_t *dma, bo
bool use_dma_rx)
{
int8_t i2cNum;
int8_t rxChannel;
int8_t txChannel;
int8_t rxChannel = -1;
int8_t txChannel = -1;

if (i2c == NULL || dma == NULL) {
return E_NULL_PTR;
Expand Down Expand Up @@ -354,6 +355,15 @@ int MXC_I2C_RevA_DMA_Init(mxc_i2c_reva_regs_t *i2c, mxc_dma_reva_regs_t *dma, bo
MXC_DMA_SetChannelInterruptEn(txChannel, 0, 1);

states[i2cNum].channelTx = txChannel;
#ifdef __arm__
NVIC_EnableIRQ(MXC_DMA_CH_GET_IRQ(txChannel));
#if TARGET_NUM == 32665
MXC_NVIC_SetVector(MXC_DMA_CH_GET_IRQ(txChannel),
MXC_DMA_Get_DMA_Handler((mxc_dma_regs_t *)dma));
#else
MXC_NVIC_SetVector(MXC_DMA_CH_GET_IRQ(txChannel), MXC_DMA_Handler);
#endif
#endif
}

// Set up I2C DMA RX.
Expand Down Expand Up @@ -384,6 +394,15 @@ int MXC_I2C_RevA_DMA_Init(mxc_i2c_reva_regs_t *i2c, mxc_dma_reva_regs_t *dma, bo

MXC_DMA_EnableInt(rxChannel);
MXC_DMA_SetChannelInterruptEn(rxChannel, 0, 1);
#ifdef __arm__
NVIC_EnableIRQ(MXC_DMA_CH_GET_IRQ(rxChannel));
#if TARGET_NUM == 32665
MXC_NVIC_SetVector(MXC_DMA_CH_GET_IRQ(txChannel),
MXC_DMA_Get_DMA_Handler((mxc_dma_regs_t *)dma));
#else
MXC_NVIC_SetVector(MXC_DMA_CH_GET_IRQ(txChannel), MXC_DMA_Handler);
#endif
#endif

states[i2cNum].channelRx = rxChannel;
}
Expand Down Expand Up @@ -1082,8 +1101,8 @@ int MXC_I2C_RevA_MasterTransactionDMA(mxc_i2c_reva_req_t *req, mxc_dma_regs_t *d
MXC_I2C_SetRXThreshold((mxc_i2c_regs_t *)i2c, 1);

states[i2cNum].req = req;
states[i2cNum].writeDone = 0;
states[i2cNum].readDone = 0;
states[i2cNum].writeDone = (req->tx_len == 0);
states[i2cNum].readDone = (req->rx_len == 0);

// If MXC_I2C_DMA_Init(...) was not already called, then configure both DMA TX/RXchannels by default.
if (states[i2cNum].dma_initialized == false) {
Expand Down Expand Up @@ -1122,17 +1141,31 @@ int MXC_I2C_RevA_MasterTransactionDMA(mxc_i2c_reva_req_t *req, mxc_dma_regs_t *d
i2c->rxctrl1 = req->rx_len; // 0 for 256, otherwise number of bytes to read
}

MXC_I2C_Start((mxc_i2c_regs_t *)i2c); // Start or Restart as needed

while (i2c->mstctrl & MXC_F_I2C_REVA_MSTCTRL_RESTART) {}

i2c->fifo = ((req->addr) << 1) | 0x1; // Load the slave address with write bit set

#if TARGET_NUM == 32665
MXC_I2C_ReadRXFIFODMA((mxc_i2c_regs_t *)i2c, req->rx_buf, req->rx_len, NULL, dma);
#else
MXC_I2C_ReadRXFIFODMA((mxc_i2c_regs_t *)i2c, req->rx_buf, req->rx_len, NULL);
#endif

MXC_I2C_Start((mxc_i2c_regs_t *)i2c); // Start or Restart as needed

while (i2c->mstctrl & MXC_F_I2C_REVA_MSTCTRL_RESTART) {}

i2c->fifo = ((req->addr) << 1) | 0x1; // Load the slave address with write bit set
while (!((i2c->intfl0 & MXC_F_I2C_REVA_INTFL0_ADDR_ACK) ||
(i2c->intfl0 & MXC_F_I2C_REVA_INTFL0_ADDR_NACK_ERR))) {
// Wait for an ACK or NACK from the slave
}
if (!(i2c->intfl0 & MXC_F_I2C_REVA_INTFL0_ADDR_ACK)) {
// If we did not get an ACK, then something went wrong.
// Abort the transaction and signal the user's callback
MXC_I2C_RevA_Stop(i2c);
MXC_DMA_Stop(states[i2cNum].channelRx);
if (states[i2cNum].req->callback != NULL) {
states[i2cNum].req->callback(states[i2cNum].req, E_COMM_ERR);
}
return E_COMM_ERR;
}
}
} else {
states[i2cNum].readDone = 1;
Expand Down
2 changes: 1 addition & 1 deletion MAX/msdk_sha
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6b6f2c3e372b48a197727c62b68df2e9fb9955c9
4e410385fd91984636606afd801858fbe1a480b6

0 comments on commit 1854aaf

Please sign in to comment.