Skip to content

Commit

Permalink
Update Zephyr MSDK Hal based on MSDK PR: analogdevicesinc/msdk#1285
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Dec 17, 2024
1 parent a994cd1 commit 934fb9a
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 9 deletions.
77 changes: 77 additions & 0 deletions MAX/Libraries/CMSIS/Device/Maxim/MAX32657/Source/heap.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <stdint.h>
#include <errno.h>
#include <unistd.h>
#include <malloc.h>

/*
sbrk
Expand Down Expand Up @@ -48,3 +49,79 @@ caddr_t _sbrk(int incr)

return (caddr_t)prev_heap_end;
}

// struct mallinfo {
// size_t arena; /* total space allocated from system */
// size_t ordblks; /* number of non-inuse chunks */
// size_t smblks; /* unused -- always zero */
// size_t hblks; /* number of mmapped regions */
// size_t hblkhd; /* total space in mmapped regions */
// size_t usmblks; /* unused -- always zero */
// size_t fsmblks; /* unused -- always zero */
// size_t uordblks; /* total allocated space */
// size_t fordblks; /* total non-inuse space */
// size_t keepcost; /* top-most, releasable (via malloc_trim) space */
// };

/*
The structure fields contain the following information:
arena The total amount of memory allocated by means other than
mmap(2) (i.e., memory allocated on the heap). This figure
includes both in-use blocks and blocks on the free list.
ordblks
The number of ordinary (i.e., non-fastbin) free blocks.
smblks The number of fastbin free blocks (see mallopt(3)).
hblks The number of blocks currently allocated using mmap(2).
(See the discussion of M_MMAP_THRESHOLD in mallopt(3).)
hblkhd The number of bytes in blocks currently allocated using
mmap(2).
usmblks
This field is unused, and is always 0. Historically, it
was the "highwater mark" for allocated space—that is, the
maximum amount of space that was ever allocated (in
bytes); this field was maintained only in nonthreading
environments.
fsmblks
The total number of bytes in fastbin free blocks.
uordblks
The total number of bytes used by in-use allocations.
fordblks
The total number of bytes in free blocks.
keepcost
The total amount of releasable free space at the top of
the heap. This is the maximum number of bytes that could
ideally (i.e., ignoring page alignment restrictions, and
so on) be released by malloc_trim(3).
*/

struct mallinfo mallinfo(void)
{
struct mallinfo temp_mallinfo;

if (heap_end == 0) {
heap_end = (caddr_t)&__HeapBase;
}

temp_mallinfo.arena = ((size_t)&__HeapLimit - (size_t)&__HeapBase);
temp_mallinfo.ordblks = 0; /* Unused */
temp_mallinfo.smblks = 0; /* Unused */
temp_mallinfo.hblks = 0; /* Unused */
temp_mallinfo.hblkhd = 0; /* Unused */
temp_mallinfo.usmblks = 0; /* Unused */
temp_mallinfo.fsmblks = 0; /* Unused */
temp_mallinfo.uordblks = (size_t)heap_end - (size_t)&__HeapBase;
temp_mallinfo.fordblks = (size_t)&__HeapLimit - (size_t)heap_end;
temp_mallinfo.keepcost = 0 /* Unused */;

return temp_mallinfo;
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "system_max32657.h"
#include "gcr_regs.h"
#include "mpc.h"
#include "icc.h"

#if defined(__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
#include "partition_max32657.h"
Expand Down Expand Up @@ -130,6 +131,9 @@ __weak int Board_Init(void)
return 0;
}

/* This function is used for the Bluetooth stack initialization */
__weak void PalSysInit(void) {}

/**
* This function is called just before control is transferred to main().
*
Expand Down Expand Up @@ -171,8 +175,8 @@ __weak void SystemInit(void)
/* Enable interrupts */
__enable_irq();

// TODO(ICC): Enable the internal cache controller after testing.
// MXC_ICC_Enable();
// Enable the internal cache controller.
MXC_ICC_Enable();

/* Change system clock source to the main high-speed clock */
MXC_SYS_Clock_Select(MXC_SYS_CLOCK_IPO);
Expand All @@ -181,6 +185,8 @@ __weak void SystemInit(void)

PinInit();
Board_Init();

PalSysInit();
}

#if defined(__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
Expand Down
16 changes: 15 additions & 1 deletion MAX/Libraries/PeriphDrivers/Source/UART/uart_me30.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ int MXC_UART_Init(mxc_uart_regs_t *uart, unsigned int baud, mxc_uart_clock_t clo
}
#endif // MSDK_NO_GPIO_CLK_INIT

retval = MXC_UART_SetClockSource(uart, clock);
if (retval != E_NO_ERROR) {
return retval;
}

return MXC_UART_RevB_Init((mxc_uart_revb_regs_t *)uart, baud, clock);
}

Expand Down Expand Up @@ -173,7 +178,16 @@ int MXC_UART_SetFlowCtrl(mxc_uart_regs_t *uart, mxc_uart_flow_t flowCtrl, int rt

int MXC_UART_SetClockSource(mxc_uart_regs_t *uart, mxc_uart_clock_t clock)
{
return MXC_UART_RevB_SetClockSource((mxc_uart_revb_regs_t *)uart, clock);
switch (clock) {
case MXC_UART_APB_CLK:
return MXC_UART_RevB_SetClockSource((mxc_uart_revb_regs_t *)uart, 0);

case MXC_UART_IBRO_CLK:
return MXC_UART_RevB_SetClockSource((mxc_uart_revb_regs_t *)uart, 1);

default:
return E_BAD_PARAM;
}
}

int MXC_UART_GetActive(mxc_uart_regs_t *uart)
Expand Down
14 changes: 9 additions & 5 deletions MAX/Libraries/PeriphDrivers/Source/UART/uart_revb.c
Original file line number Diff line number Diff line change
Expand Up @@ -636,15 +636,16 @@ int MXC_UART_RevB_Transaction(mxc_uart_revb_req_t *req)

while (req->txCnt < req->txLen) {
while (!(MXC_UART_GetFlags((mxc_uart_regs_t *)(req->uart)) &
MXC_F_UART_REVB_INT_FL_TX_HE) &&
(MXC_F_UART_REVB_INT_FL_TX_HE | MXC_F_UART_REVB_INT_FL_TX_OB)) &&
!(req->uart->status & MXC_F_UART_REVB_STATUS_TX_EM)) {}

numToWrite = MXC_UART_GetTXFIFOAvailable((mxc_uart_regs_t *)(req->uart));
numToWrite = numToWrite > (req->txLen - req->txCnt) ? req->txLen - req->txCnt :
numToWrite;
req->txCnt += MXC_UART_WriteTXFIFO((mxc_uart_regs_t *)(req->uart),
&req->txData[req->txCnt], numToWrite);
MXC_UART_ClearFlags((mxc_uart_regs_t *)(req->uart), MXC_F_UART_REVB_INT_FL_TX_HE);
MXC_UART_ClearFlags((mxc_uart_regs_t *)(req->uart),
(MXC_F_UART_REVB_INT_FL_TX_HE | MXC_F_UART_REVB_INT_FL_TX_OB));
}
}

Expand Down Expand Up @@ -709,7 +710,8 @@ int MXC_UART_RevB_TransactionAsync(mxc_uart_revb_req_t *req)
NVIC_SetPendingIRQ(MXC_UART_GET_IRQ(uart_num));
} else {
/* Else enable the half empty interrupt */
MXC_UART_EnableInt((mxc_uart_regs_t *)(req->uart), MXC_F_UART_REVB_INT_EN_TX_HE);
MXC_UART_EnableInt((mxc_uart_regs_t *)(req->uart),
(MXC_F_UART_REVB_INT_EN_TX_HE | MXC_F_UART_REVB_INT_EN_TX_OB));
}
}

Expand Down Expand Up @@ -783,7 +785,8 @@ int MXC_UART_RevB_AsyncCallback(mxc_uart_revb_regs_t *uart, int retVal)

int MXC_UART_RevB_AsyncStopTx(mxc_uart_revb_regs_t *uart)
{
MXC_UART_DisableInt((mxc_uart_regs_t *)uart, MXC_F_UART_REVB_INT_EN_TX_HE);
MXC_UART_DisableInt((mxc_uart_regs_t *)uart,
(MXC_F_UART_REVB_INT_EN_TX_HE | MXC_F_UART_REVB_INT_EN_TX_OB));

return E_NO_ERROR;
}
Expand Down Expand Up @@ -838,7 +841,8 @@ int MXC_UART_RevB_AsyncHandler(mxc_uart_revb_regs_t *uart)
numToWrite = MXC_UART_WriteTXFIFO((mxc_uart_regs_t *)(req->uart), &req->txData[req->txCnt],
numToWrite);
req->txCnt += numToWrite;
MXC_UART_ClearFlags(req->uart, MXC_F_UART_REVB_INT_FL_TX_HE);
MXC_UART_ClearFlags(req->uart,
(MXC_F_UART_REVB_INT_FL_TX_HE | MXC_F_UART_REVB_INT_FL_TX_OB));
}

req = (mxc_uart_req_t *)AsyncRxRequests[uart_num];
Expand Down
2 changes: 1 addition & 1 deletion MAX/msdk_sha
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1b95c3c0d3cedfa086518f2c628723007cac838d
6e61aa32b0dc0b7ef6e8476c039e2aacb792fc1c

0 comments on commit 934fb9a

Please sign in to comment.