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; }
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; }
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; }
int libpd_list(const char *recv, int n, t_atom *v) { t_pd *dest; sys_lock(); dest = get_object(recv); if (dest == NULL) { sys_unlock(); return -1; } pd_list(dest, &s_list, n, v); sys_unlock(); return 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; }
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); }
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); }
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); }
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(); }
/** * 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); }
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); }
//一下需要系统调用 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; } }
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); }
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(); }
int libpd_exists(const char *sym) { int retval; sys_lock(); retval = (get_object(sym) != NULL); sys_unlock(); return retval; }
void *libpd_bind(const char *sym) { t_symbol *x; sys_lock(); x = gensym(sym); sys_unlock(); return libpdreceive_new(x); }
void libpd_add_symbol(const char *s) { t_symbol *x; sys_lock(); x = gensym(s); sys_unlock(); ADD_ARG(SETSYMBOL); }
unsigned char plc_write_delay(void) { unsigned char ret = 0; sys_lock(); ret = plc_write_busy; sys_unlock(); return ret; }
int libpd_programchange(int channel, int value) { CHECK_CHANNEL CHECK_RANGE_7BIT(value) sys_lock(); inmidi_programchange(PORT, CHANNEL, value); sys_unlock(); return 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; }
int libpd_arraysize(const char *name) { int retval; sys_lock(); GETARRAY retval = garray_npoints(garray); sys_unlock(); return retval; }
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; }
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; }
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; }
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); } }
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 }
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::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); } }
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); }