main.c 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /* main.c
  2. *
  3. * Copyright (C) 2006-2024 wolfSSL Inc.
  4. *
  5. * This file is part of wolfSSL.
  6. *
  7. * wolfSSL is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * wolfSSL is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
  20. */
  21. #include <stdbool.h>
  22. #include <errno.h>
  23. #include <string.h>
  24. #include <time.h>
  25. #include <applibs/log.h>
  26. #include <applibs/gpio.h>
  27. #include <wolfssl/wolfcrypt/settings.h>
  28. #ifndef WOLFSSL_USER_SETTINGS
  29. #error "user_settings.h not included"
  30. #endif
  31. #include <server.h>
  32. #include <client.h>
  33. /*
  34. * The following #include imports a "template appliance" definition. This app
  35. * comes with multiple implementations of the template appliance, each in a
  36. * separate directory, which allow the code to run unchanged on different
  37. * hardware.
  38. *
  39. * By default, this app targets hardware that follows the MT3620-mini Reference
  40. * Development Board (MDB) specification, such as the MT3620-mini Dev Kit from
  41. * Seeed Studio.
  42. *
  43. * To target different hardware, you'll need to update CMakeLists.txt.
  44. * For example, to target the Avnet MT3620 Starter Kit, make this update:
  45. * azsphere_target_hardware_definition(${PROJECT_NAME}
  46. * TARGET_DIRECTORY "HardwareDefinitions/avnet_mt3620_sk"
  47. * TARGET_DEFINITION "template_appliance.json")
  48. *
  49. * See https://aka.ms/AzureSphereHardwareDefinitions for more details.
  50. */
  51. #include <hw/template_appliance.h>
  52. typedef enum {
  53. ExitCode_Success = 0,
  54. ExitCode_Main_Led = 1
  55. } ExitCode;
  56. int main(void)
  57. {
  58. Log_Debug(
  59. "\nVisit https://github.com/Azure/azure-sphere-samples for other"
  60. " examples.\n");
  61. int ret;
  62. int fd = GPIO_OpenAsOutput(WOLF_AZSPHERE, GPIO_OutputMode_PushPull, GPIO_Value_High);
  63. if (fd < 0) {
  64. Log_Debug(
  65. "Error opening GPIO: %s (%d). Check that app_manifest.json includes"
  66. " the GPIO used.\n",
  67. strerror(errno), errno);
  68. return ExitCode_Main_Led;
  69. }
  70. const struct timespec sleepTime = {.tv_sec = 1, .tv_nsec = 0};
  71. printf("Launching the server...\n");
  72. ret = azsphere_server_app();
  73. printf("ret azsphere_server_app = %d\n", ret);
  74. /* if server exists continually blink the red LED indicating server needs
  75. * to be rebooted */
  76. while (true) {
  77. GPIO_SetValue(fd, GPIO_Value_Low);
  78. nanosleep(&sleepTime, NULL);
  79. GPIO_SetValue(fd, GPIO_Value_High);
  80. nanosleep(&sleepTime, NULL);
  81. }
  82. }