Beispiel #1
0
EXTERN t_pdinstance *pdinstance_new(void)
{
    t_pdinstance *x = (t_pdinstance *)getbytes(sizeof(t_pdinstance));
    t_class *c;
    int i;
    pd_this = x;
    s_inter_newpdinstance();
    pdinstance_init(x);
    sys_lock();
    pd_globallock();
    pd_instances = (t_pdinstance **)resizebytes(pd_instances,
        pd_ninstances * sizeof(*pd_instances),
        (pd_ninstances+1) * sizeof(*pd_instances));
    pd_instances[pd_ninstances] = x;
    for (c = class_list; c; c = c->c_next)
    {
        c->c_methods = (t_methodentry **)t_resizebytes(c->c_methods,
            pd_ninstances * sizeof(*c->c_methods),
            (pd_ninstances + 1) * sizeof(*c->c_methods));
        c->c_methods[pd_ninstances] = t_getbytes(0);
        for (i = 0; i < c->c_nmethod; i++)
            class_addmethodtolist(c, &c->c_methods[pd_ninstances], i,
                c->c_methods[0][i].me_fun,
                dogensym(c->c_methods[0][i].me_name->s_name, 0, x),
                    c->c_methods[0][i].me_arg, x);
    }
    pd_ninstances++;
    pdinstance_renumber();
    pd_bind(&glob_pdobject, gensym("pd"));
    text_template_init();
    garray_init();
    pd_globalunlock();
    sys_unlock();
    return (x);
}
Beispiel #2
0
/**
 * The connection thread serves a client for the duration of the
 * socket lifetime.
 */
static void *connection_main(void *arg_p)
{
    struct http_server_connection_t *connection_p = arg_p;
    struct http_server_t *self_p = connection_p->self_p;
    uint32_t mask;

    /* thrd_init_env(buf, sizeof(buf)); */
    /* thrd_set_env("CWD", self_p->root_path_p); */
    thrd_set_name(connection_p->thrd.name_p);

    /* Wait for a connection from the listener. */
    while (1) {
        log_object_print(NULL,
                         LOG_DEBUG,
                         FSTR("Connection thread '%s' waiting for a new connection.\r\n"),
                         thrd_get_name());

        mask = 0x1;
        event_read(&connection_p->events, &mask, sizeof(mask));

        if (mask & 0x1) {
            handle_request(self_p, connection_p);
            socket_close(&connection_p->socket);

            /* Add thread to the free list. */
            sys_lock();
            connection_p->state = http_server_connection_state_free_t;
            sys_unlock();
            mask = 0x1;
            event_write(&self_p->events, &mask, sizeof(mask));
        }
    }

    return (NULL);
}
Beispiel #3
0
int libpd_exists(const char *sym) {
  int retval;
  sys_lock();
  retval = (get_object(sym) != NULL);
  sys_unlock();
  return retval;
}
Beispiel #4
0
int heap_free(struct heap_t *self_p,
              void *buf_p)
{
    ASSERTN(self_p != NULL, EINVAL);
    ASSERTN(buf_p != NULL, EINVAL);

    int count;
    struct heap_buffer_header_t *header_p;

    header_p = &((struct heap_buffer_header_t *)buf_p)[-1];

    sys_lock();

    if (header_p->count > 0) {
        header_p->count--;
        count = header_p->count;
        
        /* Free when count is zero. */
        if (count == 0) {
            if (header_p->u.fixed_p != NULL) {
                count = free_fixed_size(self_p, header_p);
            } else {
                count = free_dynamic_buffer(self_p, header_p);
            }
        }
    } else {
        count = -1;
    }

    sys_unlock();

    return (count);
}
Beispiel #5
0
static struct http_server_connection_t *
allocate_connection(struct http_server_t *self_p)
{
    uint32_t mask;
    struct http_server_connection_t *connection_p;

    while (1) {
        sys_lock();

        connection_p = self_p->connections_p;

        while (connection_p->thrd.stack.buf_p != NULL) {
            if (connection_p->state == http_server_connection_state_free_t) {
                connection_p->state = http_server_connection_state_allocated_t;
                break;
            }

            connection_p++;
        }

        sys_unlock();

        /* Connection available. */
        if (connection_p->thrd.name_p != NULL) {
            break;
        }

        mask = 0x1;
        event_read(&self_p->events, &mask, sizeof(mask));
    }

    return (connection_p);
}
Beispiel #6
0
void libpd_add_symbol(const char *s) {
  t_symbol *x;
  sys_lock();
  x = gensym(s);
  sys_unlock();
  ADD_ARG(SETSYMBOL);
}
Beispiel #7
0
void *libpd_bind(const char *sym) {
  t_symbol *x;
  sys_lock();
  x = gensym(sym);
  sys_unlock();
  return libpdreceive_new(x);
}
Beispiel #8
0
void socket_stub_input(int socket, void *buf_p, size_t size)
{
    struct socket_t *socket_p;

    while (1) {
        socket_p = sockets[socket];

        if (socket_p != NULL) {
            break;
        }

        thrd_sleep_ms(1);
    }

    /* Resume any polling thread. */
    sys_lock();

    if (chan_is_polled_isr(&socket_p->base)) {
        thrd_resume_isr(socket_p->base.reader_p, 0);
        socket_p->base.reader_p = NULL;
    }

    chan_write_isr(&qinput, &buf_p, sizeof(buf_p));
    chan_write_isr(&qinput, &size, sizeof(size));

    sys_unlock();
}
Beispiel #9
0
//一下需要系统调用
void plc_timing_tick_process(void)
{
	unsigned long idata curr = get_sys_clock();
	if((curr - last_tick) >= TICK_SECOND / 10) {
	    sys_lock();
		time100ms_come_flag++;
		sys_unlock();
		last_tick = curr;
	}
	if((curr - last_tick1s) >= TICK_SECOND) {
	    sys_lock();
		time1s_come_flag++;
		sys_unlock();
		last_tick1s = curr;
	}
}
Beispiel #10
0
ssize_t event_read(struct event_t *self_p,
                   void *buf_p,
                   size_t size)
{
    ASSERTN(self_p != NULL, EINVAL);
    ASSERTN(buf_p != NULL, EINVAL);
    ASSERTN(size == sizeof(uint32_t), EINVAL);

    uint32_t *mask_p, mask;

    mask_p = (uint32_t *)buf_p;

    sys_lock();

    mask = (self_p->mask & *mask_p);

    /* Event already set? Otherwise wait for it. */
    if (mask != 0) {
        *mask_p = mask;
    } else {
        self_p->base.reader_p = thrd_self();
        thrd_suspend_isr(NULL);
        *mask_p = (self_p->mask & *mask_p);
    }

    /* Remove read events from the event channel. */
    self_p->mask &= (~(*mask_p));

    sys_unlock();

    return (size);
}
Beispiel #11
0
static void cwiid_callback(cwiid_wiimote_t *wiimote, int mesg_count,
                    union cwiid_mesg mesg_array[], struct timespec *timestamp)
{
   int i;
  t_wiimote *x=NULL;
  double pd_timestamp=0;

  //  print_timestamp(timestamp, NULL);


  if(g_wiimoteList==NULL||wiimote==NULL) {
    post("no wii's known");
    return;
  }
  x=getWiimoteObject(cwiid_get_id(wiimote));
  if(NULL==x) {
      post("no wiimote loaded: %d%",cwiid_get_id(wiimote));
    return;
   }

  pd_timestamp=wiimote_timestamp2logicaltime(x, timestamp);

  sys_lock();
  for (i=0; i < mesg_count; i++) {
#if 1
    wiimote_queue(x, mesg_array+i, pd_timestamp);
#else
    wiimote_cwiid_message(x, mesg_array+i);
#endif
   }
  sys_unlock();
}
Beispiel #12
0
static ssize_t uart_soft_write_cb(void *arg_p,
                                  const void *txbuf_p,
                                  size_t size)
{
    int i, j;
    uint8_t data;
    struct uart_soft_driver_t *self_p;
    const uint8_t *tx_p = txbuf_p;

    self_p = container_of(arg_p, struct uart_soft_driver_t, chout);

    for (i = 0; i < size; i++) {
        sys_lock();
        pin_write(&self_p->tx_pin, 0);

        /* Put 8 bits on the transmission wire. */
        data = tx_p[i];

        for (j = 0; j < 8; j++) {
            time_busy_wait_us(self_p->sample_time);
            pin_write(&self_p->tx_pin, data & 1);
            data >>= 1;
        }

        time_busy_wait_us(self_p->sample_time);
        pin_write(&self_p->tx_pin, 1);
        time_busy_wait_us(self_p->sample_time);
        sys_unlock();
    }

    return (size);
}
Beispiel #13
0
int libpd_arraysize(const char *name) {
  int retval;
  sys_lock();
  GETARRAY
  retval = garray_npoints(garray);
  sys_unlock();
  return retval;
}
Beispiel #14
0
int libpd_getdollarzero(void *x) {
  sys_lock();
  pd_pushsym((t_pd *)x);
  int dzero = canvas_getdollarzero();
  pd_popsym((t_pd *)x);
  sys_unlock();
  return dzero;
}
Beispiel #15
0
int libpd_programchange(int channel, int value) {
  CHECK_CHANNEL
  CHECK_RANGE_7BIT(value)
  sys_lock();
  inmidi_programchange(PORT, CHANNEL, value);
  sys_unlock();
  return 0;
}
Beispiel #16
0
unsigned char plc_write_delay(void)
{
   unsigned char ret  = 0;
   sys_lock();
   ret = plc_write_busy;
   sys_unlock();
   return ret;
}
Beispiel #17
0
void *libpd_openfile(const char *basename, const char *dirname) {
  void * retval;
  sys_lock();
  pd_globallock();
  retval = (void *)glob_evalfile(NULL, gensym(basename), gensym(dirname));
  pd_globalunlock();
  sys_unlock();
  return retval;
}
Beispiel #18
0
int libpd_noteon(int channel, int pitch, int velocity) {
  CHECK_CHANNEL
  CHECK_RANGE_7BIT(pitch)
  CHECK_RANGE_7BIT(velocity)
  sys_lock();
  inmidi_noteon(PORT, CHANNEL, pitch, velocity);
  sys_unlock();
  return 0;
}
Beispiel #19
0
int libpd_controlchange(int channel, int controller, int value) {
  CHECK_CHANNEL
  CHECK_RANGE_7BIT(controller)
  CHECK_RANGE_7BIT(value)
  sys_lock();
  inmidi_controlchange(PORT, CHANNEL, controller, value);
  sys_unlock();
  return 0;
}
Beispiel #20
0
int queue_start(struct queue_t *self_p)
{
    ASSERTN(self_p != NULL, EINVAL);

    sys_lock();
    self_p->state = QUEUE_STATE_RUNNING;
    sys_unlock();

    return (0);
}
int worker1_main(void* arg)
{
    while(1)
    {
        while(!sys_lock(&printlock));
        sys_sleep(1000);
        Serial_puts(Serial_module_debug, "Working on 1!\r\n");
        sys_unlock(&printlock);
    }
}
Beispiel #22
0
int dcc_get_cpp_lock()
{
    int lock_fd;
    char *lockdir;
    int i, ncpus, sleepTime = 10000;
    if (dcc_get_lock_dir(&lockdir))
        return -1;
    if (dcc_ncpus(&ncpus))
        ncpus = 1;
    ncpus++;
    for (i=0; i<ncpus; i++) {
        sprintf(cpp_lock_filename, "%s/%s_%d", lockdir, "cpp_lock", i);
        if (dcc_open_lockfile(cpp_lock_filename, &lock_fd))
            lock_fd = -1;
        else {
            if (sys_lock(lock_fd, 0) != 0) {
                rs_trace("someone already has cpp lock: %s (%s)", cpp_lock_filename, strerror(errno));
                close(lock_fd);
                lock_fd = -1;
            } else {
                break;
            }
        }
    }
    if (lock_fd == -1) {
        srandom(getpid());
        sprintf(cpp_lock_filename, "%s/%s_%d", lockdir, "cpp_lock", random()%(ncpus));
        rs_trace("blocking for cpp lock: %s (%s)", cpp_lock_filename, strerror(errno));
        if (dcc_open_lockfile(cpp_lock_filename, &lock_fd))
            lock_fd = -1;
        else {
            if (sys_lock(lock_fd, 1) != 0) {
                rs_log_warning("failed to get cpp lock: %s (%s)", cpp_lock_filename, strerror(errno));
                close(lock_fd);
                lock_fd = -1;
            }
        }
    }
    if (lock_fd != -1)
        rs_trace("got cpp lock: %s", cpp_lock_filename);
    cpp_lock = lock_fd;
    return lock_fd;
}
Beispiel #23
0
static void resume_thrd(struct thrd_t *thrd_p, int res)
{
    /* Resume the reading thread. */
    sys_lock();
    thrd_resume_isr(thrd_p, res);
    sys_unlock();

#if defined(ARCH_ESP) || defined(ARCH_ESP32)
    xSemaphoreGive(thrd_idle_sem);
#endif
}
Beispiel #24
0
int queue_stop(struct queue_t *self_p)
{
    ASSERTN(self_p != NULL, EINVAL);

    int res = 0;

    sys_lock();
    res = queue_stop_isr(self_p);
    sys_unlock();

    return (res);
}
void ofxPd::sendRawMessage( const string& message )
{
	// senda  message to pd
	t_binbuf *b = binbuf_new();
	static char msg_buf[MAXPDSTRING+1];
	strncpy( msg_buf, message.c_str(), message.size() );
	binbuf_text(b, msg_buf, message.size() );
	sys_lock();
	binbuf_eval(b, 0, 0, 0);
	sys_unlock();
	binbuf_free(b);
}
void ofxPd::renderAudio( float * input, float* output, int bufferSize, int nChannels ){
	// adapted from AudioOutputController by bryan summerset
	
	// sys_schedblocksize is How many frames we have per PD dsp_tick
    // inNumberFrames is how many frames have been requested
	int inNumberFrames = bufferSize;
    
    // Make sure we're dealing with evenly divisible numbers between
    // the number of frames requested vs the block size for a given PD dsp tick.
    //Otherwise this looping scheme we're doing below doesn't make much sense.
    assert(inNumberFrames % sys_schedblocksize == 0);
	
    // How many times to generate a DSP event in PD
    int times = inNumberFrames / sys_schedblocksize;
	
    for(int i = 0; i < times; i++) {
        
		
		for (int n = 0; n < sys_schedblocksize; n++) {
            for(int ch = 0; ch < sys_ninchannels; ch++) {
				sys_soundin[n+sys_schedblocksize*ch] =   input[(n*sys_ninchannels+ch) + // offset in iteration
															   i*sys_schedblocksize*sys_ninchannels]; // iteration starting address
				
				
            }        
        }
		
		
		// do one Pd DSP block
        sys_lock();
		sched_audio_callbackfn();
        sys_unlock();
		
        // This should cover sys_noutchannels channels. Turns non-interleaved into 
        // interleaved audio.
        for (int n = 0; n < sys_schedblocksize; n++) {
            for(int ch = 0; ch < sys_noutchannels; ch++) {
                t_sample fsample = CLAMP(sys_soundout[n+sys_schedblocksize*ch],-1,1);
                output[(n*sys_noutchannels+ch) + // offset in iteration
					   i*sys_schedblocksize*sys_noutchannels] // iteration starting address
				
				
				
				= fsample;
				//sys_soundin[n+sys_schedblocksize*ch] = ofRandom(-0.5,0.5); // iteration starting address
				
			}        
        }
        
        // After loading the samples, we need to clear them for the next iteration
        memset(sys_soundout, 0, sizeof(t_sample)*sys_noutchannels*sys_schedblocksize);        
    }
}
Beispiel #27
0
int libpd_message(const char *recv, const char *msg, int n, t_atom *v) {
  t_pd *dest;
  sys_lock();
  dest = get_object(recv);
  if (dest == NULL)
  {
    sys_unlock();
    return -1;
  }
  pd_typedmess(dest, gensym(msg), n, v);
  sys_unlock();
  return 0;
}
Beispiel #28
0
int libpd_symbol(const char *recv, const char *sym) {
  void *obj;
  sys_lock();
  obj = get_object(recv);
  if (obj == NULL)
  {
    sys_unlock();
    return -1;
  }
  pd_symbol(obj, gensym(sym));
  sys_unlock();
  return 0;
}
Beispiel #29
0
int libpd_float(const char *recv, float x) {
  void *obj;
  sys_lock();
  obj = get_object(recv);
  if (obj == NULL)
  {
    sys_unlock();
    return -1;
  }
  pd_float(obj, x);
  sys_unlock();
  return 0;
}
Beispiel #30
0
int libpd_bang(const char *recv) {
  void *obj;
  sys_lock();
  obj = get_object(recv);
  if (obj == NULL)
  {
    sys_unlock();
    return -1;
  }
  pd_bang(obj);
  sys_unlock();
  return 0;
}