Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fwxv 285 Fix I2C x86 #302

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions libraries/FreeRTOS/inc/FreeRTOS.h
Original file line number Diff line number Diff line change
Expand Up @@ -904,8 +904,9 @@

/* Defaults to uint16_t for backward compatibility, but can be overridden
* in FreeRTOSConfig.h if uint16_t is too restrictive. */
#define configSTACK_DEPTH_TYPE uint16_t
#define configSTACK_DEPTH_TYPE uint16_t
#endif
// This could be too restrictive for task depths over 128, causing memory corruption

#ifndef configRUN_TIME_COUNTER_TYPE

Expand Down Expand Up @@ -1359,4 +1360,4 @@ typedef StaticStreamBuffer_t StaticMessageBuffer_t;
#endif
/* *INDENT-ON* */

#endif /* INC_FREERTOS_H */
#endif /* INC_FREERTOS_H */
4 changes: 3 additions & 1 deletion libraries/ms-freertos/inc/FreeRTOSConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ extern uint32_t SystemCoreClock;
#define configUSE_TIMERS 1
#define configTIMER_TASK_PRIORITY 3
#define configTIMER_QUEUE_LENGTH 10
#define configTIMER_TASK_STACK_DEPTH configMINIMAL_STACK_SIZE
#define configTIMER_TASK_STACK_DEPTH \
configMINIMAL_STACK_SIZE // setting task depth to 128 (minimal stack size) will cause segfaults
// for tasks above 128

// Optional functions - most linkers will remove unused functions anyway
#define INCLUDE_vTaskPrioritySet 1
Expand Down
16 changes: 16 additions & 0 deletions projects/hello_world/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!--
General guidelines
These are just guidelines, not strict rules - document however seems best.
A README for a firmware-only project (e.g. Babydriver, MPXE, bootloader, CAN explorer) should answer the following questions:
- What is it?
- What problem does it solve?
- How do I use it? (with usage examples / example commands, etc)
- How does it work? (architectural overview)
A README for a board project (powering a hardware board, e.g. power distribution, centre console, charger, BMS carrier) should answer the following questions:
- What is the purpose of the board?
- What are all the things that the firmware needs to do?
- How does it fit into the overall system?
- How does it work? (architectural overview, e.g. what each module's purpose is or how data flows through the firmware)
-->
# hello_world

6 changes: 6 additions & 0 deletions projects/hello_world/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"libs": [
"FreeRTOS",
"ms-common"
]
}
15 changes: 15 additions & 0 deletions projects/hello_world/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <stdio.h>
#include <unistd.h>

#include "log.h"

int main(void) {
int in = 0;
while (true) {
in++;
LOG_DEBUG("%d, Hello World\n", in);
sleep(1);
}

return 0;
}
Binary file added projects/hello_world/src/main.exe
Binary file not shown.
16 changes: 16 additions & 0 deletions projects/task1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!--
General guidelines
These are just guidelines, not strict rules - document however seems best.
A README for a firmware-only project (e.g. Babydriver, MPXE, bootloader, CAN explorer) should answer the following questions:
- What is it?
- What problem does it solve?
- How do I use it? (with usage examples / example commands, etc)
- How does it work? (architectural overview)
A README for a board project (powering a hardware board, e.g. power distribution, centre console, charger, BMS carrier) should answer the following questions:
- What is the purpose of the board?
- What are all the things that the firmware needs to do?
- How does it fit into the overall system?
- How does it work? (architectural overview, e.g. what each module's purpose is or how data flows through the firmware)
-->
# task1

6 changes: 6 additions & 0 deletions projects/task1/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"libs": [
"FreeRTOS",
"ms-common"
]
}
50 changes: 50 additions & 0 deletions projects/task1/src/tasks/tasks.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include "tasks.h"

#include <stdbool.h>
#include <stdint.h>

#include "FreeRTOS.h"
#include "delay.h"
#include "gpio.h"
#include "log.h"
#include "misc.h"

// Non blocking delay. Simply consumes cpu cycles until a given time has passed
static void prv_delay(const TickType_t delay_ms) {
TickType_t curr_tick = xTaskGetTickCount();
while (xTaskGetTickCount() - curr_tick < pdMS_TO_TICKS(delay_ms)) {
}
}

TASK(task1, TASK_STACK_512) {
int counter1 = 0;
while (true) {
LOG_DEBUG("task 1, %d\n", counter1);
++counter1;
prv_delay(1000);
}
}

TASK(task2, TASK_STACK_512) {
int counter2 = 0;
while (true) {
LOG_DEBUG("task 2, %d\n", counter2);
++counter2;

vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}

int main(void) {
log_init();
tasks_init();
// Create tasks here
tasks_init_task(task1, TASK_PRIORITY(0), NULL);
tasks_init_task(task2, TASK_PRIORITY(1), NULL);

LOG_DEBUG("Program start...\n");
// Start the scheduler
tasks_start();

return 0;
}
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ This repository contains all firmware for the [University of Waterloo](https://u
- FreeRTOS clock is slow on x86. Look for `PortCPUClockFreqHz`. This was used as a quick patch for a strange build issue.
- You can't `LOG_*` or `printf` in a FreeRTOS task on arm unless you set the stack size to >~512 on task creation.
- You can't set the task depth to >128 ish on x86 or else a segfault occurs upon task creation.
- Could be due to setting task depth to uint16_t in FreeRTOS.h
Loading