void
capture_task (void *data)
{
    int ret;
    
    // We need to disable interrupts during capture so we do not
    // interfere with taking a photo
    extint_disable (extint1);
    
    while ( tcm8230_frame_ready_p ())
        continue;    
    
    while (! tcm8230_frame_ready_p ())
        continue;
    
    ret = tcm8230_capture (image, sizeof(image), 200);
    
    if (ret < 0) // Capturing failed
        *comms_data[CD_PHOTO_READY-ARRAY_OFFSET] = 0;
    else
    {
        *comms_data[CD_PHOTO_READY-ARRAY_OFFSET] = 1;        
        kernelTaskBlocked (CAPTURE_TASK); // Reblock capture task
        kernelTaskReady (PHOTO_READY_FLASH_TASK); // Indicate a photo is available
    }
    extint_enable (extint1);
}
Ejemplo n.º 2
0
void SpiOpen(gcSpiHandleRx pfRxHandler)
{
    DEBUG_printf("SpiOpen\n");

    /* initialize SPI state */
    sSpiInformation.ulSpiState = eSPI_STATE_POWERUP;
    sSpiInformation.SPIRxHandler = pfRxHandler;
    sSpiInformation.usTxPacketLength = 0;
    sSpiInformation.pTxPacket = NULL;
    sSpiInformation.pRxPacket = (unsigned char *)spi_buffer;
    sSpiInformation.usRxPacketLength = 0;
    spi_buffer[CC3000_RX_BUFFER_SIZE - 1] = CC3000_BUFFER_MAGIC_NUMBER;
    wlan_tx_buffer[CC3000_TX_BUFFER_SIZE - 1] = CC3000_BUFFER_MAGIC_NUMBER;

    /* SPI configuration */
    SPI_HANDLE->Init.Mode              = SPI_MODE_MASTER;
    SPI_HANDLE->Init.Direction         = SPI_DIRECTION_2LINES;
    SPI_HANDLE->Init.DataSize          = SPI_DATASIZE_8BIT;
    SPI_HANDLE->Init.CLKPolarity       = SPI_POLARITY_LOW;
    SPI_HANDLE->Init.CLKPhase          = SPI_PHASE_2EDGE;
    SPI_HANDLE->Init.NSS               = SPI_NSS_SOFT;
    SPI_HANDLE->Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8;
    SPI_HANDLE->Init.FirstBit          = SPI_FIRSTBIT_MSB;
    SPI_HANDLE->Init.TIMode            = SPI_TIMODE_DISABLED;
    SPI_HANDLE->Init.CRCCalculation    = SPI_CRCCALCULATION_DISABLED;
    SPI_HANDLE->Init.CRCPolynomial     = 7;
    spi_init(SPI_HANDLE);

    // configure wlan CS and EN pins
    GPIO_InitTypeDef GPIO_InitStructure;
    GPIO_InitStructure.Speed = GPIO_SPEED_FAST;
    GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
    GPIO_InitStructure.Pull = GPIO_NOPULL;
    GPIO_InitStructure.Alternate = 0;

    GPIO_InitStructure.Pin = PIN_CS->pin_mask;
    HAL_GPIO_Init(PIN_CS->gpio, &GPIO_InitStructure);

    GPIO_InitStructure.Pin = PIN_EN->pin_mask;
    HAL_GPIO_Init(PIN_EN->gpio, &GPIO_InitStructure);

    HAL_GPIO_WritePin(PIN_CS->gpio, PIN_CS->pin_mask, GPIO_PIN_SET);
    HAL_GPIO_WritePin(PIN_EN->gpio, PIN_EN->pin_mask, GPIO_PIN_RESET);

    /* do a dummy read, this ensures SCLK is low before
       actual communications start, it might be required */
    CS_LOW();
    uint8_t buf[1];
    HAL_SPI_Receive(SPI_HANDLE, buf, sizeof(buf), SPI_TIMEOUT);
    CS_HIGH();

    // register EXTI
    extint_register((mp_obj_t)PIN_IRQ, GPIO_MODE_IT_FALLING, GPIO_PULLUP, (mp_obj_t)&irq_callback_obj, true, NULL);
    extint_enable(PIN_IRQ->pin);

    DEBUG_printf("SpiOpen finished; IRQ.pin=%d IRQ_LINE=%d\n", PIN_IRQ->pin, PIN_IRQ->pin);
}
static void handler (void)
{
    // Disable interrupt temp
    extint_disable (extint1);
    irq_clear (AT91C_ID_IRQ1);
    
    uint8_t addr;
    uint8_t buffer[2];
    i2c_ret_t ret;

    
    DELAY_US (4);
    //pio_output_toggle (LED1_PIO);

    ret = i2c_slave_read (i2c_slave1, buffer, sizeof (buffer), 10000);

    addr = buffer[0] - ARRAY_OFFSET;

    if (addr >= sizeof (comms_data))
        addr = 0;

    if (ret == 1)
    {
        // Have not received photo line command.
        if (buffer[0] != CD_PHOTO_LINE)
            ret = i2c_slave_write (i2c_slave1, comms_data[addr], 130, 1000); // Return data requested.
        else
        {
            // check if photo ready.
            if (comms_data[CD_PHOTO_READY-ARRAY_OFFSET])
            {
                ret = i2c_slave_write (i2c_slave1, comms_data[CD_PHOTO_NEXT_LINE-ARRAY_OFFSET], 130, 1000);
                if (ret > 0)
                {
                    ret++;
                    *comms_data[CD_FAULT - ARRAY_OFFSET] = ret;
                    comms_data[CD_PHOTO_NEXT_LINE-ARRAY_OFFSET] += ret;
                    if ((comms_data[CD_PHOTO_NEXT_LINE-ARRAY_OFFSET] - image) == image_size)
                    {
                        // We have sent the entire picture
                        comms_data[CD_PHOTO_NEXT_LINE-ARRAY_OFFSET] = image;
                        comms_data[CD_PHOTO_READY-ARRAY_OFFSET] = 0;
                    }
                }
            }
        }
        
    }
    if (ret == 2)
    {
        if (buffer[0] == COMMS_COMMAND)
            next_command = buffer[1];
    }
    extint_enable (extint1);
}
Ejemplo n.º 4
0
/** Configures the External Interrupt Controller to detect changes in the board
 *  button state.
 */
static void configure_extint(void)
{
	struct extint_chan_conf eint_chan_conf;
	extint_chan_get_config_defaults(&eint_chan_conf);

	eint_chan_conf.gpio_pin           = BUTTON_1_EIC_PIN;
	eint_chan_conf.gpio_pin_mux       = BUTTON_1_EIC_MUX;
	eint_chan_conf.detection_criteria = EXTINT_DETECT_BOTH;
	extint_chan_set_config(BUTTON_1_EIC_LINE, &eint_chan_conf);

	extint_enable();
}
int
main (void)
{
    // Configire LEDS
    pio_config_set (LED0_PIO, PIO_OUTPUT_HIGH);
    pio_config_set (LED1_PIO, PIO_OUTPUT_HIGH);
    pio_config_set (LED2_PIO, PIO_OUTPUT_HIGH);
    pio_config_set (LED3_PIO, PIO_OUTPUT_HIGH);
    
    i2c_slave1 = i2c_slave_init (&i2c_bus_cfg, &i2c_slave1_cfg); // Initialise as I2C slave
    extint1 = extint_init (&extint1_cfg);       // Initialise I2C Interrupt
    
    // Initialise comms_data
    uint8_t cd_photo_ready = 0;
    uint8_t cd_fault = 0;
    comms_data[CD_PHOTO_READY-ARRAY_OFFSET] = &cd_photo_ready;
    comms_data[CD_PHOTO_NEXT_LINE-ARRAY_OFFSET] = image;
    comms_data[CD_FAULT-ARRAY_OFFSET] = &cd_fault;
    
    extint_enable (extint1);    // Enable I2C Interrupt
    tcm8230_init (&cfg);        // Initialise Camera
    kernel_init ();             // Initialise Kernel
    
    // Register Tasks for kernel
    kernel_taskRegister (command_task, COMMAND_TASK, &comms_data, 200);
    kernel_taskRegister (capture_task, CAPTURE_TASK, 0, 500);
    kernel_taskRegister (photo_ready_flash_task, PHOTO_READY_FLASH_TASK, 0, 200);
    
    // Block any currently uneeded task
    kernelTaskBlocked (CAPTURE_TASK);
    kernelTaskBlocked (PHOTO_READY_FLASH_TASK);
    
    
    // Finally start the kernel, no code beyone here will be run
    kernel_start ();

    return 0;
}
Ejemplo n.º 6
0
/// \method enable()
/// Enable a disabled interrupt.
STATIC mp_obj_t extint_obj_enable(mp_obj_t self_in) {
    extint_obj_t *self = self_in;
    extint_enable(self->line);
    return mp_const_none;
}
Ejemplo n.º 7
0
void SpiResumeSpi(void)
{
   extint_enable(PIN_IRQ->pin);
}
Ejemplo n.º 8
0
void SpiResumeSpi(void) {
    DEBUG_printf("SpiResumeSpi\n");
    extint_enable(PIN_IRQ->pin);
}