/** * Print the status code description and return true if true. * * @param sc The RTEMS status code. * @retval true The status code is successful. * @retval false The status code is not successful. */ static bool bdbuf_test_print_sc (rtems_status_code sc, bool newline) { if (newline) fprintf (stdout, "%s\n", rtems_status_text (sc)); else fprintf (stdout, "%s", rtems_status_text (sc)); return sc == RTEMS_SUCCESSFUL; }
int rtems_rfs_buffer_bdbuf_release (rtems_rfs_buffer* buffer, bool modified) { rtems_status_code sc; int rc = 0; if (rtems_rfs_trace (RTEMS_RFS_TRACE_BUFFER_RELEASE)) printf ("rtems-rfs: bdbuf-release: block=%" PRIuPTR " bdbuf=%" PRIu32 " %s\n", ((intptr_t) buffer->user), buffer->block, modified ? "(modified)" : ""); if (modified) sc = rtems_bdbuf_release_modified (buffer); else sc = rtems_bdbuf_release (buffer); if (sc != RTEMS_SUCCESSFUL) { #if RTEMS_RFS_BUFFER_ERRORS printf ("rtems-rfs: buffer-release: bdbuf-%s: %s(%d)\n", modified ? "modified" : "not-modified", rtems_status_text (sc), sc); #endif rc = EIO; } return rc; }
void test_untar_from_memory(void) { rtems_status_code sc; rtems_printer printer; rtems_print_printer_printf(&printer); printf("Untaring from memory - "); sc = Untar_FromMemory_Print((void *)TARFILE_START, TARFILE_SIZE, &printer); if (sc != RTEMS_SUCCESSFUL) { printf ("error: untar failed: %s\n", rtems_status_text (sc)); exit(1); } printf ("successful\n"); /******************/ printf( "========= /home/test_file =========\n" ); test_cat( "/home/test_file", 0, 0 ); /******************/ printf( "========= /home/test_script =========\n" ); test_cat( "/home/test_script", 0, 0 ); test_untar_check_mode("/home/test_script", 0755); /******************/ printf( "========= /symlink =========\n" ); test_cat( "/symlink", 0, 0 ); }
/* * Create and start a new thread */ epicsThreadId epicsThreadCreate (const char *name, unsigned int priority, unsigned int stackSize, EPICSTHREADFUNC funptr,void *parm) { rtems_id tid; rtems_status_code sc; char c[4]; if (!initialized) epicsThreadInit(); if (stackSize < RTEMS_MINIMUM_STACK_SIZE) { errlogPrintf ("Warning: epicsThreadCreate %s illegal stackSize %d\n",name,stackSize); stackSize = RTEMS_MINIMUM_STACK_SIZE; } strncpy (c, name, sizeof c); sc = rtems_task_create (rtems_build_name (c[0], c[1], c[2], c[3]), epicsThreadGetOssPriorityValue (priority), stackSize, RTEMS_PREEMPT|RTEMS_NO_TIMESLICE|RTEMS_NO_ASR|RTEMS_INTERRUPT_LEVEL(0), RTEMS_FLOATING_POINT|RTEMS_LOCAL, &tid); if (sc != RTEMS_SUCCESSFUL) { errlogPrintf ("epicsThreadCreate create failure for %s: %s\n",name, rtems_status_text (sc)); return 0; } setThreadInfo (tid, name, funptr,parm); return (epicsThreadId)tid; }
static void setThreadInfo (rtems_id tid, const char *name, EPICSTHREADFUNC funptr,void *parm) { struct taskVar *v; uint32_t note; rtems_status_code sc; v = mallocMustSucceed (sizeof *v, "epicsThreadCreate_vars"); v->name = epicsStrDup(name); v->id = tid; v->funptr = funptr; v->parm = parm; v->threadVariableCapacity = 0; v->threadVariables = NULL; note = (uint32_t)v; rtems_task_set_note (tid, RTEMS_NOTEPAD_TASKVAR, note); taskVarLock (); v->forw = taskVarHead; v->back = NULL; if (v->forw) v->forw->back = v; taskVarHead = v; taskVarUnlock (); if (funptr) { sc = rtems_task_start (tid, threadWrapper, (rtems_task_argument)v); if (sc != RTEMS_SUCCESSFUL) errlogPrintf ("setThreadInfo: Can't start %s: %s\n",name, rtems_status_text (sc)); } }
/* * MUTEX support */ void rtems_gxx_mutex_init (__gthread_mutex_t *mutex) { rtems_status_code status; #ifdef DEBUG_GXX_WRAPPERS printk( "gxx_wrappers: mutex init =%X\n", *mutex ); #endif status = rtems_semaphore_create( rtems_build_name ('G', 'C', 'C', '2'), 1, RTEMS_PRIORITY|RTEMS_BINARY_SEMAPHORE| RTEMS_INHERIT_PRIORITY|RTEMS_NO_PRIORITY_CEILING|RTEMS_LOCAL, 0, (rtems_id *)mutex ); if ( status != RTEMS_SUCCESSFUL ) { #ifdef DEBUG_GXX_WRAPPERS printk( "gxx_wrappers: mutex init failed %s (%d)\n", rtems_status_text(status), status ); #endif _Internal_error_Occurred( INTERNAL_ERROR_CORE, true, INTERNAL_ERROR_GXX_MUTEX_INIT_FAILED ); } #ifdef DEBUG_GXX_WRAPPERS printk( "gxx_wrappers: mutex init complete =%X\n", *mutex ); #endif }
int rtems_rfs_buffer_bdbuf_request (rtems_rfs_file_system* fs, rtems_rfs_buffer_block block, bool read, rtems_rfs_buffer** buffer) { rtems_status_code sc; int rc = 0; if (read) sc = rtems_bdbuf_read (rtems_rfs_fs_device (fs), block, buffer); else sc = rtems_bdbuf_get (rtems_rfs_fs_device (fs), block, buffer); if (sc != RTEMS_SUCCESSFUL) { #if RTEMS_RFS_BUFFER_ERRORS printf ("rtems-rfs: buffer-bdbuf-request: block=%lu: bdbuf-%s: %d: %s\n", block, read ? "read" : "get", sc, rtems_status_text (sc)); #endif rc = EIO; } return rc; }
int rtems_rfs_buffer_sync (rtems_rfs_file_system* fs) { int result = 0; #if RTEMS_RFS_USE_LIBBLOCK rtems_status_code sc; #endif if (rtems_rfs_trace (RTEMS_RFS_TRACE_BUFFER_SYNC)) printf ("rtems-rfs: buffer-sync: syncing\n"); /* * @todo Split in the separate files for each type. */ #if RTEMS_RFS_USE_LIBBLOCK sc = rtems_bdbuf_syncdev (rtems_rfs_fs_device (fs)); if (sc != RTEMS_SUCCESSFUL) { if (rtems_rfs_trace (RTEMS_RFS_TRACE_BUFFER_SYNC)) printf ("rtems-rfs: buffer-sync: device sync failed: %s\n", rtems_status_text (sc)); result = EIO; } rtems_disk_release (fs->disk); #else if (fsync (fs->device) < 0) { result = errno; if (rtems_rfs_trace (RTEMS_RFS_TRACE_BUFFER_CLOSE)) printf ("rtems-rfs: buffer-sync: file sync failed: %d: %s\n", result, strerror (result)); } #endif return result; }
/** * Start the RTEMS Shell. */ void shell_start () { rtems_status_code sc; printf ("Starting shell....\n\n"); sc = rtems_shell_init ("fstst", 60 * 1024, 150, "/dev/console", 0, 1, NULL); if (sc != RTEMS_SUCCESSFUL) printf ("error: starting shell: %s (%d)\n", rtems_status_text (sc), sc); }
static void destroyTimer(rtems_id timerID) { rtems_status_code rc; rc = rtems_timer_delete(timerID); if(rc != RTEMS_SUCCESSFUL) { syslog(LOG_INFO, "rtems_timer_delete(): %s\n", rtems_status_text(rc)); } }
/* * Spawn a task */ static void spawnTask(rtems_task_entry entryPoint, rtems_task_priority priority, rtems_task_argument arg) { rtems_status_code sc; rtems_id tid; sc = rtems_task_create(rtems_build_name('t','a','s','k'), priority, RTEMS_MINIMUM_STACK_SIZE+(8*1024), RTEMS_PREEMPT|RTEMS_TIMESLICE|RTEMS_NO_ASR|RTEMS_INTERRUPT_LEVEL(0), RTEMS_FLOATING_POINT|RTEMS_LOCAL, &tid); if (sc != RTEMS_SUCCESSFUL) rtems_panic("Can't create task: %s", rtems_status_text(sc)); sc = rtems_task_start(tid, entryPoint, arg); if (sc != RTEMS_SUCCESSFUL) rtems_panic("Can't start task: %s", rtems_status_text(sc)); }
void epicsThreadSuspendSelf (void) { rtems_status_code sc; sc = rtems_task_suspend (RTEMS_SELF); if(sc != RTEMS_SUCCESSFUL) errlogPrintf("epicsThreadSuspendSelf failed: %s\n", rtems_status_text (sc)); }
void epicsThreadResume(epicsThreadId id) { rtems_id tid = (rtems_id)id; rtems_status_code sc; sc = rtems_task_resume (tid); if(sc != RTEMS_SUCCESSFUL) errlogPrintf("epicsThreadResume failed: %s\n", rtems_status_text (sc)); }
void epicsEventDestroy(epicsEventId id) { rtems_id sid = (rtems_id)id; rtems_status_code sc; sc = rtems_semaphore_delete (sid); if (sc != RTEMS_SUCCESSFUL) errlogPrintf ("Can't destroy semaphore: %s\n", rtems_status_text (sc)); }
/** * Run the /shell-init script. */ void shell_init_script(void) { rtems_status_code sc; printf("Running /shell-init....\n\n"); sc = rtems_shell_script("fstst", 60 * 1024, 160, "/shell-init", "stdout", 0, 1, 1); if (sc != RTEMS_SUCCESSFUL) printf("error: running shell script: %s (%d)\n", rtems_status_text (sc), sc); }
void _BSP_Fatal_error(unsigned int v) { unsigned long flags; const char *err = 0; rtems_interrupt_disable(flags); (void) flags; /* avoid set but not used warning */ printk("%s\n",_RTEMS_version); printk("FATAL ERROR:\n"); printk("Environment:"); switch (THESRC) { case INTERNAL_ERROR_CORE: printk(" RTEMS Core\n"); err = rtems_internal_error_text(THEERR); break; case INTERNAL_ERROR_RTEMS_API: printk(" RTEMS API\n"); err = rtems_status_text(THEERR); break; case INTERNAL_ERROR_POSIX_API: printk(" POSIX API (errno)\n"); /* could use strerror but I'd rather avoid using this here */ break; default: printk(" UNKNOWN (0x%x)\n",THESRC); break; } if ( _Thread_Dispatch_is_enabled() ) printk("enabled\n"); else printk( " Error occurred in a Thread Dispatching DISABLED context (level %i)\n", _Thread_Dispatch_get_disable_level()); if ( _ISR_Nest_level ) { printk( " Error occurred from ISR context (ISR nest level %i)\n", _ISR_Nest_level ); } printk("Error %d",THEERR); if (err) { printk(": %s",err); } printk("\n"); printk("Stack Trace:\n"); CPU_print_stack(); rebootQuestion(); }
static rtems_id createTimer(void) { rtems_status_code rc; rtems_id timerID = 0; rtems_name timerName = rtems_build_name('T','M','R','1'); rc = rtems_timer_create(timerName, &timerID); if(rc != RTEMS_SUCCESSFUL) { syslog(LOG_INFO, "rtems_timer_create(): %s\n", rtems_status_text(rc)); } return timerID; }
static void startTimer(rtems_id timerID, rtems_interval fireWhen, rtems_timer_service_routine_entry userFunc, void* userArg) { rtems_status_code rc; rc = rtems_timer_fire_after(timerID, fireWhen, userFunc, userArg); if(rc != RTEMS_SUCCESSFUL) { syslog(LOG_INFO, "rtems_timer_fire_after(): %s\n", rtems_status_text(rc)); } }
void epicsThreadSetPriority (epicsThreadId id,unsigned int osip) { rtems_id tid = (rtems_id)id; rtems_status_code sc; rtems_task_priority pri = epicsThreadGetOssPriorityValue(osip); sc = rtems_task_set_priority (tid, pri, &pri); if (sc != RTEMS_SUCCESSFUL) errlogPrintf("epicsThreadSetPriority failed: %s\n", rtems_status_text (sc)); }
unsigned int epicsThreadGetPriority(epicsThreadId id) { rtems_id tid = (rtems_id)id; rtems_status_code sc; rtems_task_priority pri; sc = rtems_task_set_priority (tid, RTEMS_CURRENT_PRIORITY, &pri); if (sc != RTEMS_SUCCESSFUL) errlogPrintf("epicsThreadGetPriority failed: %s\n", rtems_status_text (sc)); return epicsThreadGetOsiPriorityValue (pri); }
static bool rtems_stdio_redirect_unlock(rtems_stdio_redirect* sr) { rtems_status_code sc = rtems_semaphore_release (sr->lock); if (sc != RTEMS_SUCCESSFUL) { fprintf(stderr, "error: stdio-redirect: unlock failed: %s\n", rtems_status_text(sc)); return false; } return true; }
static int isSuspended (rtems_id tid) { rtems_status_code sc; sc = rtems_task_is_suspended (tid); if (sc == RTEMS_ALREADY_SUSPENDED) return 1; if (sc != RTEMS_SUCCESSFUL) printf ("rtems_task_is_suspended: %s\n", rtems_status_text (sc)); return 0; }
void Put_Error( uint32_t source, uint32_t error ) { if ( source == INTERNAL_ERROR_CORE ) { printk( rtems_internal_error_text( error ) ); } else if (source == INTERNAL_ERROR_RTEMS_API ){ if (error > RTEMS_NOT_IMPLEMENTED ) printk("Unknown Internal Rtems Error (0x%08x)", error); else printk( "%s", rtems_status_text( error ) ); } }
static int lock(rtems_bsd_rc_conf* rc_conf) { rtems_status_code sc; sc = rtems_semaphore_obtain(rc_conf->lock, RTEMS_WAIT, RTEMS_NO_TIMEOUT); if (sc != RTEMS_SUCCESSFUL) { fprintf(stderr, "error: rc_conf: locking: %s", rtems_status_text(sc)); errno = EIO; return -1; } return 0; }
epicsEventStatus epicsEventTrigger(epicsEventId id) { rtems_id sid = (rtems_id)id; rtems_status_code sc; sc = rtems_semaphore_release (sid); if (sc == RTEMS_SUCCESSFUL) return epicsEventOK; errlogPrintf ("Can't release semaphore: %s\n", rtems_status_text (sc)); return epicsEventError; }
static int unlock(rtems_bsd_rc_conf* rc_conf) { rtems_status_code sc; sc = rtems_semaphore_release(rc_conf->lock); if (sc != RTEMS_SUCCESSFUL) { fprintf(stderr, "error: rc_conf: locking: %s", rtems_status_text(sc)); errno = EIO; return -1; } return 0; }
static bool rtems_stdio_redirect_lock(rtems_stdio_redirect* sr) { rtems_status_code sc = rtems_semaphore_obtain (sr->lock, RTEMS_WAIT, RTEMS_NO_TIMEOUT); if (sc != RTEMS_SUCCESSFUL) { fprintf(stderr, "error: stdio-redirect: lock failed: %s\n", rtems_status_text(sc)); return false; } return true; }
static void capture_CT1c (rtems_task_argument arg) { rtems_id mutex = (rtems_id) arg; rtems_status_code sc; sc = rtems_semaphore_obtain (mutex, RTEMS_WAIT, 0); if (sc != RTEMS_SUCCESSFUL) printf ("error: CT1c: mutex obtain: %s\n", rtems_status_text (sc)); capture_wait (500); sc = rtems_semaphore_release (mutex); if (sc != RTEMS_SUCCESSFUL) printf ("error: CT1c: mutex release: %s\n", rtems_status_text (sc)); capture_CT1c_deleted = 1; rtems_task_delete (RTEMS_SELF); }
void startTask (rtems_id arg) { rtems_id tid; rtems_status_code sc; sc = rtems_task_create (rtems_build_name ('S', 'R', 'V', 'A'), RTEMS_MAXIMUM_PRIORITY - 1u, RTEMS_MINIMUM_STACK_SIZE * 2, RTEMS_PREEMPT|RTEMS_NO_TIMESLICE|RTEMS_NO_ASR|RTEMS_INTERRUPT_LEVEL(0), RTEMS_NO_FLOATING_POINT|RTEMS_LOCAL, &tid ); if (sc != RTEMS_SUCCESSFUL) { printf ("Can't create task: %s\n", rtems_status_text (sc)); rtems_task_suspend (RTEMS_SELF); } sc = rtems_task_start (tid, subtask, arg); if (sc != RTEMS_SUCCESSFUL) { printf ("Can't start task: %s\n", rtems_status_text (sc)); rtems_task_suspend (RTEMS_SELF); } }
int rtems_verror( rtems_error_code_t error_flag, const char *printf_format, va_list arglist ) { int local_errno = 0; int chars_written = 0; rtems_status_code status; if (error_flag & RTEMS_ERROR_PANIC) { if (rtems_panic_in_progress++) _Thread_Disable_dispatch(); /* disable task switches */ /* don't aggravate things */ if (rtems_panic_in_progress > 2) return 0; } (void) fflush(stdout); /* in case stdout/stderr same */ status = error_flag & ~RTEMS_ERROR_MASK; if (error_flag & RTEMS_ERROR_ERRNO) /* include errno? */ local_errno = errno; #if defined(RTEMS_MULTIPROCESSING) if (_System_state_Is_multiprocessing) fprintf(stderr, "[%" PRIu32 "] ", _Configuration_MP_table->node); #endif chars_written += vfprintf(stderr, printf_format, arglist); if (status) chars_written += fprintf(stderr, " (status: %s)", rtems_status_text(status)); if (local_errno) { if ((local_errno > 0) && *strerror(local_errno)) chars_written += fprintf(stderr, " (errno: %s)", strerror(local_errno)); else chars_written += fprintf(stderr, " (unknown errno=%d)", local_errno); } chars_written += fprintf(stderr, "\n"); (void) fflush(stderr); return chars_written; }