Exemplo n.º 1
0
//esp8266 slave isr handle funtion,tiggered when any transmission is finished.
//the function is registered in spi_slave_init.
static void ICACHE_FLASH_ATTR
spi_slave_isr_handler(void *para)
{
    uint32 regvalue;

    if(READ_PERI_REG(0x3ff00020)&BIT4)
    {
        //following 3 lines is to clear isr signal
        CLEAR_PERI_REG_MASK(SPI_SLAVE(SPI), 0x3ff);
    }
    else if(READ_PERI_REG(0x3ff00020)&BIT7)   //bit7 is for hspi isr,
    {
        regvalue=READ_PERI_REG(SPI_SLAVE(HSPI));
        CLEAR_PERI_REG_MASK(SPI_SLAVE(HSPI),
                            SPI_TRANS_DONE_EN|
                            SPI_SLV_WR_STA_DONE_EN|
                            SPI_SLV_RD_STA_DONE_EN|
                            SPI_SLV_WR_BUF_DONE_EN|
                            SPI_SLV_RD_BUF_DONE_EN);
        SET_PERI_REG_MASK(SPI_SLAVE(HSPI), SPI_SYNC_RESET);
        CLEAR_PERI_REG_MASK(SPI_SLAVE(HSPI),
                            SPI_TRANS_DONE|
                            SPI_SLV_WR_STA_DONE|
                            SPI_SLV_RD_STA_DONE|
                            SPI_SLV_WR_BUF_DONE|
                            SPI_SLV_RD_BUF_DONE);
        SET_PERI_REG_MASK(SPI_SLAVE(HSPI),
                          SPI_TRANS_DONE_EN|
                          SPI_SLV_WR_STA_DONE_EN|
                          SPI_SLV_RD_STA_DONE_EN|
                          SPI_SLV_WR_BUF_DONE_EN|
                          SPI_SLV_RD_BUF_DONE_EN);

        if(regvalue&SPI_SLV_WR_BUF_DONE)
        {
            uint32_t i, reg, recv_data;

            GPIO_OUTPUT_SET(0, 0);

            for(reg = SPI_W0(HSPI); reg < SPI_W8(HSPI); reg += 4)
            {
                recv_data = READ_PERI_REG(reg);
                for(i = 0; i < 4; ++i, ++idx, recv_data >>= 8)
                    spi_data[idx] = recv_data & 0xff;
            }

            /* TODO: post task event ... 
            *
            * system_os_post(USER_TASK_PRIO_1, ut_sig_mosi, (ETSParam)spi_data);
            * */

            GPIO_OUTPUT_SET(0, 1);
        }
Exemplo n.º 2
0
/**
 * @brief Load data to send buffer by slave mode.
 *
 */
int ICACHE_FLASH_ATTR SPISlaveSendData(SpiNum spiNum, uint32_t *pInData, uint8_t inLen)
{
    if (NULL == pInData) {
        return -1;
    }
    char i;
    for (i = 0; i < inLen; ++i) {
        WRITE_PERI_REG((SPI_W8(spiNum) + (i << 2)), *pInData++);
    }
    // Enable slave transmission liston
    SET_PERI_REG_MASK(SPI_CMD(spiNum), SPI_USR);
    return 0;
}