USB Serial application

Fork of USBSerial_HelloWorld by Samuel Mokrani

Committer:
Zaitsev
Date:
Sat Dec 16 10:26:48 2017 +0000
Revision:
11:b3f2a8bdac4d
Parent:
10:41552d038a69
A copy for D.S;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Zaitsev 10:41552d038a69 1 /**
Zaitsev 10:41552d038a69 2 *******************************************************************************
Zaitsev 10:41552d038a69 3 * @file sleep.c
Zaitsev 10:41552d038a69 4 * @brief Implementation of an sleep functionality
Zaitsev 10:41552d038a69 5 * @internal
Zaitsev 10:41552d038a69 6 * @author ON Semiconductor
Zaitsev 10:41552d038a69 7 * $Rev: 0.1 $
Zaitsev 10:41552d038a69 8 * $Date: 01-21-2016 $
Zaitsev 10:41552d038a69 9 ******************************************************************************
Zaitsev 10:41552d038a69 10 * Copyright 2016 Semiconductor Components Industries LLC (d/b/a “ON Semiconductor”).
Zaitsev 10:41552d038a69 11 * All rights reserved. This software and/or documentation is licensed by ON Semiconductor
Zaitsev 10:41552d038a69 12 * under limited terms and conditions. The terms and conditions pertaining to the software
Zaitsev 10:41552d038a69 13 * and/or documentation are available at http://www.onsemi.com/site/pdf/ONSEMI_T&C.pdf
Zaitsev 10:41552d038a69 14 * (“ON Semiconductor Standard Terms and Conditions of Sale, Section 8 Software”) and
Zaitsev 10:41552d038a69 15 * if applicable the software license agreement. Do not use this software and/or
Zaitsev 10:41552d038a69 16 * documentation unless you have carefully read and you agree to the limited terms and
Zaitsev 10:41552d038a69 17 * conditions. By using this software and/or documentation, you agree to the limited
Zaitsev 10:41552d038a69 18 * terms and conditions.
Zaitsev 10:41552d038a69 19 *
Zaitsev 10:41552d038a69 20 * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
Zaitsev 10:41552d038a69 21 * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
Zaitsev 10:41552d038a69 22 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
Zaitsev 10:41552d038a69 23 * ON SEMICONDUCTOR SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL,
Zaitsev 10:41552d038a69 24 * INCIDENTAL, OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
Zaitsev 10:41552d038a69 25 * @endinternal
Zaitsev 10:41552d038a69 26 *
Zaitsev 10:41552d038a69 27 * @ingroup sleep
Zaitsev 10:41552d038a69 28 *
Zaitsev 10:41552d038a69 29 * @details
Zaitsev 10:41552d038a69 30 * Sleep implementation
Zaitsev 10:41552d038a69 31 *
Zaitsev 10:41552d038a69 32 */
Zaitsev 10:41552d038a69 33 #if DEVICE_SLEEP
Zaitsev 10:41552d038a69 34 #include "sleep.h"
Zaitsev 10:41552d038a69 35 #include "sleep_api.h"
Zaitsev 10:41552d038a69 36 #include "cmsis_nvic.h"
Zaitsev 10:41552d038a69 37
Zaitsev 10:41552d038a69 38 #define ENABLE (uint8_t)0x01
Zaitsev 10:41552d038a69 39 #define DISABLE (uint8_t)0x00
Zaitsev 10:41552d038a69 40 #define MAC_LUT_SIZE (uint8_t)96
Zaitsev 10:41552d038a69 41
Zaitsev 10:41552d038a69 42 #define portNVIC_SYSTICK_CTRL_REG ( * ( ( volatile unsigned long * ) 0xe000e010 ) )
Zaitsev 10:41552d038a69 43 #define portNVIC_SYSTICK_CLK_BIT ( 1UL << 2UL )
Zaitsev 10:41552d038a69 44 #define portNVIC_SYSTICK_INT_BIT ( 1UL << 1UL )
Zaitsev 10:41552d038a69 45 #define portNVIC_SYSTICK_ENABLE_BIT ( 1UL << 0UL )
Zaitsev 10:41552d038a69 46
Zaitsev 10:41552d038a69 47 void fncs36510_sleep(void)
Zaitsev 10:41552d038a69 48 {
Zaitsev 10:41552d038a69 49 /** Unset SLEEPDEEP (SCR) and COMA to select sleep mode */
Zaitsev 10:41552d038a69 50 SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk;
Zaitsev 10:41552d038a69 51 PMUREG->CONTROL.BITS.ENCOMA = DISABLE;
Zaitsev 10:41552d038a69 52
Zaitsev 10:41552d038a69 53 /* Enter into sleep mode */
Zaitsev 10:41552d038a69 54 __ISB();
Zaitsev 10:41552d038a69 55 __WFI();
Zaitsev 10:41552d038a69 56 }
Zaitsev 10:41552d038a69 57
Zaitsev 10:41552d038a69 58 void fncs36510_deepsleep(void)
Zaitsev 10:41552d038a69 59 {
Zaitsev 10:41552d038a69 60 /** Set SLEEPDEEP (SCR) and unset COMA to select deep sleep mode */
Zaitsev 10:41552d038a69 61 SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
Zaitsev 10:41552d038a69 62 PMUREG->CONTROL.BITS.ENCOMA = DISABLE;
Zaitsev 10:41552d038a69 63
Zaitsev 10:41552d038a69 64 /** Enter into deep sleep mode */
Zaitsev 10:41552d038a69 65 __ISB();
Zaitsev 10:41552d038a69 66 __WFI();
Zaitsev 10:41552d038a69 67
Zaitsev 10:41552d038a69 68 /** Wait for the external 32MHz to be power-ed up & running
Zaitsev 10:41552d038a69 69 * Re-power down the 32MHz internal osc
Zaitsev 10:41552d038a69 70 */
Zaitsev 10:41552d038a69 71 while (!CLOCKREG->CSR.BITS.XTAL32M);
Zaitsev 10:41552d038a69 72 PMUREG->CONTROL.BITS.INT32M = 1;
Zaitsev 10:41552d038a69 73 }
Zaitsev 10:41552d038a69 74
Zaitsev 10:41552d038a69 75 void fncs36510_coma(void)
Zaitsev 10:41552d038a69 76 {
Zaitsev 10:41552d038a69 77 /** Set SLEEPDEEP (SCR) and set COMA to select coma mode */
Zaitsev 10:41552d038a69 78 SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
Zaitsev 10:41552d038a69 79 PMUREG->CONTROL.BITS.ENCOMA = ENABLE;
Zaitsev 10:41552d038a69 80
Zaitsev 10:41552d038a69 81 /* TODO Wait till MAC is idle */
Zaitsev 10:41552d038a69 82 // while((MACHWREG->SEQUENCER == MACHW_SEQ_TX) || (MACHWREG->SEQUENCER == MACHW_SEQ_ED) || (MACHWREG->SEQUENCER == MACHW_SEQ_CCA));
Zaitsev 10:41552d038a69 83
Zaitsev 10:41552d038a69 84 /* TODO Back up MAC_LUT *
Zaitsev 10:41552d038a69 85 uint8_t MAC_LUT_BackUp[MAC_LUT_SIZE];
Zaitsev 10:41552d038a69 86 fMacBackupFrameStoreLUT(MAC_LUT_BackUp); */
Zaitsev 10:41552d038a69 87
Zaitsev 10:41552d038a69 88 /* Disable UART 1 & 2 FIFO during coma*/
Zaitsev 10:41552d038a69 89 UART1REG->FCR.WORD &= ~(FCR_FIFO_ENABLE);
Zaitsev 10:41552d038a69 90 UART2REG->FCR.WORD &= ~(FCR_FIFO_ENABLE);
Zaitsev 10:41552d038a69 91
Zaitsev 10:41552d038a69 92 /** Enter into coma mode */
Zaitsev 10:41552d038a69 93 __ISB();
Zaitsev 10:41552d038a69 94 __WFI();
Zaitsev 10:41552d038a69 95
Zaitsev 10:41552d038a69 96 /** Wait for the external 32MHz to be power-ed up & running
Zaitsev 10:41552d038a69 97 * Re-power down the 32MHz internal osc
Zaitsev 10:41552d038a69 98 */
Zaitsev 10:41552d038a69 99 while (!CLOCKREG->CSR.BITS.XTAL32M);
Zaitsev 10:41552d038a69 100 PMUREG->CONTROL.BITS.INT32M = 1;
Zaitsev 10:41552d038a69 101
Zaitsev 10:41552d038a69 102 /** Trim the oscillators */
Zaitsev 10:41552d038a69 103 if ((TRIMREG->TRIM_32K_EXT & 0xFFFF0000) != 0xFFFF0000) {
Zaitsev 10:41552d038a69 104 CLOCKREG->TRIM_32K_EXT.WORD = TRIMREG->TRIM_32K_EXT;
Zaitsev 10:41552d038a69 105 }
Zaitsev 10:41552d038a69 106 if ((TRIMREG->TRIM_32M_EXT & 0xFFFF0000) != 0xFFFF0000) {
Zaitsev 10:41552d038a69 107 CLOCKREG->TRIM_32M_EXT.WORD = TRIMREG->TRIM_32M_EXT;
Zaitsev 10:41552d038a69 108 }
Zaitsev 10:41552d038a69 109
Zaitsev 10:41552d038a69 110 /* Enable UART 1 & 2 FIFO */
Zaitsev 10:41552d038a69 111 UART1REG->FCR.WORD |= FCR_FIFO_ENABLE;
Zaitsev 10:41552d038a69 112 UART2REG->FCR.WORD |= FCR_FIFO_ENABLE;
Zaitsev 10:41552d038a69 113
Zaitsev 10:41552d038a69 114 /* TODO Restore MAC_LUT *
Zaitsev 10:41552d038a69 115 fMacRestoreFrameStoreLUT(MAC_LUT_BackUp); */
Zaitsev 10:41552d038a69 116 }
Zaitsev 10:41552d038a69 117
Zaitsev 10:41552d038a69 118 #endif /* DEVICE_SLEEP */