Skip to content

Added spi #333

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 9 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added Makefile
Empty file.
81 changes: 17 additions & 64 deletions cores/HardwareSerial.cpp
Original file line number Diff line number Diff line change
@@ -32,7 +32,7 @@ HardwareSerial::HardwareSerial(XMC_UART_t *xmc_uart_config,
RingBuffer *tx_buffer) {
_XMC_UART_config = xmc_uart_config;
_rx_buffer = rx_buffer;
_tx_buffer = tx_buffer;
_tx_buffer = tx_buffer; // TODO: replaced by TBUF (hardware register), can be actually removed
}

// Public Methods //////////////////////////////////////////////////////////////
@@ -119,10 +119,12 @@ int HardwareSerial::available(void) {
}

int HardwareSerial::availableForWrite(void) {
int tail = _tx_buffer->_iTail; // Snapshot index affected by irq
if (_tx_buffer->_iHead >= tail)
return SERIAL_BUFFER_SIZE - 1 - _tx_buffer->_iHead + tail;
return tail - _tx_buffer->_iHead - 1;
int available = XMC_USIC_CH_GetTransmitBufferStatus(_XMC_UART_config->channel);
if (available == XMC_USIC_CH_TBUF_STATUS_IDLE) {
return 0;
} else {
return 1;
} // TODO: should return bytes avaliable to write! need to enable txFIFO in the future
}

int HardwareSerial::peek(void) {
@@ -144,59 +146,19 @@ int HardwareSerial::read(void) {
}

void HardwareSerial::flush(void) {
while (_tx_buffer->_iHead != _tx_buffer->_iTail)
; // wait for transmit data to be sent

while (XMC_USIC_CH_GetTransmitBufferStatus(_XMC_UART_config->channel) ==
XMC_USIC_CH_TBUF_STATUS_BUSY)
;
}

size_t HardwareSerial::write(const uint8_t uc_data) {
// Is the hardware currently busy?
#if defined(SERIAL_USE_U1C1)
if (_tx_buffer->_iTail != _tx_buffer->_iHead)
#else
if ((XMC_USIC_CH_GetTransmitBufferStatus(_XMC_UART_config->channel) ==
XMC_USIC_CH_TBUF_STATUS_BUSY) ||
(_tx_buffer->_iTail != _tx_buffer->_iHead))
#endif
{
// If busy we buffer
int nextWrite = _tx_buffer->_iHead + 1;
if (nextWrite >= SERIAL_BUFFER_SIZE)
nextWrite = 0;

// This should always be false but in case transmission is completed before buffer, we need
// to reenable IRQ
if (XMC_USIC_CH_GetTransmitBufferStatus(_XMC_UART_config->channel) !=
XMC_USIC_CH_TBUF_STATUS_BUSY) {
XMC_UART_CH_EnableEvent(_XMC_UART_config->channel, XMC_UART_CH_EVENT_TRANSMIT_BUFFER);
XMC_UART_CH_Transmit(_XMC_UART_config->channel,
_tx_buffer->_aucBuffer[_tx_buffer->_iTail]);
_tx_buffer->_iTail++;
if (_tx_buffer->_iTail >= SERIAL_BUFFER_SIZE)
_tx_buffer->_iTail %= SERIAL_BUFFER_SIZE; // If iTail is larger than Serial Buffer
// Size calculate the correct index value
}

unsigned long startTime = millis();
while (_tx_buffer->_iTail == nextWrite) {
if (millis() - startTime > 1000) {
return 0; // Spin locks if we're about to overwrite the buffer. This continues once
// the data is
// sent
}
}

_tx_buffer->_aucBuffer[_tx_buffer->_iHead] = uc_data;
_tx_buffer->_iHead = nextWrite;
} else {
// Make sure TX interrupt is enabled
XMC_UART_CH_EnableEvent(_XMC_UART_config->channel, XMC_UART_CH_EVENT_TRANSMIT_BUFFER);
// Bypass buffering and send character directly
XMC_UART_CH_Transmit(_XMC_UART_config->channel, uc_data);
}
// Is the hardware currently busy?

// Make sure TX interrupt is enabled
XMC_UART_CH_EnableEvent(_XMC_UART_config->channel, XMC_UART_CH_EVENT_TRANSMIT_BUFFER);
// Bypass buffering and send character directly
XMC_UART_CH_Transmit(_XMC_UART_config->channel, uc_data);

return 1;
}

@@ -220,20 +182,11 @@ void HardwareSerial::IrqHandler(void) {
XMC_UART_CH_ClearStatusFlag(_XMC_UART_config->channel,
XMC_UART_CH_STATUS_FLAG_TRANSMIT_BUFFER_INDICATION);

if (_tx_buffer->_iTail != _tx_buffer->_iHead) {
XMC_UART_CH_Transmit(_XMC_UART_config->channel,
_tx_buffer->_aucBuffer[_tx_buffer->_iTail]);
_tx_buffer->_iTail++;
if (_tx_buffer->_iTail >= SERIAL_BUFFER_SIZE)
_tx_buffer->_iTail %= SERIAL_BUFFER_SIZE; // If iTail is larger than Serial Buffer
// Size calculate the correct index value
} else {
// Mask off transmit interrupt so we don't get it any more
XMC_UART_CH_DisableEvent(_XMC_UART_config->channel, XMC_UART_CH_EVENT_TRANSMIT_BUFFER);
}
// Mask off transmit interrupt so we don't get it any more
XMC_UART_CH_DisableEvent(_XMC_UART_config->channel, XMC_UART_CH_EVENT_TRANSMIT_BUFFER);
}
}

//****************************************************************************
// END OF FILE
//****************************************************************************
//****************************************************************************
17 changes: 17 additions & 0 deletions iöjdk.fm
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
3.x-pre-release
* added_spi
core-test-xmc-3.x
master
remotes/origin/3.x-pre-release
remotes/origin/4.0.0-pre-release
remotes/origin/DESMAKERS-4279-rename-the-metafile-vendor-from-infineon-to-infineon
remotes/origin/DESMAKERS-4347-4350-development-instuctions-env-setup
remotes/origin/DESMAKERS-4349-code_convention.md-in-xmc4arduino
remotes/origin/HEAD -> origin/master
remotes/origin/HIL-test
remotes/origin/core-api-update
remotes/origin/core-test-xmc-3.x
remotes/origin/doc-preview
remotes/origin/master
remotes/origin/master-1.x
remotes/origin/xmc-dev-ops
28 changes: 21 additions & 7 deletions tests/Makefile.test
Original file line number Diff line number Diff line change
@@ -9,21 +9,35 @@
make FQBN=Infineon:xmc:XMC1400_XMC2GO PORT=COM42 UNITY_PATH=\Unity test_can_single monitor

# 2 boards
make FQBN=Infineon:xmc:XMC1400_XMC2GO PORT=COM42 UNITY_PATH=\Unity test_can_connected2_node2 monitor
make FQBN=Infineon:xmc:XMC1400_XMC2GO PORT=COM41 UNITY_PATH=\Unity test_can_connected2_node1 monitor

make FQBN=arduino-git:xmc:XMC1400_XMC2GO PORT=COM42 UNITY_PATH=\Unity test_can_connected2_node2 monitor
make FQBN=arduino-git:xmc:XMC1400_XMC2GO PORT=COM41 UNITY_PATH=\Unity test_can_connected2_node1 monitor

## IIC

# 1 board "talking to itself", wire needed
make FQBN=Infineon:xmc:XMC4700_Relax_Kit PORT=COM28 UNITY_PATH=\Unity test_wire_connected1_pingpong monitor

# 2 boards
make FQBN=Infineon:xmc:XMC4700_Relax_Kit PORT=COM85 test_wire_connected2_masterpingpong monitor
make FQBN=Infineon:xmc:XMC4700_Relax_Kit PORT=COM28 test_wire_connected2_slavepingpong monitor
make FQBN=arduino-git:xmc:XMC4700_Relax_Kit PORT=/dev/ttyACM0 test_wire_connected2_masterpingpong monitor
make FQBN=arduino-git:xmc:XMC4700_Relax_Kit PORT=/dev/ttyACM1 test_wire_connected2_slavepingpong monitor

## UART

# 2 boards
make FQBN=Infineon:xmc:XMC4700_Relax_Kit PORT=COM71 test_uart_connected2_tx monitor
make FQBN=Infineon:xmc:XMC4700_Relax_Kit PORT=COM28 test_uart_connected2_rx monitor
make FQBN=arduino-git:xmc:XMC4700_Relax_Kit PORT=/dev/ttyACM0 test_uart_connected2_tx monitor
make FQBN=arduino-git:xmc:XMC4700_Relax_Kit PORT=/dev/ttyACM1 test_uart_connected2_rx monitor

DigitalIO

# 1 boards

make FQBN=arduino-git:xmc:XMC4700_Relax_Kit PORT=/dev/ttyACM1 UNITY_PATH=\Unity test_digitalio_single monitor

## SPI

# 2 boards
make FQBN=arduino-git:xmc:XMC4700_Relax_Kit PORT=/dev/ttyACM0 test_spi_connected2_master monitor
make FQBN=arduino-git:xmc:XMC4700_Relax_Kit PORT=/dev/ttyACM1 test_spi_connected2_slave monitor

# 1 board, loopback
make FQBN=arduino-git:xmc:XMC4700_Relax_Kit PORT=/dev/ttyACM0 test_spi_connected1_loopback monitor
19 changes: 19 additions & 0 deletions tests/test_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* @file test_config.h
* @brief Configuration file for board-specific test pin definitions.
*
* This header file contains the definitions of the pins used for testing
* purposes on the specific board. These pins are configured as output and
* input pins for various test scenarios.
*
*/
#ifndef TEST_CONFIG_H
#define TEST_CONFIG_H

#include <stdint.h>

// test defines
const uint8_t TEST_DIGITALIO_OUTPUT = 4; // IO0
const uint8_t TEST_DIGITALIO_INPUT = 2; // IO1

#endif // TEST_CONFIG_H