DM: EIC and VARIANT_MCK fix
This commit is contained in:
parent
d10bf1e355
commit
6820318d33
3 changed files with 128 additions and 24 deletions
Binary file not shown.
|
|
@ -33,16 +33,18 @@ static void __initialize()
|
|||
memset(ISRcallback, 0, sizeof(ISRcallback));
|
||||
nints = 0;
|
||||
|
||||
#if defined(__SAMD51__) //TODO: verify the correct interrupts
|
||||
|
||||
///EIC MCLK is enabled by default
|
||||
|
||||
NVIC_DisableIRQ(EIC_0_IRQn);
|
||||
NVIC_ClearPendingIRQ(EIC_0_IRQn);
|
||||
NVIC_SetPriority(EIC_0_IRQn, 0);
|
||||
NVIC_EnableIRQ(EIC_0_IRQn);
|
||||
|
||||
GCLK->PCHCTRL[EIC_GCLK_ID].reg = GCLK_PCHCTRL_GEN_GCLK2_Val | (1 << GCLK_PCHCTRL_CHEN_Pos);
|
||||
#if defined(__SAMD51__)
|
||||
///EIC MCLK is enabled by default
|
||||
for (uint32_t i = 0; i <= 15; i++) // EIC_0_IRQn = 12 ... EIC_15_IRQn = 27
|
||||
{
|
||||
uint8_t irqn = EIC_0_IRQn + i;
|
||||
NVIC_DisableIRQ(irqn);
|
||||
NVIC_ClearPendingIRQ(irqn);
|
||||
NVIC_SetPriority(irqn, 0);
|
||||
NVIC_EnableIRQ(irqn);
|
||||
}
|
||||
|
||||
GCLK->PCHCTRL[EIC_GCLK_ID].reg = GCLK_PCHCTRL_GEN_GCLK2_Val | (1 << GCLK_PCHCTRL_CHEN_Pos);
|
||||
#else
|
||||
NVIC_DisableIRQ(EIC_IRQn);
|
||||
NVIC_ClearPendingIRQ(EIC_IRQn);
|
||||
|
|
@ -61,8 +63,8 @@ static void __initialize()
|
|||
|
||||
// Enable EIC
|
||||
#if defined(__SAMD51__)
|
||||
EIC->CTRLA.bit.ENABLE = 1;
|
||||
while (EIC->SYNCBUSY.bit.ENABLE == 1) { }
|
||||
EIC->CTRLA.bit.ENABLE = 1;
|
||||
while (EIC->SYNCBUSY.bit.ENABLE == 1) { }
|
||||
#else
|
||||
EIC->CTRL.bit.ENABLE = 1;
|
||||
while (EIC->STATUS.bit.SYNCBUSY == 1) { }
|
||||
|
|
@ -149,7 +151,7 @@ void attachInterrupt(uint32_t pin, voidFuncPtr callback, uint32_t mode)
|
|||
|
||||
// Enable wakeup capability on pin in case being used during sleep
|
||||
#if defined(__SAMD51__)
|
||||
//TODO: find how to do
|
||||
//I believe this is done automatically
|
||||
#else
|
||||
EIC->WAKEUP.reg |= (1 << in);
|
||||
#endif
|
||||
|
|
@ -164,11 +166,17 @@ void attachInterrupt(uint32_t pin, voidFuncPtr callback, uint32_t mode)
|
|||
config = 0;
|
||||
}
|
||||
|
||||
// Configure the interrupt mode
|
||||
pos = (in - (8 * config)) << 2;
|
||||
switch (mode)
|
||||
{
|
||||
case LOW:
|
||||
// Configure the interrupt mode
|
||||
pos = (in - (8 * config)) << 2;
|
||||
|
||||
#if defined (__SAMD51__)
|
||||
EIC->CTRLA.bit.ENABLE = 0;
|
||||
while (EIC->SYNCBUSY.bit.ENABLE == 1) { }
|
||||
#endif
|
||||
|
||||
switch (mode)
|
||||
{
|
||||
case LOW:
|
||||
EIC->CONFIG[config].reg |= EIC_CONFIG_SENSE0_LOW_Val << pos;
|
||||
break;
|
||||
|
||||
|
|
@ -189,12 +197,12 @@ void attachInterrupt(uint32_t pin, voidFuncPtr callback, uint32_t mode)
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(__SAMD51__)
|
||||
//TODO: find how to do
|
||||
#else
|
||||
// Enable the interrupt
|
||||
EIC->INTENSET.reg = EIC_INTENSET_EXTINT(1 << in);
|
||||
|
||||
#if defined (__SAMD51__)
|
||||
EIC->CTRLA.bit.ENABLE = 1;
|
||||
while (EIC->SYNCBUSY.bit.ENABLE == 1) { }
|
||||
#endif
|
||||
|
||||
// Assign callback to interrupt
|
||||
|
|
@ -221,7 +229,7 @@ void detachInterrupt(uint32_t pin)
|
|||
|
||||
// Disable wakeup capability on pin during sleep
|
||||
#if defined(__SAMD51__)
|
||||
//TODO: find how to do
|
||||
//I believe this is done automatically
|
||||
#else
|
||||
// Disable wakeup capability on pin during sleep
|
||||
EIC->WAKEUP.reg &= ~(1 << in);
|
||||
|
|
@ -248,6 +256,102 @@ void detachInterrupt(uint32_t pin)
|
|||
/*
|
||||
* External Interrupt Controller NVIC Interrupt Handler
|
||||
*/
|
||||
#if defined(__SAMD51__)
|
||||
void InterruptHandler(uint32_t i)
|
||||
{
|
||||
if ((EIC->INTFLAG.reg & (1 << i)) != 0)
|
||||
{
|
||||
// Call the callback function if assigned
|
||||
if (callbacksInt[i]) {
|
||||
callbacksInt[i]();
|
||||
}
|
||||
|
||||
// Clear the interrupt
|
||||
EIC->INTFLAG.reg = 1 << i;
|
||||
}
|
||||
}
|
||||
|
||||
void EIC_0_Handler(void)
|
||||
{
|
||||
InterruptHandler(EXTERNAL_INT_0);
|
||||
}
|
||||
|
||||
void EIC_1_Handler(void)
|
||||
{
|
||||
InterruptHandler(EXTERNAL_INT_1);
|
||||
}
|
||||
|
||||
void EIC_2_Handler(void)
|
||||
{
|
||||
InterruptHandler(EXTERNAL_INT_2);
|
||||
}
|
||||
|
||||
void EIC_3_Handler(void)
|
||||
{
|
||||
InterruptHandler(EXTERNAL_INT_3);
|
||||
}
|
||||
|
||||
void EIC_4_Handler(void)
|
||||
{
|
||||
InterruptHandler(EXTERNAL_INT_4);
|
||||
}
|
||||
|
||||
void EIC_5_Handler(void)
|
||||
{
|
||||
InterruptHandler(EXTERNAL_INT_5);
|
||||
}
|
||||
|
||||
void EIC_6_Handler(void)
|
||||
{
|
||||
InterruptHandler(EXTERNAL_INT_6);
|
||||
}
|
||||
|
||||
void EIC_7_Handler(void)
|
||||
{
|
||||
InterruptHandler(EXTERNAL_INT_7);
|
||||
}
|
||||
|
||||
void EIC_8_Handler(void)
|
||||
{
|
||||
InterruptHandler(EXTERNAL_INT_8);
|
||||
}
|
||||
|
||||
void EIC_9_Handler(void)
|
||||
{
|
||||
InterruptHandler(EXTERNAL_INT_9);
|
||||
}
|
||||
|
||||
void EIC_10_Handler(void)
|
||||
{
|
||||
InterruptHandler(EXTERNAL_INT_10);
|
||||
}
|
||||
|
||||
void EIC_11_Handler(void)
|
||||
{
|
||||
InterruptHandler(EXTERNAL_INT_11);
|
||||
}
|
||||
|
||||
void EIC_12_Handler(void)
|
||||
{
|
||||
InterruptHandler(EXTERNAL_INT_12);
|
||||
}
|
||||
|
||||
void EIC_13_Handler(void)
|
||||
{
|
||||
InterruptHandler(EXTERNAL_INT_13);
|
||||
}
|
||||
|
||||
void EIC_14_Handler(void)
|
||||
{
|
||||
InterruptHandler(EXTERNAL_INT_14);
|
||||
}
|
||||
|
||||
void EIC_15_Handler(void)
|
||||
{
|
||||
InterruptHandler(EXTERNAL_INT_15);
|
||||
}
|
||||
#else
|
||||
|
||||
void EIC_Handler(void)
|
||||
{
|
||||
// Calling the routine directly from -here- takes about 1us
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@
|
|||
#define VARIANT_MAINOSC (32768ul)
|
||||
|
||||
/** Master clock frequency */
|
||||
#define VARIANT_MCK (48000000ul)
|
||||
#define VARIANT_MCK (120000000ul)
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Headers
|
||||
|
|
|
|||
Loading…
Reference in a new issue