summaryrefslogtreecommitdiff
path: root/digital/beacon/src/Bitcloud_stack/Components/BSP/MESHBEAN/src/pwrCtrl.c
blob: 305b80a2b45329f38d5fd2ae6da121fbd9e04162 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/***************************************************************************//**
\file  pwrCtrl.c

\brief The module to control the power on periphery.

\author
    Atmel Corporation: http://www.atmel.com \n
    Support email: avr@atmel.com

  Copyright (c) 2008-2011, Atmel Corporation. All rights reserved.
  Licensed under Atmel's Limited License Agreement (BitCloudTM).

\internal
  History:
    29/05/07 E. Ivanov - Created
*******************************************************************************/
/******************************************************************************
                   Includes section
******************************************************************************/
#include <types.h>
#include <pwrCtrl.h>
#include <gpio.h>

#if BSP_MNZB_EVB_SUPPORT == 1
/******************************************************************************
                    Prototypes section
******************************************************************************/
/**************************************************************************//**
\brief Checks if amplifier is used.
\return true - is used, \n
 false - is not used.
******************************************************************************/
bool HAL_IsAmplifierUsed(void);

/******************************************************************************
                   Global variables section
******************************************************************************/
uint8_t bspPowerControl = 0;

/******************************************************************************
                   Implementations section
******************************************************************************/
/**************************************************************************//**
\brief  Powers on periphery.

\param[in]
  id - periphery id.
******************************************************************************/
void bspOnPeriphery(uint8_t id)
{
  if (!bspPowerControl)
  {
    GPIO_8_make_out();

    if (HAL_IsAmplifierUsed())
      GPIO_8_clr();
    else
      GPIO_8_set();

    GPIO_7_make_out();
    GPIO_7_set();
  }
  bspPowerControl |= (1 << id);
}


/**************************************************************************//**
\brief  Powers off periphery.

\param[in]
  id - periphery id.
******************************************************************************/
void bspOffPeriphery(uint8_t id)
{
  bspPowerControl &= ~(1 << id);
  if (bspPowerControl)
    return;

  GPIO_8_make_out();

  if (HAL_IsAmplifierUsed())
    GPIO_8_set();
  else
    GPIO_8_clr();

  GPIO_7_make_out();
  GPIO_7_clr();
}

#endif /* BSP_MNZB_EVB_SUPPORT */
// eof pwrCtrl.c