/****************************************************************************
 * Function:        TCPIPEventClose
 *
 * PreCondition:    None.
 *
 * Input:           None
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        This function closes the ethernet event notification.
 *
 * Note:            None
 ******************************************************************************/
void TCPIPEventClose(void)
{

	INTEnable(INT_ETHERNET, INT_DISABLED);		// stop Eth ints
	INTClearFlag(INT_ETHERNET);

	_TcpNotifyFnc=0;
	_TcpEnabledEvents=_TcpPendingEvents=0;
}
Пример #2
0
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);
}
Пример #3
0
void hal_uart_send_async(hal_uart_port port, uint8_t size){
    assert(port >= HAL_UART_PORT_1 && port <= HAL_UART_NUMBER_OF_PORTS );
    /* select the respective output buffer */
    struct txbuffer_struct* tx_buffer = get_tx_buffer(port);
    tx_buffer->nbytes = size;
    tx_buffer->counter = 0;
    UART_MODULE uart = logic_uart2phy_uart(port);
    INTClearFlag(INT_SOURCE_UART_TX(uart));
    INTEnable(INT_SOURCE_UART_TX(uart), INT_ENABLED);
}
Пример #4
0
/*******************************************************************************
 * 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);
}
Пример #5
0
//******************************************************************************
//Interrupt Request Routines
//******************************************************************************
void __ISR(_UART_1_VECTOR, IPL5AUTO) __UART1Interrupt(void)
{
    UINT8 rxByte = 0;
    UINT8 txByte = 0;
    int rslt = 0;

    if (INTGetFlag(INT_U1RX))
    {
        //Add received byte
        rxByte = UARTGetDataByte(UART1);
        FIFOUART1_pushRxQueue(&rxByte, 1);

        INTClearFlag(INT_U1RX);
    }
    if (INTGetFlag(INT_U1TX))
    {
        rslt = FIFOUART1_popTxQueue(&txByte);

        switch (rslt)
        {
            case 2: //Success, non-empty buffer
                UARTSendDataByte(UART1, txByte);
                break;

            case 1: //Success, empty buffer
                UARTSendDataByte(UART1, txByte);
                INTEnable(INT_U1TX, INT_DISABLED);
                break;

            case -1: //Queue is Overflowing
                //Reset the indexs
                FIFOUART1_TxBuffer_TxIndex = 0;
                FIFOUART1_TxBuffer_Index = 0;
            case -2: //Queue is Empty
            default: //unknown result
                INTEnable(INT_U1TX, INT_DISABLED);
                break;
        }

        INTClearFlag(INT_U1TX);
    }
}
Пример #6
0
FIFOI2C_RX_Byte FIFOI2C_readQueue(uint16 device)
{
    int ind = 0;
    FIFOI2C_RX_Byte rxb;

    //Checks for read-overflow error
    if (FIFOI2C_Devices_List[device].receive_buffer_length >= (FIFOI2C_RECEIVE_BUFFER_SIZE - 1))
    {
        rxb.device_command = FIFOI2C_DEVICE_COMMAND_CMDERROR;
        rxb.rx_byte = 0;
    }
    else
    {
        ind = FIFOI2C_Devices_List[device].receive_buffer_current;
        rxb.device_command = FIFOI2C_Devices_List[device].receive_buffer[ind].device_command;
        rxb.rx_byte = FIFOI2C_Devices_List[device].receive_buffer[ind].rx_byte;
        FIFOI2C_Devices_List[device].receive_buffer_current++;

        
        //If all the bytes have been read from the receive buffer reset the indexes
        if (FIFOI2C_Devices_List[device].receive_buffer_current >= FIFOI2C_Devices_List[device].receive_buffer_length)
        {
            //Sensitive Code. Disable temporarily masterinterrupt (if it's enabled.)
            if (INTGetEnable(INT_I2C2M) != 0)
            {
                INTEnable(INT_I2C2M, INT_DISABLED);
                FIFOI2C_Devices_List[device].receive_buffer_length = 0;
                FIFOI2C_Devices_List[device].receive_buffer_current = 0;
                INTEnable(INT_I2C2M, INT_ENABLED);
            }
            else
            {
                FIFOI2C_Devices_List[device].receive_buffer_length = 0;
                FIFOI2C_Devices_List[device].receive_buffer_current = 0;
            }

        }

        return rxb; //Return the received byte.
    }
}
/****************************************************************************
 * Function:        _TcpIpEventAck
 *
 * PreCondition:    TCPIPInit should have been called.
 *
 * Input:           eventFlags - the events that the user processed and need to be re-enabled
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        Internal function to acknowledge and re-enable processed events.
 *                  Same as the interface one except it can clear any kind of events passed to it.
 *                  
 *
 * Note:            None
 ******************************************************************************/
static void _TcpIpEventAck(eTCPIPEvent eventFlags)
{
	if(_TcpEnabledEvents!=0)
	{	// already have some active		
		eEthEvents	ackEvents;

		ackEvents=_XtlEventsTcp2Eth(eventFlags);

		INTEnable(INT_ETHERNET, INT_DISABLED);		// stop ints for a while

		ackEvents&=_TcpPendingEvents;			// keep just the pending ones
		_TcpPendingEvents&=~ackEvents;			// no longer pending


		EthEventsClr(ackEvents);		// clear the old pending ones
		EthEventsEnableSet(ackEvents);		// re-enable the ack ones
		
		INTEnable(INT_ETHERNET, INT_ENABLED);	// re-enable
	}

}
Пример #8
0
//******************************************************************************
//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:        TCPIPEventSetNotifyEvents
 *
 * PreCondition:    TCPIPInit should have been called.
 *
 * Input:           eventFlags - events the user of the stack wants to add for notification 
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        This function sets new enabled events.
 *                  Multiple events can be orr-ed together.
 *                  All events that are set will be added to the notification process. The other events will not ne touched.
 *                  The stack user has to catch the events that are notified and process them:
 *                   - use them eventually in a call to TCPIPEventProcess(). The stack will process only the normal transfer events
 *                   - process the specific condition and acknowledge them calling TCPIPEventAck() so that they can be re-enabled.
 *
 * Note:            - The event notification system enables the user of the Tcp/Ip stack to call into the stack
 *                    for processing only when there are relevant events rather than being forced to periodically call
 *                    from within a loop.
 *                  - If the notification events are nill the interrupt processing will be disabled.
 *                    Otherwise the event notification will be enabled and the interrupts relating to the requested events will be enabled.
 *                  - Note that once an event has been caught by the stack ISR (and reported to the user if a notification handler is in place)
 *                    it will be disabled until the user calls TCPIPEventProcess()/TCPIPEventAck().
 ******************************************************************************/
void TCPIPEventSetNotifyEvents(eTCPIPEvent eventFlags)
{
	eEthEvents	setEvents;
	
	if(_TcpEnabledEvents!=0)
	{	// already have some active		
		INTEnable(INT_ETHERNET, INT_DISABLED);		// stop ints for a while
	}
	
	setEvents=_XtlEventsTcp2Eth(eventFlags);
	_TcpEnabledEvents|=setEvents;		// add more 
	
	if(_TcpEnabledEvents!=0)
	{
		setEvents&=~_TcpPendingEvents;		// keep just the new un-ack events
		EthEventsClr(setEvents);		// clear the old pending ones
		EthEventsEnableSet(setEvents);		// enable the new un-ack ones!
		
		INTEnable(INT_ETHERNET, INT_ENABLED);	// re-enable
	}
			
}
/****************************************************************************
 * 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;
	

}
Пример #11
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);

}
Пример #12
0
/**
 * Function: Interrupt Service Routine
 * @return None
 * @remark ISR that is called when CH3 pings external interrupt
 * @author Darrel Deo
 * @date 2013.04.01  */
void __ISR(_CHANGE_NOTICE_VECTOR, ipl2) ChangeNotice_Handler(void){
    mPORTDRead();
    Serial_putChar('Y');

    //Change top-level state machine so it is in state Reciever
    CONTROL_MASTER = RECIEVER_CONTROL;
    OVERRIDE_TRIGGERED = TRUE;
    //Clear the interrupt flag that was risen for the external interrupt
    //might want to set a timer in here

    mCNClearIntFlag();
    INTEnable(INT_CN,0);
}
Пример #13
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);
			}
		}
Пример #14
0
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;
}
/****************************************************************************
 * Function:        TCPIPEventClearNotifyEvents
 *
 * PreCondition:    TCPIPInit should have been called.
 *
 * Input:           eventFlags - pointer to the events the user of the stack wants to remove from notification 
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        This function removes from the enabled events.
 *                  Multiple events can be orr-ed together.
 *                  All events that are set will be removed from the notification process. The other events will not ne touched.
 *
 * Note:            - If the notification events are nill the interrupt processing will be disabled.
 *                    Otherwise the event notification will be enabled and the interrupts relating to the requested events will be enabled.
 ******************************************************************************/
void TCPIPEventClearNotifyEvents(eTCPIPEvent eventFlags)
{
	eEthEvents	clrEvents;
	
	if(_TcpEnabledEvents!=0)
	{	// already have some active		
		INTEnable(INT_ETHERNET, INT_DISABLED);		// stop ints for a while
	}

	clrEvents=_XtlEventsTcp2Eth(eventFlags);
	clrEvents&=_TcpEnabledEvents;		// keep just the enabled ones
	_TcpEnabledEvents&=~clrEvents;		// clear some of them
	_TcpPendingEvents&=~clrEvents;		// remove them from un-ack list
	
	EthEventsEnableClr(clrEvents);		// no longer enabled
	EthEventsClr(clrEvents);		// clear the pending ones

    if(_TcpEnabledEvents!=0)
	{
		INTEnable(INT_ETHERNET, INT_ENABLED);	// re-enable
	}

}
Пример #16
0
/**
 * Function: Override_init()
 * @return None
 * @remark Initializes interrupt for Override functionality
 * @author Darrel Deo
 * @date 2013.04.01  */
void Override_init(){
    //Enable the interrupt for the override feature

    mPORTBSetPinsDigitalIn(BIT_0); // CN2

    mCNOpen(CN_ON | CN_IDLE_CON , CN2_ENABLE , CN_PULLUP_DISABLE_ALL);
    uint16_t value = mPORTDRead();
    ConfigIntCN(CHANGE_INT_ON | CHANGE_INT_PRI_2);
    //CN2 J5-15
    INTEnableSystemMultiVectoredInt();
    printf("Override Function has been Initialized\n\n");
    //INTEnableInterrupts();
    INTEnable(INT_CN,1);
}
Пример #17
0
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);

    
}
Пример #18
0
// 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);
}
Пример #19
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");
    
   
}
Пример #20
0
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);
}
Пример #21
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);



}
Пример #22
0
void PutChar(char ch) {
    if (getLength(transmitBuffer) != QUEUESIZE) {
        writeBack(transmitBuffer, ch);

        if (!INTGetEnable(INT_U1TX)) {
            INTEnable(INT_U1TX, INT_ENABLED);
            //INTSetFlag(INT_U1TX);
        }
        //        if (U1STAbits.TRMT) {
        //            INTEnable(INT_U1TX, INT_ENABLED);
        //            INTSetFlag(INT_U1TX);
        //        } else if (!INTGetEnable(INT_U1TX)) {
        //            INTEnable(INT_U1TX, INT_ENABLED);
        //            //INTSetFlag(INT_U1TX);
        //        }
    }
}
Пример #23
0
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);
}
Пример #24
0
void serial_handling(void){
    static int step = 0;
    static uint8_t msg[MESS_SIZE];

    if(UARTReceivedDataIsAvailable(UART2))
    {
       PutCharInFifo ( &descrFifoRX, UARTGetDataByte(UART2));
    }

    if(GetReadSize(&descrFifoRX) < 1){
        // Il n'y a rien à faire
        return ;
    }

    GetCharFromFifo(&descrFifoRX, &msg[step]);

    switch(step){
        case 0:
            // Recherche du caractère '!'
            if(msg[0] == '!'){
                step++;
            }
            break;
        case 1:
        case 2:
            step++;
            break;
        case 3:
            // Message complet
            msg_processing(msg);
            step = 0;
        default:
            step = 0;
            break;

    }


    if (GetReadSize(&descrFifoTX) > 0)
    {
        // Autorise int émission
        INTEnable(INT_U2TX, INT_ENABLED);
    }

}
Пример #25
0
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;
        }
    }
Пример #26
0
void __ISR(_ADC_VECTOR, ipl3) interruptGP2D12(void){

    mAD1ClearIntFlag();

    rawData = ReadADC10(8 * ((~ReadActiveBufferADC10() & 0x01))); // ADC1BUF0;
    
    double volts = (3.3/1024.0)*rawData;
    distance = (25.0/(volts-0.13)) - 0.42;
    if(distance <= 1e-5) distance = 1000.0;

    while(IFS1bits.AD1IF){
        int i = ADC1BUF0;
        mAD1ClearIntFlag();
    }

    INTEnable(INT_AD1, INT_DISABLED);

}
Пример #27
0
//TODO: implement sanity checks.
hal_uart_port hal_uart_open(hal_uart_port port, hal_uart_baudrate baudrate,
                    hal_uart_parity parity,
                    hal_uart_stop_bits stop_bits, 
    hal_uart_on_data_received_callback data_received){
    on_data_received[port] = data_received;
    assert(port >= HAL_UART_PORT_1 && port <= HAL_UART_NUMBER_OF_PORTS );
    /* Configure uart */
    UART_MODULE uart = logic_uart2phy_uart(port);
    SetRxTxPins(uart);
    UARTConfigure(uart, UART_ENABLE_PINS_TX_RX_ONLY);
    UARTSetFifoMode(uart, UART_INTERRUPT_ON_TX_DONE | UART_INTERRUPT_ON_RX_NOT_EMPTY);
    UARTSetLineControl(uart, UART_DATA_SIZE_8_BITS | get_parity(parity) | get_stop_bits(stop_bits));
    UARTSetDataRate(uart, PIC32_PERIPHERALBUS_FREQ, get_baudrate(baudrate));
    UARTEnable(uart, UART_ENABLE_FLAGS(UART_PERIPHERAL | UART_TX | UART_RX));
    INTClearFlag(INT_SOURCE_UART_RX(uart));
    INTEnable(INT_SOURCE_UART_RX(uart),INT_ENABLED);
    return port;
}
Пример #28
0
/**
 * @Function AD_End(void)
 * @param None
 * @return None
 * @brief  disables the A/D subsystem and release the pins used
 * @author Max Dunne, 2013.09.20 */
void AD_End(void)
{
    int pin;
    if (!ADActive) {
        return;
    }
    INTEnable(INT_AD1, INT_DISABLED);
    AD1CON1CLR = _AD1CON1_ON_MASK;
    PinsToRemove = ALLADPINS;
    AD_SetPins();
    for (pin = 0; pin < NUM_AD_PINS; pin++) {
        ADValues[pin] = -1;
    }
    ActivePins = 0;
    PinCount = 0;
    //CloseADC10();
    AD1PCFG = 0xFF;
}
Пример #29
0
void WF_EintEnable(void)
{

    // if interrupt line is low, then we may have missed a falling edge
    // while the interrupt was disabled.
    if ( WF_INT_IO == 0 )
    {
        // if the interrupt pin is active then the MRF24W has another event that needs to be serviced.
        // This means that the MRF24W will never generate another falling edge
        // required to trigger the interrupt... So, we must force an interrupt.
       IFS0bits.INT1IF = 1; // WF_INT_IF_SET = WF_INT_BIT;
        
    }

    /* enable the external interrupt */
    INTEnable(INT_INT1, INT_ENABLED); //enable EINT1;

}
Пример #30
0
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);
}