Mouse code for the MacroRat
mbed-dev/targets/TARGET_Atmel/TARGET_SAM_CortexM4/drivers/pmc/sleep.h@46:b156ef445742, 2017-06-03 (annotated)
- Committer:
- sahilmgandhi
- Date:
- Sat Jun 03 00:22:44 2017 +0000
- Revision:
- 46:b156ef445742
- Parent:
- 18:6a4db94011d3
Final code for internal battlebot competition.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sahilmgandhi | 18:6a4db94011d3 | 1 | /** |
sahilmgandhi | 18:6a4db94011d3 | 2 | * \file |
sahilmgandhi | 18:6a4db94011d3 | 3 | * |
sahilmgandhi | 18:6a4db94011d3 | 4 | * \brief Sleep mode access |
sahilmgandhi | 18:6a4db94011d3 | 5 | * |
sahilmgandhi | 18:6a4db94011d3 | 6 | * Copyright (c) 2012-2015 Atmel Corporation. All rights reserved. |
sahilmgandhi | 18:6a4db94011d3 | 7 | * |
sahilmgandhi | 18:6a4db94011d3 | 8 | * \asf_license_start |
sahilmgandhi | 18:6a4db94011d3 | 9 | * |
sahilmgandhi | 18:6a4db94011d3 | 10 | * \page License |
sahilmgandhi | 18:6a4db94011d3 | 11 | * |
sahilmgandhi | 18:6a4db94011d3 | 12 | * Redistribution and use in source and binary forms, with or without |
sahilmgandhi | 18:6a4db94011d3 | 13 | * modification, are permitted provided that the following conditions are met: |
sahilmgandhi | 18:6a4db94011d3 | 14 | * |
sahilmgandhi | 18:6a4db94011d3 | 15 | * 1. Redistributions of source code must retain the above copyright notice, |
sahilmgandhi | 18:6a4db94011d3 | 16 | * this list of conditions and the following disclaimer. |
sahilmgandhi | 18:6a4db94011d3 | 17 | * |
sahilmgandhi | 18:6a4db94011d3 | 18 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
sahilmgandhi | 18:6a4db94011d3 | 19 | * this list of conditions and the following disclaimer in the documentation |
sahilmgandhi | 18:6a4db94011d3 | 20 | * and/or other materials provided with the distribution. |
sahilmgandhi | 18:6a4db94011d3 | 21 | * |
sahilmgandhi | 18:6a4db94011d3 | 22 | * 3. The name of Atmel may not be used to endorse or promote products derived |
sahilmgandhi | 18:6a4db94011d3 | 23 | * from this software without specific prior written permission. |
sahilmgandhi | 18:6a4db94011d3 | 24 | * |
sahilmgandhi | 18:6a4db94011d3 | 25 | * 4. This software may only be redistributed and used in connection with an |
sahilmgandhi | 18:6a4db94011d3 | 26 | * Atmel microcontroller product. |
sahilmgandhi | 18:6a4db94011d3 | 27 | * |
sahilmgandhi | 18:6a4db94011d3 | 28 | * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED |
sahilmgandhi | 18:6a4db94011d3 | 29 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
sahilmgandhi | 18:6a4db94011d3 | 30 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE |
sahilmgandhi | 18:6a4db94011d3 | 31 | * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR |
sahilmgandhi | 18:6a4db94011d3 | 32 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
sahilmgandhi | 18:6a4db94011d3 | 33 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
sahilmgandhi | 18:6a4db94011d3 | 34 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
sahilmgandhi | 18:6a4db94011d3 | 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
sahilmgandhi | 18:6a4db94011d3 | 36 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
sahilmgandhi | 18:6a4db94011d3 | 37 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
sahilmgandhi | 18:6a4db94011d3 | 38 | * POSSIBILITY OF SUCH DAMAGE. |
sahilmgandhi | 18:6a4db94011d3 | 39 | * |
sahilmgandhi | 18:6a4db94011d3 | 40 | * \asf_license_stop |
sahilmgandhi | 18:6a4db94011d3 | 41 | * |
sahilmgandhi | 18:6a4db94011d3 | 42 | */ |
sahilmgandhi | 18:6a4db94011d3 | 43 | /* |
sahilmgandhi | 18:6a4db94011d3 | 44 | * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a> |
sahilmgandhi | 18:6a4db94011d3 | 45 | */ |
sahilmgandhi | 18:6a4db94011d3 | 46 | |
sahilmgandhi | 18:6a4db94011d3 | 47 | #ifndef SLEEP_H |
sahilmgandhi | 18:6a4db94011d3 | 48 | #define SLEEP_H |
sahilmgandhi | 18:6a4db94011d3 | 49 | |
sahilmgandhi | 18:6a4db94011d3 | 50 | #ifdef __cplusplus |
sahilmgandhi | 18:6a4db94011d3 | 51 | extern "C" { |
sahilmgandhi | 18:6a4db94011d3 | 52 | #endif |
sahilmgandhi | 18:6a4db94011d3 | 53 | |
sahilmgandhi | 18:6a4db94011d3 | 54 | #include <compiler.h> |
sahilmgandhi | 18:6a4db94011d3 | 55 | |
sahilmgandhi | 18:6a4db94011d3 | 56 | /** |
sahilmgandhi | 18:6a4db94011d3 | 57 | * \defgroup sleep_group Power Manager (PM) |
sahilmgandhi | 18:6a4db94011d3 | 58 | * |
sahilmgandhi | 18:6a4db94011d3 | 59 | * This is a stub on the SAM Power Manager Control (PMC) for the sleepmgr |
sahilmgandhi | 18:6a4db94011d3 | 60 | * service. |
sahilmgandhi | 18:6a4db94011d3 | 61 | * |
sahilmgandhi | 18:6a4db94011d3 | 62 | * \note To minimize the code overhead, these functions do not feature |
sahilmgandhi | 18:6a4db94011d3 | 63 | * interrupt-protected access since they are likely to be called inside |
sahilmgandhi | 18:6a4db94011d3 | 64 | * interrupt handlers or in applications where such protection is not |
sahilmgandhi | 18:6a4db94011d3 | 65 | * necessary. If such protection is needed, it must be ensured by the calling |
sahilmgandhi | 18:6a4db94011d3 | 66 | * code. |
sahilmgandhi | 18:6a4db94011d3 | 67 | * |
sahilmgandhi | 18:6a4db94011d3 | 68 | * @{ |
sahilmgandhi | 18:6a4db94011d3 | 69 | */ |
sahilmgandhi | 18:6a4db94011d3 | 70 | |
sahilmgandhi | 18:6a4db94011d3 | 71 | #if defined(__DOXYGEN__) |
sahilmgandhi | 18:6a4db94011d3 | 72 | /** |
sahilmgandhi | 18:6a4db94011d3 | 73 | * \brief Sets the MCU in the specified sleep mode |
sahilmgandhi | 18:6a4db94011d3 | 74 | * \param sleep_mode Sleep mode to set. |
sahilmgandhi | 18:6a4db94011d3 | 75 | */ |
sahilmgandhi | 18:6a4db94011d3 | 76 | #endif |
sahilmgandhi | 18:6a4db94011d3 | 77 | /* SAM3 and SAM4 series */ |
sahilmgandhi | 18:6a4db94011d3 | 78 | #if (SAM3S || SAM3N || SAM3XA || SAM3U || SAM4S || SAM4E || SAM4N || SAM4C || \ |
sahilmgandhi | 18:6a4db94011d3 | 79 | SAM4CM || SAM4CP || SAMG || SAMV71 || SAME70) |
sahilmgandhi | 18:6a4db94011d3 | 80 | |
sahilmgandhi | 18:6a4db94011d3 | 81 | #if (SAM3S || SAM3N || SAM3XA || SAM3U || SAM4S || SAM4E || SAM4N || SAM4C || \ |
sahilmgandhi | 18:6a4db94011d3 | 82 | SAM4CM || SAM4CP || SAMG55 || SAMV71 || SAME70) |
sahilmgandhi | 18:6a4db94011d3 | 83 | # define SAM_PM_SMODE_ACTIVE 0 /**< Active */ |
sahilmgandhi | 18:6a4db94011d3 | 84 | # define SAM_PM_SMODE_SLEEP_WFE 1 /**< Wait for Events */ |
sahilmgandhi | 18:6a4db94011d3 | 85 | # define SAM_PM_SMODE_SLEEP_WFI 2 /**< Wait for Interrupts */ |
sahilmgandhi | 18:6a4db94011d3 | 86 | # define SAM_PM_SMODE_WAIT_FAST 3 /**< Wait Mode, startup fast (in 3ms) */ |
sahilmgandhi | 18:6a4db94011d3 | 87 | # define SAM_PM_SMODE_WAIT 4 /**< Wait Mode */ |
sahilmgandhi | 18:6a4db94011d3 | 88 | # define SAM_PM_SMODE_BACKUP 5 /**< Backup Mode */ |
sahilmgandhi | 18:6a4db94011d3 | 89 | #else |
sahilmgandhi | 18:6a4db94011d3 | 90 | # define SAM_PM_SMODE_ACTIVE 0 /**< Active */ |
sahilmgandhi | 18:6a4db94011d3 | 91 | # define SAM_PM_SMODE_WAIT_FAST 1 /**< Wait Mode, startup fast (in 3ms) */ |
sahilmgandhi | 18:6a4db94011d3 | 92 | # define SAM_PM_SMODE_WAIT 2 /**< Wait Mode */ |
sahilmgandhi | 18:6a4db94011d3 | 93 | #endif |
sahilmgandhi | 18:6a4db94011d3 | 94 | |
sahilmgandhi | 18:6a4db94011d3 | 95 | /** (SCR) Sleep deep bit */ |
sahilmgandhi | 18:6a4db94011d3 | 96 | #define SCR_SLEEPDEEP (0x1 << 2) |
sahilmgandhi | 18:6a4db94011d3 | 97 | |
sahilmgandhi | 18:6a4db94011d3 | 98 | /** |
sahilmgandhi | 18:6a4db94011d3 | 99 | * Clocks restored callback function type. |
sahilmgandhi | 18:6a4db94011d3 | 100 | * Registered by routine pmc_wait_wakeup_clocks_restore() |
sahilmgandhi | 18:6a4db94011d3 | 101 | * Callback called when all clocks are restored. |
sahilmgandhi | 18:6a4db94011d3 | 102 | */ |
sahilmgandhi | 18:6a4db94011d3 | 103 | typedef void (*pmc_callback_wakeup_clocks_restored_t) (void); |
sahilmgandhi | 18:6a4db94011d3 | 104 | |
sahilmgandhi | 18:6a4db94011d3 | 105 | /** |
sahilmgandhi | 18:6a4db94011d3 | 106 | * Enter sleep mode |
sahilmgandhi | 18:6a4db94011d3 | 107 | * \param sleep_mode Sleep mode to enter |
sahilmgandhi | 18:6a4db94011d3 | 108 | */ |
sahilmgandhi | 18:6a4db94011d3 | 109 | void pmc_sleep(int sleep_mode); |
sahilmgandhi | 18:6a4db94011d3 | 110 | |
sahilmgandhi | 18:6a4db94011d3 | 111 | /** |
sahilmgandhi | 18:6a4db94011d3 | 112 | * Check if clocks are restored after wakeup |
sahilmgandhi | 18:6a4db94011d3 | 113 | * (For WAIT mode. In WAIT mode, clocks are switched to FASTRC. |
sahilmgandhi | 18:6a4db94011d3 | 114 | * After wakeup clocks should be restored, before that some of the |
sahilmgandhi | 18:6a4db94011d3 | 115 | * ISR should not be served, otherwise there may be timing or clock issue.) |
sahilmgandhi | 18:6a4db94011d3 | 116 | */ |
sahilmgandhi | 18:6a4db94011d3 | 117 | bool pmc_is_wakeup_clocks_restored(void); |
sahilmgandhi | 18:6a4db94011d3 | 118 | |
sahilmgandhi | 18:6a4db94011d3 | 119 | /** |
sahilmgandhi | 18:6a4db94011d3 | 120 | * \return true if start waiting |
sahilmgandhi | 18:6a4db94011d3 | 121 | */ |
sahilmgandhi | 18:6a4db94011d3 | 122 | void pmc_wait_wakeup_clocks_restore( |
sahilmgandhi | 18:6a4db94011d3 | 123 | pmc_callback_wakeup_clocks_restored_t callback); |
sahilmgandhi | 18:6a4db94011d3 | 124 | |
sahilmgandhi | 18:6a4db94011d3 | 125 | #endif |
sahilmgandhi | 18:6a4db94011d3 | 126 | |
sahilmgandhi | 18:6a4db94011d3 | 127 | //! @} |
sahilmgandhi | 18:6a4db94011d3 | 128 | |
sahilmgandhi | 18:6a4db94011d3 | 129 | #ifdef __cplusplus |
sahilmgandhi | 18:6a4db94011d3 | 130 | } |
sahilmgandhi | 18:6a4db94011d3 | 131 | #endif |
sahilmgandhi | 18:6a4db94011d3 | 132 | |
sahilmgandhi | 18:6a4db94011d3 | 133 | #endif /* SLEEP_H */ |