-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathmain.c
70 lines (60 loc) · 2.56 KB
/
main.c
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
/* Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the MIT License. */
// This minimal Azure Sphere app repeatedly toggles GPIO 8, which is the red channel of RGB
// LED 1 on the MT3620 RDB. Use this app to test that device and SDK installation succeeded
// that you can build, deploy, and debug a CMake app with Visual Studio.
//
// It uses the API for the following Azure Sphere application libraries:
// - gpio (digital input for button)
// - log (displays messages in the Device Output window during debugging)
#include <stdlib.h>
#include <stdbool.h>
#include <errno.h>
#include <string.h>
#include <time.h>
#include <applibs/log.h>
// The following #include imports a "sample appliance" hardware definition. This provides a set of
// named constants such as SAMPLE_BUTTON_1 which are used when opening the peripherals, rather
// that using the underlying pin names. This enables the same code to target different hardware.
//
// By default, this app targets hardware that follows the MT3620 Reference Development Board (RDB)
// specification, such as the MT3620 Dev Kit from Seeed Studio. To target different hardware, you'll
// need to update the TARGET_HARDWARE variable in CMakeLists.txt - see instructions in that file.
//
// You can also use hardware definitions related to all other peripherals on your dev board because
// the sample_appliance header file recursively includes underlying hardware definition headers.
// See https://aka.ms/azsphere-samples-hardwaredefinitions for further details on this feature.
#include <hw/sample_appliance.h>
#include "led.h"
/// <summary>
/// Exit codes for this application. These are used for the
/// application exit code. They must all be between zero and 255,
/// where zero is reserved for successful termination.
/// </summary>
typedef enum {
ExitCode_Success = 0,
ExitCode_Main_Led = 1
} ExitCode;
int main(void)
{
Log_Debug("Starting CMake Hello World application...\n");
int fd = LED_Open(SAMPLE_LED);
if (fd == -1) {
Log_Debug(
"Error opening GPIO: %s (%d). Check that app_manifest.json includes the GPIO used.\n",
strerror(errno), errno);
return ExitCode_Main_Led;
}
const struct timespec sleepTime = {.tv_sec = 1, .tv_nsec = 0};
while (true) {
LED_On(fd);
nanosleep(&sleepTime, NULL);
LED_Off(fd);
nanosleep(&sleepTime, NULL);
#ifdef LEAK
// Intentionally leak here to show an example of using valgrind to detect memory leaks
int* leak = (int*)malloc(sizeof(int));
*leak = 1;
#endif
}
}