⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 osapiarch.c

📁 osapi 2.0 操作系统抽象层 "系统抽象层"使得你可以实现一种对于RTOS、CPU和所运行产品物理特性完全透明的软件。使用这种公共通用接口
💻 C
📖 第 1 页 / 共 2 页
字号:
/*** Name: OS_MemSet**** Purpose:**	Copies 'size' number of byte of value 'value' to memory address pointed **  by 'dst' .For now we are using the standard c library call 'memset' **  but if we find we need to make it more efficient then we'll implement **  it in assembly.****** Assumptions and Notes:**** Parameters:**       dst : the starting address where to make the copy to.**       value : the value to copy to that memory area.**       size : the number of  memory location to copy to.**** Global Inputs: None**** Global Outputs: None****** Return Values: OS_SUCCESS*//*** OS_MemSet*/int32 OS_MemSet ( void *dst, uint8 value , uint32 size){  memset( dst, (int)value, (size_t)size);  return(OS_SUCCESS) ;} ;/*** Name: OS_MemCheckRange**** Purpose:**    Check that an address range exists and can be read.**** Assumptions and Notes:**** Parameters:**    Address : Starting address of range to be validated.**    Size    : Length of address range in bytes.**** Global Inputs: None**** Global Outputs: None**** Return Values:**    OS_SUCCESS         = the entire address range can be accessed**    OS_INVALID_POINTER = some addresses in the range are invalid*/int32 OS_MemCheckRange(uint32 Address, uint32 Size){   uint32        n;   OS_MemBank_t  *Bank;   /* Size must be nonzero. */   if (Size > 0) {      /* Loop over all memory banks. */      for (n = 0; n < OS_MAX_MEMORY_BANKS; n++) {         Bank = &OS_MemBankTbl[n];         /*         ** Check whether the starting address falls within the bank.         ** - If so, check whether the entire range fits within the bank.         ** - If not, try the next bank.         ** Note that the comparisons are done so that all quantities are         ** guaranteed to be nonnegative.         */         if (Address >= Bank->FirstAddr && Address <= Bank->LastAddr) {            if (Size - 1 <= Bank->LastAddr - Address)               return OS_SUCCESS;            else               return OS_INVALID_POINTER;         }      } /* END loop over banks */   } /* END if Size > 0 */   return OS_INVALID_POINTER;} /* END OS_MemCheckRange() *//*** Name: OS_EepromWrite32**** Purpose:**** Assumptions and Notes:**** Parameters:**   MemoryAddress : the address to copy the Value to**   Value32  : the value to copy to that address**** Global Inputs: None**** Global Outputs: None**** Return Values:**	 OS_SUCCESS**	 OS_ERROR_TIMEOUT write operation did not go through after a specific **       timeout.**	 OS_ERROR_ADD_MISALIGNED The Address is not aligned to 16 bit addressing**       scheme. */int32 OS_EepromWrite32( uint32 MemoryAddress, uint32 Value32 ){  uint32 timeout_counter=0 ;  uint32 ret_value = OS_SUCCESS;  uint16 pp_value ;	  /* check 32 bit alignment  */  if( MemoryAddress & 0x00000003)    {      return(OS_ERROR_ADDRESS_MISALIGNED) ;    }  /* make the Write */  *((uint32 *)MemoryAddress) = Value32;  /* poll and loop until the parallel port indicates that the eeprom write     has completed.     time out if loop exceeds EEPROM_WRITE_TIMEOUT  */	  do     {      timeout_counter++;      if(timeout_counter > EEPROM_WRITE_TIMEOUT)	{	  ret_value = OS_ERROR_TIMEOUT ;	  break ;	}      OS_PortRead16( (uint32) RHCF5208_PPDAT(MBAR), &pp_value ) ;    } while (  (pp_value & RHCF5208_PP_DAT0 ) != 0);	  return(ret_value) ;		}/*** Name: OS_EepromWrite16**** Purpose:**** Assumptions and Notes:**** Parameters:**   MemoryAddress : the address to copy the Value to**   Value16  : the value to copy to that address**** Global Inputs: None**** Global Outputs: None****** Return Values:**   OS_SUCCESS**	 OS_ERROR_TIMEOUT write operation did not go through after a specific **   timeout.**   OS_ERROR_ADD_MISALIGNED The Address is not aligned to 16 bit addressing**   scheme. */int32 OS_EepromWrite16( uint32 MemoryAddress, uint16 Value16 ){  uint32 write32 ,temp32 ;  uint32 aligned_address ;	  /* check 16 bit alignment  , check the 1st lsb */  if( MemoryAddress & 0x00000001)    {      return(OS_ERROR_ADDRESS_MISALIGNED) ;    }		  temp32 = Value16 ;	  /* check the 2nd lsb */  if( MemoryAddress & 0x00000002 )    {      /* writting the 16 high bit order of 32 bit field */      aligned_address = MemoryAddress-2 ;		      OS_MemRead32 ( aligned_address  ,&write32)  ;      write32 = (write32 & 0x0000FFFF) | (temp32<<16 ) ;    }  else    {      /* writting the 16 low bit order of 32 bit field */      aligned_address = MemoryAddress ;		      OS_MemRead32 (  aligned_address, &write32 ) ;      write32 = (write32 ) | (temp32 & 0xFFFF0000 ) ;    }		  return(OS_EepromWrite32(aligned_address,write32)) ;	}/*** Name: OS_EepromWrite8**** Purpose:**** Assumptions and Notes:**** Parameters:**   MemoryAddress : the address to copy the Value to**   Value8  : the value to copy to that address**** Global Inputs: None**** Global Outputs: None****** Return Values: **   OS_SUCCESS**   OS_ERROR_TIMEOUT write operation did not go through after a specific **   timeout.*/int32 OS_EepromWrite8( uint32 MemoryAddress, uint8 Value8 ){  uint32 aligned_address ;  uint16 write16 ,temp16;			  temp16 = Value8 ;	  /* check the 1st lsb */  if( MemoryAddress & 0x00000001)    {      /* writting the 8 high bit order of 16 bit field */      aligned_address = MemoryAddress-1 ;		      OS_MemRead16 ( aligned_address  ,&write16)  ;      write16 = (write16 & 0x00FF) | (temp16<<8 ) ;    }  else    {      /* writting the 8 low bit order of 16 bit field */      aligned_address = MemoryAddress ;		      OS_MemRead16 (  aligned_address, &write16 ) ;      write16 = (write16 ) | (temp16 & 0xFF00 ) ;    }		  return(OS_EepromWrite16(aligned_address,write16)) ;	}/*  Parallel Port layout   --------------------  Port Bit I/O Function Device Effected  - - --     -- ----------------  0 I EEPROM 1 ready signal EEPROM  1 O EEPROM 1 write protect EEPROM  2 O EEPROM reset Both EEPROM  3 O Reserved N/A  4 I Reserved N/A  5 O Reserved N/A  6 O RS-422 Enable RS-422 driver and receiver  7 O Mezzanine reset ASD  8 O Mezzanine power control ASD  9 O SP扐CE subsystem flag SP扐CE (1553)  10 O 1553 transceiver B inhibit SP扐CE (1553)  11 O 1553 transceiver A inhibit SP扐CE (1553)  12 I/O General purpose Available on 50-pin connector  13 I/O General purpose Available on 50-pin connector  14 I/O General purpose Available on 50-pin connector  15 I/O General purpose Available on 50-pin connector*//*** Name: OS_EepromWriteEnable**** Purpose:**	 Eable the eeprom for write operation**** Assumptions and Notes:**** Note : Interrrupts should be disabled prior to this function call**** Parameters:**** Global Inputs: None**** Global Outputs: None****** Return Values: **   OS_SUCCESS*/int32 OS_EepromWriteEnable(){  uint16 pp_value ;  OS_PortRead16( (uint32)RHCF5208_PPDAT(MBAR), &pp_value) ;  OS_PortWrite16 (  (uint32)RHCF5208_PPDAT(MBAR) , (pp_value | RHCF5208_PP_DAT1) ) ;  return(OS_SUCCESS) ;}/*** Name: OS_EepromWriteDisable**** Purpose:**	 Disable  the eeprom from write operation**** Assumptions and Notes:**** Parameters:**** Global Inputs: None**** Global Outputs: None****** Return Values: **   OS_SUCCESS*/int32 OS_EepromWriteDisable(){  uint16 pp_value ;  OS_PortRead16( (uint32)RHCF5208_PPDAT(MBAR), &pp_value) ;  OS_PortWrite16((uint32)RHCF5208_PPDAT(MBAR) ,(pp_value & (~RHCF5208_PP_DAT1) ) ) ;  return(OS_SUCCESS) ;}/*** Name: OS_EepromPowerUp**** Purpose:**		Power up the eeprom** Assumptions and Notes:**** Parameters:**** Global Inputs: None**** Global Outputs: None****** Return Values: **   OS_SUCCESS*/int32 OS_EepromPowerUp(){  uint16 pp_value ;  OS_PortRead16( (uint32)RHCF5208_PPDAT(MBAR), &pp_value) ;  OS_PortWrite16 ( (uint32) RHCF5208_PPDAT(MBAR) , (pp_value | RHCF5208_PP_DAT2) ) ;  return(OS_SUCCESS) ;}/*** Name: OS_EepromPowerDown**** Purpose:**		Power down the eeprom** Assumptions and Notes:**** Parameters:**** Global Inputs: None**** Global Outputs: None****** Return Values: **   OS_SUCCESS*/int32 OS_EepromPowerDown(){  uint16 pp_value ;  OS_PortRead16( (uint32)RHCF5208_PPDAT(MBAR), &pp_value) ;  OS_PortWrite16((uint32)RHCF5208_PPDAT(MBAR) ,(pp_value & (~RHCF5208_PP_DAT2) ) ) ;  return(OS_SUCCESS) ;}/*** Name: OS_ExcAttachHanlder**** Purpose:**		Attach an application high level exception handler.** Assumptions and Notes:**** Parameters:**  uint32 ExceptionNumber  -- the exception/vector ID**  void  *ExceptionHandler -- the User's C routine**  int32  parameter        -- an optional parameter****** Global Inputs: None**** Global Outputs: None****** Return Values: **   OS_SUCCESS,**   OS_ERROR,**   OS_INVALID_POINTER*//* Need a BSP header with these types and function prototypes */extern uint32 OS_BSPInstallVectorHandler(uint32 vector, void (*function_pointer)(uint32, uint32 *, uint32));int32 OS_ExcAttachHandler  (uint32 ExceptionNumber, void (*ExceptionHandler)(uint32, uint32 *,uint32), int32 parameter){  uint32 return_code;    if ( ExceptionNumber > 1 && ExceptionNumber < 256 && ExceptionHandler != NULL )  {     return_code = OS_BSPInstallVectorHandler(ExceptionNumber, ExceptionHandler);  }  else   {     return_code = OS_ERROR;  }    return (return_code);}/*** Name: OS_IntSetMask** Purpose:**      Set the masking register to mask and unmask interrupts **** Assumptions and Notes:**** Parameters:**		MaskSetting :the value to be written into the mask register**** Global Inputs: None**** Global Outputs: None****** Return Values: **		OS_SUCCESS*/int32 OS_IntSetMask ( uint32 MaskSetting ) {	/* write MaskSetting into the cpu mask register */	*RHCF5208_IMR(MBAR) = MaskSetting ;	return(OS_SUCCESS) ;}/*** Name: OS_IntGetMask** Purpose:**      Read and report the setting of the cpu mask register.**** Assumptions and Notes:**** Parameters:**		MaskSettingPtr : pointer to a location where the function store the**                       reading of the cpu mask register.**** Global Inputs: None**** Global Outputs: None****** Return Values: **    OS_SUCCESS**    OS_INVALID_POINTER if the passed pointer is a NULL        */int32 OS_IntGetMask ( uint32 * MaskSettingPtr ) {  if ( MaskSettingPtr == NULL)    return(OS_INVALID_POINTER) ;  /* read the  mask register */  *MaskSettingPtr = *RHCF5208_IMR(MBAR) ;  return(OS_SUCCESS) ;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -