Exemple #1
0
/*********************************************************************************************************
** Function name:           mqueue_tryfetch
** Descriptions:            尝试从消息队列里取出消息
** input parameters:        mqueue              消息队列
** output parameters:       msg                 消息
** Returned value:          0 OR -1
*********************************************************************************************************/
int mqueue_tryfetch(mqueue_t *mqueue, void **msg)
{
    struct mqueue *q;
    task_t *task;
    reg_t reg;

    reg = interrupt_disable();
    if (mqueue) {
        q = *mqueue;
        if (q && q->type == IPC_TYPE_MQUEUE && q->valid) {
            if (q->nr) {
                *msg = q->msg[q->out];
                q->out++;
                q->out %= q->size;
                q->nr--;

                task = q->w_wait_list;
                if (task) {
                    resume_task(task, q->w_wait_list, TASK_RESUME_MSG_OUT);
                }
                interrupt_resume(reg);
                return 0;
            }
        }
    }
    interrupt_resume(reg);
    return -1;
}
Exemple #2
0
/*
************************************************************************************************************************
*                                       Release block memory from pool
*
* Description: This function is called to release memory from pool
*
* Arguments  : block_ptr is the address want to return to memory pool.          
*                   ---------------------
*                         
* Returns     RAW_SUCCESS: raw os return success
* Note(s)     This methods will not cause fragmention. 
*
*             
************************************************************************************************************************
*/
U16 block_release(MEM_POOL *pool_ptr, void *block_ptr)
{
    U8    *work_ptr;   
    
    if (! (block_ptr && pool_ptr)) {
        return FALSE;
    }

    U32 cpu_sr = interrupt_disable();
    
    work_ptr = ((U8 *) block_ptr);

    /* Put the block back in the available list.  */
    *((U8 **)work_ptr) = pool_ptr->block_pool_available_list;

    /* Adjust the head pointer.  */
    pool_ptr->block_pool_available_list = work_ptr;        

    /* Increment the count of available blocks.  */
    pool_ptr->block_pool_available++;
    
    interrupt_enable(cpu_sr);

    /* Return completion status.  */
    return TRUE;
    
}
void usb_plug_evt(bool plugged, void *param)
{
	if (plugged) {
		if (usb_initialized == 0) {
			usb_driver_intf->usb_connect();
			usb_driver_intf->usb_driver_init(SOC_USB_BASE_ADDR);
                        f.function_init(f.priv, f.alt_strings);
			interrupt_enable(SOC_USB_INTERRUPT);
			usb_initialized = 1;
		} else {
			pr_error(LOG_MODULE_USB,
				 "Trying to init already initialized driver");
		}
	} else {
		if (usb_initialized == 1) {
			interrupt_disable(SOC_USB_INTERRUPT);
			usb_driver_intf->usb_disconnect();
			usb_initialized = 0;
			int ret = garbage_collect();
			if (ret) {
				pr_error(LOG_MODULE_USB,
					 "Mem leak avoided (idx: %d)", ret);
			}
		} else {
			pr_error(LOG_MODULE_USB,
				 "Trying to free already freed driver");
		}
	}
}
Exemple #4
0
void interrupt_init() {
    int i;
    pic_init(32, 40);
    for (i = 32; i < 48; i++) {
        interrupt_disable(i);
        interrupt_acknowledge(i);
    }
    for (i = 0; i < 32; i++) {
        interrupt_handler_table[i] = unknown_exception;
        interrupt_spurious[i] = 0;
        interrupt_count[i] = 0;
    }
    for (i = 32; i < 48; i++) {
        interrupt_handler_table[i] = unknown_hardware;
        interrupt_spurious[i] = 0;
        interrupt_count[i] = 0;
    }

    // Wire vector index 14 to pagefault handler
    interrupt_handler_table[14] = exception_handle_pagefault;

    interrupt_unblock();

    console_printf("interrupt: ready\n");
}
Exemple #5
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(interrupt_sample_process, ev, data)
{
  /* Any process must start with this. */
  PROCESS_BEGIN();

  interrupt_init(1, 1, 1, 1);
  interrupt_enable(INT0);
  interrupt_enable(INT1);

  /* Register current process with INT0 & INT1*/
  interrupt_register(INT0);
  interrupt_register(INT1);

  while(1) {
    /* Wait for an event. */
    PROCESS_WAIT_EVENT();

    /* Got the interrupt event~ */
    if (ev == PROCESS_EVENT_INTERRUPT) {
      /* Check for the int_vect. */
      if (INT0 == ((struct interrupt *)data)->int_vect) {
        /* Got an INT0 interrupt. */
        leds_toggle(LEDS_RED);
      }
      else if (INT1 == ((struct interrupt *)data)->int_vect) {
        /* Got an INT1 interrupt. */
        leds_toggle(LEDS_YELLOW);
        interrupt_disable(INT0);
      }
    }
  } // while (1)

  /* Any process must end with this, even if it is never reached. */
  PROCESS_END();
}
Exemple #6
0
/*
 * Common interrupt handler.
 */
void
interrupt_handler(void)
{
	uint32_t bits;
	int vector, old_ipl, new_ipl;

	/* Get interrupt source */
	bits = ICU_IRQSTS;
	for (vector = 0; vector < NIRQS; vector++) {
		if (bits & (uint32_t)(1 << vector))
			break;
	}
	if (vector == NIRQS)
		goto out;

	/* Adjust interrupt level */
	old_ipl = irq_level;
	new_ipl = ipl_table[vector];
	if (new_ipl > old_ipl)		/* Ignore spurious interrupt */
		irq_level = new_ipl;
	update_mask();

	/* Dispatch interrupt */
	interrupt_enable();
	irq_handler(vector);
	interrupt_disable();

	/* Restore interrupt level */
	irq_level = old_ipl;
	update_mask();
out:
	return;
}
Exemple #7
0
static int spi_read(struct bathos_pipe *pipe, char *buf, int len)
{
	struct spi_data *data = &spi_data;
	int flags;
	int l;

	interrupt_disable(flags);
	l = min(len, CIRC_CNT_TO_END(data->cbufrx.head, data->cbufrx.tail,
				     SPI_BUF_SIZE));

	if (!l) {
		interrupt_restore(flags);
		return -EAGAIN;
	}

	memcpy(buf, &data->bufrx[data->cbufrx.tail], l);
	data->cbufrx.tail = (data->cbufrx.tail + l) & (SPI_BUF_SIZE - 1);
	data->overrun = 0;

	if (CIRC_CNT(data->cbufrx.head, data->cbufrx.tail, SPI_BUF_SIZE))
		pipe_dev_trigger_event(&__spi_dev, &evt_pipe_input_ready,
				       EVT_PRIO_MAX);

	interrupt_restore(flags);
	return l;
}
Exemple #8
0
/*
 * 关闭 socket
 */
static int socket_close(void *ctx, file_t *file)
{
    privinfo_t *priv = ctx;
    reg_t reg;

    if (priv == NULL) {
        seterrno(EINVAL);
        return -1;
    }

    reg = interrupt_disable();

    atomic_dec(dev_ref(file));

    device_remove(file->ctx);

    file->ctx = NULL;

    lwip_close(priv->sock_fd);

    kfree(priv);

    interrupt_resume(reg);

    return 0;
}
Exemple #9
0
/*********************************************************************************************************
** Function name:           mqueue_flush
** Descriptions:            清空消息队列
** input parameters:        mqueue              消息队列
** output parameters:       NONE
** Returned value:          0 OR -1
*********************************************************************************************************/
int mqueue_flush(mqueue_t *mqueue)
{
    struct mqueue *q;
    task_t *task;
    reg_t reg;
    int i;

    reg = interrupt_disable();
    if (mqueue) {
        q = *mqueue;
        if (q && q->type == IPC_TYPE_MQUEUE && q->valid) {
            q->nr  = 0;
            q->in  = 0;
            q->out = 0;

            for (i = 0; ((task = q->w_wait_list) != NULL) && i < q->size; i++) {
                resume_task(task, q->w_wait_list, TASK_RESUME_MSG_OUT);
            }
            interrupt_resume(reg);
            return 0;
        }
    }
    interrupt_resume(reg);
    return -1;
}
Exemple #10
0
/*********************************************************************************************************
** Function name:           mqueue_trypost
** Descriptions:            尝试投递消息到消息队列
** input parameters:        mqueue              消息队列
**                          msg                 消息
** output parameters:       NONE
** Returned value:          0 OR -1
*********************************************************************************************************/
int mqueue_trypost(mqueue_t *mqueue, void *msg)
{
    struct mqueue *q;
    task_t *task;
    reg_t reg;

    reg = interrupt_disable();
    if (mqueue) {
        q = *mqueue;
        if (q && q->type == IPC_TYPE_MQUEUE && q->valid) {
            if (q->nr < q->size) {
                q->msg[q->in] = msg;
                q->in++;
                q->in %= q->size;
                q->nr++;

                task = q->r_wait_list;
                if (task) {
                    resume_task(task, q->r_wait_list, TASK_RESUME_MSG_COME);
                }
                interrupt_resume(reg);
                return 0;
            }
        }
    }
    interrupt_resume(reg);
    return -1;
}
Exemple #11
0
static void do_print_later(void)
{
	int lines_per_loop = 32;		/* too much at once fails */
	int copy_of_stuff_in;
	int copy_of_overflow;

	interrupt_disable();
	copy_of_stuff_in = stuff_in;
	copy_of_overflow = stuff_overflow;
	stuff_overflow = 0;
	interrupt_enable();

	if (copy_of_overflow)
		ccprintf("*** WARNING: %d MESSAGES WERE LOST ***\n",
			 copy_of_overflow);

	while (lines_per_loop && stuff_out != copy_of_stuff_in) {
		ccprintf("at %.6ld: ", stuff_to_print[stuff_out].t);
		ccprintf(stuff_to_print[stuff_out].fmt,
			 stuff_to_print[stuff_out].a0,
			 stuff_to_print[stuff_out].a1,
			 stuff_to_print[stuff_out].a2,
			 stuff_to_print[stuff_out].a3,
			 stuff_to_print[stuff_out].a4);
		ccprintf("\n");
		stuff_out = (stuff_out + 1) % MAX_ENTRIES;
		lines_per_loop--;
	}
}
Exemple #12
0
/*********************************************************************************************************
** Function name:           mutex_trylock
** Descriptions:            尝试对互斥量进行加锁
** input parameters:        mutex               互斥量
** output parameters:       NONE
** Returned value:          0 OR -1
*********************************************************************************************************/
int mutex_trylock(mutex_t *mutex)
{
    struct mutex *m;
    reg_t reg;

    if (in_interrupt()) {
        return -1;
    }

    reg = interrupt_disable();
    if (mutex) {
        m = *mutex;
        if (m && m->type == IPC_TYPE_MUTEX && m->valid) {
            if (!m->lock) {
                m->lock++;
                m->owner = current;
            } else if (m->owner == current) {
                m->lock++;
            } else {
                goto error;
            }
            interrupt_resume(reg);
            return 0;
        }
    }

    error:
    interrupt_resume(reg);
    return -1;
}
Exemple #13
0
/*********************************************************************************************************
** Function name:           mutex_unlock
** Descriptions:            对互斥量进行解锁
** input parameters:        mutex               互斥量
** output parameters:       NONE
** Returned value:          0 OR -1
*********************************************************************************************************/
int mutex_unlock(mutex_t *mutex)
{
    struct mutex *m;
    task_t *task;
    reg_t reg;

    if (in_interrupt()) {
        return -1;
    }

    reg = interrupt_disable();
    if (mutex) {
        m = *mutex;
        if (m && m->type == IPC_TYPE_MUTEX && m->valid) {
            if (m->lock) {
                if (m->owner == current) {
                    m->lock--;
                    if (!m->lock) {
                        m->owner = NULL;
                        task = m->wait_list;
                        if (task) {
                            printk(KERN_DEBUG"%s: %s unlock mutex, %s get it\n", __func__, current->name, task->name);
                            resume_task(task, m->wait_list, TASK_RESUME_MUTEX_COME);
                        }
                    }
                    interrupt_resume(reg);
                    return 0;
                }
            }
        }
    }
    interrupt_resume(reg);
    return -1;
}
Exemple #14
0
/*********************************************************************************************************
** Function name:           mqueue_abort
** Descriptions:            终止等待消息队列
** input parameters:        mqueue              消息队列
** output parameters:       NONE
** Returned value:          0 OR -1
*********************************************************************************************************/
int mqueue_abort(mqueue_t *mqueue)
{
    struct mqueue *q;
    task_t *task;
    reg_t reg;

    reg = interrupt_disable();
    if (mqueue) {
        q = *mqueue;
        if (q && q->type == IPC_TYPE_MQUEUE && q->valid) {
            while ((task = q->w_wait_list) != NULL) {
                resume_task(task, q->w_wait_list, TASK_RESUME_INTERRUPT);
            }

            while ((task = q->r_wait_list) != NULL) {
                resume_task(task, q->r_wait_list, TASK_RESUME_INTERRUPT);
            }
            interrupt_resume(reg);
            return 0;
        }
    }

    interrupt_resume(reg);
    return -1;
}
Exemple #15
0
void _system_reset(int flags, int wake_from_hibernate)
{
	uint32_t save_flags = 0;

	/* Disable interrupts to avoid task swaps during reboot */
	interrupt_disable();

	/* Save current reset reasons if necessary */
	if (flags & SYSTEM_RESET_PRESERVE_FLAGS)
		save_flags = system_get_reset_flags() | RESET_FLAG_PRESERVED;

	if (flags & SYSTEM_RESET_LEAVE_AP_OFF)
		save_flags |= RESET_FLAG_AP_OFF;

	if (wake_from_hibernate)
		save_flags |= RESET_FLAG_HIBERNATE;
	else if (flags & SYSTEM_RESET_HARD)
		save_flags |= RESET_FLAG_HARD;
	else
		save_flags |= RESET_FLAG_SOFT;

	chip_save_reset_flags(save_flags);

	/* Trigger watchdog in 1ms */
	MEC1322_WDG_LOAD = 1;
	MEC1322_WDG_CTL |= 1;

	/* Spin and wait for reboot; should never return */
	while (1)
		;
}
Exemple #16
0
MYALARM *alarm_declare(int tm,MYALARM *t){
     if(tm<0 || tm>MAXTIME){
	  printf("error time in alarm_declare\n");
	  return NULL;
     }
     MYALARM *temp;

     interrupt_disable();
     for(t=alarms;t<&alarms[MAXALARM];t++){
	  if(t->inuse == FALSE)
	       break;
     }
     
     if(t == &alarms[MAXALARM]){
	  printf("alarms is full now,please try later\n");
	  return NULL;
     }

     t->inuse=TRUE;
     t->time = (time_t)tm;
     time(&t->declare_time);
     
     alarm_update();
     interrupt_enable();
     return t;
}
Exemple #17
0
void thread_exit(int status)
{
	thread_t *cur = thread_current();
	thread_t *next = thread_next();
//	thread_t *parent;

	interrupt_disable();

//	parent = thread_by_pid(cur->ppid);

	HASH_DEL(thread_list, cur);

	//printf("exit (%i)\n",status);

	//Check if we have children
	//if we do
	//	re parent them

	sys_kill(cur->ppid, SIGCHLD);

	//Will need to reap eventually
	cur->status = THREAD_DEAD;
	cur->ret_val = status;
	thread_reschedule(cur->regs, cur, next);
}
Exemple #18
0
/*
 * method: FIFO or LIFO;
 */
void msg_put(QUEUE *entry, MSG *msg, U8 method)
{
    if ((entry == NULL) || (msg == NULL) || (entry->count > entry->length))
        OS_LOG("Message put in queue error\n");

    TCB *tcb_tmp;

    U32 cpu_sr =  interrupt_disable();

    /*Check tasks block on the message queue list*/
    if (!is_list_last(&entry->list)) {
        tcb_tmp = list_entry(entry->list.next, TCB, list);
        msg_block_queue_delete(tcb_tmp);
        prio_ready_queue_insert_head(tcb_tmp);
    }

    if (entry->count == entry->length) {
        /*XXX Todo: if queue is full, block the task*/
        // block_queue(new_task);
        OS_LOG("Message queue overflow\n");
    }else
        entry->count++;

    if (method == FIFO)
        list_insert_behind(&entry->msg_head, &msg->list);
    else
        /*Last come first server.*/
        list_insert_spec(&entry->msg_head, &msg->list);

    interrupt_enable(cpu_sr);
    /*Maybe don't schedule?*/
    schedule();
}
Exemple #19
0
void alarm_update(){
//     printf("!\n");
     MYALARM *t;
     TIME now;
     interrupt_disable();
     for(t=alarms;t<&alarms[MAXALARM];t++){
	  if(t->inuse == TRUE){
//	       printf("find the first next_timer\n");
	       next_timer =t;
	       break;
	  }
     }
     if(t == &alarms[MAXALARM]){
	  alarm(0);
//	  printf("just return?\n");
	  return ;
     }

     for(t=alarms;t<&alarms[MAXALARM];t++){
	  if(t->inuse == TRUE){
//	       printf("%d %d\n",t->time,t->declare_time);
	       fflush(0);
	       if((t->time + t->declare_time) <( next_timer->time + next_timer->declare_time)){
		    next_timer = t;
//		    printf("refresh\n");
	       }
	  }
     }
     time(&now);
     alarm(0);
     alarm(next_timer->time+next_timer->declare_time - now);

     interrupt_enable();
}
Exemple #20
0
/*********************************************************************************************************
** Function name:           socket_attach
** Descriptions:            联结 socket
** input parameters:        sock_fd             socket 的私有文件描述符
** output parameters:       NONE
** Returned value:          IO 系统文件描述符
*********************************************************************************************************/
int socket_attach(int sock_fd)
{
    char path[PATH_MAX];
    int fd;
    privinfo_t *priv;
    reg_t reg;
    file_t *file;
    int err;

    priv = kmalloc(sizeof(privinfo_t), GFP_KERNEL);
    if (priv != NULL) {
        priv->sock_fd = sock_fd;

        device_init(priv);

        sprintf(path, "/dev/socket%d", sock_fd);

        reg = interrupt_disable();

        if (device_create(path, "socket", priv) < 0) {
            interrupt_resume(reg);
            kfree(priv);
            return -1;
        }

        fd = vfs_open(path, O_RDWR, 0666);
        if (fd < 0) {
            geterrno(err);
            vfs_unlink(path);
            seterrno(err);
            interrupt_resume(reg);
            kfree(priv);
            return -1;
        }

        file = vfs_get_file(fd);
        if (file == NULL) {
            geterrno(err);
            vfs_close(fd);
            vfs_unlink(path);
            seterrno(err);
            interrupt_resume(reg);
            kfree(priv);
            return -1;
        }

        file->type = VFS_FILE_TYPE_SOCK;
        vfs_put_file(file);

        lwip_socket_set_ctx(sock_fd, priv);

        interrupt_resume(reg);
        seterrno(0);
        return fd;
    } else {
        seterrno(ENOMEM);
        return -1;
    }
}
Exemple #21
0
void timer_delete(struct timer *timer)
{
	unsigned long flags = interrupt_disable();

	if (timer->i != TIMER_INVALID_INDEX)
		__timer_delete(timer);
	interrupt_enable(flags);
}
Exemple #22
0
static error_t ctrlc_close (device_handle_t _handle)
{
    ctrlc_handle_t handle = (ctrlc_handle_t)_handle;
    
    interrupt_disable (_handle->interrupt_vector_);
    handle->is_opened_ = false;
    return 0;
}
Exemple #23
0
enum cts_rc test_interrupt_disable(void)
{
	interrupt_disable();
	if (!busy_loop()) {
		CPRINTS("Expected timeout but didn't");
		return CTS_RC_FAILURE;
	}
	return CTS_RC_SUCCESS;
}
Exemple #24
0
void lpc_keyboard_clear_buffer(void)
{
	uint32_t int_mask = get_int_mask();
	interrupt_disable();
	/* bit6, write-1 clear OBF */
	IT83XX_KBC_KBHICR |= (1 << 6);
	IT83XX_KBC_KBHICR &= ~(1 << 6);
	set_int_mask(int_mask);
}
Exemple #25
0
/*********************************************************************************************************
** Function name:           mqueue_fetch
** Descriptions:            从消息队列里取出消息
** input parameters:        mqueue              消息队列
**                          timeout             超时 TICK 数
** output parameters:       msg                 消息
** Returned value:          0 OR -1
*********************************************************************************************************/
int mqueue_fetch(mqueue_t *mqueue, void **msg, tick_t timeout)
{
    struct mqueue *q;
    task_t *task;
    reg_t reg;
    uint8_t resume_type;
    tick_t tick;

    if (in_interrupt()) {
        return mqueue_tryfetch(mqueue, msg);
    }

    reg = interrupt_disable();
    if (mqueue) {
        again:
        q = *mqueue;
        if (q && q->type == IPC_TYPE_MQUEUE && q->valid) {
            if (q->nr) {
                *msg = q->msg[q->out];
                q->out++;
                q->out %= q->size;
                q->nr--;

                task = q->w_wait_list;
                if (task) {
                    resume_task(task, q->w_wait_list, TASK_RESUME_MSG_OUT);
                }
                interrupt_resume(reg);
                return 0;
            } else {
                if (timeout != 0) {
                    wait_event_timeout(q->r_wait_list, resume_type, timeout, tick);
                } else {
                    wait_event_forever(q->r_wait_list, resume_type);
                }
                if (resume_type == TASK_RESUME_INTERRUPT ||
                    resume_type == TASK_RESUME_TIMEOUT ||
                    resume_type == TASK_RESUME_UNKNOW) {
                    goto error;
                } else {
                    if (timeout != 0) {
                        if (timeout <= tick) {
                            goto error;
                        }
                        timeout -= tick;
                    }
                    goto again;
                }
            }
        }
    }

    error:
    interrupt_resume(reg);
    return -1;
}
Exemple #26
0
/*********************************************************************************************************
** Function name:           atomic_dec
** Descriptions:            原子量自减
** input parameters:        v                   原子量
** output parameters:       NONE
** Returned value:          NONE
*********************************************************************************************************/
void atomic_dec(atomic_t *v)
{
    reg_t reg;

    reg = interrupt_disable();

    v->counter--;

    interrupt_resume(reg);
}
Exemple #27
0
/*********************************************************************************************************
** Function name:           atomic_add
** Descriptions:            原子量加上指定的值
** input parameters:        v                   原子量
**                          i                   增量
** output parameters:       NONE
** Returned value:          NONE
*********************************************************************************************************/
void atomic_add(atomic_t *v, int i)
{
    reg_t reg;

    reg = interrupt_disable();

    v->counter += i;

    interrupt_resume(reg);
}
Exemple #28
0
/**
 * Jump to what we hope is the init address of an image.
 *
 * This function does not return.
 *
 * @param init_addr	Init address of target image
 */
static void jump_to_image(uintptr_t init_addr)
{
	void (*resetvec)(void) = (void(*)(void))init_addr;

	/*
	 * Jumping to any image asserts the signal to the Silego chip that that
	 * EC is not in read-only firmware.  (This is not technically true if
	 * jumping from RO -> RO, but that's not a meaningful use case...).
	 *
	 * Pulse the signal long enough to set the latch in the Silego, then
	 * drop it again so we don't leak power through the pulldown in the
	 * Silego.
	 */
	gpio_set_level(GPIO_ENTERING_RW, 1);
	usleep(MSEC);
	gpio_set_level(GPIO_ENTERING_RW, 0);

#ifdef CONFIG_USB_POWER_DELIVERY
	/*
	 * Notify USB PD module that we are about to sysjump and give it time
	 * to do what it needs.
	 */
	pd_prepare_sysjump();
	usleep(5*MSEC);
#endif

	/* Flush UART output unless the UART hasn't been initialized yet */
	if (uart_init_done())
		uart_flush_output();

	/* Disable interrupts before jump */
	interrupt_disable();

#ifdef CONFIG_DMA
	/* Disable all DMA channels to avoid memory corruption */
	dma_disable_all();
#endif /* CONFIG_DMA */

	/* Fill in preserved data between jumps */
	jdata->reserved0 = 0;
	jdata->magic = JUMP_DATA_MAGIC;
	jdata->version = JUMP_DATA_VERSION;
	jdata->reset_flags = reset_flags;
	jdata->jump_tag_total = 0;  /* Reset tags */
	jdata->struct_size = sizeof(struct jump_data);

	/* Call other hooks; these may add tags */
	hook_notify(HOOK_SYSJUMP);

	/* Jump to the reset vector */
	resetvec();
}
Exemple #29
0
/*********************************************************************************************************
** Function name:           atomic_sub_return
** Descriptions:            原子量减去指定的值并返回新的值
** input parameters:        v                   原子量
**                          i                   减量
** output parameters:       NONE
** Returned value:          原子量新的值
*********************************************************************************************************/
int atomic_sub_return(atomic_t *v, int i)
{
    reg_t reg;
    int   ret;

    reg = interrupt_disable();

    ret = v->counter -= i;

    interrupt_resume(reg);

    return ret;
}
Exemple #30
0
/*********************************************************************************************************
** Function name:           atomic_read
** Descriptions:            获得原子量的值
** input parameters:        v                   原子量
** output parameters:       NONE
** Returned value:          原子量的值
*********************************************************************************************************/
int atomic_read(atomic_t *v)
{
    reg_t reg;
    int   ret;

    reg = interrupt_disable();

    ret = v->counter;

    interrupt_resume(reg);

    return ret;
}