void vInitialiseTimerForIntQueueTest( void ) { /* Enable the TC clocks. */ pmc_enable_peripheral( ID_TC0 ); pmc_enable_peripheral( ID_TC1 ); /* Configure TC0 channel 0 for a tmrTIMER_0_FREQUENCY frequency and trigger on RC compare. */ tc_trigger_on_freq( TC0, tmrTC0_CHANNEL_0, tmrTIMER_0_FREQUENCY ); TC0->TC_CHANNEL[ tmrTC0_CHANNEL_0 ].TC_IER = TC_IER_CPCS; /* Configure TC0 channel 1 for a tmrTIMER_1_FREQUENCY frequency and trigger on RC compare. */ tc_trigger_on_freq( TC0, tmrTC0_CHANNEL_1, tmrTIMER_1_FREQUENCY ); TC0->TC_CHANNEL[ tmrTC0_CHANNEL_1 ].TC_IER = TC_IER_CPCS; /* Configure TC1 channel 0 tmrTIMER_2_FREQUENCY frequency and trigger on RC compare. */ tc_trigger_on_freq( TC1, tmrTC1_CHANNEL_0, tmrTIMER_2_FREQUENCY ); TC1->TC_CHANNEL[ tmrTC1_CHANNEL_0 ].TC_IER = TC_IER_CPCS; /* Enable interrupts and start the timers. */ aic_configure( ID_TC0, tmrLOWER_PRIORITY ); aic_set_source_vector( ID_TC0, prvTC0_Handler ); aic_configure( ID_TC1, tmrHIGHER_PRIORITY ); aic_set_source_vector( ID_TC1, prvTC1_Handler ); aic_enable( ID_TC0 ); aic_enable( ID_TC1 ); tc_start( TC0, tmrTC0_CHANNEL_0 ); tc_start( TC0, tmrTC0_CHANNEL_1 ); tc_start( TC1, tmrTC1_CHANNEL_0 ); }
void xdmad_initialize(bool polling) { uint32_t cont, chan; _xdmad.polling = polling; for (cont = 0; cont < XDMAC_CONTROLLERS; cont++) { Xdmac* xdmac = xdmac_get_instance(cont); for (chan = 0; chan < XDMAC_CHANNELS; chan++) { xdmac_get_channel_isr(xdmac, chan); struct _xdmad_channel *channel = _xdmad_channel(cont, chan); channel->xdmac = xdmac; channel->id = chan; channel->callback = 0; channel->user_arg = 0; channel->src_txif = 0; channel->src_rxif = 0; channel->dest_txif = 0; channel->dest_rxif = 0; channel->state = XDMAD_STATE_FREE; } if (!polling) { uint32_t pid = xdmac_get_periph_id(xdmac); /* enable interrupts */ aic_set_source_vector(pid, xdmad_handler); aic_enable(pid); } } }
/** * Configure USART to work @ 115200 */ static void _configure_usart(void) { Usart* usart = usart_desc.addr; uint32_t id = get_usart_id_from_addr(usart); /* Driver initialize */ xdmad_initialize(0); usartd_configure(&usart_desc); pio_configure(usart_pins, ARRAY_SIZE(usart_pins)); usart_enable_it(usart, US_IER_RXRDY); aic_set_source_vector(id, usart_irq_handler); aic_enable(id); }
/** * \brief Init Usart COM2 master. */ static void _init_com_master (void) { uint32_t id = get_usart_id_from_addr(lin_desc2.addr); /* Configure Pios usart*/ pio_configure(&pins_com2[0], ARRAY_SIZE(pins_com2)); /* Init LIN MASTER data Node 0 */ lin_init(&lin_desc2, LIN_MASTER_NODE_NUM); /* Configure interrupts */ usart_enable_it(lin_desc2.addr, US_IER_LINTC); aic_set_source_vector(id, _com2_master_handler); }
/** * \brief Init Usart COM3 slave. */ static void _init_com_slave (void) { uint32_t id = get_usart_id_from_addr(lin_desc3.addr); /* Configure Pios usart*/ pio_configure(&pins_com3[0], ARRAY_SIZE(pins_com3)); /* Init LIN SLAVE data Node 0 */ lin_init(&lin_desc3, LIN_SLAVE_NODE_NUM); /* Configure interrupts */ usart_enable_it(lin_desc3.addr, US_IER_LINID); aic_set_source_vector(id, _com3_slave_handler); aic_enable(id); }
/** * Configure Timer Counter 0 to generate an interrupt every 250ms. */ static void _configure_tc(void) { /** Enable peripheral clock. */ pmc_enable_peripheral(ID_TC0); /* Put the source vector */ aic_set_source_vector(ID_TC0, _tc_handler); /** Configure TC for a 50Hz frequency and trigger on RC compare. */ tc_trigger_on_freq(TC0, TC_CHANNEL, TC_FREQ); /* Configure and enable interrupt on RC compare */ tc_enable_it(TC0, TC_CHANNEL, TC_IER_CPCS); aic_enable(ID_TC0); }
/** * \brief Configure RTC for test * \Set alarm ewery second */ void configure_rtc (void) { uint32_t status; struct _time MTU = {00, 00, 00}; struct _time MTA = {18, 30, 00}; struct _date MDT = {2015, 06, 01, 1}; rtc_set_hour_mode(0); // mode 24h status = rtc_set_time(&MTU); status |= rtc_set_date(&MDT); status |= rtc_set_time_alarm(&MTA); status |= rtc_set_time_event (RTC_CR_TIMEVSEL_MINUTE); rtc_disable_it (RTC_IER_ACKEN | RTC_IER_ALREN | RTC_IER_SECEN | RTC_IER_TIMEN | RTC_IER_CALEN); rtc_enable_it (RTC_IER_SECEN); aic_set_source_vector(ID_SYSC, rtc_irq_handler); aic_enable(ID_SYSC); }
/** * \brief Initialize the GMAC with the Gmac controller address * \param gmacd Pointer to GMAC Driver instance. * \param gmac Pointer to HW address for registers. * \param enableCAF Enable/Disable CopyAllFrame. * \param enableNBC Enable/Disable NoBroadCast. */ void gmacd_configure(struct _gmacd * gmacd, Gmac * gmac, uint8_t enableCAF, uint8_t enableNBC) { uint32_t ncfgr; int i; /* Initialize struct */ gmacd->gmac = gmac; gmac_configure(gmac); uint32_t id = get_gmac_id_from_addr(gmac); for (i = 0; i < ARRAY_SIZE(_gmacd_irq_handlers); i++) { if (_gmacd_irq_handlers[i].addr == gmac) { *_gmacd_irq_handlers[i].gmacd = gmacd; aic_set_source_vector(_gmacd_irq_handlers[i].irq, _gmacd_irq_handlers[i].handler); } } aic_enable(id); /* Enable the copy of data into the buffers ignore broadcasts, and don't copy FCS. */ ncfgr = gmac_get_network_config_register(gmac); ncfgr |= GMAC_NCFGR_FD; if (enableCAF) { ncfgr |= GMAC_NCFGR_CAF; } if (enableNBC) { ncfgr |= GMAC_NCFGR_NBC; } gmac_set_network_config_register(gmac, ncfgr); for (i = 0; i < GMAC_NUM_QUEUES; i++) { gmacd_setup_queue(gmacd, i, DUMMY_BUFFERS, dummy_buffer, dummy_rx_desc, DUMMY_BUFFERS, dummy_buffer, dummy_tx_desc, NULL); } }
/** * \brief (Re)Sart ADC sample. * Initialize ADC, set clock and timing, set ADC to given mode. */ static void _configure_adc(void) { uint8_t i = 0; /* Check if sequence mode is necessary */ _test_mode.sequence_enabled = 0; for(i = 0; i < NUM_CHANNELS; i++) { if(i != adc_channel_used[i]) { _test_mode.sequence_enabled = 1; break; } } /* Update channel number */ for (i = 0; i < NUM_CHANNELS; i++) { _data.channel[i] = adc_channel_used[i]; } /* Enable/disable sequencer */ if (_test_mode.sequence_enabled) { /* Set user defined channel sequence */ adc_set_sequence_by_list(adc_channel_used, NUM_CHANNELS); /* Enable sequencer */ adc_set_sequence_mode(true); } else { /* Disable sequencer */ adc_set_sequence_mode(false); } /* Enable channels, gain, single mode */ for (i = 0; i < NUM_CHANNELS; i++) { adc_enable_channel(_data.channel[i]); } /* Set power save */ if (_test_mode.power_save_enabled) { adc_set_sleep_mode(true); } else { adc_set_sleep_mode(false); } /* Transfer with/without DMA */ /* Initialize XDMA driver instance with polling mode */ /* Enable Data ready interrupt */ uint32_t ier_mask = 0; for (i = 0; i < NUM_CHANNELS; i++) { ier_mask |= 0x1u << _data.channel[i]; } adc_enable_it(ier_mask) ; /* Set ADC irq handler */ aic_set_source_vector(ID_ADC, adc_irq_handler); /* Configure trigger mode and start convention */ switch (_test_mode.trigger_mode) { case TRIGGER_MODE_SOFTWARE: /* Disable hardware trigger */ adc_set_trigger(0); /* No trigger, only software trigger can start conversions */ adc_set_trigger_mode(ADC_TRGR_TRGMOD_NO_TRIGGER); aic_enable(ID_ADC); break; case TRIGGER_MODE_ADTRG: pio_configure(pin_adtrg, ARRAY_SIZE(pin_adtrg)); break; case TRIGGER_MODE_TIMER : /* Enable hardware trigger */ adc_set_trigger(ADC_MR_TRGSEL_ADC_TRIG1); /* Trigger timer*/ adc_set_trigger_mode(ADC_TRGR_TRGMOD_PERIOD_TRIG); adc_set_trigger_period(250); aic_enable(ID_TC0); break; default : break; } }
int main(void) { uint8_t ucKey; /* Disable watchdog */ wdt_disable(); /* Configure console */ board_cfg_console(); /* Output example information */ printf("\r\n\r\n\r\n"); printf("-- RTC Example " SOFTPACK_VERSION " --\r\n"); printf("-- " BOARD_NAME "\r\n"); printf("-- Compiled: " __DATE__ " " __TIME__ " --\n\r"); // put 25 °C as a default temp, if there is no temprature sensor Temperature = 25; printf("Configure TC.\r\n"); configure_tc(); /* Default RTC configuration */ rtc_set_hour_mode(0); /* 24-hour mode */ struct _time empty_time = {0,0,0}; if (rtc_set_time_alarm(&empty_time)) { printf("\r\n Disable time alarm fail!"); } struct _date empty_date = {0,0,0}; if (rtc_set_date_alarm(&empty_date)) { printf("\r\n Disable date alarm fail!"); } /* Configure RTC interrupts */ rtc_enable_it(RTC_IER_SECEN | RTC_IER_ALREN); aic_set_source_vector(ID_SYSC, sysc_handler); aic_enable(ID_SYSC); /* Refresh display once */ _RefreshDisplay(); new_time.hour = 0; new_time.min = 0; new_time.sec = 30; rtc_set_time_alarm(&new_time); bMenuShown = 0; alarmTriggered = 0; rtc_calibration(Temperature); /* Handle keypresses */ while (1) { ucKey = console_get_char(); /* set time */ if (ucKey == 't') { bState = STATE_SET_TIME; aic_disable(ID_TC0); do { printf("\r\n\r\n Set time(hh:mm:ss): "); } while (get_new_time()); /* if valid input, none of variable for time is 0xff */ if (new_time.hour != 0xFF) { if (rtc_set_time (&new_time)) { printf ("\r\n Time not set, invalid input!\n\r"); } } bState = STATE_MENU; bMenuShown = 0; _RefreshDisplay(); CountDownTimer = 0; aic_enable(ID_TC0); } /* clock calibration */ else if (ucKey == 'p') { rtc_calibration(30); bState = STATE_MENU; bMenuShown = 0; _RefreshDisplay(); } /* set date */ else if (ucKey == 'd') { bState = STATE_SET_DATE; aic_disable(ID_TC0); do { printf("\r\n\r\n Set date(mm/dd/yyyy): "); } while (get_new_date()); /* if valid input, none of variable for date is 0xff(ff) */ if (new_date.year != 0xFFFF) { if (rtc_set_date(&new_date)) { printf ("\r\n Date not set, invalid input!\r\n"); } } /* only 'mm/dd' inputed */ if (new_date.month != 0xFF && new_date.year == 0xFFFF) { printf("\r\n Not Set for no year field!\r\n"); } bState = STATE_MENU; bMenuShown = 0; CountDownTimer = 0; aic_enable(ID_TC0); _RefreshDisplay(); } /* set time alarm */ else if (ucKey == 'i') { bState = STATE_SET_TIME_ALARM; aic_disable(ID_TC0); do { printf("\r\n\r\n Set time alarm(hh:mm:ss): "); } while (get_new_time()); if (new_time.hour != 0xFF) { if (rtc_set_time_alarm(&new_time)) { printf ("\r\n Time alarm not set, invalid input!\r\n"); } else { printf ("\r\n Time alarm is set at %02d:%02d:%02d!", new_time.hour, new_time.min, new_time.sec); } } bState = STATE_MENU; bMenuShown = 0; alarmTriggered = 0; CountDownTimer = 0; aic_enable(ID_TC0); _RefreshDisplay(); } /* set date alarm */ else if (ucKey == 'm') { bState = STATE_SET_DATE_ALARM; aic_disable(ID_TC0); do { printf("\r\n\r\n Set date alarm(mm/dd/): "); } while (get_new_date()); if (new_date.year == 0xFFFF && new_date.month != 0xFF) { if (rtc_set_date_alarm(&new_date)) { printf ("\r\n Date alarm not set, invalid input!\r\n"); } else { printf ("\r\n Date alarm is set on %02d/%02d!", new_date.month, new_date.day); } } bState = STATE_MENU; bMenuShown = 0; alarmTriggered = 0; CountDownTimer = 0; aic_enable(ID_TC0); _RefreshDisplay(); } /* clear trigger flag */ else if (ucKey == 'c') { alarmTriggered = 0; bMenuShown = 0; _RefreshDisplay(); } /* quit */ else if (ucKey == 'q') { break; } } return 0; }