本文整理汇总了C++中NVIC_ClearPendingIRQ函数的典型用法代码示例。如果您正苦于以下问题:C++ NVIC_ClearPendingIRQ函数的具体用法?C++ NVIC_ClearPendingIRQ怎么用?C++ NVIC_ClearPendingIRQ使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NVIC_ClearPendingIRQ函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ASSERT
/***************************************************************************//**
* MSS_SPI_init()
* See "mss_spi.h" for details of how to use this function.
*/
void MSS_SPI_init
(
mss_spi_instance_t * this_spi
)
{
uint16_t i;
ASSERT((this_spi == &g_mss_spi0) || (this_spi == &g_mss_spi1));
if(this_spi == &g_mss_spi0)
{
this_spi->hw_reg = ((SPI_REVB_TypeDef *) SPI0_BASE);
this_spi->irqn = SPI0_IRQn;
/* reset SPI0 */
SYSREG->SOFT_RST_CR |= SYSREG_SPI0_SOFTRESET_MASK;
/* Clear any previously pended SPI0 interrupt */
NVIC_ClearPendingIRQ(SPI0_IRQn);
/* Take SPI0 out of reset. */
SYSREG->SOFT_RST_CR &= ~SYSREG_SPI0_SOFTRESET_MASK;
}
else
{
this_spi->hw_reg = ((SPI_REVB_TypeDef *) SPI1_BASE);
this_spi->irqn = SPI1_IRQn;
/* reset SPI1 */
SYSREG->SOFT_RST_CR |= SYSREG_SPI1_SOFTRESET_MASK;
/* Clear any previously pended SPI1 interrupt */
NVIC_ClearPendingIRQ(SPI1_IRQn);
/* Take SPI1 out of reset. */
SYSREG->SOFT_RST_CR &= ~SYSREG_SPI1_SOFTRESET_MASK;
}
/* De-assert reset bit. */
this_spi->hw_reg->CONTROL &= ~CTRL_REG_RESET_MASK;
/* Initialize SPI driver instance data. */
this_spi->frame_rx_handler = 0u;
this_spi->slave_tx_frame = 0u;
this_spi->block_rx_handler = 0u;
this_spi->slave_tx_buffer = 0u;
this_spi->slave_tx_size = 0u;
this_spi->slave_tx_idx = 0u;
this_spi->resp_tx_buffer = 0u;
this_spi->resp_buff_size = 0u;
this_spi->resp_buff_tx_idx = 0u;
this_spi->cmd_handler = 0;
this_spi->slave_rx_buffer = 0;
this_spi->slave_rx_size = 0u;
this_spi->slave_rx_idx = 0u;
for(i = 0u; i < (uint16_t)MSS_SPI_MAX_NB_OF_SLAVES; ++i)
{
this_spi->slaves_cfg[i].ctrl_reg = NOT_CONFIGURED;
}
}
示例2: main
/**
* \brief Application entry point for PWM with LED example.
* Output PWM waves on LEDs to make them fade in and out.
*
* \return Unused (ANSI-C compatibility).
*/
int main(void)
{
/* Initialize the SAM system */
sysclk_init();
board_init();
/* Configure the console uart for debug information */
configure_console();
/* Output example information */
puts(STRING_HEADER);
/* Enable PWM peripheral clock */
#if (SAMV70 || SAMV71 || SAME70 || SAMS70)
pmc_enable_periph_clk(ID_PWM0);
#else
pmc_enable_periph_clk(ID_PWM);
#endif
/* Disable PWM channels for LEDs */
#if (SAMV70 || SAMV71 || SAME70 || SAMS70)
pwm_channel_disable(PWM0, PIN_PWM_LED0_CHANNEL);
pwm_channel_disable(PWM0, PIN_PWM_LED1_CHANNEL);
#else
pwm_channel_disable(PWM, PIN_PWM_LED0_CHANNEL);
pwm_channel_disable(PWM, PIN_PWM_LED1_CHANNEL);
#endif
/* Set PWM clock A as PWM_FREQUENCY*PERIOD_VALUE (clock B is not used) */
pwm_clock_t clock_setting = {
.ul_clka = PWM_FREQUENCY * PERIOD_VALUE,
.ul_clkb = 0,
.ul_mck = sysclk_get_cpu_hz()
};
#if (SAMV70 || SAMV71 || SAME70 || SAMS70)
pwm_init(PWM0, &clock_setting);
#else
pwm_init(PWM, &clock_setting);
#endif
/* Initialize PWM channel for LED0 */
/* Period is left-aligned */
g_pwm_channel_led.alignment = PWM_ALIGN_LEFT;
/* Output waveform starts at a low level */
g_pwm_channel_led.polarity = PWM_LOW;
/* Use PWM clock A as source clock */
g_pwm_channel_led.ul_prescaler = PWM_CMR_CPRE_CLKA;
/* Period value of output waveform */
g_pwm_channel_led.ul_period = PERIOD_VALUE;
/* Duty cycle value of output waveform */
g_pwm_channel_led.ul_duty = INIT_DUTY_VALUE;
g_pwm_channel_led.channel = PIN_PWM_LED0_CHANNEL;
#if (SAMV70 || SAMV71 || SAME70 || SAMS70)
pwm_channel_init(PWM0, &g_pwm_channel_led);
#else
pwm_channel_init(PWM, &g_pwm_channel_led);
#endif
/* Enable channel counter event interrupt */
#if (SAMV70 || SAMV71 || SAME70 || SAMS70)
pwm_channel_enable_interrupt(PWM0, PIN_PWM_LED0_CHANNEL, 0);
#else
pwm_channel_enable_interrupt(PWM, PIN_PWM_LED0_CHANNEL, 0);
#endif
/* Initialize PWM channel for LED1 */
/* Period is center-aligned */
g_pwm_channel_led.alignment = PWM_ALIGN_CENTER;
/* Output waveform starts at a high level */
g_pwm_channel_led.polarity = PWM_HIGH;
/* Use PWM clock A as source clock */
g_pwm_channel_led.ul_prescaler = PWM_CMR_CPRE_CLKA;
/* Period value of output waveform */
g_pwm_channel_led.ul_period = PERIOD_VALUE;
/* Duty cycle value of output waveform */
g_pwm_channel_led.ul_duty = INIT_DUTY_VALUE;
g_pwm_channel_led.channel = PIN_PWM_LED1_CHANNEL;
#if (SAMV70 || SAMV71 || SAME70 || SAMS70)
pwm_channel_init(PWM0, &g_pwm_channel_led);
/* Disable channel counter event interrupt */
pwm_channel_disable_interrupt(PWM0, PIN_PWM_LED1_CHANNEL, 0);
#else
pwm_channel_init(PWM, &g_pwm_channel_led);
/* Disable channel counter event interrupt */
pwm_channel_disable_interrupt(PWM, PIN_PWM_LED1_CHANNEL, 0);
#endif
/* Configure interrupt and enable PWM interrupt */
#if (SAMV70 || SAMV71 || SAME70 || SAMS70)
NVIC_DisableIRQ(PWM0_IRQn);
NVIC_ClearPendingIRQ(PWM0_IRQn);
NVIC_SetPriority(PWM0_IRQn, 0);
//.........这里部分代码省略.........
示例3: EXTI_Handler
/**
* @brief This function handles EXTI Handler.
* @param None
* @retval None
*/
void EXTI_Handler(void)
{
LED_Toggle(GPIOC,GPIO_Pin_0);
NVIC_ClearPendingIRQ(EXTI_IRQn);
}
示例4: rtc_init
void rtc_init(void) {
RCC_OscInitTypeDef RCC_OscInitStruct;
#if RTC_LSI
if (rtc_inited) return;
rtc_inited = 1;
#endif
RtcHandle.Instance = RTC;
#if !RTC_LSI
// Enable LSE Oscillator
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; // Mandatory, otherwise the PLL is reconfigured!
RCC_OscInitStruct.LSEState = RCC_LSE_ON; // External 32.768 kHz clock on OSC_IN/OSC_OUT
RCC_OscInitStruct.LSIState = RCC_LSI_OFF;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) == HAL_OK) { // Check if LSE has started correctly
// Connect LSE to RTC
__HAL_RCC_RTC_CONFIG(RCC_RTCCLKSOURCE_LSE);
} else {
error("Cannot initialize RTC with LSE\n");
}
#else
// Enable Power clock
__PWR_CLK_ENABLE();
// Enable access to Backup domain
HAL_PWR_EnableBkUpAccess();
// Reset Backup domain
__HAL_RCC_BACKUPRESET_FORCE();
__HAL_RCC_BACKUPRESET_RELEASE();
// Enable LSI clock
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI | RCC_OSCILLATORTYPE_LSE;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; // Mandatory, otherwise the PLL is reconfigured!
RCC_OscInitStruct.LSEState = RCC_LSE_OFF;
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
error("Cannot initialize RTC with LSI\n");
}
// Connect LSI to RTC
__HAL_RCC_RTC_CONFIG(RCC_RTCCLKSOURCE_LSI);
#endif
// Enable RTC
__HAL_RCC_RTC_ENABLE();
RtcHandle.Init.HourFormat = RTC_HOURFORMAT_24;
RtcHandle.Init.AsynchPrediv = RTC_ASYNCH_PREDIV;
RtcHandle.Init.SynchPrediv = RTC_SYNCH_PREDIV;
RtcHandle.Init.OutPut = RTC_OUTPUT_DISABLE;
RtcHandle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
RtcHandle.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
if (HAL_RTC_Init(&RtcHandle) != HAL_OK) {
error("RTC error: RTC initialization failed.");
}
#if DEVICE_LOWPOWERTIMER
#if RTC_LSI
rtc_write(0);
#else
if (!rtc_isenabled()) {
rtc_write(0);
}
#endif
NVIC_ClearPendingIRQ(RTC_IRQn);
NVIC_DisableIRQ(RTC_IRQn);
NVIC_SetVector(RTC_IRQn, (uint32_t)RTC_IRQHandler);
NVIC_EnableIRQ(RTC_IRQn);
#endif
}
示例5: app_uart_init
//.........这里部分代码省略.........
// Configure buffer TX buffer.
err_code = app_fifo_init(&m_tx_fifo, p_buffers->tx_buf, p_buffers->tx_buf_size);
if (err_code != NRF_SUCCESS)
{
// Propagate error code.
return err_code;
}
// Configure RX and TX pins.
nrf_gpio_cfg_output(p_comm_params->tx_pin_no);
nrf_gpio_cfg_input(p_comm_params->rx_pin_no, NRF_GPIO_PIN_NOPULL);
NRF_UART0->PSELTXD = p_comm_params->tx_pin_no;
NRF_UART0->PSELRXD = p_comm_params->rx_pin_no;
// Configure baud rate and parity.
NRF_UART0->BAUDRATE = (p_comm_params->baud_rate << UART_BAUDRATE_BAUDRATE_Pos);
if (p_comm_params->use_parity)
{
NRF_UART0->CONFIG = (UART_CONFIG_PARITY_Included << UART_CONFIG_PARITY_Pos);
}
else
{
NRF_UART0->CONFIG = (UART_CONFIG_PARITY_Excluded << UART_CONFIG_PARITY_Pos);
}
if (p_comm_params->use_hardware_flow_control)
{
// Configure hardware flow control.
nrf_gpio_cfg_output(p_comm_params->rts_pin_no);
NRF_GPIO->OUT = 1 << p_comm_params->rts_pin_no;
NRF_UART0->PSELCTS = UART_PIN_DISCONNECTED;
NRF_UART0->PSELRTS = p_comm_params->rts_pin_no;
NRF_UART0->CONFIG |= (UART_CONFIG_HWFC_Enabled << UART_CONFIG_HWFC_Pos);
// Setup the gpiote to handle pin events on cts-pin.
// For the UART we want to detect both low->high and high->low transistions in order to
// know when to activate/deactivate the TX/RX in the UART.
// Configure pin.
m_pin_cts_mask = (1 << p_comm_params->cts_pin_no);
GPIO_PIN_CONFIG(p_comm_params->cts_pin_no,
GPIO_PIN_CNF_DIR_Input,
GPIO_PIN_CNF_INPUT_Connect,
GPIO_PIN_CNF_PULL_Disabled,
GPIO_PIN_CNF_DRIVE_S0S1,
GPIO_PIN_CNF_SENSE_Low);
gpiote_pin_low_high_mask = (1 << p_comm_params->cts_pin_no);
gpiote_pin_high_low_mask = (1 << p_comm_params->cts_pin_no);
err_code = app_gpiote_user_register(&m_gpiote_uid,
gpiote_pin_low_high_mask,
gpiote_pin_high_low_mask,
gpiote_uart_event_handler);
if (err_code != NRF_SUCCESS)
{
return err_code;
}
err_code = app_gpiote_pins_state_get(m_gpiote_uid, &gpiote_high_pins);
if (err_code != NRF_SUCCESS)
{
return err_code;
}
err_code = app_gpiote_user_enable(m_gpiote_uid);
if (err_code != NRF_SUCCESS)
{
return err_code;
}
// UART CTS pin is active when low.
if ((gpiote_high_pins & (1 << p_comm_params->cts_pin_no)) == 0)
{
on_uart_event(ON_CTS_LOW);
}
else
{
on_uart_event(ON_CTS_HIGH);
}
}
else
{
uart_no_flow_control_init();
m_current_state = UART_READY;
}
// Enable UART interrupt
NRF_UART0->INTENCLR = 0xffffffffUL;
NRF_UART0->INTENSET = (UART_INTENSET_RXDRDY_Set << UART_INTENSET_RXDRDY_Pos) |
(UART_INTENSET_TXDRDY_Set << UART_INTENSET_TXDRDY_Pos) |
(UART_INTENSET_ERROR_Set << UART_INTENSET_ERROR_Pos);
NVIC_ClearPendingIRQ(UART0_IRQn);
NVIC_SetPriority(UART0_IRQn, irq_priority);
NVIC_EnableIRQ(UART0_IRQn);
return NRF_SUCCESS;
}
示例6: host_platform_bus_init
OSStatus host_platform_bus_init( void )
{
#ifndef USE_OWN_SPI_DRV
struct spi_master_vec_config spi;
#else
pdc_packet_t pdc_spi_packet;
#endif
OSStatus result;
platform_mcu_powersave_disable();
spi_disable_interrupt(SPI_MASTER_BASE, 0xffffffff);
//Disable_global_interrupt();//TBD!
result = mico_rtos_init_semaphore( &spi_transfer_finished_semaphore, 1 );
if ( result != kNoErr )
{
return result;
}
MicoGpioInitialize( (mico_gpio_t)MICO_GPIO_9, INPUT_PULL_UP );
//ioport_port_mask_t ul_mask = ioport_pin_to_mask(CREATE_IOPORT_PIN(PORTA,24));
//pio_set_input(PIOA,ul_mask, PIO_PULLUP|PIO_DEBOUNCE);
MicoGpioEnableIRQ( (mico_gpio_t)MICO_GPIO_9, IRQ_TRIGGER_RISING_EDGE, spi_irq_handler, NULL );
#ifndef HARD_CS_NSS0
MicoGpioInitialize( MICO_GPIO_15, OUTPUT_PUSH_PULL);//spi ss/cs
MicoGpioOutputHigh( MICO_GPIO_15 );//MICO_GPIO_15 TBD!
#else
ioport_set_pin_peripheral_mode(SPI_NPCS0_GPIO, SPI_NPCS0_FLAGS);//TBD!
#endif
/* set PORTB 01 to high to put WLAN module into g_SPI mode */
MicoGpioInitialize( (mico_gpio_t)WL_GPIO0, OUTPUT_PUSH_PULL );
MicoGpioOutputHigh( (mico_gpio_t)WL_GPIO0 );
#ifdef USE_OWN_SPI_DRV
#if (SAMG55)
/* Enable the peripheral and set SPI mode. */
flexcom_enable(BOARD_FLEXCOM_SPI);
flexcom_set_opmode(BOARD_FLEXCOM_SPI, FLEXCOM_SPI);
#else
/* Configure an SPI peripheral. */
pmc_enable_periph_clk(SPI_ID);
#endif
//Init pdc, and clear RX TX.
spi_m_pdc = spi_get_pdc_base(SPI_MASTER_BASE);
pdc_spi_packet.ul_addr = NULL;
pdc_spi_packet.ul_size = 3;
pdc_tx_init(spi_m_pdc, &pdc_spi_packet, NULL);
pdc_rx_init(spi_m_pdc, &pdc_spi_packet, NULL);
spi_disable(SPI_MASTER_BASE);
spi_reset(SPI_MASTER_BASE);
spi_set_lastxfer(SPI_MASTER_BASE);
spi_set_master_mode(SPI_MASTER_BASE);
spi_disable_mode_fault_detect(SPI_MASTER_BASE);
#ifdef HARD_CS_NSS0
//spi_enable_peripheral_select_decode(SPI_MASTER_BASE);
//spi_set_peripheral_chip_select_value(SPI_MASTER_BASE, SPI_CHIP_SEL);
spi_set_peripheral_chip_select_value(SPI_MASTER_BASE, SPI_CHIP_PCS); //use soft nss comment here
#endif
spi_set_clock_polarity(SPI_MASTER_BASE, SPI_CHIP_SEL, SPI_CLK_POLARITY);
spi_set_clock_phase(SPI_MASTER_BASE, SPI_CHIP_SEL, SPI_CLK_PHASE);
spi_set_bits_per_transfer(SPI_MASTER_BASE, SPI_CHIP_SEL, SPI_CSR_BITS_8_BIT);
spi_set_baudrate_div(SPI_MASTER_BASE, SPI_CHIP_SEL, (sysclk_get_cpu_hz() / SPI_BAUD_RATE));
spi_set_transfer_delay(SPI_MASTER_BASE, SPI_CHIP_SEL, SPI_DLYBS, SPI_DLYBCT);
/* Must be lower priority than the value of configMAX_SYSCALL_INTERRUPT_PRIORITY */
/* otherwise FreeRTOS will not be able to mask the interrupt */
/* keep in mind that ARMCM3 interrupt priority logic is inverted, the highest value */
/* is the lowest priority */
/* Configure SPI interrupts . */
spi_enable_interrupt(SPI_MASTER_BASE, SPI_IER_RXBUFF);
//spi_enable_interrupt(SPI_MASTER_BASE, SPI_IER_NSSR | SPI_IER_RXBUFF);
NVIC_DisableIRQ(SPI_IRQn);
//irq_register_handler(SPI_IRQn, 3);
NVIC_ClearPendingIRQ(SPI_IRQn);
NVIC_SetPriority(SPI_IRQn, 3);
NVIC_EnableIRQ(SPI_IRQn);
spi_enable(SPI_MASTER_BASE);
#else
spi.baudrate = SPI_BAUD_RATE;
if (STATUS_OK != spi_master_vec_init(&spi_master, SPI_MASTER_BASE, &spi)) {
return -1;
}
spi_master_vec_enable(&spi_master);
#endif
//if (!Is_global_interrupt_enabled())
// Enable_global_interrupt();
platform_mcu_powersave_enable();
return kNoErr;
}
示例7: radio_init
void radio_init (uint8_t channel)
{
/* Enable power to RADIO */
NRF_RADIO->POWER = 1;
/* Set radio transmit power to 0dBm */
NRF_RADIO->TXPOWER = (RADIO_TXPOWER_TXPOWER_0dBm << RADIO_TXPOWER_TXPOWER_Pos);
/* Set radio mode to 1Mbit/s Bluetooth Low Energy */
NRF_RADIO->MODE = (RADIO_MODE_MODE_Ble_1Mbit << RADIO_MODE_MODE_Pos);
/* Set the requested channel */
NRF_RADIO->FREQUENCY = channel_resolver_get_frequency(channel);
/* This value needs to correspond to the channel being used */
NRF_RADIO->DATAWHITEIV = channel;
/* Configure Access Address according to the BLE standard */
NRF_RADIO->PREFIX0 = 0x8e;
NRF_RADIO->BASE0 = 0x89bed600;
/* Use logical address 0 (prefix0 + base0) = 0x8E89BED6 when transmitting and receiving */
NRF_RADIO->TXADDRESS = 0x00;
NRF_RADIO->RXADDRESSES = 0x01;
/* PCNF-> Packet Configuration.
* We now need to configure the sizes S0, S1 and length field to match the
* datapacket format of the advertisement packets.
*/
NRF_RADIO->PCNF0 = (
(((1UL) << RADIO_PCNF0_S0LEN_Pos) & RADIO_PCNF0_S0LEN_Msk) | /* Length of S0 field in bytes 0-1. */
(((2UL) << RADIO_PCNF0_S1LEN_Pos) & RADIO_PCNF0_S1LEN_Msk) | /* Length of S1 field in bits 0-8. */
(((6UL) << RADIO_PCNF0_LFLEN_Pos) & RADIO_PCNF0_LFLEN_Msk) /* Length of length field in bits 0-8. */
);
/* Packet configuration */
NRF_RADIO->PCNF1 = (
(((37UL) << RADIO_PCNF1_MAXLEN_Pos) & RADIO_PCNF1_MAXLEN_Msk) | /* Maximum length of payload in bytes [0-255] */
(((0UL) << RADIO_PCNF1_STATLEN_Pos) & RADIO_PCNF1_STATLEN_Msk) | /* Expand the payload with N bytes in addition to LENGTH [0-255] */
(((3UL) << RADIO_PCNF1_BALEN_Pos) & RADIO_PCNF1_BALEN_Msk) | /* Base address length in number of bytes. */
(((RADIO_PCNF1_ENDIAN_Little) << RADIO_PCNF1_ENDIAN_Pos) & RADIO_PCNF1_ENDIAN_Msk) | /* Endianess of the S0, LENGTH, S1 and PAYLOAD fields. */
(((1UL) << RADIO_PCNF1_WHITEEN_Pos) & RADIO_PCNF1_WHITEEN_Msk) /* Enable packet whitening */
);
/* CRC config */
NRF_RADIO->CRCCNF = (RADIO_CRCCNF_LEN_Three << RADIO_CRCCNF_LEN_Pos) |
(RADIO_CRCCNF_SKIPADDR_Skip << RADIO_CRCCNF_SKIPADDR_Pos); /* Skip Address when computing CRC */
NRF_RADIO->CRCINIT = 0x555555; /* Initial value of CRC */
NRF_RADIO->CRCPOLY = 0x00065B; /* CRC polynomial function */
/* Clear events */
NRF_RADIO->EVENTS_DISABLED = 0;
NRF_RADIO->EVENTS_END = 0;
NRF_RADIO->EVENTS_READY = 0;
NRF_RADIO->EVENTS_ADDRESS = 0;
/* Enable interrupt on events */
NRF_RADIO->INTENSET = RADIO_INTENSET_ADDRESS_Msk | RADIO_INTENSET_DISABLED_Msk;
/* Enable RADIO interrupts */
NVIC_ClearPendingIRQ(RADIO_IRQn);
NVIC_EnableIRQ(RADIO_IRQn);
m_radio_dir = RADIO_DIR_NONE;
}
示例8: platform_uart_init
platform_result_t platform_uart_init( platform_uart_driver_t* driver, const platform_uart_t* interface, const platform_uart_config_t* config, wiced_ring_buffer_t* optional_ring_buffer )
{
uint32_t uart_number;
UART_FIFO_CFG_T UARTFIFOConfigStruct;
config_uart_data_t config_uart_data;
wiced_assert( "bad argument", ( driver != NULL ) && ( interface != NULL ) && ( config != NULL ) );
Chip_Clock_EnablePeriphClock( SYSCTL_CLOCK_UART0 );
uart_number = platform_uart_get_port_number(interface->uart_base);
driver->rx_size = 0;
driver->tx_size = 0;
driver->last_transmit_result = PLATFORM_SUCCESS;
driver->last_receive_result = PLATFORM_SUCCESS;
driver->interface = (platform_uart_t*)interface;
host_rtos_init_semaphore( &driver->tx_complete );
host_rtos_init_semaphore( &driver->rx_complete );
platform_gpio_set_alternate_function( &driver->interface->tx_pin);
platform_gpio_set_alternate_function( &driver->interface->rx_pin);
/* Initialise USART peripheral */
Chip_UART_FIFOConfigStructInit( driver->interface->uart_base, &UARTFIFOConfigStruct );
Chip_UART_Init( driver->interface->uart_base );
Chip_UART_SetBaud( driver->interface->uart_base, config->baud_rate );
config_uart_data.databits = ( ( config->data_width == DATA_WIDTH_8BIT ) || ( ( config->data_width == DATA_WIDTH_7BIT ) && ( config->parity != NO_PARITY ) ) ) ? UART_DATABIT_8 : UART_DATABIT_7;
config_uart_data.stopbits = ( config->stop_bits == STOP_BITS_1 ) ? UART_STOPBIT_1 : UART_STOPBIT_2;
switch ( config->parity )
{
case NO_PARITY:
config_uart_data.parity = UART_PARITY_NONE;
break;
case EVEN_PARITY:
config_uart_data.parity = UART_PARITY_EVEN;
break;
case ODD_PARITY:
config_uart_data.parity = UART_PARITY_ODD;
break;
default:
return WICED_BADARG;
}
Chip_UART_ConfigData( driver->interface->uart_base, config_uart_data.databits, config_uart_data.parity, config_uart_data.stopbits );
Chip_UART_TxCmd( driver->interface->uart_base, ENABLE );
/* Enable receive data and line status interrupt */
/* Initialize FIFO for UART0 peripheral */
Chip_UART_FIFOConfig( driver->interface->uart_base, &UARTFIFOConfigStruct );
/* Enable UART Rx interrupt */
Chip_UART_IntConfig( driver->interface->uart_base, UART_INTCFG_RBR, ENABLE );
/* Enable UART line status interrupt */
Chip_UART_IntConfig( driver->interface->uart_base, UART_INTCFG_RLS, ENABLE );
/* Enable Interrupt for UART channel */
NVIC_DisableIRQ( uart_irq_vectors[ uart_number ] );
NVIC_ClearPendingIRQ( uart_irq_vectors[ uart_number ] );
/*Note the LPC uses 5 bits for interrupt priority levels*/
NVIC_EnableIRQ( uart_irq_vectors[ uart_number ] );
if ( optional_ring_buffer != NULL )
{
/* Note that the ring_buffer should've been initialised first */
driver->rx_buffer = optional_ring_buffer;
driver->rx_size = 0;
}
return PLATFORM_SUCCESS;
}
示例9: wifi_init
int wifi_init(void){
uint32_t BUF_SIZE = MD_BUF_SIZE;
uint8_t tmp; //dummy var for flushing UART
int r; //return value from wifi_send_cmd (length of resp)
char *buf;
char *tx_buf;
//allocate static buffers if they are not NULL
if(resp_buf==NULL){
resp_buf=core_malloc(RESP_BUF_SIZE);
}
if(resp_complete_buf==NULL){
resp_complete_buf=core_malloc(RESP_COMPLETE_BUF_SIZE);
}
if(wifi_rx_buf==NULL){
wifi_rx_buf = core_malloc(WIFI_RX_BUF_SIZE);
}
//if we are standalone, don't do anything
if(wemo_config.standalone){
printf("warning: wifi_init called in standalone mode\n");
return 0;
}
//initialize the memory
buf = core_malloc(BUF_SIZE);
tx_buf = core_malloc(BUF_SIZE);
//set up the UART
static usart_serial_options_t usart_options = {
.baudrate = WIFI_UART_BAUDRATE,
.charlength = WIFI_UART_CHAR_LENGTH,
.paritytype = WIFI_UART_PARITY,
.stopbits = WIFI_UART_STOP_BITS
};
gpio_configure_pin(PIO_PA9_IDX, (PIO_PERIPH_A | PIO_DEFAULT));
gpio_configure_pin(PIO_PA10_IDX, (PIO_PERIPH_A | PIO_DEFAULT));
pmc_enable_periph_clk(ID_WIFI_UART);
sysclk_enable_peripheral_clock(ID_WIFI_UART);
usart_serial_init(WIFI_UART,&usart_options);
//flush any existing data
while(usart_serial_is_rx_ready(WIFI_UART)){
usart_serial_getchar(WIFI_UART,&tmp);
}
// Trigger from timer 0
pmc_enable_periph_clk(ID_TC0);
tc_init(TC0, 0, // channel 0
TC_CMR_TCCLKS_TIMER_CLOCK5 // source clock (CLOCK5 = Slow Clock)
| TC_CMR_CPCTRG // up mode with automatic reset on RC match
| TC_CMR_WAVE // waveform mode
| TC_CMR_ACPA_CLEAR // RA compare effect: clear
| TC_CMR_ACPC_SET // RC compare effect: set
);
TC0->TC_CHANNEL[0].TC_RA = 0; // doesn't matter
TC0->TC_CHANNEL[0].TC_RC = 64000; // sets frequency: 32kHz/32000 = 1 Hz
NVIC_ClearPendingIRQ(TC0_IRQn);
NVIC_SetPriority(TC0_IRQn,1);//high priority
NVIC_EnableIRQ(TC0_IRQn);
tc_enable_interrupt(TC0, 0, TC_IER_CPCS);
//reset the module
if(wifi_send_cmd("AT+RST","ready",buf,BUF_SIZE,8)==0){
printf("Error reseting ESP8266\n");
//free memory
core_free(buf);
core_free(tx_buf);
return -1;
}
//set to mode STA
if(wifi_send_cmd("AT+CWMODE=1","OK",buf,BUF_SIZE,8)==0){
printf("Error setting ESP8266 mode\n");
core_free(buf);
core_free(tx_buf);
return 0;
}
//try to join the specified network
snprintf(tx_buf,BUF_SIZE,"AT+CWJAP=\"%s\",\"%s\"",
wemo_config.wifi_ssid,wemo_config.wifi_pwd);
if((r=wifi_send_cmd(tx_buf,"OK",buf,BUF_SIZE,10))==0){
printf("no response to CWJAP\n");
//free memory
core_free(buf);
core_free(tx_buf);
return -1;
}
//check for errors
if( (r<1) || (strcmp(&buf[r-1],"OK")!=0)){
snprintf(tx_buf,BUF_SIZE,"failed to join network [%s]: [%s]\n",wemo_config.wifi_ssid, buf);
printf(tx_buf);
core_log(tx_buf);
//free memory
core_free(buf);
core_free(tx_buf);
return -1;
}
//see if we have an IP address
wifi_send_cmd("AT+CIFSR","OK",buf,BUF_SIZE,5);
if(strstr(buf,"ERROR")==buf){
printf("error getting IP address\n");
//free the memory
core_free(tx_buf);
core_free(buf);
return -1;
//.........这里部分代码省略.........
示例10: Board_Attach_Interrupt
void Board_Attach_Interrupt(uint32_t ulPin, void (*callback)(void), uint32_t mode)
{
uint8_t port = 1;
uint8_t pin = 24;
uint8_t pinIntChannel = 0;
LPC1347_IRQn_Type pinIntIRQ = PIN_INT0_IRQn;
port = APIN_PORT(ulPin);
pin = APIN_PIN(ulPin);
pinIntChannel = APIN_INT(ulPin);
if(pinIntChannel == EXT_INT_0)
{
pinIntIRQ = PIN_INT0_IRQn;
callbackPinIntA = callback;
}
else if(pinIntChannel == EXT_INT_1)
{
pinIntIRQ = PIN_INT1_IRQn;
callbackPinIntB = callback;
}
else if(pinIntChannel == EXT_INT_2)
{
pinIntIRQ = PIN_INT2_IRQn;
callbackPinIntC = callback;
}
else if(pinIntChannel == EXT_INT_3)
{
pinIntIRQ = PIN_INT3_IRQn;
callbackPinIntD = callback;
}
/* Configure GPIO pin as input */
Chip_GPIO_SetPinDIRInput(LPC_GPIO_PORT, port, pin);
/* Configure pin as GPIO with pulldown */
// All digital pins are selected such that GPIO is on IOCON_FUNC0
Chip_IOCON_PinMuxSet(LPC_IOCON, port, pin, (IOCON_FUNC0 | IOCON_MODE_PULLDOWN));
/* Enable PININT clock */
Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_PINT);
/* Configure interrupt channel for the GPIO pin in SysCon block */
Chip_SYSCTL_SetPinInterrupt(pinIntChannel, port, pin);
/* Configure channel interrupt as edge sensitive and falling edge interrupt */
Chip_PININT_ClearIntStatus(LPC_PININT, PININTCH(pinIntChannel));
if(mode == HIGH)
{
Chip_PININT_SetPinModeLevel(LPC_PININT, PININTCH(pinIntChannel));
Chip_PININT_EnableIntHigh(LPC_PININT, PININTCH(pinIntChannel));
}
else if(mode == LOW)
{
Chip_PININT_SetPinModeLevel(LPC_PININT, PININTCH(pinIntChannel));
Chip_PININT_EnableIntLow(LPC_PININT, PININTCH(pinIntChannel));
}
else if(mode == RISING)
{
Chip_PININT_SetPinModeEdge(LPC_PININT, PININTCH(pinIntChannel));
Chip_PININT_EnableIntHigh(LPC_PININT, PININTCH(pinIntChannel));
}
else if(mode == FALLING)
{
Chip_PININT_SetPinModeEdge(LPC_PININT, PININTCH(pinIntChannel));
Chip_PININT_EnableIntLow(LPC_PININT, PININTCH(pinIntChannel));
}
else if(mode == CHANGE)
{
Chip_PININT_SetPinModeEdge(LPC_PININT, PININTCH(pinIntChannel));
Chip_PININT_EnableIntHigh(LPC_PININT, PININTCH(pinIntChannel));
Chip_PININT_EnableIntLow(LPC_PININT, PININTCH(pinIntChannel));
}
/* Enable interrupt in the NVIC */
NVIC_ClearPendingIRQ(pinIntIRQ);
NVIC_EnableIRQ(pinIntIRQ);
}
示例11: SPI1_IRQHandler
void SPI1_IRQHandler(void)
#endif
{
mss_spi_isr(&g_mss_spi1);
NVIC_ClearPendingIRQ(SPI1_IRQn);
}
示例12: NVIC_ClearPendingIRQ
/***************************************************************************//**
* This function works around SAR28498 where receive overflows were not cleared
* properly. This is due to the receive FIFO counters getting out of synch when
* a receive overflow occurs. This can only be cleared on the A2F200 by
* resetting the SPI block.
*/
static void recover_from_rx_overflow
(
mss_spi_instance_t * this_spi
)
{
uint32_t control_reg;
uint32_t clk_gen;
uint32_t frame_size;
uint32_t control2;
uint32_t packet_size;
uint32_t cmd_size;
uint32_t slave_select;
/*
* Read current SPI hardware block configuration.
*/
control_reg = this_spi->hw_reg->CONTROL;
clk_gen = this_spi->hw_reg->CLK_GEN;
frame_size = this_spi->hw_reg->TXRXDF_SIZE;
control2 = this_spi->hw_reg->CONTROL2;
packet_size = this_spi->hw_reg->PKTSIZE;
cmd_size = this_spi->hw_reg->CMDSIZE;
slave_select = this_spi->hw_reg->SLAVE_SELECT;
/*
* Reset the SPI hardware block.
*/
if(this_spi == &g_mss_spi0)
{
this_spi->hw_reg = ((SPI_REVB_TypeDef *) SPI0_BASE);
this_spi->irqn = SPI0_IRQn;
/* reset SPI0 */
SYSREG->SOFT_RST_CR |= SYSREG_SPI0_SOFTRESET_MASK;
/* Clear any previously pended SPI0 interrupt */
NVIC_ClearPendingIRQ(SPI0_IRQn);
/* Take SPI0 out of reset. */
SYSREG->SOFT_RST_CR &= ~SYSREG_SPI0_SOFTRESET_MASK;
this_spi->hw_reg->CONTROL &= ~CTRL_REG_RESET_MASK;
}
else
{
this_spi->hw_reg = ((SPI_REVB_TypeDef *) SPI1_BASE);
this_spi->irqn = SPI1_IRQn;
/* reset SPI1 */
SYSREG->SOFT_RST_CR |= SYSREG_SPI1_SOFTRESET_MASK;
/* Clear any previously pended SPI1 interrupt */
NVIC_ClearPendingIRQ(SPI1_IRQn);
/* Take SPI1 out of reset. */
SYSREG->SOFT_RST_CR &= ~SYSREG_SPI1_SOFTRESET_MASK;
this_spi->hw_reg->CONTROL &= ~CTRL_REG_RESET_MASK;
}
/*
* Restore SPI hardware block configuration.
*/
this_spi->hw_reg->CONTROL &= ~(uint32_t)CTRL_ENABLE_MASK;
this_spi->hw_reg->CONTROL = control_reg;
this_spi->hw_reg->CLK_GEN = clk_gen;
this_spi->hw_reg->TXRXDF_SIZE = frame_size;
this_spi->hw_reg->CONTROL |= CTRL_ENABLE_MASK;
this_spi->hw_reg->CONTROL2 = control2;
this_spi->hw_reg->PKTSIZE = packet_size;
this_spi->hw_reg->CMDSIZE = cmd_size;
this_spi->hw_reg->SLAVE_SELECT = slave_select;
}
示例13: pmc_enable_periph_clk
void ADCSampler::begin(unsigned int samplingRate)
{
this->sampleingRate = sampleingRate;
// Turning devices Timer on.
pmc_enable_periph_clk(ID_TC0);
// Configure timer
TC_Configure(TC0, 0, TC_CMR_WAVE | TC_CMR_WAVSEL_UP_RC | TC_CMR_ACPA_CLEAR | TC_CMR_ACPC_SET | TC_CMR_ASWTRG_CLEAR | TC_CMR_TCCLKS_TIMER_CLOCK1);
// It is good to have the timer 0 on PIN2, good for Debugging
//int result = PIO_Configure( PIOB, PIO_PERIPH_B, PIO_PB25B_TIOA0, PIO_DEFAULT);
// Configure ADC pin A7
// the below code is taken from adc_init(ADC, SystemCoreClock, ADC_FREQ_MAX, ADC_STARTUP_FAST);
ADC->ADC_CR = ADC_CR_SWRST; // Reset the controller.
ADC->ADC_MR = 0; // Reset Mode Register.
ADC->ADC_PTCR = (ADC_PTCR_RXTDIS | ADC_PTCR_TXTDIS); // Reset PDC transfer.
ADC->ADC_MR |= ADC_MR_PRESCAL(3); // ADC clock = MSCK/((PRESCAL+1)*2), 13 -> 750000 Sps
ADC->ADC_MR |= ADC_MR_STARTUP_SUT0; // What is this by the way?
ADC->ADC_MR |= ADC_MR_TRACKTIM(15);
ADC->ADC_MR |= ADC_MR_TRANSFER(1);
ADC->ADC_MR |= ADC_MR_TRGEN_EN; // Hardware trigger selected by TRGSEL field is enabled. Включен аппаратный триггер, выбранный по полю TRGSEL.
ADC->ADC_MR |= ADC_MR_TRGSEL_ADC_TRIG1; // selecting TIOA0 as trigger.
ADC->ADC_MR |= ADC_MR_LOWRES_BITS_12; // brief (ADC_MR) 12-bit resolution
//ADC->ADC_ACR |= ADC_ACR_TSON; // Включить датчик температуры
ADC->ADC_CHER = ADC_CHANNELS; // Записать контролируемые входа
ADC->ADC_CHDR = ADC_CHANNELS_DIS; // Отключить не используемые входа
ADC->ADC_EMR = ADC_EMR_CMPMODE_IN // Генерирует событие, когда преобразованные данные пересекают окно сравнения.
// | ADC_EMR_CMPSEL(4) // Compare channel 4 = A3
| ADC_EMR_CMPALL // Compare ALL channel
| ADC_EMR_CMPFILTER(0); // Количество последовательных событий сравнения, необходимых для повышения флага = CMPFILTER + 1
// При запрограммированном значении 0 флаг увеличивается, как только происходит событие.
ADC->ADC_CWR = ADC_CWR_LOWTHRES(_compare_Low) | ADC_CWR_HIGHTHRES(_compare_High); // Установить высокий и низкий порог компаратора АЦП
//ADC->ADC_SEQR1 = 0x01234567; // использовать A0 до A7 в порядке в массив
//ADC->ADC_SEQR2 = 0x00dcba00; // использовать для А8 А11 следующие действия по порядку в массив
/* Interupts */
ADC->ADC_IDR = ~ADC_IDR_ENDRX; // сбросить регистры прерывания по готовности данных.
ADC->ADC_IDR = ~ADC_IDR_COMPE; // сбросить регистры копаратора.
ADC->ADC_IER = ADC_IER_ENDRX; // Включить прерывание по готовности данных.
// ADC->ADC_IER = ADC_IER_COMPE; // Прерывание по совпадению сравнения компаратором
ADC->ADC_ISR = ~ADC_ISR_COMPE; // ADC Interrupt Status Register Обнулить ошибку сравнения с момента последнего чтения ADC_ISR.
/* Waiting for ENDRX as end of the transfer is set
when the current DMA transfer is done (RCR = 0), i.e. it doesn't include the
next DMA transfer.
If we trigger on RXBUFF This flag is set if there is no more DMA transfer in
progress (RCR = RNCR = 0). Hence we may miss samples.
Ожидание окончания ENDRX в конце передачи
когда выполняется текущая передача DMA (RCR = 0), то есть она не включает следующая передача DMA.
Если мы запускаем RXBUFF, этот флаг устанавливается, если больше нет передачи DMA в прогресс (RCR = RNCR = 0).
Следовательно, мы можем пропустить образцы.
*/
unsigned int cycles = 42000000 / samplingRate;
/* timing of ADC */
TC_SetRC(TC0, 0, cycles); // TIOA0 goes HIGH on RC.
TC_SetRA(TC0, 0, cycles / 2); // TIOA0 goes LOW on RA.
// We have to reinitalise just in case the Sampler is stopped and restarted...
// Мы должны приступить к реинициализировать на случай, если Sampler остановлен и перезапущен ...
dataReady = false;
dataHigh = false; // Признак срабатывания компаратора
adcDMAIndex = 0;
adcTransferIndex = 0;
for (int i = 0; i < NUMBER_OF_BUFFERS; i++)
{
memset((void *)adcBuffer[i], 0, BUFFER_SIZE);
}
ADC->ADC_RPR = (unsigned long) adcBuffer[adcDMAIndex]; // DMA buffer
ADC->ADC_RCR = (unsigned int) BUFFER_SIZE; // ADC works in half-word mode.
ADC->ADC_RNPR = (unsigned long) adcBuffer[(adcDMAIndex + 1)]; // next DMA buffer
ADC->ADC_RNCR = (unsigned int) BUFFER_SIZE;
// Enable interrupts
NVIC_SetPriorityGrouping(NVIC_PriorityGroup_1);
NVIC_DisableIRQ(ADC_IRQn);
NVIC_ClearPendingIRQ(ADC_IRQn);
NVIC_SetPriority(ADC_IRQn, 6);
NVIC_EnableIRQ(ADC_IRQn);
ADC->ADC_PTCR = ADC_PTCR_RXTEN; // Enable receiving data.
ADC->ADC_CR |= ADC_CR_START; // start waiting for trigger.
// Start timer
TC0->TC_CHANNEL[0].TC_SR;
TC0->TC_CHANNEL[0].TC_CCR = TC_CCR_CLKEN;
TC_Start(TC0, 0);
}
示例14: main
/**************************************************************************//**
* @brief Main function
*****************************************************************************/
int main(void)
{
unsigned char pucMACArray[8];
uint32_t temp;
/* Chip revision alignment and errata fixes */
CHIP_Init();
/* Ensure core frequency has been updated */
SystemCoreClockUpdate();
CMU_ClockEnable(cmuClock_ADC0, true);
/* Setup SysTick Timer for 1 msec interrupts */
if (SysTick_Config(SystemCoreClock / 1000)) while (1) ;
/* Setup ADC for sampling internal temperature sensor. */
setupSensor();
/* Spi init*/
spiInit();
#if LWIP_DHCP
/* Initialze the lwIP library, using DHCP.*/
lwIPInit(pucMACArray, 0, 0, 0, IPADDR_USE_DHCP);
#else
/* Initialze the lwIP library, using Static IP.*/
lwIPInit(pucMACArray, IPADDR(192, 168, 79, 160), IPADDR(255, 255, 255, 0), \
IPADDR(192, 168, 79, 1), IPADDR_USE_STATIC);
#endif
/* Initialize a sample httpd server.*/
httpd_init();
/* Start one ADC sample */
ADC_Start(ADC0, adcStartSingle);
/* Enable board control interrupts */
gpioSetup();
axspi_write_reg(~IMR_RXPKT, P0_IMR);
/* Start LCD without boost */
SegmentLCD_Init(false);
CMU_ClockEnable(cmuClock_RTC, true);
/* RTC configuration structure */
RTC_Init_TypeDef rtcInit = {
.enable = false,
.debugRun = false,
.comp0Top = true
};
/* Initialize RTC */
RTC_Init(&rtcInit);
/* Set COMP0 value which will be the top value as well */
RTC_CompareSet(RTC_COMP, RTC_COMP_VALUE);
/* Clear all pending interrupts */
RTC_IntClear(0x7);
/* Enable COMP0 interrupts */
RTC_IntEnable(0x2);
/* Enable interrupts */
NVIC_ClearPendingIRQ(RTC_IRQn);
NVIC_EnableIRQ(RTC_IRQn);
RTC_Enable(true);
while (1)
{
/* check temperature flag*/
if (read_temperature)
{
temp = ADC_DataSingleGet(ADC0);
/* Show Celsius on numeric part of display */
temperature = (int)(convertToCelsius(temp));
/* Start a new conversion */
ADC_Start(ADC0, adcStartSingle);
/* Reset temperature flag */
read_temperature = 0;
}
if (updateIpFlag)
{
switch (ip_field)
{
case 1:
{
SegmentLCD_Write(IP_ADDR_FIRST_TEXT);
SegmentLCD_Number(IP_ADDR_FIRST_NUM(lwip_netif.ip_addr.addr));
ip_field++;
//.........这里部分代码省略.........
示例15: radio_init
int16_t radio_init(void)
{
if (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0UL) {
NRF_CLOCK->TASKS_HFCLKSTART = 1UL;
while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0UL);
}
/* nRF51 Series Reference Manual v2.1, section 6.1.1, page 18
* PCN-083 rev.1.1
*
* Fine tune BLE deviation parameters.
*/
if ((NRF_FICR->OVERRIDEEN & FICR_OVERRIDEEN_BLE_1MBIT_Msk)
== (FICR_OVERRIDEEN_BLE_1MBIT_Override
<< FICR_OVERRIDEEN_BLE_1MBIT_Pos)) {
NRF_RADIO->OVERRIDE0 = NRF_FICR->BLE_1MBIT[0];
NRF_RADIO->OVERRIDE1 = NRF_FICR->BLE_1MBIT[1];
NRF_RADIO->OVERRIDE2 = NRF_FICR->BLE_1MBIT[2];
NRF_RADIO->OVERRIDE3 = NRF_FICR->BLE_1MBIT[3];
NRF_RADIO->OVERRIDE4 = NRF_FICR->BLE_1MBIT[4] | 0x80000000;
}
/* nRF51 Series Reference Manual v2.1, section 16.2.7, page 86 */
NRF_RADIO->MODE = RADIO_MODE_MODE_Ble_1Mbit << RADIO_MODE_MODE_Pos;
/* Link Layer specification section 4.1, Core 4.1, page 2524
* nRF51 Series Reference Manual v2.1, section 16.2.7, page 92
*
* Set the inter frame space (T_IFS) to 150 us.
*/
NRF_RADIO->TIFS = 150;
/* nRF51 Series Reference Manual v2.1, section 16.2.9, page 88
*
* Enable data whitening, set the maximum payload length and set the
* access address size (3 + 1 octets).
*/
NRF_RADIO->PCNF1 =
(RADIO_PCNF1_WHITEEN_Enabled << RADIO_PCNF1_WHITEEN_Pos) |
(MAX_PAYLOAD_LEN << RADIO_PCNF1_MAXLEN_Pos) |
(3UL << RADIO_PCNF1_BALEN_Pos);
/* nRF51 Series Reference Manual v2.1, section 16.1.4, page 74
* nRF51 Series Reference Manual v2.1, section 16.2.14-15, pages 89-90
*
* Preset the address to use when receive and transmit packets (logical
* address 0, which is assembled by base address BASE0 and prefix byte
* PREFIX0.AP0.
*/
NRF_RADIO->RXADDRESSES = 1UL;
NRF_RADIO->TXADDRESS = 0UL;
/* nRF51 Series Reference Manual v2.1, section 16.1.7, page 76
* nRF51 Series Reference Manual v2.1, sections 16.1.16-17, page 90
*
* Configure the CRC length (3 octets), polynominal and set it to
* ignore the access address when calculate the CRC.
*/
NRF_RADIO->CRCCNF =
(RADIO_CRCCNF_LEN_Three << RADIO_CRCCNF_LEN_Pos) |
(RADIO_CRCCNF_SKIP_ADDR_Skip << RADIO_CRCCNF_SKIP_ADDR_Pos);
NRF_RADIO->CRCPOLY = 0x100065B;
/* nRF51 Series Reference Manual v2.1, section 16.1.2, page 74
* nRF51 Series Reference Manual v2.1, sections 16.1.8, page 87
* Link Layer specification section 2.3, Core 4.1, page 2504
* Link Layer specification section 2.4, Core 4.1, page 2511
*
* Configure the header size. The nRF51822 has 3 fields before the
* payload field: S0, LENGTH and S1. These fields can be used to store
* the PDU header.
*/
NRF_RADIO->PCNF0 = (1UL << RADIO_PCNF0_S0LEN_Pos)
| (8UL << RADIO_PCNF0_LFLEN_Pos)
| (0UL << RADIO_PCNF0_S1LEN_Pos);
/* nRF51 Series Reference Manual v2.1, section 16.1.8, page 76
* nRF51 Series Reference Manual v2.1, section 16.1.10-11, pages 78-80
* nRF51 Series Reference Manual v2.1, section 16.2.1, page 85
*
* Enable READY_START short: when the READY event happens, initialize
* the START task.
*
* Enable END_DISABLE short: when the END event happens, initialize the
* DISABLE task.
*/
NRF_RADIO->SHORTS = BASE_SHORTS;
/* Trigger RADIO interruption when an END event happens */
NRF_RADIO->INTENSET = RADIO_INTENSET_END_Msk;
NVIC_SetPriority(RADIO_IRQn, IRQ_PRIORITY_HIGH);
NVIC_ClearPendingIRQ(RADIO_IRQn);
NVIC_EnableIRQ(RADIO_IRQn);
radio_set_callbacks(NULL, NULL);
radio_set_tx_power(RADIO_POWER_0_DBM);
radio_set_out_buffer(NULL);
NRF_RADIO->PACKETPTR = (uint32_t) inbuf;
//.........这里部分代码省略.........