static void prvSetupHardware( void ) { /* Disable watchdog. */ WDT_Disable( WDT ); WDT_Disable( ( Wdt * ) RSWDT ); SCB_EnableICache(); SCB_EnableDCache(); LED_Configure( 0 ); LED_Configure( 1 ); }
/** * \brief usart-hard-handshaking Application entry point.. * * Configures USART0 in hardware handshaking mode and * Timer Counter 0 to generate an interrupt every second. Then, starts the first * transfer on the USART and wait in an endless loop. * * \return Unused (ANSI-C compatibility). * \callgraph */ extern int main( void ) { /* Disable watchdog*/ WDT_Disable( WDT ) ; /* Configure pins*/ PIO_Configure( pins, PIO_LISTSIZE( pins ) ) ; /* Configure USART and display startup trace*/ _ConfigureUsart() ; printf( "-- USART Hardware Handshaking Example %s --\n\r", SOFTPACK_VERSION ) ; printf( "-- %s\n\r", BOARD_NAME ) ; printf( "-- Compiled: %s %s --\n\r", __DATE__, __TIME__ ) ; /* Configure TC0 to generate a 1s tick*/ _ConfigureTc0() ; /* Start receiving data and start timer*/ USART_ReadBuffer( BOARD_USART_BASE, pBuffer, BUFFER_SIZE ) ; BOARD_USART_BASE->US_IER = US_IER_RXBUFF ; TC_Start( TC0, 0 ) ; /* Infinite loop*/ while ( 1 ) ; }
/** * \brief getting-started Application entry point. * * \return Unused (ANSI-C compatibility). */ int main(void) { /* Disable watchdog */ WDT_Disable(); /* Output example information */ printf("-- Getting Started Example %s --\n\r", SOFTPACK_VERSION); printf("-- %s\n\r", BOARD_NAME); printf("-- Compiled: %s %s --\n\r", __DATE__, __TIME__); /* Configure systick for 1 ms. */ printf("Configure system tick to get 1ms tick period.\n\r"); if (SysTick_Config(BOARD_MCK / (1000))) printf("-F- Systick configuration error\n\r"); /* PIO configuration for LEDs and Buttons. */ PIO_InitializeInterrupts(IRQ_PRIOR_PIO); printf("Configure LED PIOs.\n\r"); ConfigureLeds(); printf("Configure button debouncing.\n\r"); ConfigureButtons(); printf("Press USRBP1 to Start/Stop the blue LED D2 blinking.\n\r"); printf("Press USRBP2 to Start/Stop the green LED D3 blinking.\n\r"); while (1) ; }
void Init_Cpu(void) { __set_PSP((uint32_t)msp_top); __set_PRIMASK(1); __set_FAULTMASK(1); __set_CONTROL(0); #if (CN_CPU_OPTIONAL_FPU == 1) pg_scb_reg->CPACR = (3UL << 20)|(3UL << 22); //使能FPU pg_scb_reg->FPCCR = (1UL << 31); //关闭lazy stacking #endif switch(pg_scb_reg->CPUID) { // case cn_revision_r0p1://todo // break; //好像没什么要做的 } extern void WDT_Disable(void); WDT_Disable(); //关狗 extern void SysClockInit(void); SysClockInit(); extern void SDRAM_Init(void); SDRAM_Init(); extern void Cache_Init(void); Cache_Init(); Load_Preload(); }
void cpu_init(void) { /* * SAM System init: Initializes the PLL / clock. * Defined in CMSIS/ATMEL/sam3xa/source/system_sam3xa.c */ SystemInit(); /* * Config systick interrupt timing, core clock is in microseconds --> 1ms * Defined in CMSIS/CMSIS/include/core_cm3.h */ SysTick_Config(SystemCoreClock / 1000); //if (SysTick_Config(SystemCoreClock / 1000)) while (1); /* * No watchdog now * */ WDT_Disable(WDT); /* * GCC libc init, also done in Reset_Handler() */ }
/** * Initializes the system, connects the USB and waits indefinitely. * * \callgraph */ int main(void) { /* Disable watchdog */ WDT_Disable( WDT ); /* Output example information */ printf( "-- USB Device Core Project %s --\n\r", SOFTPACK_VERSION ) ; printf( "-- %s\n\r", BOARD_NAME ) ; printf( "-- Compiled: %s %s --\n\r", __DATE__, __TIME__ ) ; /* If they are present, configure Vbus & Wake-up pins */ PIO_InitializeInterrupts(0) ; /* Enable UPLL for USB */ _ConfigureUsbClock(); /* USB initialization, Disable Pull-up */ TRACE_INFO("USB initialization\n\r"); USBDDriver_Initialize(&usbdDriver, &usbdDriverDescriptors, 0); USBD_Init(); /* Wait about 10ms so that host detach the device to re-enumerate Device connection */ TRACE_INFO("Connecting device\n\r"); /* connect if needed */ VBus_Configure(); while (USBD_GetState() < USBD_STATE_CONFIGURED); // Infinite loop while (1) { } }
void WDT_NMI(void) { WDT_InitTypeDef WDT_InitStruct; WDT_InitStruct.DetectTime = WDT_DETECT_TIME_EXP_25; WDT_InitStruct.OverflowOutput = WDT_NMIINT; LED_Init(); Delay(5000U); LED_On(LED1 | LED2); WDT_Init(&WDT_InitStruct); WDT_Enable(); while (1) { if (fIntNMI == 1U) { fIntNMI = 0U; LED_On(LED3); Delay(500U); LED_Off(LED3); Delay(500U); WDT_Disable(); } else { /* Do nothing */ } #ifdef DEMO2 Delay(500U); WDT_WriteClearCode(); LED_On(LED2); Delay(500U); LED_Off(LED2); #endif } }
/** * \brief Application entry point for ssc_dam_audio example. * * \return Unused (ANSI-C compatibility). */ int main( void ) { uint16_t data = 0; /* Disable watchdog */ WDT_Disable( WDT ) ; /* Enable I and D cache */ SCB_EnableICache(); SCB_EnableDCache(); /* Output example information */ printf("-- SSC DMA Audio Example %s --\n\r", SOFTPACK_VERSION); printf("-- %s\n\r", BOARD_NAME); printf("-- Compiled: %s %s --\n\r", __DATE__, __TIME__); /* Configure systick for 1 ms. */ printf( "Configure system tick to get 1ms tick period.\n\r" ) ; if ( TimeTick_Configure( ) ) { printf("-F- Systick configuration error\n\r" ) ; } /* Configure all pins */ PIO_Configure(pinsSsc, PIO_LISTSIZE(pinsSsc)); /* Configure SSC */ SSC_Configure(AUDIO_IF , 0 , SSC_MCK ); SSC_ConfigureReceiver(AUDIO_IF,I2S_SLAVE_RX_SETTING,I2S_SLAVE_RX_FRM_SETTING); SSC_DisableReceiver(AUDIO_IF); SSC_ConfigureTransmitter(AUDIO_IF,I2S_SLAVE_TX_SETTING,I2S_SLAVE_TX_FRM_SETTING); SSC_DisableTransmitter(AUDIO_IF); /* Configure DMA */ Dma_configure(); /* Configure and enable the TWI (required for accessing the DAC) */ PMC_EnablePeripheral(ID_TWIHS0); TWI_ConfigureMaster(TWIHS0, TWI_CLOCK, BOARD_MCK); TWID_Initialize(&twid, TWIHS0); /* Configure TWI interrupts */ NVIC_ClearPendingIRQ(TWIHS0_IRQn); NVIC_EnableIRQ(TWIHS0_IRQn); /* check that WM8904 is present */ WM8904_Write(&twid, WM8904_SLAVE_ADDRESS, 22, 0); data=WM8904_Read(&twid, WM8904_SLAVE_ADDRESS, 0); if( data != 0x8904){ printf("WM8904 not found!\n\r"); while(1); } /* Initialize the audio DAC */ WM8904_Init(&twid, WM8904_SLAVE_ADDRESS, PMC_MCKR_CSS_SLOW_CLK); /* Enable the DAC master clock */ PMC_ConfigurePCK2(PMC_MCKR_CSS_SLOW_CLK, PMC_MCKR_PRES_CLK_1 ); printf("Insert Line-in cable with PC Headphone output\n\r"); PlayRecording(); while ( 1 ); }
void xs_wdt_stop(xsMachine *the) { if (wdt_enable) { CLK_ModuleClkDisable(CLK_WDT); WDT_Disable(); } }
/** * \brief usb_massstorage Application entry point. * * Configures UART, * Configures TC0, USB MSD Driver and run it. * * \return Unused (ANSI-C compatibility). */ int main( void ) { sSdCard *pSd = 0; /* Disable watchdog */ WDT_Disable( WDT ) ; SCB_EnableICache(); SCB_EnableDCache(); #if defined LUN_RAMDISK /* Enable SDRAM */ BOARD_ConfigureSdram(); #endif TRACE_INFO("-- USB Device Mass Storage Example %s --\n\r", SOFTPACK_VERSION); TRACE_INFO("-- %s\n\r", BOARD_NAME); TRACE_INFO("-- Compiled: %s %s --\n\r", __DATE__, __TIME__); /* If they are present, configure Vbus & Wake-up pins */ PIO_InitializeInterrupts(0); /* Initialize all USB power (off) */ _ConfigureUotghs(); /* Initialize PIO pins */ _ConfigurePIOs(); /* Initialize drivers */ _ConfigureDrivers(); _MemoriesInitialize(pSd); /* BOT driver initialization */ MSDDriver_Initialize(&msdDriverDescriptors, luns, MAX_LUNS); /* connect if needed */ USBD_Connect(); while (1) { /* Mass storage state machine */ if (USBD_GetState() < USBD_STATE_CONFIGURED){} else { MSDDriver_StateMachine(); if (msdRefresh) { msdRefresh = 0; if (msdWriteTotal < 50 * 1000) { /* Flush Disk Media */ } msdWriteTotal = 0; } } } }
/** * \brief Application entry point for UART example. * * \return Unused (ANSI-C compatibility). */ extern int main(void) { uint8_t ucKey; /* Disable watchdog */ WDT_Disable(WDT); /* Output example information */ printf("-- UART Example %s --\n\r", SOFTPACK_VERSION); printf("-- %s\n\r", BOARD_NAME); printf("-- Compiled: %s %s With %s--\n\r", __DATE__, __TIME__, COMPILER_NAME); /* Enable I and D cache */ SCB_EnableICache(); SCB_EnableDCache(); /* Display menu */ DisplayMenu(); while (1) { ucKey = DBG_GetChar(); switch (ucKey) { case 'h': DisplayMenu(); break; case 'i': case 'I': printf("\n\rSending Tx Buffer.. \n\r"); UartTransfer(); break; case 'd': case 'D': memset(pRxBuffer,'X' ,30); pRxBuffer[28] = '\n'; pRxBuffer[29] = '\r'; printf("\n\rRx Buffer before transfer is \n\r"); puts((char*)pRxBuffer); _UartdConfigLB(); UARTD_EnableRxChannels(&Uartd, &UartRx); UARTD_EnableTxChannels(&Uartd, &UartTx); UARTD_RcvData(&Uartd); UARTD_SendData(&Uartd); printf("\n\rRx Buffer after transfer is \n\r"); while (Uartd.pRxChannel->sempaphore == 0); puts((char*)pRxBuffer); UARTD_DisableRxChannels(&Uartd, &UartRx); UARTD_DisableTxChannels(&Uartd, &UartTx); break; default : break; } } }
void _SetupHardware( void ) { WDT_Disable( ); uint32_t i = 0; for( i = 0; i < 35; i++ ) { NVIC_SetPriority( (IRQn_Type)i, 0xF << 4 ) ; } }
static void prvSetupHardware( void ) { /* Disable watchdog */ WDT_Disable( WDT ); /* Set protect mode in the AIC for easier debugging. */ AIC->AIC_DCR |= AIC_DCR_PROT; /* Configure ports used by LEDs. */ vParTestInitialise(); CP15_EnableIcache(); }
/** * \brief Application entry point for spi_slave example. * * \return Unused (ANSI-C compatibility). */ extern int main( void ) { uint8_t ucKey ; /* Disable watchdog */ WDT_Disable( WDT ) ; /* Output example information */ printf( "-- spi slave example %s --\n\r", SOFTPACK_VERSION ) ; printf( "-- %s\n\r", BOARD_NAME ) ; printf( "-- Compiled: %s %s --\n\r", __DATE__, __TIME__ ) ; /* Configure PIO Pins for SPI */ PIO_Configure( pSpiPins, PIO_LISTSIZE( pSpiPins ) ) ; /* Configure SPI interrupts for Slave only*/ NVIC_DisableIRQ( SPI_IRQn ) ; NVIC_ClearPendingIRQ( SPI_IRQn ) ; NVIC_SetPriority( SPI_IRQn, 0 ) ; NVIC_EnableIRQ( SPI_IRQn ) ; SpiSlaveInitialize() ; /* Display menu */ DisplayMenu() ; while ( 1 ) { ucKey = UART_GetChar() ; switch ( ucKey ) { case 'h' : DisplayMenu() ; break ; case 't' : SpiMasterGo() ; break ; default : /* Set configuration #n */ if ( (ucKey >= '0') && (ucKey <= ('0' + NUM_SPCK_CONFIGURATIONS - 1)) ) { SetClockConfiguration( ucKey - '0' ) ; } break ; } } }
int main() { #if 1 WDT_Disable(WDT); /* Set 3 FWS for Embedded Flash Access */ EFC->EEFC_FMR = EEFC_FMR_FWS(3); CLOCK_SetConfig(2); /* I don't know why, the baudrate is 38400 = 115200/3 */ UART_Configure(115200, 64000000/3);// so I add this to solve the problem printf("Start GaInOS-TK.\r\n"); #endif StartOS(OSDEFAULTAPPMODE); return 0; }
static void prvSetupHardware( void ) { /* Disable watchdog */ WDT_Disable( WDT ); /* Set protect mode in the AIC for easier debugging. */ AIC->AIC_DCR |= AIC_DCR_PROT; /* Configure ports used by LEDs. */ vParTestInitialise(); #if defined (ddram) MMU_Initialize( ( uint32_t * ) 0x30C000 ); CP15_EnableMMU(); CP15_EnableDcache(); CP15_EnableIcache(); #endif }
void Example_VLTD_Reset(void) { WDT_Disable(); /* Disable WDT explicitly */ GPIO_SetOutput(GPIO_PG, GPIO_BIT_0); /* Set PG0 as output port */ if (CG_GetResetFlag().Bit.VLTDReset == 0U) { VLTD_SetVoltage(VLTD_DETECT_VOLTAGE_46); /* change the parameter to select different detection voltage */ VLTD_Enable(); /* Enable VLTD function */ GPIO_WriteData(GPIO_PG, 0x00); /* Set PG0 to LOW */ } else { VLTD_Disable(); /* Disable VLTD function */ GPIO_WriteData(GPIO_PG, 0x01); /* Set PG0 to HIGH */ } while (1) { /* Do nothing */ } }
void TB0_print(void) { TMRB_InitTypeDef myTMRB; WDT_Disable(); UART_Configuration(UART0); UART_Print(UART0, "This is a TIMER example!\n\r\n\r"); myTMRB.Mode = TMRB_INTERVAL_TIMER; myTMRB.ClkDiv = TMRB_CLK_DIV_8; myTMRB.Cycle = TMRB_1ms; /* Specific value depends on system clock */ myTMRB.UpCntCtrl = TMRB_AUTO_CLEAR; myTMRB.Duty = TMRB_1ms / 2U; /* Specific value depends on system clock */ TMRB_Enable(TSB_TB0); TMRB_Init(TSB_TB0, &myTMRB); TMRB_SetRunState(TSB_TB0, TMRB_RUN); NVIC_EnableIRQ(INTTB0_IRQn); while (1) { /* Do nothing */ } }
void naiboard_sleep(void) { if (naiboard_state.usb_vendor_enabled) // If we're not connected we won't go to sleep. return; // We're only using the IDLE sleep level because USB doesn't work below that. // Not much power saving though... SLEEP.CTRL = SLEEP_SMODE_IDLE_gc; sysclk_disable_peripheral_clock(&RTC); //printf_P(PSTR("sleep\n")); WDT_Disable(); sleep_enable(); cpu_sleep(); // Waking up sleep_disable(); WDT_Enable(); sysclk_enable_peripheral_clock(&RTC); //printf_P(PSTR("wake\n")); }
static void prvSetupHardware( void ) { /* Disable watchdog */ WDT_Disable( WDT ); /* Set protect mode in the AIC for easier debugging. THIS IS COMMENTED OUT AS IT RESULTS IN SPURIOUS INTERRUPTS. AIC->AIC_DCR |= AIC_DCR_PROT; */ /* Configure ports used by LEDs. */ vParTestInitialise(); #if defined (ddram) { MMU_Initialize( ( uint32_t * ) 0x20C000 ); CP15_EnableMMU(); CP15_EnableDcache(); CP15_EnableIcache(); } #endif }
/** * @brief The NMI interrupt request function. * @param None * @retval None */ void NMI_Handler(void) { uint8_t uRegVal = 0U; uRegVal = (uint8_t) TSB_CG->NMIFLG; switch (uRegVal) { case FLG_WDT: uCont++; TSB_PM_DATA_PM4 = !TSB_PM_DATA_PM4; if (uCont == 5U) { WDT_Disable(); uCont = 0U; } break; case FLG_NMI: /* Do nothing */ break; default: /* Do nothing */ break; } }
/** * Initializes the DBGU and ISO7816 driver, and starts some tests. * \return Unused (ANSI-C compatibility) */ extern int main( void ) { uint8_t pAtr[MAX_ATR_SIZE]; uint8_t ucSize; /* Disable watchdog*/ WDT_Disable(WDT); SCB_EnableICache(); SCB_EnableDCache(); /* Initialize Atr buffer */ memset(pAtr, 0, sizeof(pAtr)); printf("-- USART ISO7816 Example %s --\n\r", SOFTPACK_VERSION); printf("-- %s\n\r", BOARD_NAME); printf("-- Compiled: %s %s With %s--\n\r", __DATE__, __TIME__, COMPILER_NAME); /* Configure IT on Smart Card */ ConfigureCardDetection(); /* Configure ISO7816 driver */ PIO_Configure(pinsISO7816, PIO_LISTSIZE(pinsISO7816)); ISO7816_Init(USART, ID_USART, pinIso7816RstMC); /* Read ATR */ ISO7816_warm_reset(); ISO7816_Datablock_ATR(pAtr, &ucSize); /* Decode ATR */ ISO7816_Decode_ATR(pAtr); /* Allow user to send some commands */ SendReceiveCommands(); return 0; }
/** * \brief getting-started Application entry point. * * \return Unused (ANSI-C compatibility). */ extern int main(void) { uint32_t id_offset = 0; uint32_t fifo_entries; uint32_t button_state = BUTTON_PUSHED; uint32_t button_state2 = BUTTON_NOT_PUSHED; uint32_t can_mode = CAN_STANDARD; /* Disable watchdog */ WDT_Disable(WDT); /* Output example information */ printf("\n\r-- Controller Area Network (CAN) Example %s --\n\r", SOFTPACK_VERSION); printf("-- %s\n\r", BOARD_NAME); printf("-- Compiled: %s %s --\n\r\n\r", __DATE__, __TIME__); printf("-- LED0 toggles on CAN message reception\n\r"); printf("-- LED1 toggles on CAN message transmission\n\r"); printf("-- CAN message transmission stopped while SW0 is pushed\n\r"); printf("-- SW1 pushes alternate between standard CAN and CAN-FD\n\r"); SCB_EnableICache(); SCB_EnableDCache(); /* Configure systick for 1 ms. */ TimeTick_Configure(); /* Configure Board LED's */ LED_Configure(0); #if 2 == LED_NUM LED_Configure(1); #endif /* Configure Timer/Counter for 250msec Tick */ _ConfigureTc(); /* Configure Board Push-buttons */ // SW1 is a ERASE system function, switch it to port function MATRIX->CCFG_SYSIO |= (1u << 12); /* have to disable the pull down on PB12 for SW1 before the pull up can be enabled */ PIOB->PIO_PPDDR = 1 << 12; PIO_Configure(pushbutton, PIO_LISTSIZE(pushbutton)); /* Adjust pio denounce filter parameters, uses 10 Hz filter. */ PIO_SetDebounceFilter(&pushbutton[0], 10); #if 2 == BUTTON_NUM PIO_SetDebounceFilter(&pushbutton[1], 10000); #endif SystemCoreClockUpdate(); MCAN_Init(&mcan1Config); MCAN_InitFdBitRateSwitchEnable(&mcan1Config); MCAN_InitTxQueue(&mcan1Config); MCAN_InitLoopback(&mcan1Config); // remove to disable loop back mode MCAN_Enable(&mcan1Config); MCAN_IEnableMessageStoredToRxDedBuffer(&mcan1Config, CAN_INTR_LINE_1); txMailbox0 = (uint32_t *)MCAN_ConfigTxDedBuffer(&mcan1Config, TX_BUFFER_0, MSG_ID_0, CAN_STD_ID, CAN_DLC_1); txMailbox1 = (uint32_t *)MCAN_ConfigTxDedBuffer(&mcan1Config, TX_BUFFER_1, MSG_ID_1, CAN_EXT_ID, CAN_DLC_8); MCAN_ConfigRxBufferFilter(&mcan1Config, RX_BUFFER_0, FILTER_0, MSG_ID_0, CAN_STD_ID); MCAN_ConfigRxBufferFilter(&mcan1Config, RX_BUFFER_1, FILTER_0, MSG_ID_1, CAN_EXT_ID); MCAN_ConfigRxClassicFilter(&mcan1Config, CAN_FIFO_0, FILTER_1, MSG_ID_2, CAN_STD_ID, MSG_ID_2_MASK); while (1) { if (tick) { tick = 0; if (PIO_Get(&pushbutton[0]) == BUTTON_NOT_PUSHED) { if (button_state2 == BUTTON_NOT_PUSHED) { /* periodically transmit messages while SW0 is not pushed */ // send standard ID from a dedicated buffer *txMailbox0 = MSG_ID_0_DATA1; // write data into CAN mailbox MCAN_SendTxDedBuffer(&mcan1Config, TX_BUFFER_0); // send data txdCntr++; // send extended ID from a dedicated buffer *txMailbox1 = MSG_ID_1_DATA1_4; // write data into CAN mailbox *(txMailbox1 + 1) = MSG_ID_1_DATA5_8; // write data into CAN mailbox MCAN_SendTxDedBuffer(&mcan1Config, TX_BUFFER_1); // send the data txdCntr++; // send from Tx Queue MCAN_AddToTxFifoQ(&mcan1Config, MSG_ID_2 + id_offset, CAN_STD_ID, CAN_DLC_1, &txData[0]); txdCntr++; // increment the offset so we send different ID's within the // range defined by the mask id_offset = (id_offset + 1) & (uint32_t) ~MSG_ID_2_MASK; // update data being sent for next time txData[0]++; button_state2 = BUTTON_NOT_PUSHED; } } else { if (button_state2 == BUTTON_NOT_PUSHED) button_state2 = BUTTON_PUSHED; else button_state2 = BUTTON_NOT_PUSHED; } } /* poll for TX'd message complete */ if (MCAN_IsTxComplete(&mcan1Config)) { MCAN_ClearTxComplete(&mcan1Config); if (MCAN_IsBufferTxd(&mcan1Config, TX_BUFFER_0)) { #if 2 == LED_NUM LED_Toggle(1); #endif } } /* Poll for new CAN messages in RX FIFO */ do { fifo_entries = MCAN_GetRxFifoBuffer(&mcan1Config, CAN_FIFO_0, (Mailbox64Type *) &rxMailbox2); if (fifo_entries > 0) rxdCntr++; } while (fifo_entries > 1); /* SW1 used to alternate between standard CAN and CAN-FD operation */ #if 2 == BUTTON_NUM if (PIO_Get(&pushbutton[1]) == BUTTON_NOT_PUSHED) { #else if (1) { #endif button_state = BUTTON_NOT_PUSHED; } else { if (button_state == BUTTON_NOT_PUSHED ) { // Switch on a NOT PUSHED to PUSHED edge button_state = BUTTON_PUSHED; if (can_mode == CAN_STANDARD) { can_mode = CAN_FD; MCAN_RequestFdBitRateSwitch( &mcan1Config ); } else { can_mode = CAN_STANDARD; MCAN_RequestIso11898_1( &mcan1Config ); } } } #ifdef POLLKEYBOARD /* poll for keyboard entry */ if (DBG_IsRxReady()) { keyboard = DBG_GetChar(); if (((char) keyboard == 'L' ) || ( (char) keyboard == 'l')) { if (loopback == 1) { MCAN_LoopbackOff(&mcan1Config); loopback = 0; } else { MCAN_LoopbackOn(&mcan1Config); loopback = 1; } } } #endif } }
/** * \brief Application entry point for PWM with PDC example. * * Outputs a PWM on LED1. * Channel #0 is configured as synchronous channels. * The update of the duty cycle values is made automatically by the Peripheral DMA Controller. * * \return Unused (ANSI-C compatibility). */ int main(void) { uint32_t i; /* Disable watchdog */ WDT_Disable( WDT ) ; /* Enable I and D cache */ SCB_EnableICache(); SCB_EnableDCache(); /* Output example information */ printf("-- PWM with DMA Example %s --\n\r", SOFTPACK_VERSION); printf("-- %s\n\r", BOARD_NAME); printf("-- Compiled: %s %s --\n\r", __DATE__, __TIME__); /* PIO configuration */ PIO_Configure(pinPwm, PIO_LISTSIZE(pinPwm)); for (i= 0; i< DUTY_BUFFER_LENGTH; i++) dwDutys[i] = i/2; /* Enable PWMC peripheral clock */ PMC_EnablePeripheral(ID_PWM0); /* Configure interrupt for PWM transfer */ NVIC_DisableIRQ(PWM0_IRQn); NVIC_ClearPendingIRQ(PWM0_IRQn); NVIC_SetPriority(PWM0_IRQn, 0); /* Configure DMA channel for PWM transfer */ _ConfigureDma(); /* Set clock A to run at PWM_FREQUENCY * MAX_DUTY_CYCLE (clock B is not used) */ PWMC_ConfigureClocks(PWM0, PWM_FREQUENCY * MAX_DUTY_CYCLE , 0, BOARD_MCK); /* Configure PWMC channel for LED0 (left-aligned, enable dead time generator) */ PWMC_ConfigureChannel( PWM0, 0, /* channel */ PWM_CMR_CPRE_CLKA, /* prescaler, CLKA */ 0, /* alignment */ 0 /* polarity */ ); PWMC_ConfigureSyncChannel(PWM0, (1 << CHANNEL_PWM_LED0), /* Define the synchronous channels by the bits SYNCx */ PWM_SCM_UPDM_MODE2, /* Select the manual write of duty-cycle values and the automatic update by setting the field UPDM to 鈥�1鈥� */ 0, 0); /* Configure channel 0 period */ PWMC_SetPeriod(PWM0, 0, DUTY_BUFFER_LENGTH); /* Configure channel 0 duty cycle */ PWMC_SetDutyCycle(PWM0, 0, MIN_DUTY_CYCLE); /* Define the update period by the field UPR in the PWM_SCUP register*/ PWMC_SetSyncChannelUpdatePeriod(PWM0, 8); /* Enable the synchronous channels by writing CHID0 in the PWM_ENA register */ PWMC_EnableChannel(PWM0, 0); /* Enable PWM interrupt */ PWMC_EnableIt(PWM0, 0, PWM_IER2_WRDY); NVIC_EnableIRQ(PWM0_IRQn); _PwmDmaTransfer(); while(1); }
void init( void ) { SystemInit(); // Set Systick to 1ms interval, common to all SAM3 variants if (SysTick_Config(SystemCoreClock / 1000)) { // Capture error while (true); } // Disable watchdog WDT_Disable(WDT); // Initialize C library __libc_init_array(); // Disable pull-up on every pin for (int i = 0; i < PINS_COUNT; i++) digitalWrite(i, LOW); // Enable parallel access on PIO output data registers PIOA->PIO_OWER = 0xFFFFFFFF; PIOB->PIO_OWER = 0xFFFFFFFF; PIOC->PIO_OWER = 0xFFFFFFFF; PIOD->PIO_OWER = 0xFFFFFFFF; // Initialize Serial port U(S)ART pins PIO_Configure( g_APinDescription[PINS_UART].pPort, g_APinDescription[PINS_UART].ulPinType, g_APinDescription[PINS_UART].ulPin, g_APinDescription[PINS_UART].ulPinConfiguration); digitalWrite(0, HIGH); // Enable pullup for RX0 PIO_Configure( g_APinDescription[PINS_USART0].pPort, g_APinDescription[PINS_USART0].ulPinType, g_APinDescription[PINS_USART0].ulPin, g_APinDescription[PINS_USART0].ulPinConfiguration); PIO_Configure( g_APinDescription[PINS_USART1].pPort, g_APinDescription[PINS_USART1].ulPinType, g_APinDescription[PINS_USART1].ulPin, g_APinDescription[PINS_USART1].ulPinConfiguration); PIO_Configure( g_APinDescription[PINS_USART3].pPort, g_APinDescription[PINS_USART3].ulPinType, g_APinDescription[PINS_USART3].ulPin, g_APinDescription[PINS_USART3].ulPinConfiguration); // Initialize USB pins PIO_Configure( g_APinDescription[PINS_USB].pPort, g_APinDescription[PINS_USB].ulPinType, g_APinDescription[PINS_USB].ulPin, g_APinDescription[PINS_USB].ulPinConfiguration); // Initialize CAN pins /* PIO_Configure( g_APinDescription[PINS_CAN0].pPort, g_APinDescription[PINS_CAN0].ulPinType, g_APinDescription[PINS_CAN0].ulPin, g_APinDescription[PINS_CAN0].ulPinConfiguration); PIO_Configure( g_APinDescription[PINS_CAN1].pPort, g_APinDescription[PINS_CAN1].ulPinType, g_APinDescription[PINS_CAN1].ulPin, g_APinDescription[PINS_CAN1].ulPinConfiguration); */ // Initialize Analog Controller pmc_enable_periph_clk(ID_ADC); adc_init(ADC, SystemCoreClock, ADC_FREQ_MAX, ADC_STARTUP_FAST); adc_configure_timing(ADC, 0, ADC_SETTLING_TIME_3, 1); adc_configure_trigger(ADC, ADC_TRIG_SW, 0); // Disable hardware trigger. adc_disable_interrupt(ADC, 0xFFFFFFFF); // Disable all ADC interrupts. adc_disable_all_channel(ADC); // Initialize analogOutput module analogOutputInit(); }
/** * \brief usart-hw-handshaking Application entry point.. * * Configures USART in hardware handshaking mode and * Timer Counter 0 to generate an interrupt every second. Then, start the first * transfer on the USART and wait in an endless loop. * * \return Unused (ANSI-C compatibility). */ int main( void ) { char pbaud_time[8]; uint32_t BytesRead, BytesToRead, baudrate, timeout, TxBytesLeft; uint8_t AppBufferRollOver = 0; uint8_t *pTxBuff; /* Disable watchdog*/ WDT_Disable(WDT); printf("-- USART Hardware Handshaking Example %s --\n\r", SOFTPACK_VERSION); printf("-- %s\n\r", BOARD_NAME); printf("-- Compiled: %s %s With %s--\n\r", __DATE__, __TIME__, COMPILER_NAME); /* Enable I and D cache */ SCB_EnableICache(); SCB_EnableDCache(); /* Configure USART pins*/ PIO_Configure(pins, PIO_LISTSIZE(pins)); /* Configure systick for 1 ms. */ TimeTick_Configure(); NVIC_SetPriority(XDMAC_IRQn , XDMA_NVIC_PRIO); printf("\n\rEnter required baudrate:"); gets(pbaud_time); baudrate = (atoi(pbaud_time)) ? (atoi(pbaud_time)): 921600; printf("\n\rEnter required timeout (in microsec):"); gets(pbaud_time); timeout = atoi(pbaud_time); if (timeout > 1000) { timeout /= 1000; timeout = ((timeout * baudrate) / 1000); } else { timeout = (timeout * baudrate) / 1000000; } timeout = (timeout) ? ((timeout > MAX_RX_TIMEOUT) ? MAX_RX_TIMEOUT : timeout) \ : MAX_RX_TIMEOUT; printf("\n\r"); /* Configure USART */ _ConfigureUsart(baudrate, timeout); printf("\n\r"); /*Enable Rx channel of USART */ USARTD_EnableRxChannels(&Usartd, &UsartRx); #ifdef FULL_DUPLEX /*Enable Tx channel of USART */ USARTD_EnableTxChannels(&Usartd, &UsartTx); #endif /* Start receiving data and start timer*/ USARTD_RcvData(&Usartd); /*Initialize Ring buffer */ pUsartBuffer = (RignBuffer_t *)malloc(sizeof(RignBuffer_t)); _initCircularBuffer(pUsartBuffer); pTxBuff = &FirstAppBuff[0]; TxBytesLeft = 0; #ifdef USE_MD5_CHECK md5_init(&pms); #endif //USE_MD5_CHECK #ifdef FULL_DUPLEX printf( "\n\r-I- USART is in Full Duplex mode \n\r"); #else printf( "\n\r-I- USART is in Half Duplex mode \n\r"); #endif printf( "\n\r-I- Please send a file to serial port (USART0) \n\r"); BytesToRead = MIN_FREE_BYTES; // Bytes to read from ring-buffer while (1) { #ifdef USE_MD5_CHECK if (DBG_IsRxReady()) { ch = DBG_GetChar(); if (ch == 'm') { uint8_t i; md5_finish(&pms, md5); printf("\r\nmd5:"); for (i = 0; i < sizeof(md5);i++) printf("%.2x",md5[i]); printf("\r\n"); md5_init(&pms); TotalbytesReceived = 0; } } #endif /* Check Application buffer (100 KB)overflow */ if (((PingPongBufferFlag == 0) && (pTxBuff+BytesToRead) >= &FirstAppBuff[APP_BUFFER]) || (( PingPongBufferFlag == 1) && (pTxBuff+BytesToRead) >= &SecondAppBuff[APP_BUFFER])) { AppBufferRollOver = 1; // Roll over and start copying to the beginning of Application buffer to avoid errors if (PingPongBufferFlag) BytesToRead = (&SecondAppBuff[APP_BUFFER] - pTxBuff); else BytesToRead = (&FirstAppBuff[APP_BUFFER] - pTxBuff); memory_barrier(); } /* Read ring buffer */ BytesRead = RingBufferRead(pUsartBuffer, pTxBuff, BytesToRead); memory_sync(); TxBytesLeft += BytesRead; // number of bytes to send via USART Tx #ifdef USE_MD5_CHECK if (BytesRead > 0) md5_append(&pms,pTxBuff,BytesRead); #endif /* check if one of the application buffer is full and ready to send */ if (AppBufferRollOver && (TxBytesLeft == APP_BUFFER)) { AppBufferRollOver = 0; TxBytesLeft = 0; BytesRead = 0; BytesToRead = MIN_FREE_BYTES; // Bytes to read from ring-buffer while (!UsartTx.dmaProgress); if (PingPongBufferFlag) { PingPongBufferFlag = 0; pTxBuff = &FirstAppBuff[0]; } else { PingPongBufferFlag = 1; pTxBuff = &SecondAppBuff[0]; } memory_sync(); #ifdef FULL_DUPLEX USARTD_SendData(&Usartd); #endif } /* otherwise keep storing in same application buffer from Rx DMA's ring buffer */ else { BytesToRead = MIN_FREE_BYTES; // Bytes to read from ring-buffer pTxBuff += BytesRead; #ifdef FULL_DUPLEX /* Check for Tx timeout, if there is timeout then send the bytes left (less than 100 KB) in application buffer */ if ((GetDelayInTicks(TimeOutTimer, GetTicks()) == USART_TX_TIMEOUT) && TxBytesLeft) { // wait for any eventual USART Tx in progress while (!UsartTx.dmaProgress); FlushTxBuffer(TxBytesLeft); TimeOutTimer = GetTicks(); PingPongBufferFlag = 0; TxBytesLeft = 0; BytesRead = 0; BytesToRead = MIN_FREE_BYTES; // Bytes to read from ring-buffer pTxBuff = &FirstAppBuff[0]; _UpdateTxConfig((uint32_t)&FirstAppBuff[0], APP_BUFFER); TRACE_INFO_WP(" TX Tiemout \n\r"); } #endif } } }
/** * \brief Application entry point. * * \return Unused (ANSI-C compatibility). */ extern int main(void) { uint8_t ucKey; /* Disable watchdog */ WDT_Disable(WDT); SCB_EnableICache(); SCB_EnableDCache(); /* Output example information */ printf("-- USART LON Example %s --\n\r", SOFTPACK_VERSION); printf("-- %s\n\r", BOARD_NAME); printf("-- Compiled: %s %s With %s--\n\r", __DATE__, __TIME__, COMPILER_NAME); /* Configure pins */ PIO_Configure(pins, PIO_LISTSIZE(pins)); /* PB4 function selected */ MATRIX->MATRIX_WPMR = MATRIX_WPMR_WPKEY_PASSWD; MATRIX->CCFG_SYSIO |= CCFG_SYSIO_SYSIO4; /* Display menu */ _DisplayMenu(); /* Configure DMA with IRQ */ _ConfigureDma(); Buffer[0] = sizeof(palette) - 1; /* LON Data Length: */ Buffer[1] = US_LONL2HDR_BLI(2); memcpy(&Buffer[2], palette, sizeof(palette)); /* configure USART in LON mode*/ _ConfigureUsart(); NVIC_EnableIRQ(XDMAC_IRQn); while (1) { ucKey = DBG_GetChar(); switch (ucKey) { case 't': case 'T': printf("-I- LON Transmitting ... \n\r"); USART->US_CR = US_CR_RSTSTA; /* Reset Status Bits */ _DmaUsartTx(); while (!transDone); printf("-I- LON Transmitting completed \n\r"); transDone = 0; break; case 'r': case 'R': printf("-I- LON receiving ... \n\r"); USART->US_CR = US_CR_RSTSTA; /* Reset Status Bits */ recvDone = 0; _DmaUsartRx(); while (!recvDone); /* successfully received */ _DumpInfo(pRecvBufferUSART, BUFFER_SIZE - 1); printf("\n\r-I- LON Receiving completed \n\r"); memset(pRecvBufferUSART, 0, sizeof(pRecvBufferUSART)); break; case 'm': case 'M': _DisplayMenu(); break; } } }
void init( void ) { SystemInit(); // Set Systick to 1ms interval if (SysTick_Config(SystemCoreClock / 1000)) { // Capture error while (true); } // Disable watchdog WDT_Disable(WDT); // Initialize C library __libc_init_array(); // Disable pull-up on every pin for (uint i = 0u; i < PINS_COUNT; i++) digitalWrite(i, LOW); // Enable parallel access on PIO output data registers PIOA->PIO_OWER = 0xFFFFFFFF; PIOB->PIO_OWER = 0xFFFFFFFF; //PIOC->PIO_OWER = 0xFFFFFFFF; //PIOD->PIO_OWER = 0xFFFFFFFF; //turn off ERASE and JTAG pins MATRIX->CCFG_SYSIO = CCFG_SYSIO_SYSIO12 | CCFG_SYSIO_SYSIO7 | CCFG_SYSIO_SYSIO6 | CCFG_SYSIO_SYSIO5 | CCFG_SYSIO_SYSIO4; // Initialize Serial port UART pins PIO_Configure( g_APinDescription[PINS_USART0].pPort, g_APinDescription[PINS_USART0].ulPinType, g_APinDescription[PINS_USART0].ulPin, g_APinDescription[PINS_USART0].ulPinConfiguration); digitalWrite(0u, HIGH); // Enable pullup for RX0 // Initialize Serial port USART pins // Pins are disconnected from PIO controller and hooked to the peripheral. // Currently PIO_Configure always enables the pullup resistor for peripherals. This appears to be a bug, as it is not written correctly for that purpose, but has that affect. PIO_Configure( g_APinDescription[PINS_UART1].pPort, g_APinDescription[PINS_UART1].ulPinType, g_APinDescription[PINS_UART1].ulPin, g_APinDescription[PINS_UART1].ulPinConfiguration); PIO_Configure( g_APinDescription[B1].pPort, g_APinDescription[B1].ulPinType, g_APinDescription[B1].ulPin, g_APinDescription[B1].ulPinConfiguration); /* TODO: wire up USB ID line and check out USB configuration // Initialize USB pins PIO_Configure( g_APinDescription[PINS_USB].pPort, g_APinDescription[PINS_USB].ulPinType, g_APinDescription[PINS_USB].ulPin, g_APinDescription[PINS_USB].ulPinConfiguration); //TODO: Initialize I2C pins for crypto IC PIO_Configure( g_APinDescription[PINS_SPI].pPort, g_APinDescription[PINS_SPI].ulPinType, g_APinDescription[PINS_SPI].ulPin, g_APinDescription[PINS_SPI].ulPinConfiguration); */ // Initialize Analog Controller pmc_enable_periph_clk(ID_ADC); adc_init(ADC, SystemCoreClock, ADC_FREQ_MAX, ADC_STARTUP_FAST); adc_configure_timing(ADC, 0, ADC_SETTLING_TIME_3, 1); adc_configure_trigger(ADC, ADC_TRIG_SW, 0); // Disable hardware trigger. adc_disable_interrupt(ADC, 0xFFFFFFFF); // Disable all ADC interrupts. adc_disable_all_channel(ADC); // Initialize analogOutput module analogOutputInit(); }
/** * \brief UOTGHS Library Example Application entry point. * * \return 42 Fatal error. */ extern int main( void ) { /* Disable watchdog */ WDT_Disable( WDT ) ; /* UTMI parallel mode, High/Full/Low Speed */ /* UOTGCK not used in this configuration (High Speed) */ PMC->PMC_SCDR = PMC_SCDR_UOTGCK; /* USB clock register: USB Clock Input is UTMI PLL */ PMC->PMC_USB = PMC_USB_USBS; /* USBS: USB Input Clock Selection: USB Clock Input is PLLA */ /* Enable peripheral clock for UOTGHS */ PMC_EnablePeripheral(UOTGHS_IRQn); UOTGHS->UOTGHS_CTRL = 0x0; /* Enable PLL 480 MHz */ PMC->CKGR_UCKR = CKGR_UCKR_UPLLEN | CKGR_UCKR_UPLLCOUNT(0xF); /* Wait that PLL is considered locked by the PMC */ while( !(PMC->PMC_SR & PMC_SR_LOCKU) ); /* Enable peripheral clock for UOTGHS */ PMC_EnablePeripheral(UOTGHS_IRQn); /* Output example information */ printf( "-- UOTGHS Library Example %s --\n\r", SOFTPACK_VERSION ) ; printf( "-- %s\n\r", BOARD_NAME ) ; printf( "-- Compiled: %s %s --\n\r", __DATE__, __TIME__ ) ; /* UOTGHS pins */ PIO_PinConfigure( pUOTGHSPins, PIO_LISTSIZE( pUOTGHSPins ) ); if ( PIO_PinGet(&pUOTGHS_Fault) == 0 ) { TRACE_OTG("UOTGHS_Fault = 0 (active low ERROR FLAG !\r\n"); TRACE_OTG("Undervoltage, Soft Start, Overcurrent, or Overtemperature\r\n"); while(1); } /* Enable interrupt */ NVIC_EnableIRQ(UOTGHS_IRQn); /* Initialize USB task */ usb_task_init(); #if USB_DEVICE_FEATURE == ENABLED device_template_task_init(); #endif #if USB_HOST_FEATURE == ENABLED host_template_task_init(); #endif #ifdef FREERTOS_USED /* Start OS scheduler */ vTaskStartScheduler(); TRACE_OTG("FreeRTOS returned\n\r"); return 42; #else /* No OS here. Need to call each task in round-robin mode. */ while (TRUE) { usb_task(); #if USB_DEVICE_FEATURE == ENABLED device_template_task(); #endif #if USB_HOST_FEATURE == ENABLED host_template_task(); #endif } #endif /* FREERTOS_USED */ }
/** * \brief gmac_uip_telnetd example entry point. * * \return Unused (ANSI-C compatibility). */ int main(void) { uip_ipaddr_t ipaddr; struct timer periodic_timer, arp_timer; uint32_t i; struct uip_eth_addr OrigiGMacAddr; /* Disable watchdog */ WDT_Disable(WDT); SCB_EnableICache(); SCB_EnableDCache(); TimeTick_Configure(); printf("-- GMAC uIP Telnetd Example %s --\n\r", SOFTPACK_VERSION); printf("-- %s\n\r", BOARD_NAME); printf("-- Compiled: %s %s With %s--\n\r", __DATE__, __TIME__ , COMPILER_NAME); /* Configure systick for 1 ms. */ TimeTick_Configure(); /* Configure TWI pins. */ PIO_Configure(twiPins, PIO_LISTSIZE(twiPins)); /* Enable TWI */ PMC_EnablePeripheral(BOARD_ID_TWI_EEPROM); TWI_ConfigureMaster(BOARD_BASE_TWI_EEPROM, TWCK, BOARD_MCK); TWID_Initialize(&twid, BOARD_BASE_TWI_EEPROM); /* Display MAC & IP settings */ TWID_Read(&twid, AT24MAC_SERIAL_NUM_ADD, 0x9A, 1, OrigiGMacAddr.addr, PAGE_SIZE, 0); if ((OrigiGMacAddr.addr[0] == 0xFC) && (OrigiGMacAddr.addr[1] == 0xC2) && (OrigiGMacAddr.addr[2] == 0x3D)) { for (i = 0; i < 6; i++) GMacAddress.addr[i] = OrigiGMacAddr.addr[i]; } printf("-- MAC %x:%x:%x:%x:%x:%x\n\r", GMacAddress.addr[0], GMacAddress.addr[1], GMacAddress.addr[2], GMacAddress.addr[3], GMacAddress.addr[4], GMacAddress.addr[5]); #ifndef __DHCPC_H__ printf(" - Host IP %d.%d.%d.%d\n\r", HostIpAddress[0], HostIpAddress[1], HostIpAddress[2], HostIpAddress[3]); printf(" - Router IP %d.%d.%d.%d\n\r", RoutIpAddress[0], RoutIpAddress[1], RoutIpAddress[2], RoutIpAddress[3]); printf(" - Net Mask %d.%d.%d.%d\n\r", NetMask[0], NetMask[1], NetMask[2], NetMask[3]); #endif /* System devices initialize */ gmac_tapdev_setmac((uint8_t *)GMacAddress.addr); gmac_tapdev_init(); clock_init(); timer_set(&periodic_timer, CLOCK_SECOND / 2); timer_set(&arp_timer, CLOCK_SECOND * 10); /* Init uIP */ uip_init(); #ifdef __DHCPC_H__ printf("P: DHCP Supported\n\r"); uip_ipaddr(ipaddr, 0, 0, 0, 0); uip_sethostaddr(ipaddr); uip_ipaddr(ipaddr, 0, 0, 0, 0); uip_setdraddr(ipaddr); uip_ipaddr(ipaddr, 0, 0, 0, 0); uip_setnetmask(ipaddr); #else /* Set the IP address of this host */ uip_ipaddr(ipaddr, HostIpAddress[0], HostIpAddress[1], HostIpAddress[2], HostIpAddress[3]); uip_sethostaddr(ipaddr); uip_ipaddr(ipaddr, RoutIpAddress[0], RoutIpAddress[1], RoutIpAddress[2], RoutIpAddress[3]); uip_setdraddr(ipaddr); uip_ipaddr(ipaddr, NetMask[0], NetMask[1], NetMask[2], NetMask[3]); uip_setnetmask(ipaddr); #endif uip_setethaddr(GMacAddress); _app_init(); while (1) { uip_len = gmac_tapdev_read(); if (uip_len > 0) { if (BUF->type == htons(UIP_ETHTYPE_IP)) { uip_arp_ipin(); uip_input(); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if (uip_len > 0) { uip_arp_out(); gmac_tapdev_send(); } } else if (BUF->type == htons(UIP_ETHTYPE_ARP)) { uip_arp_arpin(); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if (uip_len > 0) gmac_tapdev_send(); } } else if (timer_expired(&periodic_timer)) { timer_reset(&periodic_timer); for (i = 0; i < UIP_CONNS; i++) { uip_periodic(i); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if (uip_len > 0) { uip_arp_out(); gmac_tapdev_send(); } } #if UIP_UDP for (i = 0; i < UIP_UDP_CONNS; i++) { uip_udp_periodic(i); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if (uip_len > 0) { uip_arp_out(); gmac_tapdev_send(); } } #endif /* UIP_UDP */ /* Call the ARP timer function every 10 seconds. */ if (timer_expired(&arp_timer)) { timer_reset(&arp_timer); uip_arp_timer(); } } } }