/* msdos_file_ftruncate -- * Truncate the file (if new length is greater then current do nothing). * * PARAMETERS: * iop - file control block * length - new length * * RETURNS: * RC_OK on success, or -1 if error occured (errno set appropriately). */ int msdos_file_ftruncate(rtems_libio_t *iop, rtems_off64_t length) { int rc = RC_OK; rtems_status_code sc = RTEMS_SUCCESSFUL; msdos_fs_info_t *fs_info = iop->pathinfo.mt_entry->fs_info; fat_file_fd_t *fat_fd = iop->pathinfo.node_access; if (length >= fat_fd->fat_file_size) return RC_OK; sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT, MSDOS_VOLUME_SEMAPHORE_TIMEOUT); if (sc != RTEMS_SUCCESSFUL) rtems_set_errno_and_return_minus_one(EIO); rc = fat_file_truncate(iop->pathinfo.mt_entry, fat_fd, length); if (rc != RC_OK) { rtems_semaphore_release(fs_info->vol_sema); return rc; } /* * fat_file_truncate do nothing if new length >= fat-file size, so update * file size only if length < fat-file size */ if (length < fat_fd->fat_file_size) iop->size = fat_fd->fat_file_size = length; rtems_semaphore_release(fs_info->vol_sema); return RC_OK; }
/* msdos_file_lseek -- * Process lseek call to the file: extend file if lseek is up to the end * of the file. * * PARAMETERS: * iop - file control block * offset - new offset * whence - predefine directive * * RETURNS: * new offset on success, or -1 if error occured (errno set * appropriately). */ rtems_off64_t msdos_file_lseek(rtems_libio_t *iop, rtems_off64_t offset, int whence) { int rc = RC_OK; rtems_status_code sc = RTEMS_SUCCESSFUL; msdos_fs_info_t *fs_info = iop->pathinfo.mt_entry->fs_info; fat_file_fd_t *fat_fd = iop->pathinfo.node_access; uint32_t real_size = 0; sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT, MSDOS_VOLUME_SEMAPHORE_TIMEOUT); if (sc != RTEMS_SUCCESSFUL) rtems_set_errno_and_return_minus_one(EIO); rc = fat_file_extend(iop->pathinfo.mt_entry, fat_fd, iop->offset, &real_size); if (rc != RC_OK) { rtems_semaphore_release(fs_info->vol_sema); return rc; } if (real_size > fat_fd->fat_file_size) fat_fd->fat_file_size = iop->offset = real_size; iop->size = fat_fd->fat_file_size; rtems_semaphore_release(fs_info->vol_sema); return iop->offset; }
/* * Task that calls the function we want to trace */ static void task(rtems_task_argument arg) { rtems_status_code sc; uint32_t i; for ( i = 0; i < ITERATIONS; i++ ) { /* * Wait until the previous task in the task chain * has completed its operation. */ sc = rtems_semaphore_obtain(task_data[arg].prev_sem, 0, 0); rtems_test_assert(sc == RTEMS_SUCCESSFUL); add_number_wrapper(arg, i); /* * Signal the next task in the chain to continue */ sc = rtems_semaphore_release(task_data[arg].task_sem); rtems_test_assert(sc == RTEMS_SUCCESSFUL); } /* Signal the main task that this task has finished */ sc = rtems_semaphore_release(finished_sem); rtems_test_assert(sc == RTEMS_SUCCESSFUL); rtems_task_suspend(rtems_task_self()); }
static void release_semaphore(rtems_id timer, void *arg) { /* The arg is NULL */ test_context *ctx = &ctx_instance; rtems_status_code sc; if ( _Thread_Wait_flags_get(ctx->main_task_control) == (THREAD_WAIT_CLASS_OBJECT | THREAD_WAIT_STATE_INTEND_TO_BLOCK) ) { CORE_semaphore_Control *sem; ctx->done = true; sc = rtems_semaphore_release(ctx->semaphore_id); rtems_test_assert(sc == RTEMS_SUCCESSFUL); rtems_test_assert( _Thread_Wait_flags_get(ctx->main_task_control) == (THREAD_WAIT_CLASS_OBJECT | THREAD_WAIT_STATE_READY_AGAIN) ); sem = &ctx->semaphore_control->Core_control.Semaphore; rtems_test_assert(sem->count == 0); } else { sc = rtems_semaphore_release(ctx->semaphore_id); rtems_test_assert(sc == RTEMS_SUCCESSFUL); } }
/* msdos_file_open -- * Open fat-file which correspondes to the file * * PARAMETERS: * iop - file control block * pathname - name * flag - flags * mode - mode * * RETURNS: * RC_OK, if file opened successfully, or -1 if error occured * and errno set appropriately */ int msdos_file_open(rtems_libio_t *iop, const char *pathname, uint32_t flag, uint32_t mode) { int rc = RC_OK; rtems_status_code sc = RTEMS_SUCCESSFUL; msdos_fs_info_t *fs_info = iop->pathinfo.mt_entry->fs_info; fat_file_fd_t *fat_fd = iop->pathinfo.node_access; sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT, MSDOS_VOLUME_SEMAPHORE_TIMEOUT); if (sc != RTEMS_SUCCESSFUL) rtems_set_errno_and_return_minus_one(EIO); rc = fat_file_reopen(fat_fd); if (rc != RC_OK) { rtems_semaphore_release(fs_info->vol_sema); return rc; } if (iop->flags & LIBIO_FLAGS_APPEND) iop->offset = fat_fd->fat_file_size; iop->size = fat_fd->fat_file_size; rtems_semaphore_release(fs_info->vol_sema); return RC_OK; }
/* -------------------------------------------------------------------------------------- Name: OS_FileOpenCheck Purpose: Checks to see if a file is open Returns: OS_FS_ERROR if the file is not open OS_FS_SUCCESS if the file is open ---------------------------------------------------------------------------------------*/ int32 OS_FileOpenCheck(char *Filename) { rtems_status_code rtems_sc; uint32 i; if (Filename == NULL) { return(OS_FS_ERR_INVALID_POINTER); } rtems_sc = rtems_semaphore_obtain (OS_FDTableSem, RTEMS_WAIT, RTEMS_NO_TIMEOUT); for ( i = 0; i < OS_MAX_NUM_OPEN_FILES; i++) { if ((OS_FDTable[i].IsValid == TRUE) && (strcmp(OS_FDTable[i].Path, Filename) == 0)) { rtems_sc = rtems_semaphore_release (OS_FDTableSem); return(OS_FS_SUCCESS); } }/* end for */ rtems_sc = rtems_semaphore_release (OS_FDTableSem); return OS_FS_ERROR; }/* end OS_FileOpenCheck */
rtems_status_code rtems_termios_device_open( rtems_device_major_number major, rtems_device_minor_number minor, void *arg ) { rtems_status_code sc; rtems_termios_device_node *device_node; struct rtems_termios_tty *tty; sc = rtems_semaphore_obtain( rtems_termios_ttyMutex, RTEMS_WAIT, RTEMS_NO_TIMEOUT); if (sc != RTEMS_SUCCESSFUL) return sc; device_node = rtems_termios_find_device_node (major, minor); if (device_node == NULL) { rtems_semaphore_release (rtems_termios_ttyMutex); return RTEMS_INVALID_ID; } tty = rtems_termios_open_tty( major, minor, arg, device_node->tty, device_node, NULL); if (tty == NULL) { rtems_semaphore_release (rtems_termios_ttyMutex); return RTEMS_NO_MEMORY; } rtems_semaphore_release (rtems_termios_ttyMutex); return RTEMS_SUCCESSFUL; }
rtems_status_code rtems_termios_write (void *arg) { rtems_libio_rw_args_t *args = arg; struct rtems_termios_tty *tty = args->iop->data1; rtems_status_code sc; sc = rtems_semaphore_obtain (tty->osem, RTEMS_WAIT, RTEMS_NO_TIMEOUT); if (sc != RTEMS_SUCCESSFUL) return sc; if (rtems_termios_linesw[tty->t_line].l_write != NULL) { sc = rtems_termios_linesw[tty->t_line].l_write(tty,args); rtems_semaphore_release (tty->osem); return sc; } if (tty->termios.c_oflag & OPOST) { uint32_t count = args->count; char *buffer = args->buffer; while (count--) oproc (*buffer++, tty); args->bytes_moved = args->count; } else { rtems_termios_puts (args->buffer, args->count, tty); args->bytes_moved = args->count; } rtems_semaphore_release (tty->osem); return sc; }
/* msdos_file_sync -- * Synchronize file - synchronize file data and if file is not removed * synchronize file metadata. * * PARAMETERS: * iop - file control block * * RETURNS: * RC_OK on success, or -1 if error occured (errno set appropriately) */ int msdos_file_sync(rtems_libio_t *iop) { int rc = RC_OK; rtems_status_code sc = RTEMS_SUCCESSFUL; msdos_fs_info_t *fs_info = iop->pathinfo.mt_entry->fs_info; fat_file_fd_t *fat_fd = iop->pathinfo.node_access; sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT, MSDOS_VOLUME_SEMAPHORE_TIMEOUT); if (sc != RTEMS_SUCCESSFUL) rtems_set_errno_and_return_minus_one(EIO); rc = fat_file_update(&fs_info->fat, fat_fd); if (rc != RC_OK) { rtems_semaphore_release(fs_info->vol_sema); return rc; } rc = fat_sync(&fs_info->fat); rtems_semaphore_release(fs_info->vol_sema); if ( rc != 0 ) rtems_set_errno_and_return_minus_one(EIO); return RC_OK; }
/* Task01 starts with priority 36 */ rtems_task Task01(rtems_task_argument ignored) { rtems_status_code status; printf("TA01: started with priority %d\n", getprio()); status = rtems_semaphore_obtain( sem_id[0], RTEMS_WAIT, 0 ); directive_failed( status, "rtems_semaphore_obtain of S0\n"); printf("TA01: priority %d, holding S0\n", getprio()); status = rtems_semaphore_obtain( sem_id[1], RTEMS_WAIT, 0 ); directive_failed( status, "rtems_semaphore_obtain of S1"); printf("TA01: priority %d, holding S0, S1\n", getprio()); /* Start Task 2 (TA02) with priority 34. It will run immediately. */ status = rtems_task_start( Task_id[1], Task02, 0); directive_failed( status, "rtems_task_start of TA02\n"); /* Start Task 3 (TA03) with priority 32. It will run immediately. */ status = rtems_task_start( Task_id[2], Task03, 0); directive_failed( status, "rtems_task_start of TA03\n"); printf("TA01: priority %d, holding S0, S1\n", getprio()); status = rtems_semaphore_release(sem_id[1]); directive_failed( status, "rtems_semaphore_release of S1\n"); printf("TA01: priority %d, holding S0\n", getprio()); status = rtems_semaphore_release(sem_id[0]); directive_failed( status, "rtems_semaphore_release of S0\n"); printf("TA01: priority %d\n", getprio()); printf("TA01: exiting\n"); TEST_END(); rtems_test_exit(0); }
/* Task01 starts with priority 36 */ rtems_task Task01(rtems_task_argument ignored) { rtems_status_code status; printf("TA01: started with priority %d\n", getprio()); status = rtems_semaphore_obtain( sem_id[0], RTEMS_WAIT, 0 ); directive_failed( status, "rtems_semaphore_obtain of S0\n"); printf("TA01: priority %d, holding S0\n", getprio()); status = rtems_semaphore_obtain( sem_id[1], RTEMS_WAIT, 0 ); directive_failed( status, "rtems_semaphore_obtain of S1"); printf("TA01: priority %d, holding S0, S1\n", getprio()); /* Start Task 2 (TA02) with priority 34. It will run immediately. */ status = rtems_task_start( Task_id[1], Task02, 0); directive_failed( status, "rtems_task_start of TA02\n"); status = rtems_semaphore_release(sem_id[1]); directive_failed( status, "rtems_semaphore_release of S1\n"); printf("TA01: priority %d, holding S0\n", getprio()); status = rtems_semaphore_release(sem_id[0]); directive_failed( status, "rtems_semaphore_release of S0\n"); printf("TA01: priority %d\n", getprio()); printf("TA01: exiting\n"); printf("*** END OF SEM01 ***\n"); status = rtems_task_delete( RTEMS_SELF); directive_failed( status, "rtems_task_delete TA01"); }
/* msdos_file_rmnod -- * Remove node associated with a file - set up first name character to * predefined value(and write it to the disk), and mark fat-file which * correspondes to the file as "removed" * * PARAMETERS: * pathloc - node description * * RETURNS: * RC_OK on success, or -1 if error occured (errno set appropriately) */ int msdos_file_rmnod(rtems_filesystem_location_info_t *parent_pathloc, rtems_filesystem_location_info_t *pathloc) { int rc = RC_OK; rtems_status_code sc = RTEMS_SUCCESSFUL; msdos_fs_info_t *fs_info = pathloc->mt_entry->fs_info; fat_file_fd_t *fat_fd = pathloc->node_access; sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT, MSDOS_VOLUME_SEMAPHORE_TIMEOUT); if (sc != RTEMS_SUCCESSFUL) rtems_set_errno_and_return_minus_one(EIO); /* mark file removed */ rc = msdos_set_first_char4file_name(pathloc->mt_entry, &fat_fd->dir_pos, MSDOS_THIS_DIR_ENTRY_EMPTY); if (rc != RC_OK) { rtems_semaphore_release(fs_info->vol_sema); return rc; } fat_file_mark_removed(pathloc->mt_entry, fat_fd); rtems_semaphore_release(fs_info->vol_sema); return RC_OK; }
/* msdos_file_write -- * This routine writes the specified data buffer into the file pointed to * by file control block. * * PARAMETERS: * iop - file control block * buffer - data to write * count - count of bytes to write * * RETURNS: * the number of bytes written on success, or -1 if error occured * and errno set appropriately */ ssize_t msdos_file_write(rtems_libio_t *iop,const void *buffer, size_t count) { ssize_t ret = 0; rtems_status_code sc = RTEMS_SUCCESSFUL; msdos_fs_info_t *fs_info = iop->pathinfo.mt_entry->fs_info; fat_file_fd_t *fat_fd = iop->pathinfo.node_access; sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT, MSDOS_VOLUME_SEMAPHORE_TIMEOUT); if (sc != RTEMS_SUCCESSFUL) rtems_set_errno_and_return_minus_one(EIO); ret = fat_file_write(iop->pathinfo.mt_entry, fat_fd, iop->offset, count, buffer); if (ret < 0) { rtems_semaphore_release(fs_info->vol_sema); return -1; } /* * update file size in both fat-file descriptor and file control block if * file was extended */ if (iop->offset + ret > fat_fd->fat_file_size) fat_fd->fat_file_size = iop->offset + ret; iop->size = fat_fd->fat_file_size; rtems_semaphore_release(fs_info->vol_sema); return ret; }
rtems_task Task0(rtems_task_argument ignored) { rtems_status_code status; status = rtems_semaphore_obtain( Mutex_id[0], RTEMS_WAIT, 0); printf("T0 rtems_semaphore_obtain - S0\n"); directive_failed( status,"rtems_semaphore_obtain of S0\n"); printf("The current priority of T0 is %d\n",Get_current_pri()); status = rtems_semaphore_obtain( Mutex_id[1], RTEMS_WAIT, 0); printf("T0 rtems_semaphore_obtain - S1\n"); directive_failed( status,"rtems_semaphore_obtain of S1"); printf("The current priority of T0 is %d\n",Get_current_pri()); #ifdef __RTEMS_STRICT_ORDER_MUTEX__ status = rtems_semaphore_release( Mutex_id[0] ); printf("T0 - rtems_semaphore_release - S0\n"); if(status == CORE_MUTEX_RELEASE_NOT_ORDER) printf("T0 releasing S0 not in order\n"); #endif status = rtems_semaphore_release(Mutex_id[1]); printf("T0 - rtems_semaphore_release - S1\n"); directive_failed( status,"rtems_semaphore_release of S1\n"); printf("The current priority of T0 is %d\n",Get_current_pri()); Task_name[1] = rtems_build_name( 'T','1',' ',' '); status = rtems_task_create( Task_name[1], 1, RTEMS_MINIMUM_STACK_SIZE *2, RTEMS_DEFAULT_MODES, RTEMS_DEFAULT_ATTRIBUTES, &Task_id[1] ); directive_failed( status , "rtems_task_create of T1\n"); printf("Create S1,priority is 1\n"); status = rtems_task_start( Task_id[1],Task1, 0); directive_failed( status, "rtems_task_start of T1\n"); printf("The current priority of T0 is %d\n",Get_current_pri()); status = rtems_semaphore_release(Mutex_id[0]); printf("T0 - rtems_semaphore_release - S0\n"); directive_failed( status, "rtems_semaphore_release of S0\n"); }
/*PAGE * * task_pool_release * * Return task obtained by 'obtain()' back to the task pool. * * Input parameters: * info - pointer to corresponding SessionInfo structure. * * Output parameters: * NONE * */ static void task_pool_release(FTPD_SessionInfo_t* info) { rtems_semaphore_obtain(task_pool.mutex, RTEMS_WAIT, RTEMS_NO_TIMEOUT); task_pool.queue[task_pool.tail] = info; if(++task_pool.tail >= task_pool.count) task_pool.tail = 0; rtems_semaphore_release(task_pool.mutex); rtems_semaphore_release(task_pool.sem); }
rtems_status_code rtems_termios_device_install( const char *device_file, rtems_device_major_number major, rtems_device_minor_number minor, const rtems_termios_device_handler *handler, void *context ) { rtems_status_code sc; rtems_termios_device_node *new_device_node; rtems_termios_device_node *existing_device_node; new_device_node = malloc(sizeof(*new_device_node)); if (new_device_node == NULL) { return RTEMS_NO_MEMORY; } new_device_node->major = major; new_device_node->minor = minor; new_device_node->handler = handler; new_device_node->context = context; new_device_node->tty = NULL; sc = rtems_semaphore_obtain( rtems_termios_ttyMutex, RTEMS_WAIT, RTEMS_NO_TIMEOUT); if (sc != RTEMS_SUCCESSFUL) { free(new_device_node); return RTEMS_INCORRECT_STATE; } existing_device_node = rtems_termios_find_device_node (major, minor); if (existing_device_node != NULL) { free(new_device_node); rtems_semaphore_release (rtems_termios_ttyMutex); return RTEMS_RESOURCE_IN_USE; } if (device_file != NULL) { sc = rtems_io_register_name (device_file, major, minor); if (sc != RTEMS_SUCCESSFUL) { free(new_device_node); rtems_semaphore_release (rtems_termios_ttyMutex); return RTEMS_UNSATISFIED; } } rtems_chain_append_unprotected( &rtems_termios_devices, &new_device_node->node); rtems_semaphore_release (rtems_termios_ttyMutex); return RTEMS_SUCCESSFUL; }
static rtems_device_driver grtm_open( rtems_device_major_number major, rtems_device_minor_number minor, void *arg) { struct grtm_priv *pDev; struct drvmgr_dev *dev; FUNCDBG(); if ( drvmgr_get_dev(&grtm_rmap_drv_info.general, minor, &dev) ) { DBG("Wrong minor %d\n", minor); return RTEMS_INVALID_NUMBER; } pDev = (struct grtm_priv *)dev->priv; /* Wait until we get semaphore */ if ( rtems_semaphore_obtain(grtm_dev_sem, RTEMS_WAIT, RTEMS_NO_TIMEOUT) != RTEMS_SUCCESSFUL ){ return RTEMS_INTERNAL_ERROR; } /* Is device in use? */ if ( pDev->open ){ rtems_semaphore_release(grtm_dev_sem); return RTEMS_RESOURCE_IN_USE; } /* Mark device taken */ pDev->open = 1; rtems_semaphore_release(grtm_dev_sem); DBG("grtm_open: OPENED minor %d (pDev: 0x%x)\n",pDev->minor,(unsigned int)pDev); /* Set defaults */ pDev->config.timeout = RTEMS_NO_TIMEOUT; /* no timeout (wait forever) */ pDev->config.blocking = 0; /* polling mode */ pDev->running = 0; /* not in running mode yet */ memset(&pDev->config,0,sizeof(pDev->config)); /* The core has been reset when we execute here, so it is possible * to read out what HW is implemented from core. */ grtm_hw_get_implementation(pDev, &pDev->hw_avail); /* Get default modes */ grtm_hw_get_default_modes(&pDev->config,&pDev->hw_avail); return RTEMS_SUCCESSFUL; }
int32 OS_close (int32 filedes) { int status; rtems_status_code rtems_sc; /* Make sure the file descriptor is legit before using it */ if (filedes < 0 || filedes >= OS_MAX_NUM_OPEN_FILES || OS_FDTable[filedes].IsValid == FALSE) { return OS_FS_ERR_INVALID_FD; } else { status = close ((int) OS_FDTable[filedes].OSfd); if (status == ERROR) { /* ** First, try one more time to close the file ** In case it was an interrupted system call */ status = close ((int) OS_FDTable[filedes].OSfd); /* ** Next, remove the file from the OSAL list ** to free up that slot */ /* fill in the table before returning */ rtems_sc = rtems_semaphore_obtain (OS_FDTableSem, RTEMS_WAIT, RTEMS_NO_TIMEOUT); OS_FDTable[filedes].OSfd = -1; strcpy(OS_FDTable[filedes].Path, "\0"); OS_FDTable[filedes].User = 0; OS_FDTable[filedes].IsValid = FALSE; rtems_sc = rtems_semaphore_release (OS_FDTableSem); return OS_FS_ERROR; } else { /* fill in the table before returning */ rtems_sc = rtems_semaphore_obtain (OS_FDTableSem, RTEMS_WAIT, RTEMS_NO_TIMEOUT); OS_FDTable[filedes].OSfd = -1; strcpy(OS_FDTable[filedes].Path, "\0"); OS_FDTable[filedes].User = 0; OS_FDTable[filedes].IsValid = FALSE; rtems_sc = rtems_semaphore_release (OS_FDTableSem); return OS_FS_SUCCESS; } } }/* end OS_close */
void bfin_twi_isr(int source) { void *base; int i; uint16_t r; uint16_t stat; for (i = 0; i < N_BFIN_TWI; i++) { base = twi[i].base; if (base) { stat = BFIN_REG16(base, TWI_INT_STAT_OFFSET); if (stat) { BFIN_REG16(base, TWI_INT_STAT_OFFSET) = stat; if ((stat & TWI_INT_STAT_SINIT) && !twi[i].slaveActive) { twi[i].slaveActive = true; r = BFIN_REG16(base, TWI_FIFO_CTL_OFFSET); BFIN_REG16(base, TWI_FIFO_CTL_OFFSET) = r | TWI_FIFO_CTL_XMTFLUSH; BFIN_REG16(base, TWI_FIFO_CTL_OFFSET) = r; r = BFIN_REG16(base, TWI_SLAVE_CTL_OFFSET); BFIN_REG16(base, TWI_SLAVE_CTL_OFFSET) = r | TWI_SLAVE_CTL_STDVAL; } if (twi[i].slaveActive) { if (stat & (TWI_INT_STAT_SCOMP | TWI_INT_STAT_SERR)) { r = BFIN_REG16(base, TWI_SLAVE_CTL_OFFSET); BFIN_REG16(base, TWI_SLAVE_CTL_OFFSET) = r & ~TWI_SLAVE_CTL_STDVAL; twi[i].slaveActive = false; } } if (twi[i].masterActive && !twi[i].slaveActive) { if (stat & (TWI_INT_STAT_MCOMP | TWI_INT_STAT_MERR)) { if (!(stat & TWI_INT_STAT_MERR)) { rtems_semaphore_release(twi[i].irqSem); } else rtems_semaphore_release(twi[i].irqSem); } } } } } }
/* msdos_file_sync -- * Synchronize file - synchronize file data and if file is not removed * synchronize file metadata. * * PARAMETERS: * iop - file control block * * RETURNS: * RC_OK on success, or -1 if error occured (errno set appropriately) */ int msdos_file_sync(rtems_libio_t *iop) { int rc = RC_OK; rtems_status_code sc = RTEMS_SUCCESSFUL; fat_file_fd_t *fat_fd = iop->pathinfo.node_access; msdos_fs_info_t *fs_info = iop->pathinfo.mt_entry->fs_info; sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT, MSDOS_VOLUME_SEMAPHORE_TIMEOUT); if (sc != RTEMS_SUCCESSFUL) rtems_set_errno_and_return_minus_one(EIO); /* synchronize file data */ rc = fat_file_datasync(iop->pathinfo.mt_entry, fat_fd); if (rc != RC_OK) { rtems_semaphore_release(fs_info->vol_sema); return rc; } /* * if fat-file descriptor is not marked "removed" - synchronize file * metadata */ if (!FAT_FILE_IS_REMOVED(fat_fd)) { rc = msdos_set_first_cluster_num(iop->pathinfo.mt_entry, fat_fd); if (rc != RC_OK) { rtems_semaphore_release(fs_info->vol_sema); return rc; } rc = msdos_set_file_size(iop->pathinfo.mt_entry, fat_fd); if (rc != RC_OK) { rtems_semaphore_release(fs_info->vol_sema); return rc; } rc = msdos_set_dir_wrt_time_and_date(iop->pathinfo.mt_entry, fat_fd); if (rc != RC_OK) { rtems_semaphore_release(fs_info->vol_sema); return rc; } } rtems_semaphore_release(fs_info->vol_sema); return RC_OK; }
/* -------------------------------------------------------------------------------------- Name: OS_CloseFileByName Purpose: Allows a file to be closed by name. This will only work if the name passed in is the same name used to open the file. Returns: OS_FS_ERR_PATH_INVALID if the file is not found OS_FS_ERROR if the file close returned an error OS_FS_SUCCESS if the file close suceeded ---------------------------------------------------------------------------------------*/ int32 OS_CloseFileByName(char *Filename) { rtems_status_code rtems_sc; uint32 i; int status; if (Filename == NULL) { return(OS_FS_ERR_INVALID_POINTER); } rtems_sc = rtems_semaphore_obtain (OS_FDTableSem, RTEMS_WAIT, RTEMS_NO_TIMEOUT); for ( i = 0; i < OS_MAX_NUM_OPEN_FILES; i++) { if ((OS_FDTable[i].IsValid == TRUE) && (strcmp(OS_FDTable[i].Path, Filename) == 0)) { /* ** Close the file */ status = close ((int) OS_FDTable[i].OSfd); /* ** Next, remove the file from the OSAL list ** to free up that slot */ OS_FDTable[i].OSfd = -1; strcpy(OS_FDTable[i].Path, "\0"); OS_FDTable[i].User = 0; OS_FDTable[i].IsValid = FALSE; rtems_sc = rtems_semaphore_release (OS_FDTableSem); if (status == ERROR) { return(OS_FS_ERROR); } else { return(OS_FS_SUCCESS); } } }/* end for */ rtems_sc = rtems_semaphore_release (OS_FDTableSem); return (OS_FS_ERR_PATH_INVALID); }/* end OS_CloseFileByName */
/* * Open a termios device */ rtems_status_code rtems_termios_open ( rtems_device_major_number major, rtems_device_minor_number minor, void *arg, const rtems_termios_callbacks *callbacks ) { rtems_status_code sc; struct rtems_termios_tty *tty; /* * See if the device has already been opened */ sc = rtems_semaphore_obtain( rtems_termios_ttyMutex, RTEMS_WAIT, RTEMS_NO_TIMEOUT); if (sc != RTEMS_SUCCESSFUL) return sc; for (tty = rtems_termios_ttyHead ; tty != NULL ; tty = tty->forw) { if ((tty->major == major) && (tty->minor == minor)) break; } tty = rtems_termios_open_tty( major, minor, arg, tty, NULL, callbacks); if (tty == NULL) { rtems_semaphore_release (rtems_termios_ttyMutex); return RTEMS_NO_MEMORY; } if (tty->refcount == 1) { /* * link tty */ tty->forw = rtems_termios_ttyHead; tty->back = NULL; if (rtems_termios_ttyHead != NULL) rtems_termios_ttyHead->back = tty; rtems_termios_ttyHead = tty; if (rtems_termios_ttyTail == NULL) rtems_termios_ttyTail = tty; } rtems_semaphore_release (rtems_termios_ttyMutex); return RTEMS_SUCCESSFUL; }
rtems_device_driver flash_read( rtems_device_major_number major, rtems_device_minor_number minor, void *arg ) { rtems_libio_rw_args_t *rw_args = (rtems_libio_rw_args_t *)arg; void *startaddr; int len; if (minor >= FLASH_PARTITION_COUNT) return RTEMS_UNSATISFIED; startaddr = (void *)(partitions[minor].start_address + (unsigned int)rw_args->offset); len = partitions[minor].length - rw_args->offset; if (len > rw_args->count) len = rw_args->count; if (len <= 0) { rw_args->bytes_moved = 0; return RTEMS_SUCCESSFUL; } rtems_semaphore_obtain(flash_lock, RTEMS_WAIT, RTEMS_NO_TIMEOUT); memcpy(rw_args->buffer, startaddr, len); rtems_semaphore_release(flash_lock); rw_args->bytes_moved = len; return RTEMS_SUCCESSFUL; }
static void task(rtems_task_argument arg) { rtems_status_code sc; (void) arg; rtems_test_assert(rtems_get_current_processor() == 1); rtems_test_assert(sched_get_priority_min(SCHED_RR) == 1); rtems_test_assert(sched_get_priority_max(SCHED_RR) == INT_MAX - 1); sc = rtems_semaphore_obtain(cmtx_id, RTEMS_WAIT, RTEMS_NO_TIMEOUT); rtems_test_assert(sc == RTEMS_NOT_DEFINED); sc = rtems_event_transient_send(main_task_id); rtems_test_assert(sc == RTEMS_SUCCESSFUL); sc = rtems_semaphore_obtain(imtx_id, RTEMS_WAIT, RTEMS_NO_TIMEOUT); rtems_test_assert(sc == RTEMS_SUCCESSFUL); sc = rtems_semaphore_release(imtx_id); rtems_test_assert(sc == RTEMS_SUCCESSFUL); sc = rtems_event_transient_send(main_task_id); rtems_test_assert(sc == RTEMS_SUCCESSFUL); while (1) { /* Do nothing */ } }
/* * If called with *pipep = NULL, pipe_new will call pipe_alloc to allocate a * pipe control structure and set *pipep to its address. * pipe is locked, when pipe_new returns with no error. */ static int pipe_new( pipe_control_t **pipep ) { pipe_control_t *pipe; int err = 0; if (rtems_semaphore_obtain(rtems_pipe_semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT) != RTEMS_SUCCESSFUL) return -EINTR; pipe = *pipep; if (pipe == NULL) { err = pipe_alloc(&pipe); if (err) goto out; } if (! PIPE_LOCK(pipe)) err = -EINTR; if (*pipep == NULL) { if (err) pipe_free(pipe); else *pipep = pipe; } out: rtems_semaphore_release(rtems_pipe_semaphore); return err; }
/*=========================================================================*\ | Function: | \*-------------------------------------------------------------------------*/ static rtems_isr m360_spi_irq_handler ( /*-------------------------------------------------------------------------*\ | Purpose: | | handle interrupts | +---------------------------------------------------------------------------+ | Input Parameters: | \*-------------------------------------------------------------------------*/ rtems_vector_number v /* vector number */ ) /*-------------------------------------------------------------------------*\ | Return Value: | | <none> | \*=========================================================================*/ { m360_spi_softc_t *softc_ptr = m360_spi_softc_ptr; /* * disable interrupt mask */ m360.spim = 0; if (softc_ptr->initialized) { rtems_semaphore_release(softc_ptr->irq_sema_id); } }
static void release_semaphore(rtems_id timer, void *arg) { /* The arg is NULL */ test_context *ctx = &ctx_instance; rtems_status_code sc = rtems_semaphore_release(ctx->semaphore_id); rtems_test_assert(sc == RTEMS_SUCCESSFUL); }
/*************************************************************************************** ** Name: OS_TimerGetInfo ** ** Purpose: This function will pass back a pointer to structure that contains ** all of the relevant info( name and creator) about the specified timer. ** ** Returns: OS_ERR_INVALID_ID if the id passed in is not a valid timer ** OS_INVALID_POINTER if the timer_prop pointer is null ** OS_SUCCESS if success */ int32 OS_TimerGetInfo (uint32 timer_id, OS_timer_prop_t *timer_prop) { rtems_status_code status; /* ** Check to see that the id given is valid */ if (timer_id >= OS_MAX_TIMERS || OS_timer_table[timer_id].free == TRUE) { return OS_ERR_INVALID_ID; } if (timer_prop == NULL) { return OS_INVALID_POINTER; } /* ** put the info into the stucture */ status = rtems_semaphore_obtain (OS_timer_table_sem, RTEMS_WAIT, RTEMS_NO_TIMEOUT); timer_prop ->creator = OS_timer_table[timer_id].creator; strcpy(timer_prop-> name, OS_timer_table[timer_id].name); timer_prop ->start_time = OS_timer_table[timer_id].start_time; timer_prop ->interval_time = OS_timer_table[timer_id].interval_time; timer_prop ->accuracy = OS_timer_table[timer_id].accuracy; status = rtems_semaphore_release (OS_timer_table_sem); return OS_SUCCESS; } /* end OS_TimerGetInfo */
/* * Interface to file system close. * * *pipep points to pipe control structure. When the last user releases pipe, * it will be set to NULL. */ int pipe_release( pipe_control_t **pipep, rtems_libio_t *iop ) { pipe_control_t *pipe = *pipep; uint32_t mode; rtems_status_code sc; sc = rtems_semaphore_obtain(pipe->Semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT); /* WARN pipe not released! */ if(sc != RTEMS_SUCCESSFUL) rtems_fatal_error_occurred(sc); mode = LIBIO_ACCMODE(iop); if (mode & LIBIO_FLAGS_READ) pipe->Readers --; if (mode & LIBIO_FLAGS_WRITE) pipe->Writers --; sc = rtems_semaphore_obtain(rtems_pipe_semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT); /* WARN pipe not freed and pipep not set to NULL! */ if(sc != RTEMS_SUCCESSFUL) rtems_fatal_error_occurred(sc); PIPE_UNLOCK(pipe); if (pipe->Readers == 0 && pipe->Writers == 0) { #if 0 /* To delete an anonymous pipe file when all users closed it */ if (pipe->Anonymous) delfile = TRUE; #endif pipe_free(pipe); *pipep = NULL; } else if (pipe->Readers == 0 && mode != LIBIO_FLAGS_WRITE) /* Notify waiting Writers that all their partners left */ PIPE_WAKEUPWRITERS(pipe); else if (pipe->Writers == 0 && mode != LIBIO_FLAGS_READ) PIPE_WAKEUPREADERS(pipe); rtems_semaphore_release(rtems_pipe_semaphore); #if 0 if (! delfile) return 0; if (iop->pathinfo.ops->unlink_h == NULL) return 0; /* This is safe for IMFS, but how about other FSes? */ iop->flags &= ~LIBIO_FLAGS_OPEN; if(iop->pathinfo.ops->unlink_h(&iop->pathinfo)) return -errno; #endif return 0; }
/** * Create the lock. */ static bool mmap_mappings_lock_create( void ) { /* * Lock the mapping table. We only create a lock if a call is made. First we * test if a mapping lock is present. If one is present we lock it. If not * the libio lock is locked and we then test the mapping lock again. If not * present we create the mapping lock then release libio lock. */ if ( mmap_mappings_lock == 0 ) { rtems_status_code sc = RTEMS_SUCCESSFUL; rtems_chain_initialize_empty( &mmap_mappings ); rtems_semaphore_obtain( rtems_libio_semaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT ); if ( mmap_mappings_lock == 0 ) sc = rtems_semaphore_create( rtems_build_name( 'M', 'M', 'A', 'P' ), 1, RTEMS_MUTEX_ATTRIBS, RTEMS_NO_PRIORITY, &mmap_mappings_lock ); rtems_semaphore_release( rtems_libio_semaphore ); if ( sc != RTEMS_SUCCESSFUL ) { errno = EINVAL; return false; } } return true; }