Esempio n. 1
0
/*-----------------------Start system-----------------------------------------*/
void tn_app_init()
{
    tn_cpu_int_disable(); // прерывания включаются обратно после выхода из tn_app_init();
    // start
    startup();
    // for static IP
    struct ip_addr ipaddr   = { pref_get_long(PREF_L_NET_IP) };
    struct ip_addr netmask  = { pref_get_long(PREF_L_NET_MSK) };
    struct ip_addr gw       = { pref_get_long(PREF_L_NET_GW) };
    //ip_addr_debug_print(buf, ipaddr);
    ethernet_init((enum net_mode)pref_get_long(PREF_L_NET_MODE), &ipaddr, &netmask, &gw);
    cmd_ch_init(); // init cmd for ethernet
    // creat task_leds_func
    if (tn_task_create(&task_leds_tcb, &task_leds_func, TASK_LEDS_PRI, &task_leds_stk[TASK_LEDS_STK_SZ - 1],
        TASK_LEDS_STK_SZ, 0, TN_TASK_START_ON_CREATION) != TERR_NO_ERR)
    {
        dbg_puts("tn_task_create(&task_leds_tcb) error");
        goto err;
    }
    //time_init=true;
    return;

err:
    dbg_trace();
    tn_halt();
}
Esempio n. 2
0
// init one call
void light_init(void)
{
    dbg_printf("Initializing LIGHT...");
    pin_on(OPIN_TR_EN );//включить выходные регистры
    LIGHT_STA=LIGHT_WORK;// machine stat
    light_machine.work = FALSE; // stop machine
    //
    setStatusRestart(true);// перезагрузка
    //
    BOOL is_init;
    dk_num=0;
    //
    GREEN_PORT_CONF = 0;
    RED_PORT_CONF   = 0;
    YEL_PORT_CONF   = 0;
    //
   for (int i_dk=0; i_dk<DK_N; i_dk++)
    {
       CUR_DK = i_dk;

       for (int i_try=0; i_try<3; i_try++)
       {
         is_init = ligh_load_init(2-i_try);
          if (is_init)
          {
             dk_num++;
             break;
          }
       }
       //
     if (!is_init)
         break;
    }
if (dk_num)
  light_machine.work = TRUE; // start machine
/*create event*/
if (tn_event_create(&g_light_evt, TN_EVENT_ATTR_SINGLE | TN_EVENT_ATTR_CLR, 0) != TERR_NO_ERR){
  dbg_puts("tn_event_create(&g_light_evt) error");
  dbg_trace();
  tn_halt();
  }
/*create task_light_func*/
if (tn_task_create(&task_light_tcb, &task_light_func, TASK_LIGHT_PRI,
        &task_light_stk[TASK_LIGHT_STK_SZ - 1], TASK_LIGHT_STK_SZ, 0,
        TN_TASK_START_ON_CREATION) != TERR_NO_ERR){
  dbg_puts("tn_task_create(&task_light_tcb) error");
  dbg_trace();
  tn_halt();
  }
dbg_puts("[done]");
}
Esempio n. 3
0
File: gps.c Progetto: tuzhikov/SURD
void GPS_init()
{

    dbg_printf("Initializing GPS module...");

    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART);

    MAP_GPIOPinConfigure(GPIO_PA0_U0RX);
    MAP_GPIOPinConfigure(GPIO_PA1_U0TX);
    MAP_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

    MAP_UARTConfigSetExpClk(UART_BASE, MAP_SysCtlClockGet(), UART_SPEED, UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE);
    MAP_UARTDisable(UART_BASE);
    MAP_UARTTxIntModeSet(UART_BASE, UART_TXINT_MODE_EOT);
    MAP_UARTIntEnable(UART_BASE, UART_INT_RX | UART_INT_TX);
    MAP_IntEnable(INT_UART);
    MAP_UARTEnable(UART_BASE);
    MAP_UARTFIFODisable(UART_BASE);

    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);
    //
    MAP_IntEnable(INT_GPIOG);
    // Настроить прерывания на PPS
    MAP_GPIOIntTypeSet(GPIO_PORTG_BASE, GPIO_PIN_7, GPIO_FALLING_EDGE);
    MAP_GPIOPinIntEnable(GPIO_PORTG_BASE, GPIO_PIN_7);
    //

    if (tn_task_create(&task_GPS_tcb, &task_GPS_func, TASK_GPS_PRI,
        &task_GPS_stk[TASK_GPS_STK_SZ - 1], TASK_GPS_STK_SZ, 0,
        TN_TASK_START_ON_CREATION) != TERR_NO_ERR)
    {
        dbg_puts("tn_task_create(&task_GPS_tcb) error");
        goto err;
    }

    // Настроить прерывания на PPS
    //MAP_IntEnable(INT_GPIOG);
    //MAP_GPIOIntTypeSet(GPIO_PORTG_BASE, GPIO_PIN_7, GPIO_FALLING_EDGE);
    //MAP_GPIOPinIntEnable(GPIO_PORTG_BASE, GPIO_PIN_7);

    dbg_puts("[done]");

    return;
err:
    dbg_trace();
    tn_halt();
}
Esempio n. 4
0
//----------------------------------------------------------------------------
void  tn_app_init()
{
  //--- Task LED1 blink
  task_led1.id_task = 0;
  tn_task_create(&task_led1,                     //-- task TCB
                task_led1_func,                  //-- task function
                TASK_LED1_PRIORITY,              //-- task priority
                &(task_led1_stack                //-- task stack first addr in memory
                  [TASK_LED1_STK_SIZE-1]),
                TASK_LED1_STK_SIZE,              //-- task stack size (in int,not bytes)
                NULL,                            //-- task function parameter
                TN_TASK_START_ON_CREATION        //-- Creation option
                );

  //--- Task CHECKMEM
  task_checkmem.id_task = 0;
  tn_task_create(&task_checkmem,                 //-- task TCB
                task_checkmem_func,              //-- task function
                TASK_CHECKMEM_PRIORITY,          //-- task priority
                &(task_checkmem_stack            //-- task stack first addr in memory
                   [TASK_CHECKMEM_STK_SIZE-1]),
                TASK_CHECKMEM_STK_SIZE,          //-- task stack size (in int,not bytes)
                NULL,                            //-- task function parameter
                TN_TASK_START_ON_CREATION        //-- Creation option
                );

  //GPS TASKS:
  //--- Task ACCUM
  task_accum.id_task = 0;
  tn_task_create(&task_accum,                    //-- task TCB
                task_accum_func,                 //-- task function
                TASK_ACCUM_PRIORITY,             //-- task priority
                &(task_accum_stack               //-- task stack first addr in memory
                   [TASK_ACCUM_STK_SIZE-1]),
                TASK_ACCUM_STK_SIZE,             //-- task stack size (in int,not bytes)
                NULL,                            //-- task function parameter
                TN_TASK_START_ON_CREATION        //-- Creation option
                );

  //--- Task MEAS
  task_meas.id_task = 0;
  tn_task_create(&task_meas,                     //-- task TCB
                task_meas_func,                  //-- task function
                TASK_MEAS_PRIORITY,              //-- task priority
                &(task_meas_stack                //-- task stack first addr in memory
                   [TASK_MEAS_STK_SIZE-1]),
                TASK_MEAS_STK_SIZE,              //-- task stack size (in int,not bytes)
                NULL,                            //-- task function parameter
                TN_TASK_START_ON_CREATION        //-- Creation option
                );

  //--- Task DISP
  task_disp.id_task = 0;
  tn_task_create(&task_disp,                     //-- task TCB
                task_disp_func,                  //-- task function
                TASK_DISP_PRIORITY,              //-- task priority
                &(task_disp_stack                //-- task stack first addr in memory
                   [TASK_DISP_STK_SIZE-1]),
                TASK_DISP_STK_SIZE,              //-- task stack size (in int,not bytes)
                NULL,                            //-- task function parameter
                TN_TASK_START_ON_CREATION        //-- Creation option
                );

  //--- Task ALLOC
  task_disp.id_task = 0;
  tn_task_create(&task_alloc,                    //-- task TCB
                task_alloc_func,                 //-- task function
                TASK_ALLOC_PRIORITY,             //-- task priority
                &(task_alloc_stack               //-- task stack first addr in memory
                   [TASK_ALLOC_STK_SIZE-1]),
                TASK_ALLOC_STK_SIZE,             //-- task stack size (in int,not bytes)
                NULL,                            //-- task function parameter
                TN_TASK_START_ON_CREATION        //-- Creation option
                );


  //--- Semaphores
  semTxUart.id_sem = 0;
  tn_sem_create(&semTxUart,1,1);
  //GPS
  SemISR.id_sem  = 0;
  tn_sem_create(&SemISR, 1, 1);
  SemMeas.id_sem = 0;
  tn_sem_create(&SemMeas, 1, 1);

  //--- Queues
   queueTxUart.id_dque = 0;
   tn_queue_create(&queueTxUart,           //-- Ptr to already existing TN_DQUE
                      &queueTxUartMem[0],  //-- Ptr to already existing array of void * to store data queue entries.Can be NULL
                      QUEUE_TXUART_SIZE    //-- Capacity of data queue(num entries).Can be 0
                    );



}
Esempio n. 5
0
File: tn.c Progetto: ADTL/AFGUI
//----------------------------------------------------------------------------
// TN main function (never return)
//----------------------------------------------------------------------------
void tn_start_system(void)
{
   int i;

   //-- Clear/set all globals (vars, lists, etc)

   for(i=0;i < TN_NUM_PRIORITY;i++)
   {
      queue_reset(&(tn_ready_list[i]));
      tn_tslice_ticks[i] = NO_TIME_SLICE;
   }

   queue_reset(&tn_create_queue);
   tn_created_tasks_qty = 0;

   tn_system_state = TN_ST_STATE_NOT_RUN;

   tn_ready_to_run_bmp = 0;

   tn_idle_count       = 0;
   tn_curr_performance = 0;

   tn_next_task_to_run = NULL;
   tn_curr_run_task    = NULL;

  //-- System tasks

   queue_reset(&tn_wait_timeout_list);

   //--- Timer task

   tn_task_create((TN_TCB*)&tn_timer_task,        //-- task TCB
                  tn_timer_task_func,             //-- task function
                  0,                              //-- task priority
                  &(tn_timer_task_stack           //-- task stack first addr in memory
                      [TN_TIMER_STACK_SIZE-1]),
                  TN_TIMER_STACK_SIZE,            //-- task stack size (in int,not bytes)
                  NULL,                           //-- task function parameter
                  TN_TASK_TIMER);                 //-- Creation option

   //--- Idle task

   tn_task_create((TN_TCB*)&tn_idle_task,         //-- task TCB
                  tn_idle_task_func,              //-- task function
                  TN_NUM_PRIORITY-1,              //-- task priority
                  &(tn_idle_task_stack            //-- task stack first addr in memory
                      [TN_IDLE_STACK_SIZE-1]),
                  TN_IDLE_STACK_SIZE,             //-- task stack size (in int,not bytes)
                  NULL,                           //-- task function parameter
                  TN_TASK_IDLE);                  //-- Creation option

    //-- Activate timer & idle tasks

   tn_next_task_to_run = &tn_idle_task; //-- Just for the task_to_runnable() proper op

   task_to_runnable(&tn_idle_task);
   task_to_runnable(&tn_timer_task);

   tn_curr_run_task = &tn_idle_task;  //-- otherwise it is NULL

   //-- Run OS - first context switch

   tn_start_exe();
}