Convert to UNIX CR/LF.

This commit is contained in:
Joel Sherrill 2012-03-20 09:13:05 -05:00
parent c8f671afa1
commit 66e89993e0
2 changed files with 393 additions and 393 deletions

View File

@ -1,328 +1,328 @@
/** /**
* @file * @file
* *
* @brief File system test. * @brief File system test.
*/ */
/* /*
* Copyright (c) 2010 embedded brains GmbH. All rights reserved. * Copyright (c) 2010 embedded brains GmbH. All rights reserved.
* *
* embedded brains GmbH * embedded brains GmbH
* Obere Lagerstr. 30 * Obere Lagerstr. 30
* 82178 Puchheim * 82178 Puchheim
* Germany * Germany
* <rtems@embedded-brains.de> * <rtems@embedded-brains.de>
* *
* The license and distribution terms for this file may be * The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at * found in the file LICENSE in this distribution or at
* http://www.rtems.com/license/LICENSE. * http://www.rtems.com/license/LICENSE.
*/ */
#include <assert.h> #include <assert.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <inttypes.h> #include <inttypes.h>
#include <pthread.h> #include <pthread.h>
#include <rtems.h> #include <rtems.h>
#include <rtems/media.h> #include <rtems/media.h>
#include <rtems/chain.h> #include <rtems/chain.h>
#include <rtems/libio_.h> #include <rtems/libio_.h>
#include <rtems/shell.h> #include <rtems/shell.h>
#include <rtems/console.h> #include <rtems/console.h>
#include <rtems/diskdevs.h> #include <rtems/diskdevs.h>
#include <freebsd/bsd.h> #include <freebsd/bsd.h>
#include "test.h" #include "test.h"
#define ASSERT_SC(sc) assert((sc) == RTEMS_SUCCESSFUL) #define ASSERT_SC(sc) assert((sc) == RTEMS_SUCCESSFUL)
#define ASSERT_ENO(eno) assert((eno) == 0) #define ASSERT_ENO(eno) assert((eno) == 0)
#define WORKER_COUNT 13 #define WORKER_COUNT 13
#define WORKER_EVENT RTEMS_EVENT_13 #define WORKER_EVENT RTEMS_EVENT_13
void test_file_system(unsigned index, const char *disk_path, const char *mount_path); void test_file_system(unsigned index, const char *disk_path, const char *mount_path);
typedef struct { typedef struct {
rtems_chain_node node; rtems_chain_node node;
char *disk_or_partition_path; char *disk_or_partition_path;
rtems_id task; rtems_id task;
} worker; } worker;
static worker worker_table [WORKER_COUNT]; static worker worker_table [WORKER_COUNT];
RTEMS_CHAIN_DEFINE_EMPTY(free_worker_list); RTEMS_CHAIN_DEFINE_EMPTY(free_worker_list);
static const rtems_name WORKER_NAME = rtems_build_name('W', 'O', 'R', 'K'); static const rtems_name WORKER_NAME = rtems_build_name('W', 'O', 'R', 'K');
static pthread_mutex_t worker_mutex; static pthread_mutex_t worker_mutex;
static pthread_cond_t worker_changed; static pthread_cond_t worker_changed;
static void add_worker_to_free_list(worker *w) static void add_worker_to_free_list(worker *w)
{ {
rtems_chain_append(&free_worker_list, &w->node); rtems_chain_append(&free_worker_list, &w->node);
} }
static worker *get_free_worker(void) static worker *get_free_worker(void)
{ {
return (worker *) rtems_chain_get(&free_worker_list); return (worker *) rtems_chain_get(&free_worker_list);
} }
static void activate_worker(char *disk_or_partition_path) static void activate_worker(char *disk_or_partition_path)
{ {
rtems_status_code sc = RTEMS_SUCCESSFUL; rtems_status_code sc = RTEMS_SUCCESSFUL;
worker *w = get_free_worker(); worker *w = get_free_worker();
if (w != NULL) { if (w != NULL) {
w->disk_or_partition_path = disk_or_partition_path; w->disk_or_partition_path = disk_or_partition_path;
sc = rtems_event_send(w->task, WORKER_EVENT); sc = rtems_event_send(w->task, WORKER_EVENT);
ASSERT_SC(sc); ASSERT_SC(sc);
} else { } else {
free(disk_or_partition_path); free(disk_or_partition_path);
} }
} }
static worker *find_worker_for_disk_or_partition(const char *disk_or_partition_path) static worker *find_worker_for_disk_or_partition(const char *disk_or_partition_path)
{ {
size_t i = 0; size_t i = 0;
for (i = 0; i < WORKER_COUNT; ++i) { for (i = 0; i < WORKER_COUNT; ++i) {
worker *w = &worker_table [i]; worker *w = &worker_table [i];
if (w->disk_or_partition_path != NULL && strcmp(w->disk_or_partition_path, disk_or_partition_path) == 0) { if (w->disk_or_partition_path != NULL && strcmp(w->disk_or_partition_path, disk_or_partition_path) == 0) {
return w; return w;
} }
} }
return NULL; return NULL;
} }
static void wait_for_worker_finished(const char *disk_or_partition_path) static void wait_for_worker_finished(const char *disk_or_partition_path)
{ {
int eno = 0; int eno = 0;
worker *w = NULL; worker *w = NULL;
eno = pthread_mutex_lock(&worker_mutex); eno = pthread_mutex_lock(&worker_mutex);
ASSERT_ENO(eno); ASSERT_ENO(eno);
w = find_worker_for_disk_or_partition(disk_or_partition_path); w = find_worker_for_disk_or_partition(disk_or_partition_path);
if (w != NULL) { if (w != NULL) {
while (w->disk_or_partition_path != NULL) { while (w->disk_or_partition_path != NULL) {
eno = pthread_cond_wait(&worker_changed, &worker_mutex); eno = pthread_cond_wait(&worker_changed, &worker_mutex);
ASSERT_ENO(eno); ASSERT_ENO(eno);
} }
} }
eno = pthread_mutex_unlock(&worker_mutex); eno = pthread_mutex_unlock(&worker_mutex);
ASSERT_ENO(eno); ASSERT_ENO(eno);
} }
static rtems_status_code media_listener(rtems_media_event event, rtems_media_state state, const char *src, const char *dest, void *arg) static rtems_status_code media_listener(rtems_media_event event, rtems_media_state state, const char *src, const char *dest, void *arg)
{ {
rtems_status_code rsc = RTEMS_SUCCESSFUL; rtems_status_code rsc = RTEMS_SUCCESSFUL;
char *disk_or_partition_path = NULL; char *disk_or_partition_path = NULL;
printf("media listener: event = %s, state = %s, src = %s", rtems_media_event_description(event), rtems_media_state_description(state), src); printf("media listener: event = %s, state = %s, src = %s", rtems_media_event_description(event), rtems_media_state_description(state), src);
if (dest != NULL) { if (dest != NULL) {
printf(", dest = %s", dest); printf(", dest = %s", dest);
} }
if (arg != NULL) { if (arg != NULL) {
printf(", arg = %p\n", arg); printf(", arg = %p\n", arg);
} }
printf("\n"); printf("\n");
if (state == RTEMS_MEDIA_STATE_INQUIRY) { if (state == RTEMS_MEDIA_STATE_INQUIRY) {
if (event == RTEMS_MEDIA_EVENT_MOUNT) { if (event == RTEMS_MEDIA_EVENT_MOUNT) {
rsc = RTEMS_IO_ERROR; rsc = RTEMS_IO_ERROR;
} else if (event == RTEMS_MEDIA_EVENT_PARTITION_DETACH || event == RTEMS_MEDIA_EVENT_DISK_DETACH) { } else if (event == RTEMS_MEDIA_EVENT_PARTITION_DETACH || event == RTEMS_MEDIA_EVENT_DISK_DETACH) {
wait_for_worker_finished(src); wait_for_worker_finished(src);
} else if (event == RTEMS_MEDIA_EVENT_UNMOUNT) { } else if (event == RTEMS_MEDIA_EVENT_UNMOUNT) {
assert(false); assert(false);
} }
} else if (state == RTEMS_MEDIA_STATE_SUCCESS) { } else if (state == RTEMS_MEDIA_STATE_SUCCESS) {
if (event == RTEMS_MEDIA_EVENT_PARTITION_ATTACH) { if (event == RTEMS_MEDIA_EVENT_PARTITION_ATTACH) {
disk_or_partition_path = strdup(dest); disk_or_partition_path = strdup(dest);
} }
} else if (state == RTEMS_MEDIA_STATE_FAILED) { } else if (state == RTEMS_MEDIA_STATE_FAILED) {
if (event == RTEMS_MEDIA_EVENT_PARTITION_INQUIRY) { if (event == RTEMS_MEDIA_EVENT_PARTITION_INQUIRY) {
disk_or_partition_path = strdup(src); disk_or_partition_path = strdup(src);
} }
} }
if (disk_or_partition_path != NULL) { if (disk_or_partition_path != NULL) {
activate_worker(disk_or_partition_path); activate_worker(disk_or_partition_path);
} }
return rsc; return rsc;
} }
static void worker_finished(worker *w) static void worker_finished(worker *w)
{ {
int eno = 0; int eno = 0;
eno = pthread_mutex_lock(&worker_mutex); eno = pthread_mutex_lock(&worker_mutex);
ASSERT_ENO(eno); ASSERT_ENO(eno);
free(w->disk_or_partition_path); free(w->disk_or_partition_path);
w->disk_or_partition_path = NULL; w->disk_or_partition_path = NULL;
eno = pthread_cond_broadcast(&worker_changed); eno = pthread_cond_broadcast(&worker_changed);
ASSERT_ENO(eno); ASSERT_ENO(eno);
eno = pthread_mutex_unlock(&worker_mutex); eno = pthread_mutex_unlock(&worker_mutex);
ASSERT_ENO(eno); ASSERT_ENO(eno);
} }
static void worker_task(rtems_task_argument arg) static void worker_task(rtems_task_argument arg)
{ {
rtems_status_code sc = RTEMS_SUCCESSFUL; rtems_status_code sc = RTEMS_SUCCESSFUL;
unsigned index = arg; unsigned index = arg;
worker *self = &worker_table [index]; worker *self = &worker_table [index];
char mount_path [] = "/work/????"; char mount_path [] = "/work/????";
int rv = 0; int rv = 0;
rv = snprintf(mount_path, sizeof(mount_path), "/work/%u", index); rv = snprintf(mount_path, sizeof(mount_path), "/work/%u", index);
assert(rv < (int) sizeof(mount_path)); assert(rv < (int) sizeof(mount_path));
sc = rtems_libio_set_private_env(); sc = rtems_libio_set_private_env();
ASSERT_SC(sc); ASSERT_SC(sc);
rv = rtems_mkdir(mount_path, S_IRWXU | S_IRWXG | S_IRWXO); rv = rtems_mkdir(mount_path, S_IRWXU | S_IRWXG | S_IRWXO);
assert(rv == 0); assert(rv == 0);
while (true) { while (true) {
rtems_event_set events = 0; rtems_event_set events = 0;
sc = rtems_event_receive(WORKER_EVENT, RTEMS_EVENT_ALL | RTEMS_WAIT, RTEMS_NO_TIMEOUT, &events); sc = rtems_event_receive(WORKER_EVENT, RTEMS_EVENT_ALL | RTEMS_WAIT, RTEMS_NO_TIMEOUT, &events);
ASSERT_SC(sc); ASSERT_SC(sc);
test_file_system(index, self->disk_or_partition_path, mount_path); test_file_system(index, self->disk_or_partition_path, mount_path);
worker_finished(self); worker_finished(self);
add_worker_to_free_list(self); add_worker_to_free_list(self);
} }
} }
static const char mac_address [6] = { 0x00, 0x1a, 0xf1, 0x00, 0x07, 0xa4 }; static const char mac_address [6] = { 0x00, 0x1a, 0xf1, 0x00, 0x07, 0xa4 };
static void Init(rtems_task_argument arg) static void Init(rtems_task_argument arg)
{ {
rtems_status_code sc = RTEMS_SUCCESSFUL; rtems_status_code sc = RTEMS_SUCCESSFUL;
int rv = 0; int rv = 0;
int eno = 0; int eno = 0;
rtems_id id = RTEMS_ID_NONE; rtems_id id = RTEMS_ID_NONE;
size_t i = 0; size_t i = 0;
eno = pthread_mutex_init(&worker_mutex, NULL); eno = pthread_mutex_init(&worker_mutex, NULL);
ASSERT_ENO(eno); ASSERT_ENO(eno);
eno = pthread_cond_init(&worker_changed, NULL); eno = pthread_cond_init(&worker_changed, NULL);
ASSERT_ENO(eno); ASSERT_ENO(eno);
for (i = 0; i < WORKER_COUNT; ++i) { for (i = 0; i < WORKER_COUNT; ++i) {
worker *w = &worker_table [i]; worker *w = &worker_table [i];
sc = rtems_task_create( sc = rtems_task_create(
WORKER_NAME, WORKER_NAME,
95 + 10 * (i % 4), 95 + 10 * (i % 4),
32 * 1024, 32 * 1024,
RTEMS_DEFAULT_MODES, RTEMS_DEFAULT_MODES,
RTEMS_DEFAULT_ATTRIBUTES, RTEMS_DEFAULT_ATTRIBUTES,
&id &id
); );
ASSERT_SC(sc); ASSERT_SC(sc);
w->task = id; w->task = id;
add_worker_to_free_list(w); add_worker_to_free_list(w);
sc = rtems_task_start(id, worker_task, i); sc = rtems_task_start(id, worker_task, i);
ASSERT_SC(sc); ASSERT_SC(sc);
} }
sc = rtems_disk_io_initialize(); sc = rtems_disk_io_initialize();
ASSERT_SC(sc); ASSERT_SC(sc);
sc = rtems_media_initialize(); sc = rtems_media_initialize();
ASSERT_SC(sc); ASSERT_SC(sc);
sc = rtems_media_listener_add(media_listener, NULL); sc = rtems_media_listener_add(media_listener, NULL);
ASSERT_SC(sc); ASSERT_SC(sc);
sc = rtems_media_server_initialize(200, 32 * 1024, RTEMS_DEFAULT_MODES, RTEMS_DEFAULT_ATTRIBUTES); sc = rtems_media_server_initialize(200, 32 * 1024, RTEMS_DEFAULT_MODES, RTEMS_DEFAULT_ATTRIBUTES);
ASSERT_SC(sc); ASSERT_SC(sc);
sc = rtems_bsd_initialize_with_interrupt_server(); sc = rtems_bsd_initialize_with_interrupt_server();
ASSERT_SC(sc); ASSERT_SC(sc);
rtems_bsd_shell_initialize(); rtems_bsd_shell_initialize();
sc = rtems_shell_init( sc = rtems_shell_init(
"SHLL", "SHLL",
16 * 1024, 16 * 1024,
10, 10,
CONSOLE_DEVICE_NAME, CONSOLE_DEVICE_NAME,
false, false,
true, true,
NULL NULL
); );
ASSERT_SC(sc); ASSERT_SC(sc);
exit(0); exit(0);
} }
#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
#define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK #define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK
#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM #define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
#define CONFIGURE_FILESYSTEM_IMFS #define CONFIGURE_FILESYSTEM_IMFS
#define CONFIGURE_FILESYSTEM_DOSFS #define CONFIGURE_FILESYSTEM_DOSFS
#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 32 #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 32
#define CONFIGURE_BDBUF_BUFFER_MIN_SIZE 512 #define CONFIGURE_BDBUF_BUFFER_MIN_SIZE 512
#define CONFIGURE_BDBUF_BUFFER_MAX_SIZE 512 #define CONFIGURE_BDBUF_BUFFER_MAX_SIZE 512
#define CONFIGURE_BDBUF_CACHE_MEMORY_SIZE (WORKER_COUNT * 512) #define CONFIGURE_BDBUF_CACHE_MEMORY_SIZE (WORKER_COUNT * 512)
#define CONFIGURE_BDBUF_MAX_READ_AHEAD_BLOCKS 0 #define CONFIGURE_BDBUF_MAX_READ_AHEAD_BLOCKS 0
#define CONFIGURE_MAXIMUM_TASKS 64 #define CONFIGURE_MAXIMUM_TASKS 64
#define CONFIGURE_MAXIMUM_DRIVERS 4 #define CONFIGURE_MAXIMUM_DRIVERS 4
#define CONFIGURE_MAXIMUM_SEMAPHORES 64 #define CONFIGURE_MAXIMUM_SEMAPHORES 64
#define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 4 #define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 4
#define CONFIGURE_MAXIMUM_TIMERS 64 #define CONFIGURE_MAXIMUM_TIMERS 64
#define CONFIGURE_MAXIMUM_PERIODS 4 #define CONFIGURE_MAXIMUM_PERIODS 4
#define CONFIGURE_MAXIMUM_USER_EXTENSIONS 1 #define CONFIGURE_MAXIMUM_USER_EXTENSIONS 1
#define CONFIGURE_MAXIMUM_BARRIERS 1 #define CONFIGURE_MAXIMUM_BARRIERS 1
#define CONFIGURE_MAXIMUM_POSIX_MUTEXES 32 #define CONFIGURE_MAXIMUM_POSIX_MUTEXES 32
#define CONFIGURE_MAXIMUM_POSIX_CONDITION_VARIABLES 64 #define CONFIGURE_MAXIMUM_POSIX_CONDITION_VARIABLES 64
#define CONFIGURE_EXTRA_TASK_STACKS (1 * 1024 * 1024) #define CONFIGURE_EXTRA_TASK_STACKS (1 * 1024 * 1024)
#define CONFIGURE_RTEMS_INIT_TASKS_TABLE #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
#define CONFIGURE_STACK_CHECKER_ENABLED #define CONFIGURE_STACK_CHECKER_ENABLED
#define CONFIGURE_INIT #define CONFIGURE_INIT
#include <rtems/confdefs.h> #include <rtems/confdefs.h>
#define CONFIGURE_SHELL_COMMANDS_INIT #define CONFIGURE_SHELL_COMMANDS_INIT
#include "demo-shell.h" #include "demo-shell.h"
#include "demo-shell-block-devices.h" #include "demo-shell-block-devices.h"
#include <rtems/shellconfig.h> #include <rtems/shellconfig.h>
#define USB_SYSINIT_INIT #define USB_SYSINIT_INIT
#include "usb-sysinit.h" #include "usb-sysinit.h"

View File

@ -1,65 +1,65 @@
/** /**
* @file * @file
* *
* @ingroup demo * @ingroup demo
* *
* @brief USB system initialization. * @brief USB system initialization.
*/ */
/* /*
* Copyright (c) 2009, 2010 embedded brains GmbH. All rights reserved. * Copyright (c) 2009, 2010 embedded brains GmbH. All rights reserved.
* *
* embedded brains GmbH * embedded brains GmbH
* Obere Lagerstr. 30 * Obere Lagerstr. 30
* 82178 Puchheim * 82178 Puchheim
* Germany * Germany
* <rtems@embedded-brains.de> * <rtems@embedded-brains.de>
* *
* The license and distribution terms for this file may be * The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at * found in the file LICENSE in this distribution or at
* http://www.rtems.com/license/LICENSE. * http://www.rtems.com/license/LICENSE.
*/ */
#include <rtems/freebsd/machine/rtems-bsd-sysinit.h> #include <rtems/freebsd/machine/rtems-bsd-sysinit.h>
#include <bsp.h> #include <bsp.h>
#ifdef USB_SYSINIT_INIT #ifdef USB_SYSINIT_INIT
#if defined(LIBBSP_ARM_LPC24XX_BSP_H) || defined(LIBBSP_ARM_LPC32XX_BSP_H) #if defined(LIBBSP_ARM_LPC24XX_BSP_H) || defined(LIBBSP_ARM_LPC32XX_BSP_H)
#define NEED_USB_OHCI #define NEED_USB_OHCI
#elif defined(__GEN83xx_BSP_h) || defined(LIBBSP_POWERPC_QORIQ_BSP_H) #elif defined(__GEN83xx_BSP_h) || defined(LIBBSP_POWERPC_QORIQ_BSP_H)
#define NEED_USB_EHCI #define NEED_USB_EHCI
#endif #endif
#if defined(LIBBSP_POWERPC_QORIQ_BSP_H) #if defined(LIBBSP_POWERPC_QORIQ_BSP_H)
#define NEED_SDHC #define NEED_SDHC
#endif #endif
SYSINIT_NEED_FREEBSD_CORE; SYSINIT_NEED_FREEBSD_CORE;
SYSINIT_NEED_USB_CORE; SYSINIT_NEED_USB_CORE;
#ifdef NEED_USB_OHCI #ifdef NEED_USB_OHCI
SYSINIT_NEED_USB_OHCI; SYSINIT_NEED_USB_OHCI;
#endif #endif
#ifdef NEED_USB_EHCI #ifdef NEED_USB_EHCI
SYSINIT_NEED_USB_EHCI; SYSINIT_NEED_USB_EHCI;
#endif #endif
SYSINIT_NEED_USB_MASS_STORAGE; SYSINIT_NEED_USB_MASS_STORAGE;
#ifdef NEED_SDHC #ifdef NEED_SDHC
SYSINIT_NEED_SDHC; SYSINIT_NEED_SDHC;
#endif #endif
const char *const _bsd_nexus_devices [] = { const char *const _bsd_nexus_devices [] = {
#ifdef NEED_USB_OHCI #ifdef NEED_USB_OHCI
"ohci", "ohci",
#endif #endif
#ifdef NEED_USB_EHCI #ifdef NEED_USB_EHCI
"ehci", "ehci",
#endif #endif
#ifdef NEED_SDHC #ifdef NEED_SDHC
"sdhci", "sdhci",
#endif #endif
NULL NULL
}; };
#endif /* USB_SYSINIT_INIT */ #endif /* USB_SYSINIT_INIT */