1
1
/*
2
- * Copyright (c) 2015, Freescale Semiconductor, Inc.
3
- * All rights reserved.
2
+ * Copyright (c) 2015-2016 , Freescale Semiconductor, Inc.
3
+ * Copyright 2016-2017 NXP
4
4
*
5
5
* Redistribution and use in source and binary forms, with or without modification,
6
6
* are permitted provided that the following conditions are met:
12
12
* list of conditions and the following disclaimer in the documentation and/or
13
13
* other materials provided with the distribution.
14
14
*
15
- * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
15
+ * o Neither the name of the copyright holder nor the names of its
16
16
* contributors may be used to endorse or promote products derived from this
17
17
* software without specific prior written permission.
18
18
*
@@ -115,8 +115,17 @@ static const IRQn_Type s_lpuartTxIRQ[] = LPUART_TX_IRQS;
115
115
#else
116
116
static const IRQn_Type s_lpuartIRQ [] = LPUART_RX_TX_IRQS ;
117
117
#endif
118
+ #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL ) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL )
118
119
/* Array of LPUART clock name. */
119
120
static const clock_ip_name_t s_lpuartClock [] = LPUART_CLOCKS ;
121
+
122
+ #if defined(LPUART_PERIPH_CLOCKS )
123
+ /* Array of LPUART functional clock name. */
124
+ static const clock_ip_name_t s_lpuartPeriphClocks [] = LPUART_PERIPH_CLOCKS ;
125
+ #endif
126
+
127
+ #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
128
+
120
129
/* LPUART ISR for transactional APIs. */
121
130
static lpuart_isr_t s_lpuartIsr ;
122
131
@@ -128,15 +137,15 @@ uint32_t LPUART_GetInstance(LPUART_Type *base)
128
137
uint32_t instance ;
129
138
130
139
/* Find the instance index from base address mappings. */
131
- for (instance = 0 ; instance < FSL_FEATURE_SOC_LPUART_COUNT ; instance ++ )
140
+ for (instance = 0 ; instance < ARRAY_SIZE ( s_lpuartBases ) ; instance ++ )
132
141
{
133
142
if (s_lpuartBases [instance ] == base )
134
143
{
135
144
break ;
136
145
}
137
146
}
138
147
139
- assert (instance < FSL_FEATURE_SOC_LPUART_COUNT );
148
+ assert (instance < ARRAY_SIZE ( s_lpuartBases ) );
140
149
141
150
return instance ;
142
151
}
@@ -280,11 +289,25 @@ status_t LPUART_Init(LPUART_Type *base, const lpuart_config_t *config, uint32_t
280
289
return kStatus_LPUART_BaudrateNotSupport ;
281
290
}
282
291
292
+ #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL ) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL )
293
+
294
+ uint32_t instance = LPUART_GetInstance (base );
295
+
283
296
/* Enable lpuart clock */
284
- CLOCK_EnableClock (s_lpuartClock [LPUART_GetInstance (base )]);
297
+ CLOCK_EnableClock (s_lpuartClock [instance ]);
298
+ #if defined(LPUART_PERIPH_CLOCKS )
299
+ CLOCK_EnableClock (s_lpuartPeriphClocks [instance ]);
300
+ #endif
301
+
302
+ #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
285
303
304
+ #if defined(FSL_FEATURE_LPUART_HAS_GLOBAL ) && FSL_FEATURE_LPUART_HAS_GLOBAL
305
+ /*Reset all internal logic and registers, except the Global Register */
306
+ LPUART_SoftwareReset (base );
307
+ #else
286
308
/* Disable LPUART TX RX before setting. */
287
309
base -> CTRL &= ~(LPUART_CTRL_TE_MASK | LPUART_CTRL_RE_MASK );
310
+ #endif
288
311
289
312
temp = base -> BAUD ;
290
313
@@ -422,8 +445,17 @@ void LPUART_Deinit(LPUART_Type *base)
422
445
/* Disable the module. */
423
446
base -> CTRL = 0 ;
424
447
448
+ #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL ) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL )
449
+ uint32_t instance = LPUART_GetInstance (base );
450
+
425
451
/* Disable lpuart clock */
426
- CLOCK_DisableClock (s_lpuartClock [LPUART_GetInstance (base )]);
452
+ CLOCK_DisableClock (s_lpuartClock [instance ]);
453
+
454
+ #if defined(LPUART_PERIPH_CLOCKS )
455
+ CLOCK_DisableClock (s_lpuartPeriphClocks [instance ]);
456
+ #endif
457
+
458
+ #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
427
459
}
428
460
429
461
void LPUART_GetDefaultConfig (lpuart_config_t * config )
@@ -861,7 +893,6 @@ status_t LPUART_TransferReceiveNonBlocking(LPUART_Type *base,
861
893
size_t bytesToReceive ;
862
894
/* How many bytes currently have received. */
863
895
size_t bytesCurrentReceived ;
864
- uint32_t regPrimask = 0U ;
865
896
866
897
/* How to get data:
867
898
1. If RX ring buffer is not enabled, then save xfer->data and xfer->dataSize
@@ -885,8 +916,8 @@ status_t LPUART_TransferReceiveNonBlocking(LPUART_Type *base,
885
916
/* If RX ring buffer is used. */
886
917
if (handle -> rxRingBuffer )
887
918
{
888
- /* Disable IRQ, protect ring buffer. */
889
- regPrimask = DisableGlobalIRQ ( );
919
+ /* Disable LPUART RX IRQ, protect ring buffer. */
920
+ LPUART_DisableInterrupts ( base , kLPUART_RxDataRegFullInterruptEnable );
890
921
891
922
/* How many bytes in RX ring buffer currently. */
892
923
bytesToCopy = LPUART_TransferGetRxRingBufferLength (base , handle );
@@ -923,8 +954,8 @@ status_t LPUART_TransferReceiveNonBlocking(LPUART_Type *base,
923
954
handle -> rxDataSizeAll = bytesToReceive ;
924
955
handle -> rxState = kLPUART_RxBusy ;
925
956
}
926
- /* Enable IRQ if previously enabled. */
927
- EnableGlobalIRQ ( regPrimask );
957
+ /* Enable LPUART RX IRQ if previously enabled. */
958
+ LPUART_EnableInterrupts ( base , kLPUART_RxDataRegFullInterruptEnable );
928
959
929
960
/* Call user callback since all data are received. */
930
961
if (0 == bytesToReceive )
0 commit comments