void MyCyclone_Init(void) { // Configure Reset Pin = GPIO_2[10] = RD7 mPORTDClearBits(RST_FPGA); mPORTDSetPinsDigitalOut(RST_FPGA); // Do a Reset mPORTDSetBits(RST_FPGA); mPORTDClearBits(RST_FPGA); // Do Interrupts Initialization // Set RD8/INT1 and RD9/INT2 as inputs mPORTDSetPinsDigitalIn(BIT_8 | BIT_9); // Clear corresponding bits in INTCON for falling edge trigger INTCONCLR = _INTCON_INT1EP_MASK | _INTCON_INT2EP_MASK; // Set up interrupt prioirty and sub-priority INTSetVectorPriority(INT_EXTERNAL_1_VECTOR, My_INT_EXTERNAL_1_PRIORITY); INTSetVectorSubPriority(INT_EXTERNAL_1_VECTOR, My_INT_EXTERNAL_1_SUB_PRIORITY); INTSetVectorPriority(INT_EXTERNAL_2_VECTOR, My_INT_EXTERNAL_2_PRIORITY); INTSetVectorSubPriority(INT_EXTERNAL_2_VECTOR, My_INT_EXTERNAL_2_SUB_PRIORITY); // Clear the interrupt flags INTClearFlag(INT_INT1); INTClearFlag(INT_INT2); // Enable INT1 & INT2 INTEnable(INT_INT1, INT_ENABLED); INTEnable(INT_INT2, INT_ENABLED); // Enable KEY0 and KEY1 interrupts and IOs of the MyExpansionBoard_IO_v2 MyCyclone_Write(CYCLONE_CONFIG,CYCLONE_ENABLE_INT_KEY0 | CYCLONE_ENABLE_INT_KEY1 | CYCLONE_ENABLE_IO_AB | CYCLONE_ENABLE_IO_CD); }
void InitApp(void) { /* Initialize peripherals */ // Configure UART modules UARTConfigure(UART_CMD_MODULE_ID, UART_ENABLE_PINS_TX_RX_ONLY); UARTSetFifoMode(UART_CMD_MODULE_ID, UART_INTERRUPT_ON_TX_NOT_FULL | UART_INTERRUPT_ON_RX_NOT_EMPTY); UARTSetLineControl(UART_CMD_MODULE_ID, UART_DATA_SIZE_8_BITS | UART_PARITY_NONE | UART_STOP_BITS_1); UARTSetDataRate(UART_CMD_MODULE_ID, GetPeripheralClock(), DESIRED_CMD_BAUDRATE); UARTEnable(UART_CMD_MODULE_ID, UART_ENABLE_FLAGS(UART_PERIPHERAL | UART_RX | UART_TX)); UARTConfigure(UART_WIFI_MODULE_ID, UART_ENABLE_PINS_TX_RX_ONLY); UARTSetFifoMode(UART_WIFI_MODULE_ID, UART_INTERRUPT_ON_TX_NOT_FULL | UART_INTERRUPT_ON_RX_NOT_EMPTY); UARTSetLineControl(UART_WIFI_MODULE_ID, UART_DATA_SIZE_8_BITS | UART_PARITY_NONE | UART_STOP_BITS_1); UARTSetDataRate(UART_WIFI_MODULE_ID, GetPeripheralClock(), DESIRED_WIFI_BAUDRATE); UARTEnable(UART_WIFI_MODULE_ID, UART_ENABLE_FLAGS(UART_PERIPHERAL | UART_RX | UART_TX)); // Configure UART Interrupts INTEnable(INT_SOURCE_UART_RX(UART_CMD_MODULE_ID), INT_ENABLED); INTSetVectorPriority(INT_VECTOR_UART(UART_CMD_MODULE_ID), INT_PRIORITY_LEVEL_2); INTSetVectorSubPriority(INT_VECTOR_UART(UART_CMD_MODULE_ID), INT_SUB_PRIORITY_LEVEL_0); INTEnable(INT_SOURCE_UART_RX(UART_WIFI_MODULE_ID), INT_ENABLED); INTSetVectorPriority(INT_VECTOR_UART(UART_WIFI_MODULE_ID), INT_PRIORITY_LEVEL_1); INTSetVectorSubPriority(INT_VECTOR_UART(UART_WIFI_MODULE_ID), INT_SUB_PRIORITY_LEVEL_0); // Make the requests to Wifi service - they will be picked up when the service needs them ConnectToAccessPoint(&routerConnection, &DefaultWifiService); SendHttpRequest(&DnsDynamicHttpRequest, &DefaultWifiService); }
void hal_sys_init(){ SYSTEMConfigPerformance(SYS_CLK); INTSetVectorPriority(INT_VECTOR_UART(UART3),3); INTSetVectorPriority(INT_VECTOR_UART(UART5), 3); INTConfigureSystem(INT_SYSTEM_CONFIG_MULT_VECTOR); INTDisableInterrupts(); }
BOOL ConfigSPIComms(void) { SpiChnClose(RPI_SPI_CHANNEL); /* do I need to configure this? */ INTEnable(INT_SOURCE_SPI_RX(RPI_SPI_CHANNEL),INT_DISABLED); INTEnable(INT_SOURCE_SPI_TX(RPI_SPI_CHANNEL),INT_DISABLED); INTEnable(INT_SOURCE_SPI_ERROR(RPI_SPI_CHANNEL),INT_DISABLED); INTEnable(INT_SOURCE_SPI(RPI_SPI_CHANNEL),INT_DISABLED); SPI_DATA_IN_DIRECTION = TRIS_IN; SPI_DATA_OUT_DIRECTION = TRIS_OUT; SPI_CLOCK_IN_DIRECTION = TRIS_IN; SPI_SELECT_IN_DIRECTION = TRIS_IN; SPI.RXCount=0; SPI.TXCount=0; SPI.address=0; SPI.command=TRISTHIS_SPI_NO_COMMAND; SpiChnOpen(RPI_SPI_CHANNEL, SPI_OPEN_SLVEN|SPI_OPEN_CKE_REV|SPI_OPEN_MODE8|SPI_OPEN_SSEN, 0); //TODO: Not acting consistently? RPI needs to send -b 8 -H parameters to spidev /* configure interrupts */ INTSetVectorPriority(INT_VECTOR_SPI(RPI_SPI_CHANNEL), INT_PRIORITY_LEVEL_3); INTSetVectorSubPriority(INT_VECTOR_SPI(RPI_SPI_CHANNEL), INT_SUB_PRIORITY_LEVEL_1); INTClearFlag(INT_SOURCE_SPI_RX(RPI_SPI_CHANNEL)); INTEnable(INT_SOURCE_SPI_RX(RPI_SPI_CHANNEL),INT_ENABLED); INTClearFlag(INT_SOURCE_SPI_TX(RPI_SPI_CHANNEL)); INTClearFlag(INT_SOURCE_SPI_ERROR(RPI_SPI_CHANNEL)); INTClearFlag(INT_SOURCE_SPI(RPI_SPI_CHANNEL)); //INTEnable(INT_SOURCE_SPI(RPI_SPI_CHANNEL),INT_ENABLED); /* configure change notice, as I can't figure out any other way to */ /* trigger the beginning of the slave select with just the SPI peripheral */ /* buuut the change notice pins are not on the SS pins, so a white wire is*/ /* needed */ /* tie chip enable CE0 to pin20/RE5 CE1 */ SPI_SELECT_CN_DIRECTION=TRIS_IN; CNCONbits.w=0; CNCONSET=_CNCON_ON_MASK; CNENbits.w=0; CNENSET=_CNEN_CNEN7_MASK; CNTemp=CE_PORT; /* read for change notice */ RPI_SPI_RX_OVERFLOW_CLEAR; SPI1CONbits.STXISEL=0b01; SPI.status.w=0; INTClearFlag(INT_CN); INTSetVectorPriority(INT_CHANGE_NOTICE_VECTOR, INT_PRIORITY_LEVEL_2); INTSetVectorSubPriority(INT_CHANGE_NOTICE_VECTOR, INT_SUB_PRIORITY_LEVEL_1); return TRUE; }
void configureRTC() { RtccInit(); while (RtccGetClkStat() != RTCC_CLK_ON); //printf("RTCC OK\r\n"); // set time and date // time is MSb: hour, min, sec, rsvd. date is MSb: year, mon, mday, wday. // please note that the rsvd field has to be 0 in the time field! // Time is in Hex! RtccOpen(0x17040000, 0x08100604, 0); // set the RTCC priority in the INT controller INTSetVectorPriority(INT_RTCC_VECTOR, INT_PRIORITY_LEVEL_5); // set the RTCC sub-priority in the INT controller INTSetVectorSubPriority(INT_RTCC_VECTOR, INT_SUB_PRIORITY_LEVEL_1); // enable the RTCC event interrupts in the INT controller. INTEnable(INT_RTCC, INT_ENABLED); // enable alaram or endless alaram - // it allows the alarm rpt to move back to the beginning //RtccChimeDisable(); - this is now changeable // how much repats - 0 means run the alarm only once //RtccSetAlarmRptCount(0); //the above means once we have alarm interrupt the alarm will be disabled // used for marching (i.e. window) when cpmparing RtccSetAlarmRpt(RTCC_RPT_MON); }
void WF_EintInit(void) { /* disable the external interrupt */ INTEnable(INT_INT1, INT_DISABLED); // disable interrupt #if !defined(TCPIP_STACK_USE_EVENT_NOTIFICATION) SYS_INT_DynamicRegister(MRFWB0M_INT_SOURCE, WF_NoEventISR, 0); // #else the MRF ISR is already hooked by MRF24W_MACEventInit()! #endif /* configure IO pin as input and External Interrupt pin*/ /* set the I/O high since we do not have pull-ups */ INT1Rbits.INT1R = 0x0d; //select INT1 pin = RPE8 ANSELEbits.ANSE8 = 0; /* configure IO pin as input and External Interrupt pin*/ WF_INT_IO = 1; // PORTEbits.RE8 = 1; /* configure IO pin as input and External Interrupt pin*/ WF_INT_TRIS = 1; //TRISEbits.TRISE8 = 1 ; // ; /* set the I/O high since we do not have pull-ups */ WF_INT_EDGE = 0; //INTCONbits.INT1EP = 0; /* falling edge triggered */ /* clear and enable the interrupt */ INTClearFlag(INT_INT1) ; // clear status INTSetVectorPriority(INT_EXTERNAL_1_VECTOR, 5); //set security level to 5 INTSetVectorSubPriority(INT_EXTERNAL_1_VECTOR,1); //set sub_security level to 1 // INTEnable(INT_INT1, INT_ENABLED); // Should not enable interrupt here //--- }
/** * @Function AD_Init * @param None * @return SUCCESS or ERROR * @brief Initializes the A/D subsystem and enable battery voltage monitoring. * @author Max Dunne, 2013.08.10 */ char AD_Init(void) { if (ADActive) { return ERROR; } int pin = 0; //ensure that the battery monitor is active ActivePins = BAT_VOLTAGE_MONITOR; ADActive = TRUE; AD_SetPins(); for (pin = 0; pin < NUM_AD_PINS; pin++) { ADValues[pin] = -1; } INTEnable(INT_AD1, INT_DISABLED); INTClearFlag(INT_AD1); INTSetVectorPriority(INT_ADC_VECTOR, 1); INTSetVectorSubPriority(INT_ADC_VECTOR, 3); INTEnable(INT_AD1, INT_ENABLED); EnableADC10(); ADNewData = FALSE; //wait for first reading to ensure battery monitor starts in the right spot while (!AD_IsNewDataReady()) { #ifdef AD_DEBUG_VERBOSE PutChar('.'); #endif } //set the first values for the battery monitor filter Filt_BatVoltage = AD_ReadADPin(BAT_VOLTAGE_MONITOR); CurFilt_BatVoltage = Filt_BatVoltage; PrevFilt_BatVoltage = Filt_BatVoltage; return SUCCESS; }
void SERIAL_Init(void) { transmitBuffer = (struct CircBuffer*) &outgoingUart; //set up buffer for receive newCircBuffer(transmitBuffer); receiveBuffer = (struct CircBuffer*) &incomingUart; //set up buffer for transmit newCircBuffer(receiveBuffer); UARTConfigure(UART1, 0x00); UARTSetDataRate(UART1, F_PB, 115200); UARTSetFifoMode(UART1, UART_INTERRUPT_ON_RX_NOT_EMPTY | UART_INTERRUPT_ON_TX_BUFFER_EMPTY); INTSetVectorPriority(INT_UART_1_VECTOR, INT_PRIORITY_LEVEL_4); //set the interrupt priority //RPC5R = 1; PPSOutput(1, RPC5, U1TX); PORTSetPinsDigitalIn(IOPORT_C, BIT_3); //U1RXRbits.U1RXR = 0b111; PPSInput(3, U1RX, RPC3); UARTEnable(UART1, UART_ENABLE_FLAGS(UART_PERIPHERAL | UART_TX | UART_RX)); INTEnable(INT_U1RX, INT_ENABLED); //INTSetFlag(INT_U1RX); //INTEnable(INT_U1TX, INT_ENABLED); //PutChar('z'); }
//****************************************************************************** //Public Function Definitions //****************************************************************************** void FIFOUART1_initialize() { UARTConfigure(UART1, UART_ENABLE_PINS_TX_RX_ONLY); UARTSetLineControl(UART1, UART_DATA_SIZE_8_BITS | //Sets the data transfer size to 8-bits per frame.� UART_PARITY_NONE | //Disables parity bit generation.� UART_STOP_BITS_1); //1 stop bit per frame (default).� UARTSetDataRate(UART1, GetPeripheralClock(), FIFOUART1_BAUD_RATE); //Interrupt Stuff INTSetVectorPriority(INT_UART_1_VECTOR, INT_PRIORITY_LEVEL_5); INTSetVectorSubPriority(INT_UART_1_VECTOR, INT_SUB_PRIORITY_LEVEL_0); INTClearFlag(INT_U1RX); INTClearFlag(INT_U1TX); //configure what triggers UART1 itnerrupts UARTSetFifoMode(UART1, UART_INTERRUPT_ON_TX_BUFFER_EMPTY | //TX interrupt will occur when the TX buffer is empty.� UART_INTERRUPT_ON_RX_NOT_EMPTY); //RX interrupt will occur whenever the RX buffer has any data.� //Enable UART1 Rx Interrupt INTEnable(INT_U1RX, INT_ENABLED); //Enable UART1 Tx Interrupt //INTEnable(INT_U1TX, INT_ENABLED); UARTEnable(UART1, UART_ENABLE_FLAGS(UART_PERIPHERAL | UART_RX | UART_TX)); }
void MyMIWI_Init(void) { // Configure Pins for MRF24J40MB mPORTESetBits(RST_MIWI); mPORTESetPinsDigitalOut(RST_MIWI); mPORTBSetBits(MIWI_WAKE); mPORTBSetPinsDigitalOut(MIWI_WAKE); // Configure the INT3 controller for MIWI // Set RD10/INT3 as input mPORTDSetPinsDigitalIn(BIT_10); // Clear corresponding bits in INTCON for falling edge trigger INTCONCLR = _INTCON_INT3EP_MASK; // Set up interrupt prioirty and sub-priority INTSetVectorPriority(INT_EXTERNAL_3_VECTOR, My_INT_EXTERNAL_3_PRIORITY); INTSetVectorSubPriority(INT_EXTERNAL_3_VECTOR, My_INT_EXTERNAL_3_SUB_PRIORITY); // Clear the interrupt flags INTClearFlag(INT_INT3); // Enable INT3 INTEnable(INT_INT3, INT_ENABLED); // WARNING : Change in file MRF24J40.c in Microchip Application Library // the line : void __ISR(_EXTERNAL_1_VECTOR, ipl4) _INT1Interrupt(void) // by : void __ISR(_EXTERNAL_3_VECTOR, ipl4) _INT3Interrupt(void) }
void serial_init(void) { // Initialisation du fifo de réception InitFifo ( &descrFifoRX, FIFO_RX_SIZE, fifoRX, 0 ); // Initialisation du fifo d'émission InitFifo ( &descrFifoTX, FIFO_TX_SIZE, fifoTX, 0 ); // Utilisation des fonctions séparées (XC32) // ========================================= UARTConfigure(UART2, UART_ENABLE_HIGH_SPEED | UART_ENABLE_PINS_TX_RX_ONLY ); // UARTSetFifoMode(UART2, UART_INTERRUPT_ON_TX_BUFFER_EMPTY | UART_INTERRUPT_ON_RX_HALF_FULL ); // Remarque HALF_FULL ne fonctionne pas // Pour INT RX au 3/4 UARTSetFifoMode(UART2, UART_INTERRUPT_ON_TX_BUFFER_EMPTY | UART_INTERRUPT_ON_RX_3_QUARTER_FULL ); // Pour INT RX dés que min 1 char // UARTSetFifoMode(UART2, UART_INTERRUPT_ON_TX_BUFFER_EMPTY | UART_INTERRUPT_ON_RX_NOT_EMPTY ); UARTSetLineControl(UART2, UART_DATA_SIZE_8_BITS | UART_PARITY_NONE | UART_STOP_BITS_1); UINT32 ActualBaudRate = UARTSetDataRate(UART2, PB_FREQ, 9600); UARTEnable(UART2, UART_ENABLE_FLAGS(UART_PERIPHERAL | UART_RX | UART_TX)); // Configuration Int UART2 avec les fonctions séparées // =================================================== // Configure UART RX Interrupt INTEnable(INT_SOURCE_UART_RX(UART2), INT_ENABLED); INTSetVectorPriority(INT_VECTOR_UART(UART2), INT_PRIORITY_LEVEL_5); INTSetVectorSubPriority(INT_VECTOR_UART(UART2), INT_SUB_PRIORITY_LEVEL_0); } // InitComm
//****************************************************************************** //Public Function Definitions //****************************************************************************** void Orientation_start() { //Setup Timer5 INTClearFlag(INT_T5); INTSetVectorPriority(INT_TIMER_5_VECTOR, INT_PRIORITY_LEVEL_3); INTSetVectorSubPriority(INT_TIMER_5_VECTOR, INT_SUB_PRIORITY_LEVEL_1); INTEnable(INT_T5, INT_ENABLED); //Turn on clock OpenTimer5(T5_ON | T5_SOURCE_INT | T1_PS_1_64, 12500);//50hz @ 40MHz //OpenTimer5(T5_ON | T5_SOURCE_INT | T5_PS_1_32, 3333); //375hz @ 40MHz (0.0026664 sec) }
/**************************************************************************** * Function: TCPIPEventInit * * PreCondition: None. * * Input: intPri - interrupt priority to use * intSubPri - interrupt sub-priority to use * * Output: None * * Side Effects: None * * Overview: This function initializes the ethernet event notification. * * Note: None ******************************************************************************/ void TCPIPEventInit(int intPri, int intSubPri) { INTEnable(INT_ETHERNET, INT_DISABLED); // stop Eth ints INTClearFlag(INT_ETHERNET); INTSetVectorPriority(INT_ETH_VECTOR, (INT_PRIORITY_LEVEL_1-1)+intPri); INTSetVectorSubPriority(INT_ETH_VECTOR, INT_SUB_PRIORITY_LEVEL_0+intSubPri); _TcpNotifyFnc=0; _TcpEnabledEvents=_TcpPendingEvents=0; }
void CommunicationLoop_initialize() { FIFOUART1_initialize(); //Setup Timer4 INTClearFlag(INT_T4); INTSetVectorPriority(INT_TIMER_4_VECTOR, INT_PRIORITY_LEVEL_4); INTSetVectorSubPriority(INT_TIMER_4_VECTOR, INT_SUB_PRIORITY_LEVEL_0); INTEnable(INT_T4, INT_ENABLED); //Turn on clock OpenTimer4(T4_ON | T4_SOURCE_INT | T4_PS_1_64, 0x4FFF); }
static ALWAYSINLINE MUST_CHECK s32 nu__Can__init(struct nu__Can *c, u32 bus_speed_hz, CAN_BIT_CONFIG *timings, CAN_MODULE_EVENT interrupt_events, INT_PRIORITY int_priority, CAN_MODULE_FEATURES features) { s32 err; CANEnableModule(c->module, TRUE); if ((err = go_config_mode(c)) <0) { go_normal_mode(c); return err; } CANSetSpeed(c->module, timings, NU_HZ, bus_speed_hz); CANAssignMemoryBuffer(c->module, c->buf, sizeof(c->buf)); if (interrupt_events) { INT_VECTOR int_vec; INT_SOURCE int_src; CANEnableModuleEvent(CAN1, interrupt_events, TRUE); switch (c->module) { case CAN1: int_vec = INT_CAN_1_VECTOR; int_src = INT_CAN1; break; case CAN2: int_vec = INT_CAN_2_VECTOR; int_src = INT_CAN2; break; case CAN_NUMBER_OF_MODULES: default: break; } INTSetVectorPriority(int_vec, int_priority); INTSetVectorSubPriority(int_vec, INT_SUB_PRIORITY_LEVEL_0); INTEnable(int_src, INT_ENABLED); } enable_features(c, features); if ((err = go_normal_mode(c)) < 0) return err; return 0; }
void setup(bool use_interrupt = false, INT_PRIORITY int_priority = INT_PRIORITY_DISABLED, UART_CONFIGURATION uart_config = (UART_CONFIGURATION)UART_ENABLE_PINS_TX_RX_ONLY, UART_FIFO_MODE interrupt_modes = (UART_FIFO_MODE)0, UART_LINE_CONTROL_MODE line_control_modes = (UART_LINE_CONTROL_MODE)(UART_DATA_SIZE_8_BITS|UART_PARITY_NONE|UART_STOP_BITS_1), UART_ENABLE_MODE enable_modes = (UART_ENABLE_MODE)(UART_PERIPHERAL|UART_RX|UART_TX)) { UARTConfigure(module, uart_config); UARTSetFifoMode(module, interrupt_modes); UARTSetLineControl(module, line_control_modes); UARTSetDataRate(module, param::pbus_hz(), baud); UARTEnable(module, (UART_ENABLE_MODE) UART_ENABLE_FLAGS(enable_modes)); if (use_interrupt) { INT_VECTOR int_vect; INT_SOURCE int_src; switch(module) { case UART1: int_vect = INT_UART_1_VECTOR; int_src = INT_U1RX; break; case UART2: int_vect = INT_UART_2_VECTOR; int_src = INT_U2RX; break; case UART3: int_vect = INT_UART_3_VECTOR; int_src = INT_U3RX; break; case UART4: int_vect = INT_UART_4_VECTOR; int_src = INT_U4RX; break; case UART5: int_vect = INT_UART_5_VECTOR; int_src = INT_U5RX; break; case UART6: int_vect = INT_UART_6_VECTOR; int_src = INT_U6RX; break; case UART_NUMBER_OF_MODULES: default: return; // WTF } INTEnable(int_src, INT_ENABLED); INTSetVectorPriority(int_vect, int_priority); INTSetVectorSubPriority(int_vect, INT_SUB_PRIORITY_LEVEL_0); } }
// ***************************************************************************** // Initialize the Console serial port (BAUDRATE) // ***************************************************************************** void InitConsole(UINT32 baud) { UARTConfigure(UART_CONSOLE, UART_ENABLE_PINS_TX_RX_ONLY | UART_ENABLE_HIGH_SPEED); UARTSetFifoMode(UART_CONSOLE, UART_INTERRUPT_ON_TX_NOT_FULL | UART_INTERRUPT_ON_RX_NOT_EMPTY); UARTSetLineControl(UART_CONSOLE, UART_DATA_SIZE_8_BITS | UART_PARITY_NONE | UART_STOP_BITS_1); UARTSetDataRate(UART_CONSOLE, GetPeripheralClock(), baud); #ifdef DEBUG_ALLOW_USER_INPUT INTEnable(INT_SOURCE_UART_RX(UART_CONSOLE), INT_ENABLED); INTSetVectorPriority(INT_VECTOR_UART(UART_CONSOLE), INT_PRIORITY_LEVEL_2); INTSetVectorSubPriority(INT_VECTOR_UART(UART_CONSOLE), INT_SUB_PRIORITY_LEVEL_0); INTEnable(INT_SOURCE_UART_TX(UART_CONSOLE), INT_DISABLED);//Disable TX interrupt! #endif UARTEnable(UART_CONSOLE, UART_ENABLE_FLAGS(UART_PERIPHERAL | UART_RX | UART_TX)); }
void CAN1Init(void) { CAN_BIT_CONFIG canBitConfig; UINT baudPrescalar; CANEnableModule(CAN1, TRUE); CANSetOperatingMode(CAN1, CAN_CONFIGURATION); while(CANGetOperatingMode(CAN1) != CAN_CONFIGURATION); // Standard Values canBitConfig.phaseSeg2Tq = CAN_BIT_3TQ; canBitConfig.phaseSeg1Tq = CAN_BIT_5TQ; canBitConfig.propagationSegTq = CAN_BIT_1TQ; canBitConfig.phaseSeg2TimeSelect = TRUE; canBitConfig.sample3Time = TRUE; canBitConfig.syncJumpWidth = CAN_BIT_1TQ; // Set speed to 1Mbit/s CANSetSpeed(CAN1, &canBitConfig, SYSTEM_FREQ, CAN_BUS_SPEED); // 256 bytes of storage space CANAssignMemoryBuffer(CAN1, CAN1MessageFifoArea, (2*8*16)); CANConfigureChannelForTx(CAN1, CAN_CHANNEL0, 8, CAN_TX_RTR_DISABLED, CAN_LOW_MEDIUM_PRIORITY); CANConfigureChannelForRx(CAN1, CAN_CHANNEL1, 8, CAN_RX_FULL_RECEIVE); CANConfigureFilter(CAN1, CAN_FILTER0, 0x5F1, CAN_SID); CANConfigureFilterMask(CAN1, CAN_FILTER_MASK0, 0x7FF, CAN_SID, CAN_FILTER_MASK_IDE_TYPE); CANLinkFilterToChannel(CAN1, CAN_FILTER0, CAN_FILTER_MASK0, CAN_CHANNEL1); CANEnableFilter(CAN1, CAN_FILTER0, TRUE); CANEnableChannelEvent(CAN1, CAN_CHANNEL1, CAN_RX_CHANNEL_NOT_EMPTY, TRUE); CANEnableModuleEvent(CAN1, CAN_RX_EVENT, TRUE); INTSetVectorPriority(INT_CAN_1_VECTOR, INT_PRIORITY_LEVEL_4); INTSetVectorSubPriority(INT_CAN_1_VECTOR, INT_SUB_PRIORITY_LEVEL_0); INTEnable(INT_CAN1, INT_ENABLED); CANSetOperatingMode(CAN1, CAN_NORMAL_OPERATION); while(CANGetOperatingMode(CAN1) != CAN_NORMAL_OPERATION); }
// Initialize the serial port // Note: the NU32v2 is hard wired to use UART3 (= UART2A) void initSerialNU32v2() { int pbClk; // Configure the system performance pbClk = SYSTEMConfigPerformance(SYS_FREQ); UARTConfigure(UART3, UART_ENABLE_PINS_TX_RX_ONLY); UARTSetFifoMode(UART3, UART_INTERRUPT_ON_TX_DONE | UART_INTERRUPT_ON_RX_NOT_EMPTY); UARTSetLineControl(UART3, UART_DATA_SIZE_8_BITS | UART_PARITY_NONE | UART_STOP_BITS_1); UARTSetDataRate(UART3, pbClk, DESIRED_BAUDRATE_NU32); UARTEnable(UART3, UART_ENABLE_FLAGS(UART_PERIPHERAL | UART_RX | UART_TX)); // Configure UART3 RX Interrupt INTEnable(INT_U3RX, INT_ENABLED); INTSetVectorPriority(INT_UART_3_VECTOR, INT_PRIORITY_LEVEL_2); INTSetVectorSubPriority(INT_UART_3_VECTOR, INT_SUB_PRIORITY_LEVEL_0); }
void InitBluetooth(void) { #if DESIRED_BAUDRATE == 9600 mPORTBSetPinsDigitalOut(BIT_9); mPORTBSetBits(BIT_9);// BT high level, the reset polarity is active low mPORTASetPinsDigitalOut(BIT_3); mPORTASetBits(BIT_3);// Set Baud rate (high = force 9,600, low = 115 K or firmware setting) mPORTASetPinsDigitalOut(BIT_2); mPORTASetBits(BIT_2);// Set BT master (high = auto-master mode) #elif DESIRED_BAUDRATE == 115200 mPORTBSetPinsDigitalOut(BIT_9); mPORTBSetBits(BIT_9);// BT high level, the reset polarity is active low mPORTASetPinsDigitalOut(BIT_3); mPORTAClearBits(BIT_3);// Set Baud rate (high = force 9,600, low = 115 K or firmware setting) mPORTASetPinsDigitalOut(BIT_2); mPORTASetBits(BIT_2);// Set BT master (high = auto-master mode) #elif DESIRED_BAUDRATE ==921600 //nothing #endif UARTConfigure(UART_MODULE_ID2, UART_ENABLE_PINS_TX_RX_ONLY|UART_ENABLE_PINS_CTS_RTS); UARTConfigure(UART_MODULE_ID2, UART_ENABLE_HIGH_SPEED); UARTSetFifoMode(UART_MODULE_ID2, UART_INTERRUPT_ON_TX_NOT_FULL | UART_INTERRUPT_ON_RX_NOT_EMPTY); UARTSetLineControl(UART_MODULE_ID2, UART_DATA_SIZE_8_BITS | UART_PARITY_NONE | UART_STOP_BITS_1); UARTSetDataRate(UART_MODULE_ID2, GetPeripheralClock(), DESIRED_BAUDRATE); UARTEnable(UART_MODULE_ID2, UART_ENABLE_FLAGS(UART_PERIPHERAL | UART_RX | UART_TX)); // Configure UART RX Interrupt INTEnable(INT_SOURCE_UART_RX(UART_MODULE_ID2), INT_ENABLED); INTSetVectorPriority(INT_VECTOR_UART(UART_MODULE_ID2), INT_PRIORITY_LEVEL_2); INTSetVectorSubPriority(INT_VECTOR_UART(UART_MODULE_ID2), INT_SUB_PRIORITY_LEVEL_1); // Enable multi-vector interrupts //WriteStringXbee("*** UART Bluetooth demarre ***\r\n"); }
int main(void) { BOARD_Init(); // Configure Timer 1 using PBCLK as input. This default period will make the LEDs blink at a // pretty reasonable rate to start. OpenTimer1(T1_ON | T1_SOURCE_INT | T1_PS_1_8, 0xFFFF); // Set up the timer interrupt with a priority of 4. INTClearFlag(INT_T1); INTSetVectorPriority(INT_TIMER_1_VECTOR, INT_PRIORITY_LEVEL_4); INTSetVectorSubPriority(INT_TIMER_1_VECTOR, INT_SUB_PRIORITY_LEVEL_0); INTEnable(INT_T1, INT_ENABLED); // Enable interrupts for the ADC ConfigIntADC10(ADC_INT_PRI_2 | ADC_INT_SUB_PRI_0 | ADC_INT_ON); // Set B2 to an input so AN0 can be used by the ADC. TRISBCLR = 1 << 2; // Configure and start the ADC // Read AN0 as sample a. We don't use alternate sampling, so setting sampleb is pointless. SetChanADC10(ADC_CH0_NEG_SAMPLEA_NVREF | ADC_CH0_POS_SAMPLEA_AN2); OpenADC10( ADC_MODULE_ON | ADC_IDLE_CONTINUE | ADC_FORMAT_INTG16 | ADC_CLK_AUTO | ADC_AUTO_SAMPLING_ON, ADC_VREF_AVDD_AVSS | ADC_OFFSET_CAL_DISABLE | ADC_SCAN_OFF | ADC_SAMPLES_PER_INT_8 | ADC_BUF_16 | ADC_ALT_INPUT_OFF, ADC_SAMPLE_TIME_29 | ADC_CONV_CLK_PB | ADC_CONV_CLK_51Tcy2, ENABLE_AN2_ANA, SKIP_SCAN_ALL); EnableADC10(); /*************************************************************************************************** * Your code goes in between this comment and the following one with asterisks. **************************************************************************************************/ printf("Welcome to the Lab 6 Extra Credit blank. Please remove before starting."); /*************************************************************************************************** * Your code goes in between this comment and the preceding one with asterisks **************************************************************************************************/ while (1); }
void initUART() { // PPS map UART1 pins RPB3R=0x01; // PPS MAP TX to RPB3 U1RXR=0x04; // PPS MAP RX to RPB2 // Setup UART1 UARTConfigure(UART1, UART_ENABLE_PINS_TX_RX_ONLY); UARTSetFifoMode(UART1, UART_INTERRUPT_ON_RX_NOT_EMPTY); UARTSetLineControl(UART1, UART_DATA_SIZE_8_BITS | UART_PARITY_NONE | UART_STOP_BITS_1); UARTSetDataRate(UART1, 48000000, 115200); UARTEnable(UART1, UART_ENABLE_FLAGS(UART_ENABLE | UART_PERIPHERAL | UART_RX | UART_TX)); INTEnable(INT_SOURCE_UART_RX(UART1), INT_ENABLED); INTSetVectorPriority(INT_VECTOR_UART(UART1), INT_PRIORITY_LEVEL_2); INTSetVectorSubPriority(INT_VECTOR_UART(UART1), INT_SUB_PRIORITY_LEVEL_0); }
void NU32_EnableUART2Interrupt(void) { // turn off the module to change the settings UARTEnable(UART2, UART_ENABLE_FLAGS(UART_DISABLE)); // Configure UART1 RX Interrupt // UARTConfigure(UART2, UART_ENABLE_PINS_CTS_RTS ); UARTSetFifoMode(UART2, UART_INTERRUPT_ON_TX_DONE | UART_INTERRUPT_ON_RX_NOT_EMPTY); UARTSetLineControl(UART2, UART_DATA_SIZE_8_BITS | UART_PARITY_NONE | UART_STOP_BITS_1); UARTSetDataRate(UART2, SYSCLK, 115200); UARTEnable(UART2, UART_ENABLE_FLAGS(UART_PERIPHERAL | UART_RX | UART_TX)); INTEnable(INT_U2RX, INT_ENABLED); INTSetVectorPriority(INT_UART_2_VECTOR, INT_PRIORITY_LEVEL_2); INTSetVectorSubPriority(INT_UART_2_VECTOR, INT_SUB_PRIORITY_LEVEL_0); }
extern timer * timerNew(const int TimerNumber, const int Priority) { const int TimerIndex = TimerNumber-1; timer * pTimer = &TimerList[TimerIndex]; pTimer->m_pCallback = NULL; pTimer->m_pContext = NULL; pTimer->m_TimerNumber = TimerNumber; pTimer->m_TimerIndex = TimerNumber-1; pTimer->m_InUse = true; pTimer->m_Priority = Priority; const uint16_t Vector = TimerData[TimerIndex].Vector; INTSetVectorPriority(Vector, Priority); return pTimer; }
int main(void) { BOARD_Init(); // Configure Timer 1 using PBCLK as input. This default period will make the LEDs blink at a // pretty reasonable rate to start. OpenTimer1(T1_ON | T1_SOURCE_INT | T1_PS_1_8, 0xFFFF); // Set up the timer interrupt with a priority of 4. INTClearFlag(INT_T1); INTSetVectorPriority(INT_TIMER_1_VECTOR, INT_PRIORITY_LEVEL_4); INTSetVectorSubPriority(INT_TIMER_1_VECTOR, INT_SUB_PRIORITY_LEVEL_0); INTEnable(INT_T1, INT_ENABLED); /*************************************************************************************************** * Your code goes in between this comment and the following one with asterisks. **************************************************************************************************/ int x = 0x01; LEDS_INIT(); //give the initial value checkItem.event = 0; checkItem.value = 0; int direction = RIGHT; while (1) { //set the value LEDS_SET(x); if (checkItem.event == 1) { checkItem.event = 0; //two directions if(direction == RIGHT){ x = x << 1; }else{ x = x >> 1; } } //edge case of 0x100 if((x == 0x100) && (direction == RIGHT)){ x = 0x40; direction = LEFT; } //edge case of 0x00 if((x == 0) && (direction == LEFT)){ x = 0x02; direction = RIGHT; } }
void SERIAL_Init(void) { transmitBuffer = (struct CircBuffer*) &outgoingUart; //set up buffer for receive newCircBuffer(transmitBuffer); receiveBuffer = (struct CircBuffer*) &incomingUart; //set up buffer for transmit newCircBuffer(receiveBuffer); UARTConfigure(UART1, 0x00); UARTSetDataRate(UART1, F_PB, 115200); UARTSetFifoMode(UART1, UART_INTERRUPT_ON_RX_NOT_EMPTY | UART_INTERRUPT_ON_RX_NOT_EMPTY); INTSetVectorPriority(INT_UART_1_VECTOR, INT_PRIORITY_LEVEL_4); //set the interrupt priority UARTEnable(UART1, UART_ENABLE_FLAGS(UART_PERIPHERAL | UART_TX | UART_RX)); INTEnable(INT_U1RX, INT_ENABLED); INTEnable(INT_U1TX, INT_ENABLED); }
/******************************************************************************* * FUNCTION: vUART2Init * * PARAMETERS: * ~ void * * RETURN: * ~ void * * DESCRIPTIONS: * Initialize the UART2 module. * UART 2 is used by bluetooth module. * *******************************************************************************/ void vUART2Init(void) { // Configure UART 2. UARTConfigure(UART2, UART_ENABLE_HIGH_SPEED | UART_ENABLE_PINS_TX_RX_ONLY); UARTSetFifoMode(UART2, UART_INTERRUPT_ON_TX_NOT_FULL | UART_INTERRUPT_ON_RX_NOT_EMPTY); UARTSetLineControl(UART2, UART_DATA_SIZE_8_BITS | UART_PARITY_NONE | UART_STOP_BITS_1); UARTSetDataRate(UART2, GetPeripheralClock(), BT2_BAUDRATE); UARTEnable(UART2, UART_ENABLE_FLAGS(UART_PERIPHERAL | UART_RX | UART_TX)); // Configure the interrupt. INTSetVectorPriority(INT_UART_2_VECTOR, INT_PRIORITY_LEVEL_7); INTClearFlag(INT_U2TX); INTClearFlag(INT_U2RX); INTClearFlag(INT_U2E); INTEnable(INT_U2RX, INT_ENABLED); INTEnable(INT_U2E, INT_ENABLED); }
/** * @brief If opened channels is equal to 0 let's open device, enable interrupts, * create mutex etc. If opened channels is greater than 0 just open another * channel. * * @param pUartDev Pointer to device which will be opened * @param pChannel Channel to open * @return Result value */ static retcode lldPic32ADCOpen(struct hldAdcDevice *pAdcDev, UINT8 pChannel) { UINT32 convReg, aqReg, scanFreq; assert(pAdcDev != NULL); if (pChannel > LLD_PIC32_ADC_MAX) return ERR_HLD_DEVICE_ADC_CHANNEL_NOT_EXISTS; AD1PCFG &= ~(1 << pChannel); adcInfo[pChannel].active = 1; if(openedChannels == 0) { // Enable and configure the ADC here AD1CSSL = 0xFFFF; AD1CON2 = 0b0000010000111100; convReg = (pAdcDev->config.adcClockPeriod * (configPERIPHERAL_CLOCK_HZ/1000000UL)); convReg /= (2UL*1000UL); convReg--; aqReg = pAdcDev->config.aquisitionTime / pAdcDev->config.adcClockPeriod; AD1CON3 = (convReg & 0xff) | ((aqReg & 0xff) << 8); AD1CON1 = 0b1000000011100110; DONE("LLD PIC 32 ADC device opened"); scanFreq = 1000000000UL/(pAdcDev->config.adcClockPeriod * (12+aqReg) * (LLD_PIC32_ADC_MAX+1)); LOG("LLD PIC 32 ADC Scanning frequency is %d Hz", scanFreq); // TODO: Add priority setting INTSetVectorPriority(INT_ADC_VECTOR, pAdcDev->config.intPriority); INTSetVectorSubPriority(INT_ADC_VECTOR, INT_SUB_PRIORITY_LEVEL_0); IEC1SET = 0x0002; } openedChannels++; pAdcDev->head.state |= HLD_DEVICE_STATE_RUNNING; return SUCCESS; }
int main(void) { BOARD_Init(); // Configure Timer 2 using PBCLK as input. We configure it using a 1:16 prescalar, so each timer // tick is actually at F_PB / 16 Hz, so setting PR2 to F_PB / 16 / 100 yields a .01s timer. OpenTimer2(T2_ON | T2_SOURCE_INT | T2_PS_1_16, BOARD_GetPBClock() / 16 / 100); // Set up the timer interrupt with a medium priority of 4. INTClearFlag(INT_T2); INTSetVectorPriority(INT_TIMER_2_VECTOR, INT_PRIORITY_LEVEL_4); INTSetVectorSubPriority(INT_TIMER_2_VECTOR, INT_SUB_PRIORITY_LEVEL_0); INTEnable(INT_T2, INT_ENABLED); /****************************************************************************** * Your code goes in between this comment and the following one with asterisks. *****************************************************************************/ OledInit(); MorseInit(); while (1) { if (mflag) { if (mevent == MORSE_EVENT_DOT) { MorseDecode(MORSE_CHAR_DOT); } else if (mevent == MORSE_EVENT_DASH) { MorseDecode(MORSE_CHAR_DASH); } else if (mevent == MORSE_EVENT_INTER_LETTER) { templet[0] = MorseDecode(MORSE_CHAR_END_OF_CHAR); } else if (mevent == MORSE_EVENT_INTER_WORD) { MorseDecode(MORSE_CHAR_DECODE_RESET); } updateScreen(); mevent = 0; mflag = 0; } } /****************************************************************************** * Your code goes in between this comment and the preceding one with asterisks. *****************************************************************************/ while (1); }
void initUart( UART_MODULE umPortNum, uint32_t ui32WantedBaud ) { /* UART Configuration */ UARTConfigure( umPortNum, UART_ENABLE_PINS_TX_RX_ONLY ); /* UART FIFO Mode */ UARTSetFifoMode( umPortNum, UART_INTERRUPT_ON_TX_NOT_FULL | UART_INTERRUPT_ON_RX_NOT_EMPTY ); /* UART Line Control */ UARTSetLineControl( umPortNum, UART_DATA_SIZE_8_BITS | UART_PARITY_NONE | UART_STOP_BITS_1 ); /* Set the Baud Rate of the UART */ UARTSetDataRate( umPortNum, (uint32_t)configPERIPHERAL_CLOCK_HZ, ui32WantedBaud ); /* Enable the UART for Transmit Only*/ UARTEnable( umPortNum, UART_ENABLE_FLAGS( UART_PERIPHERAL | UART_TX | UART_RX ) ); /* Set UART INterrupt Vector Priority*/ INTSetVectorPriority( INT_VECTOR_UART( UART1 ), INT_PRIORITY_LEVEL_2 ); disableUartISR( UART1 ); }