-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from imahjoub/9-add-target-nucleo-l432kc
9 add target nucleo l432kc
- Loading branch information
Showing
8 changed files
with
184 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,25 @@ | ||
#include <stdint.h> | ||
#include <Mcal/Mcu.h> | ||
#include <Mcal/Reg.h> | ||
#include <Mcal/SysTick.h> | ||
#include <OS/OS.h> | ||
#include <Util/C/UtilTimer.h> | ||
|
||
void msDelay(volatile uint32_t count); | ||
|
||
// Simple delay function | ||
void msDelay(volatile uint32_t count) | ||
{ | ||
while (count--) | ||
{ | ||
__asm volatile ("nop"); // No operation (do nothing) | ||
} | ||
} | ||
|
||
|
||
int main(void) | ||
{ | ||
/* Configure the System clock and flash */ | ||
SystemInit(); | ||
SetSysClock(); | ||
|
||
/*. Enable GPIO Clock for GPIOB */ | ||
RCC_AHB2ENR |= (1U << 1U); | ||
/* Configure systick timer.*/ | ||
SysTick_Init(); | ||
|
||
/*. Configure PB3 as output */ | ||
GPIOB_MODER |= (1U << 6U); | ||
GPIOB_MODER &= ~(1U << 7U); | ||
/* Initialize the OS. This calls the task init-functions one time only */ | ||
OS_Init(); | ||
|
||
for(;;) | ||
{ | ||
/* Toggle PB3 to turn the LED on and off */ | ||
GPIOB_ODR ^= (1U << 3U); | ||
msDelay(1000000U); | ||
} | ||
/* Start the cooperative multitasking scheduler */ | ||
OS_Start(); | ||
|
||
return 0; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#ifndef OS_CFG_2023_08_23_H | ||
#define OS_CFG_2023_08_23_H | ||
|
||
#if defined(__cplusplus) | ||
extern "C" | ||
{ | ||
#endif | ||
|
||
extern void Task01_Init(void); | ||
|
||
extern void Task01_Func(void); | ||
|
||
#define OS_CFG_TASK_LIST_ENTRY(init, func, t0, cycle) { (init), (func), (t0), (cycle) } | ||
|
||
#define OS_CFG_TASK_LIST_INIT \ | ||
{ \ | ||
OS_CFG_TASK_LIST_ENTRY(Task01_Init, Task01_Func, 0U, 17U), \ | ||
} | ||
|
||
#if defined(__cplusplus) | ||
} | ||
#endif | ||
|
||
#endif /* OS_CFG_2023_08_23_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include <stdint.h> | ||
#include <string.h> | ||
|
||
#include <Mcal/Mcu.h> | ||
#include <Mcal/Reg.h> | ||
#include <Util/C/UtilTimer.h> | ||
|
||
static uint64_t TaskTimer02; | ||
|
||
/************************* TASK1 *********************************/ | ||
void Task01_Init(void); | ||
void Task01_Func(void); | ||
|
||
void Task01_Init(void) | ||
{ | ||
/*. Enable GPIO Clock for GPIOB */ | ||
RCC_AHB2ENR |= (1U << 1U); | ||
|
||
/*. Configure PB3 as output */ | ||
GPIOB_MODER |= (1U << 6U); | ||
GPIOB_MODER &= ~(1U << 7U); | ||
|
||
/* Toggle the LED pin */ | ||
GPIOB_ODR |= (uint32_t) (1UL << 3U); | ||
|
||
/* Set the next timer timeout to be 1s later, */ | ||
/* Toggling will be sequentially carried out in the task. */ | ||
TaskTimer02 = TimerStart(1000U); | ||
} | ||
|
||
void Task01_Func(void) | ||
{ | ||
if(TimerTimeout(TaskTimer02)) | ||
{ | ||
TaskTimer02 = TimerStart(1000U); | ||
|
||
/* Toggle the LED pin */ | ||
GPIOB_ODR ^= (uint32_t) (1UL << 3U); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include <stddef.h> | ||
#include <stdint.h> | ||
|
||
#include <OS/OS.h> | ||
#include <App/C/OS/OS_Cfg.h> | ||
#include <Util/C/UtilTimer.h> | ||
|
||
typedef struct TCB | ||
{ | ||
void(*pInit)(void); | ||
void(*pFunc)(void); | ||
Gpt_ValueType CallTimeNext; | ||
const unsigned CallCycle; | ||
} | ||
TCB; | ||
|
||
static TCB TaskList[] = OS_CFG_TASK_LIST_INIT; | ||
|
||
|
||
void OS_Init(void) | ||
{ | ||
for(size_t i = (size_t) UINT8_C(0); | ||
i < (size_t) (sizeof(TaskList) / sizeof(TaskList[(size_t) UINT8_C(0)])); | ||
++i) | ||
{ | ||
/* Call each task's init-function once at OS initialization.*/ | ||
TaskList[i].pInit(); | ||
} | ||
} | ||
|
||
void OS_Start(void) | ||
{ | ||
/* Start the cooperative multitasking scheduler (and never return).*/ | ||
for(;;) | ||
{ | ||
for(size_t i = (size_t) UINT8_C(0); | ||
i < (size_t) (sizeof(TaskList) / sizeof(TaskList[(size_t) UINT8_C(0)])); | ||
++i) | ||
{ | ||
if(TimerTimeout(TaskList[i].CallTimeNext)) | ||
{ | ||
TaskList[i].CallTimeNext = TimerStart(TaskList[i].CallCycle); | ||
|
||
TaskList[i].pFunc(); | ||
|
||
/* Implement an (optional) priority mechanism. */ | ||
break; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#ifndef OS_2023_08_23_H | ||
#define OS_2023_08_23_H | ||
|
||
#if defined(__cplusplus) | ||
extern "C" | ||
{ | ||
#endif | ||
|
||
void OS_Init (void); | ||
void OS_Start(void); | ||
|
||
#if defined(__cplusplus) | ||
} | ||
#endif | ||
|
||
#endif /* OS_2023_08_23_H */ |