After having defined the port mapping (Aurix board TC275 lite kit to Arduino), it's time to define the respective pins_arduino.h definitions. Also in refenrece to DigitalPins (Wiring Framework). Here an extract:
// Arduino AURIX Arduino Meaning
//------------------------------------------------------
// 0 P15.3 Device transmit UART signal-RXD
// 1 P15.2 Device received UART signal-TXD
// 2 P02.0 External interrupt
// 3 P02.1 External interrupt / PWM output
// 4 P10.4 GPIO
// 5 P02.3 PWM output
// 6 P02.5 PWM output
// 7 P02.4 GPIO
// 8 P02.6 GPIO
// 9 P02.7 PWM output
// 10 P10.5 SPI-SS / PWM output
// 11 P10.3 SPI-MOSI / PWM output
// 12 P10.1 SPI-MISO
// 13 P10.2 SPI-SCK
// 14 GND Ground
// 15 VAREF Analog reference voltage
// 16 P13.2 I2C Data / Address
// 17 P13.1 I2C Clock
// 30 Extended Leds P0.5
// 31 Extended Leds P0.6
// 32 Extended Button 1
//------------------------------------------------------
// Port Numeric Definition
#define D0 0
#define D1 1
#define D2 2
#define D3 3
#define D4 4
#define D5 5
#define D6 6
#define D7 7
#define D8 8
#define D9 9
#define D10 10
#define D11 11
#define D12 12
#define D13 13
#define D14 -1 // Cannot drive GND
#define D15 -1 // Cannot drive VAREF
#define D16 16
#define D17 17
#define LED 18 // Cannot use standard Arduino LED pin 13
#define LED1 LED
#define LED2 19 // Extended Led
#define BUTTON 20
//...
// Port Address Definition - Digital Pins
#define D0_P &MODULE_P15,3 /* Arduino: Port, Pin definition */
#define D1_P &MODULE_P15,2 /* Arduino: Port, Pin definition */
#define D2_P &MODULE_P02,0 /* Arduino: Port, Pin definition */
#define D3_P &MODULE_P02,1 /* Arduino: Port, Pin definition */
#define D4_P &MODULE_P10,4 /* Arduino: Port, Pin definition */
#define D5_P &MODULE_P02,3 /* Arduino: Port, Pin definition */
#define D6_P &MODULE_P02,5 /* Arduino: Port, Pin definition */
#define D7_P &MODULE_P02,4 /* Arduino: Port, Pin definition */
#define D8_P &MODULE_P02,6 /* Arduino: Port, Pin definition */
#define D9_P &MODULE_P02,7 /* Arduino: Port, Pin definition */
#define D10_P &MODULE_P10,5 /* Arduino: Port, Pin definition */
#define D11_P &MODULE_P10,3 /* Arduino: Port, Pin definition */
#define D12_P &MODULE_P10,1 /* Arduino: Port, Pin definition */
#define D13_P &MODULE_P10,2 /* Arduino: Port, Pin definition */
#define D14_P &(*(Ifx_P*)0x0u),0
#define D15_P &(*(Ifx_P*)0x0u),0
#define D16_P &MODULE_P13,2 /* Arduino: Port, Pin definition */
#define D17_P &MODULE_P13,1 /* Arduino: Port, Pin definition */
#define LED_P &MODULE_P00,5 /* LED : Port, Pin definition */
#define LED1_P LED_P /* LED1 : Port, Pin definition */
#define LED2_P &MODULE_P00,6 /* LED2 : Port, Pin definition */
#define BUTTON_P &MODULE_P00,7 /* BUTTON : Port, Pin definition */
// @Global Variables
//****************************************************************************
const IfxPort_Pin pinDigitalList[] = {
D0_P,
D1_P,
D2_P,
D3_P,
D4_P,
D5_P,
D6_P,
D7_P,
D8_P,
D9_P,
D10_P,
D11_P,
D12_P,
D13_P,
D14_P,
D15_P,
D16_P,
D17_P,
LED1_P,
LED2_P,
BUTTON_P
};
[..]
// @Function pinMode
//
//----------------------------------------------------------------------------
// @Description Configures the specified pin to behave either as an input or
// an output. See the description of digital pins for details
// on the functionality of the pins.
// As of Arduino 1.0.1, it is possible to enable the internal
// pullup resistors with the mode INPUT_PULLUP.
// Additionally, the INPUT mode explicitly disables the
// internal pullups.
//
//----------------------------------------------------------------------------
// @Returnvalue None
//
//----------------------------------------------------------------------------
// @Parameters pin: the number of the pin whose mode you wish to set
// mode: INPUT, OUTPUT, or INPUT_PULLUP
//
//----------------------------------------------------------------------------
// @Link http://arduino.cc/en/Reference/PinMode
//----------------------------------------------------------------------------
// @Date 27/01/2014
//
//****************************************************************************
void pinMode(uint8 pin, uint8 mode)
{
uint16 outputMode = -1;
// Select mode
switch(mode)
{
case INPUT:
outputMode = IfxPort_Mode_inputNoPullDevice; // Input TriState
break;
case INPUT_PULLDW: // Input Pull-Down
outputMode = IfxPort_Mode_inputPullDown;
break;
case INPUT_PULLUP: // Input Pull-Up
outputMode = IfxPort_Mode_inputPullUp;
break;
case OUTPUT:
outputMode = IfxPort_Mode_outputPushPullGeneral; // Output Push-Pull
break;
}
// Set the pin mode
IfxPort_setPinMode(pinDigitalList[pin].port, pinDigitalList[pin].pinIndex, outputMode);
}
[..]
// @Function digitalRead
//
//----------------------------------------------------------------------------
// @Description Reads the value from a specified digital pin, either HIGH or LOW.
//
//----------------------------------------------------------------------------
// @Returnvalue None
//
//----------------------------------------------------------------------------
// @Parameters pin: the number of the digital pin you want to read
//
//----------------------------------------------------------------------------
// @Link http://arduino.cc/en/Reference/DigitalRead
//----------------------------------------------------------------------------
// @Date 12/04/2021
//
//****************************************************************************
uint32 digitalRead(uint8 pin)
{
boolean bVal = IfxPort_getPinState(pinDigitalList[pin].port, pinDigitalList[pin].pinIndex);
return ((bVal?HIGH:LOW));
}
// @Function digitalWrite
//
//----------------------------------------------------------------------------
// @Description Write a HIGH or a LOW value to a digital pin.
// If the pin has been configured as an OUTPUT with pinMode(),
// its voltage will be set to the corresponding value:
// 5V (or 3.3V on 3.3V boards) for HIGH, 0V (ground) for LOW.
//
//----------------------------------------------------------------------------
// @Returnvalue None
//
//----------------------------------------------------------------------------
// @Parameters pin: the pin number
// value: HIGH or LOW
//
//----------------------------------------------------------------------------
// @Link http://arduino.cc/en/Reference/DigitalWrite
//----------------------------------------------------------------------------
// @Date 27/01/2014
//
//****************************************************************************
void digitalWrite(uint8 pin, uint8 value)
{
// Set the pin
if (value == HIGH)
IfxPort_setPinState(pinDigitalList[pin].port, pinDigitalList[pin].pinIndex, IfxPort_State_high);
else
IfxPort_setPinState(pinDigitalList[pin].port, pinDigitalList[pin].pinIndex, IfxPort_State_low);
}
[..]
Cpu0_Main.c modification
It's time to add our Aurix like driver into the main, I select CPU0, but any cpu would work:
IfxCpu_emitEvent(&g_cpuSyncEvent);
IfxCpu_waitEvent(&g_cpuSyncEvent, 1);
/*
* Arduino Layer Initialization
*/
arduino_init();
// Arduino's main() function just calls setup() and loop()....
setup();
while(1)
{
loop();
}
return (1);
Sketch.c creation
And finally the Sketch.c looks like (as expected):
//****************************************************************************
// ARDUINO SKETCH
//****************************************************************************
void setup() {
}
void loop() {
uint32 iCnt = 0;
// Create a small delay to permi to observe the LED toggling
while (iCnt < 10000000)
iCnt++;
// Now toggle the LED status
toggleLED();
toggleLED2();
}
//****************************************************************************
// END OF FILE
//****************************************************************************
[..]
//------------------------------------------------------
Such permits to create a table to address all Digital Pins, as:
//****************************************************************************
And therefore finally define the pinMode() function:
[..]
//****************************************************************************
And the digitalRead() as:
//****************************************************************************
And the digitalWrite() as:
[..]
//****************************************************************************
Is now possible to use the standard Wiring syntax to drive Digital Pins from D0 to D17 (where D14 is GND-Ground and D15 is VAREF-Analog reference voltage).
[..]
/* Wait for CPU sync event */
#include "./Libraries/Arduino/Arduino.h"
The above will permit to toggle the two leds intermitting each other, as visible here:
Note: both leds happear to be on, but in reality are mutually blinking each other.
Comments
Post a Comment