Beispiel #1
0
//-----------------------------------------------------------------------------
// polled read of a register
uint8_t
kbv_readRegister(VectorNavDriver * nvp, uint8_t reg, uint8_t size, uint8_t * buf)
{
	uint8_t r[] = { 0x01, reg, 0x00, 0x00 };

	chSysLock();

	spiSelectI(nvp->spip);
	// we ignore the first exchange's return
	for ( int i = 0 ; i < 4 ; ++i )
		spiPolledExchange(nvp->spip, r[i]);
	spiUnselectI(nvp->spip);

	gptPolledDelay(nvp->gpdp, 50);

	spiSelectI(nvp->spip);
	for ( int i = 0 ; i < 4 ; ++i )
		r[i] = spiPolledExchange(nvp->spip, 0);

	// was there an error?
	if ( r[0] == 0x00 && r[1] == 0x01 && r[2] == reg && r[3] == 0x00 )
	{
		// all good!
		for ( int i = 0 ; i < size ; ++i )
			buf[i] = spiPolledExchange(nvp->spip, 0);
	}
	spiUnselectI(nvp->spip);
	gptPolledDelay(nvp->gpdp, 50);
	chSysUnlock();
	return r[3];
}
Beispiel #2
0
//-----------------------------------------------------------------------------
static void 
vectornav_spi_end_cb(SPIDriver * spip)
{
	(void)spip;

	switch( async_vn_msg.state )
	{
	case VN_ASYNC_1ST_SPI_CB:
		chSysLockFromISR();
		spiUnselectI(VND1.spip);
		async_vn_msg.state = VN_ASYNC_1ST_SLEEP;
		gptStartOneShotI(VND1.gpdp, VN_SLEEPTIME);
		chSysUnlockFromISR();
		break;

	case VN_ASYNC_2ND_SPI_CB:
		chSysLockFromISR();
		spiUnselectI(VND1.spip);
		// here we have the register
		vectornav_dispatch_register(async_vn_msg.reg, async_vn_msg.buf_size, async_vn_msg.buf);
		async_vn_msg.state = VN_ASYNC_2ND_SLEEP;
		gptStartOneShotI(VND1.gpdp, VN_SLEEPTIME);
		chSysUnlockFromISR();
		break;

	case VN_ASYNC_INACTIVE:
	case VN_ASYNC_1ST_SLEEP:
	case VN_ASYNC_2ND_SLEEP:
	default:
		// @TODO: assert?
		break;
	}
}
Beispiel #3
0
/*
 * SPI end transfer callback.
 */
static void spicb(SPIDriver *spip) {

  /* On transfer end just releases the slave select line.*/
  chSysLockFromIsr();
  spiUnselectI(spip);
  chSysUnlockFromIsr();
}
Beispiel #4
0
void write_digit(int8_t num, uint8_t dig){
     
    uint8_t out_bytes[1]; /*= {
        (((num<10)&&(num>=0)) ? number_seg_bytes[num] : number_seg_bytes[10]),
    };*/
    out_bytes[0] =(((num<10)&&(num>=0)) ? number_seg_bytes[num] : number_seg_bytes[10]); 
    chSysLockFromIsr();
    palClearPad(GPIOA,3);
    /* SPI slave selection and transmission start.*/
    spiSelectI(&SPID1);
    //spiStartSendI(&SPID1, 1, out_bytes);
    spiPolledExchange(&SPID1, out_bytes[0]);
    uint8_t nd = NUM_DIGS;
    while(nd--){
        if(nd == dig){
            palSetPad(GPIOC,nd); 
        } else {
            palClearPad(GPIOC,nd);
        }
    }
    spiUnselectI(&SPID1);
    palSetPad(GPIOA, 3);
    chSysUnlockFromIsr();
    //while(SPI_done == FALSE);
    chThdSleepMicroseconds(DIG_SWITCH_DELAY_US);
    //chThdSleepMilliseconds(DIG_SWITCH_DELAY_MS); 
}
Beispiel #5
0
/**
 * @brief   Deasserts the slave select signal.
 * @details The previously selected peripheral is unselected.
 *
 * @param[in] spip      pointer to the @p SPIDriver object
 *
 * @api
 */
void spiUnselect(SPIDriver *spip) {

  osalDbgCheck(spip != NULL);

  osalSysLock();
  osalDbgAssert(spip->state == SPI_READY, "not ready");
  spiUnselectI(spip);
  osalSysUnlock();
}
Beispiel #6
0
/**
 * @brief   Deasserts the slave select signal.
 * @details The previously selected peripheral is unselected.
 * @pre     ILI9341 is active.
 *
 * @param[in] driverp   pointer to the @p ILI9341Driver object
 *
 * @iclass
 */
void ili9341UnselectI(ILI9341Driver *driverp) {

  osalDbgCheckClassI();
  osalDbgCheck(driverp != NULL);
  osalDbgAssert(driverp->state == ILI9341_ACTIVE, "invalid state");

  spiUnselectI(driverp->config->spi);
  driverp->state = ILI9341_READY;
}
/**
 * @brief   Deasserts the slave select signal.
 * @details The previously selected peripheral is unselected.
 *
 * @param[in] spip      pointer to the @p SPIDriver object
 *
 * @api
 */
void spiUnselect(SPIDriver *spip) {

  chDbgCheck(spip != NULL, "spiUnselect");

  chSysLock();
  chDbgAssert(spip->state == SPI_READY, "spiUnselect(), #1", "not ready");
  spiUnselectI(spip);
  chSysUnlock();
}
Beispiel #8
0
/*
 * SPI end transfer callback.
 */
static void spicb(SPIDriver *spip) {
 
    if(spip->state == SPI_COMPLETE){
    /* On transfer end just releases the slave select line.*/
    chSysLockFromIsr();
    SPI_done = TRUE;
    spiUnselectI(spip);
//    palSetPad(GPIOC,4);
    chSysUnlockFromIsr();
    }
}
Beispiel #9
0
/**
 * @brief   Configures and activates the ILI9341 peripheral.
 * @pre     ILI9341 is stopped.
 *
 * @param[in] driverp   pointer to the @p ILI9341Driver object
 * @param[in] configp   pointer to the @p ILI9341Config object
 *
 * @api
 */
void ili9341Start(ILI9341Driver *driverp, const ILI9341Config *configp) {

  chSysLock();
  osalDbgCheck(driverp != NULL);
  osalDbgCheck(configp != NULL);
  osalDbgCheck(configp->spi != NULL);
  osalDbgAssert(driverp->state == ILI9341_STOP, "invalid state");

  spiSelectI(configp->spi);
  spiUnselectI(configp->spi);
  driverp->config = configp;
  driverp->state = ILI9341_READY;
  chSysUnlock();
}
Beispiel #10
0
void
vexSpiSend()
{
    int16_t      i;

    uint16_t    *txbuf = (uint16_t *)vexSpiData.txdata.data;
    uint16_t    *rxbuf = (uint16_t *)vexSpiData.rxdata_t.data;

    // configure team name if in configuration state
    if(vexSpiData.txdata.pak.state == 0x03)
        {
        char *p = spiTeamName;
        // Set team name data type
        vexSpiData.txdata.pak.type = 0x55;
        // Copy team name into data area
        // This is the same area as occupied normally by motor data
        for(i=0;i<8;i++)
            {
            if(*p != 0)
                vexSpiData.txdata.data[6+i] = *p++;
            else
                vexSpiData.txdata.data[6+i] = ' ';
            }
        }

    // Set handshake to indicate new spi message
    palSetPad( VEX_SPI_ENABLE_PORT, VEX_SPI_ENABLE_PIN );

    for(i=0;i<16;i++)
        {
        spiSelectI(&SPID1);
        rxbuf[i] = spi_lld_polled_exchange( &SPID1, txbuf[i] );
        //spiExchange( &SPID1, 1, &txbuf[i], &rxbuf[i]);
        spiUnselectI(&SPID1);

        if( ((i%4) == 3) && (i != 15) )
            {
            // long delay between each group of 4 words
            vexSpiTickDelay(73);

            // After 4 words negate handshake pin
            palClearPad( VEX_SPI_ENABLE_PORT, VEX_SPI_ENABLE_PIN );
            }
        else
            vexSpiTickDelay(8);
        }

    // increase id for next message
    vexSpiData.txdata.pak.id++;

    // check integrity of received data
    if( (vexSpiData.rxdata_t.data[0] == 0x17 ) && (vexSpiData.rxdata_t.data[1] == 0xC9 ))
        {
        // copy temporary data
        for(i=0;i<32;i++)
            vexSpiData.rxdata.data[i] = vexSpiData.rxdata_t.data[i];

        // Set online status if valid data status set
        if( (vexSpiData.rxdata.pak.status & 0x0F) == 0x08 )
            vexSpiData.online = 1;

        // If in configuration initialize state (0x02 or 0x03)
        if( (vexSpiData.txdata.pak.state & 0x0E) == 0x02 )
            {
            // check for configure request
            if( (vexSpiData.rxdata.pak.status & 0x0F) == 0x02 )
                vexSpiData.txdata.pak.state = 0x03;
            // check for configure and acknowledge
            if( (vexSpiData.rxdata.pak.status & 0x0F) == 0x03 )
                {
                vexSpiData.txdata.pak.state = 0x08;
                vexSpiData.txdata.pak.type  = 0;
                }
            // Either good or bad data force to normal transmission
            // status will either be 0x04 or 0x08
            if( (vexSpiData.rxdata.pak.status & 0x0C) != 0x00 )
                {
                vexSpiData.txdata.pak.state = 0x08;
                vexSpiData.txdata.pak.type  = 0;
                }
            }
        }
    else
        vexSpiData.errors++;
}
Beispiel #11
0
static void spiCallback(SPIDriver *spip) {
	spiUnselectI(spip);

	scheduleSimpleMsg(&logger, "spiCallback HIP=", callbackc++);

}
Beispiel #12
0
/**
 * this is the end of the non-synchronous exchange
 */
static void endOfSpiExchange(SPIDriver *spip) {
	spiUnselectI(driver);
	state = READY_TO_INTEGRATE;
	checkResponse();
}