Exemple #1
0
volatile packet_t* get_free_packet(void) {
	volatile packet_t *p;

	safe_irq_disable(MACA);
	
	BOUND_CHECK(free_head);

	p = free_head;
	if( p != 0 ) {		
		free_head = p->left;
		free_head->right = 0;
	}

	BOUND_CHECK(free_head);

#if PACKET_STATS
	p->get_free++;
#endif

//	print_packets("get_free_packet");
	irq_restore();
	if(bit_is_set(*NIPEND, INT_NUM_MACA)) { *INTFRC = (1 << INT_NUM_MACA); }

	return p;
}
Exemple #2
0
/* ends are to the left */
void free_packet(volatile packet_t *p) {
	safe_irq_disable(MACA);

	BOUND_CHECK(p);

	if(!p) {  PRINTF("free_packet passed packet 0\n\r"); return; }
	if(p == &dummy_ack) { return; }

	BOUND_CHECK(free_head);

	p->length = 0; p->offset = 0;
	p->left = free_head; p->right = 0;
#if PACKET_STATS
	p->seen = 0; 
	p->post_tx = 0;
	p->get_free = 0;
	p->rxd = 0;
#endif

	free_head = p;

	BOUND_CHECK(free_head);

	irq_restore();
	if(bit_is_set(*NIPEND, INT_NUM_MACA)) { *INTFRC = (1 << INT_NUM_MACA); }

	return;
}
void post_receive(void) {
	last_post = RX_POST;
	/* this sets the rxlen field */
	/* this is undocumented but very important */
	/* you will not receive anything without setting it */
	*MACA_TXLEN = (MAX_PACKET_SIZE << 16);
	if(dma_rx == 0) {
		dma_rx = get_free_packet();
		if (dma_rx == 0) {
			PRINTF("trying to fill MACA_DMARX in post_receieve but out of packet buffers\n\r");		
			/* set the sftclock so that we return to the maca_isr */
			*MACA_SFTCLK = *MACA_CLK + RECV_SOFTIMEOUT; /* soft timeout */ 
			*MACA_TMREN = (1 << maca_tmren_sft);
			/* no free buffers, so don't start a reception */
			enable_irq(MACA);
			return;
		}
	}
	BOUND_CHECK(dma_rx);
	BOUND_CHECK(dma_tx);
	*MACA_DMARX = (uint32_t)&(dma_rx->data[0]);
	/* with timeout */		
	*MACA_SFTCLK = *MACA_CLK + RECV_SOFTIMEOUT; /* soft timeout */ 
	*MACA_TMREN = (1 << maca_tmren_sft);
	/* start the receive sequence */
	*MACA_CONTROL = ( (1 << maca_ctrl_asap) | 
			  ( 4 << PRECOUNT) |
			  ( fcs_mode << NOFC ) |
			  (1 << maca_ctrl_auto) |
			  (1 << maca_ctrl_prm) |
			  (maca_ctrl_seq_rx));
	/* status bit 10 is set immediately */
        /* then 11, 10, and 9 get set */ 
        /* they are cleared once we get back to maca_isr */ 
}
Exemple #4
0
void insert_at_rx_head(volatile packet_t *p) {
	safe_irq_disable(MACA);

	BOUND_CHECK(p);

	if(!p) {  PRINTF("insert_at_rx_head passed packet 0\n\r"); return; }
	p->offset = 1; /* first byte is the length */
	if(rx_head == 0) {
		/* start a new queue if empty */
		rx_end = p;
		rx_end->left = 0; rx_end->right = 0;
		rx_head = rx_end;
	} else {
		rx_head->right = p;
		p->left = rx_head;
		p->right = 0;
		rx_head = p;
	}

//	print_packets("insert at rx head");
	irq_restore();
	if(bit_is_set(*NIPEND, INT_NUM_MACA)) { *INTFRC = (1 << INT_NUM_MACA); }

	return;
}
Exemple #5
0
void tx_packet(volatile packet_t *p) {
	safe_irq_disable(MACA);

	BOUND_CHECK(p);

	if(!p) {  PRINTF("tx_packet passed packet 0\n\r"); return; }
	if(tx_head == 0) {
		/* start a new queue if empty */
		tx_end = p;
		tx_end->left = 0; tx_end->right = 0;
		tx_head = tx_end; 
	} else {
		/* add p to the end of the queue */
		tx_end->left = p;
		p->right = tx_end;
		/* move the queue */
		tx_end = p; tx_end->left = 0;
	}
//	print_packets("tx packet");
	irq_restore();
	if(bit_is_set(*NIPEND, INT_NUM_MACA)) { *INTFRC = (1 << INT_NUM_MACA); } 
	if(last_post == NO_POST) { *INTFRC = (1<<INT_NUM_MACA); }
	/* if we are in a reception cycle, advance the softclock timeout to now */
	if(last_post == RX_POST) { *MACA_SFTCLK = *MACA_CLK + CLK_PER_BYTE; }
	return;
}
Exemple #6
0
void post_tx(void) {
	/* set dma tx pointer to the payload */
	/* and set the tx len */
	disable_irq(MACA);
	last_post = TX_POST;
	dma_tx = tx_head; 
#if PACKET_STATS
	dma_tx->post_tx++;
#endif
	*MACA_TXSEQNR = dma_tx->data[2];
	*MACA_TXLEN = (uint32_t)((dma_tx->length) + 2) | (3 << 16); /* set rx len to ACK length */
	*MACA_DMATX = (uint32_t)&(dma_tx->data[ 0 + dma_tx->offset]);
	if(dma_rx == 0) {
		dma_rx = get_free_packet();
		if (dma_rx == 0) { 
			dma_rx = &dummy_ack;
			PRINTF("trying to fill MACA_DMARX on post_tx but out of packet buffers\n\r");
		}
		
	}	
	BOUND_CHECK(dma_rx);
	BOUND_CHECK(dma_tx);
	*MACA_DMARX = (uint32_t)&(dma_rx->data[0]);
	/* disable soft timeout clock */
	/* disable start clock */
	*MACA_TMRDIS = (1 << maca_tmren_sft) | ( 1<< maca_tmren_cpl) | ( 1 << maca_tmren_strt ) ;
	
        /* set complete clock to long value */
	/* acts like a watchdog in case the MACA locks up */
	*MACA_CPLCLK = *MACA_CLK + CPL_TIMEOUT;
	/* enable complete clock */
	*MACA_TMREN = (1 << maca_tmren_cpl);
	
	enable_irq(MACA);
	*MACA_CONTROL = ( ( 4 << PRECOUNT) |
			  ( prm_mode << PRM) |
			  (maca_ctrl_mode_no_cca << maca_ctrl_mode) |
			  (1 << maca_ctrl_asap) |
			  (maca_ctrl_seq_tx));	
	/* status bit 10 is set immediately */
        /* then 11, 10, and 9 get set */ 
        /* they are cleared once we get back to maca_isr */ 
}
Exemple #7
0
void free_tx_head(void) {
	volatile packet_t *p;
	safe_irq_disable(MACA);

	BOUND_CHECK(tx_head);

	p = tx_head;
	tx_head = tx_head->left;
	if(tx_head == 0) { tx_end = 0; }
	free_packet(p);
	
//	print_packets("free tx head");
	irq_restore();
	if(bit_is_set(*NIPEND, INT_NUM_MACA)) { *INTFRC = (1 << INT_NUM_MACA); }

	return;
}
Exemple #8
0
/* <anonymous:1965> */
obj_t BGl_zc3anonymousza31965ze3z83zz__modulez00(obj_t BgL_envz00_1666, obj_t BgL_fz00_1668)
{ AN_OBJECT;
{ /* Llib/module.scm 213 */
{ /* Llib/module.scm 214 */
obj_t BgL_abasez00_1667;
BgL_abasez00_1667 = 
PROCEDURE_REF(BgL_envz00_1666, 
(int)(((long)0))); 
{ 
obj_t BgL_fz00_896;
BgL_fz00_896 = BgL_fz00_1668; 
{ 
obj_t BgL_fz00_903;obj_t BgL_abasez00_904;
BgL_fz00_903 = BgL_fz00_896; 
BgL_abasez00_904 = BgL_abasez00_1667; 
if(
STRINGP(BgL_fz00_903))
{ /* Llib/module.scm 203 */
bool_t BgL_testz00_2175;
if(
bigloo_strcmp(BgL_fz00_903, BGl_string2367z00zz__modulez00))
{ /* Llib/module.scm 203 */
BgL_testz00_2175 = ((bool_t)1)
; }  else 
{ /* Llib/module.scm 203 */
unsigned char BgL_arg1972z00_909;obj_t BgL_arg1973z00_910;
{ /* Llib/module.scm 203 */
obj_t BgL_s2257z00_1669;
BgL_s2257z00_1669 = BgL_fz00_903; 
{ /* Llib/module.scm 203 */
long BgL_l2259z00_1671;
BgL_l2259z00_1671 = 
STRING_LENGTH(BgL_s2257z00_1669); 
if(
BOUND_CHECK(((long)0), BgL_l2259z00_1671))
{ /* Llib/module.scm 203 */
BgL_arg1972z00_909 = 
STRING_REF(BgL_s2257z00_1669, ((long)0)); }  else 
{ 
obj_t BgL_auxz00_2182;
BgL_auxz00_2182 = 
BGl_indexzd2outzd2ofzd2boundszd2errorz00zz__errorz00(BGl_string2330z00zz__modulez00, 
BINT(((long)7865)), BGl_string2368z00zz__modulez00, 
BINT(((long)0)), BgL_s2257z00_1669); 
FAILURE(BgL_auxz00_2182,BFALSE,BFALSE);} } } 
BgL_arg1973z00_910 = 
BGl_filezd2separatorzd2zz__osz00(); 
{ /* Llib/module.scm 203 */
unsigned char BgL_char2z00_1445;
{ /* Llib/module.scm 203 */
obj_t BgL_auxz00_2188;
if(
CHARP(BgL_arg1973z00_910))
{ /* Llib/module.scm 203 */
BgL_auxz00_2188 = BgL_arg1973z00_910
; }  else 
{ 
obj_t BgL_auxz00_2191;
BgL_auxz00_2191 = 
BGl_typezd2errorzd2zz__errorz00(BGl_string2330z00zz__modulez00, 
BINT(((long)7897)), BGl_string2369z00zz__modulez00, BGl_string2370z00zz__modulez00, BgL_arg1973z00_910); 
FAILURE(BgL_auxz00_2191,BFALSE,BFALSE);} 
BgL_char2z00_1445 = 
CCHAR(BgL_auxz00_2188); } 
BgL_testz00_2175 = 
(BgL_arg1972z00_909==BgL_char2z00_1445); } } 
if(BgL_testz00_2175)
{ /* Llib/module.scm 203 */
return BgL_fz00_903;}  else 
{ /* Llib/module.scm 204 */
obj_t BgL_auxz00_2197;
if(
STRINGP(BgL_abasez00_904))
{ /* Llib/module.scm 204 */
BgL_auxz00_2197 = BgL_abasez00_904
; }  else 
{ 
obj_t BgL_auxz00_2200;
BgL_auxz00_2200 = 
BGl_typezd2errorzd2zz__errorz00(BGl_string2330z00zz__modulez00, 
BINT(((long)7928)), BGl_string2369z00zz__modulez00, BGl_string2355z00zz__modulez00, BgL_abasez00_904); 
FAILURE(BgL_auxz00_2200,BFALSE,BFALSE);} 
return 
BGl_makezd2filezd2namez00zz__osz00(BgL_auxz00_2197, BgL_fz00_903);} }  else 
{ /* Llib/module.scm 202 */
return BgL_fz00_903;} } } } } 
}
Exemple #9
0
static int luaA_mixer_ext_set(lua_State *L) {
    mixer_ext_t *mext = luaL_checkudata(L, 1, "mixer_ext");
    if ((mext->ext.flags & MIXF_WRITEABLE) == 0) return 0;

    const char* strindex = luaL_checkstring(L, 2);
    if (strcmp(strindex, "value") != 0) return 0;

    oss_mixer_enuminfo enuminf;
    int shift = 0, mask = 0, mono = 0, onoff = 0;
    int value, rvalue;

    switch (mext->ext.type) {
        case MIXT_SLIDER:
            mask = ~0; mono = 1; break;

        case MIXT_MONOSLIDER16:
        case MIXT_MONODB:
            mono = 1;
        case MIXT_STEREOSLIDER16:
        case MIXT_STEREODB:
            shift = 16; mask = 0xffff; break;

        case MIXT_MONOSLIDER:
        case MIXT_MONOPEAK:
        case MIXT_MONOVU:
            mono = 1;
        case MIXT_STEREOSLIDER:
        case MIXT_STEREOPEAK:
        case MIXT_STEREOVU:
            shift = 8; mask = 0xff; break;

        case MIXT_ONOFF:
        case MIXT_MUTE:
            onoff = 1;

        default:;
    }

    if (lua_istable(L, 3)) { // two channels
        if (!mask || mono) return 0;

        lua_rawgeti(L, 3, 1); // left channel
        lua_rawgeti(L, 3, 2); // right channel
        value = luaL_checknumber(L, -1); BOUND_CHECK(value, mext->ext.minvalue, mext->ext.maxvalue);
        rvalue = luaL_checknumber(L, -2); BOUND_CHECK(rvalue, mext->ext.minvalue, mext->ext.maxvalue);

        value = ((value & mask) << shift) | (rvalue & mask);
        lua_pop(L, 2);

    } else if (lua_isboolean(L, 3)) { // switch/mute
        if (!onoff) return 0;
        value = lua_toboolean(L, 3);

    } else if (lua_isnumber(L, 3)) { // single channel or set both channels to this value
        if (!mask) return 0;
        value = lua_tonumber(L, 3);
        BOUND_CHECK(value, mext->ext.minvalue, mext->ext.maxvalue);
        value = value & mask;
        if (!mono) value = (value << shift) | value;

    } else if (lua_isstring(L, 3)) { // set enum
        if (mext->ext.type != MIXT_ENUM) return 0;
        enuminf.dev = mext->ext.dev;
        enuminf.ctrl = mext->ext.ctrl;
        if (ioctl(mext->mixer->fh, SNDCTL_MIX_ENUMINFO, &enuminf) < 0) return 0;

        const char* strvalue = lua_tostring(L, 3);

        for (value = 0; value < mext->ext.maxvalue; value++) {
            if (!IN_ENUM(mext->ext.enum_present, value))
                continue;
            if (strcmp(enuminf.strings + enuminf.strindex[value], strvalue) == 0)
                break;
        }
        if (value == mext->ext.maxvalue) return 0;
    }

    write_mixer(mext, value);
    return 0;
}