예제 #1
0
int main(void)
{
    replyq = msgq_init(1024, 1024);
    clientq = msgq_init(1024, 5);

    pthread_t reader_thread;
    pthread_t writer_thread;
    pthread_t timer_thread;
    pthread_t socket_thread;

    pthread_attr_t high;
    init_priority(&high, 60);
    
    pthread_create(&timer_thread,  &high, timer_start,  NULL);
    pthread_create(&reader_thread, &high, reader_start, NULL);
    pthread_create(&writer_thread, NULL,  writer_start, NULL);
    pthread_create(&socket_thread, NULL,  socket_start, NULL);
    
    pause();
    
    return 0;
}
예제 #2
0
//----------------------------------------------------------------------------------------------------//
//  @func - xilkernel_init
//! @desc
//!   Initialize the system - This function is called at the start of system.
//!   It initializes the system.
//!   - Initializes the process vector table.
//!   - Creates the Idle process (pid - 0).
//!   - Creates the static set of processes.
//! @return
//!   - Nothing.
//----------------------------------------------------------------------------------------------------//
void xilkernel_init(void)
{
    unsigned int i = 0 ;

    DBG_PRINT("XMK: Initializing Hardware.\r\n");
    hw_init();                                                  // Do hardware specific initialization

    DBG_PRINT("XMK: System initialization.\r\n");
    for( ; i < MAX_PROCESS_CONTEXTS; i++ ) {
        ptable[i].is_allocated = 0 ;
        ptable[i].pcontext.isrflag = 0;
    }

#ifdef MB_XILKERNEL
    kernel_sp = (void*)((unsigned int)&_stack + SSTACK_PTR_ADJUST);
#elif defined(PPC_XILKERNEL)
    kernel_sp = (void*)((unsigned int)&__stack + SSTACK_PTR_ADJUST);
#endif
    readyq_init();

#ifdef CONFIG_PTHREAD_SUPPORT
    pthread_init();
#endif
#ifdef CONFIG_SEMA
    sem_heap_init();
#endif
#ifdef CONFIG_MSGQ
    msgq_init();
#endif
#ifdef CONFIG_SHM
    shm_init();
#endif
#ifdef CONFIG_BUFMALLOC
    bufmalloc_init ();
#endif

    init_idle_task ();

#ifdef CONFIG_STATIC_ELF_PROCESS_SUPPORT
    se_process_init() ;                                           // Create statically specified separate executable processes
#endif

#ifdef CONFIG_STATIC_PTHREAD_SUPPORT
    kb_pthread_init ();                                           // Create statically specified kernel bundled threads
#endif

#ifdef CONFIG_TIME
    soft_tmr_init ();
#endif
}
예제 #3
0
파일: msgq_get.c 프로젝트: 01org/intelRSD
int
main(void)
{
    MsgQ_t      Q;
    MsgQ_t*     pQ = NULL;
    MsgQ_t      zeroed_q;
    MsgQ_t      bogus_q;
    MsgQ_t      valid_q;
    Message_t   Msg;
    Message_t   NullMsg;
    Message_t   Req_m;
    Message_t*  pMsg = NULL;
    Message_t*  pNULLMsg = NULL;
    Message_t   zeroed_m;
    Message_t   bogus_m;
    Message_t   array_m[3];
    IpmbReq_t*  pReq     = (IpmbReq_t*)(Req_m.Data);
    size_t      old_head;
    size_t      old_tail;

    bzero(&zeroed_q, sizeof(zeroed_q));
    bzero(&zeroed_m, sizeof(zeroed_m));
    bzero(&Req_m, sizeof(Req_m));
    bzero(&array_m, sizeof(array_m));
    bzero(&NullMsg, sizeof(NullMsg));
    memset(&bogus_m, 1, sizeof(bogus_m));
    memset(&bogus_q, 1, sizeof(bogus_q));
    Q = bogus_q;
    valid_q = zeroed_q;

    Req_m.DstAddr = 0x24;
    Req_m.Length = sizeof(IpmbReq_t) + 1UL;
    pReq->NetFn = 0x6 << 2;
    pReq->MasterAddr = 0x10;
    pReq->SeqNum = 0x30;
    pReq->Command = 1;
    checksum(&Req_m);


    plan(56);

    Msg = NullMsg;
    ok(EINVAL == msgq_get(pQ, &Msg), "get returns error when passed NULL Q pointer");
    ok(0 == memcmp(&Msg, &NullMsg, sizeof(NullMsg)), "Message block untouched");
    ok(0 == mock_pthread_mutex_lock_count, "pthread_mutex_lock not called");
    ok(0 == mock_pthread_mutex_unlock_count, "pthread_mutex_unlock not called");

    ok(0 == msgq_init(&valid_q, 2), "Successfully initialized Message Q");
    Msg = Req_m;
    ok(0 == msgq_post(&valid_q, &Msg), "Successfully posted single valid message");
    pMsg = valid_q.queue;
    memcpy(array_m, pMsg, sizeof(array_m));
    Q = valid_q;
    mock_pthread_mutex_lock_count = mock_pthread_mutex_unlock_count = 0;
    ok(EINVAL == msgq_get(&Q, pNULLMsg), "get returns error when passed NULL message pointer");
    ok(valid_q.queue == pMsg, "queue pointer didn't change");
    ok(0 == memcmp(&Q, &valid_q, sizeof(valid_q)), "Q block untouched");
    ok(0 == memcmp(pMsg, array_m, sizeof(array_m)), "queue untouched");
    ok(0 == mock_pthread_mutex_lock_count, "pthread_mutex_lock not called");
    ok(0 == mock_pthread_mutex_unlock_count, "pthread_mutex_unlock not called");

    mock_pthread_mutex_lock_count = mock_pthread_mutex_unlock_count = 0;
    ok(EINVAL == msgq_get(pQ, pNULLMsg), "get returns error when passed NULL message & Q pointers");
    ok(0 == mock_pthread_mutex_lock_count, "pthread_mutex_lock not called");
    ok(0 == mock_pthread_mutex_unlock_count, "pthread_mutex_unlock not called");

    valid_q.queue = pMsg;
    Q = valid_q;
    Msg = NullMsg;
    memcpy(pMsg, array_m, sizeof(array_m));
    // corrupt by removing queue
    Q.queue = NULL;
    ok(EINVAL == msgq_get(&Q, &Msg), "get returns error when Q's queue is NULL");
    ok(0 == memcmp(&Msg, &NullMsg, sizeof(NullMsg)), "Message was untouched");
    Q.queue = pMsg;
    ok(0 == memcmp(&Q, &valid_q, sizeof(valid_q)), "Q was untouched");
    ok(0 == memcmp(pMsg, array_m, sizeof(array_m)), "queue untouched");
    ok(0 == mock_pthread_mutex_lock_count, "pthread_mutex_lock not called");
    ok(0 == mock_pthread_mutex_unlock_count, "pthread_mutex_unlock not called");

    valid_q.queue = pMsg;
    Q = valid_q;
    Msg = NullMsg;
    memcpy(pMsg, array_m, sizeof(array_m));
    // corrupt size
    Q.size = 1;
    ok(EINVAL == msgq_get(&Q, &Msg), "get returns error when Q's size is < 2");
    ok(0 == memcmp(&Msg, &NullMsg, sizeof(NullMsg)), "Message was untouched");
    Q.size = valid_q.size;
    ok(0 == memcmp(&Q, &valid_q, sizeof(valid_q)), "Q was untouched");
    ok(0 == memcmp(pMsg, array_m, sizeof(array_m)), "queue untouched");
    ok(0 == mock_pthread_mutex_lock_count, "pthread_mutex_lock not called");
    ok(0 == mock_pthread_mutex_unlock_count, "pthread_mutex_unlock not called");

    valid_q.queue = pMsg;
    Q = valid_q;
    Msg = NullMsg;
    memcpy(pMsg, array_m, sizeof(array_m));
    mock_pthread_mutex_lock_failure = EIO;
    mock_pthread_mutex_lock_count = 0;
    ok(EIO == msgq_get(&Q, &Msg), "get returns error on pthread_mutex_lock failure");
    ok(0 == memcmp(&Q, &valid_q, sizeof(valid_q)), "Q was untouched");
    ok(0 == memcmp(pMsg, array_m, sizeof(array_m)), "queue untouched");
    ok(0 == memcmp(&Msg, &NullMsg, sizeof(NullMsg)), "Message was untouched");
    ok(1 == mock_pthread_mutex_lock_count, "pthread_mutex_lock was called");
    ok(0 == mock_pthread_mutex_unlock_count, "pthread_mutex_unlock not called");

    valid_q.queue = pMsg;
    Q = valid_q;
    Msg = NullMsg;
    old_head = Q.head;
    old_tail = Q.tail;
    Q.head = Q.tail;
    memcpy(pMsg, array_m, sizeof(array_m));
    mock_pthread_mutex_lock_failure = 0;
    mock_pthread_cond_wait_failure = EINTR;
    mock_pthread_mutex_lock_count =
    mock_pthread_mutex_unlock_count =
    mock_pthread_cond_wait_count = 0;
    ok(EINTR == msgq_get(&Q, &Msg), "get returns error on pthread_cond_wait failure");
    ok(Q.head == old_tail, "Head pointer untouched");
    Q.head = old_head;
    ok(0 == memcmp(&Q, &valid_q, sizeof(valid_q)), "Q was untouched");
    ok(0 == memcmp(pMsg, array_m, sizeof(array_m)), "queue untouched");
    ok(0 == memcmp(&Msg, &NullMsg, sizeof(NullMsg)), "Message was untouched");
    ok(1 == mock_pthread_mutex_lock_count, "pthread_mutex_lock was called");
    ok(1 == mock_pthread_cond_wait_count, "pthread_cond_wait_count was called");
    ok(1 == mock_pthread_mutex_unlock_count, "pthread_mutex_unlock was called");

    valid_q.queue = pMsg;
    Q = valid_q;
    old_head = Q.head;
    old_tail = Q.tail;
    Q.head = Q.tail;
    memcpy(pMsg, array_m, sizeof(array_m));
    Msg = NullMsg;
    mock_pthread_mutex_lock_failure = 0;
    mock_pthread_cond_wait_failure = EINTR;
    mock_pthread_mutex_unlock_failure = EIO;
    mock_pthread_mutex_lock_count =
    mock_pthread_mutex_unlock_count =
    mock_pthread_cond_wait_count = 0;
    ok(EINTR == msgq_get(&Q, &Msg), "get returns error on pthread_cond_wait failure (not unlock)");
    ok(Q.head == old_tail, "Head pointer untouched");
    Q.head = old_head;
    ok(0 == memcmp(&Q, &valid_q, sizeof(valid_q)), "Q was untouched");
    ok(0 == memcmp(pMsg, array_m, sizeof(array_m)), "queue untouched");
    ok(0 == memcmp(&Msg, &NullMsg, sizeof(NullMsg)), "Message was untouched");
    ok(1 == mock_pthread_mutex_lock_count, "pthread_mutex_lock was called");
    ok(1 == mock_pthread_cond_wait_count, "pthread_cond_wait was called");
    ok(1 == mock_pthread_mutex_unlock_count, "pthread_mutex_unlock was called");

    valid_q.queue = pMsg;
    Q = valid_q;
    memcpy(pMsg, array_m, sizeof(array_m));
    Msg = NullMsg;
    mock_pthread_mutex_lock_failure = 0;
    mock_pthread_mutex_lock_count = 0;
    mock_pthread_cond_wait_failure = 0;
    mock_pthread_mutex_unlock_failure = 0;
    mock_pthread_mutex_unlock_count =
    mock_pthread_cond_signal_count =
    mock_pthread_cond_wait_count = 0;
    ok(0 == msgq_get(&Q, &Msg), "get succeeds");
    ok(Q.head == Q.tail, "Pointers updated reasonably");
    ok(0 == memcmp(&Msg, &Req_m, sizeof(Req_m)), "Message was updated");
    ok(1 == mock_pthread_mutex_lock_count, "pthread_mutex_lock was called");
    ok(0 == mock_pthread_cond_wait_count, "pthread_cond_wait_count was called");
    ok(1 == mock_pthread_cond_signal_count, "pthread_cond_signal was called");
    ok(1 == mock_pthread_mutex_unlock_count, "pthread_mutex_unlock was called");

    free(valid_q.queue);
}
예제 #4
0
파일: main.c 프로젝트: zhanglong71/Demo
int main()
{
    int i;
	msg_t msg;
	func_t func;
	
/** 外设初始化开始 **/
	Peripheral_Init();
/** 外设初始化结束 **/

    charQueueInit(&g_com1TxQue);
    //charQueueInit(&g_com2TxQue);
    MFPACK_FIFO_CLEAN("清空指纹传感器缓冲区");
    MBTACK_FIFO_CLEAN("清空蓝牙接收缓冲区");
    actionQueueInit(&g_actionQueue, &(g_timer[1]), CACT_TOUT, CACT_OVER);
    actionQueueInit(&g_promptQueue, &(g_timer[2]), CPMT_TOUT, CPMT_OVER);
    actionQueueInit(&g_blinkQueue, &(g_timer[3]), CBLK_TOUT, CBLK_OVER);
    
    adcSample_Init(&g_adcData, &(g_timer[4]), CADC_TOUT, TIMER_300MS);
    
    for(i = 0; i < TIMER_NUM; i++) {
        ClrTimer(&g_timer[i]);
    }
    
    //SetTimer(&g_timer[0], TIMER_1SEC, CMSG_TMR);
    msgq_init(&g_msgq);
    
	#if	1
	msg.msgType = CMSG_PWON;
	msgq_in(&g_msgq, &msg);
	
	fstack_init(&g_fstack);
    func.func = f_idle;
    fstack_push(&g_fstack, &func);
	#endif
	
	AWU_Config();
	//enableInterrupts();
	IRQ_enable();
	//MIRQ_disable();
	/* Infinite loop */
	while(1)
	{
        //IWDG_ReloadCounter();
        
       	//Refresh_WWDG_Window();
       	//Test_WWDGReset();
       	
        keyscan();
        //vop_busy();
        //fingerCheck();
        PeripheralInput_Check();
        
        DAEMON_USART1_Send(&g_com1TxQue);   /** output to fingerprint **/
        DAEMON_USART3_Send(&g_com3TxQue);   /** output to bluetooth **/
        //DAEMON_USART1_Recive(&g_comRevBuf);
        
        actionDoing(&g_actionQueue);
        actionDoing(&g_promptQueue);
        actionDoing(&g_blinkQueue);

		if(msgq_out_irq(&g_msgq, &msg) == FALSE) {     	/** 有消息吗? **/
			continue;
		}
		if(sysProcess(&msg) == TRUE) {   			/** 是系统消息吗? **/
			continue;
		}

		if(fstack_top(&g_fstack, &func) == FALSE) {    /** 当前处于工作状态吗? **/
		  /** something wrong happend, Power Down or recover it **/
		  	fstack_init(&g_fstack);
			func.func = f_idle;
			fstack_push(&g_fstack, &func);
			
			g_tick = 0;
			SetTimer_irq(&g_timer[0], TIMER_1SEC, CMSG_TMR);
			continue;
		}
		func.func((unsigned *)&msg);
	}
}