NativeBlink/main.c (35 lines of code) (raw):

/* 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 } }