void OS_QInit (void) { #if OS_MAX_QS == 1 OSQFreeList = &OSQTbl[0]; /* Only ONE queue! */ OSQFreeList->OSQPtr = (OS_Q *)0; #endif #if OS_MAX_QS >= 2 INT16U i; OS_Q *pq1; OS_Q *pq2; OS_MemClr((INT8U *)&OSQTbl[0], sizeof(OSQTbl)); /* Clear the queue table */ pq1 = &OSQTbl[0]; pq2 = &OSQTbl[1]; for (i = 0; i < (OS_MAX_QS - 1); i++) { /* Init. list of free QUEUE control blocks */ pq1->OSQPtr = pq2; pq1++; pq2++; } pq1->OSQPtr = (OS_Q *)0; OSQFreeList = &OSQTbl[0]; #endif }
void OS_QInit (void) { #if OS_MAX_QS == 1u OSQFreeList = &OSQTbl[0]; /* Only ONE queue! */ OSQFreeList->OSQPtr = (OS_Q *)0; #endif #if OS_MAX_QS >= 2u INT16U ix; INT16U ix_next; OS_Q *pq1; OS_Q *pq2; OS_MemClr((INT8U *)&OSQTbl[0], sizeof(OSQTbl)); /* Clear the queue table */ for (ix = 0u; ix < (OS_MAX_QS - 1u); ix++) { /* Init. list of free QUEUE control blocks */ ix_next = ix + 1u; pq1 = &OSQTbl[ix]; pq2 = &OSQTbl[ix_next]; pq1->OSQPtr = pq2; } pq1 = &OSQTbl[ix]; pq1->OSQPtr = (OS_Q *)0; OSQFreeList = &OSQTbl[0]; #endif }
void OSTmr_Init (void) { #if OS_EVENT_NAME_EN > 0u INT8U err; #endif INT16U ix; INT16U ix_next; OS_TMR *ptmr1; OS_TMR *ptmr2; OS_MemClr((INT8U *)&OSTmrTbl[0], sizeof(OSTmrTbl)); /* Clear all the TMRs */ OS_MemClr((INT8U *)&OSTmrWheelTbl[0], sizeof(OSTmrWheelTbl)); /* Clear the timer wheel */ for (ix = 0u; ix < (OS_TMR_CFG_MAX - 1u); ix++) { /* Init. list of free TMRs */ ix_next = ix + 1u; ptmr1 = &OSTmrTbl[ix]; ptmr2 = &OSTmrTbl[ix_next]; ptmr1->OSTmrType = OS_TMR_TYPE; ptmr1->OSTmrState = OS_TMR_STATE_UNUSED; /* Indicate that timer is inactive */ ptmr1->OSTmrNext = (void *)ptmr2; /* Link to next timer */ #if OS_TMR_CFG_NAME_EN > 0u ptmr1->OSTmrName = (INT8U *)(void *)"?"; #endif } ptmr1 = &OSTmrTbl[ix]; ptmr1->OSTmrType = OS_TMR_TYPE; ptmr1->OSTmrState = OS_TMR_STATE_UNUSED; /* Indicate that timer is inactive */ ptmr1->OSTmrNext = (void *)0; /* Last OS_TMR */ #if OS_TMR_CFG_NAME_EN > 0u ptmr1->OSTmrName = (INT8U *)(void *)"?"; #endif OSTmrTime = 0u; OSTmrUsed = 0u; OSTmrFree = OS_TMR_CFG_MAX; OSTmrFreeList = &OSTmrTbl[0]; OSTmrSem = OSSemCreate(1u); OSTmrSemSignal = OSSemCreate(0u); #if OS_EVENT_NAME_EN > 0u /* Assign names to semaphores */ OSEventNameSet(OSTmrSem, (INT8U *)(void *)"uC/OS-II TmrLock", &err); OSEventNameSet(OSTmrSemSignal, (INT8U *)(void *)"uC/OS-II TmrSignal", &err); #endif OSTmr_InitTask(); }
/* * @brief initialize the memory partition manager. must be called when system power on. * @inputs None * @outputs None * @retval None */ void OS_MemInit (void) { #if OS_MAX_MEM_PART == 1u OS_MemClr((uint8_t *)&OSMemTbl[0], sizeof(OSMemTbl)); /* Clear the memory partition table */ OSMemFreeList = (OS_MEM *)&OSMemTbl[0]; /* Point to beginning of free list */ #endif #if OS_MAX_MEM_PART >= 2u OS_MEM *pmem; uint16_t i; OS_MemClr((uint8_t *)&OSMemTbl[0], sizeof(OSMemTbl)); /* Clear the memory partition table */ for (i = 0u; i < (OS_MAX_MEM_PART - 1u); i++) { /* Init. list of free memory partitions */ pmem = &OSMemTbl[i]; /* Point to memory control block (MCB) */ pmem->OSMemFreeList = (void *)&OSMemTbl[i + 1u]; /* Chain list of free partitions */ } pmem = &OSMemTbl[i]; pmem->OSMemFreeList = (void *)0; /* Initialize last node */ OSMemFreeList = &OSMemTbl[0]; /* Point to beginning of free list */ #endif }
void OS_MemInit (void) { #if OS_MAX_MEM_PART == 1 OS_MemClr((INT8U *)&OSMemTbl[0], sizeof(OSMemTbl)); /* Clear the memory partition table */ OSMemFreeList = (OS_MEM *)&OSMemTbl[0]; /* Point to beginning of free list */ #if OS_MEM_NAME_SIZE > 1 OSMemFreeList->OSMemName[0] = '?'; /* Unknown name */ OSMemFreeList->OSMemName[1] = OS_ASCII_NUL; #endif #endif #if OS_MAX_MEM_PART >= 2 OS_MEM *pmem; INT16U i; OS_MemClr((INT8U *)&OSMemTbl[0], sizeof(OSMemTbl)); /* Clear the memory partition table */ pmem = &OSMemTbl[0]; /* Point to memory control block (MCB) */ for (i = 0; i < (OS_MAX_MEM_PART - 1); i++) /* Init. list of free memory partitions */ { pmem->OSMemFreeList = (void *)&OSMemTbl[i + 1]; /* Chain list of free partitions */ #if OS_MEM_NAME_SIZE > 1 pmem->OSMemName[0] = '?'; /* Unknown name */ pmem->OSMemName[1] = OS_ASCII_NUL; #endif pmem++; } pmem->OSMemFreeList = (void *)0; /* Initialize last node */ #if OS_MEM_NAME_SIZE > 1 pmem->OSMemName[0] = '?'; /* Unknown name */ pmem->OSMemName[1] = OS_ASCII_NUL; #endif OSMemFreeList = &OSMemTbl[0]; /* Point to beginning of free list */ #endif }
void OS_FlagInit(void) { #if OS_MAX_FLAGS == 1 OSFlagFreeList = (OS_FLAG_GRP *) & OSFlagTbl[0]; /* Only ONE event flag group! */ OSFlagFreeList->OSFlagType = OS_EVENT_TYPE_UNUSED; OSFlagFreeList->OSFlagWaitList = (void *) 0; OSFlagFreeList->OSFlagFlags = (OS_FLAGS) 0; #if OS_FLAG_NAME_SIZE > 1 OSFlagFreeList->OSFlagName[0] = '?'; OSFlagFreeList->OSFlagName[1] = OS_ASCII_NUL; #endif #endif #if OS_MAX_FLAGS >= 2 INT16U i; OS_FLAG_GRP *pgrp1; OS_FLAG_GRP *pgrp2; OS_MemClr((INT8U *) & OSFlagTbl[0], sizeof(OSFlagTbl)); /* Clear the flag group table */ pgrp1 = &OSFlagTbl[0]; pgrp2 = &OSFlagTbl[1]; for (i = 0; i < (OS_MAX_FLAGS - 1); i++) { /* Init. list of free EVENT FLAGS */ pgrp1->OSFlagType = OS_EVENT_TYPE_UNUSED; pgrp1->OSFlagWaitList = (void *) pgrp2; #if OS_FLAG_NAME_SIZE > 1 pgrp1->OSFlagName[0] = '?'; /* Unknown name */ pgrp1->OSFlagName[1] = OS_ASCII_NUL; #endif pgrp1++; pgrp2++; } pgrp1->OSFlagType = OS_EVENT_TYPE_UNUSED; pgrp1->OSFlagWaitList = (void *) 0; #if OS_FLAG_NAME_SIZE > 1 pgrp1->OSFlagName[0] = '?'; /* Unknown name */ pgrp1->OSFlagName[1] = OS_ASCII_NUL; #endif OSFlagFreeList = &OSFlagTbl[0]; #endif }
void OSEventPatch(void) { #if (OS_EVENT_EN) && (OS_MAX_EVENTS > 0u) #if (OS_MAX_EVENTS > 1u) INT16U ix; INT16U ix_next; OS_EVENT *pevent1; OS_EVENT *pevent2; OS_MemClr((INT8U *)&OSEventTblPatch[0], sizeof(OSEventTblPatch)); /* Clear the event table */ for (ix = 0u; ix < (10u - 1u); ix++) { /* Init. list of free EVENT control blocks */ ix_next = ix + 1u; pevent1 = &OSEventTblPatch[ix]; pevent2 = &OSEventTblPatch[ix_next]; pevent1->OSEventType = OS_EVENT_TYPE_UNUSED; pevent1->OSEventPtr = pevent2; #if OS_EVENT_NAME_EN > 0u pevent1->OSEventName = (INT8U *)(void *)"?"; /* Unknown name */ #endif } pevent1 = &OSEventTblPatch[ix]; pevent1->OSEventType = OS_EVENT_TYPE_UNUSED; pevent1->OSEventPtr = (OS_EVENT *)0; #if OS_EVENT_NAME_EN > 0u pevent1->OSEventName = (INT8U *)(void *)"?"; /* Unknown name */ #endif OSEventFreeListPatch = &OSEventTblPatch[0]; #else OSEventFreeListPatch = &OSEventTblPatch[0]; /* Only have ONE event control block */ OSEventFreeListPatch->OSEventType = OS_EVENT_TYPE_UNUSED; OSEventFreeListPatch->OSEventPtr = (OS_EVENT *)0; #if OS_EVENT_NAME_EN > 0u OSEventFreeListPatch->OSEventName = (INT8U *)"?"; /* Unknown name */ #endif #endif OSEventTbl[OS_MAX_EVENTS -1].OSEventPtr = OSEventFreeListPatch; #endif }