Skip to content

Commit

Permalink
MCUXpresso: Update the SDK LPUART drivers
Browse files Browse the repository at this point in the history
Use the latest driver from K66F

Signed-off-by: Mahesh Mahadevan <mahesh.mahadevan@nxp.com>
  • Loading branch information
mmahadevan108 committed Aug 22, 2019
1 parent bff2875 commit a184a86
Show file tree
Hide file tree
Showing 12 changed files with 786 additions and 396 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2015, Freescale Semiconductor, Inc.
* All rights reserved.
* Copyright (c) 2015-2016, Freescale Semiconductor, Inc.
* Copyright 2016-2017 NXP
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
Expand All @@ -12,7 +12,7 @@
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
* o Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
Expand Down Expand Up @@ -115,8 +115,17 @@ static const IRQn_Type s_lpuartTxIRQ[] = LPUART_TX_IRQS;
#else
static const IRQn_Type s_lpuartIRQ[] = LPUART_RX_TX_IRQS;
#endif
#if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
/* Array of LPUART clock name. */
static const clock_ip_name_t s_lpuartClock[] = LPUART_CLOCKS;

#if defined(LPUART_PERIPH_CLOCKS)
/* Array of LPUART functional clock name. */
static const clock_ip_name_t s_lpuartPeriphClocks[] = LPUART_PERIPH_CLOCKS;
#endif

#endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */

/* LPUART ISR for transactional APIs. */
static lpuart_isr_t s_lpuartIsr;

Expand All @@ -128,15 +137,15 @@ uint32_t LPUART_GetInstance(LPUART_Type *base)
uint32_t instance;

/* Find the instance index from base address mappings. */
for (instance = 0; instance < FSL_FEATURE_SOC_LPUART_COUNT; instance++)
for (instance = 0; instance < ARRAY_SIZE(s_lpuartBases); instance++)
{
if (s_lpuartBases[instance] == base)
{
break;
}
}

assert(instance < FSL_FEATURE_SOC_LPUART_COUNT);
assert(instance < ARRAY_SIZE(s_lpuartBases));

return instance;
}
Expand Down Expand Up @@ -280,11 +289,25 @@ status_t LPUART_Init(LPUART_Type *base, const lpuart_config_t *config, uint32_t
return kStatus_LPUART_BaudrateNotSupport;
}

#if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)

uint32_t instance = LPUART_GetInstance(base);

/* Enable lpuart clock */
CLOCK_EnableClock(s_lpuartClock[LPUART_GetInstance(base)]);
CLOCK_EnableClock(s_lpuartClock[instance]);
#if defined(LPUART_PERIPH_CLOCKS)
CLOCK_EnableClock(s_lpuartPeriphClocks[instance]);
#endif

#endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */

#if defined(FSL_FEATURE_LPUART_HAS_GLOBAL) && FSL_FEATURE_LPUART_HAS_GLOBAL
/*Reset all internal logic and registers, except the Global Register */
LPUART_SoftwareReset(base);
#else
/* Disable LPUART TX RX before setting. */
base->CTRL &= ~(LPUART_CTRL_TE_MASK | LPUART_CTRL_RE_MASK);
#endif

temp = base->BAUD;

Expand Down Expand Up @@ -422,8 +445,17 @@ void LPUART_Deinit(LPUART_Type *base)
/* Disable the module. */
base->CTRL = 0;

#if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
uint32_t instance = LPUART_GetInstance(base);

/* Disable lpuart clock */
CLOCK_DisableClock(s_lpuartClock[LPUART_GetInstance(base)]);
CLOCK_DisableClock(s_lpuartClock[instance]);

#if defined(LPUART_PERIPH_CLOCKS)
CLOCK_DisableClock(s_lpuartPeriphClocks[instance]);
#endif

#endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
}

void LPUART_GetDefaultConfig(lpuart_config_t *config)
Expand Down Expand Up @@ -861,7 +893,6 @@ status_t LPUART_TransferReceiveNonBlocking(LPUART_Type *base,
size_t bytesToReceive;
/* How many bytes currently have received. */
size_t bytesCurrentReceived;
uint32_t regPrimask = 0U;

/* How to get data:
1. If RX ring buffer is not enabled, then save xfer->data and xfer->dataSize
Expand All @@ -885,8 +916,8 @@ status_t LPUART_TransferReceiveNonBlocking(LPUART_Type *base,
/* If RX ring buffer is used. */
if (handle->rxRingBuffer)
{
/* Disable IRQ, protect ring buffer. */
regPrimask = DisableGlobalIRQ();
/* Disable LPUART RX IRQ, protect ring buffer. */
LPUART_DisableInterrupts(base, kLPUART_RxDataRegFullInterruptEnable);

/* How many bytes in RX ring buffer currently. */
bytesToCopy = LPUART_TransferGetRxRingBufferLength(base, handle);
Expand Down Expand Up @@ -923,8 +954,8 @@ status_t LPUART_TransferReceiveNonBlocking(LPUART_Type *base,
handle->rxDataSizeAll = bytesToReceive;
handle->rxState = kLPUART_RxBusy;
}
/* Enable IRQ if previously enabled. */
EnableGlobalIRQ(regPrimask);
/* Enable LPUART RX IRQ if previously enabled. */
LPUART_EnableInterrupts(base, kLPUART_RxDataRegFullInterruptEnable);

/* Call user callback since all data are received. */
if (0 == bytesToReceive)
Expand Down
Loading

0 comments on commit a184a86

Please sign in to comment.