Skip to content

Commit

Permalink
C2000 - Fixed Pin numbering to enable physical pin number to be used …
Browse files Browse the repository at this point in the history
…in API calls
  • Loading branch information
Trey German committed Nov 3, 2014
1 parent 1d382fc commit 605880f
Show file tree
Hide file tree
Showing 7 changed files with 336 additions and 233 deletions.
5 changes: 3 additions & 2 deletions hardware/c2000/cores/c2000/Energia.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,10 @@ void analogResolution(uint16_t);

void delay(uint32_t milliseconds);

void attachInterrupt(uint8_t pin, uint8_t interruptNum, void (*userFunc)(void), int mode);
void detachInterrupt(uint8_t interruptNum);
void attachInterrupt(uint8_t, void (*)(void), int);
void detachInterrupt(uint8_t);

extern const uint16_t pin_mapping[];
extern const uint32_t digital_pin_to_timer[];
extern const uint32_t digital_pin_to_port[];
extern const uint32_t digital_pin_to_bit_mask[];
Expand Down
16 changes: 9 additions & 7 deletions hardware/c2000/cores/c2000/Tone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,14 @@ static int16_t tone_periods[AVAILABLE_TONE_PINS] = { SETARRAY(0) };
**/
void tone(uint8_t _pin, unsigned int frequency, unsigned long duration)
{
uint8_t port = digitalPinToPort(_pin);
uint16_t gpio_number = pin_mapping[_pin];
uint8_t port = digitalPinToPort(gpio_number);
if (port == NOT_A_PORT) return;

// find if we are using it at the moment, if so: update it
for (int i = 0; i < AVAILABLE_TONE_PINS; i++)
{
if (tone_pins[i] == _pin)
if (tone_pins[i] == gpio_number)
{
setTimer(i, frequency, duration);
return; // we are done, timer reprogrammed
Expand All @@ -105,12 +106,12 @@ void tone(uint8_t _pin, unsigned int frequency, unsigned long duration)
{
if (tone_pins[i] == 255)
{
tone_pins[i] = _pin;
tone_bit[i] = digitalPinToBitMask(_pin);
tone_pins[i] = gpio_number;
tone_bit[i] = digitalPinToBitMask(gpio_number);
tone_out[i] = portOutputRegister(port);
if ( tone_state == 0 )
initToneTimers();
pinMode(_pin, OUTPUT);
pinMode(gpio_number, OUTPUT);
setTimer(i, frequency, duration);
return; // we are done, timer set
}
Expand All @@ -124,10 +125,11 @@ void tone(uint8_t _pin, unsigned int frequency, unsigned long duration)
**/
void noTone(uint8_t _pin)
{
if ( _pin == 255 ) return; // Should not happen!
uint16_t gpio_number = pin_mapping[_pin];
if ( gpio_number == 255 ) return; // Should not happen!
for (int i = 0; i < AVAILABLE_TONE_PINS; i++)
{
if (tone_pins[i] == _pin)
if (tone_pins[i] == gpio_number)
{
tone_pins[i] = 255;
stopTimer(i);
Expand Down
314 changes: 171 additions & 143 deletions hardware/c2000/cores/c2000/WInterrupts.c
Original file line number Diff line number Diff line change
@@ -1,143 +1,171 @@
/*
************************************************************************
* WInterrupts.c
*
* Arduino core files for C2000
* Copyright (c) 2012 Trey German. All right reserved.
*
*
***********************************************************************
Derived from:
WInterrupts.c Part of the Wiring project - http://wiring.uniandes.edu.co
Copyright (c) 2004-05 Hernando Barragan
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
Modified 24 November 2006 by David A. Mellis
Modified 1 August 2010 by Mark Sproul
*/

#include <inttypes.h>
#include <stdio.h>

#include "wiring_private.h"

#ifndef BV
#define BV(x) (1 << (x))
#endif

#define bit_pos(A) ((A) == 1u << 0 ? 0 \
: (A) == 1u << 1 ? 1 \
: (A) == 1u << 2 ? 2 \
: (A) == 1u << 3 ? 3 \
: (A) == 1u << 4 ? 4 \
: (A) == 1u << 5 ? 5 \
: (A) == 1u << 6 ? 6 \
: (A) == 1u << 7 ? 7 \
: 0)


static volatile voidFuncPtr intFuncP1;
static volatile voidFuncPtr intFuncP2;
static volatile voidFuncPtr intFuncP3;



interrupt void Port_1(void)
{
intFuncP1();
PieCtrlRegs.PIEACK.bit.ACK1 = 1;
}


interrupt void Port_2(void)
{
intFuncP2();
PieCtrlRegs.PIEACK.bit.ACK1 = 1;
}

interrupt void Port_3(void)
{
intFuncP3();
PieCtrlRegs.PIEACK.bit.ACK12 = 1;
}



void attachInterrupt(uint8_t pin, uint8_t interruptNum, void (*userFunc)(void), int mode) {
uint32_t bit = digitalPinToPort(pin);


if (bit == NOT_A_PIN) return;

DINT;
EALLOW;
switch(interruptNum) {
case 1:
PieVectTable.XINT1 = Port_1;
PieCtrlRegs.PIEIER1.bit.INTx4 = 1;
IER |= M_INT1;
GpioIntRegs.GPIOXINT1SEL.bit.GPIOSEL = pin;
XIntruptRegs.XINT1CR.bit.POLARITY = mode;
intFuncP1 = userFunc;
XIntruptRegs.XINT1CR.bit.ENABLE = 1;
break;
case 2:
PieVectTable.XINT2 = Port_2;
PieCtrlRegs.PIEIER1.bit.INTx5 = 1;
IER |= M_INT1;
GpioIntRegs.GPIOXINT2SEL.bit.GPIOSEL = pin;
XIntruptRegs.XINT2CR.bit.POLARITY = mode;
intFuncP2 = userFunc;
XIntruptRegs.XINT2CR.bit.ENABLE = 1;
break;
case 3:
PieVectTable.XINT3 = Port_3;
PieCtrlRegs.PIEIER12.bit.INTx1 = 1;
IER |= M_INT12;
GpioIntRegs.GPIOXINT3SEL.bit.GPIOSEL = pin;
XIntruptRegs.XINT3CR.bit.POLARITY = mode;
intFuncP3 = userFunc;
XIntruptRegs.XINT3CR.bit.ENABLE = 1;
break;
default:
break;
}
EDIS;
EINT;
}

void detachInterrupt(uint8_t interruptNum) {

switch(interruptNum) {
case 1:
XIntruptRegs.XINT1CR.bit.ENABLE = 0;
intFuncP1 = rsvd_ISR;
break;
case 2:
XIntruptRegs.XINT2CR.bit.ENABLE = 0;
intFuncP2 = rsvd_ISR;
break;
case 3:
XIntruptRegs.XINT3CR.bit.ENABLE = 0;
intFuncP3 = rsvd_ISR;
break;
default:
break;
}
}
/*
************************************************************************
* WInterrupts.c
*
* Arduino core files for C2000
* Copyright (c) 2012 Trey German. All right reserved.
*
*
***********************************************************************
Derived from:
WInterrupts.c Part of the Wiring project - http://wiring.uniandes.edu.co
Copyright (c) 2004-05 Hernando Barragan
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
Modified 24 November 2006 by David A. Mellis
Modified 1 August 2010 by Mark Sproul
*/

#include <inttypes.h>
#include <stdio.h>

#include "wiring_private.h"

#ifndef BV
#define BV(x) (1 << (x))
#endif

#define bit_pos(A) ((A) == 1u << 0 ? 0 \
: (A) == 1u << 1 ? 1 \
: (A) == 1u << 2 ? 2 \
: (A) == 1u << 3 ? 3 \
: (A) == 1u << 4 ? 4 \
: (A) == 1u << 5 ? 5 \
: (A) == 1u << 6 ? 6 \
: (A) == 1u << 7 ? 7 \
: 0)

#define AVAILABLE_EXT_INTS 3


static volatile voidFuncPtr intFuncP1;
static volatile voidFuncPtr intFuncP2;
static volatile voidFuncPtr intFuncP3;

static uint8_t extInts[AVAILABLE_EXT_INTS] = {255, 255, 255};


interrupt void Port_1(void)
{
intFuncP1();
PieCtrlRegs.PIEACK.bit.ACK1 = 1;
}


interrupt void Port_2(void)
{
intFuncP2();
PieCtrlRegs.PIEACK.bit.ACK1 = 1;
}

interrupt void Port_3(void)
{
intFuncP3();
PieCtrlRegs.PIEACK.bit.ACK12 = 1;
}



void attachInterrupt(uint8_t pin, void (*userFunc)(void), int mode) {
uint16_t gpio_number = pin_mapping[pin];
uint32_t bit = digitalPinToPort(gpio_number);
int i;

if (bit == NOT_A_PIN) return;

DINT;
EALLOW;

for(i = 0; i < AVAILABLE_EXT_INTS; i++)
{
if(extInts[i] == 255)
{
extInts[i] = gpio_number;
i++;
switch(i) {
case 1:
PieVectTable.XINT1 = Port_1;
PieCtrlRegs.PIEIER1.bit.INTx4 = 1;
IER |= M_INT1;
GpioIntRegs.GPIOXINT1SEL.bit.GPIOSEL = gpio_number;
XIntruptRegs.XINT1CR.bit.POLARITY = mode;
intFuncP1 = userFunc;
XIntruptRegs.XINT1CR.bit.ENABLE = 1;
break;
case 2:
PieVectTable.XINT2 = Port_2;
PieCtrlRegs.PIEIER1.bit.INTx5 = 1;
IER |= M_INT1;
GpioIntRegs.GPIOXINT2SEL.bit.GPIOSEL = gpio_number;
XIntruptRegs.XINT2CR.bit.POLARITY = mode;
intFuncP2 = userFunc;
XIntruptRegs.XINT2CR.bit.ENABLE = 1;
break;
case 3:
PieVectTable.XINT3 = Port_3;
PieCtrlRegs.PIEIER12.bit.INTx1 = 1;
IER |= M_INT12;
GpioIntRegs.GPIOXINT3SEL.bit.GPIOSEL = gpio_number;
XIntruptRegs.XINT3CR.bit.POLARITY = mode;
intFuncP3 = userFunc;
XIntruptRegs.XINT3CR.bit.ENABLE = 1;
break;
default:
break;
}
}


}

EDIS;
EINT;
}

void detachInterrupt(uint8_t pin) {
uint16_t gpio_number = pin_mapping[pin];
int i;
for(i = 0; i < AVAILABLE_EXT_INTS; i++)
{
if(extInts[i] == gpio_number)
{
extInts[i] = 255;
i++;
switch(i) {
case 1:
XIntruptRegs.XINT1CR.bit.ENABLE = 0;
intFuncP1 = rsvd_ISR;
break;
case 2:
XIntruptRegs.XINT2CR.bit.ENABLE = 0;
intFuncP2 = rsvd_ISR;
break;
case 3:
XIntruptRegs.XINT3CR.bit.ENABLE = 0;
intFuncP3 = rsvd_ISR;
break;
default:
break;
}

}

}

}
Loading

0 comments on commit 605880f

Please sign in to comment.