11664436fSMatthias Ringwald /*
21664436fSMatthias Ringwald * Copyright (C) 2014 BlueKitchen GmbH
31664436fSMatthias Ringwald *
41664436fSMatthias Ringwald * Redistribution and use in source and binary forms, with or without
51664436fSMatthias Ringwald * modification, are permitted provided that the following conditions
61664436fSMatthias Ringwald * are met:
71664436fSMatthias Ringwald *
81664436fSMatthias Ringwald * 1. Redistributions of source code must retain the above copyright
91664436fSMatthias Ringwald * notice, this list of conditions and the following disclaimer.
101664436fSMatthias Ringwald * 2. Redistributions in binary form must reproduce the above copyright
111664436fSMatthias Ringwald * notice, this list of conditions and the following disclaimer in the
121664436fSMatthias Ringwald * documentation and/or other materials provided with the distribution.
131664436fSMatthias Ringwald * 3. Neither the name of the copyright holders nor the names of
141664436fSMatthias Ringwald * contributors may be used to endorse or promote products derived
151664436fSMatthias Ringwald * from this software without specific prior written permission.
161664436fSMatthias Ringwald * 4. Any redistribution, use, or modification is done solely for
171664436fSMatthias Ringwald * personal benefit and not for any commercial purpose or for
181664436fSMatthias Ringwald * monetary gain.
191664436fSMatthias Ringwald *
201664436fSMatthias Ringwald * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
211664436fSMatthias Ringwald * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
221664436fSMatthias Ringwald * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23*2fca4dadSMilanka Ringwald * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BLUEKITCHEN
24*2fca4dadSMilanka Ringwald * GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
251664436fSMatthias Ringwald * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
261664436fSMatthias Ringwald * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
271664436fSMatthias Ringwald * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
281664436fSMatthias Ringwald * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
291664436fSMatthias Ringwald * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
301664436fSMatthias Ringwald * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
311664436fSMatthias Ringwald * SUCH DAMAGE.
321664436fSMatthias Ringwald *
331664436fSMatthias Ringwald * Please inquire about commercial licensing options at
341664436fSMatthias Ringwald * [email protected]
351664436fSMatthias Ringwald *
361664436fSMatthias Ringwald */
371664436fSMatthias Ringwald
381664436fSMatthias Ringwald
391664436fSMatthias Ringwald /*
401664436fSMatthias Ringwald * hal_cpu.c
411664436fSMatthias Ringwald *
421664436fSMatthias Ringwald * Implementation for MSP430 Experimenter board using low power mode 0/3
431664436fSMatthias Ringwald *
441664436fSMatthias Ringwald */
451664436fSMatthias Ringwald
461664436fSMatthias Ringwald #include "hal_cpu.h"
471664436fSMatthias Ringwald
481664436fSMatthias Ringwald #include "hal_board.h"
491664436fSMatthias Ringwald #include "hal_compat.h"
501664436fSMatthias Ringwald
511664436fSMatthias Ringwald #include <msp430.h>
521664436fSMatthias Ringwald
531664436fSMatthias Ringwald static uint8_t low_power_mode_for_sleep = LPM0_bits;
541664436fSMatthias Ringwald
hal_cpu_disable_irqs(void)551664436fSMatthias Ringwald void hal_cpu_disable_irqs(void){
561664436fSMatthias Ringwald
571664436fSMatthias Ringwald // LED off
581664436fSMatthias Ringwald LED1_OUT &= ~LED1_PIN;
591664436fSMatthias Ringwald
601664436fSMatthias Ringwald // disable irq
611664436fSMatthias Ringwald __bic_SR_register(GIE);
621664436fSMatthias Ringwald }
631664436fSMatthias Ringwald
hal_cpu_enable_irqs(void)641664436fSMatthias Ringwald void hal_cpu_enable_irqs(void){
651664436fSMatthias Ringwald
661664436fSMatthias Ringwald // enable irq
671664436fSMatthias Ringwald __bis_SR_register(GIE);
681664436fSMatthias Ringwald
691664436fSMatthias Ringwald // LED on
701664436fSMatthias Ringwald LED1_OUT |= LED1_PIN;
711664436fSMatthias Ringwald }
721664436fSMatthias Ringwald
hal_cpu_set_uart_needed_during_sleep(uint8_t enabled)731664436fSMatthias Ringwald void hal_cpu_set_uart_needed_during_sleep(uint8_t enabled){
741664436fSMatthias Ringwald if (enabled){
751664436fSMatthias Ringwald LED2_OUT |= LED2_PIN;
761664436fSMatthias Ringwald low_power_mode_for_sleep = LPM0_bits;
771664436fSMatthias Ringwald return;
781664436fSMatthias Ringwald }
791664436fSMatthias Ringwald LED2_OUT &= ~LED2_PIN;
801664436fSMatthias Ringwald low_power_mode_for_sleep = LPM3_bits;
811664436fSMatthias Ringwald }
821664436fSMatthias Ringwald
hal_cpu_enable_irqs_and_sleep(void)831664436fSMatthias Ringwald void hal_cpu_enable_irqs_and_sleep(void){
841664436fSMatthias Ringwald
851664436fSMatthias Ringwald // enable irq and enter lpm0
861664436fSMatthias Ringwald __bis_SR_register(low_power_mode_for_sleep + GIE);
871664436fSMatthias Ringwald
881664436fSMatthias Ringwald // LED on
891664436fSMatthias Ringwald LED1_OUT |= LED1_PIN;
901664436fSMatthias Ringwald }
911664436fSMatthias Ringwald
921664436fSMatthias Ringwald
93