Debian Codegraph @

thirdparty/analogdevicesinc/no-OS/Renesas/RL78G14/PmodACL2/PmodACL2.c

raw symbols SCIP
1 /***************************************************************************//**
2 * @file Main.c
3 * @brief Implementation of the program's main function.
4 * @author DNechita([email protected])
5 ********************************************************************************
6 * Copyright 2012(c) Analog Devices, Inc.
7 *
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are met:
12 * - Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * - Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
17 * distribution.
18 * - Neither the name of Analog Devices, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 * - The use of this software may or may not infringe the patent rights
22 * of one or more patent holders. This license does not release you
23 * from the requirement that you obtain separate licenses from these
24 * patent holders to use this software.
25 * - Use of the software either in source or binary form, must be run
26 * on or directly connected to an Analog Devices Inc. component.
27 *
28 * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
29 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
30 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
31 * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
32 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33 * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
34 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
35 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
36 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 *
39 ********************************************************************************
40 * SVN Revision: $WCREV$
41 *******************************************************************************/
42
43 /******************************************************************************/
44 /***************************** Option Bytes ***********************************/
45 /******************************************************************************/
46 #pragma location = "OPTBYTE"
47 __root const unsigned char opbyte0 = 0x6E; // Watchdog timer settings.
48 #pragma location = "OPTBYTE"
49 __root const unsigned char opbyte1 = 0xFF; // Low voltage detector settings.
50 #pragma location = "OPTBYTE"
51 __root const unsigned char opbyte2 = 0xE8; // Flash op. mode and osc. settings.
52 #pragma location = "OPTBYTE"
53 __root const unsigned char opbyte3 = 0x85; // On-chip Debug Option Byte.
54
55 /******************************************************************************/
56 /***************************** Include Files **********************************/
57 /******************************************************************************/
58 #include "RDKRL78G14.h" // RDKRL78G14 definitions.
59 #include "ST7579.h" // ST7579 definitions.
60 #include "TIME.h" // TIME definitions.
61 #include "ADXL362.h" // ADXL362 definitions.
62
63 /******************************************************************************/
64 /************************ Variables Definitions *******************************/
65 /******************************************************************************/
66 unsigned char status = 0;
67 float xAxis = 0;
68 float yAxis = 0;
69 float zAxis = 0;
70 float temperature = 0;
71
72 /***************************************************************************//**
73 * @brief Draws the ADI logo and displays the name of ADI component.
74 *
75 * @param componentName - The name of the ADI component.
76 *
77 * @return None.
78 *******************************************************************************/
79 void ADI_Component(unsigned char* string)
80 {
81 const unsigned char adiComponent[7] =
82 {
83 0xFE, 0xFE, 0x82, 0xC6, 0xEE, 0xFE, 0xFE
84 };
85 ST7579_Image(0, 0, adiComponent, 7, 8);
86 ST7579_String(0, 9, string, 0);
87 }
88
89 /***************************************************************************//**
90 * @brief Main function.
91 *
92 * @return None.
93 *******************************************************************************/
94 void main(void)
95 {
96 /* Set pin 7 and pin 8 (J11 connector) as input, to avoid the output pins
97 of the Pmod ACL2 to be connected to an output pin of the microcontroller. */
98 PM7 |= (1 << 6); // P76 (PMOD-IRQA)
99 PM7 |= (1 << 7); // P77 (PMOD-IRQB)
100
101 /* Initialize RDKRL78G14. */
102 RDKRL78G14_Init();
103
104 /* Enable interrupts. */
105 __enable_interrupt();
106
107 /* Initialize timer. */
108 TIME_Init();
109
110 /* Initialize the ST7579 Display. */
111 ST7579_Init();
112
113 /* Init device. */
114 if(ADXL362_Init() == 0)
115 {
116 ADI_Component("ADXL362 OK");
117 }
118 else
119 {
120 ADI_Component("ADXL362 Error");
121 }
122
123 /* Put the device in standby mode. */
124 ADXL362_SetPowerMode(0);
125
126 /* Set accelerometer's output data rate to: 12.5 Hz. */
127 ADXL362_SetOutputRate(ADXL362_ODR_12_5_HZ);
128
129 /* Setup the activity and inactivity detection. */
130 ADXL362_SetRegisterValue(
131 ADXL362_ACT_INACT_CTL_LINKLOOP(ADXL362_MODE_LINK),
132 ADXL362_REG_ACT_INACT_CTL,
133 1);
134 ADXL362_SetupActivityDetection(1, 30, 1);
135 ADXL362_SetupInactivityDetection(1, 700, 25);
136
137 /* Start the measurement process. */
138 ADXL362_SetPowerMode(1);
139
140 /* Clear ACT and INACT bits by reading the Status Register. */
141 ADXL362_GetRegisterValue(&status,
142 ADXL362_REG_STATUS,
143 1);
144
145 /* Select the 4g measurement range. */
146 ADXL362_SetRange(ADXL362_RANGE_4G);
147
148 while(1)
149 {
150
151 /* Wait for the detection of an activity or inactivity or for available
152 data. */
153 do
154 {
155 ADXL362_GetRegisterValue(&status, ADXL362_REG_STATUS, 1);
156
157 }while(
158 ((status & ADXL362_STATUS_DATA_RDY) == 0) &&
159 ((status & ADXL362_STATUS_INACT) == 0) &&
160 ((status & ADXL362_STATUS_ACT == 0)));
161
162 /* Get the data from the device and display it. */
163 if(status & ADXL362_STATUS_DATA_RDY)
164 {
165 //ADXL362_GetXyz(&xAxis, &yAxis, &zAxis);
166 ADXL362_GetGxyz(&xAxis, &yAxis, &zAxis);
167 temperature = ADXL362_ReadTemperature();
168 ST7579_String(2, 0, "X: g", 0);
169 //ST7579_Number(2, 12, xAxis, 0);
170 ST7579_FloatNumber(2, 18, xAxis, 3, 0);
171 ST7579_String(3, 0, "Y: g", 0);
172 //ST7579_Number(3, 12, yAxis, 0);
173 ST7579_FloatNumber(3, 18, yAxis, 3, 0);
174 ST7579_String(4, 0, "Z: g", 0);
175 //ST7579_Number(4, 12, zAxis, 0);
176 ST7579_FloatNumber(4, 18, zAxis, 3, 0);
177 ST7579_String(5, 0, "TMP: C", 0);
178 ST7579_FloatNumber(5, 22, temperature, 2, 0);
179 }
180
181 /* Display the activity/inactivity status. */
182 if(status & ADXL362_STATUS_INACT)
183 {
184 ST7579_String(6, 0, " ", 0);
185 ST7579_String(6, 0, "Inactivity", 0);
186 ST7579_String(7, 0, "detected", 0);
187 }
188 else if(status & ADXL362_STATUS_ACT)
189 {
190 ST7579_String(6, 0, " ", 0);
191 ST7579_String(6, 0, "Activity", 0);
192 ST7579_String(7, 0, "detected", 0);
193 }
194 TIME_DelayMs(50);
195 }
196 }