/* main ===================================================================== */ int main (void) { static volatile int i; vLedInit(); FILE * tc = xFileOpen (PORT, O_RDWR | O_NONBLOCK, &settings); stdout = tc; stderr = tc; stdin = tc; sei(); for (;;) { test_count = 1; printf_P (PSTR ("\nAvrIO Log test\n" "Press any key to proceed...\n")); while (getchar() == EOF) ; vLogSetMask (LOG_UPTO (LOG_INFO)); i = iLogMask(); test (i == LOG_UPTO (LOG_INFO)); vLog_P (LOG_INFO, flashstr, ++test_count); vLog (LOG_INFO, ramstr, ++test_count); for (i = LOG_DEBUG; i >= LOG_EMERG; i--) { fprintf_P (stderr, PSTR ("\nPriority up to %s\n"), sLogPriorityString(i)); vLogSetMask (LOG_UPTO (i)); vLedSet (LED_LED1); PERROR ("Error %d", test_count++); vLedClear (LED_LED1); delay_ms (5); vLedSet (LED_LED1); PWARNING ("Warning %d", test_count++); vLedClear (LED_LED1); delay_ms (5); vLedSet (LED_LED1); PNOTICE ("Notice %d", test_count++); vLedClear (LED_LED1); delay_ms (5); vLedSet (LED_LED1); PINFO ("Info %d", test_count++); vLedClear (LED_LED1); PDEBUG ("Debug %d", test_count++); PERROR ("Error %d", test_count++); PWARNING ("Warning %d", test_count++); PNOTICE ("Notice %d", test_count++); PINFO ("Info %d", test_count++); PDEBUG ("Debug %d", test_count++); } } return 0; }
// ----------------------------------------------------------------------------- // Start the daemon and monitor it. If it stops for any reason, restart it static void prvDaemon (gxPLSetting * setting) { int daemon_restart_count = 0; int ret; setting->malloc = 0; // the settings are not to be freed at the network closure // Begin daemon supervision // Install signal traps for proper shutdown signal (SIGTERM, prvDaemonSignalHandler); signal (SIGINT, prvDaemonSignalHandler); // To supervise the daemon, we repeatedly fork ourselves each time we // determine the daemon is not running. We maintain a circuit breaker // to prevent an endless spawning if the daemon just can't run for (;;) { // See if we can still do this if (daemon_restart_count == MAX_DAEMON_RESTARTS) { PERROR ("template has died %d times -- something may be wrong " "-- terminating supervisor", MAX_DAEMON_RESTARTS); exit (EXIT_FAILURE); } // Up the restart count daemon_restart_count++; // Fork off the daemon switch (daemon_pid = fork()) { case 0: // child // Close standard I/O and become our own process group close (fileno (stdin)); close (fileno (stdout)); close (fileno (stderr)); setpgrp(); // start the main task vMain (setting); break; default: // parent PINFO ("spawned template process, pid=%d, spawn count=%d", daemon_pid, daemon_restart_count); break; case -1: // error PERROR ("unable to spawn template-daemon supervisor, %s (%d)", strerror (errno), errno); exit (EXIT_FAILURE); } // Now we just wait for something bad to happen to our daemon waitpid (daemon_pid, &ret, 0); if (WIFEXITED (ret)) { PNOTICE ("template exited normally with status %d -- restarting...", WEXITSTATUS (ret)); continue; } if (WIFSIGNALED (ret)) { PNOTICE ("template died from by receiving unexpected signal %d" " -- restarting...", WTERMSIG (ret)); continue; } PNOTICE ("template died from unknown causes -- restarting..."); continue; } }
/*! * @brief probe bme sensor * * @param dev the pointer of device * @param data_bus the pointer of data bus communication * * @return zero success, non-zero failed * @retval zero success * @retval non-zero failed */ int bme_probe(struct device *dev, struct bme_data_bus *data_bus) { struct bme_client_data *data; int err = 0; if (!dev || !data_bus) { err = -EINVAL; goto exit; } /* check chip id */ err = bme_check_chip_id(data_bus); if (err) { PERR("Bosch Sensortec Device not found, chip id mismatch!\n"); goto exit; } else { PNOTICE("Bosch Sensortec Device %s detected.\n", BME_NAME); } data = kzalloc(sizeof(struct bme_client_data), GFP_KERNEL); if (!data) { err = -ENOMEM; goto exit; } dev_set_drvdata(dev, data); data->data_bus = *data_bus; data->dev = dev; /* Initialize the BME chip */ err = bme_init_client(data); if (err != 0) goto exit_free; /* Initialize the BME input device */ err = bme_input_init(data); if (err != 0) goto exit_free; /* Register sysfs hooks */ err = sysfs_create_group(&data->input->dev.kobj, &bme_attr_group); if (err) goto error_sysfs; /* workqueue init */ INIT_DELAYED_WORK(&data->work, bme_work_func); #ifdef CONFIG_HAS_EARLYSUSPEND data->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1; data->early_suspend.suspend = bme_early_suspend; data->early_suspend.resume = bme_late_resume; register_early_suspend(&data->early_suspend); #endif PINFO("Succesfully probe sensor %s\n", BME_NAME); regulator_disable(data->data_bus.avdd); return 0; error_sysfs: bme_input_delete(data); exit_free: regulator_disable(data->data_bus.avdd); kfree(data); exit: return err; }