コード例 #1
0
ファイル: main.c プロジェクト: c1728p9/DAPLink_old
__task void serial_process()
{
    UART_Configuration config;
    int32_t len_data = 0;
    void *msg;

    while (1) {
        // Check our mailbox to see if we need to set anything up with the UART
        // before we do any sending or receiving
        if (os_mbx_wait(&serial_mailbox, &msg, 0) == OS_R_OK) {
            switch((SERIAL_MSG)(unsigned)msg) {
                case SERIAL_INITIALIZE:
                    uart_initialize();
                    break;

                case SERIAL_UNINITIALIZE:
                    uart_uninitialize();
                    break;

                case SERIAL_RESET:
                    uart_reset();
                    break;

                case SERIAL_SET_CONFIGURATION:
                    serial_get_configuration(&config);
                    uart_set_configuration(&config);
                    break;

                default:
                    break;
            }
        }

        len_data = USBD_CDC_ACM_DataFree();
        if (len_data > SIZE_DATA) {
            len_data = SIZE_DATA;
        }
        if (len_data) {
            len_data = uart_read_data(data, len_data);
        }
        if (len_data) {
            if(USBD_CDC_ACM_DataSend(data , len_data)) {
                main_blink_cdc_led(MAIN_LED_OFF);
            }
        }

        len_data = uart_write_free();
        if (len_data > SIZE_DATA) {
            len_data = SIZE_DATA;
        }
        if (len_data) {
            len_data = USBD_CDC_ACM_DataRead(data, len_data);
        }
        if (len_data) {
            if (uart_write_data(data, len_data)) {
                main_blink_cdc_led(MAIN_LED_OFF);
            }
        }
    }
}
コード例 #2
0
/*----------------------------------------------------------------------------
 *  Task 2: RTX Kernel starts this task with os_tsk_create (consumer_task, 0)
 *---------------------------------------------------------------------------*/
__task void consumer_task (void) {

	OS_TID consumer_tskid;                          /* assigned identification for consumer */
	
	consumer_tskid = os_tsk_self();									/* get it's own task ID */
	
	T_NUM *random_num_rx;

	while( msg_counter_rec < N )
	{
		os_mbx_wait (MsgBox, (void **)&random_num_rx, 0xffff); /* wait for the message    */
		
		os_mut_wait(g_mut_uart, 0xFFFF);
		printf("[consumer_task [pid:(%d)] ]: Received %u\n", consumer_tskid, random_num_rx->number);
		msg_counter_rec += 1;
		os_mut_release(g_mut_uart);
		
		if( _free_box (mpool, random_num_rx) )           /* free memory allocated for message  */
		{
			os_mut_wait(g_mut_uart, 0xFFFF);
			printf("_free_box failed because memory couldn't be freed\n");
			os_mut_release(g_mut_uart);
			exit(1);
			
		}
	}


	//Get Time C 
	time_c = os_time_get();
	
	os_mut_wait(g_mut_uart, 0xFFFF);
	printf("Time to initialize system: %0.6f\n", (float)(((float)time_b - time_a)/1000000) );
	printf("Time to transmit data: %0.6f\n", (float)(((float)time_c - time_b)/1000000) );
	os_mut_release(g_mut_uart);

	// os_dly_wait(10);
	os_tsk_delete_self ();              /* We are done here, delete this task  */
}