/********************************************************************************************************* ** Function name: zyHeapFree ** Descriptions: 堆释放内存 ** input parameters: pvPrt: 要释放的内存 ** output parameters: none ** Returned value: zy_OK: 成功 ** 负数: 错误,绝对值参考zy_if.h ** Created by: Chenmingji ** Created Date: 2009-07-23 **-------------------------------------------------------------------------------------------------------- ** Modified by: ** Modified date: *********************************************************************************************************/ INT32S zyHeapFree (void *pvPrt) { zyIrqDisable(); free(pvPrt); zyIrqEnable(); return ZY_OK; }
/********************************************************************************************************* ** Function name: zyThreadDel ** Descriptions: 删除线程 ** input parameters: ulThreadId: 线程ID ** output parameters: none ** Returned value: zy_OK: 成功 ** 负数: 错误,绝对值参考zy_if.h ** Created by: Chenmingji ** Created Date: 2009-07-23 **-------------------------------------------------------------------------------------------------------- ** Modified by: ** Modified date: *********************************************************************************************************/ INT32S zyThreadDel (unsigned long ulThreadId) { OS_TCB *ptcbTask; /* 任务TCB */ void *pvTmp1; ptcbTask = (OS_TCB *)ulThreadId; if (zyThreadGetCurId() == ulThreadId) { zyIrqDisable(); pvTmp1 = (void *)(ptcbTask->OSTCBStkPtr); zyHeapFree(pvTmp1); OSTaskDel(ptcbTask->OSTCBPrio); zyIrqEnable(); return ZY_OK; } OSSchedLock(); pvTmp1 = (void *)(ptcbTask->OSTCBStkPtr); zyHeapFree(pvTmp1); OSTaskDel(ptcbTask->OSTCBPrio); OSSchedUnlock(); return ZY_OK; }
/********************************************************************************************************* ** Function name: zyHeapMalloc ** Descriptions: 堆分配内存 ** input parameters: ulSize: 内存大小 ** output parameters: none ** Returned value: 内存地址,NULL为不成功 ** Created by: Chenmingji ** Created Date: 2009-07-23 **-------------------------------------------------------------------------------------------------------- ** Modified by: ** Modified date: *********************************************************************************************************/ void *zyHeapMalloc (INT32U ulSize) { void *pvRt = NULL; /* 返回值 */ zyIrqDisable(); pvRt = malloc((size_t)ulSize); zyIrqEnable(); return pvRt; }
/********************************************************************************************************* ** Function name: zdIsrClr ** Descriptions: IO系统清除中断服务程序 ** input parameters: uiChannel: 中断通道号 ** output parameters: none ** Returned value: zy_OK: 成功 ** 负数: 错误,绝对值参考zy_if.h ** Created by: Chenmingji ** Created Date: 2009-07-23 **-------------------------------------------------------------------------------------------------------- ** Modified by: ** Modified date: *********************************************************************************************************/ INT32S __s_zyIsrClr (unsigned int uiChannel) { unsigned int uiTmp1, uiTmp2, uiTmp3; if (uiChannel > MAX_VICS) { return -ZY_NOT_OK; } zyIrqDisable(); changeToSYSMode(); if (uiChannel >= 16) { uiTmp3 = uiChannel - 16; uiTmp1 = uiTmp3 / 32; uiTmp2 = uiTmp3 % 32; ((INT32U *)0xE000E180)[uiTmp1] = 1ul << uiTmp2; ((INT8U *)0xE000E400)[uiTmp3] = 0; } else { switch (uiChannel) { case MMI: SHCSR = SHCSR & ~(1 << 16); break; case BFI: SHCSR = SHCSR & ~(1 << 17); break; case UFI: SHCSR = SHCSR & ~(1 << 18); break; default: break; } if (uiChannel >= MMI) { uiTmp3 = uiChannel - MMI; ((INT8U *)0xE000ED18)[uiTmp3] = 0; } } #if VECTOR_TABLE_IN_FLASH == 0 ((unsigned long *)VTOR)[uiChannel] = 0; #endif /* VECTOR_TABLE_IN_FLASH */ changeToUSRMode(); zyIrqEnable(); return ZY_OK; }
/********************************************************************************************************* ** Function name: zyIsrSet ** Descriptions: IO系统设置中断服务程序 ** input parameters: uiChannel: 中断通道号 ** ulFunction: 中断服务程序地址 ** uiPrio: 中断优先级 ** output parameters: none ** Returned value: zy_OK: 成功 ** 负数: 错误,绝对值参考zy_if.h ** Created by: Chenmingji ** Created Date: 2009-07-23 **-------------------------------------------------------------------------------------------------------- ** Modified by: ** Modified date: *********************************************************************************************************/ INT32S zyIsrSet (unsigned int uiChannel, unsigned long ulFunction, unsigned int uiPrio) { unsigned int uiTmp1, uiTmp2, uiTmp3; if (uiChannel > MAX_VICS) { return -ZY_NOT_OK; } zyIrqDisable(); if (uiChannel >= 16) { uiTmp3 = uiChannel - 16; uiTmp1 = uiTmp3 / 32; uiTmp2 = uiTmp3 % 32; ((INT32U *)0xE000E100)[uiTmp1] = 1ul << uiTmp2; ((INT8U *)0xE000E400)[uiTmp3] = uiPrio; } else { switch (uiChannel) { case MMI: SHCSR = SHCSR | (1 << 16); break; case BFI: SHCSR = SHCSR | (1 << 17); break; case UFI: SHCSR = SHCSR | (1 << 18); break; default: break; } if (uiChannel >= MMI) { uiTmp3 = uiChannel - MMI; ((INT8U *)0xE000ED18)[uiTmp3] = uiPrio; } } #if VECTOR_TABLE_IN_FLASH == 0 ((unsigned long *)VTOR)[uiChannel] = ulFunction; #endif zyIrqEnable(); return ZY_OK; }
/********************************************************************************************************* ** Function name: zyIsrDisable ** Descriptions: 禁止指定中断 ** input parameters: uiChannel: 中断通道号 ** output parameters: none ** Returned value: zy_OK: 成功 ** 负数: 错误,绝对值参考zy_if.h ** Created by: Chenmingji ** Created Date: 2009-07-23 **-------------------------------------------------------------------------------------------------------- ** Modified by: ** Modified date: *********************************************************************************************************/ INT32S __s_zyIsrDisable (unsigned int uiChannel) { unsigned int uiTmp1, uiTmp2, uiTmp3; if (uiChannel > MAX_VICS) { return -ZY_NOT_OK; } if (uiChannel < 16) { return -ZY_NOT_OK; } zyIrqDisable(); changeToSYSMode(); if (uiChannel >= 16) { uiTmp3 = uiChannel - 16; uiTmp1 = uiTmp3 / 32; uiTmp2 = uiTmp3 % 32; ((INT32U *)0xE000E180)[uiTmp1] = 1ul << uiTmp2; } else { switch (uiChannel) { case MMI: SHCSR = SHCSR & ~(1 << 16); break; case BFI: SHCSR = SHCSR & ~(1 << 17); break; case UFI: SHCSR = SHCSR & ~(1 << 18); break; default: break; } } changeToUSRMode(); zyIrqEnable(); return ZY_OK; }