Permalink
Browse files

Interrupt vector changes from Keith and Digilent.

Former-commit-id: 4ee9702
  • Loading branch information...
1 parent c97db16 commit 3eecd82300cde511f50289d0e6e87859ffae08b0 @ricklon ricklon committed Jul 2, 2013
@@ -86,6 +86,18 @@
// #define _DEBUG_USB_VIA_SERIAL0_
#endif
+extern "C"
+{
+void __attribute__((interrupt(),nomips16)) IntSer0Handler(void);
+void __attribute__((interrupt(),nomips16)) IntSer1Handler(void);
+void __attribute__((interrupt(),nomips16)) IntSer2Handler(void);
+void __attribute__((interrupt(),nomips16)) IntSer3Handler(void);
+void __attribute__((interrupt(),nomips16)) IntSer4Handler(void);
+void __attribute__((interrupt(),nomips16)) IntSer5Handler(void);
+void __attribute__((interrupt(),nomips16)) IntSer6Handler(void);
+void __attribute__((interrupt(),nomips16)) IntSer7Handler(void);
+}
+
/* ------------------------------------------------------------ */
/* General Declarations */
/* ------------------------------------------------------------ */
@@ -116,9 +128,9 @@
*/
#if defined(__PIC32MX1XX__) || defined(__PIC32MX2XX__)
-HardwareSerial::HardwareSerial(p32_uart * uartT, int irqT, int vecT, int iplT, int splT, int pinT, int pinR, ppsFunctionType ppsT, ppsFunctionType ppsR)
+HardwareSerial::HardwareSerial(p32_uart * uartT, int irqT, int vecT, int iplT, int splT, isrFunc isrHandler, int pinT, int pinR, ppsFunctionType ppsT, ppsFunctionType ppsR)
#else
-HardwareSerial::HardwareSerial(p32_uart * uartT, int irqT, int vecT, int iplT, int splT)
+HardwareSerial::HardwareSerial(p32_uart * uartT, int irqT, int vecT, int iplT, int splT, isrFunc isrHandler)
#endif
{
uart = uartT;
@@ -128,6 +140,7 @@ HardwareSerial::HardwareSerial(p32_uart * uartT, int irqT, int vecT, int iplT, i
vec = (uint8_t)vecT;
ipl = (uint8_t)iplT;
spl = (uint8_t)splT;
+ isr = isrHandler;
#if defined(__PIC32MX1XX__) || defined(__PIC32MX2XX__)
pinTx = (uint8_t)pinT;
@@ -194,6 +207,8 @@ void HardwareSerial::begin(unsigned long baudRate)
mapPps(pinRx, ppsRx);
#endif
+ setIntVector(_SER0_VECTOR, isr);
+
/* Set the interrupt privilege level and sub-privilege level
*/
setIntPriority(vec, ipl, spl);
@@ -253,6 +268,7 @@ void HardwareSerial::end()
*/
uart->uxMode.reg = 0;
+ clearIntVector(vec);
}
/* ------------------------------------------------------------ */
@@ -744,7 +760,7 @@ extern "C" {
*/
#if defined(_SER0_VECTOR)
-void __ISR(_SER0_VECTOR, _SER0_IPL_ISR) IntSer0Handler(void)
+void __attribute__((interrupt(), nomips16)) IntSer0Handler(void)
{
#if defined(_USB) && defined(_USE_USB_FOR_SERIAL_)
Serial0.doSerialInt();
@@ -772,7 +788,7 @@ void __ISR(_SER0_VECTOR, _SER0_IPL_ISR) IntSer0Handler(void)
*/
#if defined(_SER1_VECTOR)
-void __ISR(_SER1_VECTOR, _SER1_IPL_ISR) IntSer1Handler(void)
+void __attribute__((interrupt(), nomips16)) IntSer1Handler(void)
{
Serial1.doSerialInt();
}
@@ -796,7 +812,7 @@ void __ISR(_SER1_VECTOR, _SER1_IPL_ISR) IntSer1Handler(void)
*/
#if defined(_SER2_VECTOR)
-void __ISR(_SER2_VECTOR, _SER2_IPL_ISR) IntSer2Handler(void)
+void __attribute__((interrupt(), nomips16)) IntSer2Handler(void)
{
Serial2.doSerialInt();
}
@@ -820,7 +836,7 @@ void __ISR(_SER2_VECTOR, _SER2_IPL_ISR) IntSer2Handler(void)
*/
#if defined(_SER3_VECTOR)
-void __ISR(_SER3_VECTOR, _SER3_IPL_ISR) IntSer3Handler(void)
+void __attribute__((interrupt(), nomips16)) IntSer3Handler(void)
{
Serial3.doSerialInt();
}
@@ -844,7 +860,7 @@ void __ISR(_SER3_VECTOR, _SER3_IPL_ISR) IntSer3Handler(void)
*/
#if defined(_SER4_VECTOR)
-void __ISR(_SER4_VECTOR, _SER4_IPL_ISR) IntSer4Handler(void)
+void __attribute__((interrupt(), nomips16)) IntSer4Handler(void)
{
Serial4.doSerialInt();
}
@@ -868,7 +884,7 @@ void __ISR(_SER4_VECTOR, _SER4_IPL_ISR) IntSer4Handler(void)
*/
#if defined(_SER5_VECTOR)
-void __ISR(_SER5_VECTOR, _SER5_IPL_ISR) IntSer5Handler(void)
+void __attribute__((interrupt(), nomips16)) IntSer5Handler(void)
{
Serial5.doSerialInt();
}
@@ -892,7 +908,7 @@ void __ISR(_SER5_VECTOR, _SER5_IPL_ISR) IntSer5Handler(void)
*/
#if defined(_SER6_VECTOR)
-void __ISR(_SER6_VECTOR, _SER6_IPL_ISR) IntSer6Handler(void)
+void __attribute__((interrupt(), nomips16)) IntSer6Handler(void)
{
Serial6.doSerialInt();
}
@@ -916,7 +932,7 @@ void __ISR(_SER6_VECTOR, _SER6_IPL_ISR) IntSer6Handler(void)
*/
#if defined(_SER7_VECTOR)
-void __ISR(_SER7_VECTOR, _SER7_IPL_ISR) IntSer7Handler(void)
+void __attribute__((interrupt(), nomips16)) IntSer7Handler(void)
{
Serial7.doSerialInt();
}
@@ -936,9 +952,9 @@ void __ISR(_SER7_VECTOR, _SER7_IPL_ISR) IntSer7Handler(void)
USBSerial Serial(&rx_bufferUSB);
#if defined(_SER0_BASE)
#if defined(__PIC32MX1XX__) || defined(__PIC32MX2XX__)
-HardwareSerial Serial0((p32_uart *)_SER0_BASE, _SER0_IRQ, _SER0_VECTOR, _SER0_IPL, _SER0_SPL, _SER0_TX_PIN, _SER0_RX_PIN, _SER0_TX_OUT, _SER0_RX_IN);
+HardwareSerial Serial0((p32_uart *)_SER0_BASE, _SER0_IRQ, _SER0_VECTOR, _SER0_IPL, _SER0_SPL, IntSer0Handler, _SER0_TX_PIN, _SER0_RX_PIN, _SER0_TX_OUT, _SER0_RX_IN);
#else
-HardwareSerial Serial0((p32_uart *)_SER0_BASE, _SER0_IRQ, _SER0_VECTOR, _SER0_IPL, _SER0_SPL);
+HardwareSerial Serial0((p32_uart *)_SER0_BASE, _SER0_IRQ, _SER0_VECTOR, _SER0_IPL, _SER0_SPL, IntSer0Handler);
#endif
#endif
@@ -950,44 +966,44 @@ HardwareSerial Serial0((p32_uart *)_SER0_BASE, _SER0_IRQ, _SER0_VECTOR, _SER0_IP
*/
#if defined(_SER0_BASE)
#if defined(__PIC32MX1XX__) || defined(__PIC32MX2XX__)
-HardwareSerial Serial((p32_uart *)_SER0_BASE, _SER0_IRQ, _SER0_VECTOR, _SER0_IPL, _SER0_SPL, _SER0_TX_PIN, _SER0_RX_PIN, _SER0_TX_OUT, _SER0_RX_IN);
+HardwareSerial Serial((p32_uart *)_SER0_BASE, _SER0_IRQ, _SER0_VECTOR, _SER0_IPL, _SER0_SPL, IntSer0Handler, _SER0_TX_PIN, _SER0_RX_PIN, _SER0_TX_OUT, _SER0_RX_IN);
#else
-HardwareSerial Serial((p32_uart *)_SER0_BASE, _SER0_IRQ, _SER0_VECTOR, _SER0_IPL, _SER0_SPL);
+HardwareSerial Serial((p32_uart *)_SER0_BASE, _SER0_IRQ, _SER0_VECTOR, _SER0_IPL, _SER0_SPL, IntSer0Handler);
#endif
#endif
#endif //defined(_USB) && defined(_USE_USB_FOR_SERIAL_)
#if defined(_SER1_BASE)
#if defined(__PIC32MX1XX__) || defined(__PIC32MX2XX__)
-HardwareSerial Serial1((p32_uart *)_SER1_BASE, _SER1_IRQ, _SER1_VECTOR, _SER1_IPL, _SER1_SPL, _SER1_TX_PIN, _SER1_RX_PIN, _SER1_TX_OUT, _SER1_RX_IN);
+HardwareSerial Serial1((p32_uart *)_SER1_BASE, _SER1_IRQ, _SER1_VECTOR, _SER1_IPL, _SER1_SPL, IntSer1Handler, _SER1_TX_PIN, _SER1_RX_PIN, _SER1_TX_OUT, _SER1_RX_IN);
#else
-HardwareSerial Serial1((p32_uart *)_SER1_BASE, _SER1_IRQ, _SER1_VECTOR, _SER1_IPL, _SER1_SPL);
+HardwareSerial Serial1((p32_uart *)_SER1_BASE, _SER1_IRQ, _SER1_VECTOR, _SER1_IPL, _SER1_SPL, IntSer1Handler);
#endif
#endif
#if defined(_SER2_BASE)
-HardwareSerial Serial2((p32_uart *)_SER2_BASE, _SER2_IRQ, _SER2_VECTOR, _SER2_IPL, _SER2_SPL);
+HardwareSerial Serial2((p32_uart *)_SER2_BASE, _SER2_IRQ, _SER2_VECTOR, _SER2_IPL, _SER2_SPL, IntSer2Handler);
#endif
#if defined(_SER3_BASE)
-HardwareSerial Serial3((p32_uart *)_SER3_BASE, _SER3_IRQ, _SER3_VECTOR, _SER3_IPL, _SER3_SPL);
+HardwareSerial Serial3((p32_uart *)_SER3_BASE, _SER3_IRQ, _SER3_VECTOR, _SER3_IPL, _SER3_SPL, IntSer3Handler);
#endif
#if defined(_SER4_BASE)
-HardwareSerial Serial4((p32_uart *)_SER4_BASE, _SER4_IRQ, _SER4_VECTOR, _SER4_IPL, _SER4_SPL);
+HardwareSerial Serial4((p32_uart *)_SER4_BASE, _SER4_IRQ, _SER4_VECTOR, _SER4_IPL, _SER4_SPL, IntSer4Handler);
#endif
#if defined(_SER5_BASE)
-HardwareSerial Serial5((p32_uart *)_SER5_BASE, _SER5_IRQ, _SER5_VECTOR, _SER5_IPL, _SER5_SPL);
+HardwareSerial Serial5((p32_uart *)_SER5_BASE, _SER5_IRQ, _SER5_VECTOR, _SER5_IPL, _SER5_SPL, IntSer5Handler);
#endif
#if defined(_SER6_BASE)
-HardwareSerial Serial6((p32_uart *)_SER6_BASE, _SER6_IRQ, _SER6_VECTOR, _SER6_IPL, _SER6_SPL);
+HardwareSerial Serial6((p32_uart *)_SER6_BASE, _SER6_IRQ, _SER6_VECTOR, _SER6_IPL, _SER6_SPL, IntSer6Handler);
#endif
#if defined(_SER7_BASE)
-HardwareSerial Serial7((p32_uart *)_SER7_BASE, _SER7_IRQ, _SER7_VECTOR, _SER7_IPL, _SER7_SPL);
+HardwareSerial Serial7((p32_uart *)_SER7_BASE, _SER7_IRQ, _SER7_VECTOR, _SER7_IPL, _SER7_SPL, IntSer7Handler);
#endif
/* ------------------------------------------------------------ */
@@ -84,6 +84,7 @@ class HardwareSerial : public Stream
{
private:
p32_uart * uart; //uart register map
+ isrFunc isr; // the ISR routine to use
uint8_t irq; //base IRQ number for the UART
uint8_t vec; //interrupt vector for the UART
uint8_t ipl; //interrupt priority level
@@ -103,9 +104,9 @@ class HardwareSerial : public Stream
public:
#if defined(__PIC32MX1XX__) || defined(__PIC32MX2XX__)
- HardwareSerial(p32_uart * uartP, int irq, int vec, int ipl, int spl, int pinT, int pinR, ppsFunctionType ppsT, ppsFunctionType ppsR);
+ HardwareSerial(p32_uart * uartP, int irq, int vec, int ipl, int spl, isrFunc isrHandler, int pinT, int pinR, ppsFunctionType ppsT, ppsFunctionType ppsR);
#else
- HardwareSerial(p32_uart * uartP, int irq, int vec, int ipl, int spl);
+ HardwareSerial(p32_uart * uartP, int irq, int vec, int ipl, int spl, isrFunc isrHandler);
#endif
void doSerialInt(void);
@@ -34,6 +34,8 @@
#include "HardwareSerial_usb.h"
#include "HardwareSerial_cdcacm.h"
+void __attribute__((interrupt(),nomips16)) IntUSB1Handler(void);
+
// XXX -- move to relocated compat.h
#define MCF_USB_OTG_CTL U1CON
#define MCF_USB_OTG_CTL_USB_EN_SOF_EN _U1CON_SOFEN_MASK
@@ -326,7 +328,7 @@ static byte configuration[CONFIGURATION_DESCRIPTOR_SIZE];
// called by usb on device attach
//************************************************************************
#ifdef _USE_USB_IRQ_
- void __ISR(_USB_1_VECTOR, ipl6) IntUSB1Handler(void)
+ void __attribute__((interrupt(),nomips16)) IntUSB1Handler(void)
#else
void usb_isr(void)
#endif
@@ -742,13 +744,21 @@ void usb_uninitialize(void)
// power off
U1PWRCbits.USBPWR = 0;
+
+#ifdef _USE_USB_IRQ_
+ clearIntVector(_USB_1_VECTOR);
+#endif
}
//************************************************************************
void usb_initialize(void)
{
static __attribute__ ((aligned(512))) byte bdt_ram[BDT_RAM_SIZE];
+#ifdef _USE_USB_IRQ_
+ setIntVector(_USB_1_VECTOR, IntUSB1Handler);
+#endif
+
bdts = (struct bdt *)bdt_ram;
assert(BDT_RAM_SIZE >= LENGTHOF(endpoints)*4*sizeof(struct bdt));
@@ -441,45 +441,6 @@
#define _ETH_SPL_IPC 0
/* ------------------------------------------------------------ */
-/* Task Manager Declarations */
-/* ------------------------------------------------------------ */
-
-#if !defined(NUM_TASKS)
-#define NUM_TASKS 8
-#endif
-
-#define TASK_ENABLE 0xFFFF
-#define TASK_DISABLE 0
-#define TASK_RUN_ONCE 1
-
-#ifdef __cplusplus
-extern "C"{
-#endif
-
-typedef void (*taskFunc)(int id, void * tptr);
-
-int createTask(taskFunc task, unsigned long period, unsigned short state, void * var);
-void destroyTask(int id);
-int getTaskId(taskFunc task);
-void startTaskAt(int id, unsigned long time, unsigned short st);
-unsigned long getTaskNextExec(int id);
-void setTaskState(int id, unsigned short st);
-unsigned short getTaskState(int id);
-void setTaskPeriod(int id, unsigned long period);
-unsigned long getTaskPeriod(int id);
-void setTaskVar(int id, void * var);
-void * getTaskVar(int id);
-
-#if defined(OPT_SYSTEM_INTERNAL)
-void _initTaskManager();
-void _scheduleTask();
-#endif
-
-#ifdef __cplusplus
-} // extern "C"
-#endif
-
-/* ------------------------------------------------------------ */
#endif // SYSTEM_DEFS_H
@@ -65,6 +65,8 @@
#include "p32_defs.h"
#include "pins_arduino.h"
+extern "C" void __attribute__((interrupt(),nomips16)) Timer1Handler(void);
+
// timerx_toggle_count:
// > 0 - duration specified
// = 0 - stopped
@@ -103,6 +105,7 @@ uint8_t port;
{
// No tone currently playing. Init the timer.
T1CON = TACON_PS_256;
+ setIntVector(_TIMER_1_VECTOR, Timer1Handler);
clearIntFlag(_TIMER_1_IRQ);
setIntPriority(_TIMER_1_VECTOR, _T1_IPL_IPC, _T1_SPL_IPC);
setIntEnable(_TIMER_1_IRQ);
@@ -142,9 +145,10 @@ uint8_t port;
//************************************************************************
void disableTimer(uint8_t _timer)
{
- clearIntEnable(_TIMER_1_IRQ);
- T1CON = 0;
- tone_pin = 255;
+ clearIntEnable(_TIMER_1_IRQ);
+ T1CON = 0;
+ tone_pin = 255;
+ clearIntVector(_TIMER_1_VECTOR);
}
//************************************************************************
@@ -166,7 +170,7 @@ extern "C"
//* not done yet
//************************************************************************
-void __ISR(_TIMER_1_VECTOR, _T1_IPL_ISR) Timer1Handler(void)
+void __attribute__((interrupt(),nomips16)) Timer1Handler(void)
{
if (timer1_toggle_count != 0)
Oops, something went wrong.

0 comments on commit 3eecd82

Please sign in to comment.