예제 #1
0
/** Unit test to check that the Membag allocates small and large chunks of
 *  memory correctly, and fails when a chunk that is too large is requested.
 *
 *  \param test  Pointer to the unit test case instance
 */
static void run_membag_alloc_test(const struct test_case *test)
{
    void *data;

    /* Initialize membag system. */
    membag_init();

    /* Try to allocate a small chunk, should succeed. */
    data = membag_alloc(CONF_TEST_ALLOC_SIZE_SMALL);

    test_assert_false(test, data == NULL,
                      "Unable to allocate a small chunk!");

    /* Re-initialize the membag system. */
    membag_init();

    /* Try to allocate a large chunk, should succeed. */
    data = membag_alloc(CONF_TEST_ALLOC_SIZE_LARGE);

    test_assert_false(test, data == NULL,
                      "Unable to allocate a large chunk!");

    /* Try to allocate a massive (too large) chunk, should fail. */
    data = membag_alloc(CONF_TEST_ALLOC_SIZE_TOO_LARGE);

    test_assert_true(test, data == NULL,
                     "Should not be able to allocate a too-large chunk!");
}
예제 #2
0
/** Unit test to check that the Membag is initialized and re-initialized
 *  correctly.
 *
 *  \param test  Pointer to the unit test case instance
 */
static void run_membag_init_test(const struct test_case *test)
{
    /* Initialize membag system. */
    membag_init();

    /* Check that no memory is currently allocated */
    test_assert_true(test, membag_get_total() == membag_get_total_free(),
                     "Initialized membag should contain no allocated memory!");

    /* Allocate a small chunk of memory */
    membag_alloc(CONF_TEST_ALLOC_SIZE_SMALL);

    /* Check that sufficient memory was allocated */
    test_assert_false(test,
                      (membag_get_total() - membag_get_total_free()) < CONF_TEST_ALLOC_SIZE_SMALL,
                      "Not enough memory was allocated!");

    /* Re-Initialize membag system. */
    membag_init();

    /* Check that no memory is now allocated */
    test_assert_true(test,
                     membag_get_total() == membag_get_total_free(),
                     "Re-Initialized membag should contain no allocated memory!");
}
예제 #3
0
/**
 * \brief Main application function
 *
 * This function calls all the necessary initialization functions before
 * launching the calculator widget and entering the main work loop.
 *
 * The main work loop is responsible for handling the low level user input, so
 * it reads touch data from the mXT143E Xplained, translates and passes it on to
 * the window system's event queue.
 *
 * All the processing for the calculator is done by the calculator widget's
 * event handler function \ref app_calc_handler(). This function is called by
 * the window system when it maps a user input event to an interaction with the
 * calculator, i.e., a button press.
 */
int main(void)
{
	static struct mxt_device device;

	board_init();
	sysclk_init();
	membag_init();

	gfx_init();
	mxt_init(&device);
	win_init();

	setup_gui_root_window();
	win_reset_root_geometry();
	if (app_widget_launch() == false) {
		show_out_of_memory_error();
		for (;;);
	}

	while (true) {
		struct win_pointer_event win_touch_event;

		/* Queue touch events from the touchscreen if any are available */
		while (read_touch_event(&device, &win_touch_event)) {
			win_queue_pointer_event(&win_touch_event);
		}

		/* Process queued events in the windowing system */
		win_process_events();
	}
}
예제 #4
0
/** Unit test to check that the Membag re-allocates previously allocated and
 *  subsequently freed blocks of memory correctly.
 *
 *  \param test  Pointer to the unit test case instance
 */
static void run_membag_realloc_test(const struct test_case *test)
{
    void *data;

    /* Initialize membag system. */
    membag_init();

    /* Allocate as many small chunks as there are sufficiently sized blocks. */
    while (membag_get_largest_free_block_size() >=
            CONF_TEST_ALLOC_SIZE_SMALL) {
        data = membag_alloc(CONF_TEST_ALLOC_SIZE_SMALL);

        test_assert_false(test, data == NULL,
                          "Unable to allocate a small chunk!");
    }

    /* Free last allocated chunk of memory */
    membag_free(data);

    /* Re-allocate a small chunk, should succeed by re-using the last freed
     * block of memory. */
    data = membag_alloc(CONF_TEST_ALLOC_SIZE_SMALL);

    test_assert_false(test, data == NULL,
                      "Unable to re-allocate a small chunk!");
}
예제 #5
0
/** Unit test to check that the Membag functions to determine memory status work
 *  correctly.
 *
 *  \param test  Pointer to the unit test case instance
 */
static void run_membag_get_test(const struct test_case *test)
{
    void *data;
    size_t prev_total_free, chunk_size;

    /* Initialize membag system. */
    membag_init();

    prev_total_free = membag_get_total_free();

    /* Keep allocating chunks until all memory allocated */
    while (membag_get_total_free() > 0) {
        /* Keep track of how much memory we have left and the largest
         * block size */
        prev_total_free = membag_get_total_free();
        chunk_size = membag_get_largest_free_block_size();

        /* Allocate the next largest block sized chunk of memory */
        data = membag_alloc(chunk_size);
        test_assert_false(test, data == NULL,
                          "Unable to allocate a block sized chunk!");

        /* Check that the new memory usage was calculated correctly */
        test_assert_true(test, membag_get_total_free() ==
                         (prev_total_free - chunk_size),
                         "Failed to calculate correct memory usage!");
    }
}
예제 #6
0
/** Unit test to check that the Membag frees previously allocated memory
 *  correctly.
 *
 *  \param test  Pointer to the unit test case instance
 */
static void run_membag_free_test(const struct test_case *test)
{
    void *data1, *data2, *data3;

    /* Initialize membag system. */
    membag_init();

    /* Allocate three small chunks of data. */
    data1 = membag_alloc(CONF_TEST_ALLOC_SIZE_SMALL);
    data2 = membag_alloc(CONF_TEST_ALLOC_SIZE_SMALL);
    data3 = membag_alloc(CONF_TEST_ALLOC_SIZE_SMALL);

    /* Check that all three membag allocations completed successfully. */
    test_assert_false(test, (data1 == NULL) || (data2 == NULL) ||
                      (data3 == NULL),
                      "Less than three small chunks were allocated!");

    /* Check that all three membag allocations actually reserved sufficient
     *memory. */
    test_assert_false(test,
                      (membag_get_total() - membag_get_total_free()) <
                      (CONF_TEST_ALLOC_SIZE_SMALL * 3),
                      "Not enough memory was allocated!");

    membag_free(data1);
    membag_free(data2);
    membag_free(data3);

    /* Check that all memory has been returned to the membag. */
    test_assert_true(test, membag_get_total() == membag_get_total_free(),
                     "Not all memory is free!");
}
예제 #7
0
파일: main.c 프로젝트: Timvrakas/samd21_gcc
/**
 * \brief Main application function
 *
 * This function executes the necessary initialization calls and displays the
 * demo widgets before entering the main work loop of the application.
 *
 * The main work loop reads out the touch events from the mXT143E Xplained and
 * enqueues the corresponding touch events in the window system, before
 * processing the window system's event queue.
 */
int main(void)
{
	static struct mxt_device device;

	board_init();
	sysclk_init();
	membag_init();
	gfx_init();
	mxt_init(&device);
	win_init();

	setup_root_window();
	app_widget_launch();

	while (true) {
		/* Process received messages from the maXTouch device */
		while (mxt_is_message_pending(&device)) {
			struct mxt_touch_event touch_event;
			struct win_pointer_event win_touch_event;

			/* Get the first touch event in queue */
			if (mxt_read_touch_event(&device,
					&touch_event) != STATUS_OK) {
				continue;
			}

			/* Translate touch event type into a WTK event type */
			if (touch_event.status & MXT_PRESS_EVENT) {
				win_touch_event.type = WIN_POINTER_PRESS;
			} else if (touch_event.status & MXT_MOVE_EVENT) {
				win_touch_event.type = WIN_POINTER_MOVE;
			} else if (touch_event.status & MXT_RELEASE_EVENT) {
				win_touch_event.type = WIN_POINTER_RELEASE;
			} else {
				continue;
			}

			/* Indicate the touch event is a non-relative movement
			 * with the virtual touch button pressed
			 */
			win_touch_event.is_relative = false;
			win_touch_event.buttons = WIN_TOUCH_BUTTON;

			/* Translate the touch X and Y position into a screen
			 * coordinate
			 */
			win_touch_event.pos.x =
					((uint32_t)(4096 - touch_event.x) * gfx_get_width()) / 4096;
			win_touch_event.pos.y =
					((uint32_t)(4096 - touch_event.y) * gfx_get_height()) / 4096;
			win_queue_pointer_event(&win_touch_event);
		}

		/* Process queued events in the windowing system */
		win_process_events();
	}
}
예제 #8
0
/** Unit test to check that the Membag allocations fail once all suitable bags
 * are already
 *  allocated.
 *
 *  \param test  Pointer to the unit test case instance
 */
static void run_membag_alloc_when_full_test(const struct test_case *test)
{
    void *data;

    /* Initialize membag system. */
    membag_init();

    /* Allocate as many small chunks as there are sufficiently sized blocks. */
    while (membag_get_largest_free_block_size() >=
            CONF_TEST_ALLOC_SIZE_SMALL) {
        data = membag_alloc(CONF_TEST_ALLOC_SIZE_SMALL);

        test_assert_false(test, data == NULL,
                          "Unable to allocate a small chunk!");
    }

    /* Try to allocate one more small chunk, should fail */
    data = membag_alloc(CONF_TEST_ALLOC_SIZE_SMALL);

    test_assert_true(test, data == NULL,
                     "Should not be able to allocate small chunk while full!");

    /* Re-initialize the membag system. */
    membag_init();

    /* Allocate as many large chunks as there are sufficiently sized blocks. */
    while (membag_get_largest_free_block_size() >=
            CONF_TEST_ALLOC_SIZE_LARGE) {
        data = membag_alloc(CONF_TEST_ALLOC_SIZE_LARGE);

        test_assert_false(test, data == NULL,
                          "Unable to allocate a large chunk!");
    }

    /* Try to allocate one more large chunk, should fail */
    data = membag_alloc(CONF_TEST_ALLOC_SIZE_LARGE);

    test_assert_true(test, data == NULL,
                     "Should not be able to allocate large chunk while full!");
}
예제 #9
0
/*
*	Main program loop
*
*/
int main (void)
{
	char cCommand[64];
	char cCommand_last[64];
	memset(&cCommand, 0, sizeof(cCommand));
	memset(&cCommand_last, 0, sizeof(cCommand_last));
	cCommand[0] = '\0';
	charcount = 0;
	struct ip_addr x_ip_addr, x_net_mask, x_gateway;

	sysclk_init();
	board_init();

	// Set up the GPIO pin for the Mater Select jumper
	ioport_init();
	ioport_set_pin_dir(MASTER_SEL, IOPORT_DIR_INPUT);

	masterselect = ioport_get_pin_level(MASTER_SEL);	// true = slave
	stacking_init(masterselect);	// Initialise the stacking connector as either master or slave

	// Set the IRQ line as either master or slave
	if(masterselect) {
		ioport_set_pin_dir(SPI_IRQ1, IOPORT_DIR_OUTPUT);
	} else {
		ioport_set_pin_dir(SPI_IRQ1, IOPORT_DIR_INPUT);
	}

	irq_initialize_vectors(); // Initialize interrupt vector table support.

	cpu_irq_enable(); // Enable interrupts

	stdio_usb_init();
	spi_init();
	eeprom_init();
	temp_init();
	membag_init();

	loadConfig(); // Load Config

	IP4_ADDR(&x_ip_addr, Zodiac_Config.IP_address[0], Zodiac_Config.IP_address[1],Zodiac_Config.IP_address[2], Zodiac_Config.IP_address[3]);
	IP4_ADDR(&x_net_mask, Zodiac_Config.netmask[0], Zodiac_Config.netmask[1],Zodiac_Config.netmask[2], Zodiac_Config.netmask[3]);
	IP4_ADDR(&x_gateway, Zodiac_Config.gateway_address[0], Zodiac_Config.gateway_address[1],Zodiac_Config.gateway_address[2], Zodiac_Config.gateway_address[3]);

	switch_init();

	/* Initialize lwIP. */
	lwip_init();

	/* Add data to netif */
	netif_add(&gs_net_if, &x_ip_addr, &x_net_mask, &x_gateway, NULL, ethernetif_init, ethernet_input);

	/* Make it the default interface */
	netif_set_default(&gs_net_if);

	netif_set_up(&gs_net_if);

	// Telnet to be included in v0.63
	//telnet_init();

	/* Initialize timer. */
	sys_init_timing();

	int v,p;
	// Create port map
	for (v = 0;v < MAX_VLANS;v++)
	{
		if (Zodiac_Config.vlan_list[v].uActive == 1 && Zodiac_Config.vlan_list[v].uVlanType == 1)
		{
			for(p=0;p<4;p++)
			{
				if (Zodiac_Config.vlan_list[v].portmap[p] == 1) Zodiac_Config.of_port[p] = 1; // Port is assigned to an OpenFlow VLAN
			}
		}

		if (Zodiac_Config.vlan_list[v].uActive == 1 && Zodiac_Config.vlan_list[v].uVlanType == 2)
		{
			for(p=0;p<4;p++)
			{
				if (Zodiac_Config.vlan_list[v].portmap[p] == 1)
				{
					Zodiac_Config.of_port[p] = 0; // Port is assigned to a Native VLAN
					NativePortMatrix += 1<<p;
				}
			}
		}
	}

	while(1)
	{
		task_switch(&gs_net_if);
		task_command(cCommand, cCommand_last);
		// Only run the following tasks if set to Master
		if(masterselect == false)
		{
			sys_check_timeouts();
			task_openflow();	
		} 
	}
}
예제 #10
0
파일: demo.c 프로젝트: thegeek82000/asf
/** \brief Main function. Execution starts here.
 */
int main(void)
{
	uint8_t uc_result;

	/* Initialize the sleep manager */
	sleepmgr_init();
	membag_init();
	sysclk_init();
	init_specific_board();

	/* Initialize the console uart */
	configure_console();

	/* Output demo infomation. */
	printf("-- SAM Toolkit Demo Example --\n\r");
	printf("-- %s\n\r", BOARD_NAME);
	printf("-- Compiled: %s %s --\n\r", __DATE__, __TIME__);
	/* Configure systick for 1 ms. */
	puts("Configure system tick to get 1ms tick period.\r");
	if (SysTick_Config(sysclk_get_cpu_hz() / 1000)) {
		puts("Systick configuration error\r");
		while (1) {
		}
	}

	/* Initialize gfx module */
	gfx_init();
	win_init();

	/* Initialize FatFS and bitmap draw interface */
	demo_draw_bmpfile_init();

	/* Initialize touchscreen without calibration */
	rtouch_init(LCD_WIDTH, LCD_HEIGHT);
	rtouch_enable();
	rtouch_set_event_handler(event_handler);

	/* Initialize demo parameters */
	demo_parameters_initialize();
	while (g_demo_parameters.calib_points[0].raw.x == 0) {
		uc_result = rtouch_calibrate();
		if (uc_result == 0) {
			demo_set_special_mode_status(DEMO_LCD_CALIBRATE_MODE, 0);
			puts("Calibration successful !\r");
			break;
		} else {
			puts("Calibration failed; error delta is too big ! Please retry calibration procedure...\r");
		}
	}

	/* Re-caculate the calibration data */
	rtouch_compute_calibration(
			(rtouch_calibration_point_t *)&g_demo_parameters.calib_points[0]);

	/* Setup root window */
	setup_gui_root_window();
	gfx_draw_bitmap(&win_startup_bmp, 0, 40);

	/* Set backlight by the data read from demo parameters */
	aat31xx_set_backlight(g_demo_parameters.backlight);

	/* Default RTC configuration, 24-hour mode */
	rtc_set_hour_mode(RTC, 0);
	rtc_set_time(RTC, g_demo_parameters.hour, g_demo_parameters.minute,
			g_demo_parameters.second);
	rtc_set_date( RTC, g_demo_parameters.year, g_demo_parameters.month,
			g_demo_parameters.day, 1 );

	/* Create a semaphore to manage the memories data transfer */
	vSemaphoreCreateBinary(main_trans_semphr);

	/* Turn on main widget */
	app_widget_main_on(true);

	/* Initialize QTouch */
	demo_qt_init();

	/* Start USB stack to authorize VBus monitoring */
	udc_start();
	if (!udc_include_vbus_monitoring()) {
		/* VBUS monitoring is not available on this product
		 * thereby VBUS has to be considered as present */
		main_vbus_action(true);
	}

	/* Create task to window task */
	if (xTaskCreate(task_win, "WIN", TASK_WIN_STACK_SIZE, NULL,
			TASK_WIN_STACK_PRIORITY, NULL) != pdPASS) {
		printf("Failed to create test led task\r\n");
	}

	/* Create task to usb mass storage task */
	if (xTaskCreate(task_usb, "USB", TASK_USB_STACK_SIZE, NULL,
			TASK_USB_STACK_PRIORITY, NULL) != pdPASS) {
		printf("Failed to create test led task\r\n");
	}

	/* Start the scheduler. */
	vTaskStartScheduler();

	/* Will only get here if there was insufficient memory to create the
	 * idle task. */
	return 0;
}