rpp_lib_SOURCES += \
rpp/src/rpp/adc.c \
rpp/src/rpp/can.c \
- rpp/src/rpp/dac.c \
rpp/src/rpp/din.c \
- rpp/src/rpp/eth.c \
- rpp/src/rpp/fr.c \
- rpp/src/rpp/hbr.c \
- rpp/src/rpp/hout.c \
- rpp/src/rpp/irc.c \
- rpp/src/rpp/lin.c \
- rpp/src/rpp/lout.c \
- rpp/src/rpp/mout.c \
rpp/src/rpp/rpp.c \
- rpp/src/rpp/sci.c \
- rpp/src/rpp/sdc.c \
- rpp/src/rpp/sdr.c
+ rpp/src/rpp/sci.c
rpp_lib_SOURCES_7.0.2_tms570 += \
-rpp-test-suite_SOURCES := src/ain.c src/aout.c src/can.c src/din.c \
-src/eth.c src/fr.c src/hbr.c src/hout.c src/lin.c src/lout.c \
-src/main.c src/mout.c src/sci.c src/sdc.c src/sdr.c
+rpp-test-suite_SOURCES := src/ain.c src/can.c src/din.c \
+src/main.c src/sci.c
void test_adc();
-void test_dac();
void test_can();
void test_din();
-void test_eth();
-void test_fr();
-void test_hbr();
-void test_hout();
-void test_lin();
-void test_lout();
-void test_mout();
void test_sci();
-void test_sdc();
-void test_sdr();
// SCI compatibility layer for POSIX
+++ /dev/null
-/* Copyright (C) 2013 Czech Technical University in Prague
- *
- * Authors:
- * - Carlos Jenkins <carlos@jenkins.co.cr>
- *
- * This document contains proprietary information belonging to Czech
- * Technical University in Prague. Passing on and copying of this
- * document, and communication of its contents is not permitted
- * without prior written authorization.
- *
- * File : aout.c
- * Abstract:
- * RPP test suite - module for testing AOUT.
- *
- * References:
- * test.h
- */
-
-
-#include <math.h> // sin()
-
-#include "rpp/rpp.h"
-#include "test.h"
-
-#define SINE_FREQ_HZ 10
-#define SAMPLE_RATE_HZ 1000
-// Which means 100 samples per period
-
-
-// Task control
-static boolean_t stop_tasks = FALSE;
-static uint8_t tasks_running = 0;
-
-
-/**
- * FreeRTOS Task that generates a sinewave on all analog outputs.
- *
- * Waves on analog outputs are shifted by pi/2 each.
- */
-void dac_test_task(void *par)
-{
- rpp_sci_printf((const char *)
- "Analog Output Test at %d Hz:\r\n", SINE_FREQ_HZ
- );
- rpp_sci_printf((const char *)
- "===========================================================\r\n"
- );
- rpp_sci_printf((const char *)"Samples: 0");
-
- // Calculate wait time in OS ticks
- static const portTickType freq_ticks = configTICK_RATE_HZ / SAMPLE_RATE_HZ;
- portTickType last_wake_time = xTaskGetTickCount();
-
- // Constant trigonometric variables
- const double two_pi = 2.0 * (4.0 * atan(1.0)); // Just 2pi
- const double half_pi = 0.5 * (4.0 * atan(1.0)); // Just pi/2
- /*
- * A little bit of math:
- * In this example we want to generate a 10Hz sinusoid wave with a sampling
- * rate of 1000Hz. Sinus period is defined over 2pi, 10Hz means 10 periods
- * per second, at 1000Hz sampling rate means 100 samples per period. It
- * means that in 100 samples we should go from range [0, 2pi]. Here, we
- * calculate the step.
- */
- const double step = (two_pi * SINE_FREQ_HZ) / SAMPLE_RATE_HZ;
-
- uint64_t samples = 0;
- double sinus = 0.0;
- uint32_t val = 0;
- int pin = 0;
- int i = 0;
- while ((!stop_tasks)) {
-
- for (i = 0; (i < SAMPLE_RATE_HZ) && (!stop_tasks); i++, samples++) {
-
- for (pin = 1; pin <= 4; pin++) {
-
- // Calculate sine sample
- sinus = sin(i * step + (pin - 1) * half_pi);
-
- // Map wave from [-1.0, 1.0] to [0, 4095]
- val = (uint32_t)(((sinus + 1.0) / 2.0) * 4095.0);
-
- // Output value
- rpp_dac_set(pin, val);
- }
-
- // Update outputs
- rpp_dac_update();
-
- // Wait until next step
- if (!stop_tasks)
- vTaskDelayUntil(&last_wake_time, freq_ticks);
- }
-
- rpp_sci_printf((const char *)
- "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
- "Samples: %lu", samples + 1
- );
-
- }
-
- // Delete myself
- tasks_running--;
- vTaskDelete(NULL);
-}
-
-
-/**
- * DAC Test entry point.
- */
-void test_dac()
-{
- /// Configure module
- // Configure pins
- int p;
-
- for (p = 1; p <= 4; p++) {
- rpp_dac_setup(p, TRUE);
- }
- rpp_dac_update();
-
-
- /// Spawn tasks
- xTaskHandle test_task_handle;
-
- portBASE_TYPE task_created = xTaskCreate(dac_test_task,
- (const signed char *)"dac_test_task",
- TEST_TASK_STACK, NULL, TEST_TASK_PRIORITY,
- &test_task_handle
- );
-
- if (task_created != pdPASS) {
-
- rpp_sci_printf((const char *)
- "ERROR: Problem spawning the test task. "
- "Error code: %d\r\n", (uint32_t)task_created
- );
- wait_for_quit();
- return;
- }
- tasks_running++;
-
-
- // Wait for user exit
- wait_for_quit();
- stop_tasks = TRUE;
- while (tasks_running > 0)
- taskYIELD();
- stop_tasks = FALSE;
-
-
- /// Reset module configuration
- for (p = 1; p <= 4; p++) {
- rpp_dac_set(p, 0);
- //rpp_dac_setup(p, FALSE);
- }
- rpp_dac_update();
-
-
- rpp_sci_printf((const char *)"\r\n");
-
- return;
-}
+++ /dev/null
-/* Copyright (C) 2013 Czech Technical University in Prague
- *
- * Authors:
- * - Carlos Jenkins <carlos@jenkins.co.cr>
- *
- * This document contains proprietary information belonging to Czech
- * Technical University in Prague. Passing on and copying of this
- * document, and communication of its contents is not permitted
- * without prior written authorization.
- *
- * File : eth.c
- * Abstract:
- * RPP test suite - module for testing ETH.
- *
- * References:
- * test.h
- */
-
-
-#include "rpp/rpp.h"
-#include "test.h"
-
-
-/**
- * ETH Test entry point.
- */
-void test_eth()
-{
- rpp_sci_printf((const char *)
- "ETH test is unimplemented. Press any key to continue...\r\n"
- );
- wait_for_quit();
-}
+++ /dev/null
-/* Copyright (C) 2013 Czech Technical University in Prague
- *
- * Authors:
- * - Carlos Jenkins <carlos@jenkins.co.cr>
- *
- * This document contains proprietary information belonging to Czech
- * Technical University in Prague. Passing on and copying of this
- * document, and communication of its contents is not permitted
- * without prior written authorization.
- *
- * File : fr.c
- * Abstract:
- * RPP test suite - module for testing FR.
- *
- * References:
- * test.h
- */
-
-
-#include "rpp/rpp.h"
-#include "test.h"
-
-
-/**
- * FR Test entry point.
- */
-void test_fr()
-{
- rpp_sci_printf((const char *)
- "FR test is unimplemented. Press any key to continue...\r\n"
- );
- wait_for_quit();
-}
+++ /dev/null
-/* Copyright (C) 2013 Czech Technical University in Prague
- *
- * Authors:
- * - Carlos Jenkins <carlos@jenkins.co.cr>
- *
- * This document contains proprietary information belonging to Czech
- * Technical University in Prague. Passing on and copying of this
- * document, and communication of its contents is not permitted
- * without prior written authorization.
- *
- * File : aout.c
- * Abstract:
- * RPP test suite - module for testing AOUT.
- *
- * References:
- * test.h
- */
-
-
-#include <math.h> // sin()
-
-#include "rpp/rpp.h"
-#include "test.h"
-
-#define SINE_FREQ_HZ 0.05
-#define SAMPLE_RATE_HZ 20
-// Which means 1% increment of duty cycle per sample
-
-
-// Task control
-static boolean_t stop_tasks = FALSE;
-static uint8_t tasks_running = 0;
-
-
-/**
- * FreeRTOS Task that controls the H-Bridge following a sine wave.
- */
-void hbr_test_task(void *par)
-{
- rpp_sci_printf((const char *)
- "H-Bridge Test at %1.2f Hz:\r\n", SINE_FREQ_HZ
- );
- rpp_sci_printf((const char *)
- "===========================================================\r\n"
- );
- rpp_sci_printf((const char *)"Samples: 0");
-
- // Calculate wait time in OS ticks
- static const portTickType freq_ticks = configTICK_RATE_HZ / SAMPLE_RATE_HZ;
- portTickType last_wake_time = xTaskGetTickCount();
-
- // Constant trigonometric variables
- const double two_pi = 2.0 * (4.0 * atan(1.0)); // Just 2pi
- /*
- * A little bit of math:
- * In this example we want to generate a 0.05Hz (one period each 20s)
- * sinusoid wave with a sampling rate of 20Hz so duty cycle increments or
- * decrements 1% per sample.
- */
- const double step = (two_pi * SINE_FREQ_HZ) / SAMPLE_RATE_HZ;
-
- uint64_t samples = 0;
- int i = 0;
- while (!stop_tasks) {
-
- for (i = 0; (i < SAMPLE_RATE_HZ) && !stop_tasks; i++, samples++) {
-
- // Update H-Bridge
- if (rpp_hbr_control(sin(samples * step)) != SUCCESS)
- rpp_sci_printf((const char *)
- "ERROR: Input error on H-Bridge control signal.\r\n"
- );
-
- // Wait until next step
- if (!stop_tasks)
- vTaskDelayUntil(&last_wake_time, freq_ticks);
- }
-
- rpp_sci_printf((const char *)
- "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
- "Samples: %lu", samples + 1
- );
-
- }
-
- // Delete myself
- tasks_running--;
- vTaskDelete(NULL);
-}
-
-
-/**
- * HBR Test entry point.
- */
-void test_hbr()
-{
- /// Configure module
- // Configure H-Bridge at default frequency
- if (rpp_hbr_enable(-1) != SUCCESS) {
- rpp_sci_printf((const char *)
- "ERROR: H-Bridge could not be started.\r\n"
- );
- wait_for_quit();
- return;
- }
-
-
- /// Spawn tasks
- xTaskHandle test_task_handle;
-
- portBASE_TYPE task_created = xTaskCreate(hbr_test_task,
- (const signed char *)"hbr_test_task",
- TEST_TASK_STACK, NULL, TEST_TASK_PRIORITY,
- &test_task_handle
- );
-
- if (task_created != pdPASS) {
-
- rpp_sci_printf((const char *)
- "ERROR: Problem spawning the test task. "
- "Error code: %d\r\n", (uint32_t)task_created
- );
- if (rpp_hbr_disable() != SUCCESS)
- rpp_sci_printf((const char *)
- "ERROR: Could not stop H-Bridge module.\r\n"
- );
- wait_for_quit();
- return;
- }
- tasks_running++;
-
-
- // Wait for user exit
- wait_for_quit();
- stop_tasks = TRUE;
- while (tasks_running > 0)
- taskYIELD();
- stop_tasks = FALSE;
-
-
- /// Reset module configuration
- if (rpp_hbr_disable() != SUCCESS)
- rpp_sci_printf((const char *)
- "ERROR: Could not stop H-Bridge module.\r\n"
- );
-
-
- rpp_sci_printf((const char *)"\r\n");
-
- return;
-}
+++ /dev/null
-/* Copyright (C) 2013 Czech Technical University in Prague
- *
- * Authors:
- * - Carlos Jenkins <carlos@jenkins.co.cr>
- *
- * This document contains proprietary information belonging to Czech
- * Technical University in Prague. Passing on and copying of this
- * document, and communication of its contents is not permitted
- * without prior written authorization.
- *
- * File : hout.c
- * Abstract:
- * RPP test suite - module for testing HOUT.
- *
- * References:
- * test.h
- */
-
-
-#include "rpp/rpp.h"
-#include "test.h"
-
-
-/**
- * HOUT Test entry point.
- */
-void test_hout()
-{
- rpp_sci_printf((const char *)
- "HOUT test is unimplemented. Press any key to continue...\r\n"
- );
- wait_for_quit();
-}
+++ /dev/null
-/* Copyright (C) 2013 Czech Technical University in Prague
- *
- * Authors:
- * - Carlos Jenkins <carlos@jenkins.co.cr>
- *
- * This document contains proprietary information belonging to Czech
- * Technical University in Prague. Passing on and copying of this
- * document, and communication of its contents is not permitted
- * without prior written authorization.
- *
- * File : lin.c
- * Abstract:
- * RPP test suite - module for testing LIN.
- *
- * References:
- * test.h
- */
-
-
-#include "rpp/rpp.h"
-#include "test.h"
-
-
-/**
- * LIN Test entry point.
- */
-void test_lin()
-{
- rpp_sci_printf((const char *)
- "LIN test is unimplemented. Press any key to continue...\r\n"
- );
- wait_for_quit();
-}
+++ /dev/null
-/* Copyright (C) 2013 Czech Technical University in Prague
- *
- * Authors:
- * - Carlos Jenkins <carlos@jenkins.co.cr>
- *
- * This document contains proprietary information belonging to Czech
- * Technical University in Prague. Passing on and copying of this
- * document, and communication of its contents is not permitted
- * without prior written authorization.
- *
- * File : lout.c
- * Abstract:
- * RPP test suite - module for testing LOUT.
- *
- * References:
- * test.h
- */
-
-
-#include "rpp/rpp.h"
-#include "test.h"
-
-#define FREQ_MILLIS 1000
-
-
-// Task control
-static boolean_t stop_tasks = FALSE;
-static uint8_t tasks_running = 0;
-
-
-/**
- * FreeRTOS Task that outputs a counter to all the digital outputs.
- */
-void lout_test_task(void *par)
-{
- rpp_sci_printf((const char *)
- "Digital Output Test:\r\n"
- );
- rpp_sci_printf((const char *)
- "===========================================================\r\n"
- );
-
- // Calculate wait time in OS ticks
- static const portTickType freq_ticks = FREQ_MILLIS / portTICK_RATE_MS;
- portTickType last_wake_time = xTaskGetTickCount();
-
- uint8_t c = 0;
- uint8_t p = 0;
- while (!stop_tasks) {
-
- // Output counter
- for (p = 1; p <= 8; p++) {
- if (is_bit_set(c, p - 1))
- rpp_lout_set(p, HIGH);
- else
- rpp_lout_set(p, LOW);
- }
- rpp_lout_update();
-
- rpp_sci_printf((const char *)
- "\b\b\b\b\b\b\b\b\b\b\b\b"
- "Counter: %3d", c
- );
-
- c++;
-
- // Wait until next step
- if (!stop_tasks)
- vTaskDelayUntil(&last_wake_time, freq_ticks);
- }
-
- // Delete myself
- tasks_running--;
- vTaskDelete(NULL);
-}
-
-
-/**
- * LOUT Test entry point.
- */
-void test_lout()
-{
- /// Configure module
- // - Not needed
-
-
- /// Spawn tasks
- xTaskHandle test_task_handle;
-
- portBASE_TYPE task_created = xTaskCreate(lout_test_task,
- (const signed char *)"lout_test_task",
- TEST_TASK_STACK, NULL, TEST_TASK_PRIORITY,
- &test_task_handle
- );
-
- if (task_created != pdPASS) {
-
- rpp_sci_printf((const char *)
- "ERROR: Problem spawning the test task. "
- "Error code: %d\r\n", (uint32_t)task_created
- );
- wait_for_quit();
- return;
- }
- tasks_running++;
-
-
- // Wait for user exit
- wait_for_quit();
- stop_tasks = TRUE;
- while (tasks_running > 0)
- taskYIELD();
- stop_tasks = FALSE;
-
-
- /// Reset module configuration
- int p;
- for (p = 1; p <= 8; p++) {
- rpp_lout_set(p, LOW);
- }
- rpp_lout_update();
-
-
- rpp_sci_printf((const char *)"\r\n");
-
- return;
-}
{
if ( strncmp(string, "adc", BUF_SIZE) == 0)
test_adc();
- else if (strncmp(string, "dac", BUF_SIZE) == 0)
- test_dac();
else if (strncmp(string, "can", BUF_SIZE) == 0)
test_can();
else if (strncmp(string, "din", BUF_SIZE) == 0)
test_din();
- else if (strncmp(string, "eth", BUF_SIZE) == 0)
- test_eth();
- else if (strncmp(string, "fr", BUF_SIZE) == 0)
- test_fr();
- else if (strncmp(string, "hbr", BUF_SIZE) == 0)
- test_hbr();
- else if (strncmp(string, "hout", BUF_SIZE) == 0)
- test_hout();
- else if (strncmp(string, "lin", BUF_SIZE) == 0)
- test_lin();
- else if (strncmp(string, "lout", BUF_SIZE) == 0)
- test_lout();
- else if (strncmp(string, "mout", BUF_SIZE) == 0)
- test_mout();
else if (strncmp(string, "sci", BUF_SIZE) == 0)
test_sci();
- else if (strncmp(string, "sdc", BUF_SIZE) == 0)
- test_sdc();
- else if (strncmp(string, "sdr", BUF_SIZE) == 0)
- test_sdr();
else if (strncmp(string, "help", BUF_SIZE) == 0) {
rpp_sci_printf((const char *)"Available commands:\r\n");
rpp_sci_printf((const char *)"\thelp - Display this help.\r\n");
rpp_sci_printf((const char *)"\tain - Test Analog Input.\r\n");
- rpp_sci_printf((const char *)"\taout - Test Analog Output.\r\n");
rpp_sci_printf((const char *)"\tcan - Test CAN communication.\r\n");
rpp_sci_printf((const char *)"\tdin - Test Digital Inputs.\r\n");
- rpp_sci_printf((const char *)"\teth - Test Ethernet communication.\r\n");
- rpp_sci_printf((const char *)"\tfr - Test FlexRay communication.\r\n");
- rpp_sci_printf((const char *)"\thbr - Test H-Bridge.\r\n");
- rpp_sci_printf((const char *)"\thout - Test High Power Output.\r\n");
- rpp_sci_printf((const char *)"\tlin - Test LIN communication.\r\n");
- rpp_sci_printf((const char *)"\tlout - Test Digital Outputs.\r\n");
- rpp_sci_printf((const char *)"\tmout - Test Power Outputs.\r\n");
rpp_sci_printf((const char *)"\tsci - Test Serial Communication Interface.\r\n");
- rpp_sci_printf((const char *)"\tsdc - Test SD-Card.\r\n");
- rpp_sci_printf((const char *)"\tsdr - Test SD-RAM.\r\n");
}
else
// Unknown command, print buffer back
+++ /dev/null
-/* Copyright (C) 2013 Czech Technical University in Prague
- *
- * Authors:
- * - Carlos Jenkins <carlos@jenkins.co.cr>
- *
- * This document contains proprietary information belonging to Czech
- * Technical University in Prague. Passing on and copying of this
- * document, and communication of its contents is not permitted
- * without prior written authorization.
- *
- * File : mout.c
- * Abstract:
- * RPP test suite - module for testing MOUT.
- *
- * References:
- * test.h
- */
-
-
-#include "rpp/rpp.h"
-#include "test.h"
-
-#define FREQ_MILLIS 1000
-
-
-// Task control
-static boolean_t stop_tasks = FALSE;
-static uint8_t tasks_running = 0;
-
-
-/**
- * FreeRTOS Task that toggle the MOUT outputs, then reads the diagnostics and
- * compare.
- */
-void mout_test_task(void *par)
-{
- rpp_sci_printf((const char *)
- "Power Output Test:\r\n"
- );
- rpp_sci_printf((const char *)
- "===========================================================\r\n"
- );
- rpp_sci_printf((const char *)
- "1 2 3 4 5 6\r\n"
- // 1:BAD 1:BAD 1:BAD 1:BAD 1:BAD 1:BAD
- // 1: OK 1: OK 1: OK 1: OK 1: OK 1: OK
- );
-
- // Calculate wait time in OS ticks
- static const portTickType freq_ticks = FREQ_MILLIS / portTICK_RATE_MS;
- portTickType last_wake_time = xTaskGetTickCount();
-
- uint8_t i;
- uint8_t tmp;
- uint8_t pin;
- boolean_t state = TRUE;
- while (!stop_tasks) {
-
- // Toggle state one by one slowly
- for (pin = 1; pin <= 6; pin++) {
-
- // Change pin
- rpp_mout_set(pin, state);
-
- // Reprint values
- rpp_sci_printf((const char *)
- "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
- "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
- );
-
- tmp = pin;
- for (pin = 1; pin <= 6; pin++) {
- rpp_sci_printf((const char *)
- "%d: ", rpp_mout_get(pin)
- );
- }
- pin = tmp;
-
- // Wait for next change
- if (!stop_tasks)
- vTaskDelayUntil(&last_wake_time, freq_ticks);
- else
- break;
-
- }
- state = !state;
-
- if (!stop_tasks)
- rpp_sci_printf((const char *)
- "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
- "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
- );
-
- for (i = 0; i < 10; i++) {
-
- // Wait until next step
- if (!stop_tasks)
- vTaskDelayUntil(&last_wake_time, freq_ticks);
- else
- break;
-
- rpp_sci_printf((const char *)
- "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
- "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
- );
-
- for (pin = 1; pin <= 6; pin++) {
- rpp_sci_printf((const char *)
- "%d:%s ", rpp_mout_get(pin),
- (rpp_mout_diag(pin) == SUCCESS) ? " OK" : "BAD"
- );
- }
-
- }
- }
-
- // Delete myself
- tasks_running--;
- vTaskDelete(NULL);
-}
-
-
-/**
- * MOUT Test entry point.
- */
-void test_mout()
-{
- /// Configure module
- // - Not needed
-
-
- /// Spawn tasks
- xTaskHandle test_task_handle;
-
- portBASE_TYPE task_created = xTaskCreate(mout_test_task,
- (const signed char *)"mout_test_task",
- TEST_TASK_STACK, NULL, TEST_TASK_PRIORITY,
- &test_task_handle
- );
-
- if (task_created != pdPASS) {
-
- rpp_sci_printf((const char *)
- "ERROR: Problem spawning the test task. "
- "Error code: %d\r\n", (uint32_t)task_created
- );
- wait_for_quit();
- return;
- }
- tasks_running++;
-
-
- // Wait for user exit
- wait_for_quit();
- stop_tasks = TRUE;
- while (tasks_running > 0)
- taskYIELD();
- stop_tasks = FALSE;
-
-
- /// Reset module configuration
- uint8_t pin;
- for (pin = 1; pin <= 6; pin++) {
- rpp_mout_set(pin, LOW);
- }
-
-
- rpp_sci_printf((const char *)"\r\n");
-
- return;
-}
+++ /dev/null
-/* Copyright (C) 2013 Czech Technical University in Prague
- *
- * Authors:
- * - Carlos Jenkins <carlos@jenkins.co.cr>
- *
- * This document contains proprietary information belonging to Czech
- * Technical University in Prague. Passing on and copying of this
- * document, and communication of its contents is not permitted
- * without prior written authorization.
- *
- * File : sdc.c
- * Abstract:
- * RPP test suite - module for testing SDC.
- *
- * References:
- * test.h
- */
-
-
-#include "rpp/rpp.h"
-#include "test.h"
-
-
-/**
- * SDC Test entry point.
- */
-void test_sdc()
-{
- rpp_sci_printf((const char *)
- "SDC test is unimplemented. Press any key to continue...\r\n"
- );
- wait_for_quit();
-}
+++ /dev/null
-/* Copyright (C) 2013 Czech Technical University in Prague
- *
- * Authors:
- * - Carlos Jenkins <carlos@jenkins.co.cr>
- *
- * This document contains proprietary information belonging to Czech
- * Technical University in Prague. Passing on and copying of this
- * document, and communication of its contents is not permitted
- * without prior written authorization.
- *
- * File : sdr.c
- * Abstract:
- * RPP test suite - module for testing SDR.
- *
- * References:
- * test.h
- */
-
-
-#include <stdlib.h> // rand()
-
-#include "rpp/rpp.h"
-#include "test.h"
-
-#define BASE_FREQ_MILLIS 1000
-#define FREQ_VARIABILITY 100
-
-
-// Task control
-static boolean_t stop_tasks = FALSE;
-static uint8_t tasks_running = 0;
-
-
-static void wait_tasks_to_finish()
-{
- stop_tasks = TRUE;
- while (tasks_running > 0)
- taskYIELD();
- stop_tasks = FALSE;
-}
-
-
-/**
- * FreeRTOS Task that send some noise to the log from time to time.
- */
-void sdr_test_task(void *par)
-{
- // Calculate wait time in OS ticks
- static const portTickType freq_ticks = BASE_FREQ_MILLIS / portTICK_RATE_MS;
- portTickType last_wake_time = xTaskGetTickCount();
-
- // Initialize rand
- srand(2097925); // They are random, I swear xD
-
- uint32_t i = 0;
- uint32_t variation = 0;
- int8_t plus_minus = 1;
- while (!stop_tasks) {
-
- // Put something in the log
- rpp_sdr_printf((const char *)
- "This is the noise generator at iteration %d "
- "putting some noise value %d.", i, rand()
- );
- i++;
-
- if (!stop_tasks) {
- variation = freq_ticks +
- (plus_minus * ((rand() % FREQ_VARIABILITY) + 1));
- plus_minus = plus_minus * -1;
- vTaskDelayUntil(&last_wake_time, variation);
- }
- }
-
- // Delete myself
- tasks_running--;
- vTaskDelete(NULL);
-}
-
-
-extern xSemaphoreHandle rpp_sdr_cmdproc_semaphore;
-
-/**
- * SDR Test entry point.
- */
-void test_sdr()
-{
- /// Configure module
- // - See note below.
-
-
- /// Spawn tasks
- xTaskHandle test_task_handle;
-
- // Spawn noise task first, and later enable logging. Depending on the time
- // required the first logs might not be registered, but that's ok, is better
- // to check if logging could be enabled after data is being sent that enable
- // command processor (which output messages to the SCI), and that inmediatly
- // after the noise task could not be created, forcing to close the just
- // opened command processor.
- portBASE_TYPE task_created = xTaskCreate(sdr_test_task,
- (const signed char *)"sdr_test_task",
- TEST_TASK_STACK, NULL, TEST_TASK_PRIORITY,
- &test_task_handle
- );
-
- if (task_created != pdPASS) {
-
- rpp_sci_printf((const char *)
- "ERROR: Problem spawning the test task. "
- "Error code: %d\r\n", (uint32_t)task_created
- );
-
- wait_for_quit();
- return;
- }
- tasks_running++;
-
- if (rpp_sdr_setup(TRUE) != SUCCESS) {
- rpp_sci_printf((const char *)
- "ERROR: Problem enabling the logging module. "
- );
- wait_for_quit();
- wait_tasks_to_finish();
- return;
- }
-
- // Wait for the SDR included command processor to finish
- xSemaphoreTake(rpp_sdr_cmdproc_semaphore, portMAX_DELAY);
- wait_tasks_to_finish();
-
-
- /// Reset module configuration
- if (rpp_sdr_setup(FALSE) != SUCCESS) {
- rpp_sci_printf((const char *)
- "ERROR: Could not stop logging module.\r\n"
- );
- wait_for_quit();
- }
-
-
- rpp_sci_printf((const char *)"\r\n");
-
- return;
-}
#include "netif/etharp.h"
#include "lwip/sys.h"
-#include "rpp/eth.h"
#include "sys/hw_emac.h"
#define EMAC_CTRL_RAM_BASE_m(x) EMAC_CTRL_RAM_ ## x ## _BASE
+++ /dev/null
-/**
- * Analog Output RPP API header file.
- *
- * @file dac.h
- *
- * @copyright Copyright (C) 2013 Czech Technical University in Prague
- *
- * @author Carlos Jenkins <carlos@jenkins.co.cr>
- */
-
-
-#ifndef __RPP_DAC_H
-#define __RPP_DAC_H
-
-/**
- * DAC output operational amplifier multiplication constant.
- */
-#define RPP_DAC_OA 5.6
-/**
- * DAC hardware reference voltage.
- */
-#define RPP_DAC_VREF 2.5
-
-/**
- * DAC module initialization.
- *
- * Call this method before using this module.
- *
- * @return SUCCESS if initialization successful.\n
- * FAILURE if module already initialized.
- */
-int8_t rpp_dac_init();
-
-
-/**
- * Configure enabled/disabled state for given pin.
- *
- * Call rpp_dac_update() to commit setup changes to real hardware.
- *
- * @param[in] pin The pin number to setup [1-4].
- * @param[in] enabled TRUE to enable pin or FALSE to disable it.
- *
- * @return SUCCESS if successful.\n
- * -1 if pin number is out of range.
- */
-int8_t rpp_dac_setup(uint8_t pin, boolean_t enabled);
-
-
-/**
- * Set the output cache of given pin to given value.
- *
- * Call rpp_dac_update() to flush cached values to real hardware.
- *
- * @param[in] pin The pin number to set [1-4].
- * @param[in] val The value to be set [0-4095] (DAC is 12bit resolution).
- *
- * @return SUCCESS when success.\n
- * -1 if pin number is out of range.\n
- * -2 if value is out of range.
- *
- * @note Due to hardware characteristics (operational amplifiers and voltage
- * reference) the DAC outputs top 12V at arround 3510. To avoid confusion
- * to the user and to support future changes the value given is mapped
- * from [0-4095] to [0-3510] with the expected resolution loss.
- */
-int8_t rpp_dac_set(uint8_t pin, uint16_t val);
-
-
-/**
- * Set output to given voltage.
- *
- * Helper function that calculates DAC value given a voltage in millivolts.
- *
- * @param[in] pin The pin number to set [1-4].
- * @param[in] mv Voltage level in mV to be set on specified pin [0-12000].
- *
- * @return SUCCESS when success.\n
- * -1 if pin number is out of range.\n
- * -2 if voltage is out of range.
- */
-int8_t rpp_dac_set_voltage(uint8_t pin, uint16_t mv);
-
-
-/**
- * Flush cached output values and configuration changes.
- *
- * @bug This function should be called only after the FreeRTOS Scheduler has
- * started (which implies from a FreeRTOS Task). If called before starting the
- * scheduler, like for library initialization, or application DAC
- * initialization, the application will freeze. The cause of this is unknown at
- * the moment.
- *
- * @return SUCCESS when transaction was successful.\n
- * FAILURE if transaction could not be confirmed.
- */
-int8_t rpp_dac_update();
-
-
-#endif /* __RPP_DAC_H */
+++ /dev/null
-/**
- * Ethernet Communication RPP API header file.
- *
- * @file eth.h
- *
- * @copyright Copyright (C) 2013 Czech Technical University in Prague
- *
- * @author Carlos Jenkins <carlos@jenkins.co.cr>
- * @author Rostislav Lisový
- * @author Jan Doležal <pm.jenik@gmail.com>
- */
-
-#ifndef __RPP_ETH_H
-#define __RPP_ETH_H
-
-#include <stdio.h>
-
-#include "os/os.h"
-#include "lwip/netif.h"
-
-/* this MAC address is used when user put NULL on the right place when calling postInit function */
-/**
- * Default MAC address for interface.
- */
-#define RPP_MAC_ADDR {0x12,0x34,0x56,0x78,0x9a,0xbc}
-#if STATIC_IP_ADDRESS
-/**
- * When static IP is configured in lwipopts.h, this IP address is used for interface.
- */
-#define RPP_IP_ADDR 0xC0A8F701 /* 192.168.247.1 IP4_ADDR(rppip, 192,168,0,10); */
-/**
- * When static IP is configured in lwipopts.h, this NETMASK address is used for interface.
- */
-#define RPP_NETMASK 0xFFFFFF00 /* 255.255.255.0 IP4_ADDR(rppnetmask, 255,255,255,0); */
-/**
- * When static IP is configured in lwipopts.h, this Gateway address is used for interface.
- */
-#define RPP_GW 0xC0A8F7FE /* 192.168.247.254 IP4_ADDR(rppgw, 192,168,0,254); */
-#endif
-
-/**
- * While scanning phy addresses no alive phy was found.
- * Return value of rpp_eth_hw_init() function.
- */
-#define NO_PHY_ALIVE -1
-/**
- * Scanning default phy address, it was found it's not alive.
- * Return value of rpp_eth_hw_init() function.
- */
-#define DFLT_PHY_NOT_ALIVE -1
-/**
- * When setting autonegotiation parameters to EMAC module, there was found impossible mode (usually on timeout of autonegotiation).
- * Return value of rpp_eth_hw_init_postInit() function.
- */
-#define UNKN_DUPLEX_MODE -2 /* this could mean that autonegotiation was not completed yet */
-/**
- * Phy is down error.
- * Return value of rpp_eth_init_postInit() function.
- */
-#define PHY_LINK_DOWN -3
-
-/**
- * LwIP netif couldn't be added, it is likely that there was an error during initialization of the hardware.
- */
-#define NETIF_ADD_ERR -10 /* could be one of previous, except PHY_LINK_DOWN - currently */
-/**
- * Memory requirements couldn't be satisfied.
- */
-#define DHCP_MEM_ERR -11
-
-/**
- * Configure which function will be used for debugging prints
- */
-#ifdef DEBUG
-#define rpp_debug_printf rpp_sci_printf
-#else
-#define rpp_debug_printf(...)
-#endif
-
-/**
- * configures whether rpp_eth_get_macAddrStr() creates string with big or small latin letters
- */
-#define MAC_BIG_LETTERS 1
-
-/**
- * This function allows application to check whether eth was already initialized
- * (it's post OS starup part)
- *
- * @return TRUE if initialized
- * FALSE if not initialized
- */
-boolean_t isPostInitialized();
-
-/**
- * ETH module system startup initialization.
- *
- * Call this method before using this module.
- * This method starts autonegotiation and doesn't check for end of autoneg.
- * When eth module is about to be used, you have to run rpp_eth_init_postInit()
- * first and you should check whether link is up.
- *
- * @return SUCCESS if initialization successful.\n
- * FAILURE if module already initialized.
- */
-int8_t rpp_eth_init();
-
-/**
- * ETH module application initialization.
- *
- * Call this method before using eth module.
- * This method waits for a while on autonegotiation till it's complete, if not completed
- * in predefined time it continues with creating tasks for lwIP (including lwIP init),
- * for receiving and for handling transmission buffer descriptors. Sets IP address using
- * predefined static IP or DHCP. Before calling this method you must call rpp_eth_init() first.
- *
- * @param instNum number of EMAC instance
- * @param macArray address assigned to link layer - when NULL RPP_MAC_ADDR is used
- *
- * @return SUCCESS if init successful.
- * FAILURE if module was already initialized
- * NETIF_ADD_ERR if lwip netif was not succesfully initialized or on low hw init error.
- * DHCP_MEM_ERR if DHCP unsuccesfull.
- */
-int8_t rpp_eth_init_postInit(uint32_t instNum, uint8_t *macArray);
-
-// Helper routines/functions for command processor and other applications
-
-/**
- * Uses MDIO module to read link status of PHY attached to instNum network interface
- *
- * @param instNum Number of network interface
- *
- * @return TRUE if link is UP
- * FALSE if link is DOWN
- */
-uint32_t rpp_eth_phylinkstat(uint32_t instNum);
-
-/**
- * Fills macStr field with MAC address of given network interface instance as 'string'
- *
- * @note 18 bytes will be filled {2 chars per 6 mac bytes + 5 semicolons + 1 null termination}
- *
- * @param instNum Number of network interface
- * @param *macStr field where null terminated string will be inserted
- */
-void rpp_eth_get_macAddrStr(uint32_t instNum, uint8_t *macStr);
-
-/**
- * Fills ipStr field with IP address in ip_addr_t as 'string';
- * prepares an IP address to ipStr in form of null terminated string;
- * each byte of ip is converted to one of 4 field in IPv4 IP address format 0xAABBCCDD -> "aaa.bbb.ccc.ddd"
- *
- * @note up to 16 bytes will be filled {1-3 * 4 IP fields + 3 dots + 1 null termination}
- *
- *
- * @param ip ip address to be converted
- * @param ipStr pointer to string where ip will be filled as text
- */
-inline void rpp_eth_getIPDecimalStr(ip_addr_t ip, uint8_t *ipStr)
-{
- snprintf((char *)ipStr, 16, "%d.%d.%d.%d",(ip.addr >> 24),((ip.addr >> 16) & 0xff),((ip.addr >> 8) & 0xff),(ip.addr & 0xff));
-}
-
-/**
- * Fills ip.addr with converted ipstr. Checks for correct format of IP string
- * x.x.x.x where x = [0..9]. When FAILURE is returned struct ip was not modified.
- *
- * @param ip struct to be filled
- * @param ipstr string to be converted
- *
- * @return SUCCESS when succesfully converted
- * FAILURE when wrong format of IP string
- */
-err_t rpp_eth_stringToIP(ip_addr_t *ip, uint8_t *ipstr);
-
-/**
- * Converts given null terminated string containing number to number in
- * range <1-65535>
- *
- * @param string to be converted
- * @return 0 on error
- * port number otherwise
- */
-uint16_t rpp_eth_portStrToInt(uint8_t *string);
-
-/**
- * Returns struct describing network interface
- *
- * @param instNum instance number of network interface
- *
- * @return pointer to struct netif
- */
-struct netif *rpp_eth_get_netif(uint32_t instNum);
-
-/**
- * Adjusts packet (pbuf) length and send it within critical section
- * using rpp_eth_send_raw()
- *
- * @param netif lwIP network interface describing struct
- * @param p buffer for data to be sent
- *
- * @return always SUCCESS (0)
- */
-err_t rpp_eth_send(struct netif *netif, struct pbuf *p);
-
-/**
- * Handles transmission of data buffer p through EMAC to network.
- *
- * @param netif lwIP network interface describing struct
- * @param p buffer for data to be sent
- *
- * @return always SUCCESS (0)
- */
-err_t rpp_eth_send_raw(struct netif *netif, struct pbuf *p);
-
-/**
- * Receives raw data and sends them upward to lwIP stack.
- * Handles rx emac descriptors.
- *
- * @note when using OS tasks (!NO_SYS) this function is used as
- * task, otherwise (NO_SYS) this is called from RX ISR.
- *
- * @param arg netif
- */
-void rpp_eth_recv_raw(void *arg);
-
-/**
- * Handles freeing of buffer descriptors and other structures in memory
- * after transmission of bd was completed.
- *
- * @param arg hdkif
- */
-void rpp_eth_send_bd_handler(void *arg);
-
-/**
- * Handles receiving by running rpp_eth_recv_raw()
- *
- * @param instNum number of EMAC instance
- */
-void RxIntHandler(u32_t instNum);
-
-/**
- * Handles tx emac descriptors.
- *
- * @param instNum number of EMAC instance
- */
-void TxIntHandler(u32_t instNum);
-
-#endif /* __RPP_ETH_H */
+++ /dev/null
-/**
- * FlexRay Communication RPP API header file.
- *
- * @file fr.h
- *
- * @copyright Copyright (C) 2013 Czech Technical University in Prague
- *
- * @author Carlos Jenkins <carlos@jenkins.co.cr>
- * @author Michal Horn <hornmich@fel.cvut.cz>
- */
-
-
-#ifndef __RPP_FR_H
-#define __RPP_FR_H
-
-#include "drv/Fr_GeneralTypes.h"
-#include "drv/fr_tms570.h"
-
-/**
- * Enumeration of states for the FlexRay
- */
-typedef enum {
- RPP_FR_UNKNOWN, /**< FlexRay is in unknown state, this should not happen */
- RPP_FR_NOT_INITIALIZED, /**< FlexRay driver was not yet configured and initialized, communication is not running. This is the default state after reset */
- RPP_FR_DRV_INITIALIZED, /**< FlexRay driver was initialized, communication is not running, Driver is ready for controller initialization */
- RPP_FR_CTR_INITIALIZED, /**< FlexRay controller was initlized, communicatin is not running, but can be started */
- RPP_FR_RUNNING, /**< Communication is running */
- RPP_FR_HALTED, /**< Communication was halted, controller is ready for reconfiguration and restart of the communication */
- RPP_FR_ABORTED /**< Communication was aborted, controller is ready for reconfiguration and restart of the communication */
-} rpp_fr_state_t;
-
-#define RPP_FR_MAX_STATIC_BUF_CNT 32 /**< Maximum number of the buffers for static segment of the communication cycle */
-#define RPP_FR_MAX_DYNAMIC_BUF_CNT 32 /**< Maximum number of the buffers for dynamic segment of the communication cycle */
-#define RPP_FR_MAX_FIFO_BUF_DEPTH 32 /**< Maximal depth of the RX FIFO buffer */
-
-/* AUTOSAR-like API */
-
-/**
- * FlexRay driver initialization.
- *
- * This method should be called before any other function from this
- * module.
- *
- * The function copies configuration data into drivers internal
- * structures and initializes the driver.
- *
- * After a successful driver initialization, the driver is ready for calling:
- * - rpp_fr_init_controller()
- * - rpp_fr_get_poc_status()
- * - rpp_fr_get_wakeup_rx_status()
- * - rpp_fr_get_timer_irq_status()
- *
- * @param [in] config_ptr Address of the structure with all FlexRay
- * configuration parameters.
- * @param [out] error Address where error flags will be stored. The flags
- * definitions can be found in fr_tms570.h, with ERR_PARAM prefix.
- *
- * @return SUCCESS if initialization successful.
- * FAILURE if module already initialized.
- *
- */
-int8_t rpp_fr_init_driver(const Fr_ConfigType *config_ptr, uint32_t *error);
-
-/**
- * FlexRay controller initialization.
- *
- * This method should be called after rpp_fr_init_driver(), rpp_fr_halt_communication() or
- * rpp_fr_abort_communication() and before any other function from this module.
- *
- * Use this sequence to restart communication after halt or abort functions were called:
- * - rpp_fr_init_controller()
- * - rpp_fr_start_communication()
- * - rpp_fr_all_slots() (optionally)
- *
- * The functions checks configuration parameters and configures FlexRay
- * controller registers.
- *
- * After successful controller initialization, the FlexRay driver is ready for calling:
- * - rpp_fr_get_poc_status()
- * - rpp_fr_get_wakeup_rx_status()
- * - rpp_fr_get_timer_irq_status()
- * - rpp_fr_start_communication()
- * - rpp_fr_send_wup()
- * - rpp_fr_set_wu_channel()
- * - rpp_fr_get_global_time()
- * - rpp_fr_get_network_management_vector()
- * - rpp_fr_get_channel_status()
- * - rpp_fr_reconfigure_lpdu()
- *
- * @param [in] ctrl Not used, set always to zero.
- * @param [out] error Address where error flags will be stored. The flags
- * definitions can be found in fr_tms570.h, with ERR_PARAM and FR_INIT_ERR
- * prefix.
- *
- * @return SUCCESS if initialization if successful.
- * FAILURE if module already initialized.
- */
-
-int8_t rpp_fr_init_controller(uint8_t ctrl, uint32_t *error);
-
-/**
- * Start communication
- *
- * This method should be called after rpp_fr_init_controller() and
- * before any attempt to send or receive messages.
- *
- * For coldstarter node the function listens and tries to join an
- * existing network. If it fails, it tries to initiate the new one.
- * For regular node it only listens on the bus and tries to join to
- * some existing network.
- *
- * After successful communication start, the FlexRay is ready for:
- * - rpp_fr_get_poc_status()
- * - rpp_fr_get_wakeup_rx_status()
- * - rpp_fr_get_timer_irq_status()
- * - rpp_fr_set_wu_channel()
- * - rpp_fr_get_global_time()
- * - rpp_fr_get_network_management_vector()
- * - rpp_fr_get_channel_status()
- * - rpp_fr_all_slots()
- * - rpp_fr_halt_communication()
- * - rpp_fr_abort_communication()
- * - rpp_fr_transmit_lpdu()
- * - rpp_fr_cancel_transmit_lpdu()
- * - rpp_fr_receive_lpdu()
- * - rpp_fr_check_tx_lpdu_status()
- * - rpp_fr_disable_lpdu()
- * - rpp_fr_get_clock_correction()
- * - rpp_fr_get_sync_frame_list()
- * - rpp_fr_set_timer()
- * - rpp_fr_cancel_timer()
- * - rpp_fr_reconfigure_lpdu()
- *
- *
- * @param [in] ctrl Not used, set always to zero.
- * @param [out] error Address where error flags will be stored. The flags
- * definitions can be found in fr_tms570h, with FR_STARTUP_ERR prefix.
- *
- * @return SUCCESS if initialization successful.
- * FAILURE if module already initialized.
- *
- */
-int8_t rpp_fr_start_communication(uint8_t ctrl, uint32_t *error);
-
-/**
- * Allow communication on all slots
- *
- * The FlexRay node can be configured to communicate only on key
- * frames after the startup. If this is the case, after calling this
- * function, communication on all configured slots is allowed.
- *
- * The function should be called only after rpp_fr_start_communication() has been called.
- *
- * @param [in] ctrl Not used, set always to zero.
- *
- * @return SUCCESS if started successfully.
- * FAILURE if timeout reached.
- *
- */
-int8_t rpp_fr_all_slots(uint8_t ctrl);
-
-/**
- * Stop communication after the end of the communication cycle.
- *
- * The function should be called only after
- * rpp_fr_start_communication() has been called.
- *
- * After the communication is stopped, only those functions are allowed to be called:
- * - rpp_fr_set_wu_channel()
- * - rpp_fr_get_global_time()
- * - rpp_fr_get_network_management_vector()
- * - rpp_fr_get_channel_status()
- * - rpp_fr_get_clock_correction()
- * - rpp_fr_get_sync_frame_list()
- * - rpp_fr_get_wakeup_rx_status()
- * - rpp_fr_get_poc_status()
- * - rpp_fr_init_controller()
- *
- * To restart the communication, the following sequence has to be called:
- * - rpp_fr_init_controller()
- * - rpp_fr_start_communication()
- * - rpp_fr_all_slots() (optionally)
- *
- *
- * @param [in] ctrl Not used, set always to zero.
- *
- * @return SUCCESS if command passed successfully.
- * FAILURE if command rejected.
- *
- */
-int8_t rpp_fr_halt_communication(uint8_t ctrl);
-
-/**
- * Stop communication immediately.
- *
- * The function should be called only after
- * rpp_fr_start_communication() has been called.
- *
- * After the communication is stopped, only those functions are allowed to be called:
- * - rpp_fr_set_wu_channel()
- * - rpp_fr_get_global_time()
- * - rpp_fr_get_network_management_vector()
- * - rpp_fr_get_channel_status()
- * - rpp_fr_get_clock_correction()
- * - rpp_fr_get_sync_frame_list()
- * - rpp_fr_get_wakeup_rx_status()
- * - rpp_fr_get_poc_status()
- * - rpp_fr_init_controller()
- *
- * To restart the communication, the following sequence has to be called:
- * - rpp_fr_init_controller()
- * - rpp_fr_start_communication()
- * - rpp_fr_all_slots() (optionally)
- *
- * @param [in] ctrl Not used, set always to zero.
- *
- * @return SUCCESS if command passed successfully.
- * FAILURE if command rejected.
- *
- */
-int8_t rpp_fr_abort_communication(uint8_t ctrl);
-
-/**
- * Send wakeup pattern.
- *
- * The function should be called after FlexRay controller is initialized
- * and before the communication start.
- *
- * @param [in] ctrl Not used, set always to zero.
- *
- * @return SUCCESS if command passed successfully.
- * FAILURE if command rejected.
- *
- */
-int8_t rpp_fr_send_wup(uint8_t ctrl);
-
-/**
- * Set channel for wakeup pattern sending.
- *
- * This allows to change the configuration passed to the
- * rpp_fr_init_driver().
- *
- * The function should be called after FlexRay controller is initialized
- * and before the communication started.
- *
- * @param [in] ctrl Not used, set always to zero.
- * @param [in] channel Channel selector, where wakeup pattern will be sent
- *
- * @return SUCCESS if command passed successfully.
- * FAILURE if command rejected.
- *
- */
-int8_t rpp_fr_set_wu_channel(uint8_t ctrl, Fr_ChannelType channel);
-
-/**
- * Get FlexRay POC state
- *
- * The function can be called any time after the driver is
- * initialized.
- *
- * @param [in] ctrl Not used, set always to zero.
- * @param [out] poc_status_ptr Address where status will be stored.
- *
- * @return SUCCESS if status retrieved successfully.
- * FAILURE if something failed.
- *
- */
-int8_t rpp_fr_get_poc_status(uint8_t ctrl, Fr_POCStatusType *poc_status_ptr);
-
-/**
- * Send a message on the bus in the specified frame
- *
- * The function can be called any time when communication is running
- * (rpp_fr_start_communication() was called).
- *
- * If the buffer assigned to the frame is configured for continuous
- * mode, this functions starts sending the message periodically. The
- * transmission can be stopped by rpp_fr_cancel_transmit_lpdu(). If
- * the buffer assigned to the frame is configured for single-shot
- * mode, the message is sent only once.
- *
- * @param [in] ctrl Not used, set always to zero.
- * @param [in] lpdu_idx Index of the frame, where the message will be sent.
- * @param [in] lsdu Address of the first byte of the message.
- * @param [in] lsdu_length Number of bytes of the message.
- *
- * @return SUCCESS if message was transmitted.
- * FAILURE if something failed.
- *
- */
-int8_t rpp_fr_transmit_lpdu(uint8_t ctrl, uint16_t lpdu_idx, const uint8_t *lsdu, uint8_t lsdu_length);
-
-/**
- * Cancel a transmission of the message.
- *
- * The function can be called any time when communication is running
- * (rpp_fr_start_communication() was called).
- *
- * This is one way to stop transmission for buffers configured for
- * continuous mode. The other way is to use rpp_fr_disable_lpdu().
- *
- * @param [in] ctrl Not used, set always to zero.
- * @param [in] lpdu_idx Index of the frame, where the message transmission will be stopped.
- *
- * @return SUCCESS if the transmission was stopped.
- * FAILURE if something failed.
- *
- */
-int8_t rpp_fr_cancel_transmit_lpdu(uint8_t ctrl, uint16_t lpdu_idx);
-
-/**
- * Receive a message from the bus from the specified frame.
- *
- * The function can be called any time when communication is running
- * (rpp_fr_start_communication() was called).
- *
- * If a new message was received in a buffer configured for the static
- * and dynamic segment or FIFO, this function can retrieve it.
- *
- * The buffers with lower index (specified in configuration) have higher
- * priority in retrieving process. This means for example if some buffer is
- * configured to accept messages from slot 2 on channel A and another buffer
- * accepts from slot 2 on channel B, the message from the first buffer
- * will be retrieved first. If there is a FIFO buffer configured to accept
- * messages from slot 2 in different cyclesets then other buffers, those
- * messages accepted by the FIFO will be retrieved at the end of the process.
- *
- * @param [in] ctrl Not used, set always to zero.
- * @param [in] lpdu_idx Index of the frame where message will be received from.
- * @param [out] lsdu Address of the first byte of the buffer, where message will be stored.
- * @param [out] lpdu_status Address where the status will be stored. It can be:
- * FR_NOT_RECEIVED, FR_RECEIVED, FR_RECEIVED_MORE_DATA_AVAILABLE - for FIFO only.
- * @param [out] lsdu_length Number of bytes of the message.
- *
- * @return SUCCESS if message was received.
- * FAILURE if something failed.
- *
- */
-int8_t rpp_fr_receive_lpdu(uint8_t ctrl, uint16_t lpdu_idx, uint8_t *lsdu, Fr_RxLPduStatusType *lpdu_status, uint8_t *lsdu_length);
-
-/**
- * Check TX buffer status
- *
- * The function can be called any time when communication is running
- * (rpp_fr_start_communication() was called).
- *
- * The status says whether a transmission request (TXR) is pending or
- * not.
- *
- * If the buffer is configured for single-shot mode, the (TXR) is
- * pending until the message is sent. For buffers configured in
- * continuous mode, the transmission request is always pending.
- *
- *
- * @param [in] ctrl Not used, set always to zero.
- * @param [in] lpdu_idx Index of the frame to which the buffer is assigned.
- * @param [out] lpdu_status Address of the status. It can be FR_TRANSMITTED,
- * which means the TXR is not pending, or FR_NOT_TRANSMITTED which means that
- * TXR is pending.
- *
- * @return SUCCESS if everything is OK.
- * FAILURE if something failed.
- */
-int8_t rpp_fr_check_tx_lpdu_status(uint8_t ctrl, uint16_t lpdu_idx, Fr_TxLPduStatusType *lpdu_status);
-
-
-/**
- * Reconfigure buffer
- *
- * The function can be called any time when after controller was initialized
- * (rpp_fr_init_controller() was called).
- *
- * If the node is configured to allow buffer reconfiguration, some of the buffers
- * can be reconfigured in runtime. Buffers used for synchronization and buffers
- * assigned to the RX FIFO can not be reconfigured.
- *
- * It is not possible to change the direction (TX/RX) of the buffer or to change
- * the mode (single-shot/continuous).
- *
- * Messages that were planned to be sent or received might not be transmitted or received
- * if reconfiguration occurs in bad time.
- *
- * @param [in] ctrl Not used, set always to zero.
- * @param [in] lpdu_idx Index of the frame, where reconfigured buffer is communicating.
- * @param [in] frame_id Frame ID, where the buffer will be communicating after the reconfiguration.
- * @param [in] channel Channel, where the buffer will be communicating. For dynamic segment it should not be AB.
- * @param [in] cycle_set Cycle set value for cycle filtering. Can be 1, 2, 4, 8, 16, 32, 64.
- * @param [in] cycle_offset Cycle offset value for cycle filtering. Must be 0 - cycle_set-1
- * @param [in] payload Maximum payload for the reconfigured buffer in bytes. Must not be higher than the original payload, defined in half-words.
- * @param [in] header_crc Not used, set to zero. The CRC is calculated automaticaly inside the function.
- *
- * @return SUCCESS if everything is OK.
- * FAILURE if something failed.
- */
-int8_t rpp_fr_reconfigure_lpdu(uint8_t ctrl, uint16_t lpdu_idx, uint16_t frame_id, Fr_ChannelType channel, uint8_t cycle_set, uint8_t cycle_offset, uint8_t payload, uint16_t header_crc);
-
-/**
- * Disable a FlexRay buffer
- *
- * The function can be called any time when communication is running
- * (rpp_fr_start_communication() was called).
- *
- * This functions resets the configuration of the selected buffer.
- * The disabled buffer is not accessible or reconfigurable any more.
- *
- * @param [in] ctrl Not used, set always to zero.
- * @param [in] lpdu_idx Index of the frame to which the buffer is assigned.
- *
- * @return SUCCESS if buffer was disabled.
- * FAILURE if something failed.
- *
- */
-int8_t rpp_fr_disable_lpdu(uint8_t ctrl, uint16_t lpdu_idx);
-
-/**
- * Get FlexRay global time
- *
- * The function can be called any time after the controller is initialized.
- *
- * @param [in] ctrl Not used, set always to zero.
- * @param [out] cycle Adress where the number of actual cycle will be stored.
- * @param [out] macroticks Address where offset in the cycle will be stored.
- *
- * @return SUCCESS if everything is OK.
- * FAILURE if something failed.
- *
- */
-int8_t rpp_fr_get_global_time(uint8_t ctrl, uint8_t *cycle, uint16_t *macroticks);
-
-/**
- * Get Network management vector.
- *
- * The function can be called any time after the controller is initialized.
- *
- * The FlexRay controller updates the vector at the end of every cycle
- * by doing bit-wise OR on every network management (NM) vectors
- * received from all nodes.
- *
- * The NM vector can be sent in a frame by a buffer with the
- * payloadPreambleIndicatorTr parameter set. Those frames are
- * automatically processed by all the receiving controllers. But
- * sending the vector has to be done manually by copying the NM vector
- * data into the TX buffer (using the rpp_fr_transmit_lpdu() function).
- *
- * @param [in] ctrl Not used, set always to zero.
- * @param [out] nm_vector Address where the vector will be stored. The size of the buffer has to be at least gNetworkManagementVectorLength.
- *
- * @return SUCCESS if everything is OK.
- * FAILURE if something failed.
- */
-int8_t rpp_fr_get_network_management_vector(uint8_t ctrl, uint8_t *nm_vector);
-
-/**
- * Get channel status.
- *
- * The function can be called any time after the controller is
- * initialized.
- *
- * The output of the function is bitcoded in this way:
- * - Bit 0: Channel A/B aggregated channel status vSS!ValidFrame
- * - Bit 1: Channel A/B aggregated channel status vSS!SyntaxError
- * - Bit 2: Channel A/B aggregated channel status vSS!ContentError
- * - Bit 3: Channel A/B aggregated channel status additional communication
- * - Bit 4: Channel A/B aggregated channel status vSS!Bviolation
- * - Bit 5: Channel A/B aggregated channel status vSS!TxConflict
- * - Bit 6: Not used (0)
- * - Bit 7: Not used (0)
- * - Bit 8: Channel A/B symbol window status data vSS!ValidMTS
- * - Bit 9: Channel A/B symbol window status data vSS!SyntaxError
- * - Bit 10: Channel A/B symbol window status data vSS!Bviolation
- * - Bit 11: Channel A/B symbol window status data vSS!TxConflict
- * - Bit 12: Channel A/B NIT status data vSS!SyntaxError
- * - Bit 13: Channel A/B NIT status data vSS!Bviolation
- * - Bit 14: Not used (0)
- * - Bit 15: Not used (0)
- *
- * @param [in] ctrl Not used, set always to zero.
- * @param [out] channel_a_status Address where the bitcoded status of the channel A will be stored.
- * @param [out] channel_b_status Address where the bitcoded status of the channel B will be stored.
- *
- * @return SUCCESS if everything is OK.
- * FAILURE if something failed.
- *
- */
-int8_t rpp_fr_get_channel_status(uint8_t ctrl, uint16_t *channel_a_status, uint16_t *channel_b_status);
-
-/**
- * Get clock correction.
- *
- * The function can be called while the communication is running or
- * was stopped.
- *
- * @param [in] ctrl Not used, set always to zero.
- * @param [out] rate_correction Address where the rate will be stored.
- * @param [out] offset_correction Address where the offset will be stored.
- *
- * @return SUCCESS if everything is OK.
- * FAILURE if something failed.
- *
- */
-int8_t rpp_fr_get_clock_correction(uint8_t ctrl, int16_t *rate_correction, int32_t *offset_correction);
-
-/**
- * Gets a list of syncframes received or transmitted on channel A and channel B via the even and odd communication cycle.
- *
- * The function can be called while communication is running or was stopped.
- *
- * @param [in] ctrl Not used, set always to zero.
- * @param [in] list_size Size of the arrays passed via parameters:
- * @param [out] channel_a_even_list Address the list of syncframes on channel A within the
- * even communication cycle is written to. The exact
- * number of elements written to the list is limited by
- * parameter Fr_ListSize.
- * Unused list elements are filled with the value '0' to indicate that no more syncframe has been seen.
- * @param [out] channel_b_even_list Address the list of syncframes on channel B within the
- * even communication cycle is written to. The exact
- * number of elements written to the list is limited by
- * parameter Fr_ListSize.
- * @param [out] channel_a_odd_list Address the list of syncframes on channel A within the
- * odd communication cycle is written to. The exact number
- * of elements written to the list is limited by parameter
- * Fr_ListSize.
- * Unused list elements are filled with the value '0' to indicate that no more syncframe has been seen.
- * @param [out] channel_b_odd_list Address the list of syncframes on channel B within the
- *
- * @return SUCCESS if everything is OK.
- * FAILURE if something failed.
- *
- */
-int8_t rpp_fr_get_sync_frame_list(uint8_t ctrl, uint8_t list_size, uint16_t *channel_a_even_list,
- uint16_t *channel_b_even_list, uint16_t *channel_a_odd_list, uint16_t *channel_b_odd_list);
-
-/**
- * Get the status of WUP receiving
- *
- * The function can be called any time after controller is initialized.
- *
- * If the Wake Up Pattern was received on some channel, the flag is set in status address.
- * Bit 0: Wakeup received on channel A indicator
- * Bit 1: Wakeup received on channel B indicator
- * Bit 2-7: Unused
- *
- * @param [in] ctrl Not used, set always to zero.
- * @param [out] status Address where the status will be stored.
- *
- * @return SUCCESS if everything is OK.
- * FAILURE if something failed.
- *
- */
-int8_t rpp_fr_get_wakeup_rx_status(uint8_t ctrl, uint8_t *status);
-
-/**
- * Set the absolute timer and start it.
- *
- * The function can be called any time after communication is running.
- *
- * The FlexRay controller has two absolute timers. Each of them can be
- * configured to request the interrupt, when the global time reaches
- * configured cycle set and offset.
- *
- * Timer interrupt request can be detected by
- * rpp_fr_get_timer_irq_status(). The timer interrupt request can be
- * cleared by rpp_fr_clear_timer_irq(). The timer can be canceled by
- * rpp_fr_cancel_timer().
- *
- * @param [in] ctrl Not used, set always to zero.
- * @param [in] timer_idx Index of the timer (0,1).
- * @param [in] cycle_set Determines the set of cycles that trigger the interrupt (see Table 23-6 in TMS570 datasheet (SPNU499))
- * @param [in] offset_threshold Offset in the cycle in mactroticks.
- *
- * @return SUCCESS if everything is OK.
- * FAILURE if something failed.
- *
- */
-int8_t rpp_fr_set_timer(uint8_t ctrl, uint8_t timer_idx, uint8_t cycle_set, uint16_t offset_threshold);
-
-/**
- * Stop the absolute timer, clear IRQ.
- *
- * The function can be called any time after communication is running.
- *
- * The FlexRay controller has two absolute timers. Each of them can be
- * configured to request the interrupt, when the global time reaches
- * configured cycle and offset. This function stops the timer and clears
- * the interrupt request.
- *
- * Timer interrupt request can be detected by
- * rpp_fr_get_timer_irq_status(). Timer interrupt request can be
- * cleared by rpp_fr_clear_timer_irq() Timer can be started by
- * rpp_fr_set_timer().
- *
- * @param [in] ctrl Not used, set always to zero.
- * @param [in] timer_idx Index of the timer (0,1).
- *
- * @return SUCCESS if everything is OK.
- * FAILURE if something failed.
- *
- */
-int8_t rpp_fr_cancel_timer(uint8_t ctrl, uint8_t timer_idx);
-
-/**
- * Clear the IRQ flag of the absolute timer
- *
- * The function can be called any time after communication is running.
- *
- * The FlexRay controller has two absolute timers. Each of them can be
- * configured to request the interrupt, when the global time reaches
- * configured cycle and offset. This function clears the IRQ flag.
- *
- * Timer interrupt request can be detected by rpp_fr_get_timer_irq_status().
- * The timer can be started by rpp_fr_set_timer().
- * The timer can be canceled by rpp_fr_cancel_timer().
- *
- * @param [in] ctrl Not used, set always to zero.
- * @param [in] timer_idx Index of the timer (0,1).
- *
- * @return SUCCESS if everything is OK.
- * FAILURE if something failed.
- *
- */
-int8_t rpp_fr_clear_timer_irq(uint8_t ctrl, uint8_t timer_idx);
-
-/**
- * Get IRQ flag of the absolute timer
- *
- * The function can be called any time after communication is running.
- *
- * The FlexRay controller has two absolute timers. Each of them can be
- * configured to request the interrupt, when the global time reaches
- * configured cycle and offset. Using this function the IRQ can be detected.
- *
- * Timer interrupt request can be cleared by rpp_fr_clear_timer_irq().
- * The timer can be started by rpp_fr_set_timer().
- * The timer can be canceled by rpp_fr_cancel_timer().
- *
- * @param [in] ctrl Not used, set always to zero.
- * @param [in] timer_idx Index of the timer (0,1).
- * @param [out] irq_pending Address, where status of the IRQ flag will be stored.
- *
- * @return SUCCESS if everything is OK.
- * FAILURE if something failed.
- *
- */
-int8_t rpp_fr_get_timer_irq_status(uint8_t ctrl, uint8_t timer_idx, boolean_t *irq_pending);
-
-/**
- * Get information about the driver vendor, module and version.
- *
- * The function can be called any time.
- *
- * @param [out] version Address, where the information will be stored.
- *
- * @return always SUCCESS
- *
- */
-int8_t rpp_fr_get_driver_version(Std_VersionInfoType *version);
-
-/**
- * Get configuration parameter value from the internal driver structures.
- *
- * The function can be called any time.
- *
- * @param [in] ctrl Not used, set always to zero.
- * @param [in] param_idx The index if the parameter. You can find the indexes in Fr_GeneralTypes.h file with FR_CIDX prefix.
- * @param [out] param_value Address, where the information will be stored.
- *
- * @return SUCCESS if everything is OK.
- * FAILURE if something failed.
- *
- */
-int8_t rpp_fr_read_com_ctrl_config(uint8_t ctrl, uint8_t param_idx, uint32_t *param_value);
-
-#endif /* __RPP_FR_H */
+++ /dev/null
-/**
- * H-Bridge Output RPP API header file.
- *
- * @file hbr.h
- *
- * @copyright Copyright (C) 2013 Czech Technical University in Prague
- *
- * @author Carlos Jenkins <carlos@jenkins.co.cr>
- */
-
-
-#ifndef __RPP_HBR_H
-#define __RPP_HBR_H
-
-/**
- * HBR module initialization.
- *
- * Call this method before using this module.
- *
- * @return SUCCESS if initialization successful.\n
- * FAILURE if module already initialized.
- */
-int8_t rpp_hbr_init();
-
-
-/**
- * Enable the H-Bridge output and set PWM frequency.
- *
- * Sets duty cycle to zero, direction to LOW and enables the H-Bridge
- * output. Duty cycle and direction can be later controlled with
- * rpp_hbr_control() (see below).
- *
- * @param[in] period Period of the PWM in microseconds (us). If period is
- * less than 1 (the minimum, see note below) the default of
- * 55us (~18kHz, 18181.8181_ Hz to be precise) is used.
- *
- * @return SUCCESS if successful.\n
- * FAILURE if H-Bridge was already enabled or watchdog task could not
- * be created.
- *
- * @note Period considerations from Software perspective (hardware verification
- * required):
- * @par
- * - Minimum value is [1us]:
- * - 50us => 20 kHz
- * - System clock is 80MHz.
- * @par
- * - Maximum value is [2147483647us] (full 32bit signed integer):
- * - 2147483647us = 2147483.647 ms = 2147.483647 s =
- * ~35.791394 min => 0.000465661129 Hz -> 0.0... MHz
- */
-int8_t rpp_hbr_enable(int32_t period);
-
-
-/**
- * Control the H-Bridge direction and PWM duty cycle.
- *
- * @param[in] cmd [-1.0, 1.0] A double between the previous range to
- * command the H-Bridge in the following manner:
- * - cmd > 0 : direction set to HIGH and PWM
- * duty cycle proportional with
- * 1% resolution.
- * - cmd <= 0 : direction set to LOW and PWM
- * duty cycle proportional with
- * 1% resolution.
- *
- * Consider the following:
- *
- * @code
- * rpp_hbr_enable(-1); // Enable H-Bridge at 18kHz.
- * rpp_hbr_control( 1.0); // Set direction to HIGH and 100% PWM duty cycle.
- * (...)
- * rpp_hbr_control( 0.0); // 0% duty cycle, but H-Bridge output active (low-side active free wheeling)
- * (...)
- * rpp_hbr_control(-0.5); // Set direction to LOW and 50% PWM duty cycle.
- * rpp_hbr_disable(); // Disable H-Bridge output.
- * @endcode
- *
- * @return SUCCESS if change was successful.\n
- * -1 if H-Bridge is not enabled. Call rpp_hbr_enable() first.\n
- * -2 if cmd is out of range.
- */
-int8_t rpp_hbr_control(double cmd);
-
-
-/**
- * Disable the H-Bridge output.
- *
- * Completely disable H-Bridge. After this call the H-Bridge cannot be
- * controlled again until another call to rpp_hbr_enable() is made.
- *
- * @return SUCCESS if successful.\n
- * FAILURE if H-Bridge was already disabled.
- */
-int8_t rpp_hbr_disable();
-
-
-#endif /* __RPP_HBR_H */
+++ /dev/null
-/**
- * High-Power Output (12V, 10A, PWM) RPP API header file.
- *
- * @file hout.h
- *
- * @copyright Copyright (C) 2013 Czech Technical University in Prague
- *
- * @author Carlos Jenkins <carlos@jenkins.co.cr>
- */
-
-
-#ifndef __RPP_HOUT_H
-#define __RPP_HOUT_H
-
-/**
- * HOUT module initialization.
- *
- * Call this method before using this module.
- *
- * @return SUCCESS if initialization successful.\n
- * FAILURE if module already initialized.
- */
-int8_t rpp_hout_init();
-
-
-#endif /* __RPP_HOUT_H */
+++ /dev/null
-/**
- * IRC sensor signal input RPP API header file.
- *
- * @file irc.h
- *
- * @copyright Copyright (C) 2013-2014 Czech Technical University in Prague
- *
- * @author Karel Kočí
- */
-
-#ifndef __RPP_IRC_H_
-#define __RPP_IRC_H_
-
-/**
- * IRC sensor 1 connected on DIN10 and DIN11
- */
-#define RPP_IRC_1 1U
-
-/**
- * IRC sensor 2 connected on DIN14 and DIN15
- */
-#define RPP_IRC_2 2U
-
-extern boolean_t rpp_irc1_enabled; /**< Flag for indicating the state of IRC1. */
-extern boolean_t rpp_irc2_enabled; /**< Flag for indicating the state of IRC2. */
-
-/**
- * IRC module initialization.
- *
- * Call this fuction before using this module.
- *
- * @return SUCCESS if initialization successful.\n
- * FAILURE if module already initialized.
- */
-int8_t rpp_irc_init();
-
-/**
- * IRC enable
- *
- * Call this function to enable IRC.
- * Reconfigures PINMUX register and enables N2HET program for specified IRC.
- * After calling this method corresponding pins are not usable as DIN.
- *
- * @param[in] irc IRC sensor connection number.\n
- * RPP_IRC_1 IRC connected to DIN10, DIN11\n
- * RPP_IRC_2 IRC connected to DIN14, DIN15\n
- *
- * @return SUCCESS if IRC start is successful.\n
- * -RPP_EINVAL if irc is out of range.\n
- * FAILURE if modules is not initialized.
- */
-int8_t rpp_irc_enable(uint8_t irc);
-
-/**
- * Check IRC status.
- *
- * @param[in] irc IRC sensor connection number.\n
- * RPP_IRC_1 IRC connected to DIN10, DIN11\n
- * RPP_IRC_2 IRC connected to DIN14, DIN15\n
- *
- * @return 1 if IRC is running.\n
- * 0 if IRC is not running.\n
- * -RPP_EINVAL if irc is out of range.\n
- * FAILURE if module is not initialized
- */
-int8_t rpp_irc_status(uint8_t irc);
-
-/**
- * Get the current value.
- *
- * @param[in] irc IRC sensor connection number.\n
- * RPP_IRC_1 IRC connected to DIN10, DIN11\n
- * RPP_IRC_2 IRC connected to DIN14, DIN15\n
- *
- * @return Curent value or 0 if invalid irc is passed.
- */
-int32_t rpp_irc_get(uint8_t irc);
-
-/**
- * IRC disable
- *
- * Call this function to disable IRC.
- * This function reenables the DIN functionality.
- *
- * @param[in] irc IRC sensor connection number.\n
- * RPP_IRC_1 IRC connected to DIN10, DIN11\n
- * RPP_IRC_2 IRC connected to DIN14, DIN15\n
- *
- * @return SUCCESS if IRC disable is successful.\n
- * -RPP_EINVAL if irc is out of range.\n
- * FAILURE if modules is not initialized.
- */
-int8_t rpp_irc_disable(uint8_t irc);
-
-#endif /* __RPP_IRC_H_ */
+++ /dev/null
-/**
- * LIN Communication RPP API header file.
- *
- * @file lin.h
- *
- * @copyright Copyright (C) 2013 Czech Technical University in Prague
- *
- * @author Carlos Jenkins <carlos@jenkins.co.cr>
- */
-
-
-#ifndef __RPP_LIN_H
-#define __RPP_LIN_H
-
-/**
- * LIN module initialization.
- *
- * Call this method before using this module.
- *
- * @return SUCCESS if initialization successful.\n
- * FAILURE if module already initialized.
- */
-int8_t rpp_lin_init();
-
-
-#endif /* __RPP_LIN_H */
+++ /dev/null
-/**
- * Logic Output RPP API header file.
- *
- * @file lout.h
- *
- * @copyright Copyright (C) 2013 Czech Technical University in Prague
- *
- * @author Carlos Jenkins <carlos@jenkins.co.cr>
- */
-
-
-#ifndef __RPP_LOUT_H
-#define __RPP_LOUT_H
-
-/**
- * LOUT module initialization.
- *
- * Call this method before using this module.
- *
- * @return SUCCESS if initialization successful.\n
- * FAILURE if module already initialized.
- */
-int8_t rpp_lout_init();
-
-
-/**
- * Set the output cache of given pin to given value.
- *
- * Call rpp_lout_update() to flush cached values to real hardware.
- *
- * @param[in] pin The pin number to set [1-8].
- * @param[in] val The value to be set [HIGH|LOW].
- *
- * @return SUCCESS when success.\n
- * -1 if pin number is out of range.
- */
-int8_t rpp_lout_set(uint8_t pin, uint8_t val);
-
-
-/**
- * Get the diagnostic cached value for given pin.
- *
- * Call rpp_lout_update() to update cached values.
- *
- * @param[in] pin The pin number to read [1-8].
- *
- * @return HIGH or LOW if successful.\n
- * -1 if pin number is out of range.
- */
-int8_t rpp_lout_diag(uint8_t pin);
-
-
-/**
- * Flush cached output values and read back diagnostic values of all pins.
- *
- * @return SUCCESS when transaction was successful.\n
- * FAILURE if transaction could not be confirmed.
- */
-int8_t rpp_lout_update();
-
-
-#endif /* __RPP_LOUT_H */
+++ /dev/null
-/**
- * Power Output (12V, 2A, Push/Pull) RPP API header file.
- *
- * @file mout.h
- *
- * @copyright Copyright (C) 2013 Czech Technical University in Prague
- *
- * @author Carlos Jenkins <carlos@jenkins.co.cr>
- */
-
-
-#ifndef __RPP_MOUT_H
-#define __RPP_MOUT_H
-
-/**
- * MOUT module initialization.
- *
- * Call this method before using this module.
- *
- * @return SUCCESS if initialization successful.\n
- * FAILURE if module already initialized.
- */
-int8_t rpp_mout_init();
-
-
-/**
- * Set the output of given pin to given value.
- *
- * This function will also verify if a faulty condition is detected. See return
- * documentation below for details.
- *
- * @param[in] pin The pin number to set [1-6].
- * @param[in] val The value to be set [HIGH|LOW].
- *
- * @return SUCCESS if pin could be set and verified.\n
- * -1 if pin number is out of range.\n
- * -2 if val is not HIGH or LOW.\n
- * -3 if pin could not be set. With current implementation this should
- * never happen.\n
- * -4 if pin is confirmed to be in trouble.
- * This normally indicates a hardware failure and that the driver
- * chip pulled the diagnostic pin.
- */
-int8_t rpp_mout_set(uint8_t pin, uint8_t val);
-
-
-/**
- * Get the cached value of the given pin set by rpp_mout_set().
- *
- * This will not read the value on the pin. To confirm if the output is
- * correctly set call rpp_mout_diag() and confirm SUCCESS.
- *
- * @param[in] pin The pin number to get cached value [1-6].
- *
- * @return HIGH or LOW cached from last rpp_mout_set() call for given pin.
- * -1 if pin number is out of range.
- */
-int8_t rpp_mout_get(uint8_t pin);
-
-
-/**
- * Reads the value on the given diagnostic pin.
- *
- * Note that rpp_mout_set() calls this routine already before returning.
- *
- * @param[in] pin The pin number to read [1-6].
- *
- * @return SUCCESS is output is operating normally.
- * FAILURE if a faulty condition was detected.
- */
-int8_t rpp_mout_diag(uint8_t pin);
-
-
-#endif /* __RPP_MOUT_H */
/* Include modules */
#include "rpp/din.h"
-#include "rpp/lout.h"
#include "rpp/adc.h"
-#include "rpp/dac.h"
-#include "rpp/hbr.h"
-#include "rpp/mout.h"
-#include "rpp/hout.h"
#include "rpp/can.h"
-#include "rpp/lin.h"
#include "rpp/sci.h"
-#ifndef FREERTOS_POSIX
- #include "rpp/eth.h"
- #include "rpp/fr.h"
-#else
+#ifdef FREERTOS_POSIX
#include "rpp/sci_posix.h"
#endif
-#include "rpp/sdc.h"
-#include "rpp/sdr.h"
-#include "rpp/irc.h"
-
/* Library main functions */
/**
+++ /dev/null
-/**
- * SD Card logging RPP API header file.
- *
- * @file sdc.h
- *
- * @copyright Copyright (C) 2013 Czech Technical University in Prague
- *
- * @author Carlos Jenkins <carlos@jenkins.co.cr>
- */
-
-
-#ifndef __RPP_SDC_H
-#define __RPP_SDC_H
-
-/**
- * SDC module initialization.
- *
- * Call this method before using this module.
- *
- * @return SUCCESS if initialization successful.\n
- * FAILURE if module already initialized.
- */
-int8_t rpp_sdc_init();
-
-
-#endif /* __RPP_SDC_H */
+++ /dev/null
-/**
- * SD-RAN logging RPP API header file.
- *
- * @file sdr.h
- *
- * @copyright Copyright (C) 2013 Czech Technical University in Prague
- *
- * @author Carlos Jenkins <carlos@jenkins.co.cr>
- */
-
-
-#ifndef __RPP_SDR_H
-#define __RPP_SDR_H
-
-/**
- * SDRAM start address on RPP board.
- *
- * @note See RPP_SDR_ADDR_END for memory size.
- */
-#define RPP_SDR_ADDR_START 0x80000000U
-
-/**
- * SDRAM end address on RPP board.
- *
- * @note 0x83FFFFFF − 0x80000000 + 1 = 67108864 addresses.\n
- * One address per byte.\n
- * 67108864 bytes = 65536 Kbytes = 64 Mbytes.
- */
-#define RPP_SDR_ADDR_END 0x83FFFFFFU
-
-
-/**
- * SDR module initialization.
- *
- * Call this method before using this module.
- *
- * @return SUCCESS if initialization successful.\n
- * FAILURE if module already initialized.
- */
-int8_t rpp_sdr_init();
-
-
-/**
- * Configure SD-RAM logging.
- *
- * This function will enable or disable logging on application. Note that when
- * logging is enabled a command processor task which uses the SCI for user I/O
- * is spawned. This command processor might conflict with user application if it
- * also uses the SCI for user I/O.
- *
- * @param[in] enable Enable/Disable logging on application.
- *
- * @return SUCCESS if logging was successfully enabled or disabled.\n
- * FAILURE if trying to disable disabled (or enable enabled)
- * logging, SDR module have not being initialized or not
- * enough memory to allocate tasks.
- */
-int8_t rpp_sdr_setup(boolean_t enable);
-
-
-/**
- * Query for the amount of space free on the SD-RAM.
- *
- * This funtion will calculate the amount of free space left (not used by logs)
- * on the SD-RAM.
- *
- * @return Number of bytes free in the SD-RAM.\n
- * For 64MB SD-RAM value is between [0-67108864]
- */
-uint32_t rpp_sdr_available();
-
-
-/**
- * Store a formatted user string on the log, if logging is enabled.
- *
- * Implementation uses vsnprintf() from stdio.h using a fixed MAX_BUFFER_LEN
- * bytes buffer.
- *
- * @param[in] format C string that contains a format string that follows the
- * same specifications as format in printf (see stdio.h's
- * printf for details).
- * @param[in] ... (additional arguments) Depending on the format string,
- * the function may expect a sequence of additional
- * arguments, each containing a value to be used to replace
- * a format specifier in the format string (or a pointer to
- * a storage location).
- * There should be at least as many of these arguments as
- * the number of values specified in the format specifiers.
- * Additional arguments are ignored by the function.
- *
- * @return The number of characters that would have been written if the buffer
- * had been sufficiently large, not counting the terminating null
- * character.
- * If logging is disabled, an encoding error occurs or the log file is
- * full a negative number is returned.
- * Please note that only when this returned value is non-negative and
- * less than the buffer size, the string has been completely written.
- */
-int32_t rpp_sdr_printf(const char *format, ...);
-
-
-/**
- * Clear log.
- *
- * This funtion will clear all the data from the log. This will also stop the
- * show task if it's currently flushing the log.
- *
- * @return SUCCESS if log was cleared.\n
- * FAILURE if logging is disabled or log was already empty.
- */
-int8_t rpp_sdr_clear();
-
-
-/**
- * Start/Stop the task that sends the log to the SCI.
- *
- * This function will start the task that reads the log and prints it to the
- * SCI in a similar way the 'dmesg' command work on Linux.
- *
- * @param[in] start TRUE to request the log to be sent to the SCI.
- * FALSE to stop the log file from being send to the SCI.
- *
- * @return SUCCESS if log was cleared.\n
- * FAILURE if logging is disabled or trying to stop an stopped task
- * (or start an already started task).
- */
-int8_t rpp_sdr_show(boolean_t start);
-
-
-#endif /* __RPP_SDR_H */
+++ /dev/null
-/* Copyright (C) 2013 Czech Technical University in Prague
- *
- * Authors:
- * - Carlos Jenkins <carlos@jenkins.co.cr>
- *
- * This document contains proprietary information belonging to Czech
- * Technical University in Prague. Passing on and copying of this
- * document, and communication of its contents is not permitted
- * without prior written authorization.
- *
- * File : dac.c
- * Abstract:
- * Analog Output RPP API implementation file.
- *
- * References:
- * dac.h
- * RPP API documentation.
- */
-
-
-#include "rpp/rpp.h"
-
-#ifndef FREERTOS_POSIX
-#include "drv/dac.h"
-#endif
-
-static boolean_t initialized = FALSE;
-
-int8_t rpp_dac_init()
-{
- if (initialized)
- return FAILURE;
- initialized = TRUE;
-#ifndef FREERTOS_POSIX
- spi_tms570_init();
-#endif
- // Configure board
- // FIXME find out why board has default output of ~3.8V
- //rpp_dac_setup(1, FALSE);
- //rpp_dac_setup(2, FALSE);
- //rpp_dac_setup(3, FALSE);
- //rpp_dac_setup(4, FALSE);
-
- return SUCCESS;
-}
-
-
-static boolean_t changed_st[4] = {
- FALSE, FALSE, FALSE, FALSE
-};
-static boolean_t enabled_cache[4] = {
- FALSE, FALSE, FALSE, FALSE
-};
-static uint16_t out_cache[4] = {
- 0, 0, 0, 0
-};
-
-int8_t rpp_dac_setup(uint8_t pin, boolean_t enabled)
-{
- // Check range
- if ((pin < 1) || (pin > 4))
- return -1;
-
- uint8_t index = pin - 1;
-
- // Mark state
- enabled_cache[index] = enabled;
-
- // Mark as changed
- changed_st[index] = TRUE;
-
- return SUCCESS;
-}
-
-
-// Value that tops the DAC output
-const static uint16_t dac_top =
- (uint16_t)(4095.0 * (12000.0 / 1000.0) / (RPP_DAC_OA * RPP_DAC_VREF));
-
-// Simple mapping function
-static int32_t map(int32_t x,
- int32_t in_min, int32_t in_max,
- int32_t out_min, int32_t out_max)
-{
- return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
-}
-
-int8_t rpp_dac_set(uint8_t pin, uint16_t val)
-{
- // Check pin range
- if ((pin < 1) || (pin > 4))
- return -1;
-
- // Map value
- val = map(val, 0, 4095, 0, dac_top);
-
- // Check value range
- if (val > 4095)
- return -2;
-
- uint8_t index = pin - 1;
-
- // Set value to output cache
- out_cache[index] = val;
-
- // Mark as changed
- changed_st[index] = TRUE;
-
- return SUCCESS;
-}
-
-
-int8_t rpp_dac_set_voltage(uint8_t pin, uint16_t mv)
-{
- // Check pin range
- if ((pin < 1) || (pin > 4))
- return -1;
-
- // Check millivolts range
- if (mv > 12000)
- return -2;
-
- // Calculate millivolts -> value
- int val = (int)(4095.0 * ((float)mv / 1000.0) / (RPP_DAC_OA*RPP_DAC_VREF));
- if (val > 4095)
- val = 4095;
-
- uint8_t index = pin - 1;
-
- // Set value to output cache
- out_cache[index] = val;
-
- // Mark as changed
- changed_st[index] = TRUE;
-
- return SUCCESS;
-}
-
-
-int8_t rpp_dac_update()
-{
- int i = 0;
-
- for (i = 0; i < 4; i++) {
-
- // If changed commit changes to hardware
- if (changed_st[i]) {
-
-#ifndef FREERTOS_POSIX
- // TODO: Confirm via returned SPI code that transfer was successful
- drv_dac_spi_transfer(i, enabled_cache[i], out_cache[i]);
-#else
- UNUSED(enabled_cache);
- UNUSED(out_cache);
-#endif
-
- changed_st[i] = FALSE;
- }
- }
-
- return SUCCESS;
-}
static uint16_t active_cache = 0x0; /* 0 - tri-state, 1 - active */
static uint16_t can_wake_cache = 0x0;
-static boolean_t check_pin_busy(uint8_t pin)
-{
- if (rpp_irc1_enabled && (pin == 10 || pin == 11))
- return TRUE;
- if (rpp_irc2_enabled && (pin == 14 || pin == 15))
- return TRUE;
- return FALSE;
-}
-
int8_t rpp_din_setup(uint8_t pin, boolean_t pull_up,
boolean_t active, boolean_t can_wake)
{
if (!pull_up && (pin > 7))
return -2;
- // Check blockade of specific pins
- if (check_pin_busy(pin))
- return -RPP_EBUSY;
-
// Set bits
if (pull_up)
bit_set(pull_cache, pin);
if (pin > 15)
return -1;
- // Check blockade of specific pins
- if (check_pin_busy(pin))
- return -RPP_EBUSY;
-
-
if (is_bit_set(in_cache, pin))
return RPP_CLOSED;
return RPP_OPEN;
if (pin < 8 || pin > 15)
return -1;
- // Check blockade of specific pins
- if (check_pin_busy(pin))
- return -RPP_EBUSY;
-
-
#ifndef FREERTOS_POSIX
if (drv_din_get_varthr(pin) == 1)
return HIGH;
if (pin > 15)
return -1;
- // Check blockade of specific pins
- if (check_pin_busy(pin))
- return -RPP_EBUSY;
-
-
if (is_bit_set(diag_cache, pin))
return HIGH;
return LOW;
+++ /dev/null
-/**
- * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
- * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
- * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
- * OF SUCH DAMAGE.
- *
- * This file is part of the lwIP TCP/IP stack.
- *
- * Author: Adam Dunkels <adam@sics.se>
- *
- */
-
-/**
- * Copyright (c) 2010 Texas Instruments Incorporated
- *
- * This file is dervied from the "ethernetif.c" skeleton Ethernet network
- * interface driver for lwIP.
- *
- */
-/* Copyright (C) 2013-2014 Czech Technical University in Prague
- *
- * Authors:
- * - Carlos Jenkins <carlos@jenkins.co.cr>
- * - Rostislav Lisový
- * - Jan Doležal <pm.jenik@gmail.com>
- *
- * This document contains proprietary information belonging to Czech
- * Technical University in Prague. Passing on and copying of this
- * document, and communication of its contents is not permitted
- * without prior written authorization.
- *
- * File : eth.c
- * Abstract:
- * Ethernet Communication RPP API implementation file. Using one PHY.
- *
- * References:
- * eth.h
- * RPP API documentation.
- */
-
-#include "rpp/rpp.h"
-
-#ifndef FREERTOS_POSIX
-
-/* lwIP headers */
-#include "lwip/init.h"
-#include "lwip/timers.h" /* for DHCP binding in NO_SYS mode */
-#include "lwip/sys.h" /* includes - lwip/opt.h, lwip/err.h, arch/sys_arch.h */
-#include "lwip/tcpip.h" /* includes - lwip/opt.h, lwip/api_msg.h, lwip/netifapi.h, lwip/pbuf.h, lwip/api.h, lwip/sys.h, lwip/timers.h, lwip/netif.h */
-#include "lwip/stats.h" /* includes - lwip/mem.h, lwip/memp.h, lwip/opt.h */
-#include "netif/etharp.h" /* includes - lwip/ip.h, lwip/netif.h, lwip/ip_addr.h, lwip/pbuf.h */
-#include "lwip/def.h"
-#include "lwip/snmp.h"
-#include "lwip/dhcp.h"
-#include "lwip/autoip.h"
-#include "netif/ppp_oe.h"
-/* end - lwIP headers */
-
-#include "hal/hal.h"
-#include "sys/sys.h" /* includes - sys/phy_dp83848h.h */
-#include "drv/emac.h"
-#include "os/os.h"
-#include "types.h"
-
-
-/* options */
-
-/* Number of EMAC Instances */
-#define MAX_EMAC_INSTANCE 1
-
-#define DEFAULT_PHY_ADDR 0x1
-#define FIND_FIRST_PHY_ALIVE 1 /* or use default (phy_address: 1) */
-#define NUM_OF_PHYs 32
-#define SIZE_OF_DESC 16 /* in bytes */
-#define CHANNEL 0 /* channel number for everything - for rx, tx, unicast, broadcast or damaged frames ; there are different channels for rx and tx operations */
-
-#define MAX_TRANSFER_UNIT 1500 /* take in account oversized frames */
-#define PBUF_LEN_MAX MAX_TRANSFER_UNIT
-#define MAX_RX_PBUF_ALLOC 10
-#define MIN_PKT_LEN 60
-
-/* Define those to better describe the network interface. */
-#define IFNAME0 'e'
-#define IFNAME1 'n'
-
-
-/**
- * Time to wait for autonegotiation in ticks.
- */
-#define TICKS_PHY_AUTONEG 4000
-
-/**
- * NOT IMPLEMENTED
- * When cable is connected (link status goes up) autonegotiation and/or dhcp is started.
- */
-#define PHY_LINK_MONITOR_INT 0 /* turn on handling interrupt - not implemented now */
-/* end options */
-
-/* Defining interface for all the emac instances */
-static struct hdkif hdkif_data[MAX_EMAC_INSTANCE];
-
-/*
-** The lwIP network interface structure for the HDK Ethernet MAC.
-*/
-static struct netif hdkNetIF[MAX_EMAC_INSTANCE];
-
-/* rpp startup init indicator */
-static boolean_t initialized = FALSE, postInitialized = FALSE;
-
-boolean_t sendDone = TRUE;
-
-/* free pbuf notification */
-#if !NO_SYS
-xSemaphoreHandle pbufFreed;
-#endif
-
-/**********************************************testing functions**********************************************/
-
-boolean_t isPostInitialized()
-{
- return postInitialized;
-}
-
-uint32_t rpp_eth_phylinkstat(uint32_t instNum)
-{
- struct hdkif *hdkif = &hdkif_data[instNum];
-
- return PHY_link_status_get(hdkif->mdio_base, hdkif->phy_addr, 1);
-}
-
-#define BYTE_BUFF_SIZE 2
-#define OFFSET_MAC_LETTERS (MAC_BIG_LETTERS ? 'A' : 'a')
-/* puts string of MAC address assigned to EMAC instance reffered by instNum into *mac */
-void rpp_eth_get_macAddrStr(uint32_t instNum, uint8_t *macStr)
-{
- uint8_t index, outindex = 0;
- char buff[BYTE_BUFF_SIZE];
- struct hdkif *hdkif = &hdkif_data[instNum];
-
- for (index = 0; index < MAC_ADDR_LEN; index++) {
- if (index) macStr[outindex++] = ':';
- buff[0] = (hdkif->mac_addr[(MAC_ADDR_LEN - 1) - index] >> 4);
- buff[1] = (hdkif->mac_addr[(MAC_ADDR_LEN - 1) - index] & 0xf);
- macStr[outindex++] = (buff[0] < 10) ? (buff[0] + '0') : (buff[0] - '\012' + OFFSET_MAC_LETTERS);
- macStr[outindex++] = (buff[1] < 10) ? (buff[1] + '0') : (buff[1] - '\012' + OFFSET_MAC_LETTERS);
- }
- macStr[outindex] = '\0';
-}
-
-/* @param ip will be filled accroding to content of ipstr */
-err_t rpp_eth_stringToIP(ip_addr_t *ip, uint8_t *ipstr)
-{
- uint8_t charProccessed, index = 0, dotindex = 0xff, tmp = 0, dots = 0, fldEdit = 0;
- uint32_t ipaddr = 0;
-
- for (charProccessed = ipstr[index]; (charProccessed >= '0' && charProccessed <= '9') || charProccessed == '.'; charProccessed = ipstr[++index]) {
- if (charProccessed == '.') {
- if (++dotindex == index) {
- dots = 0;
- break;
- }
- dotindex = index;
-
- ipaddr = (ipaddr << 8) + tmp;
-
- dots++;
- if (dots > 3) break;
-
- tmp = 0;
- fldEdit = FALSE;
- }
- else
- {
- fldEdit = TRUE;
- tmp = tmp*10 + charProccessed - '0';
- }
- }
- if (dots != 3 || !fldEdit)
- /* if unsuccesful, don't modify previous content */
- return FAILURE;
- ipaddr = (ipaddr << 8) + tmp;
- ip->addr = ipaddr;
- return SUCCESS;
-}
-
-/* returns number in range 0-65535 where 0 is error */
-uint16_t rpp_eth_portStrToInt(uint8_t *string)
-{
- uint8_t index;
- uint16_t portNO = 0;
-
- for (index = 0; string[index] != '\0'; index++) {
- if (string[index] < '0' || string[index] > '9') {
- portNO = 0;
- break;
- }
- portNO = portNO * 10 + string[index] - '0';
- }
- return portNO;
-}
-
-struct netif *rpp_eth_get_netif(uint32_t instNum)
-{
- return &hdkNetIF[instNum];
-}
-
-/********************************************** forward declares **********************************************/
-
-/*
- * interface initializes
- */
-err_t rpp_eth_lwip_init(struct netif *netif);
-
-/*
- * Initializes hw such as PHY, MDIO, EMAC, EMAC control module
- *
- * @return SUCCESS if initialization successful.\n
- * FAILURE if initialization not successful.
- */
-err_t rpp_eth_hw_init(struct hdkif *hdkif);
-
-/*
- * Initializes hw, after lwIP was initialized and
- * OS was initialized in case OS is used.
- */
-err_t rpp_eth_hw_init_postInit(struct netif *netif);
-
-/********************************************** utility functions **********************************************/
-
-/*
- * Function to set the MAC address to the interface
- * @param inst_num the instance number
- *
- * @note mac_addr[0] is considered MSB
- */
-void hdkif_macaddrset(u32_t inst_num, u8_t *mac_addr)
-{
- struct hdkif *hdkif;
- u32_t temp;
-
- hdkif = &hdkif_data[inst_num];
-
- /* set MAC hardware address */
- for (temp = 0; temp < MAC_ADDR_LEN; temp++) {
- hdkif->mac_addr[temp] = mac_addr[(MAC_ADDR_LEN - 1) - temp];
- }
-#ifdef DEBUG
- uint8_t macStr[18];
- rpp_eth_get_macAddrStr(inst_num, macStr);
- rpp_debug_printf("Setting MAC... %s\r\n", macStr);
-#endif
-}
-
-/**
- * Function to setup the instance parameters inside the interface
- * @param hdkif
- * @return none.
- */
-static void hdkif_inst_config(struct hdkif *hdkif)
-{
- if (hdkif->inst_num == 0) {
- hdkif->emac_base = EMAC_BASE_m(0);
- hdkif->emac_ctrl_base = EMAC_CTRL_BASE_m(0);
- hdkif->emac_ctrl_ram = EMAC_CTRL_RAM_BASE_m(0);
- hdkif->mdio_base = MDIO_BASE_m(0);
- hdkif->phy_addr = DEFAULT_PHY_ADDR; /* Default address of PHY on "MDIO bus" (depends on PHY hw configuration) */
- hdkif->phy_autoneg = PHY_auto_negotiate;
- hdkif->phy_autoneg_start = PHY_start_auto_negotiate;
- hdkif->phy_autoneg_is_done = PHY_is_done_auto_negotiate;
- hdkif->phy_partnerability = PHY_partner_ability_get;
- }
-}
-
-/********************************************** initializing functions **********************************************/
-
-int8_t rpp_eth_init()
-{
- uint8_t instNum;
- int8_t retVal = SUCCESS;
-
- if (initialized)
- return FAILURE;
-
- /* config of EMAC instances and other stuff */
- for (instNum = 0; instNum < MAX_EMAC_INSTANCE; instNum++) {
- hdkif_data[instNum].inst_num = instNum;
- hdkif_inst_config(&hdkif_data[instNum]); /* hdkif_inst_config must contain instNum specific settings */
- if (retVal = rpp_eth_hw_init(&hdkif_data[instNum])) {
-#ifdef DEBUG
- rpp_sci_printk("rpp_eth_hw_init: %d", retVal);
-#endif
- retVal = FAILURE;
- }
- }
-
- /* when one of instances was not initialized correctly return FAILURE without setting initialized variable to TRUE */
- if (retVal) return FAILURE;
-
-#if NO_SYS
-
-#else /* NO_SYS */
-
-#endif /* NO_SYS */
-
- initialized = TRUE;
-
- return retVal;
-}
-
-int8_t rpp_eth_init_postInit(uint32_t instNum, uint8_t *macArray)
-{
- if (postInitialized)
- return FAILURE;
- int8_t retVal = SUCCESS;
- struct netif *netif = &hdkNetIF[instNum];
- u8_t mac_addr[MAC_ADDR_LEN] = RPP_MAC_ADDR;
-
- /* ----- lwIP stuff ----- */
- struct ip_addr ip_addr;
- struct ip_addr net_mask;
- struct ip_addr gw_addr;
- volatile unsigned int dhcpBindWait = 0x3FFFFFFF;
-
- if (macArray == NULL)
- macArray = mac_addr; /* use default MAC */
- hdkif_macaddrset(instNum, macArray);
-
- struct hdkif *hdkif;
-#if NO_SYS
- lwip_init();
-#else /* NO_SYS */
- /* this can be called only within post OS init */
- tcpip_init(NULL,NULL); /* calls lwip_init() implicitly, starts lwIP task (thread), when started function given to tcpip_init is executed first */
-#endif /* NO_SYS */
-
-#if STATIC_IP_ADDRESS
- ip_addr.addr = htonl(RPP_IP_ADDR);
- net_mask.addr = htonl(RPP_NETMASK);
- gw_addr.addr = htonl(RPP_GW);
-#else /* STATIC_IP_ADDRESS */
- ip_addr.addr = 0;
- net_mask.addr = 0;
- gw_addr.addr = 0;
-#endif /* STATIC_IP_ADDRESS */
-
- /* init and add new netif */
- /* add new network interface to lwIP list of ifaces and initialize netif with specific function */
-#if NO_SYS
- if ( netif_add(netif, &ip_addr, &net_mask, &gw_addr, (void *)instNum, rpp_eth_lwip_init, ethernet_input) == NULL )
-#else /* NO_SYS */
- if ( netif_add(netif, &ip_addr, &net_mask, &gw_addr, (void *)instNum, rpp_eth_lwip_init, tcpip_input) == NULL )
-#endif /* NO_SYS */
-
- return NETIF_ADD_ERR;
-
- netif_set_default(netif);
-
- hdkif = (struct hdkif *)netif->state;
-#if !NO_SYS
- /* ----- freeRTOS elements ----- */
- /* semaphore blocking receive task (rpp_eth_recv_raw) from receive operation, till RX interrupt occurs and notify it */
- vSemaphoreCreateBinary(hdkif->goRX);
- vSemaphoreCreateBinary(hdkif->goTX);
- /* create semaphore notificating that pbuf was freed */
- vSemaphoreCreateBinary(pbufFreed);
- /* run task rpp_eth_recv_raw */
- xTaskCreate( rpp_eth_recv_raw, "RXHandler", 200, netif, 0, NULL );
- /* ----- end - freeRTOS ----- */
-#endif /* !NO_SYS */
-
- /* if we don't use link int change, then it must be done here */
-#if !PHY_LINK_MONITOR_INT
- if (rpp_eth_phylinkstat(hdkif->inst_num)) {
- rpp_debug_printf((const char *)"cable connected ... setting IP params\r\n");
-#if STATIC_IP_ADDRESS
- netif_set_up(netif);
-#elif LWIP_DHCP /* STATIC_IP_ADDRESS-LWIP_DHCP */
- if (dhcp_start(netif) != ERR_OK) {
- rpp_debug_printf("dhcp mem err\r\n");
- return DHCP_MEM_ERR;
- }
- rpp_debug_printf("binding DHCP\r");
- while ((netif->dhcp->state != DHCP_BOUND) && (dhcpBindWait--)) /*sys_check_timeouts()*/;
- if (!dhcpBindWait)
- rpp_debug_printf("dhcp binding timeout...\r\n");
-#else /* LWIP_DHCP-LWIP_AUTOIP FIXME: there should be some kind of waiting till ip is assigned */
- autoip_start(netif);
-#endif /* STATIC_IP_ADDRESS-LWIP_DHCP-LWIP_AUTOIP */
-#ifdef DEBUG
- uint8_t ipString[16];
- rpp_eth_getIPDecimalStr(netif->ip_addr, ipString);
- rpp_debug_printf("Address: %s\r\n", ipString);
- rpp_eth_getIPDecimalStr(netif->netmask, ipString);
- rpp_debug_printf("Netmask: %s\r\n", ipString);
- rpp_eth_getIPDecimalStr(netif->gw, ipString);
- rpp_debug_printf("Gateway: %s\r\n", ipString);
-#endif
- }
- else
- {
- rpp_debug_printf((const char *)"cable not connected\r\n");
- retVal = PHY_LINK_DOWN;
- }
-
-#else /* !PHY_LINK_MONITOR_INT */
- /* now when we established environment needed for phy link status change we can allow it */
- /* set PHY number which is monitored for link changes in MDIO and enable interrupt */
- HWREG(hdkif->mdio_base + MDIO_USERPHYSEL0) = ((hdkif->phy_addr && 0x1f) | MDIO_USERPHYSEL0_LINKINTENB);
-
- /* enable MISC interrupt - link monitoring in EMAC controle module */
- HWREG(hdkif->emac_ctrl_base + EMAC_CTRL_CnMISCEN(0)) |= EMAC_CTRL_MISC_LINKINT0ENB;
-
-#endif /* !PHY_LINK_MONITOR_INT */
- /* ----- end - lwIP stuff ----- */
-
- postInitialized = TRUE;
- return retVal;
-}
-
-err_t rpp_eth_lwip_init(struct netif *netif)
-{
-#if LWIP_NETIF_HOSTNAME
- /* Initialize interface hostname */
- netif->hostname = "rpp";
-#endif /* LWIP_NETIF_HOSTNAME */
-
- uint32_t instNum = (uint32_t)netif->state;
- /*netif->num = instNum; - auto-initiated when netif_add is called */
-
- /* netif->state contained instNum, we replace it with corresponding hdkif */
- struct hdkif *hdkif = &hdkif_data[instNum];
- netif->state = hdkif;
-
- netif->name[0] = IFNAME0;
- netif->name[1] = IFNAME1;
-
-#if !NO_SYS
- hdkif->waitTicksForPHYAneg = TICKS_PHY_AUTONEG;
-#endif
-
- /*
- * Initialize the snmp variables and counters inside the struct netif.
- * The last argument should be replaced with your link speed, in units
- * of bits per second.
- */
- NETIF_INIT_SNMP(netif, snmp_ifType_ethernet_csmacd, 10000000);
-
- /* We directly use etharp_output() here to save a function call.
- * You can instead declare yo_SKIP_TO_HWur own function an call etharp_output()
- * from it if you have to do some checks before sending (e.g. if link
- * is available...)
- */
- netif->output = etharp_output;
- netif->linkoutput = rpp_eth_send;
- return rpp_eth_hw_init_postInit(netif);
-}
-
-#define INIT_ONLY_AFTER_RESET 1
-err_t rpp_eth_hw_init(struct hdkif *hdkif)
-{
- uint8_t index;
- uint16_t regContent;
- uint32_t physAlive;
-
- /* Deactivate reset pin of PHY */
- /* for hw reset of PHY, it is necessary that PIN_NAME_ETHRST is 1us logical low state, before putting it to logical high */
-#if !INIT_ONLY_AFTER_RESET
-#if NO_SYS
- uint8_t index = 80; /* Initially used to hw reset of PHY connected to GIO pin. This means 1us - for 80MHz clock. */
-#else /* NO_SYS */
- uint8_t index = configCPU_CLOCK_HZ/1000000; /* Initially used to hw reset of PHY connected to GIO pin 'rpp project only'; 1us - according to PHY specification. */
-#endif /* NO_SYS */
- hal_gpio_pin_set_value(*hal_gpio_pin_get_dsc(PIN_NAME_ETHRST,-1),0);
- while (index--) ;
-#endif /* !INIT_ONLY_AFTER_RESET */
- /* we have pull-down resistor, so after reset, we only need to put ETHRST pin to log. high */
- hal_gpio_pin_set_value(*hal_gpio_pin_get_dsc(PIN_NAME_ETHRST,-1),1);
-
- /* initializes EMAC control module and EMAC module */
- EMACInit(hdkif->emac_ctrl_base, hdkif->emac_base);
- /* initializes MDIO module (reset) */
- MDIOInit(hdkif->mdio_base, 0x0, 0x0);
-
- /* enable used receive channel if necessary */
-
-
- /* try to read random register from defaultPhy to make MDIO fill alive bit for this one if it returned
- ACK bit in msg response - this must be done, because MDIO has not set alive bit of PHY after that
- short time after MDIOInit() */
- MDIOPhyRegRead(hdkif->mdio_base, hdkif->phy_addr, PHY_BMSR, ®Content);
-
- /* find first alive PHY - or use default if alive */
- physAlive = MDIOPhyAliveStatusGet(hdkif->mdio_base);
- if (!(physAlive & (1 << hdkif->phy_addr))) {
-#if FIND_FIRST_PHY_ALIVE
- for (index = 0; index < NUM_OF_PHYs; index++) { /* i..PHY tested */
- if (physAlive && (1 << index)) {
- hdkif->phy_addr = index;
- break;
- }
- else
- {
- MDIOPhyRegRead(hdkif->mdio_base, index, PHY_BMCR, ®Content); /* try to 'wake up' PHY on 'index' address by reading random register, making MDIO set alive bit for current PHY */
- physAlive = MDIOPhyAliveStatusGet(hdkif->mdio_base); /* get updated register */
- if (physAlive && (1 << index)) {
- hdkif->phy_addr = index;
- break;
- }
- }
- }
- if (!physAlive) {
- rpp_debug_printf("no phy found, phys: %d\r\n", physAlive);
- return NO_PHY_ALIVE;
- }
-#else
- rpp_debug_printf("default phy not alive\r\n");
- return DFLT_PHY_NOT_ALIVE;
-#endif
- }
-
- /* start autonegotiation and check on completion later or when complete link register will be updated */
- hdkif->phy_autoneg_start(hdkif->mdio_base, hdkif->phy_addr, PHY_100BASETXDUPL_m | PHY_100BASETX_m | PHY_10BASETDUPL_m | PHY_10BASET_m);
-
- /* TODO: you can implement init of receive flow control somewhere here if desired - set RXBUFFERFLOWEN in MACCONTROL */
-
-
- /* acknowledge EMAC control module RX, TX and MISC interrupts */
- EMACCoreIntAck(hdkif->emac_base, EMAC_INT_CORE0_RX);
- EMACCoreIntAck(hdkif->emac_base, EMAC_INT_CORE0_TX);
- EMACCoreIntAck(hdkif->emac_base, EMAC_INT_CORE0_MISC);
-
- /* sets which channel will receive broadcasts */
- EMACRxBroadCastEnable(hdkif->emac_base, CHANNEL);
- /* sets channel where all frames will be copied to - either with MAC address different from local device address, either packets with error will be copied; appropriate error will be set in the frame EOP buffer descriptor */
- EMACRxPromiscEnable(hdkif->emac_base, CHANNEL);
- /* enables unicast */
- EMACRxUnicastSet(hdkif->emac_base, CHANNEL);
-
- /* enable TX and RX interrupts in both EMAC module and EMAC control module */
- EMACTxIntPulseEnable(hdkif->emac_base, hdkif->emac_ctrl_base, 0, CHANNEL);
- EMACRxIntPulseEnable(hdkif->emac_base, hdkif->emac_ctrl_base, 0, CHANNEL);
-
- /* switch of send bd handling and when sending, just wait till send was done and then return (making the driver simple) */
- //vim_mask_clr(TXinterruptVectorNumber);
-
- return SUCCESS;
-}
-
-err_t rpp_eth_hw_init_postInit(struct netif *netif)
-{
- volatile unsigned int autonegFinishWait = 0x3FFFFFFF; /* 0x3FFFFFFF is for 80MHz aproximately 13s */
- uint16_t regContent;
- uint32_t num_bd, pbuf_cnt = 0;
- volatile struct emac_tx_bd *curr_txbd, *last_txbd;
- volatile struct emac_rx_bd *curr_rxbd, *last_rxbd;
- struct pbuf *p, *q;
- struct rxch *rxch;
- struct txch *txch;
-
- struct hdkif *hdkif = (struct hdkif *)netif->state;
-
- rxch = &(hdkif->rxch);
- txch = &(hdkif->txch);
-
- rpp_debug_printf("autoneg started - check on cable if it's connected!\r\n");
-
-
- /*
- * Initialize the Descriptor Memory For TX and RX
- * Only Channel 0 is supported for both TX and RX
- */
- txch->free_head = ((volatile struct emac_tx_bd *)hdkif->emac_ctrl_ram);
- txch->next_bd_to_process = txch->free_head;
- txch->active_tail = NULL;
-
- /* Set the number of descriptors for the channel */
- num_bd = (SIZE_EMAC_CTRL_RAM >> 1) / sizeof(struct emac_tx_bd); /* take half of CPPI ram for TX BDs */
-
- curr_txbd = txch->free_head;
-
- /* Initialize all the TX buffer Descriptors */
- while (num_bd--) {
- curr_txbd->next = curr_txbd + 1;
- curr_txbd->flags_pktlen = 0;
- last_txbd = curr_txbd;
- curr_txbd = curr_txbd->next;
- }
- last_txbd->next = txch->free_head;
-
- /* Initialize the descriptors for the RX channel */
- rxch->active_head = (volatile struct emac_rx_bd *)(curr_txbd);
- rxch->free_head = NULL;
- rxch->freed_pbuf_len = 0;
- num_bd = ((SIZE_EMAC_CTRL_RAM >> 1) / sizeof(struct emac_rx_bd)); /* when using 20B emac_bd structs, u can allocate one more ;) ( 8192/20 = 409 together rx and tx and there is still 12 bytes remaining) */
- curr_rxbd = rxch->active_head;
- last_rxbd = curr_rxbd;
-
- /*
- ** Allocate the pbufs for the maximum count permitted or till the
- ** number of buffer desceriptors expire, which ever is earlier.
- */
- while (pbuf_cnt < MAX_RX_PBUF_ALLOC) {
- p = pbuf_alloc(PBUF_RAW, PBUF_LEN_MAX, PBUF_POOL);
-
- if (p != NULL) {
- /* write the descriptors if there are enough numbers to hold the pbuf*/
- if (((uint32_t)pbuf_clen(p)) <= num_bd)
- for (q = p; q != NULL; q = q->next) {
- curr_rxbd->bufptr = (uint8_t *)(q->payload);
- curr_rxbd->bufoff_len = q->len;
- curr_rxbd->next = curr_rxbd + 1;
- curr_rxbd->flags_pktlen = EMAC_DSC_FLAG_OWNER;
-
- /* Save the pbuf */
- curr_rxbd->pbuf = q;
- last_rxbd = curr_rxbd;
- curr_rxbd = curr_rxbd->next;
- num_bd--;
- }
-
- /* free the allocated pbuf if no free descriptors are left */
- else {
- pbuf_free(p);
- break;
- }
- }
- else
- break;
- pbuf_cnt++;
- }
-
- if (!pbuf_cnt) rpp_debug_printf("no pbufs attached to rx buffer descriptors during init\n");
-
- last_rxbd->next = NULL;
- rxch->active_tail = last_rxbd;
-
- num_bd = ( ((uint32_t)rxch->active_tail - (uint32_t)rxch->active_head) / sizeof(struct emac_rx_bd) + 1 );
- rpp_debug_printf("%d pbuf chains allocated for %d rx buffer descriptors\n", pbuf_cnt, num_bd);
- /* for flow control or QoS - there could be set an interrupt when we reach preset amount of receive descriptors remaining - see RXBUFFERFLOWEN */
- /* EMACNumFreeBufSet(hdkif->emac_base, CHANNEL, num_bd); */ /* not used */
-
- /* set header descriptor pointers - this shows EMAC which descriptor is beginning one for writing received frames/packets */
- EMACRxHdrDescPtrWrite(hdkif->emac_base, (uint32_t)rxch->active_head, CHANNEL);
-
- /* lwIP stuff */
-
- /* set length of MAC address */
- netif->hwaddr_len = MAC_ADDR_LEN;
-
- /* set MAC address */
- for (regContent = 0; regContent < MAC_ADDR_LEN; regContent++) {
- netif->hwaddr[regContent] = hdkif->mac_addr[(MAC_ADDR_LEN - 1) - regContent];
- }
-
- /* maximum transfer unit */
- netif->mtu = MAX_TRANSFER_UNIT;
-
- /* device capabilities */
- /* don't set NETIF_FLAG_ETHARP if this device is not an ethernet one */
- netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_LINK_UP;
-
- /* lwIP stuff - end */
-
- /* for flow control frames */
- EMACMACSrcAddrSet(hdkif->emac_base, hdkif->mac_addr);
-
- /* Be sure to program all eight MAC address registers -
- * whether the receive channel is to be enabled or not.
- */
- for (regContent = 0; regContent < 8; regContent++) /* i..channel_number */
- EMACMACAddrSet(hdkif->emac_base, regContent, hdkif->mac_addr, EMAC_MACADDR_NO_MATCH_NO_FILTER);
-
-#if !PHY_LINK_MONITOR_INT /* in case we don't use interrupt when phy link status changes, we need to try to finish autoneg in here */
- /* wait for autonegotiation to be done or continue, when delay was reached */
-#if !NO_SYS
- uint32_t timeToWake = hdkif->waitTicksForPHYAneg + sys_jiffies();
- while (hdkif->phy_autoneg_is_done(hdkif->mdio_base, hdkif->phy_addr) == FALSE && timeToWake > sys_jiffies()) vTaskDelay(20); /* XXX: if init is not done at the startup, but couple days later, this might cause troubles */
-#else
- while (hdkif->phy_autoneg_is_done(hdkif->mdio_base, hdkif->phy_addr) == FALSE && autonegFinishWait--) ; /* wait till aneg done */
-#endif
-
- if (hdkif->phy_autoneg_is_done(hdkif->mdio_base, hdkif->phy_addr) != FALSE)
- rpp_debug_printf("aneg finished \r\n");
- else
- rpp_debug_printf("aneg timeout \r\n");
-
- /* provide informations retrieved from autoneg to EMAC module */
- hdkif->phy_partnerability(hdkif->mdio_base, hdkif->phy_addr, ®Content);
- if (regContent & (PHY_100BASETXDUPL_m | PHY_10BASETDUPL_m))
- EMACDuplexSet(hdkif->emac_base, EMAC_DUPLEX_FULL);
- /* this is right place to implement transmit flow control if desired - set TXFLOWEN in MACCONTROL */
- else if (regContent & (PHY_100BASETX_m | PHY_10BASET_m))
- EMACDuplexSet(hdkif->emac_base, EMAC_DUPLEX_HALF);
- else {
- rpp_debug_printf("Unknown duplex mode\r\n");
- return UNKN_DUPLEX_MODE;
- }
-#endif /* !PHY_LINK_MONITOR_INT */
-
- /* enable hostpend interrupts in emac module */
- HWREG(hdkif->emac_base + EMAC_MACINTMASKSET) |= EMAC_MACINTMASKSET_HOSTMASK;
-
- /* enable hostpend interrupts in emac control module */
- HWREG(hdkif->emac_ctrl_base + EMAC_CTRL_CnMISCEN(0)) |= EMAC_CTRL_MISC_HOSTPENDENB;
-
- /* enable EMAC's Media Independent Interface TX and RX */
- EMACMIIEnable(hdkif->emac_base);
- /* enable EMAC transmit */
- EMACTxEnable(hdkif->emac_base);
- /* enable EMAC receive */
- EMACRxEnable(hdkif->emac_base);
-
- return SUCCESS;
-}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-/********************************************** send and receive functions / ISRs **********************************************/
-
-err_t rpp_eth_send(struct netif *netif, struct pbuf *p)
-{
- err_t retVal = SUCCESS;
-
- SYS_ARCH_DECL_PROTECT(lev);
-
- /**
- * This entire function must run within a "critical section" to preserve
- * the integrity of the transmit pbuf queue.
- *
- */
- SYS_ARCH_PROTECT(lev);
-
- /* protect from access receive acces from interrupt */
-#if !SYS_LIGHTWEIGHT_PROT
- uint32_t prevProt = (uint32_t)_get_CPSR() & 0x80;
- _disable_IRQ();
-#endif
-
-
- /* adjust the packet length if less than minimum required */
- if (p->tot_len < MIN_PKT_LEN) {
- p->tot_len = MIN_PKT_LEN;
- p->len = MIN_PKT_LEN;
- }
-
- /* call the actual transmit function */
- retVal = rpp_eth_send_raw(netif, p);
-
- /* Return to prior interrupt state and return. */
- SYS_ARCH_UNPROTECT(lev);
-
-#if !SYS_LIGHTWEIGHT_PROT
- if (!prevProt) _enable_IRQ();
-#endif
-
- return retVal;
-}
-
-/**
- * send packet, blocks till it is sent
- * every send uses bds on the beginning of CPPI RAM
- */
-err_t rpp_eth_send_raw(struct netif *netif, struct pbuf *p)
-{
- struct pbuf *q;
- volatile struct emac_tx_bd *curr_bd, *bd_end;
- struct hdkif *hdkif;
-
- hdkif = (struct hdkif *)netif->state;
- curr_bd = (struct emac_tx_bd *)hdkif->emac_ctrl_ram;
-
- /* destroy all flags previously set and update the total packet length */
- curr_bd->flags_pktlen = p->tot_len;
-
- /* Indicate the start of the packet */
- curr_bd->flags_pktlen |= (EMAC_DSC_FLAG_SOP | EMAC_DSC_FLAG_OWNER);
-
- /* Copy pbuf information into TX buffer descriptors */
- for (q = p; q != NULL; q = q->next) {
-
- /* Intialize the buffer pointer and length */
- curr_bd->bufptr = (uint8_t *)(q->payload);
- curr_bd->bufoff_len = (q->len) & 0xFFFF;
- bd_end = curr_bd;
- curr_bd->pbuf = p;
- curr_bd = curr_bd->next;
- curr_bd->flags_pktlen = 0x0; /* destroy all previously set flags */
- }
-
- /* Indicate the end of the packet */
- bd_end->next = NULL;
- bd_end->flags_pktlen |= EMAC_DSC_FLAG_EOP;
-
- /* don't write to hdp till it turns zero */
- while (0 != *((volatile uint32_t *)(hdkif->emac_base + EMAC_TXHDP(CHANNEL)) )) ;
- /* notify hw where to start transmission from */
- HWREG(hdkif->emac_base + EMAC_TXHDP(CHANNEL)) = hdkif->emac_ctrl_ram;
- //EMACTxHdrDescPtrWrite(hdkif->emac_base, hdkif->emac_ctrl_ram, CHANNEL);
-
- /* wait till queued pkt is sent */
- vim_mask_set(TXinterruptVectorNumber);
- xSemaphoreTake(hdkif->goTX, portMAX_DELAY);
- while (!(bd_end->flags_pktlen & EMAC_DSC_FLAG_EOQ) || (((struct emac_tx_bd *)(hdkif->emac_ctrl_ram))->flags_pktlen & EMAC_DSC_FLAG_OWNER)) rpp_sci_printk("!");
-
- EMACTxCPWrite(hdkif->emac_base, CHANNEL, (uint32_t)bd_end);
-
- EMACCoreIntAck(hdkif->emac_base, EMAC_INT_CORE0_TX);
-
- /* restore bds chain */
- bd_end->next = curr_bd;
-
- LINK_STATS_INC(link.xmit);
- return SUCCESS;
-}
-
-void rpp_eth_recv_raw(void *arg)
-{
- volatile struct emac_rx_bd *curr_bd, *processed_bd, *curr_tail, *last_bd;
- volatile struct pbuf *pbuf, *q, *new_pbuf;
- uint32_t ex_len, len_to_alloc;
- uint16_t tot_len;
- struct netif *netif = (struct netif *)arg;
- struct hdkif *hdkif = (struct hdkif *)netif->state;
- struct rxch *rxch;
-
- rxch = &(hdkif->rxch);
-
-
-#if !NO_SYS && !ONE_DRIVER_TASK
- SYS_ARCH_DECL_PROTECT(lev);
- for (;; ) {
- vim_mask_set(RXinterruptVectorNumber);
- sys_arch_sem_wait(&(hdkif->goRX), 0);
- SYS_ARCH_PROTECT(lev);
-#endif
-
-
- /* Get the bd which contains the earliest filled data */
- curr_bd = rxch->active_head;
- last_bd = rxch->active_tail;
-
- if (curr_bd->flags_pktlen & EMAC_DSC_FLAG_SOP != EMAC_DSC_FLAG_SOP) rpp_debug_printf("ERR: Active head is not SOP!\n");
-
- /**
- * Process the descriptors as long as data is available
- * when the DMA is receiving data, SOP flag will be set
- */
- while (curr_bd->flags_pktlen & EMAC_DSC_FLAG_SOP) {
- ex_len = 0;
- len_to_alloc = 0;
- /* Start processing once the packet is loaded */
- if ((curr_bd->flags_pktlen & EMAC_DSC_FLAG_OWNER) != EMAC_DSC_FLAG_OWNER) {
- if (rxch->free_head == NULL)
- /* this bd chain will be freed after processing */
- rxch->free_head = curr_bd;
-
- /* Get the total length of the packet. curr_bd points to the start
- * of the packet.
- */
- tot_len = (curr_bd->flags_pktlen) & 0xFFFF;
-
- /* Get the start of the pbuf queue */
- q = curr_bd->pbuf;
-
- do {
- /* Get the pbuf pointer which is associated with the current bd */
- pbuf = curr_bd->pbuf;
-
- /* If the earlier pbuf ended, update the chain */
- if (pbuf->next == NULL)
- pbuf->next = (struct pbuf *)(curr_bd->next)->pbuf;
-
- len_to_alloc += pbuf->len;
- /* Update the len and tot_len fields for the pbuf in the chain*/
- pbuf->len = (curr_bd->bufoff_len) & 0xFFFF;
- pbuf->tot_len = tot_len - ex_len;
- processed_bd = curr_bd;
- ex_len += pbuf->len;
- curr_bd = curr_bd->next;
-#ifdef DEBUG
- if (curr_bd == NULL) rpp_debug_printf("rx curr_bd set to zero!\n");
-#endif
- /* FIXME: curr_bd here could be NULL - (currently solved by having always allocated enough pbufs -> waiting for pbuf_free() function) a solution could be: we need to keep at least TCP_MSS bytes, so allocate at least that if not possible block */
- } while ((processed_bd->flags_pktlen & EMAC_DSC_FLAG_EOP) != EMAC_DSC_FLAG_EOP);
-
- /**
- * Close the chain for this pbuf. A full packet is received in
- * this pbuf chain. Now this pbuf can be given to upper layers for
- * processing. The start of the pbuf chain is now 'q'.
- */
- pbuf->next = NULL;
-
- /* Adjust the link statistics */
- LINK_STATS_INC(link.recv);
-
- /* Process the packet - this function is specified while adding netif using netif_add() function */
- if (netif->input((struct pbuf *)q, netif) != ERR_OK) {
- /* Adjust the link statistics */
- LINK_STATS_INC(link.memerr);
- LINK_STATS_INC(link.drop);
- }
-
- /* Acknowledge that this packet is processed */
- EMACRxCPWrite(hdkif->emac_base, CHANNEL, (unsigned int)processed_bd);
-
- if (curr_bd != NULL)
- rxch->active_head = curr_bd;
- else
- rxch->active_head = processed_bd + 1; //todo:reconsider
-
- /**
- * The earlier pbuf chain is freed from the upper layer. So, we need to
- * allocate a new pbuf chain and update the descriptors with the pbuf info.
- * To support chaining, the total length freed by the upper layer is tracked.
- * Care should be taken even if the allocation fails.
- */
- /**
- * now len_to_alloc will contain the length of the pbuf which was freed
- * from the upper layer
- */
- rxch->freed_pbuf_len += len_to_alloc;
-#if !NO_SYS
- /* if there is not enough pbufs predefined, we need application to process them and return them back to pool -> YIELD */
- /* XXX: this is not fixed in NO_SYS version - problem is when curr_bd is set to NULL (see above), and we don't obtain new_pbuf
- * from pool, then in *bd pointing to NULL might be such values (EMAC_DSC_FLAG_SOP == 1 &| EMAC_DSC_FLAG_OWNER == 0), that we
- * stay cycling around */
- do {
-#endif
- new_pbuf = pbuf_alloc(PBUF_RAW, (rxch->freed_pbuf_len), PBUF_POOL);
-#if !NO_SYS
- if (new_pbuf != NULL)
- break;
- else
- xSemaphoreTake(pbufFreed, 0);
- xSemaphoreTake(pbufFreed, portMAX_DELAY);
- }
- while (1) ;
-#endif
-
- /* Write the descriptors with the pbuf info till either of them expires */
- if (new_pbuf != NULL) {
- curr_bd = rxch->free_head;
-
- for (q = new_pbuf; (q != NULL) && (curr_bd != rxch->active_head); q = q->next) {
- curr_bd->bufptr = (uint8_t *)(q->payload);
-
- /* no support for buf_offset. RXBUFFEROFFSET register is 0 */
- curr_bd->bufoff_len = (q->len) & 0xFFFF;
- curr_bd->flags_pktlen = EMAC_DSC_FLAG_OWNER;
-
- rxch->freed_pbuf_len -= q->len;
-
- /* Save the pbuf */
- curr_bd->pbuf = q;
- last_bd = curr_bd;
- curr_bd = curr_bd->next;
- }
-
- /**
- * At this point either pbuf expired or no rxbd to allocate. If
- * there are no, enough rx bds to allocate all pbufs in the chain,
- * free the rest of the pbuf
- */
- if (q != NULL)
- pbuf_free((struct pbuf *)q);
-
- curr_tail = rxch->active_tail;
- last_bd->next = NULL;
-
- curr_tail->next = rxch->free_head;
-
- /**
- * Check if the reception has ended. If the EOQ flag is set, the NULL
- * Pointer is taken by the DMA engine. So we need to write the RX HDP
- * with the next descriptor.
- */
- if (curr_tail->flags_pktlen & EMAC_DSC_FLAG_EOQ)
- EMACRxHdrDescPtrWrite(hdkif->emac_base, (u32_t)(rxch->free_head), CHANNEL);
-
- rxch->free_head = curr_bd;
- rxch->active_tail = last_bd;
- }
- }
- curr_bd = rxch->active_head;
- }
- EMACCoreIntAck(hdkif->emac_base, EMAC_INT_CORE0_RX);
-
-#if !NO_SYS && !ONE_DRIVER_TASK
- SYS_ARCH_UNPROTECT(lev);
-}
-#endif
-}
-
-void RxIntHandler(u32_t instNum)
-{
-#if !NO_SYS
- vim_mask_clr(RXinterruptVectorNumber);
- /*
- static portBASE_TYPE xHigherPriorityTaskWoken;
- xHigherPriorityTaskWoken = pdFALSE;
- */
- /* 'Give' the semaphore to unblock the task. */
- xSemaphoreGiveFromISR(hdkif_data[instNum].goRX, NULL); // whenever there is time to process received packets, wake up task processing them
- /*
- if( xHigherPriorityTaskWoken == pdTRUE )
- {
- */
- /* Giving the semaphore unblocked a task, and the priority of the
- unblocked task is higher than or equal to the currently running task
- - force a context switch to ensure that the interrupt returns directly
- to the unblocked (higher priority) task.
- NOTE: The actual macro to use to force a context switch from an
- ISR is dependent on the port. This is the correct macro for the
- Open Watcom DOS port. Other ports may require different syntax.
- Refer to the examples provided for the port being used to determine
- the syntax required. */
- /*
- portSWITCH_CONTEXT();
- }
- */
-#else
- rpp_eth_recv_raw((void *)&hdkNetIF[instNum]);
-#endif
-}
-
-void TxIntHandler(u32_t instNum)
-{
- //struct hdkif *hdkif = &hdkif_data[instNum];
-#if !NO_SYS
- vim_mask_clr(TXinterruptVectorNumber); /* see sys_startup.c */
- xSemaphoreGiveFromISR(hdkif_data[instNum].goTX, NULL);
-#else
- //sendDone = TRUE;
- //rpp_eth_send_bd_handler((void *) &hdkif_data[instNum]);
-#endif
-}
-
-/**
- * TX err codes:
- *
- * 0 No error
- * 1h SOP error; the buffer is the first buffer in a packet, but the SOP bit is not set in software.
- * 2h Ownership bit not set in SOP buffer
- * 3h Zero next buffer descriptor pointer without EOP
- * 4h Zero buffer pointer
- * 5h Zero buffer length
- * 6h Packet length error (sum of buffers is less than packet length)
- *
- *
- * RX err codes:
- *
- * 0 No error
- * 1h Reserved
- * 2h Ownership bit not set in SOP buffer
- * 3h Reserved
- * 4h Zero buffer pointer
- */
-boolean_t HostPendErrHandler(void)
-{
- uint8_t index = MAX_EMAC_INSTANCE, errFound = FALSE;
- uint32_t reg;
- struct hdkif *hdkif;
-
- while (index) {
- hdkif = &hdkif_data[--index];
- if (EMACIntVectorGet(hdkif->emac_base) & EMAC_MACINVECTOR_HOSTPEND) errFound = TRUE;
- }
- if (!errFound) return FALSE; /* this is not the cause of the interrupt */
- rpp_sci_printk("HOSTPEND err\n");
- reg = HWREG(hdkif->emac_base + EMAC_MACSTATUS);
- rpp_sci_printk("TXCHERR: %d at CH: %d\n", ((reg >> EMAC_MACSTATUS_TXERRCODE_SHIFT) & 0x7), ((reg >> EMAC_MACSTATUS_TXERRCH_SHIFT) & 0x7));
- rpp_sci_printk("RXCHERR: %d at CH: %d\n", ((reg >> EMAC_MACSTATUS_RXERRCODE_SHIFT) & 0x7), ((reg >> EMAC_MACSTATUS_RXERRCH_SHIFT) & 0x7));
- /* no acknowledge - emac module has to be restarted */
- return TRUE; /* this was the reason of interrupt */
-}
-
-#if PHY_LINK_MONITOR_INT
-boolean_t LinkIntHandler(void)
-{
- uint8_t index = MAX_EMAC_INSTANCE, phyFound = FALSE;
- struct hdkif *hdkif;
- uint16_t regContent;
- volatile unsigned int autonegFinishWait = 0xFFFFFFF;
- volatile unsigned int dhcpBindWait = 0x3FFFFFFF;
-
- /* check each instance, whether this interrupt was meant for this function, if not return FALSE so other function may be tried */
- while (index) {
- hdkif = &hdkif_data[--index];
- if ( hdkif->phy_addr == (HWREG(hdkif->mdio_base + MDIO_USERPHYSEL0) & 0x1f) && EMACIntVectorGet(hdkif->emac_base) & EMAC_MACINVECTOR_LINKINT0 ) phyFound = TRUE;
- }
- if (!phyFound) return FALSE;
- struct netif *netif = &hdkNetIF[hdkif->inst_num];
-
- /* we handles here connection of cable after startup, not changes of linkstatus */
-
- /* wait for autonegotiation to be done */
-#if ONCE_LINK_SETUP
- while (hdkif->phy_autoneg_is_done(hdkif->mdio_base, hdkif->phy_addr) == FALSE) ;
-#else /* ONCE_LINK_SETUP */
- while (hdkif->phy_autoneg_is_done(hdkif->mdio_base, hdkif->phy_addr) == FALSE & autonegFinishWait--) ;
-#endif /* ONCE_LINK_SETUP */
-
- /* provide informations retrieved from autoneg to EMAC module */
- hdkif->phy_partnerability(hdkif->mdio_base, hdkif->phy_addr, ®Content);
- if (regContent & (PHY_100BASETXDUPL_m | PHY_10BASETDUPL_m))
- EMACDuplexSet(hdkif->emac_base, EMAC_DUPLEX_FULL);
- /* this is right place to implement transmit flow control if desired - set TXFLOWEN in MACCONTROL */
- else if (regContent & (PHY_100BASETX_m | PHY_10BASET_m))
- EMACDuplexSet(hdkif->emac_base, EMAC_DUPLEX_HALF);
- else {
- /* acknowledge MDIO module */
- HWREG(hdkif->mdio_base + MDIO_LINKINTRAW) = MDIO_LINKINTMASKED_USERPHY0;
- HWREG(hdkif->mdio_base + MDIO_LINKINTMASKED) = MDIO_LINKINTMASKED_USERPHY0;
-
- /* acknowledge EMAC control module by writing appropriate key to MACEOIVECTOR */
- EMACCoreIntAck(hdkif->emac_base, EMAC_INT_CORE0_MISC);
- return FALSE;
- }
- /* if link is up configure lwip struct netif */
- if (rpp_eth_phylinkstat(hdkif->inst_num)) {
-#if STATIC_IP_ADDRESS
- netif_set_up(netif);
-#elif LWIP_DHCP /* STATIC_IP_ADDRESS-LWIP_DHCP */
- if (dhcp_start(netif) != ERR_OK) /* XXX: can't be used from ISR (mem_malloc()) */
- return DHCP_MEM_ERR;
-
-#if ONCE_LINK_SETUP
- while (netif->dhcp->state != DHCP_BOUND) ;
-#else
- while (netif->dhcp->state != DHCP_BOUND & dhcpBindWait--) ;
- if (!dhcpBindWait) {
- /* acknowledge MDIO module */
- HWREG(hdkif->mdio_base + MDIO_LINKINTRAW) = MDIO_LINKINTMASKED_USERPHY0;
- HWREG(hdkif->mdio_base + MDIO_LINKINTMASKED) = MDIO_LINKINTMASKED_USERPHY0;
-
- /* acknowledge EMAC control module by writing appropriate key to MACEOIVECTOR */
- EMACCoreIntAck(hdkif->emac_base, EMAC_INT_CORE0_MISC);
- return FALSE;
- }
-#endif
-#else /* LWIP_DHCP-LWIP_AUTOIP FIXME: there should be some kind of waiting till ip is assigned */
- autoip_start(netif);
-#endif /* STATIC_IP_ADDRESS-LWIP_DHCP-LWIP_AUTOIP */
-#if ONCE_LINK_SETUP
- /* turn this interrupt off */
- HWREG(hdkif->emac_ctrl_base + EMAC_CTRL_CnMISCEN(0)) &= (~EMAC_CTRL_MISC_LINKINT0ENB & 0xf);
-#endif /* ONCE_LINK_SETUP */
- }
- else
- {
-#if ONCE_LINK_SETUP
- /* acknowledge MDIO module */
- HWREG(hdkif->mdio_base + MDIO_LINKINTRAW) = MDIO_LINKINTMASKED_USERPHY0;
- HWREG(hdkif->mdio_base + MDIO_LINKINTMASKED) = MDIO_LINKINTMASKED_USERPHY0;
-
- /* acknowledge EMAC control module by writing appropriate key to MACEOIVECTOR */
- EMACCoreIntAck(hdkif->emac_base, EMAC_INT_CORE0_MISC);
- return FALSE;
-#else
-#if STATIC_IP_ADDRESS
- netif_set_down(netif);
-#elif LWIP_DHCP /* STATIC_IP_ADDRESS-LWIP_DHCP */
- dhcp_stop(netif);
-#endif /* STATIC_IP_ADDRESS-LWIP_DHCP-LWIP_AUTOIP */
-#endif
- }
-
- /* acknowledge MDIO module */
- HWREG(hdkif->mdio_base + MDIO_LINKINTRAW) = MDIO_LINKINTMASKED_USERPHY0;
- HWREG(hdkif->mdio_base + MDIO_LINKINTMASKED) = MDIO_LINKINTMASKED_USERPHY0;
-
- /* acknowledge EMAC control module by writing appropriate key to MACEOIVECTOR */
- EMACCoreIntAck(hdkif->emac_base, EMAC_INT_CORE0_MISC);
-
- return TRUE;
-}
-#endif /* PHY_LINK_MONITOR_INT */
-#endif /* FREERTOS_POSIX */
+++ /dev/null
-/* Copyright (C) 2013 Czech Technical University in Prague
- *
- * Authors:
- * - Carlos Jenkins <carlos@jenkins.co.cr>
- * - Michal Horn <hornmich@fel.cvut.cz>
- *
- * This document contains proprietary information belonging to Czech
- * Technical University in Prague. Passing on and copying of this
- * document, and communication of its contents is not permitted
- * without prior written authorization.
- *
- * File : fr.c
- * Abstract:
- * FlexRay Communication RPP API implementation file.
- *
- * References:
- * fr.h
- * RPP API documentation.
- */
-
-
-#include "rpp/rpp.h"
-
-#ifndef FREERTOS_POSIX
-
-#include "stdio.h"
-#include "string.h"
-#include "drv/drv.h"
-
-static rpp_fr_state_t rpp_fr_state = RPP_FR_NOT_INITIALIZED; /**< Stores the actual state of the FlexRay module */
-
-/* AUTOSAR-like API */
-
-int8_t rpp_fr_init_driver(const Fr_ConfigType *config_ptr, uint32_t *error)
-{
- if (rpp_fr_state >= RPP_FR_DRV_INITIALIZED)
- return FAILURE;
-#ifndef FREERTOS_POSIX
- spi_tms570_init();
-#endif
- Fr_Init(config_ptr);
- rpp_fr_state = RPP_FR_DRV_INITIALIZED;
- return SUCCESS;
-}
-
-int8_t rpp_fr_init_controller(uint8_t ctrl, uint32_t *error)
-{
- Std_ReturnType retVal = ERR_PARAM_NO_ERROR;
-
- if (rpp_fr_state == RPP_FR_DRV_INITIALIZED ||
- rpp_fr_state == RPP_FR_HALTED ||
- rpp_fr_state == RPP_FR_ABORTED) {
- retVal = Fr_ControllerInit(ctrl);
- if (retVal & E_OK) {
- rpp_fr_state = RPP_FR_CTR_INITIALIZED;
- return SUCCESS;
- }
- else {
- *error = retVal;
- return FAILURE;
- }
- }
- return FAILURE;
-}
-
-int8_t rpp_fr_start_communication(uint8_t ctrl, uint32_t *error)
-{
- Std_ReturnType retVal = ERR_PARAM_NO_ERROR;
-
- if (rpp_fr_state == RPP_FR_CTR_INITIALIZED) {
- retVal = Fr_StartCommunication(ctrl);
- if (retVal & E_OK) {
- rpp_fr_state = RPP_FR_RUNNING;
- return SUCCESS;
- }
- else {
- *error = retVal;
- return FAILURE;
- }
- }
- return FAILURE;
-}
-
-int8_t rpp_fr_all_slots(uint8_t ctrl)
-{
- if (rpp_fr_state == RPP_FR_RUNNING && Fr_AllSlots(ctrl) & E_OK)
- return SUCCESS;
- return FAILURE;
-}
-
-int8_t rpp_fr_halt_communication(uint8_t ctrl)
-{
- if (rpp_fr_state == RPP_FR_RUNNING && Fr_HaltCommunication(ctrl) & E_OK) {
- rpp_fr_state = RPP_FR_HALTED;
- return SUCCESS;
- }
- return FAILURE;
-}
-
-int8_t rpp_fr_abort_communication(uint8_t ctrl)
-{
- if (rpp_fr_state == RPP_FR_RUNNING && Fr_AbortCommunication(ctrl) & E_OK) {
- rpp_fr_state = RPP_FR_ABORTED;
- return SUCCESS;
- }
- return FAILURE;
-}
-
-int8_t rpp_fr_send_wup(uint8_t ctrl)
-{
- if (rpp_fr_state == RPP_FR_CTR_INITIALIZED && Fr_SendWUP(ctrl) & E_OK)
- return SUCCESS;
- return FAILURE;
-}
-
-int8_t rpp_fr_set_wu_channel(uint8_t ctrl, Fr_ChannelType channel)
-{
- if (rpp_fr_state >= RPP_FR_CTR_INITIALIZED && Fr_SetWakeupChannel(ctrl, channel) & E_OK)
- return SUCCESS;
- return FAILURE;
-}
-
-int8_t rpp_fr_get_poc_status(uint8_t ctrl, Fr_POCStatusType *poc_status_ptr)
-{
- if (rpp_fr_state >= RPP_FR_DRV_INITIALIZED && Fr_GetPOCStatus(ctrl, poc_status_ptr) & E_OK)
- return SUCCESS;
- return FAILURE;
-}
-
-int8_t rpp_fr_transmit_lpdu(uint8_t ctrl, uint16_t lpdu_idx, const uint8_t *lsdu, uint8_t lsdu_length)
-{
- if (rpp_fr_state == RPP_FR_RUNNING && Fr_TransmitTxLPdu(ctrl, lpdu_idx, lsdu, lsdu_length) & E_OK)
- return SUCCESS;
- return FAILURE;
-}
-
-int8_t rpp_fr_cancel_transmit_lpdu(uint8_t ctrl, uint16_t lpdu_idx)
-{
- if (rpp_fr_state == RPP_FR_RUNNING && Fr_CancelTxLPdu(ctrl, lpdu_idx) & E_OK)
- return SUCCESS;
- return FAILURE;
-}
-
-int8_t rpp_fr_receive_lpdu(uint8_t ctrl, uint16_t lpdu_idx, uint8_t *lsdu, Fr_RxLPduStatusType *lpdu_status, uint8_t *lsdu_length)
-{
- if (rpp_fr_state == RPP_FR_RUNNING && Fr_ReceiveRxLPdu(ctrl, lpdu_idx, lsdu, lpdu_status, lsdu_length) & E_OK)
- return SUCCESS;
- return FAILURE;
-}
-
-int8_t rpp_fr_check_tx_lpdu_status(uint8_t ctrl, uint16_t lpdu_idx, Fr_TxLPduStatusType *lpdu_status)
-{
- if (rpp_fr_state == RPP_FR_RUNNING && Fr_CheckTxLPduStatus(ctrl, lpdu_idx, lpdu_status) & E_OK)
- return SUCCESS;
- return FAILURE;
-}
-
-int8_t rpp_fr_reconfigure_lpdu(uint8_t ctrl, uint16_t lpdu_idx, uint16_t frame_id, Fr_ChannelType channel, uint8_t cycle_set, uint8_t cycle_offset, uint8_t payload, uint16_t header_crc)
-{
- if (rpp_fr_state >= RPP_FR_CTR_INITIALIZED && Fr_ReconfigLPdu(ctrl, lpdu_idx, frame_id, channel, cycle_set, cycle_offset, payload, header_crc) & E_OK)
- return SUCCESS;
- return FAILURE;
-}
-
-int8_t rpp_fr_disable_lpdu(uint8_t ctrl, uint16_t lpdu_idx)
-{
- if (rpp_fr_state == RPP_FR_RUNNING && Fr_DisableLPdu(ctrl, lpdu_idx) & E_OK)
- return SUCCESS;
- return FAILURE;
-}
-
-int8_t rpp_fr_get_global_time(uint8_t ctrl, uint8_t *cycle, uint16_t *macroticks)
-{
- if (rpp_fr_state >= RPP_FR_CTR_INITIALIZED && Fr_GetGlobalTime(ctrl, cycle, macroticks) & E_OK)
- return SUCCESS;
- return FAILURE;
-}
-
-int8_t rpp_fr_get_network_management_vector(uint8_t ctrl, uint8_t *nm_vector)
-{
- if (rpp_fr_state >= RPP_FR_CTR_INITIALIZED && Fr_GetNmVector(ctrl, nm_vector) & E_OK)
- return SUCCESS;
- return FAILURE;
-}
-
-int8_t rpp_fr_get_channel_status(uint8_t ctrl, uint16_t *channel_a_status, uint16_t *channel_b_status)
-{
- if (rpp_fr_state >= RPP_FR_CTR_INITIALIZED && Fr_GetChannelStatus(ctrl, channel_a_status, channel_b_status) & E_OK)
- return SUCCESS;
- return FAILURE;
-}
-
-int8_t rpp_fr_get_clock_correction(uint8_t ctrl, int16_t *rate_correction, int32_t *offset_correction)
-{
- if (rpp_fr_state >= RPP_FR_RUNNING && Fr_GetClockCorrection(ctrl, rate_correction, offset_correction) & E_OK)
- return SUCCESS;
- return FAILURE;
-}
-
-int8_t rpp_fr_get_sync_frame_list(uint8_t ctrl, uint8_t list_size, uint16_t *channel_a_even_list, uint16_t *channel_b_even_list, uint16_t *channel_a_odd_list, uint16_t *channel_b_odd_list)
-{
- if (rpp_fr_state >= RPP_FR_RUNNING && Fr_GetSyncFrameList(ctrl, list_size, channel_a_even_list, channel_b_even_list, channel_a_odd_list, channel_b_odd_list) & E_OK)
- return SUCCESS;
- return FAILURE;
-}
-
-int8_t rpp_fr_get_wakeup_rx_status(uint8_t ctrl, uint8_t *status)
-{
- if (rpp_fr_state >= RPP_FR_DRV_INITIALIZED && Fr_GetWakeupRxStatus(ctrl, status) & E_OK)
- return SUCCESS;
- return FAILURE;
-}
-
-int8_t rpp_fr_set_timer(uint8_t ctrl, uint8_t timer_idx, uint8_t cycle_set, uint16_t offset_threshold)
-{
- if (rpp_fr_state == RPP_FR_RUNNING && Fr_SetAbsoluteTimer(ctrl, timer_idx, cycle_set, offset_threshold) & E_OK)
- return SUCCESS;
- return FAILURE;
-}
-
-int8_t rpp_fr_cancel_timer(uint8_t ctrl, uint8_t timer_idx)
-{
- if (rpp_fr_state == RPP_FR_RUNNING && Fr_CancelAbsoluteTimer(ctrl, timer_idx) & E_OK)
- return SUCCESS;
- return FAILURE;
-}
-
-int8_t rpp_fr_clear_timer_irq(uint8_t ctrl, uint8_t timer_idx)
-{
- if (rpp_fr_state >= RPP_FR_DRV_INITIALIZED && Fr_AckAbsoluteTimerIRQ(ctrl, timer_idx) & E_OK)
- return SUCCESS;
- return FAILURE;
-}
-
-int8_t rpp_fr_get_timer_irq_status(uint8_t ctrl, uint8_t timer_idx, boolean_t *irq_pending)
-{
- if (rpp_fr_state >= RPP_FR_DRV_INITIALIZED && Fr_GetAbsoluteTimerIRQStatus(ctrl, timer_idx, irq_pending) & E_OK)
- return SUCCESS;
- return FAILURE;
-}
-
-int8_t rpp_fr_get_driver_version(Std_VersionInfoType *version)
-{
- Fr_GetVersionInfo(version);
- return SUCCESS;
-}
-
-int8_t rpp_fr_read_com_ctrl_config(uint8_t ctrl, uint8_t param_idx, uint32_t *param_value)
-{
- if (Fr_ReadCCConfig(ctrl, param_idx, param_value) & E_OK)
- return SUCCESS;
- return FAILURE;
-}
-#endif /* FREERTOS_POSIX */
+++ /dev/null
-/* Copyright (C) 2013, 2014 Czech Technical University in Prague
- *
- * Authors:
- * - Carlos Jenkins <carlos@jenkins.co.cr>
- *
- * This document contains proprietary information belonging to Czech
- * Technical University in Prague. Passing on and copying of this
- * document, and communication of its contents is not permitted
- * without prior written authorization.
- *
- * File : hbr.c
- * Abstract:
- * H-Bridge Output RPP API implementation file.
- *
- * References:
- * hbr.h
- * RPP API documentation.
- */
-
-
-#include "rpp/rpp.h"
-
-#ifndef FREERTOS_POSIX
-#include "drv/hbridge.h"
-#endif
-
-static boolean_t initialized = FALSE;
-
-int8_t rpp_hbr_init()
-{
- if (initialized)
- return FAILURE;
- initialized = TRUE;
-#ifndef FREERTOS_POSIX
- dmmInit();
- hetInit();
- spi_tms570_init();
-#endif
- return SUCCESS;
-}
-
-
-// Private function to set the H-Bridge to default OFF settings
-static void rpp_hdr_reset()
-{
-#ifndef FREERTOS_POSIX
- drv_hbr_set_en(LOW);
- drv_hbr_pwm_set_duty(0);
- drv_hbr_pwm_stop();
- drv_hbr_set_dir(LOW);
-#endif
-}
-
-
-static boolean_t enabled = FALSE;
-
-int8_t rpp_hbr_enable(int32_t period)
-{
- if (enabled)
- return FAILURE;
-
- if (period < 1)
- period = 55; // ~18kHz (18181.818181818 Hz to be precise)
-
- rpp_hdr_reset();
-
-#ifndef FREERTOS_POSIX
-
- // Configure N2HET
- if (drv_hbr_pwm_set_signal(period, 0) != SUCCESS)
- return FAILURE;
- drv_hbr_pwm_start();
-
- drv_hbr_set_en(HIGH);
-
- // Start watchdog
- int ret = drv_hbr_wdg_start();
- if (ret != SUCCESS && ret != -RPP_EBUSY) // Don't fail if already started
- return FAILURE;
-
-#endif
-
- enabled = TRUE;
-
- return SUCCESS;
-}
-
-
-int8_t rpp_hbr_control(double cmd)
-{
- if (!enabled)
- return -1;
-
- // Check range of the command
- if ((cmd < -1.0) || (cmd > 1.0))
- return -2;
-
-#ifndef FREERTOS_POSIX
- // Great, now scale and return to sanity world of ints :D
- int32_t scaled = (int32_t)(cmd * 100.0);
-
-
- // Set direction
- drv_hbr_set_dir(scaled > 0);
-
- // Set PWM duty cycle
- drv_hbr_pwm_set_duty(abs(scaled));
-#endif
-
- return SUCCESS;
-}
-
-
-int8_t rpp_hbr_disable()
-{
- if (!enabled)
- return FAILURE;
-
-#ifndef FREERTOS_POSIX
- rpp_hdr_reset();
-
- // We ignore is watchdog could not be stopped, because is harmless.
- // It would be worse if we just could not stop the H-Bridge just because
- // the watchdog could not be stopped.
- drv_hbr_wdg_stop();
-#endif
-
- enabled = FALSE;
-
- return SUCCESS;
-}
+++ /dev/null
-/* Copyright (C) 2013 Czech Technical University in Prague
- *
- * Authors:
- * - Carlos Jenkins <carlos@jenkins.co.cr>
- *
- * This document contains proprietary information belonging to Czech
- * Technical University in Prague. Passing on and copying of this
- * document, and communication of its contents is not permitted
- * without prior written authorization.
- *
- * File : hout.c
- * Abstract:
- * High-Power Output (12V, 10A, PWM) RPP API implementation file.
- *
- * References:
- * hout.h
- * RPP API documentation.
- */
-
-
-#include "rpp/rpp.h"
-
-static boolean_t initialized = FALSE;
-
-int8_t rpp_hout_init()
-{
- if (initialized)
- return FAILURE;
- initialized = TRUE;
-
- // FIXME: Implement.
- return SUCCESS;
-}
+++ /dev/null
-/* Copyright (C) 2013-2014 Czech Technical University in Prague
- *
- * Authors:
- * - Karel Kočí
- *
- * This document contains proprietary information belonging to Czech
- * Technical University in Prague. Passing on and copying of this
- * document, and communication of its contents is not permitted
- * without prior written authorization.
- *
- * File : irc.c
- * Abstract:
- * IRC sensor input driver RPP API implementation file.
- *
- * References:
- * irc.h
- * RPP API documentation.
- */
-
-#include "rpp/rpp.h"
-
-#ifndef FREERTOS_POSIX
-#include "sys/ti_drv_het2.h"
-#include "sys/sys_pinmux.h"
-#else
-#define setMuxForIRC(a, b)
-#define ircEnable(a)
-#define ircDisable(a)
-#endif
-
-static boolean_t initialized = FALSE;
-
-boolean_t rpp_irc1_enabled = FALSE;
-boolean_t rpp_irc2_enabled = FALSE;
-
-int8_t rpp_irc_init()
-{
-
- if (initialized)
- return FAILURE;
-
-#ifndef FREERTOS_POSIX
- het2Init();
-#endif
-
- initialized = TRUE;
- return SUCCESS;
-}
-
-int8_t rpp_irc_enable(uint8_t irc)
-{
-
- if (!initialized)
- return FAILURE;
-
- if (irc < 1 || irc > 2)
- return -RPP_EINVAL;
-
- switch (irc) {
- case 1:
- rpp_irc1_enabled = TRUE;
- break;
- case 2:
- rpp_irc2_enabled = TRUE;
- break;
- }
-
- setMuxForIRC(irc, TRUE);
- ircEnable(irc);
-
- return SUCCESS;
-}
-
-int8_t rpp_irc_status(uint8_t irc)
-{
-
- if (!initialized)
- return FAILURE;
-
- if (irc < 1 || irc > 2)
- return -RPP_EINVAL;
-
- switch (irc) {
- case 1:
- return rpp_irc1_enabled ? 1 : 0;
- case 2:
- return rpp_irc2_enabled ? 1 : 0;
- }
- return FAILURE;
-}
-
-int32_t rpp_irc_get(uint8_t irc)
-{
-
- if (!initialized)
- return FAILURE;
-
- if (irc < 1 || irc > 2)
- return 0;
-
- if (rpp_irc_status(irc) != 1)
- return FAILURE;
-
-#ifndef FREERTOS_POSIX
- return ircGet(irc);
-#else
- return 1;
-#endif
-}
-
-int8_t rpp_irc_disable(uint8_t irc)
-{
-
- if (!initialized)
- return FAILURE;
-
- if (irc < 1 || irc > 2)
- return -RPP_EINVAL;
-
- if (rpp_irc_status(irc) != 1)
- return FAILURE;
-
- ircDisable(irc);
- setMuxForIRC(irc, FALSE);
- switch (irc) {
- case 1:
- rpp_irc1_enabled = FALSE;
- break;
- case 2:
- rpp_irc2_enabled = FALSE;
- break;
- }
- return FAILURE;
-}
+++ /dev/null
-/* Copyright (C) 2013 Czech Technical University in Prague
- *
- * Authors:
- * - Carlos Jenkins <carlos@jenkins.co.cr>
- *
- * This document contains proprietary information belonging to Czech
- * Technical University in Prague. Passing on and copying of this
- * document, and communication of its contents is not permitted
- * without prior written authorization.
- *
- * File : lin.c
- * Abstract:
- * LIN Communication RPP API implementation file.
- *
- * References:
- * lin.h
- * RPP API documentation.
- */
-
-
-#include "rpp/rpp.h"
-
-static boolean_t initialized = FALSE;
-
-int8_t rpp_lin_init()
-{
- if (initialized)
- return FAILURE;
- initialized = TRUE;
-
- // FIXME: Implement.
- return SUCCESS;
-}
+++ /dev/null
-/* Copyright (C) 2013 Czech Technical University in Prague
- *
- * Authors:
- * - Carlos Jenkins <carlos@jenkins.co.cr>
- *
- * This document contains proprietary information belonging to Czech
- * Technical University in Prague. Passing on and copying of this
- * document, and communication of its contents is not permitted
- * without prior written authorization.
- *
- * File : lout.c
- * Abstract:
- * Logic Output RPP API implementation file.
- *
- * References:
- * lout.h
- * RPP API documentation.
- */
-
-
-#include "rpp/rpp.h"
-
-#ifndef FREERTOS_POSIX
-#include "drv/lout.h"
-#endif
-
-static boolean_t initialized = FALSE;
-
-int8_t rpp_lout_init()
-{
- if (initialized)
- return FAILURE;
- initialized = TRUE;
-#ifndef FREERTOS_POSIX
- spi_tms570_init();
-#endif
-
- // FIXME: Implement.
- return SUCCESS;
-}
-
-
-static uint8_t out_cache = 0x0;
-
-int8_t rpp_lout_set(uint8_t pin, uint8_t val)
-{
- if ((pin < 1) || (pin > 8))
- return -1;
-
- uint8_t index = pin - 1;
- if (val)
- bit_set(out_cache, index);
- else
- bit_clear(out_cache, index);
- return SUCCESS;
-}
-
-
-static uint8_t diag_cache = 0x0;
-
-int8_t rpp_lout_diag(uint8_t pin)
-{
- if ((pin < 1) || (pin > 8))
- return -1;
-
- if (is_bit_set(diag_cache, pin - 1))
- return HIGH;
- return LOW;
-}
-
-
-int8_t rpp_lout_update()
-{
-#ifndef FREERTOS_POSIX
- // Update output values
- lout_set_word(out_cache);
- // FIXME: Check which SPI transfer statuses could be considered errors
- lout_spi_transfer();
-
- // Read back diagnostic values
- // FIXME: Implement. Dummy assign for now.
- diag_cache = out_cache;
-
- if (diag_cache != out_cache)
- return FAILURE;
-
-#endif
-
- return SUCCESS;
-}
+++ /dev/null
-/* Copyright (C) 2013 Czech Technical University in Prague
- *
- * Authors:
- * - Carlos Jenkins <carlos@jenkins.co.cr>
- *
- * This document contains proprietary information belonging to Czech
- * Technical University in Prague. Passing on and copying of this
- * document, and communication of its contents is not permitted
- * without prior written authorization.
- *
- * File : mout.c
- * Abstract:
- * Power Output (12V, 2A, Push/Pull) RPP API implementation file.
- *
- * References:
- * mout.h
- * RPP API documentation.
- */
-
-
-#include "rpp/rpp.h"
-
-#ifndef FREERTOS_POSIX
-#include "drv/mout.h"
-#endif
-
-static boolean_t initialized = FALSE;
-
-int8_t rpp_mout_init()
-{
- if (initialized)
- return FAILURE;
- initialized = TRUE;
-#ifndef FREERTOS_POSIX
- dmmInit();
- gioInit();
- hetInit();
-#endif
-
- return SUCCESS;
-}
-
-
-static uint8_t cache[] = {
- LOW, LOW, LOW, LOW, LOW, LOW
-};
-
-int8_t rpp_mout_set(uint8_t pin, uint8_t val)
-{
- // Check range
- if ((pin < 1) || (pin > 6))
- return -1;
-
- // Check val
- if ((val != HIGH) && (val != LOW))
- return -2;
-
- uint8_t idx = pin - 1;
-
-#ifndef FREERTOS_POSIX
- // Set and store value
- if (drv_mout_set(idx, val) != SUCCESS)
- return -3;
- cache[idx] = val;
-
- // FIXME Wait some time for synchronization
- // Don't use vTaskDelay() here because the minimum time to wait is one tick,
- // and depending of the configuration of the user model one tick can overrun
- // the program.
- int wait;
- for (wait = 0; wait < 10; wait++) {
- asm (" nop");
- }
-
- // Get value back and compare
- if (drv_mout_diag(idx) == FAILURE)
- return -4;
-
-#else
- cache[idx] = val;
-#endif
-
- return SUCCESS;
-}
-
-
-int8_t rpp_mout_get(uint8_t pin)
-{
- // Check range
- if ((pin < 1) || (pin > 6))
- return -1;
-
- return cache[pin - 1];
-}
-
-
-int8_t rpp_mout_diag(uint8_t pin)
-{
- // Check range
- if ((pin < 1) || (pin > 6))
- return -1;
-
-#ifndef FREERTOS_POSIX
- if (drv_mout_diag(pin - 1) == 0)
- return FAILURE;
-
-#endif
- return SUCCESS;
-}
#endif
rpp_din_init();
- rpp_lout_init();
rpp_adc_init();
- rpp_dac_init();
- rpp_hbr_init();
- rpp_mout_init();
- rpp_hout_init();
- rpp_lin_init();
rpp_sci_init();
- rpp_sdc_init();
- rpp_sdr_init();
- rpp_irc_init();
#ifndef FREERTOS_POSIX
- rpp_eth_init();
_enable_IRQ();
#endif
+++ /dev/null
-/* Copyright (C) 2013 Czech Technical University in Prague
- *
- * Authors:
- * - Carlos Jenkins <carlos@jenkins.co.cr>
- *
- * This document contains proprietary information belonging to Czech
- * Technical University in Prague. Passing on and copying of this
- * document, and communication of its contents is not permitted
- * without prior written authorization.
- *
- * File : sdc.c
- * Abstract:
- * SD Card logging RPP API implementation file.
- *
- * References:
- * sdc.h
- * RPP API documentation.
- */
-
-
-#include "rpp/rpp.h"
-
-static boolean_t initialized = FALSE;
-
-int8_t rpp_sdc_init()
-{
- if (initialized)
- return FAILURE;
- initialized = TRUE;
-
- // FIXME: Implement.
- return SUCCESS;
-}
+++ /dev/null
-/* Copyright (C) 2013, 2014 Czech Technical University in Prague
- *
- * Authors:
- * - Carlos Jenkins <carlos@jenkins.co.cr>
- *
- * This document contains proprietary information belonging to Czech
- * Technical University in Prague. Passing on and copying of this
- * document, and communication of its contents is not permitted
- * without prior written authorization.
- *
- * File : sdr.c
- * Abstract:
- * SD-RAM logging RPP API implementation file.
- *
- * References:
- * sdr.h
- * RPP API documentation.
- */
-
-
-#include "rpp/rpp.h"
-#include <stdio.h> // vsnprintf()
-#include <ctype.h> // isprint()
-#include <string.h> // strncmp()
-#include <stdarg.h> // va_start, va_end
-
-#ifndef FREERTOS_POSIX
-#include "drv/drv.h"
-#define echo(x) rpp_sci_putc(x)
-#else
-#define echo(x) (void)(x)
-#endif
-
-static const char *prompt = "--> ";
-static const char *newline = "\r\n";
-
-// extern this semaphore to wait for cmdproc to exit
-xSemaphoreHandle rpp_sdr_cmdproc_semaphore;
-
-
-/// Memory management variables ------------------------------------------------
-static xSemaphoreHandle memory_mutex;
-static uint32_t memory_size = 0;
-static uint8_t *memory_start = NULL;
-static uint8_t *memory_end = NULL;
-static uint8_t *memory_current = NULL;
-
-
-
-/// Tasks control --------------------------------------------------------------
-// Task handle for command processor task
-static xTaskHandle cmdproc_handle;
-
-// Task handle for log show task
-static xTaskHandle show_handle;
-
-// Flag the request the tasks to stop
-static boolean_t stop_tasks = FALSE;
-
-// Number of tasks running
-static uint8_t tasks_running = 0;
-
-// Force context change to other tasks until all
-// the tasks created by this module are deleted.
-static void wait_tasks_to_finish()
-{
- stop_tasks = TRUE;
- while (tasks_running > 0)
- taskYIELD();
- stop_tasks = FALSE;
-}
-
-
-
-/// Show log task --------------------------------------------------------------
-// Semaphore to order the show task to start flushing the log
-static xSemaphoreHandle show_semaphore;
-
-// Flag to check if log show task is flushing the log
-static boolean_t show_flushing = FALSE;
-
-// Show log task
-void rpp_sdr_showtask(void *p)
-{
- uint8_t *current;
- uint8_t byte;
-
- while (!stop_tasks) {
-
- // Wait semaphore to start
- if (xSemaphoreTake(show_semaphore, 1) != pdTRUE)
- // This will wake up each tick to check if
- // deletion of this task was requested.
- continue;
- current = memory_start;
-
- // Iterate until the end of the log
- while (show_flushing &&
- (current != memory_current) &&
- (current < memory_end)) { // Just in case
-
- // Print characters in this memory location.
- // Ignores non-printable characters except \r and \n
- byte = *current;
- if ((byte == '\r') || (byte == '\n') || isprint(byte))
- rpp_sci_putc(byte);
- current++;
- }
-
- // If user waited to finish
- if (show_flushing) {
- rpp_sci_printf((const char *)"%s", newline);
- rpp_sci_printf((const char *)"%s", prompt);
- show_flushing = FALSE;
- }
- }
-
- // Delete myself
- tasks_running--;
- vTaskDelete(NULL);
-}
-
-
-
-/// Command processor task -----------------------------------------------------
-#define BUF_SIZE 80
-
-// Buffer to store incomming command
-static char in_buffer[BUF_SIZE];
-
-// SCI log command processor task
-void rpp_sdr_cmdproc(void *p)
-{
- rpp_sci_printf((const char *)
- "Log control: %dkB available.\r\n",
- (rpp_sdr_available() / 1024)
- );
- rpp_sci_printf((const char *)
- "===========================================================\r\n"
- );
- rpp_sci_printf((const char *)"%s", prompt);
-
- uint8_t input = 0;
- uint8_t buff_index = 0;
- boolean_t flush = FALSE;
- while (!stop_tasks) {
-
- // Get one character from the user
- if (rpp_sci_read_nb(1, &input) != SUCCESS) {
- if (!stop_tasks)
- vTaskDelay(50 / portTICK_RATE_MS);
- continue;
- }
-
- // Stop flushing if one character is received
- if (show_flushing) {
- rpp_sdr_show(FALSE);
- vTaskDelay(100 / portTICK_RATE_MS);
- rpp_sci_printf("%s", newline);
- rpp_sci_printf("%s", prompt);
- continue;
- }
-
- // Backspace and Delete
- if (input == 8 || input == 127) {
- if (buff_index > 0) {
- buff_index--;
- echo('\b');
- echo(' ' );
- echo('\b');
- }
-
- // Line feed or Carriage return
- }
- else if (input == 10 || input == 13) {
- flush = TRUE;
- echo('\r');
- echo('\n');
-
- // If is any printable character
- }
- else if (isprint(input)) {
-
- // Store character and increment buffer index
- in_buffer[buff_index] = input;
- buff_index++;
- echo(input);
-
- // Check if buffer is full and force flush
- if (buff_index == BUF_SIZE - 1)
- flush = TRUE;
- }
- // All other character are ignored
-
- // Flush buffer
- if (flush) {
-
- // Terminate string
- in_buffer[buff_index] = '\0';
-
-
- // Re-prompt
- if (buff_index == 0) {
- rpp_sci_printf((const char *)"%s", newline);
- rpp_sci_printf((const char *)"%s", prompt);
-
- }
- // Help command
- else if (strncmp(in_buffer, "help", BUF_SIZE) == 0) {
-
- rpp_sci_printf((const char *)
- "Available commands:\r\n"
- );
- rpp_sci_printf((const char *)
- "\tlog - Show the log.\r\n"
- );
- rpp_sci_printf((const char *)
- "\tclear - Clear the log.\r\n"
- );
- rpp_sci_printf((const char *)
- "\tavailable - Display amount of memory left.\r\n"
- );
- rpp_sci_printf((const char *)
- "\texit - Exit this command processor.\r\n"
- );
-
- rpp_sci_printf((const char *)"%s", newline);
- rpp_sci_printf((const char *)"%s", prompt);
- }
- // Log command
- else if (strncmp(in_buffer, "log", BUF_SIZE) == 0)
- rpp_sdr_show(TRUE);
-
- // Clear command
- else if (strncmp(in_buffer, "clear", BUF_SIZE) == 0) {
- rpp_sdr_clear();
- rpp_sci_printf((const char *)"Done.\r\n");
- rpp_sci_printf((const char *)"%s", newline);
- rpp_sci_printf((const char *)"%s", prompt);
-
- }
- // Available command
- else if (strncmp(in_buffer, "available", BUF_SIZE) == 0) {
- rpp_sci_printf(
- (const char *)"%d kB of %d kB available.\r\n",
- rpp_sdr_available() / 1024,
- memory_size / 1024
- );
- rpp_sci_printf((const char *)"%s", newline);
- rpp_sci_printf((const char *)"%s", prompt);
-
- }
- // Exit command
- else if (strncmp(in_buffer, "exit", BUF_SIZE) == 0) {
- xSemaphoreGive(rpp_sdr_cmdproc_semaphore);
- tasks_running--;
- vTaskDelete(NULL);
-
- }
- // Unknown command, print buffer back
- else {
- rpp_sci_printf(
- (const char *)"ERROR: Unknown command \"%s\"\r\n",
- (char *)&in_buffer);
- rpp_sci_printf((const char *)"%s", prompt);
- }
-
- // Reset variables
- rpp_sci_flush(TRUE);
- buff_index = 0;
- flush = FALSE;
- }
- }
-
- // Delete myself
- tasks_running--;
- vTaskDelete(NULL);
-}
-
-
-
-/// Public API -----------------------------------------------------------------
-// Flag to check if SDR module is initialized
-static boolean_t initialized = FALSE;
-
-// Memory for Simulation only
-#ifdef FREERTOS_POSIX
-static uint8_t memory_simulation[1024*1024]; // Allocate 1MB for test
-#endif
-
-// Initialize SDR module
-int8_t rpp_sdr_init()
-{
- if (initialized)
- return FAILURE;
- initialized = TRUE;
-
- // Create memory write mutex
- memory_mutex = xSemaphoreCreateMutex();
-
- // Create log show semaphore
- vSemaphoreCreateBinary(show_semaphore);
- xSemaphoreTake(show_semaphore, 0);
-
- // Create semaphore for outer applications to wait cmdproc to exit.
- // Non static! The symbol should be exported, so use the full prefix.
- vSemaphoreCreateBinary(rpp_sdr_cmdproc_semaphore);
- xSemaphoreTake(rpp_sdr_cmdproc_semaphore, 0);
-
- // Define memory bounds
-#ifndef FREERTOS_POSIX
- memory_size = RPP_SDR_ADDR_END - RPP_SDR_ADDR_START + 1;
- memory_start = (uint8_t *)RPP_SDR_ADDR_START;
- memory_end = (uint8_t *)RPP_SDR_ADDR_END;
-#else
- memory_size = sizeof(memory_simulation);
- memory_start = (uint8_t *)&memory_simulation;
- memory_end = (uint8_t *)(memory_start + memory_size - 1);
-#endif
- memory_current = memory_start;
-
- // Low level init
-#ifndef FREERTOS_POSIX
- emif_SDRAMInit();
-#endif
-
- return SUCCESS;
-}
-
-
-// General flag to check if logging is enabled
-static boolean_t log_enabled = FALSE;
-
-// Enable/Disable logging
-int8_t rpp_sdr_setup(boolean_t enable)
-{
- // Just in case user ignore everything
- if (!initialized)
- return FAILURE;
-
- // No change, ignore
- if (log_enabled == enable)
- return FAILURE;
-
- // Shut down is requested
- if (log_enabled && !enable) {
- // Stop show task if running
- rpp_sdr_show(FALSE);
- // Delete tasks
- wait_tasks_to_finish();
- // Disable logging
- log_enabled = FALSE;
-
- // Startup is requested
- }
- else {
- if (xTaskCreate(rpp_sdr_showtask,
- (const signed char *)"rpp_sdr_showtask",
- 256, NULL, 2, &show_handle) != pdPASS)
- return FAILURE;
- tasks_running++;
-
- if (xTaskCreate(rpp_sdr_cmdproc,
- (const signed char *)"rpp_sdr_cmdproc",
- 512, NULL, 2, &cmdproc_handle) != pdPASS) {
- wait_tasks_to_finish();
- return FAILURE;
- }
- tasks_running++;
-
- log_enabled = TRUE;
- }
-
- return SUCCESS;
-}
-
-
-// Memory available
-uint32_t rpp_sdr_available()
-{
- return (uint32_t)(memory_end - memory_current + 1);
-}
-
-
-// Store something to the log, if logging is enabled
-int32_t rpp_sdr_printf(const char *format, ...)
-{
- if (!log_enabled)
- return FAILURE;
-
- // Don't even try if memory is full
- if (memory_current == memory_end)
- return FAILURE;
-
- /// Format user string
- char str[MAX_BUFFER_LEN];
- int length = -1;
-
- va_list argList;
- va_start(argList, format);
-
- length = vsnprintf(str, sizeof(str), format, argList);
-
- va_end(argList);
-
- if (length < 1)
- return length;
-
-
- /// Format header
- // uint32_t max value is 4294967295 (10 digits) + [] + ' ' + '\0' = 14
- char hdr[14];
- int hdr_length = -1;
- hdr_length = sprintf(hdr, (const char *)"[%10d] ", xTaskGetTickCount());
-
- if (hdr_length < 1)
- return hdr_length;
-
-
- /// Write header
- uint32_t cnt = 0;
- int i = 0;
- xSemaphoreTake(memory_mutex, portMAX_DELAY);
- while ((memory_current != memory_end) && (i < hdr_length)) {
-
- *memory_current = hdr[i];
-
- memory_current++;
- cnt++;
- i++;
- }
-
-
- /// Write user string
- i = 0;
- if (length > sizeof(str))
- length = sizeof(str);
- while ((memory_current != memory_end) && (i < length)) {
-
- *memory_current = str[i];
-
- memory_current++;
- cnt++;
- i++;
- }
-
- /// Write trailer
- static const char trl[2] = {'\r', '\n'};
- i = 0;
- while ((memory_current != memory_end) && (i < sizeof(trl))) {
-
- *memory_current = trl[i];
-
- memory_current++;
- cnt++;
- i++;
- }
-
- xSemaphoreGive(memory_mutex);
- return cnt;
-}
-
-
-// Clears log. Will also stop the show task
-int8_t rpp_sdr_clear()
-{
- if (!log_enabled)
- return FAILURE;
-
- // Stop log show flushing if running
- if (show_flushing)
- rpp_sdr_show(FALSE);
-
- // Check if log is already empty
- if (memory_current == memory_start)
- return FAILURE;
-
- // Reset memory pointer
- memory_current = memory_start;
-
- return SUCCESS;
-}
-
-
-// Starts/Stops the task that sends the log to the SCI
-int8_t rpp_sdr_show(boolean_t start)
-{
- if (!log_enabled)
- return FAILURE;
-
- // No change, ignore
- if (start == show_flushing)
- return FAILURE;
-
- // Log flush stop requested
- if (show_flushing && !start)
- show_flushing = FALSE;
-
- // Log flush start requested
- else {
- show_flushing = TRUE;
- xSemaphoreGive(show_semaphore);
- }
-
- return SUCCESS;
-}
/* Include Files */
#include "sys/sys.h"
-#include "rpp/eth.h"
void esmGroup1Notification(uint32_t channel)
{
xSemaphoreGiveFromISR(linMsgReceived, NULL);
}
}
-
-#ifndef FREERTOS_POSIX
-extern boolean_t HostPendErrHandler(void);
-#if PHY_LINK_MONITOR_INT
-extern boolean_t LinkIntHandler(void);
-#endif
-#pragma INTERRUPT(MDIOMiscInt, IRQ)
-void MDIOMiscInt(void)
-{
- if (HostPendErrHandler()) return;
-#if PHY_LINK_MONITOR_INT
- if (LinkIntHandler()) return;
-#endif
-}
-
-extern void RxIntHandler(uint32_t instNum);
-extern void TxIntHandler(uint32_t instNum);
-
-volatile int countEMACCore0RxIsr = 0;
-#pragma INTERRUPT(EMACCore0RxIsr, IRQ)
-void EMACCore0RxIsr(void)
-{
- countEMACCore0RxIsr++;
- RxIntHandler(0);
- /* FIXME was in emac_cmd.c/eth.c and should move somewhere else.
- rx_irq_cnt++;
-
- // We know we have only one RX Packet Buffer descriptor --
- // so we write it in CP to disable interrupt
- EMACRxCPWrite(emacBase, channel, (unsigned int)rx_desc);
- EMACCoreIntAck(emacBase, EMAC_INT_CORE0_RX);
- */
-}
-
-volatile int countEMACCore0TxIsr = 0;
-#pragma INTERRUPT(EMACCore0TxIsr, IRQ)
-void EMACCore0TxIsr(void)
-{
- countEMACCore0TxIsr++;
- TxIntHandler(0);
- /* FIXME Was in emac_cmd.c/eth.c and should move somewhere else
- tx_irq_cnt++;
- // If is not being processed by the EMAC anymore
- if (!(fr1.PktFlgLen & EMAC_DSC_FLAG_OWNER)) {
- EMACTxCPWrite(emacBase, channel, (unsigned int)&fr1);
- EMACCoreIntAck(emacBase, EMAC_INT_CORE0_TX);
- }
- */
-}
-#endif /* ifndef FREERTOS_POSIX */
&phantomInterrupt,
&phantomInterrupt,
&phantomInterrupt, // 75
- &MDIOMiscInt, //MDIOMiscInt
- &EMACCore0TxIsr, //EMACCore0TxIsr
+ &phantomInterrupt, //MDIOMiscInt
+ &phantomInterrupt, //EMACCore0TxIsr
&phantomInterrupt,
- &EMACCore0RxIsr, //EMACCore0RxIsr
+ &phantomInterrupt, //EMACCore0RxIsr
&phantomInterrupt, // 80
&phantomInterrupt,
&phantomInterrupt,