/* user main thread created by MICO APP thread */
void user_main_thread(void* arg)
{
  OSStatus err = kUnknownErr;
  app_context_t *app_context = (app_context_t *)arg;
  
  // loop in user mian function && must not return
  err = user_main(app_context);
  
  // never get here only if user work error.
  app_log("ERROR: user_main thread exit err=%d, system will reboot...", err);
  
  err = mico_system_power_perform(app_context->mico_context, eState_Software_Reset);
  UNUSED_PARAMETER(err);
  
  mico_rtos_delete_thread(NULL);   
}
/* user main thread created by MICO APP thread */
void user_main_thread(void* arg)
{
  OSStatus err = kUnknownErr;
  mico_Context_t *mico_context = (mico_Context_t *)arg;
  
#if (MICO_CLOUD_TYPE != CLOUD_DISABLED)
  // wait semaphore for cloud connection
  //mico_fogcloud_waitfor_connect(mico_context, MICO_WAIT_FOREVER);  // block to wait fogcloud connect
  //app_log("Cloud connected, call user_main function.");
#endif
  
  // loop in user mian function && must not return
  err = user_main(mico_context);
  UNUSED_PARAMETER(err);
  
  // never get here only if user work error.
  app_log("ERROR: user_main thread exit err=%d, system reboot...", err);
  MicoSystemReboot();
}
Beispiel #3
0
int main(void)
{

  /* USER CODE BEGIN 1 */
  void user_main(void);
  /* USER CODE END 1 */

  /* MCU Configuration----------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* Configure the system clock */
  SystemClock_Config();

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_DMA_Init();
  MX_TIM1_Init();
  MX_USART3_UART_Init();

  /* USER CODE BEGIN 2 */
  user_main();
  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */

  }
  /* USER CODE END 3 */

}
/** 
 * \fn     main
 * \brief  Main entry point to a user-mode program 
 * 
 * This is the main() function for a user mode program, or the entry point
 * called by the OS, This calls an OS-abstracted main function
 * 
 * \param  argc - command line argument count
 * \param  argv - command line arguments
 * \return 0 on success, any other value indicates error 
 * \sa     user_main
 */ 
int main (int argc, char** argv)
{
    return user_main (argc, (PPS8)argv);
}
Beispiel #5
0
DCUserConn *
user_connection_new(struct sockaddr_in *addr, int user_socket)
{
    DCUserConn *uc;
    int get_fd[2] = { -1, -1 };
    int put_fd[2] = { -1, -1 };
    pid_t pid;

    if (pipe(get_fd) != 0 || pipe(put_fd) != 0) {
        warn(_("Cannot create pipe pair - %s\n"), errstr);
        goto cleanup;
    }

    pid = fork();
    if (pid < 0) {
        warn(_("Cannot create process - %s\n"), errstr);
        goto cleanup;
    }
    if (pid == 0)
        user_main(put_fd, get_fd, addr, user_socket);

    if (close(get_fd[1]) != 0 || close(put_fd[0]) != 0)
        warn(_("Cannot close pipe - %s\n"), errstr);
    /* Non-blocking mode is not required, but there may be some latency otherwise. */
    if (!fd_set_nonblock_flag(get_fd[0], true) || !fd_set_nonblock_flag(put_fd[1], true))
        warn(_("Cannot set non-blocking flag - %s\n"), errstr);
    /* The user socket is only used by the newly created user process. */
    if (user_socket >= 0 && close(user_socket) < 0)
        warn(_("Cannot close socket - %s\n"), errstr);

    uc = (DCUserConn*) xmalloc(sizeof(DCUserConn));
    uc->pid = pid;
    uc->info = NULL;
    uc->occupied_slot = 0;
    uc->occupied_minislot = 0;
    uc->dir = DC_DIR_UNKNOWN;
    uc->transfer_file = NULL;
    uc->local_file = NULL;
    uc->transfer_start = 0;
    uc->transfer_pos = 0;
    uc->transfer_total = 0;
    uc->transfer_time = (time_t) -1;
    uc->transferring = false;
    uc->queue_pos = 0;
    uc->queued_valid = false;
    /* uc->we_connected = (user_socket < 0); */
    uc->get_mq = msgq_new(get_fd[0]);
    uc->put_mq = msgq_new(put_fd[1]);
    FD_SET(uc->get_mq->fd, &read_fds);
    if (user_conn_unknown_free->cur > 0) {
        uc->name = (char*) ptrv_remove_first(user_conn_unknown_free);
    } else {
        /* TRANSLATORS: This represents the connection name used when
         * the user name is not yet known. It must not contains '|',
         * because that's used to distinguish between 'unknown' and
         * (perhaps partially) identified connections.
         */
        uc->name = xasprintf(_("unknown%" PRIu32), user_conn_unknown_last+1);
        user_conn_unknown_last++;
    }
    hmap_put(user_conns, uc->name, uc);
    return uc;

cleanup:
    if (get_fd[0] != -1)
        close(get_fd[0]);
    if (get_fd[1] != -1)
        close(get_fd[1]);
    if (put_fd[0] != -1)
        close(put_fd[0]);
    if (put_fd[1] != -1)
        close(put_fd[1]);
    return NULL;
}