Update repo
This commit is contained in:
1 parent
ef5f9a563e
commit
dfe8ec02bd
12 files changed
+723
-341
No files matched your search
+134
-117
@@ -8,6 +8,11 @@
|
||||
// Driverlib headers
|
||||
#include "driverlib.h"
|
||||
#include "device.h"
|
||||
#include "sci.h"
|
||||
|
||||
// Customized headers
|
||||
#include "uart_drv.h"
|
||||
#include "at24cm02.h"
|
||||
|
||||
// FreeRTOS headers
|
||||
#include "FreeRTOS.h"
|
||||
@@ -16,33 +21,15 @@
|
||||
#include "queue.h"
|
||||
#include "timers.h"
|
||||
|
||||
// STDOUT redirection specific
|
||||
#include "uart_drv.h"
|
||||
#include "sci.h"
|
||||
|
||||
#define LED_R 41U // Red LED
|
||||
#define LED_B 58U // Blue LED
|
||||
|
||||
#define SCI_RXDA_PIN 85U
|
||||
#define SCI_TXDA_PIN 84U
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
#if defined (__TI_EABI__)
|
||||
void *malloc(size_t xSize);
|
||||
#pragma WEAK (malloc)
|
||||
#endif
|
||||
|
||||
#if defined (__TI_EABI__)
|
||||
// malloc - Traps malloc calls
|
||||
void *malloc(size_t xSize) {
|
||||
(void)xSize;
|
||||
// There should not be a heap defined, trap any attempts to call malloc()
|
||||
void* malloc(size_t xSize) {
|
||||
(void) xSize;
|
||||
taskDISABLE_INTERRUPTS();
|
||||
for(;;) {
|
||||
ESTOP0; // Optional: useful during CCS debug
|
||||
for (;;) {
|
||||
ESTOP0;
|
||||
}
|
||||
}
|
||||
#pragma WEAK (malloc)
|
||||
#endif
|
||||
|
||||
#if(configAPPLICATION_ALLOCATED_HEAP == 1)
|
||||
@@ -51,26 +38,36 @@ uint8_t ucHeap[configTOTAL_HEAP_SIZE];
|
||||
#pragma DATA_ALIGN(ucHeap, portBYTE_ALIGNMENT)
|
||||
#endif
|
||||
|
||||
// UART stdout redirection configuration related functions
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
#define LED_R 41U // Red LED
|
||||
#define LED_B 58U // Blue LED
|
||||
|
||||
#define SCI_RXDA_PIN 85U
|
||||
#define SCI_TXDA_PIN 84U
|
||||
|
||||
// UART: SCIA
|
||||
void UartSetup(void);
|
||||
void UartPutChar(uint16_t charToWrite);
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
// Configuration of CPU timer 1
|
||||
// CPU Timer 1
|
||||
void configCPUTimer(uint32_t cpuTimer, uint32_t period_us);
|
||||
__interrupt void timer1_ISR(void);
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// EEPROM: AT24CM02 (2Mbit)
|
||||
static EEPROM_Status eepromInitStatus = EEPROM_STATUS_NOT_INITIALIZED;
|
||||
static uint16_t eepromReadData[AT24CM02_PAGE_SIZE_BYTES];
|
||||
static uint16_t eepromWriteData[AT24CM02_PAGE_SIZE_BYTES];
|
||||
|
||||
void LED_TaskRed(void * pvParameters);
|
||||
void LED_TaskBlue(void * pvParameters);
|
||||
// FreeRTOS tasks
|
||||
void RedLED_Task(void *pvParameters);
|
||||
void BlueLED_Task(void *pvParameters);
|
||||
void EEPROM_Task(void *pvParameters);
|
||||
static SemaphoreHandle_t xSemaphore = NULL;
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
void main(void)
|
||||
{
|
||||
void main(void) {
|
||||
|
||||
// Initializes device clock and peripherals
|
||||
Device_init();
|
||||
|
||||
@@ -89,6 +86,9 @@ void main(void)
|
||||
GPIO_setDirectionMode(LED_B, GPIO_DIR_MODE_OUT);
|
||||
GPIO_writePin(LED_B, 0);
|
||||
|
||||
// GPIO91/GPIO92 and I2CA are configured by the EEPROM driver.
|
||||
eepromInitStatus = EEPROM_init();
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
// Clear all interrupts and initialize PIE vector table
|
||||
@@ -119,29 +119,17 @@ void main(void)
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
// Enable global Interrupts and higher priority real-time debug events
|
||||
EINT; // Enable Global interrupt INTM
|
||||
ERTM; // Enable Global real-time interrupt DBGM
|
||||
EINT;
|
||||
// Enable Global interrupt INTM
|
||||
ERTM;
|
||||
// Enable Global real-time interrupt DBGM
|
||||
|
||||
// ------------------------ Redirect STDOUT to SCI ------------------------
|
||||
|
||||
//**************************************************************************
|
||||
// NOTE: SCI Configuration for this example is done in UartSetup()
|
||||
// As an alternative, the user can configure SCI here in the main, and then
|
||||
// provide an empty UartSetup() function. UartSetup() must be defined, even
|
||||
// if it is empty.
|
||||
//**************************************************************************
|
||||
|
||||
// Add the UART device. When fopen is called with a filename that
|
||||
// begins "uart:", the UART device will be used to handle the file
|
||||
add_device("uart",
|
||||
_SSA,
|
||||
UART_open,
|
||||
UART_close,
|
||||
UART_read,
|
||||
UART_write,
|
||||
UART_lseek,
|
||||
UART_unlink,
|
||||
UART_rename);
|
||||
add_device("uart", _SSA, UART_open, UART_close, UART_read, UART_write,
|
||||
UART_lseek, UART_unlink, UART_rename);
|
||||
|
||||
// Assign stdout to be a UART device
|
||||
assert(freopen("uart:", "w", stdout) != NULL);
|
||||
@@ -149,72 +137,114 @@ void main(void)
|
||||
// ------------------------------- FreeRTOS -------------------------------
|
||||
|
||||
xSemaphore = xSemaphoreCreateBinary();
|
||||
if(xSemaphore == NULL) {
|
||||
while(1);
|
||||
}
|
||||
|
||||
// Create tasks dynamically
|
||||
if(xTaskCreate(LED_TaskRed,
|
||||
(const char *) "Red LED Task",
|
||||
256,
|
||||
NULL,
|
||||
tskIDLE_PRIORITY + 2,
|
||||
NULL) != pdPASS) {
|
||||
ESTOP0;
|
||||
}
|
||||
xTaskCreate(RedLED_Task,
|
||||
(const char*) "RedLED_Task",
|
||||
256,
|
||||
NULL,
|
||||
1,
|
||||
NULL);
|
||||
|
||||
if(xTaskCreate(LED_TaskBlue,
|
||||
(const char *) "Blue LED Task",
|
||||
256,
|
||||
NULL,
|
||||
tskIDLE_PRIORITY + 1,
|
||||
NULL) != pdPASS) {
|
||||
ESTOP0;
|
||||
}
|
||||
xTaskCreate(BlueLED_Task,
|
||||
(const char*) "BlueLED_Task",
|
||||
256,
|
||||
NULL,
|
||||
1,
|
||||
NULL);
|
||||
|
||||
xTaskCreate(EEPROM_Task,
|
||||
(const char*) "EEPROM_Task",
|
||||
384,
|
||||
NULL,
|
||||
2,
|
||||
NULL);
|
||||
|
||||
// Start the scheduler. This should not return
|
||||
vTaskStartScheduler();
|
||||
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------------
|
||||
|
||||
// This is an event-driven task. It sits in a blocked state waiting for
|
||||
// xSemaphore to be available by calling xSemaphoreTake() with a timeout
|
||||
// of portMAX_DELAY. Because Timer 1 releases this semaphore every 100 ms,
|
||||
// the Red LED task will unblock and toggle the LED exactly every 100 ms.
|
||||
// It is created with a higher priority of tskIDLE_PRIORITY + 2.
|
||||
void LED_TaskRed(void * pvParameters) {
|
||||
void RedLED_Task(void *pvParameters) {
|
||||
(void)pvParameters;
|
||||
int uart_count = 0;
|
||||
while(1) {
|
||||
if(xSemaphoreTake(xSemaphore, portMAX_DELAY) == pdTRUE) {
|
||||
// Toggle red LED
|
||||
while (1) {
|
||||
if (xSemaphoreTake(xSemaphore, portMAX_DELAY) == pdTRUE) {
|
||||
GPIO_togglePin(LED_R);
|
||||
uart_count++;
|
||||
printf("Hello from FreeRTOS running on the F28377S Coreboard, %d!\r\n", uart_count);
|
||||
printf("Hello from FreeRTOS running on the F28377S Coreboard, %d!\r\n",
|
||||
uart_count);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// This is a time-driven task. It simply toggles the blue LED and then puts
|
||||
// itself to sleep using vTaskDelay(500 / portTICK_PERIOD_MS).
|
||||
// Based on the RTOS configuration, this creates a 500 ms delay cycle.
|
||||
// It runs at a lower priority of tskIDLE_PRIORITY + 1.
|
||||
void LED_TaskBlue(void * pvParameters) {
|
||||
while(1) {
|
||||
// Toggle blue LED
|
||||
void BlueLED_Task(void *pvParameters) {
|
||||
(void)pvParameters;
|
||||
while (1) {
|
||||
GPIO_togglePin(LED_B);
|
||||
vTaskDelay(500);
|
||||
vTaskDelay(pdMS_TO_TICKS(500));
|
||||
}
|
||||
}
|
||||
|
||||
void EEPROM_Task(void *pvParameters) {
|
||||
uint16_t i;
|
||||
uint16_t mismatchCount = 0U;
|
||||
EEPROM_Status status = eepromInitStatus;
|
||||
const char *operation = "initialization";
|
||||
|
||||
(void)pvParameters;
|
||||
|
||||
// Allow the EEPROM supply and power-on reset to settle before the first
|
||||
// command. The datasheet requires at least 100 us after VCC is stable.
|
||||
vTaskDelay(pdMS_TO_TICKS(2U));
|
||||
|
||||
for (i = 0U; i < AT24CM02_PAGE_SIZE_BYTES; i++) {
|
||||
eepromWriteData[i] = i;
|
||||
eepromReadData[i] = 0U;
|
||||
}
|
||||
|
||||
if (status == EEPROM_STATUS_SUCCESS) {
|
||||
operation = "page write";
|
||||
status = EEPROM_writePage(eepromWriteData,
|
||||
AT24CM02_DEFAULT_ADDRESS,
|
||||
AT24CM02_PAGE_COUNT,
|
||||
AT24CM02_PAGE_SIZE_BYTES,
|
||||
pdMS_TO_TICKS(50U));
|
||||
}
|
||||
|
||||
if (status == EEPROM_STATUS_SUCCESS) {
|
||||
operation = "page read";
|
||||
status = EEPROM_readPage(eepromReadData,
|
||||
AT24CM02_DEFAULT_ADDRESS,
|
||||
AT24CM02_PAGE_COUNT,
|
||||
AT24CM02_PAGE_SIZE_BYTES,
|
||||
pdMS_TO_TICKS(50U));
|
||||
}
|
||||
|
||||
if (status == EEPROM_STATUS_SUCCESS) {
|
||||
for (i = 0U; i < AT24CM02_PAGE_SIZE_BYTES; i++) {
|
||||
if (eepromReadData[i] != eepromWriteData[i]) {
|
||||
mismatchCount++;
|
||||
}
|
||||
}
|
||||
printf("AT24CM02 page %u test: %s (%u mismatches)\r\n",
|
||||
AT24CM02_PAGE_COUNT,
|
||||
(mismatchCount == 0U) ? "PASS" : "FAIL",
|
||||
mismatchCount);
|
||||
} else {
|
||||
printf("AT24CM02 %s failed: %s\r\n",
|
||||
operation,
|
||||
EEPROM_statusString(status));
|
||||
}
|
||||
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------------
|
||||
|
||||
// configCPUTimer - This function initializes the selected timer to the
|
||||
// period specified by the "freq" and "period" variables. The "freq" is
|
||||
// CPU frequency in Hz and the period in uSeconds. The timer is held in
|
||||
// the stopped state after configuration.
|
||||
// This function initializes the selected timer to the period specified
|
||||
// by the "freq" and "period" variables. The "freq" is CPU frequency
|
||||
// in Hz and the period in us.
|
||||
void configCPUTimer(uint32_t cpuTimer, uint32_t period_us) {
|
||||
|
||||
uint32_t periodCount, freq = DEVICE_SYSCLK_FREQ;
|
||||
@@ -226,29 +256,20 @@ void configCPUTimer(uint32_t cpuTimer, uint32_t period_us) {
|
||||
// Set pre-scale counter to divide by 1 (SYSCLKOUT)
|
||||
CPUTimer_setPreScaler(cpuTimer, 0);
|
||||
|
||||
// Initializes timer control register. The timer is stopped,
|
||||
// reloaded, free run disabled, and interrupt enabled.
|
||||
// Additionally, the free and soft bits are set
|
||||
// Initializes timer control register
|
||||
CPUTimer_stopTimer(cpuTimer);
|
||||
CPUTimer_reloadTimerCounter(cpuTimer);
|
||||
CPUTimer_setEmulationMode(
|
||||
cpuTimer,
|
||||
CPUTIMER_EMULATIONMODE_STOPAFTERNEXTDECREMENT
|
||||
);
|
||||
CPUTimer_setEmulationMode(cpuTimer,
|
||||
CPUTIMER_EMULATIONMODE_STOPAFTERNEXTDECREMENT);
|
||||
|
||||
CPUTimer_enableInterrupt(cpuTimer);
|
||||
|
||||
}
|
||||
|
||||
|
||||
// When Timer 1 fires, the Interrupt Service Routine executes
|
||||
// xSemaphoreGiveFromISR(). This unlocks the semaphore so a waiting task
|
||||
// can proceed. portYIELD_FROM_ISR() is then called to force an immediate
|
||||
// FreeRTOS context switch if the newly unblocked task has a higher priority
|
||||
// than the interrupted task.
|
||||
// Timer 1 ISR function
|
||||
__interrupt void timer1_ISR(void) {
|
||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||
if(xSemaphore != NULL) {
|
||||
if (xSemaphore != NULL) {
|
||||
xSemaphoreGiveFromISR(xSemaphore, &xHigherPriorityTaskWoken);
|
||||
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
|
||||
}
|
||||
@@ -257,7 +278,7 @@ __interrupt void timer1_ISR(void) {
|
||||
|
||||
// -----------------------------------------------------------------------------------------
|
||||
|
||||
// UartSetup - Configures SCIA
|
||||
// Configures SCIA, baud rate is 115200
|
||||
void UartSetup(void) {
|
||||
|
||||
// SCIA RX: GPIO85
|
||||
@@ -278,11 +299,10 @@ void UartSetup(void) {
|
||||
SCI_performSoftwareReset(SCIA_BASE);
|
||||
|
||||
SCI_setConfig(SCIA_BASE,
|
||||
DEVICE_LSPCLK_FREQ,
|
||||
DEVICE_LSPCLK_FREQ,
|
||||
115200U,
|
||||
SCI_CONFIG_WLEN_8 |
|
||||
SCI_CONFIG_STOP_ONE |
|
||||
SCI_CONFIG_PAR_NONE);
|
||||
SCI_CONFIG_STOP_ONE | SCI_CONFIG_PAR_NONE);
|
||||
|
||||
SCI_resetChannels(SCIA_BASE);
|
||||
SCI_resetRxFIFO(SCIA_BASE);
|
||||
@@ -296,10 +316,7 @@ void UartSetup(void) {
|
||||
SCI_performSoftwareReset(SCIA_BASE);
|
||||
}
|
||||
|
||||
// UartPutChar - Implements SCI based putchar()
|
||||
// Implements SCI based putchar()
|
||||
void UartPutChar(uint16_t charToWrite) {
|
||||
SCI_writeCharBlockingFIFO(SCIA_BASE, charToWrite);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------------
|
||||
|
||||
Reference in new issue
Block a user