void drvr_at86_reset()
{
    hal_set_rst_low();
    hal_set_slptr_low();
    delay_us(TIME_RESET);
    hal_set_rst_high();
}
示例#2
0
/**
 * @brief Initializes the transceiver
 *
 * This function is called to initialize the transceiver.
 *
 * @return MAC_SUCCESS  if the transceiver state is changed to TRX_OFF and the
 *                 current device part number and version number are correct;
 *         FAILURE otherwise
 */
static uint8_t trx_init(void)
{
    uint8_t trx_status;
    uint8_t poll_counter = 0;

    hal_set_rst_high();
    hal_set_slptr_low();
    /* Wait typical time of timer TR1. */
    delay_us(P_ON_TO_CLKM_AVAILABLE_TYP_US);
    /* Apply reset pulse */
    hal_set_rst_low();
    delay_us(RST_PULSE_WIDTH_US);
    hal_set_rst_high();
    /* Verify that TRX_OFF can be written */
    do
    {
        /* Wait not more than max. value of TR1. */
        if (poll_counter == P_ON_TO_CLKM_ATTEMPTS)
        {
            return(-1/* FAILURE*/);
        }
        /* Wait a short time interval. */
        delay_us(TRX_POLL_WAIT_TIME_US);
        poll_counter++;
        /* Check if AT86RF231 is connected; omit manufacturer id check */
    } while ((hal_register_read(RG_VERSION_NUM) != AT86RF231_VERSION_NUM) ||
             (hal_register_read(RG_PART_NUM) != AT86RF231_PART_NUM));

    /* Verify that TRX_OFF can be written */
    hal_register_write(RG_TRX_STATE, CMD_TRX_OFF);

    /* Verify that the trx has reached TRX_OFF. */
    poll_counter = 0;
    do
    {
        /* Wait a short time interval. */
        delay_us(TRX_POLL_WAIT_TIME_US);

        trx_status = (uint8_t)hal_subregister_read(SR_TRX_STATUS);

        /* Wait not more than max. value of TR2. */
        if (poll_counter == SLEEP_TO_TRX_OFF_ATTEMPTS)
        {
            return(-1/* FAILURE*/);
        }
        poll_counter++;
    } while (trx_status != TRX_OFF);

    tal_trx_status = TRX_OFF;

    return(0);
}
示例#3
0
void hal_init(void)
{
  int i;
  uint32_t volatile dummy;

  RCC->AHBENR |= RCC_AHBENR_GPIOAEN;
  RCC->APB2ENR |= (RCC_APB2ENR_SPI1EN);
  RCC->APB1ENR |= (RCC_APB1ENR_SPI2EN);

  /* Configure I/O */
#if (RF230_BUS == 1)

  /* SPI: MISO; MOSI and CLK */
  gpio_conf_af(GPIOA, 5, GPIO_OUTPUT_TYPE_PPULL, GPIO_OSPEED_40MHZ, GPIO_RESISTORS_PULLDN);
  gpio_conf_af(GPIOA, 6, GPIO_OUTPUT_TYPE_PPULL, GPIO_OSPEED_40MHZ, GPIO_RESISTORS_PULLDN);
  gpio_conf_af(GPIOA, 7, GPIO_OUTPUT_TYPE_PPULL, GPIO_OSPEED_40MHZ, GPIO_RESISTORS_PULLDN);
  gpio_map_af(GPIOA, 5, GPIO_AF_SPI1);
  gpio_map_af(GPIOA, 6, GPIO_AF_SPI1);
  gpio_map_af(GPIOA, 7, GPIO_AF_SPI1);

  /* Manual CS */
  gpio_conf_output(GPIOA, 4, GPIO_OUTPUT_TYPE_PPULL, GPIO_OSPEED_40MHZ);
  gpio_set_resistors(GPIOA, 4, GPIO_RESISTORS_PULLUP);
  /* Reset */
  gpio_conf_output(GPIOA, 8, GPIO_OUTPUT_TYPE_PPULL, GPIO_OSPEED_40MHZ);
  /* Sleep */
  gpio_conf_output(GPIOA, 10, GPIO_OUTPUT_TYPE_PPULL, GPIO_OSPEED_40MHZ);

#if 0
  /* printf("Initiating GPIO for radio\r\n"); */
  /* CS */
  GPIO_CONF_OUTPUT_PORT(A, 4, PUSH_PULL, 50);
  /* CLOCK */
  GPIO_CONF_OUTPUT_PORT(A, 5, ALT_PUSH_PULL, 50);
  /* MISO */
  GPIO_CONF_OUTPUT_PORT(A, 6, ALT_PUSH_PULL, 50);
  /* MOSI */
  GPIO_CONF_OUTPUT_PORT(A, 7, ALT_PUSH_PULL, 50);
  /* Reset */
  GPIO_CONF_OUTPUT_PORT(A, 8, PUSH_PULL, 50);
  /* Sleep */
  GPIO_CONF_OUTPUT_PORT(A, 10, PUSH_PULL, 50);

  /* Set up interrupt pin from radio */

  /* PA11 -> EXTI11, PA -> set EXTICR to 0 */
  AFIO->EXTICR[2] &= 0x0FfF;

  /* Enable clock to peripheral IOPA */
  RCC->APB2ENR |= (RCC_APB2ENR_AFIOEN |
		   RCC_APB2ENR_IOPAEN);
  /* Configure IRQ pin as input */
  GPIO_CONF_INPUT_PORT(A, 11, FLOATING);
  /* Unmask interrupt for interrupt line */ 
  EXTI->IMR |= (1 << RADIO_IRQ_PIN);
  /* Unmask event for interrupt line */ 
  EXTI->EMR |= (1 << RADIO_IRQ_PIN);
  /* Rising edge trigger  */
  EXTI->RTSR |= (1 << RADIO_IRQ_PIN);
  /* Falling edge trigger  */
  /* EXTI->FTSR |= (1 << RADIO_IRQ_PIN); */
  dummy = EXTI->PR;
  NVIC->ISER[1] |= (1 << (EXTI15_10_IRQChannel & 0x1F));
#endif
#else
  /* CS */
  GPIO_CONF_OUTPUT_PORT(B, 12, PUSH_PULL, 50);
  /* CLOCK */
  GPIO_CONF_OUTPUT_PORT(B, 13, ALT_PUSH_PULL, 50);
  /* MISO */
  GPIO_CONF_OUTPUT_PORT(B, 14, ALT_PUSH_PULL, 50);
  /* MOSI */
  GPIO_CONF_OUTPUT_PORT(B, 15, ALT_PUSH_PULL, 50);
  /* Reset */
  GPIO_CONF_OUTPUT_PORT(B, 10, PUSH_PULL, 50);
  /* Sleep */
  GPIO_CONF_OUTPUT_PORT(B, 11, PUSH_PULL, 50);

  /* Set up interrupt pin from radio */

  /* PC11 -> EXTI11, PC -> set EXTICR bits to 2 */
  AFIO->EXTICR[2] &= 0xFF0F;
  AFIO->EXTICR[2] |= 0x0020;
  /* Enable clock to peripheral IOPC */
  RCC->APB2ENR |= (RCC_APB2ENR_AFIOEN |
		   RCC_APB2ENR_IOPCEN);
  /* Configure IRQ pin as input */
  GPIO_CONF_INPUT_PORT(C, 9, FLOATING);
  /* Unmask interrupt for line 9 */ 
  EXTI->IMR |= (1 << RADIO_IRQ_PIN);
  /* Unmask event for line 9 */ 
  EXTI->EMR |= (1 << RADIO_IRQ_PIN);
  /* Rising edge trigger  */
  EXTI->RTSR |= (1 << RADIO_IRQ_PIN);
  /* Falling edge trigger  */
  /* EXTI->FTSR |= (1 << RADIO_IRQ_PIN); */
  dummy = EXTI->PR;
  NVIC->ISER[0] |= (1 << (EXTI9_5_IRQChannel & 0x1F));
#endif

  /* Assert reset */
  hal_set_rst_low();

  /* slptr */
  hal_set_slptr_low();

  /* Don't do like this...*/
  for(i=0; i<100000; i++)
    ;

  /* Init SPI */
  uspi_init(RF230_SPI_BUS, 000);

  /* No chip select */
  spi_radio_cs(1);

  /* De-assert reset */
  hal_set_rst_high();
}