Beispiel #1
0
void clr_set_ctrl(u2_t clr, u2_t set)
{
	static u2_t ctrl;
	u2_t _ctrl = ctrl;
	
	ctrl &= ~clr;
	ctrl |= set;
	if (clr) spi_set(CmdCtrlClr, clr);
	if (set) spi_set(CmdCtrlSet, set);
	//printf("clr_set_ctrl: %04x -> %04x\n", _ctrl, ctrl);
}
Beispiel #2
0
int cfi_init(int unit) {
    struct cfi *cfi = &cfid[unit];
    int spi;

    if (inited) return 1;
    
    switch (unit) {
        case 0:
            cfi->spi = CFI_SPI;
            cfi->unit = 0;
            cfi->cs = CFI_CS;
            cfi->speed = CFI_KHZ;
            break;
    }
    
    spi = cfi->spi;
    
    // Init spi port
    if (spi_init(spi) != 0) {
        syslog(LOG_ERR, "cfi%u cannot open spi%u port", unit, spi);
        return 0;
    }
    
    spi_set_cspin(spi, cfi->cs);
    spi_set_speed(spi, cfi->speed);
    spi_set(spi, PIC32_SPICON_CKE);

    syslog(LOG_INFO, 
           "cfi%u is at port %s, pin cs=%c%d",
           cfi->unit, spi_name(spi), spi_csname(spi), spi_cspin(spi)
    );

    // Setup driver
    return cfi_setup(cfi);
}
Beispiel #3
0
u32 platform_spi_setup( spi_userdata *spi, int mode, u32 clock, unsigned cpol, unsigned cpha, unsigned databits ) {
    if (spi_init(spi->spi) != 0) {
        return 0;
    }
    
    spi_set_speed(spi->spi, spi->speed);
    spi_set_cspin(spi->spi, spi->cs);
    spi_deselect(spi->spi);
    
    if (mode == 1) {
        spi->mode = PIC32_SPICON_MSTEN | PIC32_SPICON_ON | PIC32_SPICON_CKE | PIC32_SPICON_SMP;
        
        switch (databits) {
            case 8:
                break;
            case 16:
                spi->mode |= PIC32_SPICON_MODE16;
                break;

            case 32:
                spi->mode |= PIC32_SPICON_MODE16;
                break;
        }
        spi_set(spi->spi, spi->mode);
    } else {
        return 0;
    }

    return 0;
}
Beispiel #4
0
float ecpu_use()
{
	typedef struct {
		u1_t f0, g0, f1, g1, f2, g2, f3, g3;
	} ctr_t;
	ctr_t *c;
	static SPI_MISO cpu;
	
	if (down || do_fft) return 0;
	spi_get_noduplex(CmdGetCPUCtr, &cpu, sizeof(u2_t[3]));
	c = (ctr_t*) &cpu.word[0];
	u4_t gated = (c->g3 << 24) | (c->g2 << 16) | (c->g1 << 8) | c->g0;
	u4_t free_run = (c->f3 << 24) | (c->f2 << 16) | (c->f1 << 8) | c->f0;
	spi_set(CmdCPUCtrClr);
	return ((float) gated / (float) free_run * 100);
}
Beispiel #5
0
static void data_pump()
{
	ctrl_clr_set(CTRL_INTERRUPT, 0);
	spi_set(CmdSetRXNsamps, NRX_SAMPS-1);
	evDP(EC_EVENT, EV_DPUMP, -1, "dpump_init", evprintf("INIT: SPI CTRL_INTERRUPT %d",
		GPIO_READ_BIT(GPIO0_15)));

	while (1) {

		evDP(EC_EVENT, EV_DPUMP, -1, "data_pump", evprintf("SLEEPING: SPI CTRL_INTERRUPT %d",
			GPIO_READ_BIT(GPIO0_15)));
		TaskSleep(0);
		ctrl_clr_set(CTRL_INTERRUPT, 0);		// ack interrupt, and updates spi status
		evDP(EC_EVENT, EV_DPUMP, -1, "data_pump", evprintf("WAKEUP: SPI CTRL_INTERRUPT %d",
			GPIO_READ_BIT(GPIO0_15)));

		interrupt_task_last_run = timer_us64();
		evDP(EC_EVENT, EV_DPUMP, -1, "data_pump", evprintf("interrupt last run @%.6f ",
			(float) interrupt_task_last_run / 1000000));
		
		snd_service();
		
		for (int ch=0; ch < RX_CHANS; ch++) {
			rx_chan_t *rx = &rx_chan[ch];
			if (!rx->enabled) continue;
			conn_t *c = rx->conn;
			assert(c);
			if (c->task) {
				TaskWakeup(c->task, FALSE, 0);
			}
			#ifdef SND_SEQ_CHECK
			if (audio_dropped != last_audio_dropped) {
				send_msg(c, SM_NO_DEBUG, "MSG audio_dropped=%d", audio_dropped);
			}
			#endif
		}
		#ifdef SND_SEQ_CHECK
		if (audio_dropped != last_audio_dropped) last_audio_dropped = audio_dropped;
		#endif
	}
}
Beispiel #6
0
void Print::digitalWrite(int pin, int state) {
    static int reg;
    reg&=~(1<<pin);
    reg|=state<<pin;
    if (pin==LCD_EN) spi_set(CmdSetLCD, reg);
}