xref: /btstack/port/archive/msp430f5229lp-cc2564b/src/hal_cpu.c (revision 1664436fd643daf66517dc309e6cc72448e8a86d)
1*1664436fSMatthias Ringwald /*
2*1664436fSMatthias Ringwald  * Copyright (C) 2014 BlueKitchen GmbH
3*1664436fSMatthias Ringwald  *
4*1664436fSMatthias Ringwald  * Redistribution and use in source and binary forms, with or without
5*1664436fSMatthias Ringwald  * modification, are permitted provided that the following conditions
6*1664436fSMatthias Ringwald  * are met:
7*1664436fSMatthias Ringwald  *
8*1664436fSMatthias Ringwald  * 1. Redistributions of source code must retain the above copyright
9*1664436fSMatthias Ringwald  *    notice, this list of conditions and the following disclaimer.
10*1664436fSMatthias Ringwald  * 2. Redistributions in binary form must reproduce the above copyright
11*1664436fSMatthias Ringwald  *    notice, this list of conditions and the following disclaimer in the
12*1664436fSMatthias Ringwald  *    documentation and/or other materials provided with the distribution.
13*1664436fSMatthias Ringwald  * 3. Neither the name of the copyright holders nor the names of
14*1664436fSMatthias Ringwald  *    contributors may be used to endorse or promote products derived
15*1664436fSMatthias Ringwald  *    from this software without specific prior written permission.
16*1664436fSMatthias Ringwald  * 4. Any redistribution, use, or modification is done solely for
17*1664436fSMatthias Ringwald  *    personal benefit and not for any commercial purpose or for
18*1664436fSMatthias Ringwald  *    monetary gain.
19*1664436fSMatthias Ringwald  *
20*1664436fSMatthias Ringwald  * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
21*1664436fSMatthias Ringwald  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22*1664436fSMatthias Ringwald  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23*1664436fSMatthias Ringwald  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
24*1664436fSMatthias Ringwald  * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25*1664436fSMatthias Ringwald  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26*1664436fSMatthias Ringwald  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
27*1664436fSMatthias Ringwald  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28*1664436fSMatthias Ringwald  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29*1664436fSMatthias Ringwald  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
30*1664436fSMatthias Ringwald  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31*1664436fSMatthias Ringwald  * SUCH DAMAGE.
32*1664436fSMatthias Ringwald  *
33*1664436fSMatthias Ringwald  * Please inquire about commercial licensing options at
34*1664436fSMatthias Ringwald  * [email protected]
35*1664436fSMatthias Ringwald  *
36*1664436fSMatthias Ringwald  */
37*1664436fSMatthias Ringwald 
38*1664436fSMatthias Ringwald 
39*1664436fSMatthias Ringwald /*
40*1664436fSMatthias Ringwald  *  hal_cpu.c
41*1664436fSMatthias Ringwald  *
42*1664436fSMatthias Ringwald  *  Implementation for MSP430 Experimenter board using low power mode 0/3
43*1664436fSMatthias Ringwald  *
44*1664436fSMatthias Ringwald  */
45*1664436fSMatthias Ringwald 
46*1664436fSMatthias Ringwald #include "hal_cpu.h"
47*1664436fSMatthias Ringwald 
48*1664436fSMatthias Ringwald #include "hal_board.h"
49*1664436fSMatthias Ringwald #include "hal_compat.h"
50*1664436fSMatthias Ringwald 
51*1664436fSMatthias Ringwald #include <msp430.h>
52*1664436fSMatthias Ringwald 
53*1664436fSMatthias Ringwald static uint8_t low_power_mode_for_sleep = LPM0_bits;
54*1664436fSMatthias Ringwald 
55*1664436fSMatthias Ringwald void hal_cpu_disable_irqs(void){
56*1664436fSMatthias Ringwald 
57*1664436fSMatthias Ringwald     // LED off
58*1664436fSMatthias Ringwald     LED1_OUT &= ~LED1_PIN;
59*1664436fSMatthias Ringwald 
60*1664436fSMatthias Ringwald     // disable irq
61*1664436fSMatthias Ringwald     __bic_SR_register(GIE);
62*1664436fSMatthias Ringwald }
63*1664436fSMatthias Ringwald 
64*1664436fSMatthias Ringwald void hal_cpu_enable_irqs(void){
65*1664436fSMatthias Ringwald 
66*1664436fSMatthias Ringwald     // enable irq
67*1664436fSMatthias Ringwald     __bis_SR_register(GIE);
68*1664436fSMatthias Ringwald 
69*1664436fSMatthias Ringwald     // LED on
70*1664436fSMatthias Ringwald     LED1_OUT |= LED1_PIN;
71*1664436fSMatthias Ringwald }
72*1664436fSMatthias Ringwald 
73*1664436fSMatthias Ringwald void hal_cpu_set_uart_needed_during_sleep(uint8_t enabled){
74*1664436fSMatthias Ringwald     if (enabled){
75*1664436fSMatthias Ringwald         LED2_OUT |= LED2_PIN;
76*1664436fSMatthias Ringwald         low_power_mode_for_sleep = LPM0_bits;
77*1664436fSMatthias Ringwald         return;
78*1664436fSMatthias Ringwald     }
79*1664436fSMatthias Ringwald     LED2_OUT &= ~LED2_PIN;
80*1664436fSMatthias Ringwald     low_power_mode_for_sleep = LPM3_bits;
81*1664436fSMatthias Ringwald }
82*1664436fSMatthias Ringwald 
83*1664436fSMatthias Ringwald void hal_cpu_enable_irqs_and_sleep(void){
84*1664436fSMatthias Ringwald 
85*1664436fSMatthias Ringwald     // enable irq and enter lpm0
86*1664436fSMatthias Ringwald     __bis_SR_register(low_power_mode_for_sleep + GIE);
87*1664436fSMatthias Ringwald 
88*1664436fSMatthias Ringwald     // LED on
89*1664436fSMatthias Ringwald     LED1_OUT |= LED1_PIN;
90*1664436fSMatthias Ringwald }
91*1664436fSMatthias Ringwald 
92*1664436fSMatthias Ringwald 
93