9
0
Fork 0

Finally, a clean SDCC compile

git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@20 7fd9a85b-ad96-42d3-883c-3090e2eb8679
This commit is contained in:
patacongo 2007-02-27 21:17:21 +00:00
parent e5b41fc741
commit 2611da5e2a
171 changed files with 1513 additions and 1325 deletions

View File

@ -92,11 +92,6 @@ defconfig -- This is a configuration file similar to the Linux
CONFIG_ARCH_STRNCPY, CONFIG_ARCH_STRLEN, CONFIG_ARCH_BZERO
CONFIG_ARCH_KMALLOC, CONFIG_ARCH_KZMALLOC, CONFIG_ARCH_KFREE
General Compile environment setup
CONFIG_HAVE_LONG_LONG - enable if your architecture supports
long long types and if you plan to use them
Sizes of configurable things (0 disables)
CONFIG_NPTHREAD_KEYS - The number of items of thread-

View File

@ -129,32 +129,6 @@ CONFIG_ARCH_KMALLOC=n
CONFIG_ARCH_KZMALLOC=n
CONFIG_ARCH_KFREE=n
#
# General Compile environment setup
#
# CONFIG_SMALL_MEMORY - enable if your processor supports
# 16-bit addressing; disable if it supports 32-bit.
# CONFIG_HAVE_INLINE - enable if your compiler supports
# inline functions
# CONFIG_HAVE_DOUBLE - enable if your compiler supports type
# double.
# CONFIG_HAVE_LONG_LONG - enable if your architecture supports
# long long types and if you plan to use them
# CONFIG_CAN_PASS_STRUCTS - enable if your compiler supports
# passing and assiging structures and unions as values
# CONFIG_CAN_CAST_POINTERS - enable if you can cast between
# integers and pointer.
# CONFIG_HAVE_WEAKFUNCTIONS - enable if you compiler supports
# weak functions (see include/nuttx/comp
#
CONFIG_SMALL_MEMORY=n
CONFIG_HAVE_INLINE=y
CONFIG_HAVE_DOUBLE=y
CONFIG_HAVE_LONG_LONG=n
CONFIG_CAN_PASS_STRUCTS=y
CONFIG_CAN_CAST_POINTERS=y
CONFIG_HAVE_WEAKFUNCTIONS=y
#
# General build options
#

View File

@ -96,32 +96,6 @@ CONFIG_ARCH_KMALLOC=n
CONFIG_ARCH_KZMALLOC=n
CONFIG_ARCH_KFREE=n
#
# General Compile environment setup
#
# CONFIG_SMALL_MEMORY - enable if your processor supports
# 16-bit addressing; disable if it supports 32-bit.
# CONFIG_HAVE_INLINE - enable if your compiler supports
# inline functions
# CONFIG_HAVE_DOUBLE - enable if your compiler supports type
# double.
# CONFIG_HAVE_LONG_LONG - enable if your architecture supports
# long long types and if you plan to use them
# CONFIG_CAN_PASS_STRUCTS - enable if your compiler supports
# passing and assiging structures and unions as values
# CONFIG_CAN_CAST_POINTERS - enable if you can cast between
# integers and pointer.
# CONFIG_HAVE_WEAKFUNCTIONS - enable if you compiler supports
# weak functions (see include/nuttx/comp
#
CONFIG_SMALL_MEMORY=n
CONFIG_HAVE_INLINE=y
CONFIG_HAVE_DOUBLE=y
CONFIG_HAVE_LONG_LONG=n
CONFIG_CAN_PASS_STRUCTS=y
CONFIG_CAN_CAST_POINTERS=y
CONFIG_HAVE_WEAKFUNCTIONS=y
#
# General build options
#

View File

@ -69,7 +69,7 @@ $(BIN): $(OBJS)
depend: .depend
clean:
rm -f $(BIN) *.o *~
rm -f $(BIN) *.o *.asm *.lst *.sym *.adb *~
distclean: clean
rm -f Make.dep .depend

View File

@ -61,8 +61,11 @@ static ssize_t devnull_write(struct file *, const char *, size_t);
static struct file_operations devnull_fops =
{
.read = devnull_read,
.write = devnull_write,
NULL, /* open */
NULL, /* close */
devnull_read, /* read */
devnull_write, /* write */
NULL /* ioctl */
};
/************************************************************

View File

@ -70,7 +70,7 @@ $(BIN): $(OBJS)
depend: .depend
clean:
rm -f $(BIN) *.o *~
rm -f $(BIN) *.o *.asm *.lst *.sym *.adb *~
distclean: clean
rm -f Make.dep .depend

View File

@ -96,7 +96,7 @@ static void *thread_waiter(void *parameter)
}
printf("thread_waiter: Exit with status 0x12345678\n");
pthread_exit((void*)0x12345678);
pthread_exit((pthread_addr_t)0x12345678);
return NULL;
}
@ -140,7 +140,7 @@ static void start_thread(pthread_t *waiter, int cancelable)
/* Start the waiter thread */
printf("start_thread: Starting thread\n");
status = pthread_create(waiter, NULL, thread_waiter, (void*)cancelable);
status = pthread_create(waiter, &attr, thread_waiter, (pthread_addr_t)cancelable);
if (status != 0)
{
printf("start_thread: ERROR pthread_create failed, status=%d\n", status);

View File

@ -190,6 +190,9 @@ void cond_test(void)
pthread_t waiter;
pthread_t signaler;
pthread_attr_t attr;
#ifdef SDCC
pthread_addr_t result;
#endif
struct sched_param sparam;
int prio_min;
int prio_max;
@ -270,7 +273,11 @@ void cond_test(void)
/* Wait for the threads to stop */
#ifdef SDCC
pthread_join(signaler, &result);
#else
pthread_join(signaler, NULL);
#endif
printf("cond_test: signaler terminated, now cancel the waiter\n");
pthread_detach(waiter);
pthread_cancel(waiter);

View File

@ -55,18 +55,18 @@
#define STACKSIZE 8192
#define NARGS 4
#define ARG1 "Arg1"
#define ARG2 "Arg2"
#define ARG3 "Arg3"
#define ARG4 "Arg4"
/************************************************************
* Private Data
************************************************************/
static FAR char arg1[] = "Arg1";
static FAR char arg2[] = "Arg2";
static FAR char arg3[] = "Arg3";
static FAR char arg4[] = "Arg4";
static char write_data1[] = "Standard I/O Check: write fd=1\n";
static char write_data2[] = "Standard I/O Check: write fd=2\n";
static char *args[NARGS] = { ARG1, ARG2, ARG3, ARG4 };
static char *args[NARGS] = { arg1, arg2, arg3, arg4 };
/************************************************************
* Private Functions
@ -165,7 +165,7 @@ int user_start(int parm1, int parm2, int parm3, int parm4)
/* Verify that we can spawn a new task */
result = task_create("ostest", PRIORITY, STACKSIZE, user_main,
ARG1, ARG2, ARG3, ARG4);
arg1, arg2, arg3, arg4);
if (result == ERROR)
{
fprintf(stderr, "user_start: Failed to start user_main\n");

View File

@ -50,7 +50,11 @@
**************************************************************************/
#define TEST_MESSAGE "This is a test and only a test"
#ifdef SDCC
#define TEST_MSGLEN (31)
#else
#define TEST_MSGLEN (strlen(TEST_MESSAGE)+1)
#endif
/**************************************************************************
* Private Types
@ -108,7 +112,7 @@ static void *sender_thread(void *arg)
if (mqfd < 0)
{
printf("sender_thread: ERROR mq_open failed\n");
pthread_exit((void*)1);
pthread_exit((pthread_addr_t)1);
}
/* Fill in a test message buffer to send */
@ -139,7 +143,7 @@ static void *sender_thread(void *arg)
}
printf("sender_thread: returning nerrors=%d\n", nerrors);
return (void*)nerrors;
return (pthread_addr_t)nerrors;
}
static void *receiver_thread(void *arg)
@ -174,7 +178,7 @@ static void *receiver_thread(void *arg)
if (mqfd < 0)
{
printf("receiver_thread: ERROR mq_open failed\n");
pthread_exit((void*)1);
pthread_exit((pthread_addr_t)1);
}
/* Perform the receive 10 times */
@ -221,7 +225,7 @@ static void *receiver_thread(void *arg)
nerrors++;
}
pthread_exit((void*)nerrors);
pthread_exit((pthread_addr_t)nerrors);
/* Destroy the queue */
@ -232,7 +236,7 @@ static void *receiver_thread(void *arg)
}
printf("receiver_thread: returning nerrors=%d\n", nerrors);
return (void*)nerrors;
return (pthread_addr_t)nerrors;
}
void mqueue_test(void)

View File

@ -91,6 +91,11 @@ static void *thread_func(void *parameter)
void mutex_test(void)
{
pthread_t thread1, thread2;
#ifdef SDCC
pthread_addr_t result1, result2;
pthread_attr_t attr;
#endif
int status;
/* Initialize the mutex */
@ -100,19 +105,35 @@ void mutex_test(void)
/* Start two thread instances */
printf("Starting thread 1\n");
if ((pthread_create(&thread1, NULL, thread_func, (void*)1)) != 0)
#ifdef SDCC
(void)pthread_attr_init(&attr);
status = pthread_create(&thread1, &attr, thread_func, (pthread_addr_t)1);
#else
status = pthread_create(&thread1, NULL, thread_func, (pthread_addr_t)1);
#endif
if (status != 0)
{
printf("Error in thread#1 creation\n");
}
printf("Starting thread 2\n");
if ((pthread_create(&thread2, NULL, thread_func, (void*)2)) != 0)
#ifdef SDCC
status = pthread_create(&thread2, &attr, thread_func, (pthread_addr_t)2);
#else
status = pthread_create(&thread2, NULL, thread_func, (pthread_addr_t)2);
#endif
if (status != 0)
{
printf("Error in thread#2 creation\n");
}
#ifdef SDCC
pthread_join(thread1, &result1);
pthread_join(thread2, &result2);
#else
pthread_join(thread1, NULL);
pthread_join(thread2, NULL);
#endif
printf("\t\tThread1\tThread2\n");
printf("\tLoops\t%ld\t%ld\n", nloops[0], nloops[1]);

View File

@ -144,6 +144,9 @@ void sem_test(void)
pthread_t waiter_thread1;
pthread_t waiter_thread2;
pthread_t poster_thread;
#ifdef SDCC
pthread_addr_t result;
#endif
struct sched_param sparam;
int prio_min;
int prio_max;
@ -178,7 +181,7 @@ void sem_test(void)
printf("sem_test: Set thread 1 priority to %d\n", sparam.sched_priority);
}
status = pthread_create(&waiter_thread1, &attr, waiter_func, (void*)1);
status = pthread_create(&waiter_thread1, &attr, waiter_func, (pthread_addr_t)1);
if (status != 0)
{
printf("sem_test: Error in thread 1 creation, status=%d\n", status);
@ -202,7 +205,7 @@ void sem_test(void)
printf("sem_test: Set thread 2 priority to %d\n", sparam.sched_priority);
}
status = pthread_create(&waiter_thread2, &attr, waiter_func, (void*)2);
status = pthread_create(&waiter_thread2, &attr, waiter_func, (pthread_addr_t)2);
if (status != 0)
{
printf("sem_test: Error in thread 2 creation, status=%d\n", status);
@ -226,13 +229,19 @@ void sem_test(void)
printf("sem_test: Set thread 3 priority to %d\n", sparam.sched_priority);
}
status = pthread_create(&poster_thread, &attr, poster_func, (void*)3);
status = pthread_create(&poster_thread, &attr, poster_func, (pthread_addr_t)3);
if (status != 0)
{
printf("sem_test: Error in thread 3 creation, status=%d\n", status);
}
#ifdef SDCC
pthread_join(waiter_thread1, &result);
pthread_join(waiter_thread2, &result);
pthread_join(poster_thread, &result);
#else
pthread_join(waiter_thread1, NULL);
pthread_join(waiter_thread2, NULL);
pthread_join(poster_thread, NULL);
#endif
}

View File

@ -145,8 +145,10 @@ static int waiter_main(int argc, char *argv[])
printf("waiter_main: ERROR sigaction failed, status=%d\n" , status);
}
#ifndef SDCC
printf("waiter_main: oact.sigaction=%p oact.sa_flags=%x oact.sa_mask=%x\n",
oact.sa_sigaction, oact.sa_flags, oact.sa_mask);
#endif
/* Take the semaphore */
@ -225,7 +227,11 @@ void sighand_test(void)
/* Then signal the waiter thread. */
sigvalue.sival_int = SIGVALUE_INT;
#ifdef CONFIG_CAN_PASS_STRUCTS
status = sigqueue(waiterpid, WAKEUP_SIGNAL, sigvalue);
#else
status = sigqueue(waiterpid, WAKEUP_SIGNAL, sigvalue.sival_ptr);
#endif
if (status != OK)
{
printf("sighand_test: ERROR sigqueue failed\n" );

View File

@ -95,7 +95,7 @@ static void *thread_waiter(void *parameter)
}
printf("thread_waiter: Exit with status 0x12345678\n");
pthread_exit((void*)0x12345678);
pthread_exit((pthread_addr_t)0x12345678);
return NULL;
}

View File

@ -70,7 +70,7 @@ $(BIN): $(OBJS)
depend: .depend
clean:
rm -f $(BIN) *.o *~
rm -f $(BIN) *.o *.asm *.lst *.sym *.adb *~
distclean: clean
rm -f Make.dep .depend

View File

@ -60,7 +60,7 @@
int close(int fd)
{
struct filelist *list;
FAR struct filelist *list;
/* Get the thread-specific file list */
@ -73,7 +73,7 @@ int close(int fd)
if ((unsigned int)fd < CONFIG_NFILE_DESCRIPTORS)
{
struct inode *inode = list->fl_files[fd].f_inode;
FAR struct inode *inode = list->fl_files[fd].f_inode;
if (inode)
{
files_release(fd);

View File

@ -69,7 +69,7 @@
int dup(int fildes)
{
struct filelist *list;
FAR struct filelist *list;
int fildes2;
/* Get the thread-specific file list */
@ -109,7 +109,7 @@ int dup(int fildes)
int dup2(int fildes1, int fildes2)
{
struct filelist *list;
FAR struct filelist *list;
/* Get the thread-specific file list */

View File

@ -72,7 +72,7 @@
* Private Functions
************************************************************/
static void _files_semtake(struct filelist *list)
static void _files_semtake(FAR struct filelist *list)
{
/* Take the semaphore (perhaps waiting) */
@ -102,10 +102,10 @@ void files_initialize(void)
/* Allocate a list of files for a new task */
struct filelist *files_alloclist(void)
FAR struct filelist *files_alloclist(void)
{
struct filelist *list;
list = (struct filelist*)kzmalloc(sizeof(struct filelist));
FAR struct filelist *list;
list = (FAR struct filelist*)kzmalloc(sizeof(struct filelist));
if (list)
{
/* Start with a reference count of one */
@ -121,7 +121,7 @@ struct filelist *files_alloclist(void)
/* Increase the reference count on a file list */
int files_addreflist(struct filelist *list)
int files_addreflist(FAR struct filelist *list)
{
if (list)
{
@ -136,7 +136,7 @@ int files_addreflist(struct filelist *list)
/* Release a reference to the file list */
int files_releaselist(struct filelist *list)
int files_releaselist(FAR struct filelist *list)
{
int crefs;
if (list)
@ -159,7 +159,7 @@ int files_releaselist(struct filelist *list)
for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++)
{
struct inode *inode = list->fl_files[i].f_inode;
FAR struct inode *inode = list->fl_files[i].f_inode;
if (inode)
{
inode_release(inode);
@ -179,9 +179,9 @@ int files_releaselist(struct filelist *list)
* heart of dup2.
*/
int files_dup(struct file *filep1, struct file *filep2)
int files_dup(FAR struct file *filep1, FAR struct file *filep2)
{
struct filelist *list;
FAR struct filelist *list;
if (!filep1 || !filep1->f_inode || !filep2)
{
@ -225,34 +225,34 @@ int files_dup(struct file *filep1, struct file *filep2)
* the files array.
*/
int files_allocate(struct inode *inode, int oflags, off_t pos)
int files_allocate(FAR struct inode *inode, int oflags, off_t pos)
{
struct filelist *list;
FAR struct filelist *list;
int i;
list = sched_getfiles();
if (list)
{
_files_semtake(list);
for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++)
{
if (!list->fl_files[i].f_inode)
{
list->fl_files[i].f_oflags = oflags;
list->fl_files[i].f_pos = pos;
list->fl_files[i].f_inode = inode;
_files_semgive(list);
return i;
}
}
_files_semgive(list);
}
_files_semtake(list);
for (i = 0; i < CONFIG_NFILE_DESCRIPTORS; i++)
{
if (!list->fl_files[i].f_inode)
{
list->fl_files[i].f_oflags = oflags;
list->fl_files[i].f_pos = pos;
list->fl_files[i].f_inode = inode;
_files_semgive(list);
return i;
}
}
_files_semgive(list);
}
return ERROR;
}
void files_release(int filedes)
{
struct filelist *list;
FAR struct filelist *list;
list = sched_getfiles();
if (list)

View File

@ -69,7 +69,7 @@ static sem_t tree_sem;
* Public Variables
************************************************************/
struct inode *root_inode = NULL;
FAR struct inode *root_inode = NULL;
/************************************************************
* Private Functions
@ -92,7 +92,7 @@ static void _inode_semtake(void)
#define _inode_semgive(void) sem_post(&tree_sem)
static int _inode_compare(const char *fname,
struct inode *node)
FAR struct inode *node)
{
char *nname = node->i_name;
@ -172,12 +172,12 @@ static const char *_inode_nextname(const char *name)
return name;
}
static struct inode *_inode_alloc(const char *name,
struct file_operations *fops,
mode_t mode, void *private)
static FAR struct inode *_inode_alloc(const char *name,
struct file_operations *fops,
mode_t mode, void *private)
{
int namelen = _inode_namelen(name);
struct inode *node = malloc(FSNODE_SIZE(namelen));
FAR struct inode *node = (FAR struct inode*)malloc(FSNODE_SIZE(namelen));
if (node)
{
node->i_peer = NULL;
@ -192,14 +192,14 @@ static struct inode *_inode_alloc(const char *name,
return node;
}
static struct inode *_inode_find(const char **path,
struct inode **peer,
struct inode **parent)
static FAR struct inode *_inode_find(const char **path,
FAR struct inode **peer,
FAR struct inode **parent)
{
const char *name = *path + 1; /* Skip over leading '/' */
struct inode *node = root_inode;
struct inode *left = NULL;
struct inode *above = NULL;
const char *name = *path + 1; /* Skip over leading '/' */
FAR struct inode *node = root_inode;
FAR struct inode *left = NULL;
FAR struct inode *above = NULL;
while (node)
{
@ -278,9 +278,9 @@ static struct inode *_inode_find(const char **path,
return node;
}
static void _inode_insert(struct inode *node,
struct inode *peer,
struct inode *parent)
static void _inode_insert(FAR struct inode *node,
FAR struct inode *peer,
FAR struct inode *parent)
{
/* If peer is non-null, then new node simply goes to the right
* of that peer node.
@ -342,7 +342,7 @@ static void _inode_remove(struct inode *node,
node->i_peer = NULL;
}
static void _inode_free(struct inode *node)
static void _inode_free(FAR struct inode *node)
{
if (node)
{
@ -370,7 +370,9 @@ void fs_initialize(void)
/* Initialize files array (if it is used) */
#ifdef CONFIG_HAVE_WEAKFUNCTIONS
if (files_initialize != NULL)
#endif
{
files_initialize();
}
@ -380,9 +382,9 @@ void fs_initialize(void)
* to the inode associatged with a path.
*/
struct inode *inode_find(const char *path)
FAR struct inode *inode_find(const char *path)
{
struct inode *node;
FAR struct inode *node;
if (!*path || path[0] != '/')
{
@ -394,7 +396,7 @@ struct inode *inode_find(const char *path)
*/
_inode_semtake();
node = _inode_find(&path, NULL, NULL);
node = _inode_find(&path, (FAR void*)NULL, (FAR void*)NULL);
if (node) node->i_crefs++;
_inode_semgive();
return node;
@ -404,7 +406,7 @@ struct inode *inode_find(const char *path)
* descriptor is dup'ed.
*/
void inode_addref(struct inode *inode)
void inode_addref(FAR struct inode *inode)
{
if (inode)
{
@ -418,14 +420,17 @@ void inode_addref(struct inode *inode)
* to the inode.
*/
void inode_release(struct inode *node)
void inode_release(FAR struct inode *node)
{
if (node)
{
/* Decrement the references of the inode */
_inode_semtake();
if (node->i_crefs) node->i_crefs--;
if (node->i_crefs)
{
node->i_crefs--;
}
/* If the subtree was previously deleted and the reference
* count has decrement to zero, then delete the inode
@ -450,9 +455,9 @@ STATUS register_inode(const char *path,
struct file_operations *fops,
mode_t mode, void *private)
{
const char *name = path;
struct inode *left;
struct inode *parent;
const char *name = path;
FAR struct inode *left;
FAR struct inode *parent;
if (!*path || path[0] != '/')
{
@ -474,7 +479,7 @@ STATUS register_inode(const char *path,
for (;;)
{
struct inode *node;
FAR struct inode *node;
/* Create a new node -- we need to know if this is the
* the leaf node or some intermediary. We can find this
@ -519,10 +524,10 @@ STATUS register_inode(const char *path,
STATUS unregister_inode(const char *path)
{
const char *name = path;
struct inode *node;
struct inode *left;
struct inode *parent;
const char *name = path;
FAR struct inode *node;
FAR struct inode *left;
FAR struct inode *parent;
if (*path && path[0] == '/')
{

View File

@ -58,10 +58,7 @@
* Global Variables
************************************************************/
#if CONFIG_NFILE_DESCRIPTORS >0
extern struct file files[CONFIG_NFILE_DESCRIPTORS];
#endif
extern struct inode *root_inode;
extern FAR struct inode *root_inode;
/************************************************************
* Pulblic Function Prototypes
@ -77,23 +74,21 @@ extern "C" {
/* fs_inode.c ***********************************************/
EXTERN struct inode *inode_find(const char *path);
EXTERN void inode_addref(struct inode *inode);
EXTERN void inode_release(struct inode *inode);
EXTERN FAR struct inode *inode_find(const char *path);
EXTERN void inode_addref(FAR struct inode *inode);
EXTERN void inode_release(FAR struct inode *inode);
/* fs_files.c ***********************************************/
#if CONFIG_NFILE_DESCRIPTORS >0
EXTERN void weak_function files_initialize(void);
EXTERN int files_allocate(struct inode *inode, int oflags, off_t pos);
EXTERN int files_allocate(FAR struct inode *inode, int oflags, off_t pos);
EXTERN void files_release(int filedes);
#endif
#undef EXTERN
#if defined(__cplusplus)
}
#endif
#endif
#endif /* __FS_INTERNAL_H */

View File

@ -53,14 +53,24 @@
int ioctl(int fd, int req, unsigned long arg)
{
FAR struct filelist *list;
int ret = EBADF;
/* We we give a valid file descriptor? */
/* Get the thread-specific file list */
list = sched_getfiles();
if (!list)
{
*get_errno_ptr() = EMFILE;
return ERROR;
}
/* Were we give a valid file descriptor? */
if ((unsigned int)fd < CONFIG_NFILE_DESCRIPTORS)
{
struct file *this_file = &files[fd];
struct inode *inode = this_file->f_inode;
FAR struct file *this_file = &list->fl_files[fd];
struct inode *inode = this_file->f_inode;
/* Is a driver registered? Does it support the ioctl method? */

View File

@ -68,7 +68,7 @@
* Public Functions
************************************************************/
int inode_checkflags(struct inode *inode, int oflags)
int inode_checkflags(FAR struct inode *inode, int oflags)
{
if (((oflags & O_RDOK) != 0 && !inode->i_ops->read) ||
((oflags & O_WROK) != 0 && !inode->i_ops->write))
@ -85,7 +85,7 @@ int inode_checkflags(struct inode *inode, int oflags)
int open(const char *path, int oflags, ...)
{
struct filelist *list;
struct inode *inode;
FAR struct inode *inode;
int status;
int fd;
@ -150,7 +150,7 @@ int open(const char *path, int oflags, ...)
status = OK;
if (inode->i_ops && inode->i_ops->open)
{
status = inode->i_ops->open(&list->fl_files[fd]);
status = inode->i_ops->open((FAR struct file*)&list->fl_files[fd]);
}
if (status != OK || !inode->i_ops)

View File

@ -57,7 +57,7 @@
int read(int fd, void *buf, unsigned int nbytes)
{
struct filelist *list;
FAR struct filelist *list;
int ret = EBADF;
/* Get the thread-specific file list */
@ -73,23 +73,23 @@ int read(int fd, void *buf, unsigned int nbytes)
if ((unsigned int)fd < CONFIG_NFILE_DESCRIPTORS)
{
struct file *this_file = &list->fl_files[fd];
FAR struct file *this_file = &list->fl_files[fd];
/* Was this file opened for read access? */
if ((this_file->f_oflags & O_RDOK) != 0)
{
{
struct inode *inode = this_file->f_inode;
/* Is a driver registered? Does it support the read method? */
/* Is a driver registered? Does it support the read method? */
if (inode && inode->i_ops && inode->i_ops->read)
{
/* Yes, then let it perform the read */
if (inode && inode->i_ops && inode->i_ops->read)
{
/* Yes, then let it perform the read */
ret = (int)inode->i_ops->read(this_file, (char*)buf, (size_t)nbytes);
}
}
ret = (int)inode->i_ops->read(this_file, (char*)buf, (size_t)nbytes);
}
}
}
return ret;
}

View File

@ -57,7 +57,7 @@
int write(int fd, const void *buf, unsigned int nbytes)
{
struct filelist *list;
FAR struct filelist *list;
int ret = EBADF;
/* Get the thread-specific file list */
@ -73,7 +73,7 @@ int write(int fd, const void *buf, unsigned int nbytes)
if ((unsigned int)fd < CONFIG_NFILE_DESCRIPTORS)
{
struct file *this_file = &list->fl_files[fd];
FAR struct file *this_file = &list->fl_files[fd];
/* Was this file opened for write access? */

View File

@ -106,8 +106,8 @@ extern "C" {
#endif
#ifdef __GNUC__
EXTERN void up_assert(const ubyte *fileName, int lineNum);
EXTERN void up_assert_code(const ubyte *fileName, int lineNum,
EXTERN void up_assert(FAR const ubyte *filename, int linenum);
EXTERN void up_assert_code(FAR const ubyte *filename, int linenum,
int error_code);
#else
EXTERN void up_assert(void);

View File

@ -190,13 +190,7 @@ extern "C" {
/* Return a pointer to the thread specifid errno */
extern int *get_errno_ptr(void);
#ifndef CONFIG_CAN_CAST_POINTERS
/* Return the value ERROR cast to (void*) */
extern void *get_errorptr(void);
#endif
extern FAR int *get_errno_ptr(void);
#undef EXTERN
#if defined(__cplusplus)

View File

@ -78,7 +78,7 @@ struct sigevent {
/* Message queue descriptor */
typedef struct mq_des *mqd_t;
typedef FAR struct mq_des *mqd_t;
/************************************************************
* Global Variables
@ -95,8 +95,7 @@ extern "C" {
#define EXTERN extern
#endif
EXTERN mqd_t mq_open(const char *mq_name,
int oflags, ... );
EXTERN mqd_t mq_open(const char *mq_name, int oflags, ... );
EXTERN int mq_close(mqd_t mqdes );
EXTERN int mq_unlink(const char *mq_name );
EXTERN int mq_send(mqd_t mqdes, const void *msg,

View File

@ -127,7 +127,7 @@ EXTERN void up_idle(void);
*
************************************************************/
EXTERN void up_initial_state(_TCB *tcb);
EXTERN void up_initial_state(FAR _TCB *tcb);
/************************************************************
* Name: up_create_stack
@ -150,7 +150,7 @@ EXTERN void up_initial_state(_TCB *tcb);
* must be allocated.
************************************************************/
EXTERN STATUS up_create_stack(_TCB *tcb, size_t stack_size);
EXTERN STATUS up_create_stack(FAR _TCB *tcb, size_t stack_size);
/************************************************************
* Name: up_use_stack
@ -173,7 +173,7 @@ EXTERN STATUS up_create_stack(_TCB *tcb, size_t stack_size);
*
************************************************************/
EXTERN STATUS up_use_stack(_TCB *tcb, void *stack, size_t stack_size);
EXTERN STATUS up_use_stack(FAR _TCB *tcb, FAR void *stack, size_t stack_size);
/************************************************************
* Name: up_release_stack
@ -184,7 +184,7 @@ EXTERN STATUS up_use_stack(_TCB *tcb, void *stack, size_t stack_size);
*
************************************************************/
EXTERN void up_release_stack(_TCB *dtcb);
EXTERN void up_release_stack(FAR _TCB *dtcb);
/************************************************************
* Name: up_unblock_task
@ -202,7 +202,7 @@ EXTERN void up_release_stack(_TCB *dtcb);
*
************************************************************/
EXTERN void up_unblock_task(_TCB *tcb);
EXTERN void up_unblock_task(FAR _TCB *tcb);
/************************************************************
* Name: up_block_task
@ -224,7 +224,7 @@ EXTERN void up_unblock_task(_TCB *tcb);
*
************************************************************/
EXTERN void up_block_task(_TCB *tcb, tstate_t task_state);
EXTERN void up_block_task(FAR _TCB *tcb, tstate_t task_state);
/************************************************************
* Name: up_release_pending
@ -259,7 +259,7 @@ EXTERN void up_release_pending(void);
*
************************************************************/
EXTERN void up_reprioritize_rtr(_TCB *tcb, ubyte priority);
EXTERN void up_reprioritize_rtr(FAR _TCB *tcb, ubyte priority);
/************************************************************
* Name: _exit
@ -314,7 +314,7 @@ EXTERN void up_reprioritize_rtr(_TCB *tcb, ubyte priority);
*
************************************************************/
EXTERN void up_schedule_sigaction(_TCB *tcb, sig_deliver_t sigdeliver);
EXTERN void up_schedule_sigaction(FAR _TCB *tcb, sig_deliver_t sigdeliver);
/************************************************************
* Name: up_allocate_heap
@ -328,7 +328,7 @@ EXTERN void up_schedule_sigaction(_TCB *tcb, sig_deliver_t sigdeliver);
************************************************************/
#ifndef CONFIG_HEAP_BASE
EXTERN void up_allocate_heap(void **heap_start, size_t *heap_size);
EXTERN void up_allocate_heap(FAR void **heap_start, size_t *heap_size);
#endif
/************************************************************
@ -401,7 +401,7 @@ EXTERN void sched_process_timer(void);
*
***********************************************************/
EXTERN void irq_dispatch(int irq, void *context);
EXTERN void irq_dispatch(int irq, FAR void *context);
/************************************************************
* Debug interfaces exported by the architecture-specific

View File

@ -44,26 +44,128 @@
* Definitions
************************************************************/
/* GCC-specific definitions *********************************/
#ifdef __GNUC__
/* GCC supports weak symbols which can be used to reduce
* code size because unnecessary "weak" functions can be
* excluded from the link.
*/
# define CONFIG_HAVE_WEAKFUNCTIONS 1
# define weak_alias(name, aliasname) \
extern __typeof (name) aliasname __attribute__ ((weak, alias (#name)));
# define weak_function __attribute__ ((weak))
# define weak_const_function __attribute__ ((weak, __const__))
/* The noreturn attribute informs GCC that the function will
* not return.
*/
# define noreturn_function __attribute__ ((noreturn))
/* GCC does not support the reentrant attribute */
# define reentrant_function
#elif defined(__SDCC__)
/* GCC has does not use storage classes to qualify addressing */
# define FAR
# define NEAR
/* Select the large, 32-bit addressing model */
# undef CONFIG_SMALL_MEMORY
/* GCC supports inlined functions */
# define CONFIG_HAVE_INLINE 1
/* GCC supports both types double and long long */
# define CONFIG_HAVE_DOUBLE 1
# define CONFIG_HAVE_LONG_LONG 1
/* Structures and unions can be assigned and passed as values */
# define CONFIG_CAN_PASS_STRUCTS 1
/* SDCC-specific definitions ********************************/
#elif defined(SDCC)
/* Disable warnings for unused function arguments */
# pragma disable_warning 85
/* SDCC does not support weak symbols */
# undef CONFIG_HAVE_WEAKFUNCTIONS
# define weak_alias(name, aliasname)
# define weak_function
# define weak_const_function
/* SDCC does not support the noreturn attribute */
# define noreturn_function
/* The reentrant attribute informs SDCC that the function
* must be reentrant. In this case, SDCC will store input
* arguments on the stack to support reentrancy.
*/
# define reentrant_function __reentrant
/* It is assumed that the system is build using the small
* data model with storage defaulting to internal RAM.
* The NEAR storage class can also be used to address data
* in internal RAM; FAR can be used to address data in
* external RAM.
*/
#define FAR __xdata
#define NEAR __data
/* Select small, 16-bit address model */
# define CONFIG_SMALL_MEMORY 1
/* SDCC does not support inline functions */
# undef CONFIG_HAVE_INLINE
/* SDCC does not support type long long or type double */
# undef CONFIG_HAVE_LONG_LONG
# undef CONFIG_HAVE_DOUBLE
/* Structures and unions cannot be passed as values or used
* in assignments.
*/
# undef CONFIG_CAN_PASS_STRUCTS
/* Unknown compiler *****************************************/
#else
# undef CONFIG_HAVE_WEAKFUNCTIONS
# define weak_alias(name, aliasname)
# define weak_function
# define weak_const_function
# define noreturn_function
# define reentrant_function
# define FAR
# define NEAR
# undef CONFIG_SMALL_MEMORY
# undef CONFIG_HAVE_INLINE
# undef CONFIG_HAVE_LONG_LONG
# undef CONFIG_HAVE_DOUBLE
# undef CONFIG_CAN_PASS_STRUCTS
#endif
/************************************************************

View File

@ -60,29 +60,27 @@
struct file;
struct file_operations
{
int (*open)(struct file *);
int (*close)(struct file *);
// off_t (*llseek)(struct file *, off_t, int);
ssize_t (*read)(struct file *, char *, size_t);
ssize_t (*write)(struct file *, const char *, size_t);
// unsigned int (*poll)(struct file *, struct poll_table_struct *);
int (*ioctl)(struct file *, int, unsigned long);
int (*open)(FAR struct file *);
int (*close)(FAR struct file *);
ssize_t (*read)(FAR struct file *, char *, size_t);
ssize_t (*write)(FAR struct file *, const char *, size_t);
int (*ioctl)(FAR struct file *, int, unsigned long);
};
/* This structure represents one inode in the Nuttx psuedo-file system */
struct inode
{
struct inode *i_peer; /* Pointer to inode at same level */
struct inode *i_child; /* Pointer to inode at lower level */
struct file_operations *i_ops; /* Driver file operations for inode */
sint16 i_crefs; /* References to inode */
uint16 i_flags; /* flags for inode */
FAR struct inode *i_peer; /* Pointer to inode at same level */
FAR struct inode *i_child; /* Pointer to inode at lower level */
struct file_operations *i_ops; /* Driver file operations for inode */
sint16 i_crefs; /* References to inode */
uint16 i_flags; /* flags for inode */
#ifdef CONFIG_FILE_MODE
mode_t i_mode; /* Access mode flags */
mode_t i_mode; /* Access mode flags */
#endif
void *i_private; /* Driver private data */
char i_name[1]; /* Name of inode (variable length) */
FAR void *i_private; /* Driver private data */
char i_name[1]; /* Name of inode (variable length) */
};
#define FSNODE_SIZE(n) (sizeof(struct inode) + (n))
@ -94,9 +92,9 @@ struct inode
struct file
{
int f_oflags; /* Open mode flags */
off_t f_pos; /* File position */
struct inode *f_inode; /* Driver interface */
int f_oflags; /* Open mode flags */
off_t f_pos; /* File position */
FAR struct inode *f_inode; /* Driver interface */
};
/* This defines a list of files indexed by the file descriptor */
@ -119,20 +117,20 @@ struct filelist
#if CONFIG_NFILE_STREAMS > 0
struct file_struct
{
int fs_filedes; /* File descriptor associated with stream */
mode_t fs_oflags; /* Open mode flags */
int fs_filedes; /* File descriptor associated with stream */
mode_t fs_oflags; /* Open mode flags */
#if CONFIG_NUNGET_CHARS > 0
uint8 fs_nungotten; /* The number of characters buffered for ungetc */
unsigned char fs_ungotten[CONFIG_NUNGET_CHARS];
uint8 fs_nungotten; /* The number of characters buffered for ungetc */
unsigned char fs_ungotten[CONFIG_NUNGET_CHARS];
#endif
#if CONFIG_STDIO_BUFFER_SIZE > 0
sem_t fs_sem; /* For thread safety */
pid_t fs_holder; /* Holder of sem */
int fs_counts; /* Number of times sem is held */
unsigned char *fs_bufstart; /* Pointer to start of buffer */
unsigned char *fs_bufend; /* Pointer to 1 past end of buffer */
unsigned char *fs_bufpos; /* Current position in buffer */
unsigned char *fs_bufread; /* Pointer to 1 past last buffered read char. */
sem_t fs_sem; /* For thread safety */
pid_t fs_holder; /* Holder of sem */
int fs_counts; /* Number of times sem is held */
FAR unsigned char *fs_bufstart; /* Pointer to start of buffer */
FAR unsigned char *fs_bufend; /* Pointer to 1 past end of buffer */
FAR unsigned char *fs_bufpos; /* Current position in buffer */
FAR unsigned char *fs_bufread; /* Pointer to 1 past last buffered read char. */
#endif
};
@ -170,15 +168,15 @@ EXTERN STATUS unregister_inode(const char *path);
/* fs_open.c ************************************************/
EXTERN int inode_checkflags(struct inode *inode, int oflags);
EXTERN int inode_checkflags(FAR struct inode *inode, int oflags);
/* fs_files.c ***********************************************/
#if CONFIG_NFILE_DESCRIPTORS >0
EXTERN struct filelist *files_alloclist(void);
EXTERN int files_addreflist(struct filelist *list);
EXTERN int files_releaselist(struct filelist *list);
EXTERN int files_dup(struct file *filep1, struct file *filep2);
EXTERN FAR struct filelist *files_alloclist(void);
EXTERN int files_addreflist(FAR struct filelist *list);
EXTERN int files_releaselist(FAR struct filelist *list);
EXTERN int files_dup(FAR struct file *filep1, FAR struct file *filep2);
#endif
/* lib_fopen.c **********************************************/
@ -186,16 +184,16 @@ EXTERN int files_dup(struct file *filep1, struct file *filep2);
/* Used by the OS to clone stdin, stdout, stderr */
#if CONFIG_NFILE_STREAMS > 0
EXTERN struct file_struct *lib_fdopen(int fd,
const char *mode,
struct filelist *flist,
struct streamlist *slist);
EXTERN FAR struct file_struct *lib_fdopen(int fd,
const char *mode,
FAR struct filelist *flist,
FAR struct streamlist *slist);
#endif
/* lib_fflush.c *********************************************/
#if CONFIG_NFILE_STREAMS > 0
EXTERN void lib_flushall(struct streamlist *list);
EXTERN void lib_flushall(FAR struct streamlist *list);
#endif
/* drivers **************************************************/

View File

@ -60,9 +60,9 @@
/* This struct defines the way the registers are stored */
#ifndef __ASSEMBLY__
typedef int (*xcpt_t)(int irq, void *context);
typedef int (*xcpt_t)(int irq, FAR void *context);
typedef int (*swint_t)(int code, int parm2, int parm3,
void *context);
FAR void *context);
#endif
/* Now include architecture-specific types */

View File

@ -63,28 +63,28 @@ extern "C" {
# include <stdlib.h>
# define kmalloc(s) malloc(s)
#else
KMALLOC_EXTERN void *kmalloc(size_t);
KMALLOC_EXTERN FAR void *kmalloc(size_t);
#endif
#ifndef CONFIG_ARCH_KZMALLOC
# include <stdlib.h>
# define kzmalloc(s) zalloc(s)
#else
KMALLOC_EXTERN void *kzalloc(size_t);
KMALLOC_EXTERN FAR void *kzalloc(size_t);
#endif
#ifndef CONFIG_ARCH_KFREE
# include <stdlib.h>
# define kfree(p) free(p)
#else
KMALLOC_EXTERN void kfree(void*);
KMALLOC_EXTERN void kfree(FAR void*);
#endif
/* Functions defined in os_list.c ***************************/
/* Handles memory freed from an interrupt handler */
KMALLOC_EXTERN void sched_free(void *address);
KMALLOC_EXTERN void sched_free(FAR void *address);
#undef KMALLOC_EXTERN
#if defined(__cplusplus)

View File

@ -64,11 +64,11 @@ extern "C" {
/* Functions contained in lib_init.c ************************/
EXTERN void weak_function lib_initialize(void);
EXTERN void weak_function lib_initialize(void);
#if CONFIG_NFILE_STREAMS > 0
EXTERN struct streamlist *lib_alloclist(void);
EXTERN void lib_addreflist(struct streamlist *list);
EXTERN void lib_releaselist(struct streamlist *list);
EXTERN FAR struct streamlist *lib_alloclist(void);
EXTERN void lib_addreflist(FAR struct streamlist *list);
EXTERN void lib_releaselist(FAR struct streamlist *list);
#endif
#undef EXTERN

View File

@ -75,7 +75,7 @@ EXTERN void os_start(void); /* OS entry point called by boot logic */
/* Functions contained in mm_init.c *************************/
EXTERN void mm_initialize(void *heap_start, size_t heap_size);
EXTERN void mm_initialize(FAR void *heap_start, size_t heap_size);
#undef EXTERN
#ifdef __cplusplus

View File

@ -41,6 +41,7 @@
************************************************************/
#include <nuttx/config.h> /* Default settings */
#include <nuttx/compiler.h> /* Compiler settings */
#include <sys/types.h> /* Needed for general types */
#include <semaphore.h> /* Needed for sem_t */
#include <time.h> /* Needed for struct timespec */
@ -85,11 +86,7 @@
/* Thread return value when a pthread is canceled */
#ifdef CONFIG_CAN_CAST_POINTERS
# define PTHREAD_CANCELED ((void*)ERROR)
#else
# define PTHREAD_CANCELED ((void*)pthread_create)
#endif
# define PTHREAD_CANCELED ((FAR void*)ERROR)
/************************************************************
* Global Type Declarations
@ -107,7 +104,7 @@ extern "C" {
*----------------------------------------------------------*/
typedef int pthread_key_t;
typedef void *pthread_addr_t;
typedef FAR void *pthread_addr_t;
typedef pthread_addr_t any_t;
typedef pthread_addr_t (*pthread_startroutine_t)(pthread_addr_t);
@ -115,10 +112,10 @@ typedef pthread_startroutine_t pthread_func_t;
struct pthread_addr_s
{
unsigned long stacksize; /* Size of the stack allocated for the pthead */
short priority; /* Priority of the pthread */
ubyte policy; /* Pthread scheduler policy */
ubyte inheritsched; /* Inherit parent prio/policy? */
size_t stacksize; /* Size of the stack allocated for the pthead */
short priority; /* Priority of the pthread */
ubyte policy; /* Pthread scheduler policy */
ubyte inheritsched; /* Inherit parent prio/policy? */
};
typedef struct pthread_addr_s pthread_attr_t;
@ -173,8 +170,10 @@ EXTERN int pthread_attr_destroy(pthread_attr_t *attr);
* Set or obtain the default scheduling algorithm
*----------------------------------------------------------*/
EXTERN int pthread_attr_setschedpolicy(pthread_attr_t *attr, int policy);
EXTERN int pthread_attr_getschedpolicy(pthread_attr_t *attr, int *policy);
EXTERN int pthread_attr_setschedpolicy(pthread_attr_t *attr,
int policy);
EXTERN int pthread_attr_getschedpolicy(pthread_attr_t *attr,
int *policy);
EXTERN int pthread_attr_setschedparam(pthread_attr_t *attr,
const struct sched_param *param);
EXTERN int pthread_attr_getschedparam(pthread_attr_t *attr,
@ -188,8 +187,10 @@ EXTERN int pthread_attr_getinheritsched(const pthread_attr_t *attr,
* Set or obtain the default stack size
*----------------------------------------------------------*/
EXTERN int pthread_attr_setstacksize(pthread_attr_t *attr, long stacksize);
EXTERN int pthread_attr_getstacksize(pthread_attr_t *attr, long *stackaddr);
EXTERN int pthread_attr_setstacksize(pthread_attr_t *attr,
long stacksize);
EXTERN int pthread_attr_getstacksize(pthread_attr_t *attr,
long *stackaddr);
/*----------------------------------------------------------*
* To create a thread object and runnable thread, a routine
@ -200,7 +201,8 @@ EXTERN int pthread_attr_getstacksize(pthread_attr_t *attr, long *stackaddr);
* specify details about the kind of thread being created.
*----------------------------------------------------------*/
EXTERN int pthread_create(pthread_t *thread, pthread_attr_t *attr,
EXTERN int pthread_create(pthread_t *thread,
pthread_attr_t *attr,
pthread_startroutine_t startRoutine,
pthread_addr_t arg);
@ -216,7 +218,7 @@ EXTERN int pthread_detach(pthread_t thread);
* execution of another thread.
*----------------------------------------------------------*/
EXTERN void pthread_exit(pthread_addr_t pvValue) noreturn_function;
EXTERN void pthread_exit(pthread_addr_t value) noreturn_function;
EXTERN int pthread_cancel(pthread_t thread);
EXTERN int pthread_setcancelstate(int state, int *oldstate);
EXTERN void pthread_testcancel(void);
@ -226,7 +228,8 @@ EXTERN void pthread_testcancel(void);
* the return value of the thread.
*----------------------------------------------------------*/
EXTERN int pthread_join(pthread_t thread, pthread_addr_t *ppvValue);
EXTERN int pthread_join(pthread_t thread,
pthread_addr_t *value);
/*----------------------------------------------------------*
* A thread may tell the scheduler that its processor can be
@ -245,7 +248,8 @@ EXTERN void pthread_yield(void);
* Thread scheduling parameters
*----------------------------------------------------------*/
EXTERN int pthread_getschedparam(pthread_t thread, int *policy,
EXTERN int pthread_getschedparam(pthread_t thread,
int *policy,
struct sched_param *param);
EXTERN int pthread_setschedparam(pthread_t thread, int policy,
const struct sched_param *param);
@ -255,9 +259,9 @@ EXTERN int pthread_setschedparam(pthread_t thread, int policy,
*----------------------------------------------------------*/
EXTERN int pthread_key_create(pthread_key_t *key,
void (*destructor)(void*));
EXTERN int pthread_setspecific(pthread_key_t key, void *value);
EXTERN void *pthread_getspecific(pthread_key_t key);
FAR void (*destructor)(FAR void*));
EXTERN int pthread_setspecific(pthread_key_t key, FAR void *value);
EXTERN FAR void *pthread_getspecific(pthread_key_t key);
EXTERN int pthread_key_delete(pthread_key_t key);
/*----------------------------------------------------------*
@ -294,7 +298,8 @@ EXTERN int pthread_condattr_destroy(pthread_condattr_t *attr);
* A thread can create and delete condition variables.
*----------------------------------------------------------*/
EXTERN int pthread_cond_init(pthread_cond_t *cond, pthread_condattr_t *attr);
EXTERN int pthread_cond_init(pthread_cond_t *cond,
pthread_condattr_t *attr);
EXTERN int pthread_cond_destroy(pthread_cond_t *cond);
/*----------------------------------------------------------*
@ -302,21 +307,23 @@ EXTERN int pthread_cond_destroy(pthread_cond_t *cond);
*----------------------------------------------------------*/
EXTERN int pthread_cond_broadcast(pthread_cond_t *cond);
EXTERN int pthread_cond_signal(pthread_cond_t *dond);
EXTERN int pthread_cond_signal(pthread_cond_t *cond);
/*----------------------------------------------------------*
* A thread can wait for a condition variable to be signalled
* or broadcast.
*----------------------------------------------------------*/
EXTERN int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex);
EXTERN int pthread_cond_wait(pthread_cond_t *cond,
pthread_mutex_t *mutex);
/*----------------------------------------------------------*
* A thread can perform a timed wait on a condition variable.
*----------------------------------------------------------*/
EXTERN int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
const struct timespec *abstime);
EXTERN int pthread_cond_timedwait(pthread_cond_t *cond,
pthread_mutex_t *mutex,
const struct timespec *abstime);
#undef EXTERN
#ifdef __cplusplus

View File

@ -58,25 +58,28 @@
struct sq_entry_s
{
struct sq_entry_s *flink;
FAR struct sq_entry_s *flink;
};
typedef struct sq_entry_s sq_entry_t;
struct dq_entry_s
{
struct dq_entry_s *flink, *blink;
FAR struct dq_entry_s *flink;
FAR struct dq_entry_s *blink;
};
typedef struct dq_entry_s dq_entry_t;
struct sq_queue_s
{
sq_entry_t *head, *tail;
FAR sq_entry_t *head;
FAR sq_entry_t *tail;
};
typedef struct sq_queue_s sq_queue_t;
struct dq_queue_s
{
dq_entry_t *head, *tail;
FAR dq_entry_t *head;
FAR dq_entry_t *tail;
};
typedef struct dq_queue_s dq_queue_t;
@ -91,23 +94,24 @@ extern "C" {
#define EXTERN extern
#endif
EXTERN void sq_addfirst(sq_entry_t *node, sq_queue_t *queue);
EXTERN void dq_addfirst(dq_entry_t *node, dq_queue_t *queue);
EXTERN void sq_addlast(sq_entry_t *node, sq_queue_t *queue);
EXTERN void dq_addlast(dq_entry_t *node, dq_queue_t *queue);
EXTERN void sq_addafter(sq_entry_t *prev, sq_entry_t *node,
sq_queue_t *queue);
EXTERN void dq_addafter(dq_entry_t *prev, dq_entry_t *node,
dq_queue_t *queue);
EXTERN void dq_addbefore(dq_entry_t *next, dq_entry_t *node,
dq_queue_t *queue);
EXTERN sq_entry_t *sq_remafter(sq_entry_t *node, sq_queue_t *queue);
EXTERN void sq_rem(sq_entry_t *node, sq_queue_t *queue);
EXTERN void dq_rem(dq_entry_t *node, dq_queue_t *queue);
EXTERN sq_entry_t *sq_remlast(sq_queue_t *queue);
EXTERN dq_entry_t *dq_remlast(dq_queue_t *queue);
EXTERN sq_entry_t *sq_remfirst(sq_queue_t *queue);
EXTERN dq_entry_t *dq_remfirst(dq_queue_t *queue);
EXTERN void sq_addfirst(FAR sq_entry_t *node, sq_queue_t *queue);
EXTERN void dq_addfirst(FAR dq_entry_t *node, dq_queue_t *queue);
EXTERN void sq_addlast(FAR sq_entry_t *node, sq_queue_t *queue);
EXTERN void dq_addlast(FAR dq_entry_t *node, dq_queue_t *queue);
EXTERN void sq_addafter(FAR sq_entry_t *prev, FAR sq_entry_t *node,
sq_queue_t *queue);
EXTERN void dq_addafter(FAR dq_entry_t *prev, FAR dq_entry_t *node,
dq_queue_t *queue);
EXTERN void dq_addbefore(FAR dq_entry_t *next, FAR dq_entry_t *node,
dq_queue_t *queue);
EXTERN FAR sq_entry_t *sq_remafter(FAR sq_entry_t *node, sq_queue_t *queue);
EXTERN void sq_rem(FAR sq_entry_t *node, sq_queue_t *queue);
EXTERN void dq_rem(FAR dq_entry_t *node, dq_queue_t *queue);
EXTERN FAR sq_entry_t *sq_remlast(sq_queue_t *queue);
EXTERN FAR dq_entry_t *dq_remlast(dq_queue_t *queue);
EXTERN FAR sq_entry_t *sq_remfirst(sq_queue_t *queue);
EXTERN FAR dq_entry_t *dq_remfirst(dq_queue_t *queue);
#undef EXTERN
#ifdef __cplusplus

View File

@ -147,7 +147,8 @@ struct _TCB
{
/* Fields used to support list management ***************************/
struct _TCB *flink, *blink; /* link in DQ of TCBs */
FAR struct _TCB *flink; /* link in DQ of TCBs */
FAR struct _TCB *blink;
/* Task Management Fields *******************************************/
@ -159,7 +160,7 @@ struct _TCB
tstate_t task_state; /* Current state of the thread */
uint16 flags; /* Misc. general status flags */
sint16 lockcount; /* 0=preemptable (not-locked) */
void *joininfo; /* Detach-able info to support join */
FAR void *joininfo; /* Detach-able info to support join */
#if CONFIG_RR_INTERVAL > 0
int timeslice; /* RR timeslice interval remaining */
#endif
@ -167,27 +168,27 @@ struct _TCB
/* Values needed to restart a task **********************************/
ubyte init_priority; /* Initial priority of the task */
char *argv[NUM_TASK_ARGS+1]; /* Name + start-up parameters */
FAR char *argv[NUM_TASK_ARGS+1]; /* Name + start-up parameters */
/* Stack-Related Fields *********************************************/
size_t adj_stack_size; /* Stack size after adjustment */
/* for hardware, processor, etc. */
/* (for debug purposes only) */
void *stack_alloc_ptr; /* Pointer to allocated stack */
FAR void *stack_alloc_ptr; /* Pointer to allocated stack */
/* Need to deallocate stack */
void *adj_stack_ptr; /* Adjusted StatckAllocPtr for HW */
FAR void *adj_stack_ptr; /* Adjusted StatckAllocPtr for HW */
/* The initial stack pointer value */
/* POSIX thread Specific Data ***************************************/
#if CONFIG_NPTHREAD_KEYS > 0
void *pthread_data[CONFIG_NPTHREAD_KEYS];
FAR void *pthread_data[CONFIG_NPTHREAD_KEYS];
#endif
/* POSIX Semaphore Control Fields ***********************************/
sem_t *waitsem; /* Semaphore ID waiting on */
sem_t *waitsem; /* Semaphore ID waiting on */
/* POSIX Signal Control Fields **************************************/
@ -202,7 +203,7 @@ struct _TCB
/* POSIX Named Message Queue Fields *********************************/
sq_queue_t msgdesq; /* List of opened message queues */
msgq_t *msgwaitq; /* Waiting for this message queue */
FAR msgq_t *msgwaitq; /* Waiting for this message queue */
/* Library related fields *******************************************/
@ -211,11 +212,11 @@ struct _TCB
/* File system support **********************************************/
#if CONFIG_NFILE_DESCRIPTORS > 0
struct filelist *filelist; /* Maps file descriptor to file */
FAR struct filelist *filelist; /* Maps file descriptor to file */
#endif
#if CONFIG_NFILE_STREAMS > 0
struct streamlist *streams; /* Holds C buffered I/O info */
FAR struct streamlist *streams; /* Holds C buffered I/O info */
#endif
/* State save areas *************************************************/
@ -246,29 +247,31 @@ extern "C" {
/* Task Control Interfaces (non-standard) */
EXTERN STATUS task_init(_TCB *tcb , char *name, int priority,
uint32 *stack, uint32 stack_size, main_t entry,
char *arg1, char *arg2, char *arg3, char *arg4);
EXTERN STATUS task_activate(_TCB *tcb);
EXTERN int task_create(char *name, int priority, int stack_size, main_t main,
char *arg1, char *arg2, char *arg3, char *arg4);
EXTERN STATUS task_init(FAR _TCB *tcb, const char *name, int priority,
FAR uint32 *stack, uint32 stack_size, main_t entry,
FAR char *arg1, FAR char *arg2,
FAR char *arg3, FAR char *arg4);
EXTERN STATUS task_activate(FAR _TCB *tcb);
EXTERN int task_create(const char *name, int priority, int stack_size, main_t main,
FAR char *arg1, FAR char *arg2,
FAR char *arg3, FAR char *arg4);
EXTERN STATUS task_delete(pid_t pid);
EXTERN STATUS task_restart(pid_t pid);
/* Task Scheduling Interfaces (based on POSIX APIs) */
EXTERN int sched_setparam(pid_t pid,
const struct sched_param * param);
const struct sched_param *param);
EXTERN int sched_getparam(pid_t pid,
struct sched_param * param);
struct sched_param *param);
EXTERN int sched_setscheduler(pid_t pid, int policy,
const struct sched_param * param);
const struct sched_param *param);
EXTERN int sched_getscheduler(pid_t pid);
EXTERN int sched_yield(void);
EXTERN int sched_get_priority_max(int policy);
EXTERN int sched_get_priority_min(int policy);
EXTERN int sched_rr_get_interval(pid_t pid,
struct timespec * interval);
struct timespec *interval);
/* Task Switching Interfaces (non-standard) */
@ -282,9 +285,9 @@ EXTERN sint32 sched_lockcount(void);
#ifdef CONFIG_SCHED_INSTRUMENTATION
EXTERN void sched_note_start(_TCB *tcb );
EXTERN void sched_note_stop(_TCB *tcb );
EXTERN void sched_note_switch(_TCB *pFromTcb, _TCB *pToTcb);
EXTERN void sched_note_start(FAR _TCB *tcb );
EXTERN void sched_note_stop(FAR _TCB *tcb );
EXTERN void sched_note_switch(FAR _TCB *pFromTcb, FAR _TCB *pToTcb);
#else
# define sched_note_start(t)
@ -295,9 +298,9 @@ EXTERN void sched_note_switch(_TCB *pFromTcb, _TCB *pToTcb);
/* File system helpers */
#if CONFIG_NFILE_DESCRIPTORS > 0
EXTERN struct filelist *sched_getfiles(void);
EXTERN FAR struct filelist *sched_getfiles(void);
#if CONFIG_NFILE_STREAMS > 0
EXTERN struct streamlist *sched_getstreams(void);
EXTERN FAR struct streamlist *sched_getstreams(void);
#endif /* CONFIG_NFILE_STREAMS */
#endif /* CONFIG_NFILE_DESCRIPTORS */

View File

@ -84,15 +84,15 @@ typedef struct sem_s sem_t;
/* Counting Semaphore Interfaces (based on POSIX APIs) */
EXTERN int sem_init(sem_t *sem, int pshared, unsigned int value);
EXTERN int sem_destroy(sem_t *sem);
EXTERN sem_t *sem_open(const char *name, int oflag, ...);
EXTERN int sem_close(sem_t *sem);
EXTERN int sem_unlink(const char *name);
EXTERN int sem_wait(sem_t *sem);
EXTERN int sem_trywait(sem_t *sem);
EXTERN int sem_post(sem_t *sem);
EXTERN int sem_getvalue(sem_t *sem, int *sval);
EXTERN int sem_init(sem_t *sem, int pshared, unsigned int value);
EXTERN int sem_destroy(sem_t *sem);
EXTERN FAR sem_t *sem_open(const char *name, int oflag, ...);
EXTERN int sem_close(FAR sem_t *sem);
EXTERN int sem_unlink(const char *name);
EXTERN int sem_wait(sem_t *sem);
EXTERN int sem_trywait(sem_t *sem);
EXTERN int sem_post(sem_t *sem);
EXTERN int sem_getvalue(sem_t *sem, int *sval);
#undef EXTERN
#ifdef __cplusplus

View File

@ -41,6 +41,7 @@
************************************************************/
#include <nuttx/config.h>
#include <nuttx/compiler.h>
#include <time.h> /* Needed for struct timespec */
#include <sys/types.h> /* Needed for, e.g., sigset_t */
@ -123,7 +124,7 @@ struct sigaction
union
{
void (*_sa_handler)(int);
void (*_sa_sigaction)(int, siginfo_t *, void *);
void (*_sa_sigaction)(int, FAR siginfo_t *, FAR void *);
} sa_u;
sigset_t sa_mask;
int sa_flags;
@ -155,7 +156,7 @@ EXTERN int sigaction(int sig,
const struct sigaction *act,
struct sigaction *oact);
EXTERN int sigprocmask(int how, const sigset_t *set,
sigset_t *oset);
sigset_t *oset);
EXTERN int sigpending(sigset_t *set);
EXTERN int sigsuspend(const sigset_t *sigmask);
EXTERN int sigwaitinfo(const sigset_t *set,

View File

@ -129,12 +129,12 @@
struct _dirent
{
char *d_name; /* name of directory entry */
FAR char *d_name; /* name of directory entry */
};
struct dirent
{
char *d_name; /* A pointer to szName */
char szName[NAME_MAX+1]; /* name of the directory entry */
FAR char *d_name; /* A pointer to d_szname */
char d_szname[NAME_MAX+1]; /* name of the directory entry */
};
typedef struct
@ -147,7 +147,7 @@ typedef struct
{
unsigned long inode;
int generation;
char *fileName;
FAR char *filename;
} HANDLE_TO_NAME_IOCTL;
struct stat
@ -186,7 +186,7 @@ struct statfs
/* Streams */
typedef struct file_struct FILE;
typedef FAR struct file_struct FILE;
typedef void DIR;
@ -239,22 +239,22 @@ EXTERN int close(int fd);
EXTERN int closedir(DIR *dirp);
EXTERN int creat(const char *path, mode_t mode);
EXTERN FILE *fdopen(int fd, const char *type);
EXTERN int fstat(int fd, struct stat *buf);
EXTERN char *getcwd(char *buf, size_t size);
EXTERN int fstat(int fd, FAR struct stat *buf);
EXTERN char *getcwd(FAR char *buf, size_t size);
EXTERN int ioctl(int fd, int req, unsigned long arg);
EXTERN off_t lseek(int fd, off_t offset, int whence);
EXTERN int mkdir(const char *path, mode_t mode);
EXTERN int open( const char *path, int oflag, ... );
EXTERN int open(const char *path, int oflag, ...);
EXTERN DIR *opendir(const char *path);
EXTERN int read(int fd, void *buf, unsigned int nbytes);
EXTERN struct _dirent *readdir(DIR *dirp);
EXTERN int readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result);
EXTERN void rewinddir(DIR *dirp);
EXTERN struct _dirent *readdir(FAR DIR *dirp);
EXTERN int readdir_r(FAR DIR *dirp, struct dirent *entry, FAR struct dirent **result);
EXTERN void rewinddir(FAR DIR *dirp);
EXTERN int rmdir(const char *path);
EXTERN void seekdir(DIR *dirp, int loc);
EXTERN int stat(const char *path, struct stat *buf);
EXTERN int statfs(const char *path, struct statfs *buf);
EXTERN int telldir(DIR *dirp);
EXTERN void seekdir(FAR DIR *dirp, int loc);
EXTERN int stat(const char *path, FAR struct stat *buf);
EXTERN int statfs(const char *path, FAR struct statfs *buf);
EXTERN int telldir(FAR DIR *dirp);
EXTERN int unlink(const char *path);
EXTERN int write(int fd, const void *buf, unsigned int nbytes);

View File

@ -83,30 +83,40 @@ extern "C" {
#endif
/* Random number generation */
EXTERN void srand(unsigned int seed);
EXTERN int rand(void);
EXTERN void srand(unsigned int seed);
EXTERN int rand(void);
/* Environment variable support */
EXTERN char *getenv(const char *name);
EXTERN char *getenv(const char *name);
/* Process exit functions */
EXTERN void exit(int status);
EXTERN void abort(void);
EXTERN int atexit(void (*func)(void));
EXTERN void exit(int status);
EXTERN void abort(void);
EXTERN int atexit(void (*func)(void));
/* String to binary conversions */
#define atoi(nptr) strtol((nptr), (char**)NULL, 10)
EXTERN long strtol(const char *, char **, int);
EXTERN double_t strtod(const char *, char **);
#define atoi(nptr) strtol((nptr), (FAR char**)NULL, 10)
EXTERN long strtol(const char *, char **, int);
EXTERN double_t strtod(const char *, char **);
/* Memory Management */
EXTERN void *malloc(size_t);
EXTERN void free(void*);
EXTERN void *realloc(void*, size_t);
EXTERN void *memalign(size_t, size_t);
EXTERN void *zalloc(size_t);
EXTERN void *calloc(size_t, size_t);
EXTERN FAR void *malloc(size_t);
EXTERN void free(FAR void*);
EXTERN FAR void *realloc(FAR void*, size_t);
EXTERN FAR void *memalign(size_t, size_t);
EXTERN FAR void *zalloc(size_t);
EXTERN FAR void *calloc(size_t, size_t);
#ifdef CONFIG_CAN_PASS_STRUCTS
EXTERN struct mallinfo mallinfo(void);
#else
EXTERN int mallinfo(struct mallinfo *info);
#endif
#undef EXTERN
#if defined(__cplusplus)

View File

@ -60,7 +60,7 @@ extern "C" {
#endif
EXTERN char *strchr(const char *s, int c);
EXTERN char *strdup(const char *s);
EXTERN FAR char *strdup(const char *s);
EXTERN char *strerror(int);
EXTERN size_t strlen(const char *);
EXTERN char *strncat(char *, const char *, size_t);
@ -74,7 +74,7 @@ EXTERN char *strrchr(const char *, int);
EXTERN size_t strspn(const char *, const char *);
EXTERN size_t strcspn(const char *, const char *);
EXTERN char *strstr(const char *, const char *);
EXTERN char *strtok(char *, const char *);
EXTERN char *strtok(FAR char *, const char *);
EXTERN void *memset(void *s, int c, size_t n);
EXTERN void *memcpy(void *dest, const void *src, size_t n);

View File

@ -67,7 +67,7 @@ extern "C" {
/* Task Control Interfaces (based on ANSII APIs) */
EXTERN pid_t getpid( void );
EXTERN pid_t getpid(void);
EXTERN void _exit(int status) noreturn_function;
EXTERN unsigned int sleep(unsigned int seconds);
EXTERN void usleep(unsigned long usec);

View File

@ -80,7 +80,7 @@ typedef void (*wdentry_t)(int argc, uint32 arg1, ...);
/* Watchdog 'handle' */
typedef struct wdog_s *WDOG_ID;
typedef FAR struct wdog_s *WDOG_ID;
/************************************************************
* Global Variables

View File

@ -91,7 +91,7 @@ $(BIN): $(OBJS)
depend: .depend
clean:
rm -f $(BIN) *.o *~
rm -f $(BIN) *.o *.asm *.lst *.sym *.adb *~
distclean: clean
rm -f Make.dep .depend

View File

@ -56,7 +56,7 @@
*
************************************************************/
void dq_addafter(dq_entry_t *prev, dq_entry_t *node,
void dq_addafter(FAR dq_entry_t *prev, FAR dq_entry_t *node,
dq_queue_t *queue)
{
if (!queue->head || prev == queue->tail)
@ -65,10 +65,10 @@ void dq_addafter(dq_entry_t *prev, dq_entry_t *node,
}
else
{
dq_entry_t *next = prev->flink;
node->blink = prev;
node->flink = next;
next->blink = node;
prev->flink = node;
FAR dq_entry_t *next = prev->flink;
node->blink = prev;
node->flink = next;
next->blink = node;
prev->flink = node;
}
}

View File

@ -55,7 +55,7 @@
*
************************************************************/
void dq_addbefore(dq_entry_t *next, dq_entry_t *node,
void dq_addbefore(FAR dq_entry_t *next, FAR dq_entry_t *node,
dq_queue_t *queue)
{
if (!queue->head || next == queue->head)
@ -64,10 +64,10 @@ void dq_addbefore(dq_entry_t *next, dq_entry_t *node,
}
else
{
dq_entry_t *prev = next->blink;
node->flink = next;
node->blink = prev;
prev->flink = node;
next->blink = node;
FAR dq_entry_t *prev = next->blink;
node->flink = next;
node->blink = prev;
prev->flink = node;
next->blink = node;
}
}

View File

@ -55,7 +55,7 @@
*
************************************************************/
void dq_addfirst(dq_entry_t *node, dq_queue_t *queue)
void dq_addfirst(FAR dq_entry_t *node, dq_queue_t *queue)
{
node->blink = NULL;
node->flink = queue->head;
@ -71,3 +71,4 @@ void dq_addfirst(dq_entry_t *node, dq_queue_t *queue)
queue->head = node;
}
}

View File

@ -55,7 +55,7 @@
*
************************************************************/
void dq_addlast(dq_entry_t *node, dq_queue_t *queue)
void dq_addlast(FAR dq_entry_t *node, dq_queue_t *queue)
{
node->flink = NULL;
node->blink = queue->tail;
@ -71,3 +71,4 @@ void dq_addlast(dq_entry_t *node, dq_queue_t *queue)
queue->tail = node;
}
}

View File

@ -55,10 +55,10 @@
*
************************************************************/
void dq_rem(dq_entry_t *node, dq_queue_t *queue)
void dq_rem(FAR dq_entry_t *node, dq_queue_t *queue)
{
dq_entry_t *prev = node->blink;
dq_entry_t *next = node->flink;
FAR dq_entry_t *prev = node->blink;
FAR dq_entry_t *next = node->flink;
if (!prev)
{
@ -81,3 +81,4 @@ void dq_rem(dq_entry_t *node, dq_queue_t *queue)
node->flink = NULL;
node->blink = NULL;
}

View File

@ -55,13 +55,13 @@
*
************************************************************/
dq_entry_t *dq_remfirst(dq_queue_t *queue)
FAR dq_entry_t *dq_remfirst(dq_queue_t *queue)
{
dq_entry_t *ret = queue->head;
FAR dq_entry_t *ret = queue->head;
if (ret)
{
dq_entry_t *next = ret->flink;
FAR dq_entry_t *next = ret->flink;
if (!next)
{
queue->head = NULL;
@ -79,3 +79,4 @@ dq_entry_t *dq_remfirst(dq_queue_t *queue)
return ret;
}

View File

@ -55,13 +55,13 @@
*
************************************************************/
dq_entry_t *dq_remlast(dq_queue_t *queue)
FAR dq_entry_t *dq_remlast(dq_queue_t *queue)
{
dq_entry_t *ret = queue->tail;
FAR dq_entry_t *ret = queue->tail;
if (ret)
{
dq_entry_t *prev = ret->blink;
FAR dq_entry_t *prev = ret->blink;
if (!prev)
{
queue->head = NULL;
@ -79,3 +79,4 @@ dq_entry_t *dq_remlast(dq_queue_t *queue)
return ret;
}

View File

@ -65,7 +65,7 @@ int fclose(FILE *stream)
ret = close(stream->fs_filedes);
}
#warning REVIEW for race conditions
#if CONFIG_NFILE_STREAMS > 0
#if CONFIG_STDIO_BUFFER_SIZE > 0
/* Destroy the semaphore */
sem_destroy(&stream->fs_sem);

View File

@ -88,7 +88,7 @@
/* Called by the OS when a task exits */
void lib_flushall(struct streamlist *list)
void lib_flushall(FAR struct streamlist *list)
{
/* Make sure that there are streams associated with this thread */
if (list)

View File

@ -39,14 +39,14 @@
#include <nuttx/config.h>
#if CONFIG_STDIO_BUFFER_SIZE > 0
#include <unistd.h>
#include <semaphore.h>
#include <errno.h>
#include <assert.h>
#include "lib_internal.h"
#if CONFIG_STDIO_BUFFER_SIZE > 0
/************************************************************
* Definitions
************************************************************/
@ -63,7 +63,7 @@
* lib_sem_initialize
************************************************************/
void lib_sem_initialize(struct file_struct *stream)
void lib_sem_initialize(FAR struct file_struct *stream)
{
/* Initialize the LIB semaphore to one (to support one-at-
* a-time access to private data sets.
@ -79,7 +79,7 @@ void lib_sem_initialize(struct file_struct *stream)
* lib_take_semaphore
************************************************************/
void lib_take_semaphore(struct file_struct *stream)
void lib_take_semaphore(FAR struct file_struct *stream)
{
pid_t my_pid = getpid();
@ -115,7 +115,7 @@ void lib_take_semaphore(struct file_struct *stream)
* lib_give_semaphore
************************************************************/
void lib_give_semaphore(struct file_struct *stream)
void lib_give_semaphore(FAR struct file_struct *stream)
{
pid_t my_pid = getpid();

View File

@ -130,14 +130,14 @@ static int lib_mode2oflags(const char *mode)
* Public Functions
************************************************************/
struct file_struct *lib_fdopen(int fd, const char *mode,
struct filelist *flist,
struct streamlist *slist)
FAR struct file_struct *lib_fdopen(int fd, const char *mode,
FAR struct filelist *flist,
FAR struct streamlist *slist)
{
struct inode *inode = flist->fl_files[fd].f_inode;
FILE *stream;
int oflags = lib_mode2oflags(mode);
int i;
FAR struct inode *inode = flist->fl_files[fd].f_inode;
FILE *stream;
int oflags = lib_mode2oflags(mode);
int i;
if (fd < 0 || !flist || !slist)
{
@ -209,19 +209,19 @@ struct file_struct *lib_fdopen(int fd, const char *mode,
FILE *fdopen(int fd, const char *mode)
{
struct filelist *flist = sched_getfiles();
struct streamlist *slist = sched_getstreams();
FAR struct filelist *flist = sched_getfiles();
FAR struct streamlist *slist = sched_getstreams();
return lib_fdopen(fd, mode, flist, slist);
}
FILE *fopen(const char *path, const char *mode)
{
struct filelist *flist = sched_getfiles();
struct streamlist *slist = sched_getstreams();
int oflags = lib_mode2oflags(mode);
int fd = open(path, oflags, 0666);
FAR struct filelist *flist = sched_getfiles();
FAR struct streamlist *slist = sched_getstreams();
int oflags = lib_mode2oflags(mode);
int fd = open(path, oflags, 0666);
FILE *ret = lib_fdopen(fd, mode, flist, slist);
FILE *ret = lib_fdopen(fd, mode, flist, slist);
if (!ret)
{
(void)close(fd);

View File

@ -103,61 +103,68 @@ char *getenv(const char *name)
const char *pend = &environment[size-1];
const char *ptmp;
dbg("getenv(ge): name=\"%s\"\n", name);
dbg("name=\"%s\"\n", name);
if (name) {
if (name)
{
/* Process each string in the environment. */
/* Process each string in the environment. */
while (penv < pend) {
while (penv < pend)
{
vdbg("Compare to=\"%s\"\n", penv);
vdbg("(ge):\tCompare to=\"%s\"\n", penv);
/* The logic below basically implements a version of
* strcmp where the strings may be terminated with = signs.
*/
/* The logic below basically implements a version of
* strcmp where the strings may be terminated with = signs. */
ptmp = name;
for (;;) {
ptmp = name;
for (;;)
{
/* Are we at the end of the name-to-matching? */
/* Are we at the end of the name-to-matching? */
if ((!*ptmp) || (*ptmp == '=')) {
if (!*ptmp || *ptmp == '=')
{
/* Yes.. are we also at the end of the matching-name? */
/* Yes.. are we also at the end of the matching-name? */
if (*penv == '=') {
if (*penv == '=')
{
/* Yes.. return the pointer to the value. */
/* Yes.. return the pointer to the value. */
dbg("(ge):\tReturning \"%s\"\n", penv+1);
return ((char*)penv+1);
dbg("Returning \"%s\"\n", penv+1);
return ((char*)penv+1);
}
else
{
/* No.. Skip to the next name matching name candidate. */
} /* end if */
else {
while(*penv++);
break;
}
}
/* No.. Skip to the next name matching name candidate. */
while(*penv++);
break;
} /* end else */
} /* end if */
/* NO.. are we at the end of the matching name candidate?
* OR.. do the corresponding characters not match.
*/
/* NO.. are we at the end of the matching name candidate? */
/* OR.. do the corresponding characters not match. */
else if (*penv != *ptmp) {
else if (*penv != *ptmp)
{
/* Yes.. Skip to the next name matching name candidate. */
/* Yes.. Skip to the next name matching name candidate. */
while(*penv++);
break;
} /* end else if */
else {
while(*penv++);
break;
}
else
{
/* No.. try the next characters. */
/* No.. try the next characters. */
penv++; ptmp++;
} /* end else */
} /* end for */
} /* end while */
} /* end if */
penv++; ptmp++;
}
}
}
}
/* If we got here, then no matching string was found. */
dbg("(ge):\tReturning NULL\n");
return NULL;
} /* end getenv */
dbg("Returning NULL\n");
return NULL;
}

View File

@ -57,7 +57,7 @@
* Private Functions
************************************************************/
static void _lib_semtake(struct streamlist *list)
static void _lib_semtake(FAR struct streamlist *list)
{
/* Take the semaphore (perhaps waiting) */
@ -92,10 +92,10 @@ void weak_const_function lib_initialize(void)
* creates the streamlist instance that is stored in the TCB.
*/
struct streamlist *lib_alloclist(void)
FAR struct streamlist *lib_alloclist(void)
{
struct streamlist *list;
list = (struct streamlist*)kzmalloc(sizeof(struct streamlist));
FAR struct streamlist *list;
list = (FAR struct streamlist*)kzmalloc(sizeof(struct streamlist));
if (list)
{
int i;
@ -136,7 +136,7 @@ struct streamlist *lib_alloclist(void)
* list.
*/
void lib_addreflist(struct streamlist *list)
void lib_addreflist(FAR struct streamlist *list)
{
if (list)
{
@ -153,7 +153,7 @@ void lib_addreflist(struct streamlist *list)
* separately when the file descriptor list is freed.
*/
void lib_releaselist(struct streamlist *list)
void lib_releaselist(FAR struct streamlist *list)
{
int crefs;
if (list)
@ -178,7 +178,7 @@ void lib_releaselist(struct streamlist *list)
sched_free(list);
/* Initialize each FILE structure */
#if CONFIG_STDIO_BUFFER_SIZE > 0
for (i = 0; i < CONFIG_NFILE_STREAMS; i++)
{
/* Destroy the semaphore that protects the IO buffer */
@ -191,6 +191,7 @@ void lib_releaselist(struct streamlist *list)
free(list->sl_streams[i].fs_bufstart);
}
}
#endif
}
}
}

View File

@ -104,8 +104,8 @@ struct lib_rawstream_s
/* Defined in lib_streamsem.c */
extern void stream_semtake(struct streamlist *list);
extern void stream_semgive(struct streamlist *list);
extern void stream_semtake(FAR struct streamlist *list);
extern void stream_semgive(FAR struct streamlist *list);
/* Defined in lib_memstream.c */
@ -135,8 +135,8 @@ extern int lib_sprintf (struct lib_stream_s *obj,
/* Defined lib_libvsprintf.c */
extern int lib_vsprintf(struct lib_stream_s *obj,
const char *src, va_list ap);
extern int lib_vsprintf(struct lib_stream_s *obj,
const char *src, va_list ap);
/* Defined in lib_libwrite.c */
@ -149,9 +149,9 @@ extern ssize_t lib_fread(void *ptr, size_t count, FILE *stream);
/* Defined in lib_sem.c */
#if CONFIG_STDIO_BUFFER_SIZE > 0
extern void lib_sem_initialize(struct file_struct *stream);
extern void lib_take_semaphore(struct file_struct *stream);
extern void lib_give_semaphore(struct file_struct *stream);
extern void lib_sem_initialize(FAR struct file_struct *stream);
extern void lib_take_semaphore(FAR struct file_struct *stream);
extern void lib_give_semaphore(FAR struct file_struct *stream);
#endif
/* Defined in lib_libgetbase.c */

View File

@ -41,6 +41,7 @@
* Included Files
************************************************************/
#include <nuttx/compiler.h>
#include <sys/types.h>
#include <stdio.h>
#include <string.h>

View File

@ -37,6 +37,7 @@
* Included Files
************************************************************/
#include <nuttx/compiler.h>
#include <sys/types.h>
#include <stdarg.h>
#include <stdlib.h>
@ -128,203 +129,214 @@ int vsscanf(char *buf, const char *s, va_list ap)
/* Skip over white space */
while (isspace(*s))
s++;
s++;
/* Check for a conversion specifier */
if (*s == '%')
{
vdbg("vsscanf: Specifier found\n");
{
vdbg("vsscanf: Specifier found\n");
/* Check for qualifiers on the conversion specifier */
s++;
for (; *s; s++)
{
vdbg("vsscanf: Processing %c\n", *s);
/* Check for qualifiers on the conversion specifier */
s++;
for (; *s; s++)
{
vdbg("vsscanf: Processing %c\n", *s);
if (strchr("dibouxcsefg%", *s))
break;
if (*s == '*')
noassign = 1;
else if (*s == 'l' || *s == 'L')
lflag = 1;
else if (*s >= '1' && *s <= '9') {
for (tc = s; isdigit(*s); s++);
strncpy(tmp, tc, s - tc);
tmp[s - tc] = '\0';
width = atoi(tmp);
/* atob(&width, tmp, 10); */
s--;
}
}
if (strchr("dibouxcsefg%", *s))
break;
if (*s == '*')
noassign = 1;
else if (*s == 'l' || *s == 'L')
lflag = 1;
else if (*s >= '1' && *s <= '9') {
for (tc = s; isdigit(*s); s++);
strncpy(tmp, tc, s - tc);
tmp[s - tc] = '\0';
width = atoi(tmp);
/* atob(&width, tmp, 10); */
s--;
}
}
/* Process %s: String conversion */
/* Process %s: String conversion */
if (*s == 's')
{
vdbg("vsscanf: Performing string conversion\n");
if (*s == 's')
{
vdbg("vsscanf: Performing string conversion\n");
while (isspace(*buf))
buf++;
if (!width)
{
width = strcspn(buf, spaces);
}
if (!noassign)
{
tv = va_arg(ap, char*);
strncpy(tv, buf, width);
tv[width] = '\0';
}
buf += width;
}
while (isspace(*buf))
buf++;
if (!width)
{
width = strcspn(buf, spaces);
}
if (!noassign)
{
tv = va_arg(ap, char*);
strncpy(tv, buf, width);
tv[width] = '\0';
}
buf += width;
}
/* Process %c: Character conversion */
/* Process %c: Character conversion */
else if (*s == 'c')
{
vdbg("vsscanf: Performing character conversion\n");
else if (*s == 'c')
{
vdbg("vsscanf: Performing character conversion\n");
if (!width)
width = 1;
if (!noassign)
{
tv = va_arg(ap, char*);
strncpy(tv, buf, width);
tv[width] = '\0';
}
buf += width;
}
if (!width)
width = 1;
if (!noassign)
{
tv = va_arg(ap, char*);
strncpy(tv, buf, width);
tv[width] = '\0';
}
buf += width;
}
/* Process %d, %o, %b, %x, %u: Various integer conversions */
/* Process %d, %o, %b, %x, %u: Various integer conversions */
else if (strchr("dobxu", *s))
{
vdbg("vsscanf: Performing integer conversion\n");
else if (strchr("dobxu", *s))
{
vdbg("vsscanf: Performing integer conversion\n");
/* Skip over any white space before the integer string */
/* Skip over any white space before the integer string */
while (isspace(*buf))
buf++;
while (isspace(*buf))
buf++;
/* The base of the integer conversion depends on the specific
* conversion specification.
*/
/* The base of the integer conversion depends on the specific
* conversion specification.
*/
if (*s == 'd' || *s == 'u')
base = 10;
else if (*s == 'x')
base = 16;
else if (*s == 'o')
base = 8;
else if (*s == 'b')
base = 2;
if (*s == 'd' || *s == 'u')
base = 10;
else if (*s == 'x')
base = 16;
else if (*s == 'o')
base = 8;
else if (*s == 'b')
base = 2;
/* Copy the integer string into a temporary working buffer. */
/* Copy the integer string into a temporary working buffer. */
if (!width)
{
if (isspace(*(s + 1)) || *(s + 1) == 0)
{
width = strcspn(buf, spaces);
}
else
{
width = strchr(buf, *(s + 1)) - buf;
}
}
strncpy(tmp, buf, width);
tmp[width] = '\0';
if (!width)
{
if (isspace(*(s + 1)) || *(s + 1) == 0)
{
width = strcspn(buf, spaces);
}
else
{
width = strchr(buf, *(s + 1)) - buf;
}
}
strncpy(tmp, buf, width);
tmp[width] = '\0';
vdbg("vsscanf: tmp[]=\"%s\"\n", tmp);
vdbg("vsscanf: tmp[]=\"%s\"\n", tmp);
/* Perform the integer conversion */
/* Perform the integer conversion */
buf += width;
if (!noassign)
{
int *pint = va_arg(ap, int*);
int tmpint = strtol(tmp, NULL, base);
vdbg("vsscanf: Return %d to 0x%p\n", tmpint, pint);
*pint = tmpint;
}
}
buf += width;
if (!noassign)
{
int *pint = va_arg(ap, int*);
#ifdef SDCC
char *endptr;
int tmpint = strtol(tmp, &endptr, base);
#else
int tmpint = strtol(tmp, NULL, base);
#endif
vdbg("vsscanf: Return %d to 0x%p\n", tmpint, pint);
*pint = tmpint;
}
}
/* Process %f: Floating point conversion */
/* Process %f: Floating point conversion */
else if (*s == 'f')
{
vdbg("vsscanf: Performing floating point conversion\n");
else if (*s == 'f')
{
vdbg("vsscanf: Performing floating point conversion\n");
/* Skip over any white space before the real string */
/* Skip over any white space before the real string */
while (isspace(*buf))
buf++;
while (isspace(*buf))
{
buf++;
}
/* Copy the real string into a temporary working buffer. */
/* Copy the real string into a temporary working buffer. */
if (!width)
{
if (isspace(*(s + 1)) || *(s + 1) == 0)
{
width = strcspn(buf, spaces);
}
else
{
width = strchr(buf, *(s + 1)) - buf;
}
}
strncpy(tmp, buf, width);
tmp[width] = '\0';
buf += width;
if (!width)
{
if (isspace(*(s + 1)) || *(s + 1) == 0)
{
width = strcspn(buf, spaces);
}
else
{
width = strchr(buf, *(s + 1)) - buf;
}
}
strncpy(tmp, buf, width);
tmp[width] = '\0';
buf += width;
vdbg("vsscanf: tmp[]=\"%s\"\n", tmp);
vdbg("vsscanf: tmp[]=\"%s\"\n", tmp);
/* Perform the floating point conversion */
/* Perform the floating point conversion */
if (!noassign)
{
/* strtod always returns a double */
if (!noassign)
{
/* strtod always returns a double */
#ifdef SDCC
char *endptr;
double_t dvalue = strtod(tmp,&endptr);
#else
double_t dvalue = strtod(tmp, NULL);
#endif
void *pv = va_arg(ap, void*);
double_t dvalue = strtod(tmp, NULL);
void *pv = va_arg(ap, void*);
vdbg("vsscanf: Return %f to 0x%p\n", dvalue, pv);
vdbg("vsscanf: Return %f to 0x%p\n", dvalue, pv);
/* But we have to check whether we need to return a
* float or a double.
*/
/* But we have to check whether we need to return a
* float or a double.
*/
#ifdef CONFIG_HAVE_DOUBLE
if (lflag)
{
*((double_t*)pv) = dvalue;
}
else
if (lflag)
{
*((double_t*)pv) = dvalue;
}
else
#endif
{
*((float*)pv) = (float)dvalue;
}
}
}
{
*((float*)pv) = (float)dvalue;
}
}
}
if (!noassign)
count++;
width = noassign = lflag = 0;
s++;
}
if (!noassign)
count++;
width = noassign = lflag = 0;
s++;
}
/* Its is not a conversion specifier */
else
{
while (isspace(*buf))
buf++;
if (*s != *buf)
break;
else
s++, buf++;
}
{
while (isspace(*buf))
buf++;
if (*s != *buf)
break;
else
s++, buf++;
}
}
return count;
}

View File

@ -46,12 +46,12 @@
* Global Functions
************************************************************/
char *strdup(const char *s)
FAR char *strdup(const char *s)
{
char *news = NULL;
FAR char *news = NULL;
if (s)
{
news = malloc(strlen(s) + 1);
news = (FAR char*)malloc(strlen(s) + 1);
if (news)
{
strcpy(news, s);

View File

@ -76,7 +76,7 @@
* Public Functions
************************************************************/
void stream_semtake(struct streamlist *list)
void stream_semtake(FAR struct streamlist *list)
{
/* Take the semaphore (perhaps waiting) */
@ -90,7 +90,7 @@ void stream_semtake(struct streamlist *list)
}
}
void stream_semgive(struct streamlist *list)
void stream_semgive(FAR struct streamlist *list)
{
sem_post(&list->sl_sem);
}

View File

@ -56,7 +56,7 @@
*
************************************************************/
void sq_addafter(sq_entry_t *prev, sq_entry_t *node,
void sq_addafter(FAR sq_entry_t *prev, FAR sq_entry_t *node,
sq_queue_t *queue)
{
if (!queue->head || prev == queue->tail)

View File

@ -56,7 +56,7 @@
*
************************************************************/
void sq_addfirst(sq_entry_t *node, sq_queue_t *queue)
void sq_addfirst(FAR sq_entry_t *node, sq_queue_t *queue)
{
node->flink = queue->head;
if (!queue->head)

View File

@ -55,7 +55,7 @@
* the 'queue'
************************************************************/
void sq_addlast(sq_entry_t *node, sq_queue_t *queue)
void sq_addlast(FAR sq_entry_t *node, sq_queue_t *queue)
{
node->flink = NULL;
if (!queue->head)

View File

@ -55,7 +55,7 @@
*
************************************************************/
void sq_rem(sq_entry_t *node, sq_queue_t *queue)
void sq_rem(FAR sq_entry_t *node, sq_queue_t *queue)
{
if (queue->head && node)
{
@ -69,8 +69,8 @@ void sq_rem(sq_entry_t *node, sq_queue_t *queue)
}
else
{
sq_entry_t *prev;
for(prev = (sq_entry_t*)queue->head;
FAR sq_entry_t *prev;
for(prev = (FAR sq_entry_t*)queue->head;
prev && prev->flink != node;
prev = prev->flink);

View File

@ -56,9 +56,9 @@
*
************************************************************/
sq_entry_t *sq_remafter(sq_entry_t *node, sq_queue_t *queue)
FAR sq_entry_t *sq_remafter(FAR sq_entry_t *node, sq_queue_t *queue)
{
sq_entry_t *ret = node->flink;
FAR sq_entry_t *ret = node->flink;
if (queue->head && ret)
{
if (queue->tail == ret)
@ -76,3 +76,4 @@ sq_entry_t *sq_remafter(sq_entry_t *node, sq_queue_t *queue)
return ret;
}

View File

@ -56,9 +56,9 @@
*
************************************************************/
sq_entry_t *sq_remfirst(sq_queue_t *queue)
FAR sq_entry_t *sq_remfirst(sq_queue_t *queue)
{
sq_entry_t *ret = queue->head;
FAR sq_entry_t *ret = queue->head;
if (ret)
{
@ -73,3 +73,4 @@ sq_entry_t *sq_remfirst(sq_queue_t *queue)
return ret;
}

View File

@ -55,9 +55,9 @@
*
************************************************************/
sq_entry_t *sq_remlast(sq_queue_t *queue)
FAR sq_entry_t *sq_remlast(sq_queue_t *queue)
{
sq_entry_t *ret = queue->tail;
FAR sq_entry_t *ret = queue->tail;
if (ret)
{
@ -68,7 +68,7 @@ sq_entry_t *sq_remlast(sq_queue_t *queue)
}
else
{
sq_entry_t *prev;
FAR sq_entry_t *prev;
for(prev = queue->head;
prev && prev->flink != ret;
prev = prev->flink);

View File

@ -70,7 +70,7 @@ $(BIN): $(OBJS)
depend: .depend
clean:
rm -f $(BIN) *.o *~
rm -f $(BIN) *.o *.asm *.lst *.sym *.adb *~
distclean: clean
rm -f Make.dep .depend

View File

@ -61,10 +61,10 @@
*
************************************************************/
void mm_addfreechunk(struct mm_freenode_s *node)
void mm_addfreechunk(FAR struct mm_freenode_s *node)
{
struct mm_freenode_s *next;
struct mm_freenode_s *prev;
FAR struct mm_freenode_s *next;
FAR struct mm_freenode_s *prev;
/* Convert the size to a nodelist index */

View File

@ -55,9 +55,9 @@
* calloc calculates the size and calls zalloc
************************************************************/
void *calloc(size_t n, size_t elem_size)
FAR void *calloc(size_t n, size_t elem_size)
{
void *ret = NULL;
FAR void *ret = NULL;
if (n > 0 && elem_size > 0)
{

View File

@ -47,6 +47,7 @@
#ifndef MM_TEST
# include <nuttx/config.h>
# include <nuttx/compiler.h>
# include <sys/types.h>
# include <stdlib.h>
# include <string.h>

View File

@ -62,11 +62,11 @@
*
************************************************************/
void free(void *mem)
void free(FAR void *mem)
{
struct mm_freenode_s *node;
struct mm_freenode_s *prev;
struct mm_freenode_s *next;
FAR struct mm_freenode_s *node;
FAR struct mm_freenode_s *prev;
FAR struct mm_freenode_s *next;
/* Protect against attempts to free a NULL reference */
@ -83,22 +83,22 @@ void free(void *mem)
/* Map the memory chunk into a free node */
node = (struct mm_freenode_s *)((char*)mem - SIZEOF_MM_ALLOCNODE);
node = (FAR struct mm_freenode_s *)((char*)mem - SIZEOF_MM_ALLOCNODE);
node->preceding &= ~MM_ALLOC_BIT;
/* Check if the following node is free and, if so, merge it */
next = (struct mm_freenode_s *)((char*)node + node->size);
next = (FAR struct mm_freenode_s *)((char*)node + node->size);
if ((next->preceding & MM_ALLOC_BIT) == 0)
{
struct mm_allocnode_s *andbeyond;
FAR struct mm_allocnode_s *andbeyond;
/* Get the node following the next node (which will
* become the new next node). We know that we can never
* index past the tail chunk because it is always allocated.
*/
andbeyond = (struct mm_allocnode_s*)((char*)next + next->size);
andbeyond = (FAR struct mm_allocnode_s*)((char*)next + next->size);
/* Remove the next node. There must be a predecessor,
* but there may not be a successor node.
@ -115,14 +115,14 @@ void free(void *mem)
node->size += next->size;
andbeyond->preceding = node->size | (andbeyond->preceding & MM_ALLOC_BIT);
next = (struct mm_freenode_s *)andbeyond;
next = (FAR struct mm_freenode_s *)andbeyond;
}
/* Check if the preceding node is also free and, if so, merge
* it with this node
*/
prev = (struct mm_freenode_s *)((char*)node - node->preceding);
prev = (FAR struct mm_freenode_s *)((char*)node - node->preceding);
if ((prev->preceding & MM_ALLOC_BIT) == 0)
{
/* Remove the node. There must be a predecessor, but there may
@ -146,6 +146,5 @@ void free(void *mem)
/* Add the merged node to the nodelist */
mm_addfreechunk(node);
mm_givesemaphore();
}

View File

@ -50,19 +50,19 @@
/* This is the size of the heap provided to mm */
size_t g_heapsize;
size_t g_heapsize;
/* This is the first and last nodes of the heap */
struct mm_allocnode_s *g_heapstart;
struct mm_allocnode_s *g_heapend;
FAR struct mm_allocnode_s *g_heapstart;
FAR struct mm_allocnode_s *g_heapend;
/* All free nodes are maintained in a doubly linked list. This
* array provides some hooks into the list at various points to
* speed searches for free nodes.
*/
struct mm_freenode_s g_nodelist[MM_NNODES];
FAR struct mm_freenode_s g_nodelist[MM_NNODES];
/************************************************************
* Public Functions
@ -85,9 +85,11 @@ struct mm_freenode_s g_nodelist[MM_NNODES];
*
************************************************************/
void mm_initialize(void *heapstart, size_t heapsize)
void mm_initialize(FAR void *heapstart, size_t heapsize)
{
struct mm_freenode_s *node;
FAR struct mm_freenode_s *node;
size_t heapbase;
size_t heapend;
int i;
CHECK_ALLOCNODE_SIZE;
@ -97,8 +99,8 @@ void mm_initialize(void *heapstart, size_t heapsize)
* both aligned with the MM_MIN_CHUNK size.
*/
size_t heapbase = MM_ALIGN_UP((size_t)heapstart);
size_t heapend = MM_ALIGN_DOWN((size_t)heapstart + (size_t)heapsize);
heapbase = MM_ALIGN_UP((size_t)heapstart);
heapend = MM_ALIGN_DOWN((size_t)heapstart + (size_t)heapsize);
/* Save the size of the heap */
@ -121,15 +123,15 @@ void mm_initialize(void *heapstart, size_t heapsize)
* all available memory.
*/
g_heapstart = (struct mm_allocnode_s *)heapbase;
g_heapstart = (FAR struct mm_allocnode_s *)heapbase;
g_heapstart->size = SIZEOF_MM_ALLOCNODE;
g_heapstart->preceding = MM_ALLOC_BIT;
node = (struct mm_freenode_s *)(heapbase + SIZEOF_MM_ALLOCNODE);
node = (FAR struct mm_freenode_s *)(heapbase + SIZEOF_MM_ALLOCNODE);
node->size = g_heapsize - 2*SIZEOF_MM_ALLOCNODE;
node->preceding = SIZEOF_MM_ALLOCNODE;
g_heapend = (struct mm_allocnode_s *)(heapend - SIZEOF_MM_ALLOCNODE);
g_heapend = (FAR struct mm_allocnode_s *)(heapend - SIZEOF_MM_ALLOCNODE);
g_heapend->size = SIZEOF_MM_ALLOCNODE;
g_heapend->preceding = node->size | MM_ALLOC_BIT;

View File

@ -120,14 +120,14 @@ struct mm_allocnode_s
struct mm_freenode_s
{
size_t size; /* Size of this chunk */
size_t preceding; /* Size of the preceding chunk */
struct mm_freenode_s *flink; /* Supports a doubly linked list */
struct mm_freenode_s *blink;
size_t size; /* Size of this chunk */
size_t preceding; /* Size of the preceding chunk */
FAR struct mm_freenode_s *flink; /* Supports a doubly linked list */
FAR struct mm_freenode_s *blink;
};
#ifdef CONFIG_SMALL_MEMORY
# define SIZEOF_MM_FREENODE 10
# define SIZEOF_MM_FREENODE 8
#else
# define SIZEOF_MM_FREENODE 16
#endif
@ -160,15 +160,15 @@ extern size_t g_heapsize;
/* This is the first and last nodes of the heap */
extern struct mm_allocnode_s *g_heapstart;
extern struct mm_allocnode_s *g_heapend;
extern FAR struct mm_allocnode_s *g_heapstart;
extern FAR struct mm_allocnode_s *g_heapend;
/* All free nodes are maintained in a doubly linked list. This
* array provides some hooks into the list at various points to
* speed searches for free nodes.
*/
extern struct mm_freenode_s g_nodelist[MM_NNODES];
extern FAR struct mm_freenode_s g_nodelist[MM_NNODES];
/************************************************************
* Pulblic Function Prototypes
@ -177,23 +177,28 @@ extern struct mm_freenode_s g_nodelist[MM_NNODES];
/* Normally defined in malloc.h */
#ifdef MM_TEST
extern void *mm_malloc(size_t);
extern void mm_free(void*);
extern void *mm_realloc(void*, size_t);
extern void *mm_memalign(size_t, size_t);
extern void *mm_zalloc(size_t);
extern void *mm_calloc(size_t, size_t);
extern FAR void *mm_malloc(size_t);
extern void mm_free(void*);
extern FAR void *mm_realloc(void*, size_t);
extern FAR void *mm_memalign(size_t, size_t);
extern FAR void *mm_zalloc(size_t);
extern FAR void *mm_calloc(size_t, size_t);
#ifdef CONFIG_CAN_PASS_STRUCTS
extern struct mallinfo mallinfo(void);
#else
extern int mallinfo(struct mallinfo *info);
#endif
#endif
extern void mm_shrinkchunk(struct mm_allocnode_s *node, size_t size);
extern void mm_addfreechunk(struct mm_freenode_s *node);
extern int mm_size2ndx(size_t size);
extern void mm_seminitialize(void);
extern void mm_takesemaphore(void);
extern void mm_givesemaphore(void);
extern void mm_shrinkchunk(FAR struct mm_allocnode_s *node,
size_t size);
extern void mm_addfreechunk(FAR struct mm_freenode_s *node);
extern int mm_size2ndx(size_t size);
extern void mm_seminitialize(void);
extern void mm_takesemaphore(void);
extern void mm_givesemaphore(void);
#ifdef MM_TEST
extern int mm_getsemaphore(void);
extern int mm_getsemaphore(void);
#endif
#endif /* __MM_INTERNAL_H */

View File

@ -65,15 +65,26 @@
*
************************************************************/
#ifdef CONFIG_CAN_PASS_STRUCTS
struct mallinfo mallinfo(void)
#else
int mallinfo(struct mallinfo *info)
#endif
{
static struct mallinfo stats;
struct mm_allocnode_s *node;
size_t mxordblk = 0;
int ordblks = 0; /* Number of non-inuse chunks */
size_t uordblks = 0; /* Total allocated space */
size_t fordblks = 0; /* Total non-inuse space */
#ifdef CONFIG_CAN_PASS_STRUCTS
static struct mallinfo info;
#else
if (!info)
{
return ERROR;
}
#endif
/* Visit each node in physical memory */
for (node = g_heapstart;
@ -99,10 +110,19 @@ struct mallinfo mallinfo(void)
uordblks += SIZEOF_MM_ALLOCNODE; /* account for the tail node */
DEBUGASSERT(uordblks + fordblks == g_heapsize);
stats.arena = g_heapsize;
stats.ordblks = ordblks;
stats.mxordblk = mxordblk;
stats.uordblks = uordblks;
stats.fordblks = fordblks;
return stats;
#ifdef CONFIG_CAN_PASS_STRUCTS
info.arena = g_heapsize;
info.ordblks = ordblks;
info.mxordblk = mxordblk;
info.uordblks = uordblks;
info.fordblks = fordblks;
return info;
#else
info->arena = g_heapsize;
info->ordblks = ordblks;
info->mxordblk = mxordblk;
info->uordblks = uordblks;
info->fordblks = fordblks;
return OK;
#endif
}

View File

@ -85,9 +85,9 @@
*
************************************************************/
void *malloc(size_t size)
FAR void *malloc(size_t size)
{
struct mm_freenode_s *node;
FAR struct mm_freenode_s *node;
void *ret = NULL;
int ndx;
@ -142,8 +142,8 @@ void *malloc(size_t size)
if (node)
{
struct mm_freenode_s *remainder;
struct mm_freenode_s *next;
FAR struct mm_freenode_s *remainder;
FAR struct mm_freenode_s *next;
size_t remaining;
/* Remove the node. There must be a predecessor, but there may
@ -169,11 +169,11 @@ void *malloc(size_t size)
{
/* Get a pointer to the next node in physical memory */
next = (struct mm_freenode_s*)(((char*)node) + node->size);
next = (FAR struct mm_freenode_s*)(((char*)node) + node->size);
/* Create the remainder node */
remainder = (struct mm_freenode_s*)(((char*)node) + size);
remainder = (FAR struct mm_freenode_s*)(((char*)node) + size);
remainder->size = remaining;
remainder->preceding = size;

View File

@ -63,9 +63,9 @@
*
************************************************************/
void *memalign(size_t alignment, size_t size)
FAR void *memalign(size_t alignment, size_t size)
{
struct mm_allocnode_s *node;
FAR struct mm_allocnode_s *node;
size_t rawchunk;
size_t alignedchunk;
size_t mask = (size_t)(alignment - 1);
@ -115,7 +115,7 @@ void *memalign(size_t alignment, size_t size)
* node after the allocation.
*/
node = (struct mm_allocnode_s*)(rawchunk - SIZEOF_MM_ALLOCNODE);
node = (FAR struct mm_allocnode_s*)(rawchunk - SIZEOF_MM_ALLOCNODE);
/* Find the aligned subregion */
@ -125,13 +125,13 @@ void *memalign(size_t alignment, size_t size)
if (alignedchunk != rawchunk)
{
struct mm_allocnode_s *newnode;
struct mm_allocnode_s *next;
FAR struct mm_allocnode_s *newnode;
FAR struct mm_allocnode_s *next;
size_t precedingsize;
/* Get the node the next node after the allocation. */
next = (struct mm_allocnode_s*)((char*)node + node->size);
next = (FAR struct mm_allocnode_s*)((char*)node + node->size);
/* Make sure that there is space to convert the preceding mm_allocnode_s
* into an mm_freenode_s. I think that this should always be true
@ -139,7 +139,7 @@ void *memalign(size_t alignment, size_t size)
DEBUGASSERT(alignedchunk >= rawchunk + 8);
newnode = (struct mm_allocnode_s*)(alignedchunk - SIZEOF_MM_ALLOCNODE);
newnode = (FAR struct mm_allocnode_s*)(alignedchunk - SIZEOF_MM_ALLOCNODE);
/* Preceding size is full size of the new 'node,' including
* SIZEOF_MM_ALLOCNODE
@ -158,7 +158,7 @@ void *memalign(size_t alignment, size_t size)
if (precedingsize < SIZEOF_MM_FREENODE)
{
alignedchunk += alignment;
newnode = (struct mm_allocnode_s*)(alignedchunk - SIZEOF_MM_ALLOCNODE);
newnode = (FAR struct mm_allocnode_s*)(alignedchunk - SIZEOF_MM_ALLOCNODE);
precedingsize = (size_t)newnode - (size_t)node;
}
@ -184,7 +184,7 @@ void *memalign(size_t alignment, size_t size)
/* Add the original, newly freed node to the free nodelist */
mm_addfreechunk((struct mm_freenode_s *)node);
mm_addfreechunk((FAR struct mm_freenode_s *)node);
/* Replace the original node with the newlay realloaced,
* aligned node
@ -206,5 +206,5 @@ void *memalign(size_t alignment, size_t size)
}
mm_givesemaphore();
return (void*)alignedchunk;
return (FAR void*)alignedchunk;
}

View File

@ -73,11 +73,11 @@
*
************************************************************/
void *realloc(void *oldmem, size_t size)
FAR void *realloc(FAR void *oldmem, size_t size)
{
struct mm_allocnode_s *oldnode;
struct mm_freenode_s *prev;
struct mm_freenode_s *next;
FAR struct mm_allocnode_s *oldnode;
FAR struct mm_freenode_s *prev;
FAR struct mm_freenode_s *next;
size_t oldsize;
size_t prevsize = 0;
size_t nextsize = 0;
@ -106,7 +106,7 @@ void *realloc(void *oldmem, size_t size)
/* Map the memory chunk into an allocated node structure */
oldnode = (struct mm_allocnode_s *)((char*)oldmem - SIZEOF_MM_ALLOCNODE);
oldnode = (FAR struct mm_allocnode_s *)((FAR char*)oldmem - SIZEOF_MM_ALLOCNODE);
/* We need to hold the MM semaphore while we muck with the
* nodelist.
@ -129,13 +129,13 @@ void *realloc(void *oldmem, size_t size)
* the best decision
*/
next = (struct mm_freenode_s *)((char*)oldnode + oldnode->size);
next = (FAR struct mm_freenode_s *)((FAR char*)oldnode + oldnode->size);
if ((next->preceding & MM_ALLOC_BIT) == 0)
{
nextsize = next->size;
}
prev = (struct mm_freenode_s *)((char*)oldnode - (oldnode->preceding & ~MM_ALLOC_BIT));
prev = (FAR struct mm_freenode_s *)((FAR char*)oldnode - (oldnode->preceding & ~MM_ALLOC_BIT));
if ((prev->preceding & MM_ALLOC_BIT) == 0)
{
prevsize = prev->size;
@ -145,9 +145,9 @@ void *realloc(void *oldmem, size_t size)
if (nextsize + prevsize + oldsize >= size)
{
size_t needed = size - oldsize;
size_t takeprev;
size_t takenext;
size_t needed = size - oldsize;
size_t takeprev = 0;
size_t takenext = 0;
/* Check if we can extend into the previous chunk and if the
* previous chunk is smaller than the next chunk.
@ -207,7 +207,7 @@ void *realloc(void *oldmem, size_t size)
if (takeprev)
{
struct mm_allocnode_s *newnode;
FAR struct mm_allocnode_s *newnode;
/* Remove the previous node. There must be a predecessor,
* but there may not be a successor node.
@ -222,7 +222,7 @@ void *realloc(void *oldmem, size_t size)
/* Extend the node into the previous free chunk */
newnode = (struct mm_allocnode_s *)((char*)oldnode - takeprev);
newnode = (FAR struct mm_allocnode_s *)((FAR char*)oldnode - takeprev);
/* Did we consume the entire preceding chunk? */
@ -261,12 +261,12 @@ void *realloc(void *oldmem, size_t size)
if (takenext)
{
struct mm_freenode_s *newnode;
struct mm_allocnode_s *andbeyond;
FAR struct mm_freenode_s *newnode;
FAR struct mm_allocnode_s *andbeyond;
/* Get the chunk following the next node (which could be the tail chunk) */
andbeyond = (struct mm_allocnode_s*)((char*)next + nextsize);
andbeyond = (FAR struct mm_allocnode_s*)((char*)next + nextsize);
/* Remove the next node. There must be a predecessor,
* but there may not be a successor node.
@ -282,7 +282,7 @@ void *realloc(void *oldmem, size_t size)
/* Extend the node into the previous next chunk */
oldnode->size = oldsize + takenext;
newnode = (struct mm_freenode_s *)((char*)oldnode + oldnode->size);
newnode = (FAR struct mm_freenode_s *)((char*)oldnode + oldnode->size);
/* Did we consume the entire preceding chunk? */
@ -310,19 +310,21 @@ void *realloc(void *oldmem, size_t size)
mm_givesemaphore();
return (void*)((char*)oldnode + SIZEOF_MM_ALLOCNODE);
return (FAR void*)((FAR char*)oldnode + SIZEOF_MM_ALLOCNODE);
}
/* The current chunk cannot be extended. Just allocate a new chunk and copy */
else
{
FAR void *newmem;
/* Allocate a new block. On failure, realloc must return NULL but
* leave the original memory in place.
*/
mm_givesemaphore();
char *newmem = (char*)malloc(size);
newmem = (FAR void*)malloc(size);
if (newmem)
{
memcpy(newmem, oldmem, oldsize);

View File

@ -64,24 +64,24 @@
*
************************************************************/
void mm_shrinkchunk(struct mm_allocnode_s *node, size_t size)
void mm_shrinkchunk(FAR struct mm_allocnode_s *node, size_t size)
{
struct mm_freenode_s *next;
FAR struct mm_freenode_s *next;
/* Get a reference to the next node */
next = (struct mm_freenode_s*)((char*)node + node->size);
next = (FAR struct mm_freenode_s*)((char*)node + node->size);
/* Check if it is free */
if ((next->preceding & MM_ALLOC_BIT) == 0)
{
struct mm_allocnode_s *andbeyond;
struct mm_freenode_s *newnode;
FAR struct mm_allocnode_s *andbeyond;
FAR struct mm_freenode_s *newnode;
/* Get the chunk next the next node (which could be the tail chunk) */
andbeyond = (struct mm_allocnode_s*)((char*)next + next->size);
andbeyond = (FAR struct mm_allocnode_s*)((char*)next + next->size);
/* Remove the next node. There must be a predecessor, but there may
* not be a successor node.
@ -98,7 +98,7 @@ void mm_shrinkchunk(struct mm_allocnode_s *node, size_t size)
* and the tailing memory from the aligned chunk.
*/
newnode = (struct mm_freenode_s*)((char*)node + size);
newnode = (FAR struct mm_freenode_s*)((char*)node + size);
/* Set up the size of the new node */
@ -118,13 +118,13 @@ void mm_shrinkchunk(struct mm_allocnode_s *node, size_t size)
else if (node->size >= size + SIZEOF_MM_FREENODE)
{
struct mm_freenode_s *newnode;
FAR struct mm_freenode_s *newnode;
/* Create a new chunk that will hold both the next chunk
* and the tailing memory from the aligned chunk.
*/
newnode = (struct mm_freenode_s*)((char*)node + size);
newnode = (FAR struct mm_freenode_s*)((char*)node + size);
/* Set up the size of the new node */

View File

@ -56,9 +56,9 @@
*
************************************************************/
void *zalloc(size_t size)
FAR void *zalloc(size_t size)
{
void *alloc = malloc(size);
FAR void *alloc = malloc(size);
if (alloc)
{
memset(alloc, 0, size);

View File

@ -40,7 +40,7 @@ MKDEP = $(TOPDIR)/tools/mkdeps.sh
ASRCS =
AOBJS = $(ASRCS:.S=.o)
MISC_SRCS = os_start.c get_errno_ptr.c get_errorptr.c \
MISC_SRCS = os_start.c get_errno_ptr.c \
sched_setupstreams.c sched_getfiles.c sched_getstreams.c \
sched_setupidlefiles.c sched_setuptaskfiles.c sched_setuppthreadfiles.c \
sched_releasefiles.c
@ -124,7 +124,7 @@ $(BIN): $(OBJS)
depend: .depend
clean:
rm -f $(BIN) *.o *.asm *.lst *.sym *~
rm -f $(BIN) *.o *.asm *.lst *.sym *.adb *~
distclean: clean
rm -f Make.dep .depend

View File

@ -61,9 +61,9 @@
*
************************************************************/
int *get_errno_ptr(void)
FAR int *get_errno_ptr(void)
{
_TCB *ptcb = (_TCB*)g_readytorun.head;
FAR _TCB *ptcb = (FAR _TCB*)g_readytorun.head;
return &ptcb->errno;
}

View File

@ -1,83 +0,0 @@
/************************************************************
* get_errorptr.c
*
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name Gregory Nutt nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
************************************************************/
/************************************************************
* Included Files
************************************************************/
#include <sys/types.h>
#include <errno.h>
/************************************************************
* Global Functions
************************************************************/
/************************************************************
* Function: get_errorptr
*
* Description:
* Return a pointer that is just ERROR cast to void *.
* most fully performing processors don't need anything
* like this. Hoever, this little of nonsense is necessary
* for some processors where sizeof(pointer) < sizeof(uint32)
* and which do not support casts of integers to pointers.
*
* Parameters:
* None
*
* Return Value:
* ERROR cast as a pointer value
*
* Assumptions:
*
************************************************************/
void *get_errnorptr(void)
{
#ifdef CONFIG_CAN_CAST_POINTERS
return (void*)ERROR;
#else
union
{
void *verror;
sint32 ierror;
} u;
u.ierror = ERROR;
return u.verror;
#endif
}

View File

@ -76,6 +76,7 @@
int irq_attach(int irq, xcpt_t isr)
{
#if NR_IRQS > 0
int ret = ERROR;
if ((unsigned)irq < NR_IRQS)
@ -102,6 +103,9 @@ int irq_attach(int irq, xcpt_t isr)
}
return ret;
#else
return OK;
#endif
}

View File

@ -76,12 +76,13 @@
*
***********************************************************/
void irq_dispatch(int irq, void *context)
void irq_dispatch(int irq, FAR void *context)
{
xcpt_t vector;
/* Perform some sanity checks */
#if NR_IRQS > 0
if ((unsigned)irq >= NR_IRQS || g_irqvector[irq] == NULL)
{
vector = irq_unexpected_isr;
@ -90,6 +91,9 @@ void irq_dispatch(int irq, void *context)
{
vector = g_irqvector[irq];
}
#else
vector = irq_unexpected_isr;
#endif
/* Then dispatch to the interrupt handler */

View File

@ -71,7 +71,7 @@ extern "C" {
#endif
EXTERN void weak_function irq_initialize(void);
EXTERN int irq_unexpected_isr(int irq, void *context);
EXTERN int irq_unexpected_isr(int irq, FAR void *context);
#undef EXTERN
#ifdef __cplusplus

View File

@ -75,7 +75,7 @@
*
************************************************************/
int irq_unexpected_isr(int irq, void *context)
int irq_unexpected_isr(int irq, FAR void *context)
{
(void)irqsave();
PANIC(OSERR_UNEXPECTEDISR);

View File

@ -75,7 +75,7 @@
*
************************************************************/
#define mq_desfree(mqdes) sq_addlast((sq_entry_t*)mqdes, &g_desfree)
#define mq_desfree(mqdes) sq_addlast((FAR sq_entry_t*)mqdes, &g_desfree)
/************************************************************
* Public Functions
@ -113,10 +113,10 @@
int mq_close(mqd_t mqdes)
{
_TCB *rtcb = (_TCB*)g_readytorun.head;
msgq_t *msgq;
irqstate_t saved_state;
int ret = ERROR;
FAR _TCB *rtcb = (FAR _TCB*)g_readytorun.head;
FAR msgq_t *msgq;
irqstate_t saved_state;
int ret = ERROR;
/* Verify the inputs */
@ -128,7 +128,7 @@ int mq_close(mqd_t mqdes)
* list of message descriptors.
*/
sq_rem((sq_entry_t*)mqdes, &rtcb->msgdesq);
sq_rem((FAR sq_entry_t*)mqdes, &rtcb->msgdesq);
/* Find the message queue associated with the message descriptor */
@ -165,7 +165,7 @@ int mq_close(mqd_t mqdes)
*/
saved_state = irqsave();
(void)sq_rem((sq_entry_t*)msgq, &g_msgqueues);
(void)sq_rem((FAR sq_entry_t*)msgq, &g_msgqueues);
irqrestore(saved_state);
/* Then deallocate it (and any messages left in it) */
@ -183,3 +183,4 @@ int mq_close(mqd_t mqdes)
return ret;
}

View File

@ -132,7 +132,7 @@ static mqd_t mq_desalloc(void)
*
************************************************************/
mqd_t mq_descreate(_TCB* mtcb, msgq_t* msgq, int oflags)
mqd_t mq_descreate(FAR _TCB* mtcb, FAR msgq_t* msgq, int oflags)
{
mqd_t mqdes;
@ -149,7 +149,7 @@ mqd_t mq_descreate(_TCB* mtcb, msgq_t* msgq, int oflags)
/* And add it to the specified tasks's TCB */
sq_addlast((sq_entry_t*)mqdes, &mtcb->msgdesq);
sq_addlast((FAR sq_entry_t*)mqdes, &mtcb->msgdesq);
}
return mqdes;

View File

@ -81,13 +81,13 @@
*
************************************************************/
msgq_t *mq_findnamed(const char *mq_name)
FAR msgq_t *mq_findnamed(const char *mq_name)
{
msgq_t *msgq;
FAR msgq_t *msgq;
/* Search the list of named message queues */
for (msgq = (msgq_t*)g_msgqueues.head; (msgq); msgq = msgq->flink)
for (msgq = (FAR msgq_t*)g_msgqueues.head; (msgq); msgq = msgq->flink)
{
/* Break out of the lloop with a non-NULL msgq if the
* name matches.

View File

@ -144,7 +144,7 @@ static mqmsg_t *mq_msgblockalloc(sq_queue_t *queue, uint16 nmsgs,
for (i = 0; i < nmsgs; i++)
{
mqmsg->type = alloc_type;
sq_addlast((sq_entry_t*)mqmsg++, queue);
sq_addlast((FAR sq_entry_t*)mqmsg++, queue);
}
}
@ -233,13 +233,13 @@ void mq_desblockalloc(void)
* we ever need to reclaim the memory.
*/
sq_addlast(&mqdesblock->queue, &g_desalloc);
sq_addlast((FAR sq_entry_t*)&mqdesblock->queue, &g_desalloc);
/* Then add each message queue descriptor to the free list */
for (i = 0; i < NUM_MSG_DESCRIPTORS; i++)
{
sq_addlast((sq_entry_t*)&mqdesblock->mqdes[i], &g_desfree);
sq_addlast((FAR sq_entry_t*)&mqdesblock->mqdes[i], &g_desfree);
}
}
}

View File

@ -95,13 +95,12 @@ struct mqmsg
* MQ_type.
*/
struct mqmsg *next; /* Forward link to next message */
ubyte type; /* (Used to manage allocations) */
FAR struct mqmsg *next; /* Forward link to next message */
ubyte type; /* (Used to manage allocations) */
ubyte priority; /* priority of message */
ubyte msglen; /* Message data length */
ubyte pad; /* Not used */
uint16 mail[MQ_MAX_HWORDS]; /* Message data */
ubyte priority; /* priority of message */
ubyte msglen; /* Message data length */
uint16 mail[MQ_MAX_HWORDS]; /* Message data */
};
typedef struct mqmsg mqmsg_t;
@ -111,20 +110,20 @@ struct mq_des; /* forward reference */
struct msgq_s
{
struct msgq_s *flink; /* Forward link to next message queue */
sq_queue_t msglist; /* Prioritized message list */
sint16 maxmsgs; /* Maximum number of messages in the queue */
sint16 nmsgs; /* Number of message in the queue */
sint16 nconnect; /* Number of connections to message queue */
sint16 nwaitnotfull; /* Number tasks waiting for not full */
sint16 nwaitnotempty; /* Number tasks waiting for not empty */
ubyte maxmsgsize; /* Max size of message in message queue */
boolean unlinked; /* TRUE if the msg queue has been unlinked */
struct mq_des *ntmqdes; /* Notification: Owning mqdes (NULL if none) */
pid_t ntpid; /* Notification: Receiving Task's PID */
int ntsigno; /* Notification: Signal number */
union sigval ntvalue; /* Notification: Signal value */
char name[1]; /* Start of the queue name */
FAR struct msgq_s *flink; /* Forward link to next message queue */
sq_queue_t msglist; /* Prioritized message list */
sint16 maxmsgs; /* Maximum number of messages in the queue */
sint16 nmsgs; /* Number of message in the queue */
sint16 nconnect; /* Number of connections to message queue */
sint16 nwaitnotfull; /* Number tasks waiting for not full */
sint16 nwaitnotempty; /* Number tasks waiting for not empty */
ubyte maxmsgsize; /* Max size of message in message queue */
boolean unlinked; /* TRUE if the msg queue has been unlinked */
FAR struct mq_des *ntmqdes; /* Notification: Owning mqdes (NULL if none) */
pid_t ntpid; /* Notification: Receiving Task's PID */
int ntsigno; /* Notification: Signal number */
union sigval ntvalue; /* Notification: Signal value */
char name[1]; /* Start of the queue name */
};
#define SIZEOF_MQ_HEADER ((int)(((msgq_t*)NULL)->name))
@ -135,9 +134,9 @@ struct msgq_s
struct mq_des
{
struct mq_des *flink; /* Forward link to next message descriptor */
msgq_t *msgq; /* Pointer to associated message queue */
int oflags; /* Flags set when message queue was opened */
FAR struct mq_des *flink; /* Forward link to next message descriptor */
FAR msgq_t *msgq; /* Pointer to associated message queue */
int oflags; /* Flags set when message queue was opened */
};
/************************************************************
@ -182,12 +181,12 @@ extern "C" {
/* Functions defined in mq_initialized.c *******************/
EXTERN void weak_function mq_initialize(void);
EXTERN void mq_desblockalloc(void);
EXTERN void mq_desblockalloc(void);
EXTERN mqd_t mq_descreate(_TCB* mtcb, msgq_t* msgq, int oflags);
EXTERN msgq_t *mq_findnamed(const char *mq_name);
EXTERN void mq_msgfree(mqmsg_t *mqmsg);
EXTERN void mq_msgqfree(msgq_t *msgq);
EXTERN mqd_t mq_descreate(FAR _TCB* mtcb, FAR msgq_t* msgq, int oflags);
EXTERN FAR msgq_t *mq_findnamed(const char *mq_name);
EXTERN void mq_msgfree(FAR mqmsg_t *mqmsg);
EXTERN void mq_msgqfree(FAR msgq_t *msgq);
#undef EXTERN
#ifdef __cplusplus

View File

@ -84,7 +84,7 @@
*
************************************************************/
void mq_msgfree(mqmsg_t * mqmsg)
void mq_msgfree(FAR mqmsg_t *mqmsg)
{
irqstate_t saved_state;
@ -99,7 +99,7 @@ void mq_msgfree(mqmsg_t * mqmsg)
*/
saved_state = irqsave();
sq_addlast((sq_entry_t*)mqmsg, &g_msgfree);
sq_addlast((FAR sq_entry_t*)mqmsg, &g_msgfree);
irqrestore(saved_state);
}
@ -114,7 +114,7 @@ void mq_msgfree(mqmsg_t * mqmsg)
*/
saved_state = irqsave();
sq_addlast((sq_entry_t*)mqmsg, &g_msgfreeirq);
sq_addlast((FAR sq_entry_t*)mqmsg, &g_msgfreeirq);
irqrestore(saved_state);
}

View File

@ -84,14 +84,14 @@
*
************************************************************/
void mq_msgqfree(msgq_t *msgq)
void mq_msgqfree(FAR msgq_t *msgq)
{
mqmsg_t *curr;
mqmsg_t *next;
FAR mqmsg_t *curr;
FAR mqmsg_t *next;
/* Deallocate any stranded messages in the message queue. */
curr = (mqmsg_t*)msgq->msglist.head;
curr = (FAR mqmsg_t*)msgq->msglist.head;
while (curr)
{
/* Deallocate the message structure. */

View File

@ -103,8 +103,8 @@
mqd_t mq_open(const char *mq_name, int oflags, ...)
{
_TCB *rtcb = (_TCB*)g_readytorun.head;
msgq_t *msgq;
FAR _TCB *rtcb = (FAR _TCB*)g_readytorun.head;
FAR msgq_t *msgq;
mqd_t mqdes = NULL;
va_list arg; /* Points to each un-named argument */
mode_t mode; /* MQ creation mode parameter (ignored) */
@ -151,7 +151,7 @@ mqd_t mq_open(const char *mq_name, int oflags, ...)
* of the message queue name+1.
*/
msgq = (msgq_t*)kzmalloc(SIZEOF_MQ_HEADER + namelen + 1);
msgq = (FAR msgq_t*)kzmalloc(SIZEOF_MQ_HEADER + namelen + 1);
if (msgq)
{
/* Create a message queue descriptor for the TCB */
@ -196,7 +196,7 @@ mqd_t mq_open(const char *mq_name, int oflags, ...)
* message queues
*/
sq_addlast((sq_entry_t*)msgq, &g_msgqueues);
sq_addlast((FAR sq_entry_t*)msgq, &g_msgqueues);
/* Clean-up variable argument stuff */
@ -218,11 +218,7 @@ mqd_t mq_open(const char *mq_name, int oflags, ...)
if (mqdes == NULL)
{
#ifdef CONFIG_CAN_CAST_POINTERS
return (mqd_t)ERROR;
#else
return get_errorptr();
#endif
}
else
{

View File

@ -114,13 +114,13 @@
int mq_receive(mqd_t mqdes, void *msg, size_t msglen, int *prio)
{
_TCB *rtcb;
_TCB *btcb;
msgq_t *msgq;
mqmsg_t *curr;
irqstate_t saved_state;
ubyte rcvmsglen;
int ret = ERROR;
FAR _TCB *rtcb;
FAR _TCB *btcb;
FAR msgq_t *msgq;
FAR mqmsg_t *curr;
irqstate_t saved_state;
ubyte rcvmsglen;
int ret = ERROR;
/* Verify the input parameters */
@ -142,7 +142,7 @@ int mq_receive(mqd_t mqdes, void *msg, size_t msglen, int *prio)
/* Get the message from the head of the queue */
while ((curr = (mqmsg_t*)sq_remfirst(&msgq->msglist)) == NULL)
while ((curr = (FAR mqmsg_t*)sq_remfirst(&msgq->msglist)) == NULL)
{
/* Should we block until there the above condition has been
* satisfied?
@ -152,7 +152,7 @@ int mq_receive(mqd_t mqdes, void *msg, size_t msglen, int *prio)
{
/* Block and try again */
rtcb = (_TCB*)g_readytorun.head;
rtcb = (FAR _TCB*)g_readytorun.head;
rtcb->msgwaitq = msgq;
msgq->nwaitnotempty++;
up_block_task(rtcb, TSTATE_WAIT_MQNOTEMPTY);
@ -207,7 +207,7 @@ int mq_receive(mqd_t mqdes, void *msg, size_t msglen, int *prio)
*/
saved_state = irqsave();
for (btcb = (_TCB*)g_waitingformqnotfull.head;
for (btcb = (FAR _TCB*)g_waitingformqnotfull.head;
btcb && btcb->msgwaitq != msgq;
btcb = btcb->flink);

View File

@ -37,6 +37,7 @@
* Included Files
************************************************************/
#include <nuttx/compiler.h>
#include <nuttx/kmalloc.h>
#include <sys/types.h> /* uint32, etc. */
#include <mqueue.h>
@ -92,10 +93,10 @@
*
************************************************************/
mqmsg_t *mq_msgalloc(void)
FAR mqmsg_t *mq_msgalloc(void)
{
mqmsg_t *mqmsg;
irqstate_t saved_state;
FAR mqmsg_t *mqmsg;
irqstate_t saved_state;
/* If we were called from an interrupt handler, then try to
* get the message from generally available list of messages.
@ -107,12 +108,12 @@ mqmsg_t *mq_msgalloc(void)
{
/* Try the general free list */
mqmsg = (mqmsg_t*)sq_remfirst(&g_msgfree);
mqmsg = (FAR mqmsg_t*)sq_remfirst(&g_msgfree);
if (!mqmsg)
{
/* Try the free list reserved for interrupt handlers */
mqmsg = (mqmsg_t*)sq_remfirst(&g_msgfreeirq);
mqmsg = (FAR mqmsg_t*)sq_remfirst(&g_msgfreeirq);
}
}
@ -125,14 +126,14 @@ mqmsg_t *mq_msgalloc(void)
*/
saved_state = irqsave();
mqmsg = (mqmsg_t*)sq_remfirst(&g_msgfree);
mqmsg = (FAR mqmsg_t*)sq_remfirst(&g_msgfree);
irqrestore(saved_state);
/* If we cannot a message from the free list, then we will have to allocate one. */
if (!mqmsg)
{
mqmsg = (mqmsg_t *)kmalloc((sizeof (mqmsg_t)));
mqmsg = (FAR mqmsg_t *)kmalloc((sizeof (mqmsg_t)));
/* Check if we got an allocated message */
@ -152,7 +153,6 @@ mqmsg_t *mq_msgalloc(void)
}
return(mqmsg);
}
/************************************************************
@ -202,14 +202,14 @@ mqmsg_t *mq_msgalloc(void)
int mq_send(mqd_t mqdes, const void *msg, size_t msglen, int prio)
{
_TCB *rtcb;
_TCB *btcb;
msgq_t *msgq;
mqmsg_t *curr;
mqmsg_t *next;
mqmsg_t *prev;
irqstate_t saved_state;
int ret = ERROR;
FAR _TCB *rtcb;
FAR _TCB *btcb;
FAR msgq_t *msgq;
FAR mqmsg_t *curr;
FAR mqmsg_t *next;
FAR mqmsg_t *prev;
irqstate_t saved_state;
int ret = ERROR;
/* Verify the input parameters */
@ -267,7 +267,7 @@ int mq_send(mqd_t mqdes, const void *msg, size_t msglen, int prio)
* When we are unblocked, we will try again
*/
rtcb = (_TCB*)g_readytorun.head;
rtcb = (FAR _TCB*)g_readytorun.head;
rtcb->msgwaitq = msgq;
(msgq->nwaitnotfull)++;
up_block_task(rtcb, TSTATE_WAIT_MQNOTFULL);
@ -314,7 +314,7 @@ int mq_send(mqd_t mqdes, const void *msg, size_t msglen, int prio)
* message. Each is list is maintained in ascending priority order.
*/
for (prev = NULL, next = (mqmsg_t*)msgq->msglist.head;
for (prev = NULL, next = (FAR mqmsg_t*)msgq->msglist.head;
next && prio <= next->priority;
prev = next, next = next->next);
@ -322,12 +322,12 @@ int mq_send(mqd_t mqdes, const void *msg, size_t msglen, int prio)
if (prev)
{
sq_addafter((sq_entry_t*)prev, (sq_entry_t*)curr,
sq_addafter((FAR sq_entry_t*)prev, (FAR sq_entry_t*)curr,
&msgq->msglist);
}
else
{
sq_addfirst((sq_entry_t*)curr, &msgq->msglist);
sq_addfirst((FAR sq_entry_t*)curr, &msgq->msglist);
}
/* Increment the count of message in the queue */
@ -378,7 +378,7 @@ int mq_send(mqd_t mqdes, const void *msg, size_t msglen, int prio)
* interrupts should never cause a change in this list
*/
for (btcb = (_TCB*)g_waitingformqnotempty.head;
for (btcb = (FAR _TCB*)g_waitingformqnotempty.head;
btcb && btcb->msgwaitq != msgq;
btcb = btcb->flink);

Some files were not shown because too many files have changed in this diff Show More