0
mirror of https://github.com/OneOfEleven/uv-k5-firmware-custom.git synced 2025-06-20 15:08:37 +03:00

Initial commit

This commit is contained in:
OneOfEleven
2023-09-09 08:03:56 +01:00
parent 92305117f1
commit 54441e27d9
3388 changed files with 582553 additions and 0 deletions

View File

@ -0,0 +1,51 @@
#include "cmsis_os2.h" // CMSIS RTOS header file
/*----------------------------------------------------------------------------
* Event Flags creation & usage
*---------------------------------------------------------------------------*/
#define FLAGS_MSK1 0x00000001U
osEventFlagsId_t evt_id; // event flasg id
osThreadId_t tid_Thread_EventSender; // thread id 1
osThreadId_t tid_Thread_EventReceiver; // thread id 2
void Thread_EventSender (void *argument); // thread function 1
void Thread_EventReceiver (void *argument); // thread function 2
int Init_Events (void) {
evt_id = osEventFlagsNew(NULL);
if (evt_id == NULL) {
; // Event Flags object not created, handle failure
}
tid_Thread_EventSender = osThreadNew(Thread_EventSender, NULL, NULL);
if (tid_Thread_EventSender == NULL) {
return(-1);
}
tid_Thread_EventReceiver = osThreadNew(Thread_EventReceiver, NULL, NULL);
if (tid_Thread_EventReceiver == NULL) {
return(-1);
}
return(0);
}
void Thread_EventSender (void *argument) {
while (1) {
osEventFlagsSet(evt_id, FLAGS_MSK1);
osThreadYield(); // suspend thread
}
}
void Thread_EventReceiver (void *argument) {
uint32_t flags;
while (1) {
flags = osEventFlagsWait(evt_id, FLAGS_MSK1, osFlagsWaitAny, osWaitForever);
//handle event
}
}

View File

@ -0,0 +1,62 @@
#include "cmsis_os2.h" // CMSIS RTOS header file
/*----------------------------------------------------------------------------
* Memory Pool creation & usage
*---------------------------------------------------------------------------*/
#define MEMPOOL_OBJECTS 16 // number of Memory Pool Objects
typedef struct { // object data type
uint8_t Buf[32];
uint8_t Idx;
} MEM_BLOCK_t;
osMemoryPoolId_t mpid_MemPool; // memory pool id
osThreadId_t tid_Thread_MemPool; // thread id
void Thread_MemPool (void *argument); // thread function
int Init_MemPool (void) {
mpid_MemPool = osMemoryPoolNew(MEMPOOL_OBJECTS, sizeof(MEM_BLOCK_t), NULL);
if (mpid_MemPool == NULL) {
; // MemPool object not created, handle failure
}
tid_Thread_MemPool = osThreadNew(Thread_MemPool, NULL, NULL);
if (tid_Thread_MemPool == NULL) {
return(-1);
}
return(0);
}
void Thread_MemPool (void *argument) {
MEM_BLOCK_t *pMem;
osStatus_t status;
while (1) {
; // Insert thread code here...
pMem = (MEM_BLOCK_t *)osMemoryPoolAlloc(mpid_MemPool, 0U); // get Mem Block
if (pMem != NULL) { // Mem Block was available
pMem->Buf[0] = 0x55U; // do some work...
pMem->Idx = 0U;
status = osMemoryPoolFree(mpid_MemPool, pMem); // free mem block
switch (status) {
case osOK:
break;
case osErrorParameter:
break;
case osErrorNoMemory:
break;
default:
break;
}
}
osThreadYield(); // suspend thread
}
}

View File

@ -0,0 +1,64 @@
#include "cmsis_os2.h" // CMSIS RTOS header file
/*----------------------------------------------------------------------------
* Message Queue creation & usage
*---------------------------------------------------------------------------*/
#define MSGQUEUE_OBJECTS 16 // number of Message Queue Objects
typedef struct { // object data type
uint8_t Buf[32];
uint8_t Idx;
} MSGQUEUE_OBJ_t;
osMessageQueueId_t mid_MsgQueue; // message queue id
osThreadId_t tid_Thread_MsgQueue1; // thread id 1
osThreadId_t tid_Thread_MsgQueue2; // thread id 2
void Thread_MsgQueue1 (void *argument); // thread function 1
void Thread_MsgQueue2 (void *argument); // thread function 2
int Init_MsgQueue (void) {
mid_MsgQueue = osMessageQueueNew(MSGQUEUE_OBJECTS, sizeof(MSGQUEUE_OBJ_t), NULL);
if (mid_MsgQueue == NULL) {
; // Message Queue object not created, handle failure
}
tid_Thread_MsgQueue1 = osThreadNew(Thread_MsgQueue1, NULL, NULL);
if (tid_Thread_MsgQueue1 == NULL) {
return(-1);
}
tid_Thread_MsgQueue2 = osThreadNew(Thread_MsgQueue2, NULL, NULL);
if (tid_Thread_MsgQueue2 == NULL) {
return(-1);
}
return(0);
}
void Thread_MsgQueue1 (void *argument) {
MSGQUEUE_OBJ_t msg;
while (1) {
; // Insert thread code here...
msg.Buf[0] = 0x55U; // do some work...
msg.Idx = 0U;
osMessageQueuePut(mid_MsgQueue, &msg, 0U, 0U);
osThreadYield(); // suspend thread
}
}
void Thread_MsgQueue2 (void *argument) {
MSGQUEUE_OBJ_t msg;
osStatus_t status;
while (1) {
; // Insert thread code here...
status = osMessageQueueGet(mid_MsgQueue, &msg, NULL, 0U); // wait for message
if (status == osOK) {
; // process data
}
}
}

View File

@ -0,0 +1,52 @@
#include "cmsis_os2.h" // CMSIS RTOS header file
/*----------------------------------------------------------------------------
* Mutex creation & usage
*---------------------------------------------------------------------------*/
osMutexId_t mid_Mutex; // mutex id
osThreadId_t tid_Thread_Mutex; // thread id
void Thread_Mutex (void *argument); // thread function
int Init_Mutex (void) {
mid_Mutex = osMutexNew(NULL);
if (mid_Mutex == NULL) {
; // Mutex object not created, handle failure
}
tid_Thread_Mutex = osThreadNew(Thread_Mutex, NULL, NULL);
if (tid_Thread_Mutex == NULL) {
return(-1);
}
return(0);
}
void Thread_Mutex (void *argument) {
osStatus_t status;
while (1) {
; // Insert thread code here...
status = osMutexAcquire(mid_Mutex, 0U);
switch (status) {
case osOK:
; // Use protected code here...
osMutexRelease(mid_Mutex);
break;
case osErrorResource:
break;
case osErrorParameter:
break;
case osErrorISR:
break;
default:
break;
}
osThreadYield(); // suspend thread
}
}

View File

@ -0,0 +1,50 @@
#include "cmsis_os2.h" // CMSIS RTOS header file
/*----------------------------------------------------------------------------
* Semaphore creation & usage
*---------------------------------------------------------------------------*/
osSemaphoreId_t sid_Semaphore; // semaphore id
osThreadId_t tid_Thread_Semaphore; // thread id
void Thread_Semaphore (void *argument); // thread function
int Init_Semaphore (void) {
sid_Semaphore = osSemaphoreNew(2U, 2U, NULL);
if (sid_Semaphore == NULL) {
; // Semaphore object not created, handle failure
}
tid_Thread_Semaphore = osThreadNew(Thread_Semaphore, NULL, NULL);
if (tid_Thread_Semaphore == NULL) {
return(-1);
}
return(0);
}
void Thread_Semaphore (void *argument) {
int32_t val;
while (1) {
; // Insert thread code here...
val = osSemaphoreAcquire(sid_Semaphore, 10U); // wait 10 mSec
switch (val) {
case osOK:
; // Use protected code here...
osSemaphoreRelease(sid_Semaphore); // return a token back to a semaphore
break;
case osErrorResource:
break;
case osErrorParameter:
break;
default:
break;
}
osThreadYield(); // suspend thread
}
}

View File

@ -0,0 +1,27 @@
#include "cmsis_os2.h" // CMSIS RTOS header file
/*----------------------------------------------------------------------------
* Thread 1 'Thread_Name': Sample thread
*---------------------------------------------------------------------------*/
osThreadId_t tid_Thread; // thread id
void Thread (void *argument); // thread function
int Init_Thread (void) {
tid_Thread = osThreadNew(Thread, NULL, NULL);
if (tid_Thread == NULL) {
return(-1);
}
return(0);
}
void Thread (void *argument) {
while (1) {
; // Insert thread code here...
osThreadYield(); // suspend thread
}
}

View File

@ -0,0 +1,51 @@
#include "cmsis_os2.h" // CMSIS RTOS header file
/*----------------------------------------------------------------------------
* Timer: Sample timer functions
*---------------------------------------------------------------------------*/
/*----- One-Shoot Timer Example -----*/
osTimerId_t tim_id1; // timer id
static uint32_t exec1; // argument for the timer call back function
// One-Shoot Timer Function
static void Timer1_Callback (void const *arg) {
// add user code here
}
/*----- Periodic Timer Example -----*/
osTimerId_t tim_id2; // timer id
static uint32_t exec2; // argument for the timer call back function
// Periodic Timer Function
static void Timer2_Callback (void const *arg) {
// add user code here
}
// Example: Create and Start timers
int Init_Timers (void) {
osStatus_t status; // function return status
// Create one-shoot timer
exec1 = 1U;
tim_id1 = osTimerNew((osTimerFunc_t)&Timer1_Callback, osTimerOnce, &exec1, NULL);
if (tim_id1 != NULL) { // One-shot timer created
// start timer with delay 100ms
status = osTimerStart(tim_id1, 100U);
if (status != osOK) {
return -1;
}
}
// Create periodic timer
exec2 = 2U;
tim_id2 = osTimerNew((osTimerFunc_t)&Timer2_Callback, osTimerPeriodic, &exec2, NULL);
if (tim_id2 != NULL) { // Periodic timer created
// start timer with periodic 1000ms interval
status = osTimerStart(tim_id2, 1000U);
if (status != osOK) {
return -1;
}
}
return NULL;
}

View File

@ -0,0 +1,28 @@
/*----------------------------------------------------------------------------
* CMSIS-RTOS 'main' function template
*---------------------------------------------------------------------------*/
#include "RTE_Components.h"
#include CMSIS_device_header
#include "cmsis_os2.h"
/*----------------------------------------------------------------------------
* Application main thread
*---------------------------------------------------------------------------*/
__NO_RETURN static void app_main (void *argument) {
(void)argument;
// ...
for (;;) {}
}
int main (void) {
// System Initialization
SystemCoreClockUpdate();
// ...
osKernelInitialize(); // Initialize CMSIS-RTOS
osThreadNew(app_main, NULL, NULL); // Create application main thread
osKernelStart(); // Start thread execution
for (;;) {}
}

View File

@ -0,0 +1,33 @@
/*
* Copyright (c) 2013-2018 Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the License); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* -----------------------------------------------------------------------------
*
* Project: CMSIS-RTOS RTX
* Title: SVC User Table
*
* -----------------------------------------------------------------------------
*/
#define USER_SVC_COUNT 0 // Number of user SVC functions
extern void * const osRtxUserSVC[1+USER_SVC_COUNT];
void * const osRtxUserSVC[1+USER_SVC_COUNT] = {
(void *)USER_SVC_COUNT,
//(void *)user_function1,
// ...
};