Esempio n. 1
0
uint8_t cNRF24L01::read(uint8_t addr, uint8_t *data)
{
    static enum {RX_RECIEVE, RX_READ } step = RX_RECIEVE;
    const uint8_t len = 10;
    static uint8_t data_tx[len] = {0x11, 0x12, 0x13, 0x14, 0x15,
		                     0x16, 0x17, 0x18, 0x19, 0x1A};
    switch (step) {
    default:
    case RX_RECIEVE:
    	addr_set(addr);
    	power_mode_set(RF_24_PWR_UP, RF24_DIR_RX);
    	status.flush(RX_BUFF);
    	status.flush(TX_BUFF);
    	irq_status_reset();
        hal->gpio->set(SPI1_CE_PIN_PORT, SPI1_CE, PIN_HIGH);
    	//CE.set(PIN_HIGH);
    	step = RX_READ;
    	status.write_ack_payload(data_tx, len);
    	break;
    case RX_READ:
        REG.status.mask = status.read();
        if (!REG.status.bit.RX_DR)
            break;

        read(data, dynamic_payload ? payload_size : dyn_pd.get_dyn_payload_size());
        status.write_ack_payload(data_tx, len);
        irq_status_reset();
        hal->gpio->set(SPI1_CE_PIN_PORT, SPI1_CE, PIN_LOW);
        //CE.set(PIN_LOW);
        step = RX_RECIEVE;
		return 1;
    	}
    return 0;
}
Esempio n. 2
0
/**@brief Function for adding new 6lowpan interface to interface table.
 *
 * @param[in]    p_6lo_interface  Pointer to 6LoWPAN interface.
 * @param[out]   p_index          Pointer to index of internal network interface.
 *
 * @return      NRF_SUCCESS on success, otherwise NRF_ERROR_NO_MEM error.
 */
static uint32_t interface_add(iot_interface_t * p_interface,
                              uint32_t        * p_index )
{
    uint32_t         index;
    uint32_t         err_code;
    ipv6_addr_conf_t linklocal_addr;

    for (index = 0; index < IPV6_MAX_INTERFACE; index++)
    {
        if (m_interfaces[index].p_interface == NULL)
        {
            m_interfaces[index].p_interface = p_interface;
            p_interface->p_upper_stack      = (void *) index;
            (*p_index) = index;

            // Add link local address.
            IPV6_CREATE_LINK_LOCAL_FROM_EUI64(&linklocal_addr.addr, p_interface->local_addr.identifier);
            linklocal_addr.state = IPV6_ADDR_STATE_PREFERRED;

            err_code = addr_set(p_interface, &linklocal_addr);
            if (err_code != NRF_SUCCESS)
            {
                IPV6_ERR("Cannot add link-local address to interface!");
            }

            return NRF_SUCCESS;
        }
    }

    return NRF_ERROR_NO_MEM;
}
Esempio n. 3
0
uint8_t cNRF24L01::write(uint8_t addr, uint8_t *data)
{
    uint8_t timer = 100;

    addr_set(addr);
    power_mode_set(RF_24_PWR_UP, RF24_DIR_TX);
    status.flush(RX_BUFF);
    status.flush(TX_BUFF);
    irq_status_reset();

	status.write_payload(data, payload_size);
    hal->gpio->set(SPI1_CE_PIN_PORT, SPI1_CE, PIN_HIGH);

    while (!tx_complete() || !timer--);
			
    hal->gpio->set(SPI1_CE_PIN_PORT, SPI1_CE, PIN_LOW);
	power_mode_set(RF24_PWR_DOWN, RF24_DIR_TX);
    return timer;
}
Esempio n. 4
0
uint32_t ipv6_address_set(const iot_interface_t  * p_interface,
                          const ipv6_addr_conf_t * p_addr)
{
    VERIFY_MODULE_IS_INITIALIZED();

    NULL_PARAM_CHECK(p_addr);
    NULL_PARAM_CHECK(p_interface);

    uint32_t err_code;

    IPV6_MUTEX_LOCK();

    IPV6_ENTRY();

    err_code = addr_set(p_interface, p_addr);

    IPV6_EXIT();

    IPV6_MUTEX_UNLOCK();

    return err_code;
}