1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
/*
* FPGA_Int.c
*
* Created on: Oct 15, 2018
* Author: avi
*/
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include "inc/hw_memmap.h"
#include "driverlib/interrupt.h"
#include "driverlib/gpio.h"
#include "driverlib/sysctl.h"
#include <drivers/FPGA/FPGA_Comm.h>
#include "include.h"
#include "Drivers/Motors/Motor.h"
#include "drivers/FPGA/FPGA_SPI_Comm.h"
#include "drivers/FPGA/FPGA_INTERRUPTS/fpga_interrupts.h"
#include "Modules/Thread/Thread_ex.h"
#define Screw_Not_Busy_Mask 0x02
volatile uint32_t delay;
//static bool flag = 0;
SCREW_InterruptCallback Callback_Fptr = NULL;
void PortPIntHandler(void)//FPGA1_INTn()
{
volatile uint32_t temp = F1_Moto_Driver_NBUSY2_D; // read the busy value
/*delay=400;
if (GPIOIntStatus(GPIO_PORTP_BASE, false) & GPIO_PIN_0)
{
// PP0 was interrupt cause
if((temp & Screw_Not_Busy_Mask ) == Screw_Not_Busy_Mask)
{
//not busy change the direction
if(flag)
{
MotorMove(HARDWARE_MOTOR_TYPE__MOTO_SCREW, true, 300000 );
}
else
{
MotorMove(HARDWARE_MOTOR_TYPE__MOTO_SCREW, false, 300000 );
}
flag ^=1;
}
}
while(delay)
{
delay -=1;
}*/
// must be done minimum 20uSec after the move command !!!
// temp = F1_Moto_Driver_NBUSY2_L; // read the latch in order to clear the latch value (read it after moving to prevent interrupt before movement)
GPIOIntClear(GPIO_PORTP_BASE, GPIO_INT_PIN_0);
if (Callback_Fptr)
Callback_Fptr();
}
void Screw_Interrupt(bool IsEnable ,SCREW_InterruptCallback callback)
{
volatile short temp = F1_Moto_Driver_NBUSY2_M;
if (IsEnable == ENABLE)
{
temp |= Screw_Not_Busy_Mask; // Mask F1_MOTO_SCREW_A1_NBUSY
F1_Moto_Driver_NBUSY2_M = temp;
temp = F1_Moto_Driver_NBUSY2_L; // read the latch in order to clear the latch value
Callback_Fptr = callback;
}
else
{
temp &= ~Screw_Not_Busy_Mask; // Unask F1_MOTO_SCREW_A1_NBUSY
F1_Moto_Driver_NBUSY2_M = temp;
temp = F1_Moto_Driver_NBUSY2_L; // read the latch in order to clear the latch value
Callback_Fptr = NULL;
}
}
void Init_GPI_Interrupts()
{
uint32_t ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), SYS_CLK_FREQ);
// **** Settings for FPGA1_INTn *****
// Pin P0 setup
//SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOP); // Enable port p
//SysCtlDelay(3);
//GPIOPinTypeGPIOInput(GPIO_PORTP_BASE, GPIO_PIN_0); // Init PP0 as input
//GPIOPadConfigSet(GPIO_PORTP_BASE, GPIO_PIN_0, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); // Enable weak pullup resistor for PP0
// Interrupt setup
GPIOIntDisable(GPIO_PORTP_BASE, GPIO_PIN_0); // Disable interrupt for PP0 (in case it was enabled)
GPIOIntClear(GPIO_PORTP_BASE, GPIO_PIN_0); // Clear pending interrupts for PP0
GPIOIntTypeSet(GPIO_PORTP_BASE, GPIO_PIN_0, GPIO_RISING_EDGE); // Configure PF4 for rising edge trigger (or GPIO_FALLING_EDGE)
//GPIOIntRegister(GPIO_PORTP_BASE, PortPIntHandler); // Register our handler function for port P - done in the cfg file
GPIOIntEnable(GPIO_PORTP_BASE, GPIO_PIN_0); // Enable interrupt for PF4
F1_Moto_Driver_NBUSY2_M = 0; // disable all FPGA1_INTn interrupts
uint32_t temp = F1_Moto_Driver_NBUSY2_L; // read the latch in order to clear the latch value for screw interrupt
// **********************************
// **** Settings for FPGA2_INTn *****
// TBD
// **********************************
// **** Settings for FPGA3_INTn *****
// TBD
// **********************************
}
|