Ejemplo n.º 1
0
//Funkcja dodaje waidomoϾ do kolejki
//Zwraca: 0 jeœli powodzenie. 1 jeœli nie przepe³nienie
uint8_t system_msgPut(uint8_t msg)
{
	uint8_t in = (system_msg.indexIn + 1) % ELEMS(system_msg.quene);
	if(in != system_msg.indexOut)
	{
		system_msg.quene[system_msg.indexIn] = msg;
		system_msg.indexIn = in;
		return 0;
	}
	return 1;
	
//Funkcja pobiera wiadomoϾ z kolejki.
//Zwraca: 0 jeœli brak danych, lub kod wiadomoœci
uint8_t system_msgGet(void)
{
	if(system_msg.indexIn == system_msg.indexOut)
		return 0;
	uint8_t msg = system_msg.quene[system_msg.indexOut];
	system_msg.indexOut = (system_msg.indexOut + 1) %
		ELEMS(system_msg.quene);
		
	return msg;
}

uint8_t system_msgWaitFor(void)
{
	uint8_t msg;
	while(0 == (msg = system_msg())) {};
	
	return msg;
}
Ejemplo n.º 2
0
grpc_metadata *grpc_metadata_buffer_extract_elements(
    grpc_metadata_buffer *buffer) {
  grpc_metadata_buffer_impl *impl;
  elems_hdr *hdr;
  qelem *src;
  grpc_metadata *out;
  size_t i;

  impl = *buffer;

  if (!impl) {
    return NULL;
  }

  hdr = gpr_malloc(sizeof(elems_hdr) + impl->elems * sizeof(grpc_metadata));
  src = ELEMS(impl);
  out = (grpc_metadata *)(hdr + 1);

  hdr->impl = impl;
  for (i = 0; i < impl->elems; i++) {
    out[i].key = (char *)grpc_mdstr_as_c_string(src[i].md->key);
    out[i].value = (char *)grpc_mdstr_as_c_string(src[i].md->value);
    out[i].value_length = GPR_SLICE_LENGTH(src[i].md->value->slice);
  }

  /* clear out buffer (it's not possible to extract elements twice */
  *buffer = NULL;

  return out;
}
Ejemplo n.º 3
0
void grpc_metadata_buffer_flush(grpc_metadata_buffer *buffer,
                                grpc_call_element *elem) {
  grpc_metadata_buffer_impl *impl = *buffer;
  grpc_call_op op;
  qelem *qe;
  size_t i;

  if (!impl) {
    /* nothing to send */
    return;
  }

  /* construct call_op's, and push them down the stack */
  op.type = GRPC_SEND_METADATA;
  op.dir = GRPC_CALL_DOWN;
  for (i = 0; i < impl->elems; i++) {
    qe = &ELEMS(impl)[i];
    op.done_cb = qe->cb;
    op.user_data = qe->user_data;
    op.flags = qe->flags;
    op.data.metadata = qe->md;
    grpc_call_next_op(elem, &op);
  }

  /* free data structures and reset to NULL: we can only flush once */
  gpr_free(impl);
  *buffer = NULL;
}
Ejemplo n.º 4
0
static bool
find_in_cid_tables(uint16 unicode, font_encoding &encoding, uint16 &index,
	font_encoding* order)
{
	for (unsigned int i = 0; i < ELEMS(cid_tables, cid_table); i++) {
		encoding = order[i];
		if (encoding == invalid_encoding) break;
		int index = encoding - first_cjk_encoding;
		int32 bottom = 0;
		int32 top = cid_tables[index].length-1;
		unicode_to_cid *table = cid_tables[index].table;
		while (top >= bottom) {
		    int32 m = (top + bottom) / 2;
			if (unicode < table[m].unicode) {
				top = m-1;
			} else if (unicode > table[m].unicode) {
				bottom = m+1;
			} else {
				index = table[m].cid;
				return true;
			}
		}
	}
	return false;
}
Ejemplo n.º 5
0
static bool
find_encoding(uint16 unicode, uint8 &encoding, uint16 &index)
{
	for (unsigned int i = 0; i < ELEMS(encodings, unicode_to_encoding); i++) {
		if (encodings[i].from <= unicode && unicode <= encodings[i].to) {
			int16 bottom = 0;
			int16 top = encodings[i].length-1;
			uint16* codes = encodings[i].unicodes;
			while (top >= bottom) {
			    int16 m = (top + bottom) / 2;
				if (unicode < codes[m]) {
					top = m-1;
				} else if (unicode > codes[m]) {
					bottom = m+1;
				} else {
					index = m;
					encoding = i;
					return true;
				}
			}
		    return false;
		}
	}
	return false;
}
Ejemplo n.º 6
0
void grpc_metadata_buffer_destroy(grpc_metadata_buffer *buffer,
                                  grpc_op_error error) {
  size_t i;
  qelem *qe;
  if (*buffer) {
    for (i = 0; i < (*buffer)->elems; i++) {
      qe = &ELEMS(*buffer)[i];
      grpc_mdelem_unref(qe->md);
      qe->cb(qe->user_data, error);
    }
    gpr_free(*buffer);
  }
}
Ejemplo n.º 7
0
static void init(void) {
	for (int i=0; i<ELEMS(LED); i++) {
		set_output(LED_DDR, LED[i]);
	}
	LED_PORT = ~0;
	set_input(REED_DDR, REED_PIN);
	set_output(SR_DDR, SR_DATA);
	set_output(SR_DDR, SR_CLOCK);
	set_output(SR_DDR, SR_LATCH);

	OCR1A = 2;
	TCCR1A = 0x00;
	// WGM1=4, prescale at 1024
	TCCR1B = (0 << WGM13)|(1 << WGM12)|(1 << CS12)|(0 << CS11)|(1 << CS10);
	//Set bit 6 in TIMSK to enable Timer 1 compare interrupt
	TIMSK |= (1 << OCIE1A);
	sei();
}
Ejemplo n.º 8
0
static void update_leds(void) {
	// only display something with a valid clock content
	uint8_t on = (clock.state == VALID);
	uint8_t p = on ? (cycle_position() + GLOBAL_OFFSET)%(CYCLE_POS_CNT) : 0;
	// handle any daughter boards
	for (uint8_t i=0; i<ELEMS(daughters); i++) {
		uint8_t content = on ? get_content((p+daughters[i].offset)%CYCLE_POS_CNT) : 0;
		// invert the bitmask since LED are activated on LOW ports.
		if (daughters[i].shift) {
			shift_out(~content);
		} else {
			// directly connected
			LED_PORT = ~content;
		}
	}
	// activate the daughter board LEDs
	trigger_latch();
}
Ejemplo n.º 9
0
void grpc_metadata_buffer_queue(grpc_metadata_buffer *buffer,
                                grpc_call_op *op) {
  grpc_metadata_buffer_impl *impl = *buffer;
  qelem *qe;
  size_t bytes;

  GPR_ASSERT(op->type == GRPC_SEND_METADATA || op->type == GRPC_RECV_METADATA);

  if (!impl) {
    /* this is the first element: allocate enough space to hold the
       header object and the initial element capacity of qelems */
    bytes =
        sizeof(grpc_metadata_buffer_impl) + INITIAL_ELEM_CAP * sizeof(qelem);
    impl = gpr_malloc(bytes);
    /* initialize the header object */
    impl->elems = 0;
    impl->elem_cap = INITIAL_ELEM_CAP;
  } else if (impl->elems == impl->elem_cap) {
    /* more qelems than what we can deal with: grow by doubling size */
    impl->elem_cap *= 2;
    bytes = sizeof(grpc_metadata_buffer_impl) + impl->elem_cap * sizeof(qelem);
    impl = gpr_realloc(impl, bytes);
  }

  /* append an element to the queue */
  qe = &ELEMS(impl)[impl->elems];
  impl->elems++;

  qe->md = op->data.metadata;
  qe->cb = op->done_cb;
  qe->user_data = op->user_data;
  qe->flags = op->flags;

  /* header object may have changed location: store it back */
  *buffer = impl;
}
Ejemplo n.º 10
0
#	error check code!
#endif

#define ELEMS(v, e) sizeof(v) / sizeof(e)

// Adobe Glyph List
#include "enc_range.h"
#include "unicode0.h"
#include "unicode1.h"
#include "unicode2.h"
#include "unicode3.h"
#include "unicode4.h"


static unicode_to_encoding encodings[] = {
	{UNICODE0_FROM, UNICODE0_TO, ELEMS(unicode0, uint16), unicode0},
	{UNICODE1_FROM, UNICODE1_TO, ELEMS(unicode1, uint16), unicode1},
	{UNICODE2_FROM, UNICODE2_TO, ELEMS(unicode2, uint16), unicode2},
	{UNICODE3_FROM, UNICODE3_TO, ELEMS(unicode3, uint16), unicode3},
	{UNICODE4_FROM, UNICODE4_TO, ELEMS(unicode4, uint16), unicode4}
};

// unicode to cid
#include "japanese.h"
#include "gb1.h"
#include "cns1.h"
#include "korean.h"


static cid_table cid_tables[] = {
	{ELEMS(japanese, unicode_to_cid), japanese},