Esempio n. 1
0
void COMM_UDP_init() {
#ifdef CONFIG_ETHSPI
  DBG(D_COMM, D_DEBUG, "COMM UDP init\n");
  memset(&ecomm, 0, sizeof(comm));

  ecomm.tx_ix = UDP_DATA_P;

  OS_thread_create(&ecomm.thread, OS_THREAD_FLAG_PRIVILEGED,
      COMM_UDP_thread_func, NULL, comm_udp_thr_stack,
      sizeof(comm_udp_thr_stack) - 4, "comm_udp");

  // comm stack setup
  comm_init(&ecomm.driver,        // comm stack struct
      0,                    // conf
      1,                    // this address
      0,                    // comm_phy_rx_char - called from eth callback
      COMM_UDP_tx_char,         // comm_phy_tx_char
      COMM_UDP_tx_buf,          // comm_phy_tx_buf
      COMM_UDP_tx_flush,        // comm_phy_tx_flush
      COMM_cb_get_tick_count,  // comm_app_get_time
      COMM_cb_rx_pkt,          // comm_app_user_rx
      COMM_cb_ack_pkt,         // comm_app_user_ack
      COMM_cb_err,             // comm_app_user_err
      COMM_cb_tra_inf,         // comm_app_user_inf
      COMM_cb_alert            // comm_app_alert
      );
  // using comm stacks allocation callback for pkt buffers
  comm_init_alloc(&ecomm.driver, COMM_UDP_alloc, COMM_UDP_free);

  // stack now active
#endif
}
Esempio n. 2
0
File: wlan.c Progetto: ianjuch/ee149
void wlan_start(unsigned short usPatchesAvailableAtHost)
{
    OS_mutex_lock(g_main_mutex, &mtx_key);

    s_thread_params params = {0};
    int index = 0;

    for(index = 0; index < MAX_NUM_OF_SOCKETS; index++){
        g_sockets[index].sd = -1;
        g_sockets[index].status = SOC_NOT_INITED;
        if (NULL == g_sockets[index].sd_semaphore)
            OS_semaphore_create(&g_sockets[index].sd_semaphore, "SockSem", 0);
    }

    if (NULL == g_accept_semaphore)
        OS_semaphore_create(&g_accept_semaphore, "AcceptSem", 0);

    if (NULL == g_select_sleep_semaphore)
        OS_semaphore_create(&g_select_sleep_semaphore, "SelectSleepSem", 0);

    /**/
    c_wlan_start(usPatchesAvailableAtHost);

    g_wlan_stopped = 0;
    g_should_poll_accept = 0;
    g_accept_socket = -1;

    if (NULL == g_select_thread){ /* Thread not created yet */
        /* Fill Thread Params */
        strncpy(params.thread_name, "SelectThread", strlen("SelectThread"));
        params.p_stack_start = NULL; /* TBD - Mandatory in Thread-X */
        params.p_entry_function = SelectThread;
        *(sInt32 *)params.p_func_params = 0;
        params.stack_size = 512;
        params.priority = 3;

        if (e_SUCCESS != OS_thread_create(&g_select_thread, &params))
        {
            OS_mutex_unlock(g_main_mutex, mtx_key); /* Error */
        }
    }

    OS_mutex_unlock(g_main_mutex, mtx_key);
}
Esempio n. 3
0
void dpow_srcupdate(struct supernet_info *myinfo,struct dpow_info *dp,int32_t height,bits256 hash,uint32_t timestamp,uint32_t blocktime)
{
    void **ptrs; char str[65]; struct dpow_checkpoint checkpoint; int32_t freq,minsigs; //uint8_t pubkeys[64][33];
    dpow_checkpointset(myinfo,&dp->last,height,hash,timestamp,blocktime);
    checkpoint = dp->srcfifo[dp->srcconfirms];
    if ( strcmp("BTC",dp->dest) == 0 )
    {
        freq = DPOW_CHECKPOINTFREQ;
        minsigs = DPOW_MINSIGS;
    }
    else
    {
        freq = 1;
        //minsigs = 7;//(komodo_notaries(dp->symbol,pubkeys,height) >> 1) + 1;
        //if ( minsigs < DPOW_MINSIGS )
        minsigs = DPOW_MINSIGS;
    }
    printf("%s/%s src ht.%d dest.%u nonz.%d %s minsigs.%d\n",dp->symbol,dp->dest,checkpoint.blockhash.height,dp->destupdated,bits256_nonz(checkpoint.blockhash.hash),bits256_str(str,dp->last.blockhash.hash),minsigs);
    dpow_fifoupdate(myinfo,dp->srcfifo,dp->last);
    if ( dp->SRCREALTIME == 0 && strcmp(dp->dest,"KMD") == 0 )
        return;
    if ( bits256_nonz(checkpoint.blockhash.hash) != 0 && (checkpoint.blockhash.height % freq) == 0 )
    {
        dpow_heightfind(myinfo,dp,checkpoint.blockhash.height + 1000);
        ptrs = calloc(1,sizeof(void *)*5 + sizeof(struct dpow_checkpoint));
        ptrs[0] = (void *)myinfo;
        ptrs[1] = (void *)dp;
        ptrs[2] = (void *)(uint64_t)minsigs;
        ptrs[3] = (void *)DPOW_DURATION;
        ptrs[4] = 0;
        memcpy(&ptrs[5],&checkpoint,sizeof(checkpoint));
        if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)dpow_statemachinestart,(void *)ptrs) != 0 )
        {
        }
    }
}
Esempio n. 4
0
int main(int argc, const char *argv[])
{

    // for our
    int     i;
    int     circle;
    int     check_times;
    char    command[COMMAND_LENGTHS];

    char * p_real_cmd;

    // pthread
    int     thread_pid;
    char    kill_command[256];
    char    kill_name[256];

    // for share memory
	int key;
	int ret;

    // for socket
    
    char message_send[MAX_LENGTH];
    int         send_data_len;
    int         client_sockfd;
    struct      sockaddr_in server_addr;
    socklen_t   server_len;    

    pid_t pid;
    int monitor_time_cnt;

    // signal sigint
    if (signal(SIGINT, sig_handler) == SIG_ERR)
        OS_log(LVL_ERR,0,"can't catch SIGINT");


    if(strstr(argv[1],"--help"))
    {
        printf("this is serial_client\n");
        return 0;
    }

    if(!check_process_exist_ex("server_serial",&thread_pid,500))
    {
        printf("\n\npls running server_serial firstly!\n\n");
        return -1;
    }


    // init the share memory and log
    OS_logInit(NULL,0,1);


    pid = getpid();
    pthread_args = '0';

    
    
    // for our init
    check_times = 0;

    // got the argv[]
    //memset(command,0,4*1024);
    strcat(command,"1");
    for(circle = 0; circle < argc;circle++)
    {
        strcat(command,argv[circle]);
        strcat(command," ");
    }

    key = pid;
    //printf("key:%d\n",key);
    shared_mem = create_share_memory(key, SHARED_MEMORY_SIZE);
    	if(shared_mem == NULL)
	{
		OS_log(LVL_ERR,0,"get shared memory failed");
		return -1;
	}
     else
	{
        strcpy(shared_mem,command);
	}

    // init the socket
    bzero(&server_addr,sizeof(server_addr));

    server_addr.sin_family = AF_INET;
    server_addr.sin_port = htons(SERVER_PORT);

    // build the socket and do job
    if( inet_pton(AF_INET,SERVER_IP,&server_addr.sin_addr) <= 0)
    {
        ret = close_share_memory(shared_mem);
        perror("inet_pton error");
        return -1;
    }
    
    client_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
    server_len = sizeof(server_addr);

    sprintf(message_send,"%d",key);

    send_data_len = 0;
    send_data_len = sendto(client_sockfd,message_send,MAX_LENGTH,0,\
                        (struct sockaddr *)&server_addr,sizeof(server_addr));

    if(send_data_len < MAX_LENGTH)
    {
        printf("leave some data to send.");
    }
    else
    {
        while(shared_mem[0])
        {
            // check the status              
            usleep(SLEEP_TIME_UNIT);
            if(check_times++ > SLEEP_TIME_COUNT)
            {
                check_times = 0;
                printf("this program run 10s,pid=%d\n",key);
            }
        }          
    }       

    p_real_cmd = command +1;
    
    if(!memcmp(p_real_cmd,"jar",3))
    {
        p_real_cmd[2]='1';
        strcpy(kill_name,"ja1");
    }
    else if(!memcmp(p_real_cmd,"java",4))
    {
        p_real_cmd[3]='1';
        strcpy(kill_name,"jav1");
    }
    else
    {
        printf("cmd error:\n %s\n",p_real_cmd);
    }

    while(pthread_args != '1')
    {
        system_ret = 0;
        thread_pid = 0;
        OS_thread_create((OS_THREAD_FUNC)pthread_func,(void *)p_real_cmd);
        

        usleep(SLEEP_TIME_UNIT);

        

   #if 0     
        if((ret == 0)&&(pthread_args == '0'))
        {
            //说明没有找到应该存在的进程,这是不应该出现的现象。
            printf("\n running %s, but process not exist!\n",kill_name);
            sleep(1);
            system_ret = -1;
            break;
        }
   #endif
   
        if(!strcmp(kill_name,"ja1"))
        {
            monitor_time_cnt = THE_MAX_TIME_EXIT_THREAD;
            printf("\nkill_name = ja1\n");
        }
        else
        {
            monitor_time_cnt = 7*THE_MAX_TIME_EXIT_THREAD;
            printf("\nkill_name = jav1\n");
        }
            
        for(i=0;(i<monitor_time_cnt)&&(pthread_args == '0');i++)
        {
            usleep(SLEEP_TIME_UNIT);
            if(!thread_pid)
            {
                check_process_exist_ex(kill_name,&thread_pid,500);
            }
            // if pthread_args = '1' break;
        }
        
        if(pthread_args == '1')
        {
            break;
        }
        else
        {
            if(thread_pid)
            {
                sprintf(kill_command,"kill -9 %d",thread_pid);
                system(kill_command);
                printf("\n\nfound %s block, kill pid %d\n",kill_name,thread_pid);
            }
            else
            {
                printf("\n running %s, but process not exist!\n",kill_name);
            }

            sleep(1);
            //因为kill掉system拉起的线程后,而使
            if((pthread_args=='1')&&thread_pid)
                pthread_args = '0';
            else
            {
                printf("\nkill the thread,but pthread_args!=1 \n");
            }
        }
    }
    

    //ret = system(p_real_cmd);

    shared_mem[0] = '2';
    
    close_share_memory(shared_mem);
    
   
    return system_ret;
}