This commit is contained in:
pvvx 2017-06-21 03:00:20 +03:00
parent 34d3652711
commit 39f77eb92b
1844 changed files with 899433 additions and 7 deletions

View file

@ -0,0 +1,739 @@
SECTIONS
{
__vectors_table = 0x0;
Reset_Handler = 0x101;
NMI_Handler = 0x109;
HardFault_Handler = 0x10d;
MemManage_Handler = 0x121;
BusFault_Handler = 0x125;
UsageFault_Handler = 0x129;
HalLogUartInit = 0x201;
HalSerialPutcRtl8195a = 0x2d9;
HalSerialGetcRtl8195a = 0x309;
HalSerialGetIsrEnRegRtl8195a = 0x329;
HalSerialSetIrqEnRegRtl8195a = 0x335;
HalCpuClkConfig = 0x341;
HalGetCpuClk = 0x355;
HalRomInfo = 0x39d;
HalGetRomInfo = 0x3b5;
HalResetVsr = 0x3c5;
HalDelayUs = 0x899;
HalNMIHandler = 0x8e1;
HalHardFaultHandler = 0x911;
HalMemManageHandler = 0xc09;
HalBusFaultHandler = 0xc39;
HalUsageFaultHandler = 0xc69;
HalUart0PinCtrlRtl8195A = 0xcfd;
HalUart1PinCtrlRtl8195A = 0xdc9;
HalUart2PinCtrlRtl8195A = 0xe9d;
HalSPI0PinCtrlRtl8195A = 0xf75;
HalSPI1PinCtrlRtl8195A = 0x1015;
HalSPI2PinCtrlRtl8195A = 0x10e5;
HalSPI0MCSPinCtrlRtl8195A = 0x11b5;
HalI2C0PinCtrlRtl8195A = 0x1275;
HalI2C1PinCtrlRtl8195A = 0x1381;
HalI2C2PinCtrlRtl8195A = 0x1459;
HalI2C3PinCtrlRtl8195A = 0x1529;
HalI2S0PinCtrlRtl8195A = 0x1639;
HalI2S1PinCtrlRtl8195A = 0x176d;
HalPCM0PinCtrlRtl8195A = 0x1845;
HalPCM1PinCtrlRtl8195A = 0x1949;
HalSDIODPinCtrlRtl8195A = 0x1a1d;
HalSDIOHPinCtrlRtl8195A = 0x1a6d;
HalMIIPinCtrlRtl8195A = 0x1ab9;
HalWLLEDPinCtrlRtl8195A = 0x1b51;
HalWLANT0PinCtrlRtl8195A = 0x1c0d;
HalWLANT1PinCtrlRtl8195A = 0x1c61;
HalWLBTCOEXPinCtrlRtl8195A = 0x1cb5;
HalWLBTCMDPinCtrlRtl8195A = 0x1d05;
HalNFCPinCtrlRtl8195A = 0x1d59;
HalPWM0PinCtrlRtl8195A = 0x1da9;
HalPWM1PinCtrlRtl8195A = 0x1ead;
HalPWM2PinCtrlRtl8195A = 0x1fb5;
HalPWM3PinCtrlRtl8195A = 0x20b1;
HalETE0PinCtrlRtl8195A = 0x21b9;
HalETE1PinCtrlRtl8195A = 0x22c1;
HalETE2PinCtrlRtl8195A = 0x23c9;
HalETE3PinCtrlRtl8195A = 0x24d1;
HalEGTIMPinCtrlRtl8195A = 0x25d9;
HalSPIFlashPinCtrlRtl8195A = 0x2679;
HalSDRPinCtrlRtl8195A = 0x2725;
HalJTAGPinCtrlRtl8195A = 0x280d;
HalTRACEPinCtrlRtl8195A = 0x2861;
HalLOGUartPinCtrlRtl8195A = 0x28b9;
HalLOGUartIRPinCtrlRtl8195A = 0x291d;
HalSICPinCtrlRtl8195A = 0x2981;
HalEEPROMPinCtrlRtl8195A = 0x29d9;
HalDEBUGPinCtrlRtl8195A = 0x2a31;
HalPinCtrlRtl8195A = 0x2b39;
SpicRxCmdRtl8195A = 0x2e5d;
SpicWaitBusyDoneRtl8195A = 0x2ea5;
SpicGetFlashStatusRtl8195A = 0x2eb5;
SpicWaitWipDoneRtl8195A = 0x2f55;
SpicTxCmdRtl8195A = 0x2f6d;
SpicSetFlashStatusRtl8195A = 0x2fc1;
SpicCmpDataForCalibrationRtl8195A = 0x3049;
SpicLoadInitParaFromClockRtl8195A = 0x3081;
SpicInitRtl8195A = 0x30e5;
SpicEraseFlashRtl8195A = 0x31bd;
SpiFlashApp = 0x3279;
HalPeripheralIntrHandle = 0x33b5;
HalSysOnIntrHandle = 0x3439;
HalWdgIntrHandle = 0x3485;
HalTimer0IntrHandle = 0x34d5;
HalTimer1IntrHandle = 0x3525;
HalI2C3IntrHandle = 0x3575;
HalTimer2To7IntrHandle = 0x35c5;
HalSpi0IntrHandle = 0x3615;
HalGpioIntrHandle = 0x3665;
HalUart0IntrHandle = 0x36b5;
HalSpiFlashIntrHandle = 0x3705;
HalUsbOtgIntrHandle = 0x3755;
HalSdioHostIntrHandle = 0x37a5;
HalI2s0OrPcm0IntrHandle = 0x37f5;
HalI2s1OrPcm1IntrHandle = 0x3845;
HalWlDmaIntrHandle = 0x3895;
HalWlProtocolIntrHandle = 0x38e5;
HalCryptoIntrHandle = 0x3935;
HalGmacIntrHandle = 0x3985;
HalGdma0Ch0IntrHandle = 0x39d5;
HalGdma0Ch1IntrHandle = 0x3a25;
HalGdma0Ch2IntrHandle = 0x3a75;
HalGdma0Ch3IntrHandle = 0x3ac5;
HalGdma0Ch4IntrHandle = 0x3b15;
HalGdma0Ch5IntrHandle = 0x3b65;
HalGdma1Ch0IntrHandle = 0x3bb5;
HalGdma1Ch1IntrHandle = 0x3c05;
HalGdma1Ch2IntrHandle = 0x3c55;
HalGdma1Ch3IntrHandle = 0x3ca5;
HalGdma1Ch4IntrHandle = 0x3cf5;
HalGdma1Ch5IntrHandle = 0x3d45;
HalSdioDeviceIntrHandle = 0x3d95;
VectorTableInitRtl8195A = 0x3de5;
txt0123456789ABCDEF = 0x3ec24;
VectorTableInitForOSRtl8195A = 0x4019;
VectorIrqRegisterRtl8195A = 0x4029;
VectorIrqUnRegisterRtl8195A = 0x4091;
VectorIrqEnRtl8195A = 0x40f1;
VectorIrqDisRtl8195A = 0x418d;
_UartRxDmaIrqHandle = 0x422d;
HalRuartPutCRtl8195a = 0x4281;
HalRuartGetCRtl8195a = 0x429d;
HalRuartRTSCtrlRtl8195a = 0x42bd;
HalRuartGetDebugValueRtl8195a = 0x42e1;
HalRuartGetIMRRtl8195a = 0x43e1;
HalRuartSetIMRRtl8195a = 0x442d;
_UartIrqHandle = 0x4465;
HalRuartDmaInitRtl8195a = 0x4681;
HalRuartIntDisableRtl8195a = 0x4845;
HalRuartDeInitRtl8195a = 0x4855;
HalRuartIntEnableRtl8195a = 0x4985;
_UartTxDmaIrqHandle = 0x4995;
HalRuartRegIrqRtl8195a = 0x49d1;
HalRuartAdapterLoadDefRtl8195a = 0x4a4d;
HalRuartTxGdmaLoadDefRtl8195a = 0x4add;
HalRuartRxGdmaLoadDefRtl8195a = 0x4bc9;
RuartLock = 0x4cc9;
RuartUnLock = 0x4ced;
HalRuartIntSendRtl8195a = 0x4d09;
HalRuartDmaSendRtl8195a = 0x4e35;
HalRuartStopSendRtl8195a = 0x4f89;
HalRuartIntRecvRtl8195a = 0x504d;
HalRuartDmaRecvRtl8195a = 0x51ad;
HalRuartStopRecvRtl8195a = 0x52cd;
RuartIsTimeout = 0x5385;
HalRuartSendRtl8195a = 0x53b1;
HalRuartRecvRtl8195a = 0x5599;
RuartResetRxFifoRtl8195a = 0x5751;
HalRuartResetRxFifoRtl8195a = 0x5775;
HalRuartInitRtl8195a = 0x5829;
HalGdmaOnOffRtl8195a = 0x5df1;
HalGdmaChIsrEnAndDisRtl8195a = 0x5e0d;
HalGdmaChEnRtl8195a = 0x5e51;
HalGdmaChDisRtl8195a = 0x5e6d;
HalGdamChInitRtl8195a = 0x5e91;
HalGdmaChSetingRtl8195a = 0x5ebd;
HalGdmaChBlockSetingRtl8195a = 0x000060dd;
HalGdmaChIsrCleanRtl8195a = 0x6419;
HalGdmaChCleanAutoSrcRtl8195a = 0x64a1;
HalGdmaChCleanAutoDstRtl8195a = 0x6501;
HalEFUSEPowerSwitch8195AROM = 0x6561;
HALEFUSEOneByteReadROM = 0x65f9;
HALEFUSEOneByteWriteROM = 0x6699;
__rtl_memcmpb_v1_00 = 0x681d;
__rtl_random_v1_00 = 0x6861;
__rtl_align_to_be32_v1_00 = 0x6881;
__rtl_memsetw_v1_00 = 0x6899;
__rtl_memsetb_v1_00 = 0x68ad;
__rtl_memcpyw_v1_00 = 0x68bd;
__rtl_memcpyb_v1_00 = 0x68dd;
__rtl_memDump_v1_00 = 0x68f5;
__rtl_AES_set_encrypt_key = 0x6901;
__rtl_cryptoEngine_AES_set_decrypt_key = 0x6c11;
__rtl_cryptoEngine_set_security_mode_v1_00 = 0x6c95;
__rtl_cryptoEngine_init_v1_00 = 0x6ea9;
__rtl_cryptoEngine_exit_v1_00 = 0x7055;
__rtl_cryptoEngine_reset_v1_00 = 0x70b1;
__rtl_cryptoEngine_v1_00 = 0x70ed;
__rtl_crypto_cipher_init_v1_00 = 0x7c69;
__rtl_crypto_cipher_encrypt_v1_00 = 0x7c89;
__rtl_crypto_cipher_decrypt_v1_00 = 0x7cad;
HalSsiPinmuxEnableRtl8195a = 0x7cd5;
HalSsiEnableRtl8195a = 0x7e45;
HalSsiDisableRtl8195a = 0x7ef9;
HalSsiLoadSettingRtl8195a = 0x7fad;
HalSsiSetInterruptMaskRtl8195a = 0x8521;
HalSsiGetInterruptMaskRtl8195a = 0x85c9;
HalSsiSetSclkPolarityRtl8195a = 0x863d;
HalSsiSetSclkPhaseRtl8195a = 0x8715;
HalSsiWriteRtl8195a = 0x87e9;
HalSsiSetDeviceRoleRtl8195a = 0x8861;
HalSsiSetRxFifoThresholdLevelRtl8195a = 0x88c9;
HalSsiSetTxFifoThresholdLevelRtl8195a = 0x8941;
HalSsiReadRtl8195a = 0x89b9;
HalSsiGetRxFifoLevelRtl8195a = 0x8a2d;
HalSsiGetTxFifoLevelRtl8195a = 0x8aa5;
HalSsiGetStatusRtl8195a = 0x8b1d;
HalSsiWriteableRtl8195a = 0x8b91;
HalSsiReadableRtl8195a = 0x8c09;
HalSsiBusyRtl8195a = 0x8c81;
HalSsiReadInterruptRtl8195a = 0x8cf9;
HalSsiWriteInterruptRtl8195a = 0x8efd;
HalSsiSetSlaveEnableRegisterRtl8195a = 0x9009;
HalSsiGetInterruptStatusRtl8195a = 0x90d9;
HalSsiInterruptEnableRtl8195a = 0x914d;
HalSsiInterruptDisableRtl8195a = 0x9299;
HalSsiGetRawInterruptStatusRtl8195a = 0x93e9;
HalSsiGetSlaveEnableRegisterRtl8195a = 0x945d;
HalSsiInitRtl8195a = 0x94d1;
_SsiReadInterrupt = 0x9ba5;
_SsiWriteInterrupt = 0x9db1;
_SsiIrqHandle = 0x9eb1;
HalI2CWrite32 = 0xa061;
HalI2CRead32 = 0xa09d;
HalI2CDeInit8195a = 0xa0dd;
HalI2CSendRtl8195a = 0xa1f1;
HalI2CReceiveRtl8195a = 0xa25d;
HalI2CEnableRtl8195a = 0xa271;
HalI2CIntrCtrl8195a = 0xa389;
HalI2CReadRegRtl8195a = 0xa3a1;
HalI2CWriteRegRtl8195a = 0xa3b1;
HalI2CSetCLKRtl8195a = 0xa3c5;
HalI2CMassSendRtl8195a = 0xa6e9;
HalI2CClrIntrRtl8195a = 0xa749;
HalI2CClrAllIntrRtl8195a = 0xa761;
HalI2CInit8195a = 0xa775;
HalI2CDMACtrl8195a = 0xaa31;
RtkI2CIoCtrl = 0xaa61;
RtkI2CPowerCtrl = 0xaa65;
HalI2COpInit = 0xaa69;
I2CIsTimeout = 0xac65;
I2CTXGDMAISRHandle = 0xb435;
I2CRXGDMAISRHandle = 0xb4c1;
RtkI2CIrqInit = 0xb54d;
RtkI2CIrqDeInit = 0xb611;
RtkI2CPinMuxInit = 0xb675;
RtkI2CPinMuxDeInit = 0xb7c9;
RtkI2CDMAInit = 0xb955;
RtkI2CInit = 0xbc95;
RtkI2CDMADeInit = 0xbdad;
RtkI2CDeInit = 0xbe4d;
RtkI2CSendUserAddr = 0xbee5;
RtkI2CSend = 0xc07d;
_RtkI2CReceive = 0x0c6dd;
RtkI2CLoadDefault = 0xce51;
RtkSalI2COpInit = 0xcf21;
HalI2SWrite32 = 0xcf65;
HalI2SRead32 = 0xcf85;
HalI2SDeInitRtl8195a = 0xcfa9;
HalI2STxRtl8195a = 0xcfc9;
HalI2SRxRtl8195a = 0xd011;
HalI2SEnableRtl8195a = 0xd05d;
HalI2SIntrCtrlRtl8195a = 0xd0b1;
HalI2SReadRegRtl8195a = 0xd0d1;
HalI2SClrIntrRtl8195a = 0xd0dd;
HalI2SClrAllIntrRtl8195a = 0xd0fd;
HalI2SInitRtl8195a = 0xd11d;
GPIO_GetIPPinName_8195a = 0xd2e5;
GPIO_GetChipPinName_8195a = 0xd331;
GPIO_PullCtrl_8195a = 0xd39d;
GPIO_FuncOn_8195a = 0xd421;
GPIO_FuncOff_8195a = 0xd481;
GPIO_Int_Mask_8195a = 0xd4e9;
GPIO_Int_SetType_8195a = 0xd511;
HAL_GPIO_IrqHandler_8195a = 0xd5fd;
HAL_GPIO_MbedIrqHandler_8195a = 0xd645;
HAL_GPIO_UserIrqHandler_8195a = 0xd6a1;
HAL_GPIO_IntCtrl_8195a = 0xd6cd;
HAL_GPIO_Init_8195a = 0xd805;
HAL_GPIO_DeInit_8195a = 0xdac1;
HAL_GPIO_ReadPin_8195a = 0xdbd1;
HAL_GPIO_WritePin_8195a = 0xdc91;
HAL_GPIO_RegIrq_8195a = 0xddad;
HAL_GPIO_UnRegIrq_8195a = 0xddf5;
HAL_GPIO_UserRegIrq_8195a = 0xde15;
HAL_GPIO_UserUnRegIrq_8195a = 0xdef9;
HAL_GPIO_MaskIrq_8195a = 0xdfc1;
HAL_GPIO_UnMaskIrq_8195a = 0xe061;
HAL_GPIO_IntDebounce_8195a = 0xe101;
HAL_GPIO_GetIPPinName_8195a = 0xe1c1;
HAL_GPIO_PullCtrl_8195a = 0xe1c9;
DumpForOneBytes = 0xe259;
CmdRomHelp = 0xe419;
CmdWriteWord = 0xe491;
CmdDumpHelfWord = 0xe505;
CmdDumpWord = 0xe5f1;
CmdDumpByte = 0xe6f5;
CmdSpiFlashTool = 0xe751;
GetRomCmdNum = 0xe7a9;
CmdWriteByte = 0xe7ad;
Isspace = 0xe7ed;
Strtoul = 0xe801;
ArrayInitialize = 0xe8b1;
GetArgc = 0xe8c9;
GetArgv = 0xe8f9;
UartLogCmdExecute = 0xe95d;
UartLogShowBackSpace = 0xe9fd;
UartLogRecallOldCmd = 0xea39;
UartLogHistoryCmd = 0xea71;
UartLogCmdChk = 0xeadd;
UartLogIrqHandle = 0xebf5;
RtlConsolInit = 0xecc5;
RtlConsolTaskRom = 0xed49;
RtlExitConsol = 0xed79;
RtlConsolRom = 0xedcd;
HalTimerOpInit = 0xee0d;
HalTimerIrq2To7Handle = 0xee59;
HalGetTimerIdRtl8195a = 0xef09;
HalTimerInitRtl8195a = 0xef3d;
HalTimerDisRtl8195a = 0xf069; /* error! */
HalTimerEnRtl8195a = 0xf089; /* error! */
HalTimerReadCountRtl8195a = 0xf0a9;
HalTimerIrqClearRtl8195a = 0xf0bd;
HalTimerDumpRegRtl8195a = 0xf0d1;
VSprintf = 0xf129;
DiagPrintf = 0xf39d;
DiagSPrintf = 0xf3b9;
DiagSnPrintf = 0xf3d1;
prvDiagPrintf = 0xf3ed;
prvDiagSPrintf = 0xf40d;
_memcmp = 0xf429;
_memcpy = 0xf465;
_memset = 0xf511;
Rand = 0xf585;
_strncpy = 0xf60d;
_strcpy = 0xf629;
prvStrCpy = 0xf639;
_strlen = 0xf651;
_strnlen = 0xf669;
prvStrLen = 0xf699;
_strcmp = 0xf6b1;
_strncmp = 0xf6d1;
prvStrCmp = 0xf719;
StrUpr = 0xf749;
prvAtoi = 0xf769;
prvStrStr = 0xf7bd;
_strsep = 0xf7d5;
skip_spaces = 0xf815;
skip_atoi = 0xf831;
_parse_integer_fixup_radix = 0xf869;
_parse_integer = 0xf8bd;
simple_strtoull = 0xf915;
simple_strtoll = 0xf945;
simple_strtoul = 0xf965;
simple_strtol = 0xf96d;
_vsscanf = 0xf985;
_sscanf = 0xff71;
div_u64 = 0xff91;
div_s64 = 0xff99;
div_u64_rem = 0xffa1;
div_s64_rem = 0xffb1;
_strpbrk = 0xffc1;
_strchr = 0xffed;
aes_set_key = 0x10005;
aes_encrypt = 0x103d1;
aes_decrypt = 0x114a5;
AES_WRAP = 0x125c9;
AES_UnWRAP = 0x12701;
crc32_get = 0x12861;
arc4_byte = 0x12895;
rt_arc4_init = 0x128bd;
rt_arc4_crypt = 0x12901;
rt_md5_init = 0x131c1;
rt_md5_append = 0x131f5;
rt_md5_final = 0x1327d;
rt_md5_hmac = 0x132d5;
rtw_get_bit_value_from_ieee_value = 0x13449;
rtw_is_cckrates_included = 0x13475;
rtw_is_cckratesonly_included = 0x134b5;
rtw_check_network_type = 0x134dd;
rtw_set_fixed_ie = 0x1350d;
rtw_set_ie = 0x1352d;
rtw_get_ie = 0x1355d;
rtw_set_supported_rate = 0x13591;
rtw_get_rateset_len = 0x13611;
rtw_get_wpa_ie = 0x1362d;
rtw_get_wpa2_ie = 0x136c9;
rtw_get_wpa_cipher_suite = 0x13701;
rtw_get_wpa2_cipher_suite = 0x13769;
rtw_parse_wpa_ie = 0x137d1;
rtw_parse_wpa2_ie = 0x138ad;
rtw_get_sec_ie = 0x13965;
rtw_get_wps_ie = 0x13a15;
rtw_get_wps_attr = 0x13a99;
rtw_get_wps_attr_content = 0x13b49;
rtw_ieee802_11_parse_elems = 0x13b91;
str_2char2num = 0x13d9d;
key_2char2num = 0x13db9;
convert_ip_addr = 0x13dd1;
rom_psk_PasswordHash = 0x13e9d;
rom_psk_CalcGTK = 0x13ed5;
rom_psk_CalcPTK = 0x13f69;
wep_80211_encrypt = 0x14295;
wep_80211_decrypt = 0x142f5;
tkip_micappendbyte = 0x14389;
rtw_secmicsetkey = 0x143d9;
rtw_secmicappend = 0x14419;
rtw_secgetmic = 0x14435;
rtw_seccalctkipmic = 0x1449d;
tkip_phase1 = 0x145a5;
tkip_phase2 = 0x14725;
tkip_80211_encrypt = 0x14941;
tkip_80211_decrypt = 0x149d5;
aes1_encrypt = 0x14a8d;
aesccmp_construct_mic_iv = 0x14c65;
aesccmp_construct_mic_header1 = 0x14ccd;
aesccmp_construct_mic_header2 = 0x14d21;
aesccmp_construct_ctr_preload = 0x14db5;
aes_80211_encrypt = 0x14e29;
aes_80211_decrypt = 0x151ad;
_sha1_process_message_block = 0x155b9;
_sha1_pad_message = 0x15749;
rt_sha1_init = 0x157e5;
rt_sha1_update = 0x15831;
rt_sha1_finish = 0x158a9;
rt_hmac_sha1 = 0x15909;
rom_aes_128_cbc_encrypt = 0x15a65;
rom_aes_128_cbc_decrypt = 0x15ae1;
rom_rijndaelKeySetupEnc = 0x15b5d;
rom_aes_decrypt_init = 0x15c39;
rom_aes_internal_decrypt = 0x15d15;
rom_aes_decrypt_deinit = 0x16071;
rom_aes_encrypt_init = 0x16085;
rom_aes_internal_encrypt = 0x1609d;
rom_aes_encrypt_deinit = 0x16451;
bignum_init = 0x17b35;
bignum_deinit = 0x17b61;
bignum_get_unsigned_bin_len = 0x17b81;
bignum_get_unsigned_bin = 0x17b85;
bignum_set_unsigned_bin = 0x17c21;
bignum_cmp = 0x17cd1;
bignum_cmp_d = 0x17cd5;
bignum_add = 0x17cfd;
bignum_sub = 0x17d0d;
bignum_mul = 0x17d1d;
bignum_exptmod = 0x17d2d;
WPS_realloc = 0x17d51;
os_zalloc = 0x17d99;
rom_hmac_sha256_vector = 0x17dc1;
rom_hmac_sha256 = 0x17ebd;
rom_sha256_vector = 0x18009;
phy_CalculateBitShift = 0x18221;
PHY_SetBBReg_8195A = 0x18239;
PHY_QueryBBReg_8195A = 0x18279;
ROM_odm_QueryRxPwrPercentage = 0x1829d;
ROM_odm_EVMdbToPercentage = 0x182bd;
ROM_odm_SignalScaleMapping_8195A = 0x182e5;
ROM_odm_FalseAlarmCounterStatistics = 0x183cd;
ROM_odm_SetEDCCAThreshold = 0x18721;
ROM_odm_SetTRxMux = 0x18749;
ROM_odm_SetCrystalCap = 0x18771;
ROM_odm_GetDefaultCrytaltalCap = 0x187d5;
ROM_ODM_CfoTrackingReset = 0x187e9;
ROM_odm_CfoTrackingFlow = 0x18811;
curve25519_donna = 0x1965d;
aes_test_alignment_detection = 0x1a391;
aes_mode_reset = 0x1a3ed;
aes_ecb_encrypt = 0x1a3f9;
aes_ecb_decrypt = 0x1a431;
aes_cbc_encrypt = 0x1a469;
aes_cbc_decrypt = 0x1a579;
aes_cfb_encrypt = 0x1a701;
aes_cfb_decrypt = 0x1a9e5;
aes_ofb_crypt = 0x1acc9;
aes_ctr_crypt = 0x1af7d;
aes_encrypt_key128 = 0x1b289;
aes_encrypt_key192 = 0x1b2a5;
aes_encrypt_key256 = 0x1b2c1;
aes_encrypt_key = 0x1b2e1;
aes_decrypt_key128 = 0x1b351;
aes_decrypt_key192 = 0x1b36d;
aes_decrypt_key256 = 0x1b389;
aes_decrypt_key = 0x1b3a9;
aes_init = 0x1b419;
CRYPTO_chacha_20 = 0x1b41d;
CRYPTO_poly1305_init = 0x1bc25;
CRYPTO_poly1305_update = 0x1bd09;
CRYPTO_poly1305_finish = 0x1bd8d;
rom_sha512_starts = 0x1ceb5;
rom_sha512_update = 0x1d009;
rom_sha512_finish = 0x1d011;
rom_sha512 = 0x1d261;
rom_sha512_hmac_starts = 0x1d299;
rom_sha512_hmac_update = 0x1d35d;
rom_sha512_hmac_finish = 0x1d365;
rom_sha512_hmac_reset = 0x1d3b5;
rom_sha512_hmac = 0x1d3d1;
rom_sha512_hkdf = 0x1d40d;
rom_ed25519_gen_keypair = 0x1d501;
rom_ed25519_gen_signature = 0x1d505;
rom_ed25519_verify_signature = 0x1d51d;
rom_ed25519_crypto_sign_seed_keypair = 0x1d521;
rom_ed25519_crypto_sign_detached = 0x1d579;
rom_ed25519_crypto_sign_verify_detached = 0x1d655;
rom_ed25519_ge_double_scalarmult_vartime = 0x1f86d;
rom_ed25519_ge_frombytes_negate_vartime = 0x1fc35;
rom_ed25519_ge_p3_tobytes = 0x207d5;
rom_ed25519_ge_scalarmult_base = 0x20821;
rom_ed25519_ge_tobytes = 0x209e1;
rom_ed25519_sc_muladd = 0x20a2d;
rom_ed25519_sc_reduce = 0x2603d;
__rtl_memchr_v1_00 = 0x28a4d;
__rtl_memcmp_v1_00 = 0x28ae1;
__rtl_memcpy_v1_00 = 0x28b49;
__aeabi_memcpy = 0x28b49;
__aeabi_memcpy4 = 0x28b49;
__rtl_memmove_v1_00 = 0x28bed;
__rtl_memset_v1_00 = 0x28cb5;
__aeabi_memset = 0x28cb5;
__rtl_strcat_v1_00 = 0x28d49;
__rtl_strchr_v1_00 = 0x28d91;
__rtl_strcmp_v1_00 = 0x28e55;
__rtl_strcpy_v1_00 = 0x28ec9;
__rtl_strlen_v1_00 = 0x28f15;
__rtl_strncat_v1_00 = 0x28f69;
__rtl_strncmp_v1_00 = 0x28fc5;
__rtl_strncpy_v1_00 = 0x2907d;
__rtl_strstr_v1_00 = 0x293cd;
__rtl_strsep_v1_00 = 0x2960d;
__rtl_strtok_v1_00 = 0x29619;
__rtl__strtok_r_v1_00 = 0x2962d;
__rtl_strtok_r_v1_00 = 0x29691;
__rtl_close_v1_00 = 0x29699;
__rtl_fstat_v1_00 = 0x296ad;
__rtl_isatty_v1_00 = 0x296c1;
__rtl_lseek_v1_00 = 0x296d5;
__rtl_open_v1_00 = 0x296e9;
__rtl_read_v1_00 = 0x296fd;
__rtl_write_v1_00 = 0x29711;
__rtl_sbrk_v1_00 = 0x29725;
__rtl_ltoa_v1_00 = 0x297bd;
__rtl_ultoa_v1_00 = 0x29855;
__rtl_dtoi_v1_00 = 0x298c5;
__rtl_dtoi64_v1_00 = 0x29945;
__rtl_dtoui_v1_00 = 0x299dd;
__rtl_ftol_v1_00 = 0x299e5;
__rtl_itof_v1_00 = 0x29a51;
__rtl_itod_v1_00 = 0x29ae9;
__rtl_i64tod_v1_00 = 0x29b79;
__rtl_uitod_v1_00 = 0x29c55;
__rtl_ftod_v1_00 = 0x29d2d;
__rtl_dtof_v1_00 = 0x29de9;
__rtl_uitof_v1_00 = 0x29e89;
__rtl_fadd_v1_00 = 0x29f65;
__rtl_fsub_v1_00 = 0x2a261;
__rtl_fmul_v1_00 = 0x2a559;
__rtl_fdiv_v1_00 = 0x2a695;
__rtl_dadd_v1_00 = 0x2a825;
__rtl_dsub_v1_00 = 0x2aed9;
__rtl_dmul_v1_00 = 0x2b555;
__rtl_ddiv_v1_00 = 0x2b8ad;
__rtl_dcmpeq_v1_00 = 0x2be4d;
__rtl_dcmplt_v1_00 = 0x2bebd;
__rtl_dcmpgt_v1_00 = 0x2bf51;
__rtl_dcmple_v1_00 = 0x2c049;
__rtl_fcmplt_v1_00 = 0x2c139;
__rtl_fcmpgt_v1_00 = 0x2c195;
__rtl_cos_f32_v1_00 = 0x2c229;
__rtl_sin_f32_v1_00 = 0x2c435;
__rtl_fabs_v1_00 = 0x2c639;
__rtl_fabsf_v1_00 = 0x2c641;
__rtl_dtoa_r_v1_00 = 0x2c77d;
__rom_mallocr_init_v1_00 = 0x2d7d1;
__rtl_free_r_v1_00 = 0x2d841;
__rtl_malloc_r_v1_00 = 0x2da31;
__rtl_realloc_r_v1_00 = 0x2df55;
__rtl_memalign_r_v1_00 = 0x2e331;
__rtl_valloc_r_v1_00 = 0x2e421;
__rtl_pvalloc_r_v1_00 = 0x2e42d;
__rtl_calloc_r_v1_00 = 0x2e441;
__rtl_cfree_r_v1_00 = 0x2e4a9;
__rtl_Balloc_v1_00 = 0x2e515;
__rtl_Bfree_v1_00 = 0x2e571;
__rtl_i2b_v1_00 = 0x2e585;
__rtl_multadd_v1_00 = 0x2e599;
__rtl_mult_v1_00 = 0x2e629;
__rtl_pow5mult_v1_00 = 0x2e769;
__rtl_hi0bits_v1_00 = 0x2e809;
__rtl_d2b_v1_00 = 0x2e845;
__rtl_lshift_v1_00 = 0x2e901;
__rtl_cmp_v1_00 = 0x2e9bd;
__rtl_diff_v1_00 = 0x2ea01;
__rtl_sread_v1_00 = 0x2eae9;
__rtl_seofread_v1_00 = 0x2eb39;
__rtl_swrite_v1_00 = 0x2eb3d;
__rtl_sseek_v1_00 = 0x2ebc1;
__rtl_sclose_v1_00 = 0x2ec11;
__rtl_sbrk_r_v1_00 = 0x2ec41;
__rtl_fflush_r_v1_00 = 0x2ef8d;
__rtl_vfprintf_r_v1_00 = 0x2f661;
__rtl_fpclassifyd = 0x30c15;
CpkClkTbl = 0x30c68;
ROM_IMG1_VALID_PATTEN = 0x30c80;
SpicCalibrationPattern = 0x30c88;
SpicInitCPUCLK = 0x30c98;
BAUDRATE = 0x30ca8;
OVSR = 0x30d1c;
DIV = 0x30d90;
OVSR_ADJ = 0x30e04;
__AES_rcon = 0x30e78;
__AES_Te4 = 0x30ea0;
I2CDmaChNo = 0x312a0;
_GPIO_PinMap_Chip2IP_8195a = 0x312b4;
_GPIO_PinMap_PullCtrl_8195a = 0x3136c;
_GPIO_SWPORT_DDR_TBL = 0x31594;
_GPIO_EXT_PORT_TBL = 0x31598;
_GPIO_SWPORT_DR_TBL = 0x3159c;
UartLogRomCmdTable = 0x316a0;
_HalRuartOp = 0x31700;
_HalGdmaOp = 0x31760;
RTW_WPA_OUI_TYPE = 0x3540c;
WPA_CIPHER_SUITE_NONE = 0x35410;
WPA_CIPHER_SUITE_WEP40 = 0x35414;
WPA_CIPHER_SUITE_TKIP = 0x35418;
WPA_CIPHER_SUITE_CCMP = 0x3541c;
WPA_CIPHER_SUITE_WEP104 = 0x35420;
RSN_CIPHER_SUITE_NONE = 0x35424;
RSN_CIPHER_SUITE_WEP40 = 0x35428;
RSN_CIPHER_SUITE_TKIP = 0x3542c;
RSN_CIPHER_SUITE_CCMP = 0x35430;
RSN_CIPHER_SUITE_WEP104 = 0x35434;
RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X = 0x35444;
RSN_AUTH_KEY_MGMT_UNSPEC_802_1X = 0x35448;
RSN_VERSION_BSD = 0x3544c;
rom_wps_Te0 = 0x35988;
rom_wps_rcons = 0x35d88;
rom_wps_Td4s = 0x35d94;
rom_wps_Td0 = 0x35e94;
str_rom_57ch3Dch0A = 0x3ed05; /* "========================================================\n" */
str_rom_0123456789ABCDEF = 0x3ec24; /* "0123456789ABCDEF" */
str_rom_hex_addr = 0x442D6; /* "[Addr] .0 .1 .2 .3 .4 .5 .6 .7 .8 .9 .A .B .C .D .E .F\r\n" */
str_rom_0123456789abcdef = 0x44660; /* "0123456789abcdef" */
__rom_b_cut_end__ = 0x4467c;
__rom_c_cut_text_start__ = 0x4467c;
HalInitPlatformLogUartV02 = 0x4467d;
HalReInitPlatformLogUartV02 = 0x4471d;
HalInitPlatformTimerV02 = 0x44755;
HalShowBuildInfoV02 = 0x447cd;
SpicReleaseDeepPowerDownFlashRtl8195A = 0x44831;
HalSpiInitV02 = 0x4488d;
HalBootFlowV02 = 0x44a29;
HalInitialROMCodeGlobalVarV02 = 0x44ae5;
HalResetVsrV02 = 0x44b41;
HalI2CSendRtl8195aV02 = 0x44ce1;
HalI2CSetCLKRtl8195aV02 = 0x44d59;
RtkI2CSendV02 = 0x4508d;
RtkI2CReceiveV02 = 0x459a1;
HalI2COpInitV02 = 0x461ed;
I2CISRHandleV02 = 0x463e9;
RtkSalI2COpInitV02 = 0x46be1;
SpicLoadInitParaFromClockRtl8195AV02 = 0x46c25;
SpiFlashAppV02 = 0x46c85;
SpicInitRtl8195AV02 = 0x46dc5;
SpicEraseFlashRtl8195AV02 = 0x46ea1;
HalTimerIrq2To7HandleV02 = 0x46f5d;
HalTimerIrqRegisterRtl8195aV02 = 0x46fe1;
HalTimerInitRtl8195aV02 = 0x4706d;
HalTimerReadCountRtl8195aV02 = 0x471b5;
HalTimerReLoadRtl8195aV02 = 0x471d1;
HalTimerIrqUnRegisterRtl8195aV02 = 0x4722d;
HalTimerDeInitRtl8195aV02 = 0x472c1;
HalTimerOpInitV02 = 0x472f9;
GPIO_LockV02 = 0x47345;
GPIO_UnLockV02 = 0x47379;
GPIO_Int_Clear_8195aV02 = 0x473a5;
HAL_GPIO_IntCtrl_8195aV02 = 0x473b5;
FindElementIndexV02 = 0x47541;
HalRuartInitRtl8195aV02 = 0x4756d;
DramInit_rom = 0x47619;
ChangeRandSeed_rom = 0x47979;
Sdr_Rand2_rom = 0x47985;
MemTest_rom = 0x479dd;
SdrCalibration_rom = 0x47a45;
SdrControllerInit_rom = 0x47d99;
SDIO_EnterCritical = 0x47e39;
SDIO_ExitCritical = 0x47e85;
SDIO_IRQ_Handler_Rom = 0x47ec5;
SDIO_Interrupt_Init_Rom = 0x47f31;
SDIO_Device_Init_Rom = 0x47f81;
SDIO_Interrupt_DeInit_Rom = 0x48215;
SDIO_Device_DeInit_Rom = 0x48255;
SDIO_Enable_Interrupt_Rom = 0x48281;
SDIO_Disable_Interrupt_Rom = 0x482a1;
SDIO_Clear_ISR_Rom = 0x482c1;
SDIO_Alloc_Rx_Pkt_Rom = 0x482d9;
SDIO_Free_Rx_Pkt_Rom = 0x48331;
SDIO_Recycle_Rx_BD_Rom = 0x48355;
SDIO_RX_IRQ_Handler_BH_Rom = 0x484f1;
SDIO_RxTask_Rom = 0x4851d;
SDIO_Process_H2C_IOMsg_Rom = 0x4856d;
SDIO_Send_C2H_IOMsg_Rom = 0x4859d;
SDIO_Process_RPWM_Rom = 0x485b5;
SDIO_Reset_Cmd_Rom = 0x485e9;
SDIO_Rx_Data_Transaction_Rom = 0x48611;
SDIO_Send_C2H_PktMsg_Rom = 0x48829;
SDIO_Register_Tx_Callback_Rom = 0x488f5;
SDIO_ReadMem_Rom = 0x488fd;
SDIO_WriteMem_Rom = 0x489a9;
SDIO_SetMem_Rom = 0x48a69;
SDIO_TX_Pkt_Handle_Rom = 0x48b29;
SDIO_TX_FIFO_DataReady_Rom = 0x48c69;
SDIO_IRQ_Handler_BH_Rom = 0x48d95;
SDIO_TxTask_Rom = 0x48e9d;
SDIO_TaskUp_Rom = 0x48eed;
SDIO_Boot_Up = 0x48f55;
__rom_c_cut_text_end__ = 0x49070;
__rom_c_cut_rodata_start__ = 0x49070;
BAUDRATE_v02 = 0x49070;
OVSR_v02 = 0x490fc;
DIV_v02 = 0x49188;
OVSR_ADJ_v02 = 0x49214;
SdrDramInfo_rom = 0x492a0; /* DRAM_DEVICE_INFO *DramInfo */
SdrDramTiming_rom = 0x492b4;
SdrDramModeReg_rom = 0x492e8;
SdrDramDev_rom = 0x49304;
__rom_c_cut_rodata_end__ = 0x49314;
/* RAM data used in ROM */
__ram_image_start__ = 0x10000000;
__rom_bss_start__ = 0x10000300;
__ram_start_table_start__ = 0x10000bc8;
__rom_bss_end__ = 0x10000bc8;
/* BOOT-LOADER */
gRamStartFun = 0x10000bc8; /* HalResetVsrV02(), HalResetVsr() */
gRamPatchWAKE = 0x10000bcc; /* HalResetVsrV02(), HalResetVsr() */
gRamPatchFun0 = 0x10000bd0; /* HalResetVsrV02(), HalResetVsr() */
gRamPatchFun1 = 0x10000bd4; /* HalResetVsrV02(), HalResetVsr() */
gRamPatchFun2 = 0x10000bd8; /* HalResetVsrV02(), HalResetVsr() */
__image1_validate_code__ = 0x10000bdc; /* 8 bytes HalResetVsrV02(), HalResetVsr() */
/* __ram_image_end__ = 0x10002100; */
/* End RAM data used in ROM */
/* 1006D000..1006F998: data SDIO_Device_Init_Rom(), SDIO_Boot_Up(), SDIO_TX_Pkt_Handle_Rom(),.. */
}

View file

@ -0,0 +1,19 @@
set libname=lib_platform
del %libname%_new.a
md %libname%.lib
cd %libname%.lib
PATH=D:\MCU\GNU_Tools_ARM_Embedded\5.2_2015q4\bin;%PATH%
arm-none-eabi-ar.exe x ..\%libname%.a
del hal_efuse.o
del hal_common.o
del freertos_pmu_8195a.o
del hal_soc_ps_monitor.o
del app_start.o
del hal_log_uart.o
del hal_pinmux.o
del hal_misc.o
del startup.o
rem del hal_spi_flash_ram.o
arm-none-eabi-ar.exe ru ..\%libname%_new.a *.o
cd ..
rem rd /q /s %libname%.lib

View file

@ -0,0 +1,256 @@
ENTRY(Reset_Handler)
ENTRY(main)
INCLUDE "export-rom_v04.txt"
MEMORY
{
ROM (rx) : ORIGIN = 0x000000, LENGTH = 1M /* end 0x00100000 */
ROM_USED_RAM (rwx): ORIGIN = 0x10000000, LENGTH = 0x2400 /* end 0x10002400 */
BOOT_RAM (rwx) : ORIGIN = 0x10000bc8, LENGTH = 21560 /* end 0x10006000 */
ROM_HEAP (rwx) : ORIGIN = 0x10002400, LENGTH = 3K /* end 0x10003000 */
RAM_HEAP1 (rwx) : ORIGIN = 0x10003000, LENGTH = 12K /* end 0x10006000 */
BD_RAM (rwx) : ORIGIN = 0x10006000, LENGTH = 424K /* end 0x10070000 */
TCM (rwx) : ORIGIN = 0x1FFF0000, LENGTH = 64K /* end 0x20000000 */
TCM_TAB (rwx) : ORIGIN = 0x1FFFFD00, LENGTH = 768 /* end 0x20000000 */
SDRAM_RAM (rwx) : ORIGIN = 0x30000000, LENGTH = 2M /* end 0x30200000 */
}
EXTERN(RAM_IMG2_VALID_PATTEN)
EXTERN(InfraStart)
SECTIONS
{
/* 0x00000000: ROM */
.rom :
{
__rom_image_start__ = .;
KEEP(*(.rom));
__rom_image_end__ = .;
} > ROM
/* 0x10000000: SRAM */
.rom_ram : /* use in rom */
{
__ram_image_start__ = .;
KEEP(*(.ram_dedecated_vector_table)) /* 0x10000000: NewVectorTable */
KEEP(*(.ram_user_define_irq_table)) /* 0x10000100: UserIrqFunTable */
KEEP(*(.ram_user_define_data_table)) /* 0x10000200: UserIrqDataTable */
__rom_bss_start__ = .;
KEEP(*(.hal.ram.bss)) /* 0x10000300: CfgSysDebugWarn .. _pHAL_Gpio_Adapter */
KEEP(*(.timer2_7_vector_table.data)) /* 0x10000358: Timer2To7VectorTable */
KEEP(*(.infra.ram.bss)) /* 0x10000370: first .. z4 */
KEEP(*(.mon.ram.bss)) /* 0x10000384: pUartLogCtl .. ArgvArray */
KEEP(*(.wlan_ram_map)) /* 0x100006d4: rom_wlan_ram_map, FalseAlmCnt, ROMInfo, DM_CfoTrack */
KEEP(*(.ram.rom.wlanmap)) /* align(8) */
KEEP(*(.libc.ram.bss)) /* 0x10000760: rom_libgloss_ram_map __rtl_malloc_av_ __rtl_errno */
__rom_bss_end__ = .;
} > ROM_USED_RAM
/* 0x10000bc8: bootloader */
.ram_image1.text . : /* use in rom & boot */
{
/* __ram_start_table_start__ = .; */
__ram_image1_text_start__ = .;
KEEP(*(.boot.start.ram.data*))
/* __image1_validate_code__ = .; */
KEEP(*(.image1.validate.rodata))
KEEP(*(.infra.ram.data*))
KEEP(*(.timer.ram.data*))
KEEP(*(.cutb.ram.data*))
KEEP(*(.cutc.ram.data*))
KEEP(*(.libc.reent))
KEEP(*(.rom.unc.data))
KEEP(*(.sdr.rand2.data))
PROVIDE (__ram_image_end__ = .); /* 0x100020c0: end */
/* boot & images data */
KEEP(*(.hal.ram.data))
KEEP(*(.hal.flash.data))
KEEP(*(.boot.rodata*))
KEEP(*(.boot.text*))
KEEP(*(.boot.data*))
__image1_bss_start__ = .;
KEEP(*(.boot.bss*))
__image1_bss_end__ = .;
__ram_image1_text_end__ = .;
} > BOOT_RAM
.romheap :
{
__rom_heap_start__ = .;
end = __rom_heap_start__;
. = ALIGN(0x1000);
__rom_heap_end__ = .;
} > ROM_HEAP
.ram_heap1 :
{
__ram_heap1_start__ = .;
/* *(.heap1*) */
} > RAM_HEAP1
.tcm :
{
__ram_tcm_start__ = .;
__tcm_heap_start__ = .;
*(.tcm.heap)
} > TCM
.soc_ps_monitor :
{
__tcm_heap_end__ = .;
} > TCM_TAB
.image2.start.table :
{
__ram_heap1_end__ = .;
__ram_image2_text_start__ = .;
__image2_entry_func__ = .;
.image2.start.table1$$Base = .;
KEEP(*(SORT(.image2.ram.data*)))
__image2_validate_code__ = .;
KEEP(*(.image2.validate.rodata*))
KEEP(*(.custom.validate.rodata*))
} > BD_RAM
.ram_image2.text :
{
*(.infra.ram.start*)
. = ALIGN(4);
KEEP(*(.init))
/* init data */
. = ALIGN(4);
PROVIDE (__init_array_start = .);
KEEP(*(SORT(.init_array.*)))
KEEP(*(.init_array))
PROVIDE (__init_array_end = .);
. = ALIGN(4);
KEEP(*(.fini))
. = ALIGN(4);
PROVIDE (__fini_array_start = .);
KEEP(*(SORT(.fini_array.*)))
KEEP(*(.fini_array))
PROVIDE (__fini_array_end = .);
*(.mon.ram.text*)
*(.hal.flash.text*)
*(.hal.sdrc.text*)
*(.hal.gpio.text*)
*(.fwu.text*)
*(.otg.rom.text*)
*(.text*)
*(.sdram.text*)
*(.p2p.text*)
*(.wps.text*)
*(.websocket.text*)
} > BD_RAM
.ram_image2.rodata :
{
*(.rodata*)
*(.fwu.rodata*)
*(.sdram.rodata*)
*(.p2p.rodata*)
*(.wps.rodata*)
*(.websocket.rodata*)
. = ALIGN(4);
xHeapRegions = .;
LONG(__ram_heap1_start__)
LONG(__ram_heap1_end__ - __ram_heap1_start__)
LONG(__ram_heap2_start__)
LONG(__ram_heap2_end__ - __ram_heap2_start__)
LONG(__sdram_heap_start__)
LONG(__sdram_heap_end__ - __sdram_heap_start__)
LONG(0)
LONG(0)
UartLogRamCmdTable = .;
KEEP(*(SORT(.mon.tab*)))
UartLogRamCmdTable_end = .;
LONG(0)
} > BD_RAM
PROVIDE(UartLogRamCmdTableSize = UartLogRamCmdTable_end - UartLogRamCmdTable);
.ram.data :
{
__data_start__ = .;
*(.data*)
*(.p2p.data*)
*(.wps.data*)
*(.websocket.data*)
*(.sdram.data*)
__data_end__ = .;
__ram_image2_text_end__ = .;
} > BD_RAM
.ram.bss :
{
__bss_start__ = .;
.ram.bss$$Base = .;
*(.hal.flash.data*)
*(.hal.sdrc.data*)
*(.hal.gpio.data*)
*(.fwu.data*)
*(.bdsram.data*)
*(.bfsram.data*)
*(COMMON)
*(.bss*)
*(.sdram.bss*)
*(.p2p.bss*)
*(.wps.bss*)
*(.websocket.bss*)
*(.ssl_ram_map*)
__bss_end__ = .;
.ram.bss$$Limit = .;
} > BD_RAM
.ram_heap2 :
{
. = ALIGN(8);
__ram_heap2_start__ = .;
*(.heap*) /* ucHeap */
} > BD_RAM
__ram_heap2_end__ = 0x10070000;
.sdr_text :
{
__sdram_data_start__ = .;
} > SDRAM_RAM
.sdr_rodata :
{
} > SDRAM_RAM
.sdr_data :
{
__sdram_data_end__ = .;
} > SDRAM_RAM
.sdr_bss :
{
__sdram_bss_start__ = .;
__sdram_bss_end__ = .;
. = ALIGN(8);
__sdram_heap_start__ = .;
} > SDRAM_RAM
__sdram_heap_end__ = 0x30200000;
.boot.head :
{
KEEP(*(.loader.head*))
}
ASSERT(__ram_image_end__ == 0x100020c0, "Error rom-bios-boot code & data!")
}

View file

@ -0,0 +1,240 @@
ENTRY(Reset_Handler)
INCLUDE "export-rom_v04.txt"
MEMORY
{
ROM (rx) : ORIGIN = 0x000000, LENGTH = 1M
ROM_RAM1 (rwx): ORIGIN = 0x10000000, LENGTH = 0x2100 /* end 0x10002100 */
BOOT_RAM (rwx): ORIGIN = 0x10000bc8, LENGTH = 13368 /* end 0x10006000 */
RECY_RAM (rwx): ORIGIN = 0x10002100, LENGTH = 0x3F00 /* end 0x10006000 */
BD_RAM (rwx) : ORIGIN = 0x10006000, LENGTH = 424K /* end 0x10070000 */
ROM_RAM3 (rwx): ORIGIN = 0x1006D000, LENGTH = 12K /* end 0x10070000 */
TCM (rwx) : ORIGIN = 0x1FFF0000, LENGTH = 64K /* end 0x20000000 */
SDRAM (rwx) : ORIGIN = 0x30000000, LENGTH = 2M /* end 0x30200000 */
}
EXTERN(PreProcessForVendor)
EXTERN(RtlBootToSram)
EXTERN(_rtl_impure_ptr)
EXTERN(impure_data)
SECTIONS
{
/* 0x00000000: ROM */
.rom :
{
__rom_image_start__ = .;
KEEP(*(.rom));
__rom_image_end__ = .;
} > ROM
/* 0x10000000: SRAM */
.rom_ram : /* use in rom */
{
__ram_image_start__ = .;
KEEP(*(.ram_dedecated_vector_table)) /* 0x10000000: NewVectorTable */
KEEP(*(.ram_user_define_irq_table)) /* 0x10000100: UserIrqFunTable */
KEEP(*(.ram_user_define_data_table)) /* 0x10000200: UserIrqDataTable */
/* __rom_bss_start__ = .; */
KEEP(*(.hal.ram.bss)) /* 0x10000300: CfgSysDebugWarn .. _pHAL_Gpio_Adapter */
KEEP(*(.timer2_7_vector_table.data)) /* 0x10000358: Timer2To7VectorTable */
KEEP(*(.infra.ram.bss)) /* 0x10000370: first .. z4 */
KEEP(*(.mon.ram.bss)) /* 0x10000384: pUartLogCtl .. ArgvArray */
KEEP(*(.wlan_ram_map)) /* 0x100006d4: rom_wlan_ram_map, FalseAlmCnt, ROMInfo, DM_CfoTrack */
KEEP(*(.ram.rom.wlanmap)) /* align(8) */
KEEP(*(.libc.ram.bss)) /* 0x10000760: rom_libgloss_ram_map __rtl_malloc_av_ __rtl_errno */
/* __rom_bss_end__ = .; */
} > ROM_RAM1
/* 0x10000bc8: bootloader */
.ram_image1.text . : /* use in rom & boot */
{
/* __ram_start_table_start__ = .; */
__ram_image1_text_start__ = .;
KEEP(*(SORT(.start.ram.data*)))
/* __image1_validate_code__ = .; */
KEEP(*(.image1.validate.rodata))
KEEP(*(.infra.ram.data*))
KEEP(*(.timer.ram.data*))
KEEP(*(.cutb.ram.data*))
KEEP(*(.cutc.ram.data*))
KEEP(*(.data));
KEEP(*(.hal.ram.data))
KEEP(*(.libc.reent))
KEEP(*(.rom.unc.data))
KEEP(*(.sdr.rand2.data))
build/obj/project/src/user/rtl_bios_data.o (.rodata*)
__ram_image_end__ = .;
/* 0x100020c0: end */
build/obj/project/src/user/rtl_boot.o (.text* .rodata*)
__image1_bss_start__ = .;
__image1_bss_end__ = .;
__ram_image1_text_end__ = .;
} > BOOT_RAM
.tcm :
{
__tcm_start__ = .;
*(.tcm.heap)
__tcm_end__ = .;
} > TCM
.image2.start.table :
{
__ram_image2_text_start__ = .;
__image2_entry_func__ = .;
.image2.start.table1$$Base = .;
KEEP(*(SORT(.image2.ram.data*)))
__image2_validate_code__ = .;
KEEP(*(.image2.validate.rodata*))
KEEP(*(.custom.validate.rodata*))
} > BD_RAM
.ram_image2.text :
{
*(.infra.ram.start*)
*(.mon.ram.text*)
*(.hal.flash.text*)
*(.hal.sdrc.text*)
*(.hal.gpio.text*)
*(.fwu.text*)
*(.text*)
*(.sdram.text*)
*(.p2p.text*)
*(.wps.text*)
*(.websocket.text*)
} > BD_RAM
.ram_image2.rodata :
{
*(.rodata*)
*(.fwu.rodata*)
*(.sdram.rodata*)
*(.p2p.rodata*)
*(.wps.rodata*)
*(.websocket.rodata*)
} > BD_RAM
.ram.data :
{
__data_start__ = .;
*(.data*)
*(.sdram.data*)
*(.p2p.data*)
*(.wps.data*)
*(.websocket.data*)
__data_end__ = .;
__ram_image2_text_end__ = .;
} > BD_RAM
.ram.bss :
{
__bss_start__ = .;
.ram.bss$$Base = .;
*(.hal.flash.data*)
*(.hal.sdrc.data*)
*(.hal.gpio.data*)
*(.fwu.data*)
*(.bss*)
*(COMMON)
*(.bdsram.data*)
*(.sdram.bss*)
*(.p2p.bss*)
*(.wps.bss*)
*(.websocket.bss*)
__bss_end__ = .;
.ram.bss$$Limit = .;
} > BD_RAM
.bf_data :
{
__buffer_data_start__ = .;
*(.bfsram.data*)
__buffer_data_end__ = .;
} > BD_RAM
.bf_data2 :
{
__buffer_data_start2__ = .;
__buffer_data_end2__ = .;
} > RECY_RAM
.sdr_text :
{
__sdram_data_start__ = .;
} > SDRAM
.sdr_rodata :
{
} > SDRAM
.sdr_data :
{
__sdram_data_end__ = .;
} > SDRAM
.sdr_bss :
{
__sdram_bss_start__ = .;
__sdram_bss_end__ = .;
} > SDRAM
.heap :
{
__end__ = .;
end = __end__;
*(.heap*)
__HeapLimit = .;
} > BD_RAM
/* .stack_dummy section doesn't contains any symbols. It is only
* used for linker to calculate size of stack sections, and assign
* values to stack symbols later */
.stack_dummy :
{
*(.stack)
} > BD_RAM
/* Set stack top to end of RAM, and stack limit move down by
* size of stack_dummy section */
__StackTop = ORIGIN(BD_RAM) + LENGTH(BD_RAM);
__StackLimit = __StackTop - SIZEOF(.stack_dummy);
PROVIDE(__stack = __StackTop);
/* Check if data + heap + stack exceeds RAM limit */
ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack")
.boot.head :
{
KEEP(*(.loader.head*))
}
.image1.head :
{
KEEP(*(SORT(.image1.head*)))
}
.image2.head :
{
KEEP(*(SORT(.image2.head*)))
}
.image3.head :
{
KEEP(*(SORT(.image3.head*)))
}
.image4.head :
{
KEEP(*(SORT(.image4.head*)))
}
}

View file

@ -0,0 +1,247 @@
/******************************************************************************
*
* Copyright(c) 2007 - 2016 Realtek Corporation. All rights reserved.
*
*
******************************************************************************/
#include <platform_opts.h>
#include "FreeRTOS.h"
#include "task.h"
#include <platform/platform_stdlib.h>
#include "semphr.h"
#include "device.h"
#include "serial_api.h"
#include "at_cmd/log_service.h"
#include "osdep_service.h"
#include "serial_ex_api.h"
#include "pinmap.h"
char hs_uart_ready = 0; // used to switch between loguart and high speed uart
// 0: loguart
// 1: highspeed uart
// select uart tx/rx pin with gpio interrupt function
#define UART_TX PA_7
#define UART_RX PA_6
#define KEY_NL 0xa // '\n'
#define KEY_ENTER 0xd // '\r'
#define KEY_BS 0x8
#define KEY_ESC 0x1B
#define KEY_LBRKT 0x5B
#define STR_END_OF_MP_FORMAT "\r\n\r\r#"
#define CMD_HISTORY_LEN 4 // max number of executed command saved
extern char log_buf[LOG_SERVICE_BUFLEN];
extern xSemaphoreHandle log_rx_interrupt_sema;
char cmd_history[CMD_HISTORY_LEN][LOG_SERVICE_BUFLEN];
static unsigned int cmd_history_count = 0;
serial_t loguart_sobj;
//_sema at_printf_sema;
_sema hs_uart_dma_tx_sema;
#define HS_UART_USE_DMA_TX 1
void hs_uart_put_char(u8 c){
serial_putc(&loguart_sobj, c);
}
void hs_uart_send_string(char *str)
{
unsigned int i=0;
while (str[i] != '\0') {
serial_putc(&loguart_sobj, str[i]);
i++;
}
}
#if UART_AT_USE_DMA_TX
static void hs_uart_send_buf_done(uint32_t id)
{
//serial_t *sobj = (serial_t *)id;
rtw_up_sema_from_isr(&uart_at_dma_tx_sema);
}
#endif
void hs_uart_send_buf(u8 *buf, u32 len)
{
unsigned char *st_p=buf;
if(!len || (!buf)){
return;
}
#if UART_AT_USE_DMA_TX
int ret;
while(rtw_down_sema(&uart_at_dma_tx_sema) == _TRUE){
ret = serial_send_stream_dma(&loguart_sobj, st_p, len);
if(ret != HAL_OK){
rtw_up_sema(&uart_at_dma_tx_sema);
return;
}else{
return;
}
}
#else
while(len){
serial_putc(&loguart_sobj, *st_p);
st_p++;
len--;
}
#endif
}
void hs_uart_irq(uint32_t id, SerialIrq event)
{
serial_t *sobj = (serial_t *)id;
unsigned char rc=0;
static unsigned char temp_buf[LOG_SERVICE_BUFLEN] = "\0";
static unsigned char combo_key = 0;
static unsigned short buf_count = 0;
static unsigned char key_enter = 0;
static char cmd_history_index = 0;
if(event == RxIrq) {
rc = serial_getc(sobj);
if(key_enter && rc == KEY_NL){
//serial_putc(sobj, rc);
return;
}
if(rc == KEY_ESC){
combo_key = 1;
}else if(combo_key == 1){
if(rc == KEY_LBRKT)
combo_key = 2;
else
combo_key = 0;
}else if(combo_key == 2){
if(rc == 'A' || rc == 'B'){ // UP or Down
if(rc == 'A'){
cmd_history_index--;
if(cmd_history_index < 0)
cmd_history_index = (cmd_history_count>CMD_HISTORY_LEN)?CMD_HISTORY_LEN-1:(cmd_history_count-1)%CMD_HISTORY_LEN;
}else{
cmd_history_index++;
if(cmd_history_index > (cmd_history_count>CMD_HISTORY_LEN?CMD_HISTORY_LEN-1:(cmd_history_count-1)%CMD_HISTORY_LEN))
cmd_history_index = 0;
}
if(cmd_history_count > 0){
buf_count = strlen(temp_buf);
rtw_memset(temp_buf,'\0',buf_count);
while(--buf_count >= 0){
serial_putc(sobj, KEY_BS);
serial_putc(sobj, ' ');
serial_putc(sobj, KEY_BS);
}
hs_uart_send_string(cmd_history[cmd_history_index%CMD_HISTORY_LEN]);
strcpy(temp_buf, cmd_history[cmd_history_index%CMD_HISTORY_LEN]);
buf_count = strlen(temp_buf);
}
}
// exit combo
combo_key = 0;
}
else if(rc == KEY_ENTER){
key_enter = 1;
if(buf_count>0){
serial_putc(sobj, KEY_NL);
serial_putc(sobj, KEY_ENTER);
rtw_memset(log_buf,'\0',LOG_SERVICE_BUFLEN);
strncpy(log_buf,(char *)&temp_buf[0],buf_count);
rtw_up_sema_from_isr(&log_rx_interrupt_sema);
rtw_memset(temp_buf,'\0',buf_count);
/* save command */
rtw_memset(cmd_history[((cmd_history_count)%CMD_HISTORY_LEN)], '\0', buf_count+1);
strcpy(cmd_history[((cmd_history_count++)%CMD_HISTORY_LEN)], log_buf);
cmd_history_index = cmd_history_count%CMD_HISTORY_LEN;
//cmd_history_count++;
buf_count=0;
}else{
hs_uart_send_string(STR_END_OF_MP_FORMAT);
}
}
else if(rc == KEY_BS){
if(buf_count>0){
buf_count--;
temp_buf[buf_count] = '\0';
serial_putc(sobj, rc);
serial_putc(sobj, ' ');
serial_putc(sobj, rc);
}
}
else{
/* cache input characters */
if(buf_count < (LOG_SERVICE_BUFLEN - 1)){
temp_buf[buf_count] = rc;
buf_count++;
serial_putc(sobj, rc);
key_enter = 0;
}
else if(buf_count == (LOG_SERVICE_BUFLEN - 1)){
temp_buf[buf_count] = '\0';
hs_uart_send_string("\r\nERROR:exceed size limit"STR_END_OF_ATCMD_RET);
}
}
}
}
void console_init_hs_uart(void)
{
serial_init(&loguart_sobj,UART_TX,UART_RX);
serial_baud(&loguart_sobj,38400);
serial_format(&loguart_sobj, 8, ParityNone, 1);
#if UART_AT_USE_DMA_TX
rtw_init_sema(&hs_uart_dma_tx_sema, 1);
serial_send_comp_handler(&loguart_sobj, (void*)hs_uart_send_buf_done, (uint32_t)&loguart_sobj);
#endif
serial_irq_handler(&loguart_sobj, hs_uart_irq, (uint32_t)&loguart_sobj);
serial_irq_set(&loguart_sobj, RxIrq, 1);
for(char i=0; i<CMD_HISTORY_LEN; i++)
memset(cmd_history[i], '\0', LOG_SERVICE_BUFLEN);
/* indicate low level layer that hs uart is ready */
hs_uart_ready = 1;
}
int use_mode;
VOID HalSerialPutcRtl8195a(
IN u8 c
)
{
extern char hs_uart_ready;
extern void hs_uart_put_char(u8 c);
if(hs_uart_ready)
hs_uart_put_char(c);
}
void console_init(void)
{
sys_log_uart_off();
console_init_hs_uart();
#if !TASK_SCHEDULER_DISABLED
RtlConsolInitRam((u32)RAM_STAGE,(u32)0,(VOID*)NULL);
#else
RtlConsolInitRam((u32)ROM_STAGE,(u32)0,(VOID*)NULL);
#endif
#if BUFFERED_PRINTF
rtl_printf_init();
#endif
}

View file

@ -0,0 +1,166 @@
#include <platform_opts.h>
#include "serial_api.h"
#include "serial_ex_api.h"
#include "PinNames.h"
#include "i2c_api.h"
#include "pinmap.h"
#include "ex_api.h"
#define MBED_I2C_MTR_SDA PB_3 //i2c3
#define MBED_I2C_MTR_SCL PB_2
#define UART_BAUDRATE 115200
#define MBED_I2C_SLAVE_ADDR0 0x4D // 0x9A //
#define MBED_I2C_BUS_CLK 500000 //hz *Remind that in baud rate 9600 or 19200, 100000hz is suitable*
static i2c_t i2cmaster;
#define I2C_DATA_LENGTH 2
static char i2cdatardsrc[I2C_DATA_LENGTH];
static char i2cdatarddst[I2C_DATA_LENGTH];
const u8 DLL = 921600/UART_BAUDRATE;
char ctrl_initial_1[2] = {0x03 << 3,0x80};
char ctrl_initial_2[2] = {0x00 << 3,921600/UART_BAUDRATE};
char ctrl_initial_3[2] = {0x01 << 3,0x00};
char ctrl_initial_4[2] = {0x03 << 3,0xbf};
char ctrl_initial_5[2] = {0x02 << 3,0x10};
char ctrl_initial_6[2] = {0x03 << 3,0x03};
char ctrl_initial_7[2] = {0x02 << 3,0x06};
char ctrl_initial_8[2] = {0x02 << 3,0x01};
//end i2c
// Master// Tx
#define CLEAR_MST_TXC_FLAG (masterTXC = 0)
#define SET_MST_TXC_FLAG (masterTXC = 1)
#define WAIT_MST_TXC while(masterTXC == 0){;}
volatile int masterTXC;
static char i2c_ready = 0;
static void i2c_master_rxc_callback(void *userdata)
{
int i2clocalcnt;
int result = 0;
// verify result
result = 1;
for (i2clocalcnt = 0; i2clocalcnt < I2C_DATA_LENGTH; i2clocalcnt++) {
if (i2cdatarddst[i2clocalcnt] != i2cdatardsrc[i2clocalcnt]) {
result = 0;
break;
}
}
}
static void i2c_master_txc_callback(void *userdata)
{
SET_MST_TXC_FLAG;
}
static void i2c_master_write(void)
{
//DBG_8195A("Mst-W\n");
CLEAR_MST_TXC_FLAG;
i2c_write(&i2cmaster, MBED_I2C_SLAVE_ADDR0, &ctrl_initial_1[0], 2, 1);
i2c_write(&i2cmaster, MBED_I2C_SLAVE_ADDR0, &ctrl_initial_2[0], 2, 1);
i2c_write(&i2cmaster, MBED_I2C_SLAVE_ADDR0, &ctrl_initial_3[0], 2, 1);
i2c_write(&i2cmaster, MBED_I2C_SLAVE_ADDR0, &ctrl_initial_4[0], 2, 1);
i2c_write(&i2cmaster, MBED_I2C_SLAVE_ADDR0, &ctrl_initial_5[0], 2, 1);
i2c_write(&i2cmaster, MBED_I2C_SLAVE_ADDR0, &ctrl_initial_6[0], 2, 1);
i2c_write(&i2cmaster, MBED_I2C_SLAVE_ADDR0, &ctrl_initial_7[0], 2, 1);
i2c_write(&i2cmaster, MBED_I2C_SLAVE_ADDR0, &ctrl_initial_8[0], 2, 1);
WAIT_MST_TXC;
}
static void i2c_master_enable(void)
{
_memset(&i2cmaster, 0x00, sizeof(i2c_t));
i2c_init(&i2cmaster, MBED_I2C_MTR_SDA ,MBED_I2C_MTR_SCL);
i2c_frequency(&i2cmaster,MBED_I2C_BUS_CLK);
i2c_set_user_callback(&i2cmaster, I2C_RX_COMPLETE, i2c_master_rxc_callback);
i2c_set_user_callback(&i2cmaster, I2C_TX_COMPLETE, i2c_master_txc_callback);
//i2c_set_user_callback(&i2cmaster, I2C_ERR_OCCURRED, i2c_master_err_callback);
}
void i2c_redirect_init(void)
{
// prepare for transmission
_memset(&i2cdatardsrc[0], 0x00, I2C_DATA_LENGTH);
_memset(&i2cdatarddst[0], 0x00, I2C_DATA_LENGTH);
i2c_ready = 1;
i2c_master_enable();
i2c_master_write();
}
static u8 tx_data_i2c[2];
static u8 rx_data_i2c[2];
void i2c_put_char(u8 c){
_memset(&tx_data_i2c[0],0x00,2);
_memset(&rx_data_i2c[0],0x00,2);
tx_data_i2c[0] = 0x00 << 3;
tx_data_i2c[1] = c;
i2c_write(&i2cmaster, 0x4D, &tx_data_i2c[0], 2, 1);
i2c_read (&i2cmaster, 0x4D, &rx_data_i2c[0], 2, 1);
}
int use_mode;
void console_init(void)
{
i2c_redirect_init();
if(HalCheckSDramExist()){
//DiagPrintf("It's 8195_AM\n");
redirect_rom_init();
}
#if !TASK_SCHEDULER_DISABLED
RtlConsolInitRam((u32)RAM_STAGE,(u32)0,(VOID*)NULL);
#else
RtlConsolInitRam((u32)ROM_STAGE,(u32)0,(VOID*)NULL);
#endif
#if BUFFERED_PRINTF
rtl_printf_init();
#endif
}
VOID HalSerialPutcRtl8195a(IN u8 c){
u32 CounterIndex = 0;
extern char i2c_ready;
if(i2c_ready)
i2c_put_char(c);
}

View file

@ -0,0 +1,119 @@
#include <stdio.h>
#include "hal_api.h"
#include "rtl8195a.h"
#include "platform_opts.h"
#if !defined (__ICCARM__)
extern u8 RAM_IMG1_VALID_PATTEN[];
void *tmp = RAM_IMG1_VALID_PATTEN;
#endif
//for internal test
#ifdef USE_MODE
extern int use_mode;
void mode_init(void){use_mode = 1;}
#endif
#if defined ( __ICCARM__ )
size_t __write(int Handle, const unsigned char * Buf, size_t Bufsize)
{
int nChars = 0;
/* Check for stdout and stderr
(only necessary if file descriptors are enabled.) */
if (Handle != 1 && Handle != 2)
{
return -1;
}
for (/*Empty */; Bufsize > 0; --Bufsize)
{
DiagPutChar(*Buf++);
++nChars;
}
return nChars;
}
size_t __read(int Handle, unsigned char * Buf, size_t Bufsize)
{
int nChars = 0;
/* Check for stdin
(only necessary if FILE descriptors are enabled) */
if (Handle != 0)
{
return -1;
}
for (/*Empty*/; Bufsize > 0; --Bufsize)
{
int c = DiagGetChar(_FALSE);
if (c < 0)
break;
*(Buf++) = c;
++nChars;
}
return nChars;
}
#endif
int disablePrintf = FALSE;
__weak VOID HalSerialPutcRtl8195a(IN u8 c){
u32 CounterIndex = 0;
if(disablePrintf == TRUE) return;
while(1) {
CounterIndex++;
if (CounterIndex >=6540)
break;
if (HAL_UART_READ8(UART_LINE_STATUS_REG_OFF) & 0x60)
break;
}
HAL_UART_WRITE8(UART_TRAN_HOLD_OFF, c);
if (c == 0x0a) {
HAL_UART_WRITE8(UART_TRAN_HOLD_OFF, 0x0d);
}
}
#include <diag.h>
u32
DiagPrintf(
IN const char *fmt, ...
)
{
if(disablePrintf == TRUE) return _TRUE;
(void)VSprintf(0, fmt, ((const int *)&fmt)+1);
return _TRUE;
}
extern u32 ConfigDebugErr;
extern u32 ConfigDebugInfo;
extern u32 ConfigDebugWarn;
static u32 backupErr;
static u32 backupInfo;
static u32 backupWarn;
void log_uart_enable_printf(void)
{
disablePrintf = FALSE;
ConfigDebugErr = backupErr;
ConfigDebugInfo = backupInfo;
ConfigDebugWarn = backupWarn;
}
void log_uart_disable_printf(void)
{
disablePrintf = TRUE;
backupErr = ConfigDebugErr;
backupInfo = ConfigDebugInfo;
backupWarn = ConfigDebugWarn;
ConfigDebugErr = 0;
ConfigDebugInfo = 0;
ConfigDebugWarn = 0;
}

View file

@ -0,0 +1,487 @@
/*
* Routines to access hardware
*
* Copyright (c) 2013 Realtek Semiconductor Corp.
*
* This module is a confidential and proprietary property of RealTek and
* possession or use of this module requires written permission of RealTek.
*/
#include "rtl8195a.h"
//#include <stdarg.h>
#include "rtl_consol.h"
#include "FreeRTOS.h"
#include "task.h"
#include <event_groups.h>
#include "semphr.h"
#if defined(configUSE_WAKELOCK_PMU) && (configUSE_WAKELOCK_PMU == 1)
#include "freertos_pmu.h"
#endif
#include "tcm_heap.h"
// Those symbols will be defined in linker script for gcc compiler
// If not doing this would cause extra memory cost
#if defined (__GNUC__)
extern volatile UART_LOG_CTL UartLogCtl;
extern volatile UART_LOG_CTL *pUartLogCtl;
extern u8 *ArgvArray[MAX_ARGV];
extern UART_LOG_BUF UartLogBuf;
#ifdef CONFIG_UART_LOG_HISTORY
extern u8 UartLogHistoryBuf[UART_LOG_HISTORY_LEN][UART_LOG_CMD_BUFLEN];
#endif
#else
MON_RAM_BSS_SECTION
volatile UART_LOG_CTL UartLogCtl;
MON_RAM_BSS_SECTION
volatile UART_LOG_CTL *pUartLogCtl;
MON_RAM_BSS_SECTION
u8 *ArgvArray[MAX_ARGV];
MON_RAM_BSS_SECTION
UART_LOG_BUF UartLogBuf;
#ifdef CONFIG_UART_LOG_HISTORY
MON_RAM_BSS_SECTION
u8 UartLogHistoryBuf[UART_LOG_HISTORY_LEN][UART_LOG_CMD_BUFLEN];
#endif
#endif
#ifdef CONFIG_KERNEL
static void (*up_sema_from_isr)(_sema *) = NULL;
#endif
_LONG_CALL_
extern u8
UartLogCmdChk(
IN u8 RevData,
IN UART_LOG_CTL *prvUartLogCtl,
IN u8 EchoFlag
);
_LONG_CALL_
extern VOID
ArrayInitialize(
IN u8 *pArrayToInit,
IN u8 ArrayLen,
IN u8 InitValue
);
_LONG_CALL_
extern VOID
UartLogHistoryCmd(
IN u8 RevData,
IN UART_LOG_CTL *prvUartLogCtl,
IN u8 EchoFlag
);
_LONG_CALL_
extern VOID
UartLogCmdExecute(
IN PUART_LOG_CTL pUartLogCtlExe
);
//=================================================
/* Minimum and maximum values a `signed long int' can hold.
(Same as `int'). */
#ifndef __LONG_MAX__
#if defined (__alpha__) || (defined (__sparc__) && defined(__arch64__)) || defined (__sparcv9) || defined (__s390x__)
#define __LONG_MAX__ 9223372036854775807L
#else
#define __LONG_MAX__ 2147483647L
#endif /* __alpha__ || sparc64 */
#endif
#undef LONG_MIN
#define LONG_MIN (-LONG_MAX-1)
#undef LONG_MAX
#define LONG_MAX __LONG_MAX__
/* Maximum value an `unsigned long int' can hold. (Minimum is 0). */
#undef ULONG_MAX
#define ULONG_MAX (LONG_MAX * 2UL + 1)
#ifndef __LONG_LONG_MAX__
#define __LONG_LONG_MAX__ 9223372036854775807LL
#endif
//======================================================
//<Function>: UartLogIrqHandleRam
//<Usage >: To deal with Uart-Log RX IRQ
//<Argus >: VOID
//<Return >: VOID
//<Notes >: NA
//======================================================
//MON_RAM_TEXT_SECTION
VOID
UartLogIrqHandleRam
(
VOID * Data
)
{
u8 UartReceiveData = 0;
//For Test
BOOL PullMode = _FALSE;
u32 IrqEn = DiagGetIsrEnReg();
DiagSetIsrEnReg(0);
UartReceiveData = DiagGetChar(PullMode);
if (UartReceiveData == 0) {
goto exit;
}
//KB_ESC chk is for cmd history, it's a special case here.
if (UartReceiveData == KB_ASCII_ESC) {
//4 Esc detection is only valid in the first stage of boot sequence (few seconds)
if (pUartLogCtl->ExecuteEsc != _TRUE)
{
pUartLogCtl->ExecuteEsc = _TRUE;
(*pUartLogCtl).EscSTS = 0;
}
else
{
//4 the input commands are valid only when the task is ready to execute commands
if ((pUartLogCtl->BootRdy == 1)
#ifdef CONFIG_KERNEL
||(pUartLogCtl->TaskRdy == 1)
#endif
)
{
if ((*pUartLogCtl).EscSTS==0)
{
(*pUartLogCtl).EscSTS = 1;
}
}
else
{
(*pUartLogCtl).EscSTS = 0;
}
}
}
else if ((*pUartLogCtl).EscSTS==1){
if (UartReceiveData != KB_ASCII_LBRKT){
(*pUartLogCtl).EscSTS = 0;
}
else{
(*pUartLogCtl).EscSTS = 2;
}
}
else{
if ((*pUartLogCtl).EscSTS==2){
(*pUartLogCtl).EscSTS = 0;
#ifdef CONFIG_UART_LOG_HISTORY
if ((UartReceiveData=='A')|| UartReceiveData=='B'){
UartLogHistoryCmd(UartReceiveData,(UART_LOG_CTL *)pUartLogCtl,1);
}
#endif
}
else{
if (UartLogCmdChk(UartReceiveData,(UART_LOG_CTL *)pUartLogCtl,1)==2)
{
//4 check UartLog buffer to prevent from incorrect access
if (pUartLogCtl->pTmpLogBuf != NULL)
{
pUartLogCtl->ExecuteCmd = _TRUE;
#if defined(CONFIG_KERNEL) && !TASK_SCHEDULER_DISABLED
if (pUartLogCtl->TaskRdy && up_sema_from_isr != NULL)
//RtlUpSemaFromISR((_Sema *)&pUartLogCtl->Sema);
up_sema_from_isr((_sema *)&pUartLogCtl->Sema);
#endif
}
else
{
ArrayInitialize((u8 *)pUartLogCtl->pTmpLogBuf->UARTLogBuf, UART_LOG_CMD_BUFLEN, '\0');
}
}
}
}
exit:
DiagSetIsrEnReg(IrqEn);
}
//MON_RAM_TEXT_SECTION
VOID
RtlConsolInitRam(
IN u32 Boot,
IN u32 TBLSz,
IN VOID *pTBL
)
{
UartLogBuf.BufCount = 0;
ArrayInitialize(&UartLogBuf.UARTLogBuf[0],UART_LOG_CMD_BUFLEN,'\0');
pUartLogCtl = &UartLogCtl;
pUartLogCtl->NewIdx = 0;
pUartLogCtl->SeeIdx = 0;
pUartLogCtl->RevdNo = 0;
pUartLogCtl->EscSTS = 0;
pUartLogCtl->BootRdy = 0;
pUartLogCtl->pTmpLogBuf = &UartLogBuf;
#ifdef CONFIG_UART_LOG_HISTORY
pUartLogCtl->CRSTS = 0;
pUartLogCtl->pHistoryBuf = &UartLogHistoryBuf[0];
#endif
pUartLogCtl->pfINPUT = (VOID*)&DiagPrintf;
pUartLogCtl->pCmdTbl = (PCOMMAND_TABLE) pTBL;
pUartLogCtl->CmdTblSz = TBLSz;
#ifdef CONFIG_KERNEL
pUartLogCtl->TaskRdy = 0;
#endif
//executing boot sequence
if (Boot == ROM_STAGE)
{
pUartLogCtl->ExecuteCmd = _FALSE;
pUartLogCtl->ExecuteEsc = _FALSE;
}
else
{
pUartLogCtl->ExecuteCmd = _FALSE;
pUartLogCtl->ExecuteEsc= _TRUE;//don't check Esc anymore
#if defined(CONFIG_KERNEL)
/* Create a Semaphone */
//RtlInitSema((_Sema*)&(pUartLogCtl->Sema), 0);
rtw_init_sema((_sema*)&(pUartLogCtl->Sema), 0);
pUartLogCtl->TaskRdy = 0;
#ifdef PLATFORM_FREERTOS
#define LOGUART_STACK_SIZE 128 //USE_MIN_STACK_SIZE modify from 512 to 128
#if CONFIG_USE_TCM_HEAP
{
int ret = 0;
void *stack_addr = tcm_heap_malloc(LOGUART_STACK_SIZE*sizeof(int));
//void *stack_addr = rtw_malloc(stack_size*sizeof(int));
if(stack_addr == NULL){
DiagPrintf("Out of TCM heap in \"LOGUART_TASK\" ");
}
ret = xTaskGenericCreate(
RtlConsolTaskRam,
(const char *)"LOGUART_TASK",
LOGUART_STACK_SIZE,
NULL,
tskIDLE_PRIORITY + 5 + PRIORITIE_OFFSET,
NULL,
stack_addr,
NULL);
if (pdTRUE != ret)
{
DiagPrintf("Create Log UART Task Err!!\n");
}
}
#else
if (pdTRUE != xTaskCreate( RtlConsolTaskRam, (const signed char * const)"LOGUART_TASK", LOGUART_STACK_SIZE, NULL, tskIDLE_PRIORITY + 5 + PRIORITIE_OFFSET, NULL))
{
DiagPrintf("Create Log UART Task Err!!\n");
}
#endif
#endif
#endif
}
CONSOLE_8195A();
}
extern u8** GetArgv(const u8 *string);
#if SUPPORT_LOG_SERVICE
extern char log_buf[LOG_SERVICE_BUFLEN];
extern xSemaphoreHandle log_rx_interrupt_sema;
#endif
//======================================================
void console_cmd_exec(PUART_LOG_CTL pUartLogCtlExe)
{
u8 CmdCnt = 0;
u8 argc = 0;
u8 **argv;
//u32 CmdNum;
PUART_LOG_BUF pUartLogBuf = pUartLogCtlExe->pTmpLogBuf;
#if SUPPORT_LOG_SERVICE
strncpy(log_buf, (const u8*)&(*pUartLogBuf).UARTLogBuf[0], LOG_SERVICE_BUFLEN-1);
#endif
argc = GetArgc((const u8*)&((*pUartLogBuf).UARTLogBuf[0]));
argv = GetArgv((const u8*)&((*pUartLogBuf).UARTLogBuf[0]));
if(argc > 0){
#if SUPPORT_LOG_SERVICE
// if(log_handler(argv[0]) == NULL)
// legency_interactive_handler(argc, argv);
//RtlUpSema((_Sema *)&log_rx_interrupt_sema);
rtw_up_sema((_sema *)&log_rx_interrupt_sema);
#endif
ArrayInitialize(argv[0], sizeof(argv[0]) ,0);
}else{
#if defined(configUSE_WAKELOCK_PMU) && (configUSE_WAKELOCK_PMU == 1)
pmu_acquire_wakelock(BIT(PMU_LOGUART_DEVICE));
#endif
CONSOLE_8195A(); // for null command
}
(*pUartLogBuf).BufCount = 0;
ArrayInitialize(&(*pUartLogBuf).UARTLogBuf[0], UART_LOG_CMD_BUFLEN, '\0');
}
//======================================================
// overload original RtlConsolTaskRam
//MON_RAM_TEXT_SECTION
VOID
RtlConsolTaskRam(
VOID *Data
)
{
#if SUPPORT_LOG_SERVICE
log_service_init();
#endif
//4 Set this for UartLog check cmd history
#ifdef CONFIG_KERNEL
pUartLogCtl->TaskRdy = 1;
up_sema_from_isr = rtw_up_sema_from_isr;
#endif
#ifndef CONFIG_KERNEL
pUartLogCtl->BootRdy = 1;
#endif
do{
#if defined(CONFIG_KERNEL) && !TASK_SCHEDULER_DISABLED
//RtlDownSema((_Sema *)&pUartLogCtl->Sema);
rtw_down_sema((_sema *)&pUartLogCtl->Sema);
#endif
if (pUartLogCtl->ExecuteCmd) {
// Add command handler here
console_cmd_exec((PUART_LOG_CTL)pUartLogCtl);
//UartLogCmdExecute((PUART_LOG_CTL)pUartLogCtl);
pUartLogCtl->ExecuteCmd = _FALSE;
}
}while(1);
}
//======================================================
#if BUFFERED_PRINTF
xTaskHandle print_task = NULL;
EventGroupHandle_t print_event = NULL;
char print_buffer[MAX_PRINTF_BUF_LEN];
int flush_idx = 0;
int used_length = 0;
int available_space(void)
{
return MAX_PRINTF_BUF_LEN-used_length;
}
int buffered_printf(const char* fmt, ...)
{
if((print_task==NULL) || (print_event==NULL) )
return 0;
char tmp_buffer[UART_LOG_CMD_BUFLEN+1];
static int print_idx = 0;
int cnt;
if(xEventGroupGetBits(print_event)!=1)
xEventGroupSetBits(print_event, 1);
memset(tmp_buffer,0,UART_LOG_CMD_BUFLEN+1);
VSprintf(tmp_buffer, fmt, ((const int *)&fmt)+1);
cnt = _strlen(tmp_buffer);
if(cnt < available_space()){
if(print_idx >= flush_idx){
if(MAX_PRINTF_BUF_LEN-print_idx >= cnt){
memcpy(&print_buffer[print_idx], tmp_buffer, cnt);
}else{
memcpy(&print_buffer[print_idx], tmp_buffer, MAX_PRINTF_BUF_LEN-print_idx);
memcpy(&print_buffer[0], &tmp_buffer[MAX_PRINTF_BUF_LEN-print_idx], cnt-(MAX_PRINTF_BUF_LEN-print_idx));
}
}else{ // space is flush_idx - print_idx, and available space is enough
memcpy(&print_buffer[print_idx], tmp_buffer, cnt);
}
// protection needed
taskENTER_CRITICAL();
used_length+=cnt;
taskEXIT_CRITICAL();
print_idx+=cnt;
if(print_idx>=MAX_PRINTF_BUF_LEN)
print_idx -= MAX_PRINTF_BUF_LEN;
}else{
// skip
cnt = 0;
}
return cnt;
}
void printing_task(void* arg)
{
while(1){
//wait event
if(xEventGroupWaitBits(print_event, 1, pdFALSE, pdFALSE, 100 ) == 1){
while(used_length > 0){
putchar(print_buffer[flush_idx]);
flush_idx++;
if(flush_idx >= MAX_PRINTF_BUF_LEN)
flush_idx-=MAX_PRINTF_BUF_LEN;
taskENTER_CRITICAL();
used_length--;
taskEXIT_CRITICAL();
}
// clear event
xEventGroupClearBits( print_event, 1);
}
}
}
void rtl_printf_init()
{
if(print_event==NULL){
print_event = xEventGroupCreate();
if(print_event == NULL)
printf("\n\rprint event init fail!\n");
}
if(print_task == NULL){
if(xTaskCreate(printing_task, (const char *)"print_task", 512, NULL, tskIDLE_PRIORITY + 1, &print_task) != pdPASS)
printf("\n\rprint task init fail!\n");
}
}
#endif
//======================================================
__weak void console_init(void)
{
IRQ_HANDLE UartIrqHandle;
//4 Register Log Uart Callback function
UartIrqHandle.Data = NULL;//(u32)&UartAdapter;
UartIrqHandle.IrqNum = UART_LOG_IRQ;
UartIrqHandle.IrqFun = (IRQ_FUN) UartLogIrqHandleRam;
UartIrqHandle.Priority = 6;
//4 Register Isr handle
InterruptUnRegister(&UartIrqHandle);
InterruptRegister(&UartIrqHandle);
#if !TASK_SCHEDULER_DISABLED
RtlConsolInitRam((u32)RAM_STAGE,(u32)0,(VOID*)NULL);
#else
RtlConsolInitRam((u32)ROM_STAGE,(u32)0,(VOID*)NULL);
#endif
#if BUFFERED_PRINTF
rtl_printf_init();
#endif
}

View file

@ -0,0 +1,140 @@
/*
* Routines to access hardware
*
* Copyright (c) 2013 Realtek Semiconductor Corp.
*
* This module is a confidential and proprietary property of RealTek and
* possession or use of this module requires written permission of RealTek.
*/
#ifndef _RTK_CONSOL_H_
#define _RTK_CONSOL_H_
/*
* Include user defined options first. Anything not defined in these files
* will be set to standard values. Override anything you dont like!
*/
#if defined(CONFIG_PLATFORM_8195A) || defined(CONFIG_PLATFORM_8711B)
#include "platform_opts.h"
#endif
//#include "osdep_api.h"
#include "osdep_service.h"
#include "hal_diag.h"
#include "platform_stdlib.h"
#define CONSOLE_PREFIX "#"
//Log UART
//UART_LOG_CMD_BUFLEN: only 126 bytes could be used for keeping input
// cmd, the last byte is for string end ('\0').
#define UART_LOG_CMD_BUFLEN 127
#define MAX_ARGV 10
//print log buffer length, if buffer get full, the extra logs will be discarded.
#if BUFFERED_PRINTF
#define MAX_PRINTF_BUF_LEN 1024
#endif
typedef u32 (*ECHOFUNC)(IN u8*,...); //UART LOG echo-function type.
typedef struct _UART_LOG_BUF_ {
u8 BufCount; //record the input cmd char number.
u8 UARTLogBuf[UART_LOG_CMD_BUFLEN]; //record the input command.
} UART_LOG_BUF, *PUART_LOG_BUF;
typedef struct _UART_LOG_CTL_ {
u8 NewIdx;
u8 SeeIdx;
u8 RevdNo;
u8 EscSTS;
u8 ExecuteCmd;
u8 ExecuteEsc;
u8 BootRdy;
u8 Resvd;
PUART_LOG_BUF pTmpLogBuf;
VOID *pfINPUT;
PCOMMAND_TABLE pCmdTbl;
u32 CmdTblSz;
#ifdef CONFIG_UART_LOG_HISTORY
u32 CRSTS;
#endif
#ifdef CONFIG_UART_LOG_HISTORY
u8 (*pHistoryBuf)[UART_LOG_CMD_BUFLEN];
#endif
#ifdef CONFIG_KERNEL
u32 TaskRdy;
//_Sema Sema;
_sema Sema;
#else
// Since ROM code will reference this typedef, so keep the typedef same size
u32 TaskRdy;
void *Sema;
#endif
} UART_LOG_CTL, *PUART_LOG_CTL;
#define KB_ASCII_NUL 0x00
#define KB_ASCII_BS 0x08
#define KB_ASCII_TAB 0x09
#define KB_ASCII_LF 0x0A
#define KB_ASCII_CR 0x0D
#define KB_ASCII_ESC 0x1B
#define KB_ASCII_SP 0x20
#define KB_ASCII_BS_7F 0x7F
#define KB_ASCII_LBRKT 0x5B //[
#define KB_SPACENO_TAB 1
#ifdef CONFIG_UART_LOG_HISTORY
#define UART_LOG_HISTORY_LEN 5
#endif
#ifdef CONFIG_DEBUG_LOG
#define _ConsolePrint DiagPrintf
#else
#define _ConsolePrint
#endif
#ifndef CONSOLE_PREFIX
#define CONSOLE_PREFIX "<RTL8195A>"
#endif
#define CONSOLE_8195A(...) do {\
_ConsolePrint("\r"CONSOLE_PREFIX __VA_ARGS__);\
}while(0)
_LONG_CALL_ VOID
RtlConsolInit(
IN u32 Boot,
IN u32 TBLSz,
IN VOID *pTBL
);
#if defined(CONFIG_KERNEL)
_LONG_CALL_ VOID
RtlConsolTaskRam(
VOID *Data
);
#endif
_LONG_CALL_ VOID
RtlConsolTaskRom(
VOID *Data
);
_LONG_CALL_ u32
Strtoul(
IN const u8 *nptr,
IN u8 **endptr,
IN u32 base
);
void console_init(void);
#endif //_RTK_CONSOL_H_

View file

@ -0,0 +1,341 @@
/*
* console_api.c
*
* Created on: 24/02/17
* Author: pvvx
*/
//======================================================
#ifndef LOGUART_STACK_SIZE
#define LOGUART_STACK_SIZE 400 // USE_MIN_STACK_SIZE modify from 512 to 128
#endif
#define CONSOLE_PRIORITY 0
//======================================================
#include "rtl8195a.h"
#include "rtl_bios_data.h"
#include "osdep_api.h"
#if defined(configUSE_WAKELOCK_PMU) && (configUSE_WAKELOCK_PMU == 1)
#include "freertos_pmu.h"
#else
#error "Define configUSE_WAKELOCK_PMU = 1 & configUSE_WAKELOCK_PMU = 1!"
#endif
#if defined(CONFIG_KERNEL) && !TASK_SCHEDULER_DISABLED
#else
#error "Define CONFIG_KERNEL & TASK_SCHEDULER_DISABLED = 0!"
#endif
#ifndef CONFIG_UART_LOG_HISTORY
#error "Define CONFIG_UART_LOG_HISTORY!"
#endif
//======================================================
// #define USE_ROM_CONSOLE
//======================================================
_LONG_CALL_ extern u8 UartLogCmdChk(
IN u8 RevData, IN UART_LOG_CTL *prvUartLogCtl,
IN u8 EchoFlag);
_LONG_CALL_ extern void ArrayInitialize(
IN u8 *pArrayToInit,
IN u8 ArrayLen,
IN u8 InitValue);
_LONG_CALL_ extern void UartLogHistoryCmd(
IN u8 RevData, IN UART_LOG_CTL *prvUartLogCtl,
IN u8 EchoFlag);
//_LONG_CALL_ extern void UartLogCmdExecute(IN PUART_LOG_CTL pUartLogCtlExe);
//======================================================
extern PCOMMAND_TABLE UartLogRamCmdTable[];
extern UartLogRamCmdTableSize;
//======================================================
//<Function>: UartLogIrqHandleRam
//<Usage >: To deal with Uart-Log RX IRQ
//<Argus >: void
//<Return >: void
//<Notes >: NA
//======================================================
// overload original UartLogIrqHandle
MON_RAM_TEXT_SECTION
void UartLogIrqHandleRam(void * Data) {
uint32 IrqEn = DiagGetIsrEnReg(); // HAL_UART_READ32(UART_INTERRUPT_EN_REG_OFF)
DiagSetIsrEnReg(0); // HAL_UART_WRITE32(UART_INTERRUPT_EN_REG_OFF, 0)
uint8 UartReceiveData = DiagGetChar(_FALSE); // if(flg) while(!(HAL_UART_READ32(UART_LINE_STATUS_REG_OFF)&1)); return HAL_UART_READ32(UART_REV_BUF_OFF);
if (UartReceiveData == 0) {
goto exit;
}
PUART_LOG_CTL p = pUartLogCtl;
//KB_ESC chk is for cmd history, it's a special case here.
if (UartReceiveData == KB_ASCII_ESC) {
// Esc detection is only valid in the first stage of boot sequence (few seconds)
if (p->ExecuteEsc != _TRUE) {
p->ExecuteEsc = _TRUE;
p->EscSTS = 0;
} else {
//4 the input commands are valid only when the task is ready to execute commands
if (p->BootRdy == 1 || p->TaskRdy == 1) {
if (p->EscSTS == 0) {
p->EscSTS = 1;
}
} else {
p->EscSTS = 0;
}
}
} else if (p->EscSTS == 1) {
if (UartReceiveData != KB_ASCII_LBRKT) { // '['
p->EscSTS = 0;
} else {
p->EscSTS = 2;
}
} else {
if (p->EscSTS == 2) {
p->EscSTS = 0;
if (UartReceiveData == 'A' || UartReceiveData == 'B') {
// if(UartReceiveData == ...) set pUartLogCtl->SeeIdx ...
// prvStrCpy(pUartLogCtl->pTmpLogBuf->UARTLogBuf, pUartLogCtl->pHistoryBuf[pUartLogCtl->SeeIdx]);
// pUartLogCtl->pTmpLogBuf->BufCount = prvStrLen(pUartLogCtl->pTmpLogBuf->UARTLogBuf);
// if(EchoFlag) pUartLogCtl->pfINPUT(pUartLogCtl->pTmpLogBuf->UARTLogBuf);
UartLogHistoryCmd(UartReceiveData, (UART_LOG_CTL *) pUartLogCtl,
1);
}
} else {
if (UartLogCmdChk(UartReceiveData, (UART_LOG_CTL *) pUartLogCtl, 1)
== 2) {
// check UartLog buffer to prevent from incorrect access
if (p->pTmpLogBuf != NULL) {
p->ExecuteCmd = _TRUE;
if (p->TaskRdy) {
rtw_up_sema_from_isr((_Sema *) &pUartLogCtl->Sema);
}
} else {
ArrayInitialize((u8 *) pUartLogCtl->pTmpLogBuf->UARTLogBuf,
UART_LOG_CMD_BUFLEN, '\0');
}
}
}
}
exit:
DiagSetIsrEnReg(IrqEn); // HAL_UART_WRITE32(UART_INTERRUPT_EN_REG_OFF, IrqEn)
}
//======================================================
//<Function>: GetArgvRam
//<Usage >: парсигн аргументов строки
//<Argus >: pstr - указатель на строку
//<Return >: кол-во аргументов
//<Notes >: 2 формата:
// 1) cmd=arg1,arg2,...
// 2) cmd arg1 arg2
// arg может быть обрамлен '"' или '\''
// для передачи ' ' или ','.
// Начальные пробелы cmd или arg удаляются.
//======================================================
int GetArgvRam(IN u8 *pstr, u8** argv) {
int arvc = 0;
// u8** argv = ArgvArray;
u8* p = pstr;
u8 t, n = ' ';
int m = 0;
while(*p != 0
&& *p != '\r'
&& *p != '\n'
&& arvc < MAX_ARGV
&& p < &pstr[UART_LOG_CMD_BUFLEN-1]) {
switch(m) {
case 0: // wait cmd
if(*p == ' ') {
// *p = 0;
break;
}
*argv++ = p;
arvc++;
m++;
break;
case 1: // test end cmd, type format parm
if(*p == ' ') { // format cmd arg1 arg2 ...
m++;
*p = 0;
} else if(*p == '=') { // "at" format cmd=arg1,arg2,...
n = ',';
m++;
*p = 0;
}
break;
case 2: // wait start arg
if(*p == ' ') {
*p = 0;
break;
}
if(*p == '"' || *p == '\'') {
t = *p;
m = 4;
*p = 0;
break;
}
*argv++ = p;
arvc++;
m++;
case 3: // end arg
if(*p == n) { // ' ' or ','
m = 2;
*p = 0;
}
break;
case 4:
*argv++ = p;
arvc++;
m++;
case 5:
if(*p == t) { // '\'' or '"'
m = 3;
*p = 0;
}
break;
}
p++;
}
return arvc;
}
//======================================================
//<Function>: RtlConsolTaskRam
//<Usage >: overload original RtlConsolTaskRam
//<Argus >: Data - указатель PUART_LOG_CTL
//<Return >: none
//<Notes >:
//======================================================
MON_RAM_TEXT_SECTION void RtlConsolTaskRam(void *Data) {
PUART_LOG_CTL p = pUartLogCtl;
#ifdef USE_ROM_CONSOLE // show Help
p->pTmpLogBuf->UARTLogBuf[0] = '?';
p->pTmpLogBuf->BufCount = 1;
p->ExecuteCmd = _TRUE;
#endif
do {
p->TaskRdy = _TRUE;
rtw_down_sema(&p->Sema);
if (p->ExecuteCmd) {
// UartLogCmdExecute(pUartLogCtl);
int argc = GetArgvRam(p->pTmpLogBuf->UARTLogBuf, ArgvArray);
if(argc) {
StrUpr(ArgvArray[0]);
PCOMMAND_TABLE pcmd = p->pCmdTbl;
int flg = 1;
#ifdef USE_ROM_CONSOLE
for(int i = 0; i < p->CmdTblSz; i++) {
#else
while(pcmd->cmd) {
#endif
if(prvStrCmp(ArgvArray[0], pcmd->cmd) == 0) {
flg = 0;
if(pcmd->ArgvCnt < argc) {
#ifdef USE_ROM_CONSOLE
pcmd->func(argc-1, &ArgvArray[1]);
#else
pcmd->func(argc, &ArgvArray);
#endif
} else {
#ifdef USE_ROM_CONSOLE
DiagPrintf(pcmd->msg);
#else
DiagPrintf("%s%s\n", pcmd->cmd, pcmd->msg);
#endif
}
}
pcmd++;
}
if(flg) DiagPrintf("cmd: %s - nothing!\n", ArgvArray[0]);
#if defined(configUSE_WAKELOCK_PMU) && (configUSE_WAKELOCK_PMU == 1)
pmu_release_wakelock(WAKELOCK_LOGUART);
#endif
}
#if defined(configUSE_WAKELOCK_PMU) && (configUSE_WAKELOCK_PMU == 1)
else pmu_acquire_wakelock(WAKELOCK_LOGUART);
#endif
p->pTmpLogBuf->BufCount = 0;
p->pTmpLogBuf->UARTLogBuf[0] = 0;
HalSerialPutcRtl8195a('\r');
HalSerialPutcRtl8195a('>');
p->ExecuteCmd = _FALSE;
}
} while (1);
}
//======================================================
//<Function>: console_init
//<Usage >: Initialize rtl console
//<Argus >: none
//<Return >: none
//<Notes >: delete rtl_concole.h from project
//======================================================
MON_RAM_TEXT_SECTION void console_init(void) {
IRQ_HANDLE UartIrqHandle;
// Register Log Uart Callback function
UartIrqHandle.Data = 0; // (u32)&UartAdapter;
UartIrqHandle.IrqNum = UART_LOG_IRQ;
UartIrqHandle.IrqFun = (IRQ_FUN) UartLogIrqHandleRam;
UartIrqHandle.Priority = 0; // ??
// Register Isr handle
InterruptUnRegister(&UartIrqHandle);
#ifdef USE_ROM_CONSOLE // use ROM Consol init & printf "<RTL8195A>"
RtlConsolInit(RAM_STAGE, (u32) 6, (void*) UartLogRomCmdTable);
#else
UartLogBuf.BufCount = 0;
ArrayInitialize(&UartLogBuf.UARTLogBuf[0], UART_LOG_CMD_BUFLEN, '\0');
pUartLogCtl = &UartLogCtl;
pUartLogCtl->NewIdx = 0;
pUartLogCtl->SeeIdx = 0;
pUartLogCtl->EscSTS = 0;
pUartLogCtl->BootRdy = 0;
pUartLogCtl->pTmpLogBuf = &UartLogBuf;
pUartLogCtl->CRSTS = 0;
pUartLogCtl->pHistoryBuf = UartLogHistoryBuf;
pUartLogCtl->pfINPUT = (void*) &DiagPrintf;
pUartLogCtl->pCmdTbl = (PCOMMAND_TABLE) UartLogRamCmdTable;
pUartLogCtl->CmdTblSz = UartLogRamCmdTableSize/16; //6; // GetRomCmdNum()
pUartLogCtl->TaskRdy = 0;
#endif
pUartLogCtl->RevdNo = UART_LOG_HISTORY_LEN;
// Create a Semaphone
rtw_init_sema(&pUartLogCtl->Sema, 1);
// executing boot sequence
pUartLogCtl->ExecuteCmd = _FALSE;
pUartLogCtl->ExecuteEsc = _TRUE; //don't check Esc anymore
InterruptRegister(&UartIrqHandle);
if (pdTRUE
!= xTaskCreate(RtlConsolTaskRam,
(const signed char * const )"loguart", LOGUART_STACK_SIZE,
NULL, tskIDLE_PRIORITY + CONSOLE_PRIORITY + PRIORITIE_OFFSET, NULL)) {
DiagPrintf("Create Log UART Task Err!!\n");
}
}
#ifndef USE_ROM_CONSOLE
//======================================================
//<Function>: console_help
//<Usage >: Initialize rtl console
//<Argus >: argc - кол-во аргуметов, argv - список аргументов
//<Return >: none
//<Notes >:
//======================================================
extern char str_rom_57ch3Dch0A[]; // "=========================================================\n" 57 шт
_WEAK void console_help(int argc, char *argv[]) { // Help
DiagPrintf("CONSOLE COMMAND SET:\n");
DiagPrintf(&str_rom_57ch3Dch0A[25]); // DiagPrintf("==============================\n");
PCOMMAND_TABLE pcmdtab = UartLogRamCmdTable;
while(pcmdtab->cmd) {
#ifdef USE_ROM_CONSOLE
DiagPrintf(pcmdtab->msg);
#else
DiagPrintf("%s%s\n", pcmdtab->cmd, pcmdtab->msg);
#endif
pcmdtab++;
}
DiagPrintf(&str_rom_57ch3Dch0A[25]); // DiagPrintf("==============================\n");
}
void print_on(int argc, char *argv[])
{
print_off = argv[1][0]!='1';
}
// (!) размещается в специальном сегменте '.mon.tab*' (см. *.ld файл)
MON_RAM_TAB_SECTION COMMAND_TABLE console_commands[] = {
{"PR", 1, print_on, "=<1/0>: Printf on/off"}, // Help
{"?", 0, console_help, ": This Help"} // Help
// {"HELP", 0, console_help, ": Help"} // Help
};
#endif

View file

@ -0,0 +1,12 @@
#ifndef RTL_SEC_H
#define RTL_SEC_H
#include <platform_stdlib.h>
#define SEC_PROCESS_OPT_ENC 1
#define SEC_PROCESS_OPT_DEC 2
#define sec_process_data ProcessSecData
uint32_t sec_process_data(uint8_t key_idx, uint32_t opt, uint8_t *iv, uint8_t *input_buf, uint32_t buf_len, uint8_t *output_buf);
#endif // RTL_SEC_H

View file

@ -0,0 +1,136 @@
// pick.cpp : main project file.
#include "stdafx.h"
using namespace System;
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/types.h>
#define PATTERN_1 0x96969999
#define PATTERN_2 0xFC66CC3F
#define PATTERN_3 0x03CC33C0
#define PATTERN_4 0x6231DCE5
unsigned int fw_head[4] = { PATTERN_1, PATTERN_2, PATTERN_3, PATTERN_4 };
unsigned int seg_head[4] = { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF };
/*
int main(array<System::String ^> ^args)
{
Console::WriteLine(L"Hello World");
return 0;
}
*/
int main(int argc, char* argv[])
{
int arg_num = 6;
if ((argc>5) && (strstr(argv[5], "head"))) arg_num++;
if (argc != arg_num){
printf("Usage: pick.exe <start addr> <end addr> <input name> <output name> <body[+reset_offset][+sig], head[+reset_offset] [image2_start]>\n");
return -1;
}
unsigned char *buf;
unsigned int start;//=atoi(argv[1]);
unsigned int end;// = atoi(argv[2]);
unsigned int base;
int is_raw = 0;
int is_sig = 0;
char *inf = argv[3];
char *outf = argv[4];
int size;
FILE *ifp, *ofp;
//if(argv[1][0]=='0'&&(argv[1][1]=='x'||argv[1][1]=='X'))
// sscanf(argv[1], "0x%x", &start);
//else
// start=atoi(argv[1]);
start = strtol(argv[1], NULL, 0);
//if(argv[2][0]=='0'&&(argv[2][1]=='x'||argv[2][1]=='X'))
// sscanf(argv[2], "0x%x", &end);
//else
// end=atoi(argv[2]);
end = strtol(argv[2], NULL, 0);
base = start & 0xFFFF0000;
if (strstr(argv[5], "reset_offset")){
base = start;
}
if (strstr(argv[5], "raw")){
is_raw = 1;
}
else
is_raw = 0;
if (strstr(argv[5], "sig")){
is_sig = 1;
}
else
is_sig = 0;
printf("b:%d s:%d e:%d\n", base, start, end);
//printf("%s %s\n", inf, outf);
ifp = fopen(inf, "rb");
if (!ifp) return -2;
ofp = fopen(outf, "wb");
if (!ofp) return -3;
fseek(ifp, 0, SEEK_END);
size = ftell(ifp);
printf("size %d\n", size);
buf = (unsigned char *)malloc(size);
if (!buf) return -4;
if (end == 0) end = base + size;
if (end - start + 1 > 0){
fseek(ifp, start - base, SEEK_SET);
fread(buf, end - start, 1, ifp);
if (is_raw == 0){
if (strstr(argv[5], "head")){
int offset = strtol(argv[6], NULL, 0);
printf("append fw head %x\n", offset);
fwrite(fw_head, 4, sizeof(unsigned int), ofp);
seg_head[2] = (0xFFFF0000 | (offset / 1024));
}
else{
if (is_sig){
seg_head[2] = 0x35393138;
seg_head[3] = 0x31313738;
}
else{
seg_head[2] = 0xFFFFFFFF;
seg_head[3] = 0xFFFFFFFF;
}
}
seg_head[0] = end - start;
seg_head[1] = start;
fwrite(seg_head, 4, sizeof(unsigned int), ofp);
}
fwrite(buf, end - start, 1, ofp);
}
printf("copy size %d\n", end - start);
fclose(ifp);
fclose(ofp);
free(buf);
return 0;
}

View file

@ -0,0 +1,309 @@
#include "FreeRTOS.h"
#include "freertos_pmu.h"
#include <platform_opts.h>
#include "platform_autoconf.h"
#include "sys_api.h"
#include "sleep_ex_api.h"
#include "task.h"
#ifndef portNVIC_SYSTICK_CURRENT_VALUE_REG
#define portNVIC_SYSTICK_CURRENT_VALUE_REG ( * ( ( volatile uint32_t * ) 0xe000e018 ) )
#endif
uint32_t missing_tick = 0;
static uint32_t wakelock = DEFAULT_WAKELOCK;
static uint32_t wakeup_event = DEFAULT_WAKEUP_EVENT;
typedef struct {
uint32_t nDeviceId;
PSM_HOOK_FUN sleep_hook_fun;
void* sleep_param_ptr;
PSM_HOOK_FUN wakeup_hook_fun;
void* wakeup_param_ptr;
} PSM_DD_HOOK_INFO;
#define MAX_PSM_DD_HOOK_INFO_SIZE 8
uint32_t psm_dd_hook_info_size = 0;
PSM_DD_HOOK_INFO psm_dd_hook_infos[MAX_PSM_DD_HOOK_INFO_SIZE];
static uint8_t last_wakelock_state[32] = {
DEFAULT_WAKELOCK & 0x01, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0
};
static uint32_t last_acquire_wakelock_time[32] = {0};
static uint32_t hold_wakelock_time[32] = {0};
static uint32_t base_sys_time = 0;
static uint32_t sys_sleep_time = 0;
unsigned char reserve_pll = 0;
unsigned char generate_wakelock_stats = 0;
/* ++++++++ FreeRTOS macro implementation ++++++++ */
/*
* It is called in idle task.
*
* @return true : System is ready to check conditions that if it can enter sleep.
* false : System keep awake.
**/
/*
* It is called when freertos is going to sleep.
* At this moment, all sleep conditons are satisfied. All freertos' sleep pre-processing are done.
*
* @param expected_idle_time : The time that FreeRTOS expect to sleep.
* If we set this value to 0 then FreeRTOS will do nothing in its sleep function.
**/
void freertos_pre_sleep_processing(unsigned int *expected_idle_time) {
#ifdef CONFIG_SOC_PS_MODULE
uint32_t i;
uint32_t stime;
uint32_t tick_before_sleep;
uint32_t tick_after_sleep;
uint32_t tick_passed;
uint32_t backup_systick_reg;
unsigned char IsDramOn = 1;
unsigned char suspend_sdram = 1;
/* To disable freertos sleep function and use our sleep function,
* we can set original expected idle time to 0. */
stime = *expected_idle_time;
*expected_idle_time = 0;
for (i=0; i<psm_dd_hook_info_size; i++) {
if ( psm_dd_hook_infos[i].sleep_hook_fun != NULL) {
psm_dd_hook_infos[i].sleep_hook_fun( stime, psm_dd_hook_infos[i].sleep_param_ptr );
}
}
// Store gtimer timestamp before sleep
tick_before_sleep = us_ticker_read();
if ( sys_is_sdram_power_on() == 0 ) {
IsDramOn = 0;
}
if (IsDramOn) {
#if defined(FREERTOS_PMU_TICKLESS_SUSPEND_SDRAM) && (FREERTOS_PMU_TICKLESS_SUSPEND_SDRAM==0)
// sdram is turned on, and we don't want suspend sdram
suspend_sdram = 0;
#endif
} else {
// sdram didn't turned on, we should not suspend it
suspend_sdram = 0;
}
backup_systick_reg = portNVIC_SYSTICK_CURRENT_VALUE_REG;
// sleep
sleep_ex_selective(wakeup_event, stime, reserve_pll, suspend_sdram);
portNVIC_SYSTICK_CURRENT_VALUE_REG = backup_systick_reg;
// update kernel tick by calculating passed tick from gtimer
{
// get current gtimer timestamp
tick_after_sleep = us_ticker_read();
// calculated passed time
if (tick_after_sleep > tick_before_sleep) {
tick_passed = tick_after_sleep - tick_before_sleep;
} else {
// overflow
tick_passed = (0xffffffff - tick_before_sleep) + tick_after_sleep;
}
/* If there is a rapid interrupt (<1ms), it makes tick_passed less than 1ms.
* The tick_passed would be rounded and make OS can't step tick.
* We collect the rounded tick_passed into missing_tick and step tick properly.
* */
tick_passed += missing_tick;
if (tick_passed > stime * 1000) {
missing_tick = tick_passed - stime * 1000;
tick_passed = stime * 1000;
} else {
missing_tick = tick_passed % 1000;
}
// update kernel tick
vTaskStepTick( tick_passed/1000 );
}
sys_sleep_time += tick_passed/1000;
for (i=0; i<psm_dd_hook_info_size; i++) {
if ( psm_dd_hook_infos[i].wakeup_hook_fun != NULL) {
psm_dd_hook_infos[i].wakeup_hook_fun( stime, psm_dd_hook_infos[i].wakeup_param_ptr );
}
}
#else
// If PS is not enabled, then use freertos sleep function
#endif
}
void freertos_post_sleep_processing(unsigned int *expected_idle_time) {
#ifndef configSYSTICK_CLOCK_HZ
*expected_idle_time = 1 + ( portNVIC_SYSTICK_CURRENT_VALUE_REG / ( configCPU_CLOCK_HZ / configTICK_RATE_HZ ) );
#else
*expected_idle_time = 1 + ( portNVIC_SYSTICK_CURRENT_VALUE_REG / ( configSYSTICK_CLOCK_HZ / configTICK_RATE_HZ ) );
#endif
}
/* -------- FreeRTOS macro implementation -------- */
int freertos_ready_to_sleep() {
return wakelock == 0;
}
void pmu_acquire_wakelock(uint32_t lock_id) {
wakelock |= BIT(lock_id);
if (generate_wakelock_stats) {
uint32_t i;
uint32_t current_timestamp = osKernelSysTick();
for (i=0; i<32; i++) {
if ( (1<<i & BIT(lock_id)) && (last_wakelock_state[i] == 0) ) {
last_acquire_wakelock_time[i] = current_timestamp;
last_wakelock_state[i] = 1;
}
}
}
}
void pmu_release_wakelock(uint32_t lock_id) {
wakelock &= ~BIT(lock_id);
if (generate_wakelock_stats) {
uint32_t i;
uint32_t current_timestamp = osKernelSysTick();
for (i=0; i<32; i++) {
if ( (1<<i & BIT(lock_id)) && (last_wakelock_state[i] == 1) ) {
hold_wakelock_time[i] += current_timestamp - last_acquire_wakelock_time[i];
last_wakelock_state[i] = 0;
}
}
}
}
uint32_t pmu_get_wakelock_status() {
return wakelock;
}
void pmu_enable_wakelock_stats(unsigned char enable) {
generate_wakelock_stats = enable;
}
void pmu_get_wakelock_hold_stats( char *pcWriteBuffer ) {
uint32_t i;
uint32_t current_timestamp = osKernelSysTick();
*pcWriteBuffer = 0x00;
if (generate_wakelock_stats) {
// print header
sprintf(pcWriteBuffer, "wakelock_id\tholdtime\r\n");
pcWriteBuffer += strlen( pcWriteBuffer );
for (i=0; i<32; i++) {
if (last_wakelock_state[i] == 1) {
sprintf(pcWriteBuffer, "%x\t\t%d\r\n", i, hold_wakelock_time[i] + (current_timestamp - last_acquire_wakelock_time[i]));
} else {
if (hold_wakelock_time[i] > 0) {
sprintf(pcWriteBuffer, "%x\t\t%d\r\n", i, hold_wakelock_time[i]);
}
}
pcWriteBuffer += strlen( pcWriteBuffer );
}
sprintf(pcWriteBuffer, "time passed: %d ms, system sleep %d ms\r\n", current_timestamp - base_sys_time, sys_sleep_time);
}
}
void pmu_clean_wakelock_stat() {
uint32_t i;
base_sys_time = osKernelSysTick();
for (i=0; i<32; i++) {
hold_wakelock_time[i] = 0;
if (last_wakelock_state[i] == 1) {
last_acquire_wakelock_time[i] = base_sys_time;
}
}
sys_sleep_time = 0;
}
void pmu_add_wakeup_event(uint32_t event) {
wakeup_event |= event;
}
void pmu_del_wakeup_event(uint32_t event) {
wakeup_event &= ~event;
// To fulfill tickless design, system timer is required to be wakeup event
wakeup_event |= SLEEP_WAKEUP_BY_STIMER;
}
void pmu_register_sleep_callback(uint32_t nDeviceId, PSM_HOOK_FUN sleep_hook_fun, void* sleep_param_ptr, PSM_HOOK_FUN wakeup_hook_fun, void* wakeup_param_ptr) {
uint32_t i;
for (i=0; i<psm_dd_hook_info_size; i++) {
if (psm_dd_hook_infos[i].nDeviceId == nDeviceId) {
psm_dd_hook_infos[i].sleep_hook_fun = sleep_hook_fun;
psm_dd_hook_infos[i].sleep_param_ptr = sleep_param_ptr;
psm_dd_hook_infos[i].wakeup_hook_fun = wakeup_hook_fun;
psm_dd_hook_infos[i].wakeup_param_ptr = wakeup_param_ptr;
break;
}
}
if (i == psm_dd_hook_info_size) {
psm_dd_hook_infos[psm_dd_hook_info_size].nDeviceId = nDeviceId;
psm_dd_hook_infos[psm_dd_hook_info_size].sleep_hook_fun = sleep_hook_fun;
psm_dd_hook_infos[psm_dd_hook_info_size].sleep_param_ptr = sleep_param_ptr;
psm_dd_hook_infos[psm_dd_hook_info_size].wakeup_hook_fun = wakeup_hook_fun;
psm_dd_hook_infos[psm_dd_hook_info_size].wakeup_param_ptr = wakeup_param_ptr;
psm_dd_hook_info_size++;
}
}
void pmu_unregister_sleep_callback(uint32_t nDeviceId) {
uint32_t i;
for (i=0; i<psm_dd_hook_info_size; i++) {
if (psm_dd_hook_infos[i].nDeviceId == nDeviceId) {
if (psm_dd_hook_info_size > 1) {
// if we have more than 2 items, just swap the last item into current slot
psm_dd_hook_infos[i].nDeviceId = psm_dd_hook_infos[psm_dd_hook_info_size-1].nDeviceId;
psm_dd_hook_infos[i].sleep_hook_fun = psm_dd_hook_infos[psm_dd_hook_info_size-1].sleep_hook_fun;
psm_dd_hook_infos[i].sleep_param_ptr = psm_dd_hook_infos[psm_dd_hook_info_size-1].sleep_param_ptr;
psm_dd_hook_infos[i].wakeup_hook_fun = psm_dd_hook_infos[psm_dd_hook_info_size-1].wakeup_hook_fun;
psm_dd_hook_infos[i].wakeup_param_ptr = psm_dd_hook_infos[psm_dd_hook_info_size-1].wakeup_param_ptr;
// Then erase the last item
psm_dd_hook_infos[psm_dd_hook_info_size-1].nDeviceId = 0;
psm_dd_hook_infos[psm_dd_hook_info_size-1].sleep_hook_fun = NULL;
psm_dd_hook_infos[psm_dd_hook_info_size-1].sleep_param_ptr = NULL;
psm_dd_hook_infos[psm_dd_hook_info_size-1].wakeup_hook_fun = NULL;
psm_dd_hook_infos[psm_dd_hook_info_size-1].wakeup_param_ptr = NULL;
} else {
// we only have one item, just erase it
psm_dd_hook_infos[i].nDeviceId = 0;
psm_dd_hook_infos[i].sleep_hook_fun = NULL;
psm_dd_hook_infos[i].sleep_param_ptr = NULL;
psm_dd_hook_infos[i].wakeup_hook_fun = NULL;
psm_dd_hook_infos[i].wakeup_param_ptr = NULL;
}
psm_dd_hook_info_size--;
break;
}
}
}
void pmu_set_pll_reserved(unsigned char reserve) {
reserve_pll = reserve;
}

View file

@ -0,0 +1,4 @@
#ifndef _FREERTOS_PMU_8195A_H_
#define _FREERTOS_PMU_8195A_H_
#endif

View file

@ -0,0 +1,566 @@
/******************************************************************************
*
* Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
*
*
******************************************************************************/
#define _MAILBOX_C_
#include "mailbox.h"
/******************************************************************************
* Function Prototype Declaration
******************************************************************************/
static PRTL_MAILBOX RtlMBoxIdToHdl(IN u8 MBoxId);
PRTL_MAILBOX RtlMailboxCreate(IN u8 MboxID, IN u32 MboxSize, IN _Sema *pWakeSema);
VOID RtlMailboxDel(IN PRTL_MAILBOX MboxHdl);
u8 RtlMailboxSendToBack(
IN u8 MboxID,
IN MSG_BLK *pMsg,
IN u32 MSToWait,
IN u8 IsFromISR
);
u8 RtlMailboxSendToFront(
IN u8 MboxID,
IN MSG_BLK *pMsg,
IN u32 MSToWait,
IN u8 IsFromISR
);
u8 RtlMailboxReceive(
IN u8 MboxID,
OUT MSG_BLK *pMsg,
IN u32 MSToWait,
IN u8 IsFromISR
);
u8 RtlMailboxPeek(
IN u8 MboxID,
OUT MSG_BLK *pMsg,
IN u32 MSToWait,
IN u8 IsFromISR
);
u32 RtlMailboxMsgWaiting(
IN u8 MboxID,
IN u8 IsFromISR
);
/******************************************************************************
* Global Variable Declaration
******************************************************************************/
static RTL_MBOX_ROOT MBox_Entry;
/******************************************************************************
* External Function & Variable Declaration
******************************************************************************/
/******************************************************************************
* Function: RtlMBoxIdToHdl
* Desc: Map a mailbox ID to the mailbox pointer.
* Para:
* MBoxId: The Mailbox ID
* Return: The pointer of the mailbox. If didn't found match mailbox,
* return NULL.
*
******************************************************************************/
static PRTL_MAILBOX RtlMBoxIdToHdl(
IN u8 MBoxId
)
{
RTL_MAILBOX *pMbox=NULL;
RTL_MAILBOX *pTmpMbox;
_LIST *pHead;
_LIST *pList;
// if the Mailbox root entry initialed ? if not, initial it
if (!MBox_Entry.isInitialed) {
RtlMutexInit(&MBox_Entry.Mutex); // Init the Mutex for the mailbox add/delete procedure protection
RtlInitListhead(&MBox_Entry.mbox_list); // Init the link list head to chain all created mailbox
MBox_Entry.isInitialed = 1;
MSG_MBOX_INFO("MBox Entry Initial...\n");
}
pHead = &MBox_Entry.mbox_list;
RtlDownMutex(&MBox_Entry.Mutex);
pList = RtlListGetNext(&MBox_Entry.mbox_list);
while (pList != pHead) {
pTmpMbox = CONTAINER_OF(pList, RTL_MAILBOX, mbox_list);
if (MBoxId == pTmpMbox->mbox_id) {
pMbox = pTmpMbox;
break;
}
pList = RtlListGetNext(pList);
}
RtlUpMutex(&MBox_Entry.Mutex);
return pMbox;
}
/******************************************************************************
* Function: RtlMailboxCreate
* Desc: To create a mailbox with a given mailbox ID and size
* Para:
* MboxID: A number to identify this created mailbox. A message block can
* be send to a mailbox by a given MboxID. The MboxID must be unique
* in the whole system. If this MboxID is conflict with a created
* mailbox, the mailbox creation will fail and return NULL.
* MboxSize: The size of this mailbox to be created. It means maximum number
* of message blocks can be stored in this mailbox.
* pWakeSema: The semaphore to wake up the receiving task to receive the new
* message. If the receiving task doesn't need a semaphore to wakeup
* it, then just let this pointer is NULL.
* Return: The created mailbox pointer. If it failed, return NULL.
******************************************************************************/
PRTL_MAILBOX RtlMailboxCreate(
IN u8 MboxID,
IN u32 MboxSize,
IN _Sema *pWakeSema
)
{
PRTL_MAILBOX pMBox=NULL;
// if the Mailbox root entry initialed ? if not, initial it
if (!MBox_Entry.isInitialed) {
RtlMutexInit(&MBox_Entry.Mutex); // Init the Mutex for the mailbox add/delete procedure protection
RtlInitListhead(&MBox_Entry.mbox_list); // Init the link list head to chain all created mailbox
MBox_Entry.isInitialed = 1;
MSG_MBOX_INFO("MBox Entry Initial...\n");
}
// check if this mailbox ID is ocupied ?
pMBox = RtlMBoxIdToHdl(MboxID);
if (NULL != pMBox) {
MSG_MBOX_ERR("RtlMailboxCreate: The Mailbox ID %d is used by someone!!\n", MboxID);
return NULL;
}
pMBox = (RTL_MAILBOX *)RtlZmalloc(sizeof(RTL_MAILBOX));
if (NULL==pMBox) {
MSG_MBOX_ERR("RtlMailboxCreate: MAlloc Failed\n");
return NULL;
}
RtlInitListhead(&pMBox->mbox_list); // Init the link list to be chained into the created mailbox list
pMBox->mbox_id = MboxID;
pMBox->pWakeSema = pWakeSema;
#ifdef PLATFORM_FREERTOS
pMBox->mbox_hdl = xQueueCreate(MboxSize, sizeof(MSG_BLK));
if (NULL == pMBox->mbox_hdl) {
MSG_MBOX_ERR("RtlMailboxCreate: xQueueCreate Failed\n");
RtlMfree((void *)pMBox, sizeof(RTL_MAILBOX));
return NULL;
}
#endif
#ifdef PLATFORM_ECOS
// TODO: Create mailbox
#endif
// Add this mailbox to the link list of created mailbox
RtlDownMutex(&MBox_Entry.Mutex);
RtlListInsertTail(&pMBox->mbox_list, &MBox_Entry.mbox_list);
RtlUpMutex(&MBox_Entry.Mutex);
MSG_MBOX_INFO("A Mailbox Created: Size=%d\n", MboxSize);
return pMBox;
}
/******************************************************************************
* Function: RtlMailboxDel
* Desc: To delete a mailbox by a given mailbox handle.
* Para:
* MboxHdl: The handle of the mailbox to be deleted.
* Return: None.
******************************************************************************/
VOID RtlMailboxDel(
IN PRTL_MAILBOX MboxHdl
)
{
if (NULL == MboxHdl) {
MSG_MBOX_ERR("RtlMailboxDel: Try to delete a NULL mailbox\n");
return;
}
// Remove this mailbox from the link list of created mailbox
RtlDownMutex(&MBox_Entry.Mutex);
RtlListDelete(&MboxHdl->mbox_list);
RtlUpMutex(&MBox_Entry.Mutex);
// delete the Queue/Mailbox
#ifdef PLATFORM_FREERTOS
vQueueDelete((xQueueHandle)(MboxHdl->mbox_hdl));
#endif
#ifdef PLATFORM_ECOS
// TODO: Delete mailbox
#endif
RtlMfree((void *)MboxHdl, sizeof(RTL_MAILBOX));
}
/******************************************************************************
* Function: RtlMailboxSendToBack
* Desc: To put a message block to the tail of a given mailbox.
* Para:
* MboxID: The identifier of the target mailbox.
* pMsg: The pointer of the message block to be put into the mailbox.
* MSToWait: If the mailbox is full, this value gives a time to wait to put
* this message. The time unit is millisecond.
* The special values are:
* 0: no waiting;
* 0xffffffff: wait without timeout.
* If the waiting is timeout, the message sending is failed and
* return _FAIL.
* IsFromISR: Is this function is called from an ISR ?
* Return: _SUCCESS or _FAIL.
******************************************************************************/
u8 RtlMailboxSendToBack(
IN u8 MboxID,
IN MSG_BLK *pMsg,
IN u32 MSToWait,
IN u8 IsFromISR
)
{
RTL_MAILBOX *pMbox=NULL;
u32 wait_ticks;
#ifdef PLATFORM_FREERTOS
portBASE_TYPE ret;
#endif
pMbox = RtlMBoxIdToHdl(MboxID);
if (NULL == pMbox) {
MSG_MBOX_ERR("RtlMailboxSendToBack: Didn't find matched MBoxID=%d\n", MboxID);
return _FAIL;
}
#ifdef PLATFORM_FREERTOS
if (MBOX_WAIT_NO_TIMEOUT == MSToWait) {
wait_ticks = portMAX_DELAY;
}
else if (MBOX_WAIT_NONE == MSToWait) {
wait_ticks = 0;
}
else {
wait_ticks = ((MSToWait/portTICK_RATE_MS)>0)?(MSToWait/portTICK_RATE_MS):(1);
}
if (IsFromISR) {
ret = xQueueSendToBackFromISR(pMbox->mbox_hdl, (void *)pMsg, NULL);//(portTickType) wait_ticks);
}
else {
ret = xQueueSendToBack(pMbox->mbox_hdl, (void *)pMsg, (portTickType) wait_ticks);
}
if(ret != pdPASS ) {
// send message to the queue failed
MSG_MBOX_ERR("RtlMailboxSendToBack: Put Msg to Queue Failed, MBoxID=%d\n", MboxID);
ret = _FAIL;
}
else {
// try to give a semaphore to wake up the receiving task
if (pMbox->pWakeSema) {
RtlUpSema(pMbox->pWakeSema);
}
ret = _SUCCESS;
}
return ret;
#endif
#ifdef PLATFORM_ECOS
// TODO: Put the message to a mailbox
#endif
}
/******************************************************************************
* Function: RtlMailboxSendToFront
* Desc: To put a message block to the head of a mailbox.
* Para:
* MboxID: The identifier of the target mailbox.
* pMsg: The pointer of the message block to be put into the mailbox.
* MSToWait: If the mailbox is full, this value gives a time to wait to put
* this message. The time unit is millisecond.
* The special values are:
* 0: no waiting;
* 0xffffffff: wait without timeout.
* If the waiting is timeout, the message sending is failed and
* return _FAIL.
* IsFromISR: Is this function is called from an ISR ?
* Return: _SUCCESS or _FAIL.
******************************************************************************/
u8 RtlMailboxSendToFront(
IN u8 MboxID,
IN MSG_BLK *pMsg,
IN u32 MSToWait,
IN u8 IsFromISR
)
{
RTL_MAILBOX *pMbox=NULL;
u32 wait_ticks;
#ifdef PLATFORM_FREERTOS
portBASE_TYPE ret;
#endif
pMbox = RtlMBoxIdToHdl(MboxID);
if (NULL == pMbox) {
MSG_MBOX_ERR("RtlMailboxSendToBack: Didn't find matched MBoxID=%d\n", MboxID);
return _FAIL;
}
#ifdef PLATFORM_FREERTOS
if (MBOX_WAIT_NO_TIMEOUT == MSToWait) {
wait_ticks = portMAX_DELAY;
}
else if (MBOX_WAIT_NONE == MSToWait) {
wait_ticks = 0;
}
else {
wait_ticks = ((MSToWait/portTICK_RATE_MS)>0)?(MSToWait/portTICK_RATE_MS):(1);
}
if (IsFromISR) {
ret = xQueueSendToFrontFromISR(pMbox->mbox_hdl, (void *)pMsg, NULL);//(portTickType) wait_ticks);
}
else {
ret = xQueueSendToFront(pMbox->mbox_hdl, (void *)pMsg, (portTickType) wait_ticks);
}
if(ret != pdPASS ) {
// send message to the queue failed
MSG_MBOX_ERR("RtlMailboxSendToBack: Put Msg to Queue Failed, MBoxID=%d\n", MboxID);
ret = _FAIL;
}
else {
// try to give a semaphore to wake up the receiving task
if (pMbox->pWakeSema) {
RtlUpSema(pMbox->pWakeSema);
}
ret = _SUCCESS;
}
return ret;
#endif
#ifdef PLATFORM_ECOS
// TODO: eCos has no API to put message to the head of a mailbox
#endif
}
/******************************************************************************
* Function: RtlMailboxSendToFront
* Desc: To get a message block from a given mailbox.
* Para:
* MboxID: The identifier of the target mailbox.
* pMsg: The message block to store the gotten message.
* MSToWait: If the mailbox is full, this value gives a time to wait to put
* this message. The time unit is millisecond.
* The special values are:
* 0: no waiting;
* 0xffffffff: wait without timeout.
* If the waiting is timeout, the message sending is failed and
* return _FAIL.
* IsFromISR: Is this function is called from an ISR ?
* Return: _SUCCESS or _FAIL.
******************************************************************************/
u8 RtlMailboxReceive(
IN u8 MboxID,
OUT MSG_BLK *pMsg,
IN u32 MSToWait,
IN u8 IsFromISR
)
{
RTL_MAILBOX *pMbox=NULL;
u32 wait_ticks;
#ifdef PLATFORM_FREERTOS
portBASE_TYPE ret;
#endif
pMbox = RtlMBoxIdToHdl(MboxID);
if (NULL == pMbox) {
MSG_MBOX_ERR("RtlMailboxReceive: Didn't find the MBox with ID=%d\n", MboxID);
return _FAIL;
}
#ifdef PLATFORM_FREERTOS
if (MBOX_WAIT_NONE == MSToWait) {
wait_ticks = 0;
}
else if (MBOX_WAIT_NO_TIMEOUT == MSToWait) {
wait_ticks = portMAX_DELAY;
}
else {
wait_ticks = ((MSToWait/portTICK_RATE_MS)>0)?(MSToWait/portTICK_RATE_MS):(1);
}
if (IsFromISR) {
ret = xQueueReceiveFromISR(pMbox->mbox_hdl, (void *)pMsg, NULL);//( portTickType ) wait_ticks);
}
else {
ret = xQueueReceive(pMbox->mbox_hdl, (void *)pMsg, ( portTickType ) wait_ticks);
}
if(ret != pdTRUE ) {
// receive message failed
if (0 != MSToWait) {
MSG_MBOX_ERR("RtlMailboxReceive: Receive Msg Failed, MBoxID=%d\n", MboxID);
}
ret = _FAIL;
}
else {
ret = _SUCCESS;
}
return ret;
#endif
#ifdef PLATFORM_ECOS
// TODO: Get a message from the mailbox
#endif
}
/******************************************************************************
* Function: RtlMailboxPeek
* Desc: To copy the head message from a given mailbox without move this
* message block out from the mailbox.
* Para:
* MboxID: The identifier of the target mailbox.
* pMsg: The message block to store the gotten message.
* MSToWait: If the mailbox is full, this value gives a time to wait to put
* this message. The time unit is millisecond.
* The special values are:
* 0: no waiting;
* 0xffffffff: wait without timeout.
* If the waiting is timeout, the message sending is failed and
* return _FAIL.
* IsFromISR: Is this function is called from an ISR ?
* Return: _SUCCESS or _FAIL.
******************************************************************************/
u8 RtlMailboxPeek(
IN u8 MboxID,
OUT MSG_BLK *pMsg,
IN u32 MSToWait,
IN u8 IsFromISR
)
{
RTL_MAILBOX *pMbox=NULL;
u32 wait_ticks;
#ifdef PLATFORM_FREERTOS
portBASE_TYPE ret;
#endif
pMbox = RtlMBoxIdToHdl(MboxID);
if (NULL == pMbox) {
MSG_MBOX_ERR("RtlMailboxPeek: Didn't find the MBox with ID=%d\n", MboxID);
return _FAIL;
}
#ifdef PLATFORM_FREERTOS
if (MBOX_WAIT_NONE == MSToWait) {
wait_ticks = 0;
}
else if (MBOX_WAIT_NO_TIMEOUT == MSToWait) {
wait_ticks = portMAX_DELAY;
}
else {
wait_ticks = ((MSToWait/portTICK_RATE_MS)>0)?(MSToWait/portTICK_RATE_MS):(1);
}
if (IsFromISR) {
// ret = xQueuePeekFromISR(pMbox->mbox_hdl, (void *)pMsg, ( portTickType ) wait_ticks);
// TODO: check why we have no "xQueuePeekFromISR"
MSG_MBOX_ERR("RtlMailboxPeek: Current version has no 'xQueuePeekFromISR'\n");
ret = pdFALSE;
}
else {
ret = xQueuePeek(pMbox->mbox_hdl, (void *)pMsg, ( portTickType ) wait_ticks);
}
if(ret != pdTRUE ) {
// receive message failed
MSG_MBOX_ERR("RtlMailboxReceive: Receive Msg Failed, MBoxID=%d\n", MboxID);
ret = _FAIL;
}
else {
ret = _SUCCESS;
}
return ret;
#endif
#ifdef PLATFORM_ECOS
// TODO: Get a message from the mailbox
#endif
}
/******************************************************************************
* Function: RtlMailboxMsgWaiting
* Desc: To get the number of message blocks are storing in a given mailbox.
* Para:
* MboxID: The identifier of the target mailbox.
* IsFromISR: Is this function is called from an ISR ?
* Return: The number of message blocks are storing in this mailbox.
******************************************************************************/
u32 RtlMailboxMsgWaiting(
IN u8 MboxID,
IN u8 IsFromISR
)
{
RTL_MAILBOX *pMbox=NULL;
u32 msg_num=0;
pMbox = RtlMBoxIdToHdl(MboxID);
if (NULL == pMbox) {
MSG_MBOX_ERR("RtlMailboxMsgWaiting: Didn't find the MBox with ID=%d\n", MboxID);
return 0;
}
#ifdef PLATFORM_FREERTOS
if (IsFromISR) {
msg_num = uxQueueMessagesWaitingFromISR(pMbox->mbox_hdl);
}
else {
msg_num = uxQueueMessagesWaiting(pMbox->mbox_hdl);
}
#endif
#ifdef PLATFORM_ECOS
// TODO: call eCos API to implement this function
#endif
return msg_num;
}

View file

@ -0,0 +1,127 @@
/******************************************************************************
*
* Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
*
*
******************************************************************************/
#ifndef __MAILBOX_H_
#define __MAILBOX_H_
#include "hal_api.h"
#include "osdep_api.h"
#include "hal_util.h"
#ifdef PLATFORM_FREERTOS
#include "queue.h"
#endif
#define MBOX_WAIT_NO_TIMEOUT 0xffffffff // waiting for send/receive message with no timeout
#define MBOX_WAIT_NONE 0 // No wait for send/receive message
typedef enum _MAILBOX_ID_ {
MBOX_ID_WLAN = 0,
MBOX_ID_UART = 1,
MBOX_ID_I2C = 2,
MBOX_ID_I2S = 3,
MBOX_ID_SPI = 4,
MBOX_ID_SDIO = 5,
MBOX_ID_SDIO_MP = 6,
MBOX_ID_MAX = 0xff
} MAILBOX_ID;
#if defined(CONFIG_SDIO_DEVICE_EN) && defined(CONFIG_SDIO_DEVICE_NORMAL)
typedef enum _MSG_TYPE_SDIO {
MSG_SDIO_RX_PKT=1, // request to send a SDIO RX packet to the host side
MSG_SDIO_C2H=2, // request to send a C2H message
MSG_SDIO_RPWM=3, // request to set the RPWM
MSG_SDIO_MP_LOOP_TXPKT=4, // request to loopback this TX packet
MSG_SDIO_MAX=0xff
} MSG_TYPE_SDIO;
#endif // end of "#ifdef CONFIG_SDIO_DEVICE_EN"
/* the data structure of a MailBox to deliver message blocks */
typedef struct _RTL_MAILBOX_ {
void *mbox_hdl; // the mailbox handle which return from OS create queue API
_Sema *pWakeSema; // the semaphore to wakeup the message receiving task
_LIST mbox_list; // the link list to chain all created mailbox
u8 mbox_id; /* the ID of this Mailbox, this ID is
used to locate the MBox for send/get message */
} RTL_MAILBOX, *PRTL_MAILBOX;
/* the data structure of a message block */
typedef struct _RTL_MSG_BLK {
u8 MsgType; // the message type
u8 Reserved; // reserved
u16 DateLen; // the vaild data length of the pBuf
u32 Para; // the optional parameters associated with this message type
u8 *pBuf; // point to a data buffer associated with this message type
} MSG_BLK, *PMSG_BLK;
/* the data structure for system level message block management */
typedef struct _RTL_MBOX_ROOT_ {
_LIST mbox_list; // the link list of all created mailbox
_Mutex Mutex; // the Mutex to protect the mailbox create/delete procedure
u8 isInitialed; // is this Mailbox link-list initialed
} RTL_MBOX_ROOT, *PRTL_MBOX_ROOT;
// Export Funcction API
extern PRTL_MAILBOX RtlMailboxCreate(
IN u8 MboxID,
IN u32 MboxSize,
IN _Sema *pWakeSema
);
extern VOID RtlMailboxDel(
IN PRTL_MAILBOX MboxHdl
);
extern u8 RtlMailboxSendToBack(
IN u8 MboxID,
IN MSG_BLK *pMsg,
IN u32 MSToWait,
IN u8 IsFromISR
);
extern u8 RtlMailboxSendToFront(
IN u8 MboxID,
IN MSG_BLK *pMsg,
IN u32 MSToWait,
IN u8 IsFromISR
);
extern u8 RtlMailboxReceive(
IN u8 MboxID,
OUT MSG_BLK *pMsg,
IN u32 MSToWait,
IN u8 IsFromISR
);
extern u8 RtlMailboxPeek(
IN u8 MboxID,
OUT MSG_BLK *pMsg,
IN u32 MSToWait,
IN u8 IsFromISR
);
extern u32 RtlMailboxMsgWaiting(
IN u8 MboxID,
IN u8 IsFromISR
);
#endif // #ifndef __MAILBOX_H_

View file

@ -0,0 +1,36 @@
/******************************************************************************
*
* Name: sys-support.h - System type support for Linux
* $Revision: 1.1.1.1 $
*
*****************************************************************************/
#ifndef __OS_SUPPORT_H__
#define __OS_SUPPORT_H__
#include <FreeRTOS.h>
#include <basic_types.h>
#include "task.h"
#include "osdep_service.h"
#define RTL_HZ 100
#define RtlKmalloc(size, flag) pvPortMalloc(size)
#define RtlKfree(pv) vPortFreeAligned(pv)
#ifdef CONFIG_TIMER_MODULE
#define __Delay(t) HalDelayUs(t)
#else
static __inline__ u32 __Delay(u32 us)
{
DBG_8195A("No Delay: please enable hardware Timer\n");
}
#endif
#define Mdelay(t) __Delay(t*1000)
#define Udelay(t) __Delay(t)
#endif /* __SYS_SUPPORT_H__ */

View file

@ -0,0 +1,165 @@
/******************************************************************************
*
* Name: sys-support.h - System type support for Linux
* $Revision: 1.1.1.1 $
*
*****************************************************************************/
#ifndef __OS_TIMER_H__
#define __OS_TIMER_H__
#include "diag.h"
#include "os_support.h"
#include "osdep_service.h"
#define JIFFIES xTaskGetTickCount()
enum {
TIMER_NO_INIT = 0,
TIMER_INIT = 1,
TIMER_START = 2,
TIMER_DISABLE = 3
};
struct TIMER_LIST {
_timerHandle TimeHdl;
u32 Flag;
unsigned long Data;
VOID (*Function)(void *);
u32 TimerID;
};
static inline VOID InitTimer(IN struct TIMER_LIST *Timer)
{
u32 TimerID = Timer->TimerID;
VOID (*Function)(VOID *) = Timer->Function;
save_and_cli();
if (Timer->Flag != TIMER_DISABLE) {
if (Timer->Flag == TIMER_NO_INIT) {
Timer->TimeHdl = rtw_timerCreate( (const char *)"Timer", // Just a test name, not used by the kernel.
( 100 ), // The timer period in ticks.
_FALSE, // The timers will auto-reload themselves when they expire.
( void * ) TimerID, // Assign each timer a unique id equal to its array index.
Function
#ifdef RTK_MODE_TIMER
,data // Each timer calls the same callback when it expires.
#endif
);
if (NULL == Timer->TimeHdl) {
DBG_ERROR_LOG("\rInitial Timer fail!\n");
}
else {
TimerID++;
}
Timer->Flag = TIMER_INIT;
}
else if (Timer->Flag == TIMER_START) {
rtw_timerStop(Timer->TimeHdl,0);
Timer->Flag = TIMER_DISABLE;
}
}
restore_flags();
}
static inline void ModTimer(IN struct TIMER_LIST *Timer, IN u32 TimeoutTicks)
{
#ifndef PLATFORM_FREERTOS
u32 Flags;
#endif
void (*Function)(void *) = Timer->Function;
save_and_cli();
if (Timer->Flag == TIMER_NO_INIT) {
if (Timer->Function) {
Timer->TimeHdl = rtw_timerCreate((const char *)"Timer", // Just a text name, not used by the kernel.
( 100 ), // The timer period in ticks.
_FALSE, // The timers will auto-reload themselves when they expire.
( void * ) Timer->TimerID, // Assign each timer a unique id equal to its array index.
Function
#ifdef RTK_MODE_TIMER
,Timer->Data // Each timer calls the same callback when it expires.
#endif
);
if (NULL == Timer->TimeHdl) {
DBG_ERROR_LOG("\rInitial Timer fail!\n");
}
else {
Timer->TimerID++;
}
Timer->Flag = TIMER_INIT;
}
else {
restore_flags();
return;
}
}
else if (Timer->Flag == TIMER_START) {
rtw_timerStop(Timer->TimeHdl,0);
Timer->Flag = TIMER_DISABLE;
}
TimeoutTicks -= rtw_get_current_time();
if (TimeoutTicks <= 0)
TimeoutTicks = 2;
if (xTimerStart(Timer->TimeHdl, TimeoutTicks ))
Timer->Flag = TIMER_START;
else
DBG_ERROR_LOG("\rmod_timer() - no slots available\n");
restore_flags();
}
static inline int TimerPending (IN const struct TIMER_LIST *Timer)
{
if (Timer->TimeHdl && Timer->Flag != TIMER_NO_INIT)
return 1;
else
return 0;
}
static inline void DelTimerSync(IN struct TIMER_LIST *Timer)
{
save_and_cli();
if (Timer->TimeHdl && Timer->Flag != TIMER_INIT) {
if (Timer->Flag == TIMER_START)
rtw_timerStop(Timer->TimeHdl, 0);
rtw_timerDelete(Timer->TimeHdl, 0);
Timer->Flag = TIMER_NO_INIT;
}
restore_flags();
}
/*
* These inlines deal with timer wrapping correctly. You are
* strongly encouraged to use them
* 1. Because people otherwise forget
* 2. Because if the timer wrap changes in future you wont have to
* alter your driver code.
*
* time_after(a,b) returns true if the time a is after time b.
*
* Do this with "<0" and ">=0" to only test the sign of the result. A
* good compiler would generate better code (and a really good compiler
* wouldn't care). Gcc is currently neither.
*/
#define TIME_AFTER(a,b) ((long)(b) - (long)(a) < 0)
#define TIMER_BEFORE(a,b) TIME_AFTER(b,a)
#define TIME_AFTER_EQ(a,b) ((long)(a) - (long)(b) >= 0)
#define TIMER_BEFORE_EQ(a,b) TIME_AFTER_EQ(b,a)
#endif //__OS_TIMER_H__

View file

@ -0,0 +1,535 @@
/******************************************************************************
*
* Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
*
*
******************************************************************************/
#define _OSDEP_API_C_
#include <osdep_api.h>
#include "osdep_service.h"
extern _LONG_CALL_ char *_strcpy(char *dest, const char *src);
extern _LONG_CALL_ VOID *_memset(void *dst0, int Val,SIZE_T length);
u8* RtlMalloc(IN u32 sz)
{
u8 *pbuf=NULL;
pbuf = rtw_malloc((u32)sz);
return pbuf;
}
u8* RtlZmalloc(IN u32 sz)
{
u8 *pbuf;
pbuf= rtw_malloc((u32)sz);
if (pbuf != NULL) {
_memset(pbuf, 0, sz);
}
return pbuf;
}
VOID RtlMfree(IN u8 *pbuf, IN u32 sz)
{
rtw_mfree(pbuf, sz);
}
VOID* RtlMalloc2d(IN u32 h, IN u32 w, IN u32 size)
{
u32 j;
VOID **a = (VOID **) rtw_malloc2d(h, w, size);
if(a == NULL)
{
DBG_ERROR_LOG("%s: alloc memory fail!\n", __FUNCTION__);
return NULL;
}
return a;
}
VOID RtlMfree2d(IN VOID *pbuf, IN u32 h, IN u32 w, IN u32 size)
{
rtw_mfree2d(pbuf, h, w, size);
}
VOID RtlInitSema(IN _Sema *sema, IN u32 init_val)
{
rtw_init_sema(sema, init_val);
}
VOID RtlFreeSema(IN _Sema *sema)
{
rtw_free_sema(sema);
}
VOID RtlUpSema(IN _Sema *sema)
{
rtw_up_sema(sema);
}
VOID RtlUpSemaFromISR(IN _Sema *sema)
{
rtw_up_sema_from_isr(sema);
}
u32 RtlDownSema(IN _Sema *sema)
{
rtw_down_sema(sema);
return _SUCCESS;
}
u32 RtlDownSemaWithTimeout(IN _Sema *sema,IN u32 ms)
{
return rtw_down_timeout_sema(sema, ms);
}
VOID RtlMutexInit(IN _Mutex *pmutex)
{
rtw_mutex_init(pmutex);
}
VOID RtlMutexFree(IN _Mutex *pmutex)
{
rtw_mutex_free(pmutex);
}
VOID RtlSpinlockInit(IN _Lock *plock)
{
rtw_spinlock_init((_lock *)plock);
}
VOID RtlSpinlockFree(IN _Lock *plock)
{
rtw_spinlock_free((_lock *)plock);
}
VOID RtlSpinlock(IN _Lock *plock)
{
rtw_spin_lock((_lock *)plock);
}
VOID RtlSpinunlock(IN _Lock *plock)
{
rtw_spin_unlock((_lock *)plock);
}
VOID RtlSpinlockEx(IN _Lock *plock)
{
}
VOID RtlSpinunlockEx(IN _Lock *plock)
{
}
u32 RtlGetCurrentTime(VOID)
{
return rtw_get_current_time();
}
VOID RtlSleepSchedulable(IN u32 ms)
{
}
VOID RtlMsleepOS(IN u32 ms)
{
rtw_msleep_os(ms);
}
VOID RtlUsleepOS(IN u32 us)
{
rtw_usleep_os(us);
}
VOID RtlMdelayOS(IN u32 ms)
{
rtw_mdelay_os(ms);
}
VOID RtlUdelayOS(IN u32 us)
{
rtw_udelay_os(us);
}
VOID RtlYieldOS(VOID)
{
rtw_yield_os();
}
#if defined(__ICCARM__)
u64 RtlModular64(IN u64 n, IN u64 base)
{
unsigned int __base = (base);
unsigned int __rem;
//(void)(((typeof((n)) *)0) == ((__uint64_t *)0));
if (((n) >> 32) == 0) {
__rem = (unsigned int)(n) % __base;
(n) = (unsigned int)(n) / __base;
} else
__rem = __Div64_32(&(n), __base);
return __rem;
}
#else
u64 RtlModular64(IN u64 x, IN u64 y)
{
return rtw_modular64(x, y);
}
#endif
/******************************************************************************
* Function: RtlTimerCallbckEntry
* Desc: This function is a timer callback wrapper. All OS timer callback
* will call this function and then call the real callback function inside
* this function.
*
* Para:
* pxTimer: The FreeRTOS timer handle which is expired and call this callback.
*
* Return: None
*
******************************************************************************/
#ifdef PLATFORM_FREERTOS
void RtlTimerCallbckEntry (IN _timerHandle pxTimer)
{
PRTL_TIMER pTimer;
if (NULL == pxTimer) {
MSG_TIMER_ERR("RtlTimerCallbckEntry: NULL Timer Handle Err!\n");
return;
}
pTimer = (PRTL_TIMER) rtw_timerGetID( pxTimer );
pTimer->CallBackFunc(pTimer->Context);
}
#endif // end of "#ifdef PLATFORM_FREERTOS"
/******************************************************************************
* Function: RtlTimerCreate
* Desc: To create a software timer.
*
* Para:
* pTimerName: A string for the timer name.
* TimerPeriodMS: The timer period, the unit is milli-second.
* CallbckFunc: The callback function of this timer.
* pContext: A pointer will be used as the parameter to call the timer
* callback function.
* isPeriodical: Is this timer periodical ? (Auto reload after expired)
* Return: The created timer handle, a pointer. It can be used to delete the
* timer. If timer createion failed, return NULL.
*
******************************************************************************/
PRTL_TIMER RtlTimerCreate(
IN char *pTimerName,
IN u32 TimerPeriodMS,
IN RTL_TIMER_CALL_BACK CallbckFunc,
IN void *pContext,
IN u8 isPeriodical)
{
PRTL_TIMER pTimer;
u32 timer_ticks;
int i;
pTimer = (PRTL_TIMER)RtlZmalloc(sizeof(RTL_TIMER));
if (NULL == pTimer) {
MSG_TIMER_ERR("RtlTimerCreate: Alloc Mem Err!\n");
return NULL;
}
if (portTICK_RATE_MS >= TimerPeriodMS) {
timer_ticks = 1; // at least 1 system tick
}
else {
timer_ticks = TimerPeriodMS/portTICK_RATE_MS;
}
pTimer->TimerHandle = rtw_timerCreate ((const char*)(pTimer->TimerName), timer_ticks,
(portBASE_TYPE)isPeriodical, (void *) pTimer, RtlTimerCallbckEntry);
#ifdef PLATFORM_FREERTOS // if any RTOS is used
if (pTimer->TimerHandle) {
pTimer->msPeriod = TimerPeriodMS;
pTimer->CallBackFunc = CallbckFunc;
pTimer->Context = pContext;
pTimer->isPeriodical = isPeriodical;
// copy the timer name
if (NULL != pTimerName) {
for(i = 0; i < sizeof(pTimer->TimerName); i++)
{
pTimer->TimerName[i] = pTimerName[i];
if(pTimerName[i] == '\0')
{
break;
}
}
}
else {
_strcpy((char*)(pTimer->TimerName), "None");
}
MSG_TIMER_INFO("RtlTimerCreate: SW Timer Created: Name=%s Period=%d isPeriodical=%d\n", \
pTimer->TimerName, pTimer->msPeriod, pTimer->isPeriodical);
}
else
#endif
{
RtlMfree((u8 *)pTimer, sizeof(RTL_TIMER));
pTimer = NULL;
MSG_TIMER_ERR("RtlTimerCreate: OS Create Timer Failed!\n");
}
return (pTimer);
}
/******************************************************************************
* Function: RtlTimerDelete
* Desc: To delete a created software timer.
*
* Para:
* pTimerHdl: The timer to be deleted
*
* Return: None
*
******************************************************************************/
VOID RtlTimerDelete(IN PRTL_TIMER pTimerHdl)
{
#ifdef PLATFORM_FREERTOS
portBASE_TYPE ret;
#endif
if (NULL == pTimerHdl) {
MSG_TIMER_ERR("RtlTimerDelete: NULL Timer Handle!\n");
return;
}
MSG_TIMER_INFO("RtlTimerDelete: Name=%s\n", pTimerHdl->TimerName);
#ifdef PLATFORM_FREERTOS
/* try to delete the soft timer and wait max RTL_TIMER_API_MAX_BLOCK_TICKS
to send the delete command to the timer command queue */
ret = rtw_timerDelete(pTimerHdl->TimerHandle, RTL_TIMER_API_MAX_BLOCK_TICKS);
if (pdPASS != ret) {
MSG_TIMER_ERR("RtlTimerDelete: Delete OS Timer Failed!\n");
}
#endif
RtlMfree((u8 *)pTimerHdl, sizeof(RTL_TIMER));
}
/******************************************************************************
* Function: RtlTimerStart
* Desc: To start a created timer..
*
* Para:
* pTimerHdl: The timer to be started.
* isFromISR: The flag to indicate that is this function is called from an ISR.
*
* Return: _SUCCESS or _FAIL
*
******************************************************************************/
u8 RtlTimerStart(IN PRTL_TIMER pTimerHdl, IN u8 isFromISR)
{
#ifdef PLATFORM_FREERTOS
u8 ret=_FAIL;
portBASE_TYPE HigherPriorityTaskWoken=pdFALSE;
if (isFromISR) {
if (pdPASS == rtw_timerStartFromISR(pTimerHdl->TimerHandle,&HigherPriorityTaskWoken))
{
// start OS timer successful
if (pdFALSE != HigherPriorityTaskWoken) {
rtw_yield_os();
}
ret = _SUCCESS;
}
else {
MSG_TIMER_ERR("RtlTimerStart: Start Timer(%s) from ISR failed\n", pTimerHdl->TimerName);
}
}
else {
if (pdPASS == rtw_timerStart(pTimerHdl->TimerHandle, RTL_TIMER_API_MAX_BLOCK_TICKS)) {
ret = _SUCCESS;
}
else {
MSG_TIMER_ERR("RtlTimerStart: Start Timer(%s) failed\n", pTimerHdl->TimerName);
}
}
MSG_TIMER_INFO("RtlTimerStart: SW Timer %s Started\n", pTimerHdl->TimerName);
return ret;
#endif
}
/******************************************************************************
* Function: RtlTimerStop
* Desc: To stop a running timer..
*
* Para:
* pTimerHdl: The timer to be stoped.
* isFromISR: The flag to indicate that is this function is called from an ISR.
*
* Return: _SUCCESS or _FAIL
*
******************************************************************************/
u8 RtlTimerStop(IN PRTL_TIMER pTimerHdl, IN u8 isFromISR)
{
#ifdef PLATFORM_FREERTOS
u8 ret=_FAIL;
portBASE_TYPE HigherPriorityTaskWoken=pdFALSE;
if (isFromISR) {
if (pdPASS == rtw_timerStopFromISR(pTimerHdl->TimerHandle,&HigherPriorityTaskWoken))
{
// start OS timer successful
if (pdFALSE != HigherPriorityTaskWoken) {
rtw_yield_os();
}
ret = _SUCCESS;
}
}
else {
if (pdPASS == rtw_timerStop(pTimerHdl->TimerHandle, RTL_TIMER_API_MAX_BLOCK_TICKS)) {
ret = _SUCCESS;
}
}
if (_FAIL == ret) {
MSG_TIMER_ERR("RtlTimerStop: Stop Timer(%s) Failed, IsFromISR=%d\n", pTimerHdl->TimerName, isFromISR);
}
MSG_TIMER_INFO("RtlTimerStop: SW Timer %s Stoped\n", pTimerHdl->TimerName);
return ret;
#endif
}
/******************************************************************************
* Function: RtlTimerReset
* Desc: To reset a timer. A reset will get a re-start and reset
* the timer ticks counting. A running timer expired time is relative
* to the time when Reset function be called. Please ensure the timer
* is in active state (Started). A stopped timer also will be started
* when this function is called.
*
* Para:
* pTimerHdl: The timer to be reset.
* isFromISR: The flag to indicate that is this function is called from an ISR.
*
* Return: _SUCCESS or _FAIL
*
******************************************************************************/
u8
RtlTimerReset(
IN PRTL_TIMER pTimerHdl,
IN u8 isFromISR
)
{
#ifdef PLATFORM_FREERTOS
u8 ret=_FAIL;
portBASE_TYPE HigherPriorityTaskWoken=pdFALSE;
if (isFromISR) {
if (pdPASS == rtw_timerResetFromISR(pTimerHdl->TimerHandle,&HigherPriorityTaskWoken))
{
// start OS timer successful
if (pdFALSE != HigherPriorityTaskWoken) {
rtw_yield_os();
}
ret = _SUCCESS;
}
}
else {
if (pdPASS == rtw_timerReset(pTimerHdl->TimerHandle, RTL_TIMER_API_MAX_BLOCK_TICKS)) {
ret = _SUCCESS;
}
}
if (_FAIL == ret) {
MSG_TIMER_ERR("RtlTimerReset: Reset Timer(%s) Failed, IsFromISR=%d\n", pTimerHdl->TimerName, isFromISR);
}
MSG_TIMER_INFO("RtlTimerReset: SW Timer %s Reset\n", pTimerHdl->TimerName);
return ret;
#endif
}
/******************************************************************************
* Function: RtlTimerChangePeriod
* Desc: To change the period of a timer that was created previously.
*
* Para:
* pTimerHdl: The timer handle to be changed the priod.
* NewPeriodMS: The new timer period, in milli-second.
* isFromISR: The flag to indicate that is this function is called from an ISR.
*
* Return: _SUCCESS or _FAIL
*
******************************************************************************/
u8 RtlTimerChangePeriod(
IN PRTL_TIMER pTimerHdl,
IN u32 NewPeriodMS,
IN u8 isFromISR)
{
#ifdef PLATFORM_FREERTOS
u32 timer_ticks;
u8 ret=_FAIL;
portBASE_TYPE HigherPriorityTaskWoken=pdFALSE;
if (portTICK_RATE_MS >= NewPeriodMS) {
timer_ticks = 1; // at least 1 system tick
}
else {
timer_ticks = NewPeriodMS/portTICK_RATE_MS;
}
if (isFromISR) {
if (pdPASS == rtw_timerChangePeriodFromISR(pTimerHdl->TimerHandle, timer_ticks, &HigherPriorityTaskWoken))
{
// start OS timer successful
if (pdFALSE != HigherPriorityTaskWoken) {
taskYIELD();
}
ret = _SUCCESS;
}
}
else {
if (pdPASS == rtw_timerChangePeriod(pTimerHdl->TimerHandle, timer_ticks, RTL_TIMER_API_MAX_BLOCK_TICKS)) {
ret = _SUCCESS;
}
}
if (_FAIL == ret) {
MSG_TIMER_ERR("RtlTimerChangePeriod: Change Timer(%s) Period Failed, IsFromISR=%d\n", pTimerHdl->TimerName, isFromISR);
}
else {
pTimerHdl->msPeriod = NewPeriodMS;
MSG_TIMER_INFO("RtlTimerChangePeriod: SW Timer %s change period to %d\n", pTimerHdl->TimerName, pTimerHdl->msPeriod);
}
return ret;
#endif
}

View file

@ -0,0 +1,362 @@
/******************************************************************************
*
* Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
*
*
******************************************************************************/
#ifndef __OSDEP_API_H_
#define __OSDEP_API_H_
#include "os_timer.h"
#include "os_support.h"
#include "osdep_service.h"
#define MAX_SEMA_COUNT 32 /* the maximum count of a semaphore */
typedef _sema _Sema;
typedef _mutex _Mutex;
typedef u32 _Lock;
typedef struct TIMER_LIST _Timer;
typedef unsigned long _IRQL;
typedef _thread_hdl_ _THREAD_HDL_;
typedef VOID THREAD_RETURN;
typedef VOID THREAD_CONTEXT;
#ifndef mdelay
#define mdelay(t) ((t/portTICK_RATE_MS)>0)?(vTaskDelay(t/portTICK_RATE_MS)):(vTaskDelay(1))
#endif
#ifndef udelay
#define udelay(t) ((t/(portTICK_RATE_MS*1000))>0)?vTaskDelay(t/(portTICK_RATE_MS*1000)):(vTaskDelay(1))
#endif
/* to delete/start/stop a timer it will send a message to the timer task through a message queue,
so we define the max wait time for message sending */
#define RTL_TIMER_API_MAX_BLOCK_TIME 1000 // unit is ms
#define RTL_TIMER_API_MAX_BLOCK_TICKS (RTL_TIMER_API_MAX_BLOCK_TIME/portTICK_RATE_MS)
typedef VOID (*RTL_TIMER_CALL_BACK)(void *pContext);
typedef struct _RTL_TIMER{
#ifdef PLATFORM_FREERTOS
_timerHandle TimerHandle; // The timer handle of created FreeRTOS soft-timer
#endif
RTL_TIMER_CALL_BACK CallBackFunc; // Callback function of this timer
u32 msPeriod; // The period of this timer
void *Context; // Timer specific context.
u8 isPeriodical; // Is a periodical timer
u8 TimerName[35]; // The Name of timer
}RTL_TIMER, *PRTL_TIMER;
__inline static VOID RtlEnterCritical(VOID)
{
rtw_enter_critical(NULL, NULL);
}
__inline static VOID RtlExitCritical(VOID)
{
rtw_exit_critical(NULL, NULL);
}
__inline static VOID RtlEnterCriticalBh(IN _Lock *plock, IN _IRQL *pirqL)
{
rtw_enter_critical_bh((_lock *)plock, pirqL);
}
__inline static VOID RtlExitCriticalBh(IN _Lock *plock, IN _IRQL *pirqL)
{
rtw_exit_critical_bh((_lock *)plock, pirqL);
}
__inline static u32 RtlEnterCriticalMutex(IN _Mutex *pmutex, IN _IRQL *pirqL)
{
return rtw_enter_critical_mutex(pmutex, pirqL);
}
__inline static VOID RtlExitCriticalMutex(IN _Mutex *pmutex,IN _IRQL *pirqL)
{
rtw_exit_critical_mutex(pmutex, pirqL);
}
__inline static VOID RtlInitTimer(
IN _Timer *ptimer,
IN VOID *Data,
IN VOID (*pfunc)(VOID *),
IN VOID* cntx
)
{
ptimer->Function = pfunc;
ptimer->Data = (unsigned long)cntx;
InitTimer(ptimer);
}
__inline static VOID RtlSetTimer(
IN _Timer *ptimer,
IN u32 delay_time
)
{
ModTimer(ptimer , (JIFFIES+(delay_time*RTL_HZ/1000)));
}
__inline static VOID RtlCancelTimer(
IN _Timer *ptimer,
IN u8 *bcancelled
)
{
DelTimerSync(ptimer);
*bcancelled= _TRUE;//TRUE ==1; FALSE==0
}
__inline static u32 RtlSystime2Ms(IN u32 systime)
{
return rtw_systime_to_ms(systime);
}
__inline static u32 RtlMs2Systime(IN u32 ms)
{
return rtw_ms_to_systime(ms);
}
extern u8* RtlZmalloc(u32 sz);
extern u8* RtlMalloc(u32 sz);
extern VOID RtlMfree(u8 *pbuf, u32 sz);
extern VOID* RtlMalloc2d(u32 h, u32 w, u32 size);
extern VOID RtlMfree2d(VOID *pbuf, u32 h, u32 w, u32 size);
extern VOID RtlInitSema(_Sema *sema, u32 init_val);
extern VOID RtlFreeSema(_Sema *sema);
extern VOID RtlUpSema(_Sema *sema);
extern VOID RtlUpSemaFromISR(_Sema *sema);
extern u32 RtlDownSema(_Sema *sema);
extern u32 RtlDownSemaWithTimeout(_Sema *sema, u32 ms);
extern VOID RtlMutexInit(_Mutex *pmutex);
extern VOID RtlMutexFree(_Mutex *pmutex);
extern VOID RtlSpinlockInit(_Lock *plock);
extern VOID RtlSpinlockFree(_Lock *plock);
extern VOID RtlSpinlock(_Lock *plock);
extern VOID RtlSpinunlock(_Lock *plock);
extern VOID RtlSpinlockEx(_Lock *plock);
extern VOID RtlSpinunlockEx(_Lock *plock);
extern VOID RtlSleepSchedulable(u32 ms);
extern VOID RtlMsleepOS(u32 ms);
extern VOID RtlUsleepOS(u32 us);
extern VOID RtlMdelayOS(u32 ms);
extern VOID RtlUdelayOS(u32 us);
extern VOID RtlYieldOS(VOID);
#define RtlUpMutex(mutex) RtlUpSema(mutex)
#define RtlDownMutex(mutex) RtlDownSema(mutex)
__inline static u8 RtlCancelTimerEx(IN _Timer *ptimer)
{
DelTimerSync(ptimer);
return 0;
}
static __inline VOID ThreadEnter(IN char *name)
{
DBG_8195A("\rRTKTHREAD_enter %s\n", name);
}
#define ThreadExit() do{DBG_8195A("\rRTKTHREAD_exit %s\n", __FUNCTION__);}while(0)
__inline static VOID FlushSignalsThread(VOID)
{
}
#define RTL_RND(sz, r) ((((sz)+((r)-1))/(r))*(r))
#define RTL_RND4(x) (((x >> 2) + (((x & 3) == 0) ? 0: 1)) << 2)
__inline static u32 RtlRnd4(IN u32 sz)
{
u32 val;
val = ((sz >> 2) + ((sz & 3) ? 1: 0)) << 2;
return val;
}
__inline static u32 RtlRnd8(IN u32 sz)
{
u32 val;
val = ((sz >> 3) + ((sz & 7) ? 1: 0)) << 3;
return val;
}
__inline static u32 RtlRnd128(IN u32 sz)
{
u32 val;
val = ((sz >> 7) + ((sz & 127) ? 1: 0)) << 7;
return val;
}
__inline static u32 RtlRnd256(IN u32 sz)
{
u32 val;
val = ((sz >> 8) + ((sz & 255) ? 1: 0)) << 8;
return val;
}
__inline static u32 RtlRnd512(IN u32 sz)
{
u32 val;
val = ((sz >> 9) + ((sz & 511) ? 1: 0)) << 9;
return val;
}
__inline static u32 BitShift(IN u32 BitMask)
{
u32 i;
for (i = 0; i <= 31; i++)
if (((BitMask>>i) & 0x1) == 1) break;
return i;
}
//#ifdef __GNUC__
#ifdef PLATFORM_LINUX
#define STRUCT_PACKED __attribute__ ((packed))
#else
#define STRUCT_PACKED
#endif
//Atomic integer operations
#define RTL_ATOMIC_T atomic_t
static inline VOID RTL_ATOMIC_SET(IN RTL_ATOMIC_T *v, IN u32 i)
{
ATOMIC_SET(v,i);
}
static inline uint32_t RTL_ATOMIC_READ(IN RTL_ATOMIC_T *v)
{
return ATOMIC_READ(v);
}
static inline VOID RTL_ATOMIC_ADD(IN RTL_ATOMIC_T *v, IN u32 i)
{
ATOMIC_ADD(v,i);
}
static inline VOID RTL_ATOMIC_SUB(IN RTL_ATOMIC_T *v, IN u32 i)
{
ATOMIC_SUB(v,i);
}
static inline VOID RTL_ATOMIC_INC(IN RTL_ATOMIC_T *v)
{
ATOMIC_INC(v);
}
static inline VOID RTL_ATOMIC_DEC(IN RTL_ATOMIC_T *v)
{
ATOMIC_DEC(v);
}
static inline u32 RTL_ATOMIC_ADD_RETURN(IN RTL_ATOMIC_T *v, IN u32 i)
{
return ATOMIC_ADD_RETURN(v, i);
}
static inline u32 RTL_ATOMIC_SUB_RETURN(IN RTL_ATOMIC_T *v, IN u32 i)
{
return ATOMIC_SUB_RETURN(v, i);
}
static inline u32 RTL_ATOMIC_INC_RETURN(IN RTL_ATOMIC_T *v)
{
return ATOMIC_INC_RETURN(v);
}
static inline u32 RTL_ATOMIC_DEC_RETURN(IN RTL_ATOMIC_T *v)
{
return ATOMIC_DEC_RETURN(v);
}
extern u64 RtlModular64(u64 x, u64 y);
extern PRTL_TIMER
RtlTimerCreate(
IN char *pTimerName,
IN u32 TimerPeriodMS,
IN RTL_TIMER_CALL_BACK CallbckFunc,
IN void *pContext,
IN u8 isPeriodical
);
extern VOID
RtlTimerDelete(
IN PRTL_TIMER pTimerHdl
);
extern u8
RtlTimerStart(
IN PRTL_TIMER pTimerHdl,
IN u8 isFromISR
);
extern u8
RtlTimerStop(
IN PRTL_TIMER pTimerHdl,
IN u8 isFromISR
);
extern u8
RtlTimerReset(
IN PRTL_TIMER pTimerHdl,
IN u8 isFromISR
);
extern u8
RtlTimerChangePeriod(
IN PRTL_TIMER pTimerHdl,
IN u32 NewPeriodMS,
IN u8 isFromISR
);
#endif //#ifndef __OSDEP_API_H_

View file

@ -0,0 +1,22 @@
/**************************************************
* malloc/free/realloc wrap for gcc compiler
*
**************************************************/
#if defined(__GNUC__)
#include "FreeRTOS.h"
void* __wrap_malloc( size_t size )
{
return pvPortMalloc(size);
}
void* __wrap_realloc( void *p, size_t size )
{
return pvPortReAalloc(p, size);
}
void __wrap_free( void *p )
{
vPortFree(p);
}
#endif

View file

@ -0,0 +1,825 @@
#include <sys.h>
#include <device_lock.h>
#include "ota_8195a.h"
#include "lwip/netdb.h"
sys_thread_t TaskOTA = NULL;
#define STACK_SIZE 1024
#define TASK_PRIORITY tskIDLE_PRIORITY + 1
#if SWAP_UPDATE
static uint32_t OldImg2Addr;
#endif
static flash_t flash_ota;
#if CONFIG_CUSTOM_SIGNATURE
/* ---------------------------------------------------
* Customized Signature
* ---------------------------------------------------*/
// This signature can be used to verify the correctness of the image
// It will be located in fixed location in application image
#include "section_config.h"
SECTION(".custom.validate.rodata")
const unsigned char cus_sig_demo[32] = "Customer Signature-modelxxx";
#endif
void* update_malloc(unsigned int size){
return pvPortMalloc(size);
}
void update_free(void *buf){
vPortFree(buf);
}
void ota_platform_reset(void){
// Set processor clock to default before system reset
HAL_WRITE32(SYSTEM_CTRL_BASE, 0x14, 0x00000021);
osDelay(100);
// Cortex-M3 SCB->AIRCR
HAL_WRITE32(0xE000ED00, 0x0C, (0x5FA << 16) | // VECTKEY
(HAL_READ32(0xE000ED00, 0x0C) & (7 << 8)) | // PRIGROUP
(1 << 2)); // SYSRESETREQ
while(1) osDelay(1000);
}
#if WRITE_OTA_ADDR
int write_ota_addr_to_system_data(flash_t *flash, uint32_t ota_addr)
{
uint32_t data, i = 0;
//Get upgraded image 2 addr from offset
device_mutex_lock(RT_DEV_LOCK_FLASH);
flash_read_word(flash, OFFSET_DATA, &data);
printf("\n\r[%s] data 0x%x ota_addr 0x%x", __FUNCTION__, data, ota_addr);
if(~0x0 == data){
flash_write_word(flash, OFFSET_DATA, ota_addr);
}
else{
//erase backup sector
flash_erase_sector(flash, BACKUP_SECTOR);
//backup system data to backup sector
for(i = 0; i < 0x1000; i+= 4){
flash_read_word(flash, OFFSET_DATA + i, &data);
if(0 == i)
data = ota_addr;
flash_write_word(flash, BACKUP_SECTOR + i,data);
}
//erase system data
flash_erase_sector(flash, OFFSET_DATA);
//write data back to system data
for(i = 0; i < 0x1000; i+= 4){
flash_read_word(flash, BACKUP_SECTOR + i, &data);
flash_write_word(flash, OFFSET_DATA + i,data);
}
//erase backup sector
flash_erase_sector(flash, BACKUP_SECTOR);
}
device_mutex_unlock(RT_DEV_LOCK_FLASH);
return 0;
}
#endif
int update_ota_connect_server(int server_socket, update_cfg_local_t *cfg){
struct sockaddr_in server_addr;
server_socket = socket(AF_INET, SOCK_STREAM, 0);
if(server_socket < 0){
printf("\n\r[%s] Create socket failed", __FUNCTION__);
return -1;
}
server_addr.sin_family = AF_INET;
server_addr.sin_addr.s_addr = cfg->ip_addr;
server_addr.sin_port = cfg->port;
if(connect(server_socket, (struct sockaddr *)&server_addr, sizeof(server_addr)) == -1){
printf("\n\r[%s] Socket connect failed", __FUNCTION__);
return -1;
}
return server_socket;
}
uint32_t update_ota_prepare_addr(void){
uint32_t Img2Len = 0;
uint32_t IMAGE_x = 0, ImgxLen = 0, ImgxAddr = 0;
uint32_t NewImg2Addr = 0;
#if WRITE_OTA_ADDR
uint32_t ota_addr = 0x80000;
#endif
DBG_INFO_MSG_OFF(_DBG_SPI_FLASH_);
// The upgraded image2 pointer must 4K aligned and should not overlap with Default Image2
device_mutex_lock(RT_DEV_LOCK_FLASH);
flash_read_word(&flash_ota, IMAGE_2, &Img2Len);
IMAGE_x = IMAGE_2 + Img2Len + 0x10;
flash_read_word(&flash_ota, IMAGE_x, &ImgxLen);
flash_read_word(&flash_ota, IMAGE_x+4, &ImgxAddr);
device_mutex_unlock(RT_DEV_LOCK_FLASH);
if(0x30000000 == ImgxAddr){
printf("\n\r[%s] IMAGE_3 0x%x Img3Len 0x%x", __FUNCTION__, IMAGE_x, ImgxLen);
}
else{
printf("\n\r[%s] There is no IMAGE_3", __FUNCTION__);
IMAGE_x = IMAGE_2;
ImgxLen = Img2Len;
}
#if WRITE_OTA_ADDR
if((ota_addr > IMAGE_x) && ((ota_addr < (IMAGE_x+ImgxLen))) || (ota_addr < IMAGE_x) ||
((ota_addr & 0xfff) != 0) || (ota_addr == ~0x0)){
printf("\n\r[%s] illegal ota addr 0x%x", __FUNCTION__, ota_addr);
return -1;
}
else
write_ota_addr_to_system_data(&flash_ota, ota_addr);
#endif
//Get upgraded image 2 addr from offset
device_mutex_lock(RT_DEV_LOCK_FLASH);
flash_read_word(&flash_ota, OFFSET_DATA, &NewImg2Addr);
device_mutex_unlock(RT_DEV_LOCK_FLASH);
if((NewImg2Addr > IMAGE_x) && ((NewImg2Addr < (IMAGE_x+ImgxLen))) || (NewImg2Addr < IMAGE_x) ||
((NewImg2Addr & 0xfff) != 0) || (NewImg2Addr == ~0x0)){
printf("\n\r[%s] Invalid OTA Address 0x%x", __FUNCTION__, NewImg2Addr);
return -1;
}
return NewImg2Addr;
}
#if SWAP_UPDATE
uint32_t update_ota_swap_addr(uint32_t img_len, uint32_t NewImg2Addr){
uint32_t SigImage0,SigImage1;
uint32_t Part1Addr=0xFFFFFFFF, Part2Addr=0xFFFFFFFF;
device_mutex_lock(RT_DEV_LOCK_FLASH);
flash_read_word(&flash_ota, 0x18, &Part1Addr);
Part1Addr = (Part1Addr&0xFFFF)*1024; //PART1 : 0x0000B000
Part2Addr = NewImg2Addr; //PART2 : 0x00080000
// read Part1 signature
flash_read_word(&flash_ota, Part1Addr+8, &SigImage0);
flash_read_word(&flash_ota, Part1Addr+12, &SigImage1);
printf("\n\r[%s] Part1 Sig %x", __FUNCTION__, SigImage0);
device_mutex_unlock(RT_DEV_LOCK_FLASH);
if(SigImage0==0x35393138 && SigImage1==0x31313738)//Part1 is the new one with signature "81958711"
OldImg2Addr = Part1Addr; //Change Part1 to older version
else{
// read Part2 signature
device_mutex_lock(RT_DEV_LOCK_FLASH);
flash_read_word(&flash_ota, Part2Addr+8, &SigImage0);
flash_read_word(&flash_ota, Part2Addr+12, &SigImage1);
device_mutex_unlock(RT_DEV_LOCK_FLASH);
printf("\n\r[%s] Part2 Sig %x", __FUNCTION__, SigImage0);
if(SigImage0==0x30303030 && SigImage1==0x30303030){// ATSC signature "00000000"
OldImg2Addr = Part1Addr; //Store the new version to Part2
}
else if(SigImage0==0x35393138 && SigImage1==0x31313738){//Part2 is the new one with signature "81958711"
OldImg2Addr = Part2Addr; //Change Part2 to older version
NewImg2Addr = Part1Addr;
if( img_len > (Part2Addr-Part1Addr) ){ // firmware size too large
printf("\n\r[%s] Part1 size < OTA size", __FUNCTION__);
return -1;
}
}
else
NewImg2Addr = Part2Addr;
}
printf("\n\r[%s] New %x, Old %x", __FUNCTION__, NewImg2Addr, OldImg2Addr);
return NewImg2Addr;
}
#endif
int update_ota_erase_upg_region(uint32_t img_len, uint32_t NewImg2Len, uint32_t NewImg2Addr){
uint32_t NewImg2BlkSize = 0;
if(NewImg2Len == 0){
NewImg2Len = img_len;
printf("\n\r[%s] NewImg2Len %d ", __FUNCTION__, NewImg2Len);
if((int)NewImg2Len > 0){
NewImg2BlkSize = ((NewImg2Len - 1)/4096) + 1;
printf("\n\r[%s] NewImg2BlkSize %d 0x%8x", __FUNCTION__, NewImg2BlkSize, NewImg2BlkSize);
device_mutex_lock(RT_DEV_LOCK_FLASH);
for(int i = 0; i < NewImg2BlkSize; i++)
flash_erase_sector(&flash_ota, NewImg2Addr + i * 4096);
device_mutex_unlock(RT_DEV_LOCK_FLASH);
}else{
printf("\n\r[%s] Size INVALID", __FUNCTION__);
return -1;
}
}
printf("\n\r[%s] NewImg2Addr 0x%x", __FUNCTION__, NewImg2Addr);
return NewImg2Len;
}
int update_ota_checksum(_file_checksum *file_checksum, uint32_t flash_checksum, uint32_t NewImg2Addr){
#if CONFIG_CUSTOM_SIGNATURE
char custom_sig[32] = "Customer Signature-modelxxx";
uint32_t read_custom_sig[8];
device_mutex_lock(RT_DEV_LOCK_FLASH);
for(int i = 0; i < 8; i ++){
flash_read_word(&flash_ota, NewImg2Addr + 0x28 + i *4, read_custom_sig + i);
}
device_mutex_unlock(RT_DEV_LOCK_FLASH);
printf("\n\r[%s] read_custom_sig %s", __FUNCTION__ , (char*)read_custom_sig);
#endif
printf("\n\rflash checksum 0x%8x attached checksum 0x%8x", flash_checksum, file_checksum->u);
// compare checksum with received checksum
if( (file_checksum->u == flash_checksum)
#if CONFIG_CUSTOM_SIGNATURE
&& !strcmp((char*)read_custom_sig,custom_sig)
#endif
){
//Set signature in New Image 2 addr + 8 and + 12
uint32_t sig_readback0,sig_readback1;
device_mutex_lock(RT_DEV_LOCK_FLASH);
flash_write_word(&flash_ota,NewImg2Addr + 8, 0x35393138);
flash_write_word(&flash_ota,NewImg2Addr + 12, 0x31313738);
flash_read_word(&flash_ota, NewImg2Addr + 8, &sig_readback0);
flash_read_word(&flash_ota, NewImg2Addr + 12, &sig_readback1);
device_mutex_unlock(RT_DEV_LOCK_FLASH);
printf("\n\r[%s] signature %x,%x", __FUNCTION__ , sig_readback0, sig_readback1);
#if SWAP_UPDATE
if(OldImg2Addr != ~0x0){
device_mutex_lock(RT_DEV_LOCK_FLASH);
flash_write_word(&flash_ota,OldImg2Addr + 8, 0x35393130);
flash_write_word(&flash_ota,OldImg2Addr + 12, 0x31313738);
flash_read_word(&flash_ota, OldImg2Addr + 8, &sig_readback0);
flash_read_word(&flash_ota, OldImg2Addr + 12, &sig_readback1);
device_mutex_unlock(RT_DEV_LOCK_FLASH);
printf("\n\r[%s] old signature %x,%x", __FUNCTION__ , sig_readback0, sig_readback1);
}
#endif
printf("\n\r[%s] Update OTA success!", __FUNCTION__);
return 0;
}
return -1;
}
static void update_ota_local_task(void *param)
{
int server_socket;
unsigned char *buf, *alloc;
_file_checksum *file_checksum;
int read_bytes = 0, size = 0, i = 0;
update_cfg_local_t *cfg = (update_cfg_local_t *)param;
uint32_t address, flash_checksum=0;
uint32_t NewImg2Len = 0, NewImg2Addr = 0, file_info[3];
int ret = -1 ;
printf("\n\r[%s] Update task start", __FUNCTION__);
alloc = update_malloc(BUF_SIZE+4);
if(!alloc){
printf("\n\r[%s] Alloc buffer failed", __FUNCTION__);
goto update_ota_exit;
}
buf = &alloc[4];
file_checksum = (void*)alloc;
// Connect server
server_socket = update_ota_connect_server(server_socket, cfg);
if(server_socket == -1){
goto update_ota_exit;
}
NewImg2Addr = update_ota_prepare_addr();
if(NewImg2Addr == -1){
goto update_ota_exit;
}
//Clear file_info
memset(file_info, 0, sizeof(file_info));
if(file_info[0] == 0){
printf("\n\r[%s] Read info first", __FUNCTION__);
read_bytes = read(server_socket, file_info, sizeof(file_info));
// !X!X!X!X!X!X!X!X!X!X!X!X!X!X!X!X!X!X!X!X
// !W checksum !W padding 0 !W file size !W
// !X!X!X!X!X!X!X!X!X!X!X!X!X!X!X!X!X!X!X!X
printf("\n\r[%s] info %d bytes", __FUNCTION__, read_bytes);
printf("\n\r[%s] tx chechsum 0x%x, file size 0x%x", __FUNCTION__, file_info[0],file_info[2]);
if(file_info[2] == 0){
printf("\n\r[%s] No checksum and file size", __FUNCTION__);
goto update_ota_exit;
}
}
#if SWAP_UPDATE
NewImg2Addr = update_ota_swap_addr(file_info[2], NewImg2Addr);
if(NewImg2Addr == -1){
goto update_ota_exit;
}
#endif
NewImg2Len = update_ota_erase_upg_region(file_info[2], NewImg2Len, NewImg2Addr);
if(NewImg2Len == -1){
goto update_ota_exit;
}
// reset
file_checksum->u = 0;
// Write New Image 2 sector
if(NewImg2Addr != ~0x0){
address = NewImg2Addr;
printf("\n\rStart to read data %d bytes\r\n", NewImg2Len);
while(1){
memset(buf, 0, BUF_SIZE);
read_bytes = read(server_socket, buf, BUF_SIZE);
if(read_bytes == 0)
break; // Read end
if(read_bytes < 0){
printf("\n\r[%s] Read socket failed", __FUNCTION__);
goto update_ota_exit;
}
if(read_bytes<4)
printf("\n\r[%s] Recv small packet", __FUNCTION__);
printf(".");
if((size+read_bytes)>NewImg2Len){
printf("\n\r[%s] Redundant bytes received", __FUNCTION__);
read_bytes = NewImg2Len-size;
}
device_mutex_lock(RT_DEV_LOCK_FLASH);
if(flash_stream_write(&flash_ota, address + size, read_bytes, buf) < 0){
printf("\n\r[%s] Write stream failed", __FUNCTION__);
device_mutex_unlock(RT_DEV_LOCK_FLASH);
goto update_ota_exit;
}
device_mutex_unlock(RT_DEV_LOCK_FLASH);
size += read_bytes;
file_checksum->c[0] = alloc[4+read_bytes-4]; // checksum attached at file end
file_checksum->c[1] = alloc[4+read_bytes-3];
file_checksum->c[2] = alloc[4+read_bytes-2];
file_checksum->c[3] = alloc[4+read_bytes-1];
if(size == NewImg2Len)
break;
}
printf("\n\rRead data finished\r\n");
// read flash data back and calculate checksum
for(i = 0; i < size-4; i += BUF_SIZE){
int k;
int rlen = (size-4-i) > BUF_SIZE ? BUF_SIZE : (size-4-i);
flash_stream_read(&flash_ota, NewImg2Addr+i, rlen, buf);
for(k = 0; k < rlen; k++)
flash_checksum+=buf[k];
}
ret = update_ota_checksum(file_checksum, flash_checksum, NewImg2Addr);
if(ret == -1){
printf("\r\nThe checksume is wrong!\r\n");
goto update_ota_exit;
}
}
update_ota_exit:
if(alloc)
update_free(alloc);
if(server_socket >= 0)
close(server_socket);
if(param)
update_free(param);
TaskOTA = NULL;
printf("\n\r[%s] Update task exit", __FUNCTION__);
if(!ret){
printf("\n\r[%s] Ready to reboot", __FUNCTION__);
ota_platform_reset();
}
vTaskDelete(NULL);
return;
}
int update_ota_local(char *ip, int port){
update_cfg_local_t *pUpdateCfg;
if(TaskOTA){
printf("\n\r[%s] Update task has created.", __FUNCTION__);
return 0;
}
pUpdateCfg = update_malloc(sizeof(update_cfg_local_t));
if(pUpdateCfg == NULL){
printf("\n\r[%s] Alloc update cfg failed", __FUNCTION__);
return -1;
}
pUpdateCfg->ip_addr = inet_addr(ip);
pUpdateCfg->port = ntohs(port);
if(xTaskCreate(update_ota_local_task, "OTA_server", STACK_SIZE, pUpdateCfg, TASK_PRIORITY, &TaskOTA) != pdPASS){
update_free(pUpdateCfg);
printf("\n\r[%s] Create update task failed", __FUNCTION__);
}
return 0;
}
void cmd_update(int argc, char **argv){
int port;
if(argc != 3){
printf("\n\r[%s] Usage: update IP PORT", __FUNCTION__);
return;
}
port = atoi(argv[2]);
update_ota_local(argv[1], port);
}
void cmd_ota_image(bool cmd){
flash_t flash;
uint32_t Part1Addr = 0xFFFFFFFF,Part2Addr = 0xFFFFFFFF;
uint8_t *pbuf = NULL;
device_mutex_lock(RT_DEV_LOCK_FLASH);
flash_read_word(&flash, 0x18, &Part1Addr);
Part1Addr = (Part1Addr&0xFFFF)*1024; // first partition
flash_read_word(&flash, OFFSET_DATA, &Part2Addr);
device_mutex_unlock(RT_DEV_LOCK_FLASH);
if(Part2Addr == ~0x0)
return;
pbuf = update_malloc(FLASH_SECTOR_SIZE);
if(!pbuf) return;
device_mutex_lock(RT_DEV_LOCK_FLASH);
flash_stream_read(&flash, Part2Addr, FLASH_SECTOR_SIZE, pbuf);
if (cmd == 1)
memcpy((char*)pbuf+8, "81958711", 8);
else
memcpy((char*)pbuf+8, "01958711", 8);
flash_erase_sector(&flash, Part2Addr);
flash_stream_write(&flash, Part2Addr, FLASH_SECTOR_SIZE, pbuf);
device_mutex_unlock(RT_DEV_LOCK_FLASH);
#if SWAP_UPDATE
device_mutex_lock(RT_DEV_LOCK_FLASH);
flash_stream_read(&flash, Part1Addr, FLASH_SECTOR_SIZE, pbuf);
if (cmd == 1)
memcpy((char*)pbuf+8, "01958711", 8);
else
memcpy((char*)pbuf+8, "81958711", 8);
flash_erase_sector(&flash, Part1Addr);
flash_stream_write(&flash, Part1Addr, FLASH_SECTOR_SIZE, pbuf);
device_mutex_unlock(RT_DEV_LOCK_FLASH);
#endif
update_free(pbuf);
}
#ifdef HTTP_OTA_UPDATE
/******************************************************************************************************************
** Function Name : update_ota_http_connect_server
** Description : connect to the OTA server
** Input : server_socket: the socket used
** host: host address of the OTA server
** port: port of the OTA server
** Return : connect ok: socket value
** Failed: -1
*******************************************************************************************************************/
int update_ota_http_connect_server(int server_socket, char *host, int port){
struct sockaddr_in server_addr;
struct hostent *server;
server_socket = socket(AF_INET, SOCK_STREAM, 0);
if(server_socket < 0){
printf("\n\r[%s] Create socket failed", __FUNCTION__);
return -1;
}
server = gethostbyname(host);
if(server == NULL){
printf("[ERROR] Get host ip failed\n");
return -1;
}
memset(&server_addr,0,sizeof(server_addr));
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(port);
memcpy(&server_addr.sin_addr.s_addr,server->h_addr,server->h_length);
if (connect(server_socket,(struct sockaddr *)&server_addr, sizeof(server_addr)) < 0){
printf("\n\r[%s] Socket connect failed", __FUNCTION__);
return -1;
}
return server_socket;
}
/******************************************************************************************************************
** Function Name : parse_http_response
** Description : Parse the http response to get some useful parameters
** Input : response : The http response got from server
** response_len: The length of http response
** result : The struct that store the usful infor about the http response
** Return : Parse OK: 1 -> Only got the status code
** 3 -> Got the status code and content_length, but didn't get the full header
** 4 -> Got all the information needed
** Failed: -1
*******************************************************************************************************************/
int parse_http_response(uint8_t *response, uint32_t response_len, http_response_result_t *result) {
uint32_t i, p, q, m;
uint32_t header_end = 0;
//Get status code
if(0 == result->parse_status){//didn't get the http response
uint8_t status[4] = {0};
i = p = q = m = 0;
for (; i < response_len; ++i) {
if (' ' == response[i]) {
++m;
if (1 == m) {//after HTTP/1.1
p = i;
}
else if (2 == m) {//after status code
q = i;
break;
}
}
}
if (!p || !q || q-p != 4) {//Didn't get the status code
return -1;
}
memcpy(status, response+p+1, 3);//get the status code
result->status_code = atoi((char const *)status);
if(result->status_code == 200)
result->parse_status = 1;
else{
printf("\n\r[%s] The http response status code is %d", __FUNCTION__, result->status_code);
return -1;
}
}
//if didn't receive the full http header
if(3 == result->parse_status){//didn't get the http response
p = q = 0;
for (i = 0; i < response_len; ++i) {
if (response[i] == '\r' && response[i+1] == '\n' &&
response[i+2] == '\r' && response[i+3] == '\n') {//the end of header
header_end = i+4;
result->parse_status = 4;
result->header_len = header_end;
result->body = response + header_end;
break;
}
}
if (3 == result->parse_status) {//Still didn't receive the full header
result->header_bak = update_malloc(HEADER_BAK_LEN + 1);
memset(result->header_bak, 0, strlen(result->header_bak));
memcpy(result->header_bak, response + response_len - HEADER_BAK_LEN, HEADER_BAK_LEN);
}
}
//Get Content-Length
if(1 == result->parse_status){//didn't get the content length
uint32_t content_length = 0;
const uint8_t *content_length_buf1 = "CONTENT-LENGTH";
const uint8_t *content_length_buf2 = "Content-Length";
const uint32_t content_length_buf_len = strlen(content_length_buf1);
p = q = 0;
for (i = 0; i < response_len; ++i) {
if (response[i] == '\r' && response[i+1] == '\n') {
q = i;//the end of the line
if (!memcmp(response+p, content_length_buf1, content_length_buf_len) ||
!memcmp(response+p, content_length_buf2, content_length_buf_len)) {//get the content length
int j1 = p+content_length_buf_len, j2 = q-1;
while ( j1 < q && (*(response+j1) == ':' || *(response+j1) == ' ') ) ++j1;
while ( j2 > j1 && *(response+j2) == ' ') --j2;
uint8_t len_buf[12] = {0};
memcpy(len_buf, response+j1, j2-j1+1);
result->body_len = atoi((char const *)len_buf);
result->parse_status = 2;
}
p = i+2;
}
if (response[i] == '\r' && response[i+1] == '\n' &&
response[i+2] == '\r' && response[i+3] == '\n') {//Get the end of header
header_end = i+4;//p is the start of the body
if(result->parse_status == 2){//get the full header and the content length
result->parse_status = 4;
result->header_len = header_end;
result->body = response + header_end;
}
else {//there are no content length in header
printf("\n\r[%s] No Content-Length in header", __FUNCTION__);
return -1;
}
break;
}
}
if (1 == result->parse_status) {//didn't get the content length and the full header
result->header_bak = update_malloc(HEADER_BAK_LEN + 1);
memset(result->header_bak, 0, strlen(result->header_bak));
memcpy(result->header_bak, response + response_len - HEADER_BAK_LEN, HEADER_BAK_LEN);
}
else if (2 == result->parse_status) {//didn't get the full header but get the content length
result->parse_status = 3;
result->header_bak = update_malloc(HEADER_BAK_LEN + 1);
memset(result->header_bak, 0, strlen(result->header_bak));
memcpy(result->header_bak, response + response_len - HEADER_BAK_LEN, HEADER_BAK_LEN);
}
}
return result->parse_status;
}
int http_update_ota(char *host, int port, char *resource)
{
int server_socket;
unsigned char *buf, *alloc, *request;
_file_checksum *file_checksum;
int read_bytes = 0, i = 0;
uint32_t address, flash_checksum = 0;
uint32_t NewImg2Len = 0, NewImg2Addr = 0;
int ret = -1;
http_response_result_t rsp_result = {0};
alloc = update_malloc(BUF_SIZE + 4);
if(!alloc){
printf("\n\r[%s] Alloc buffer failed", __FUNCTION__);
goto update_ota_exit;
}
buf = &alloc[4];
file_checksum = (void*)alloc;
// Connect server
server_socket = update_ota_http_connect_server(server_socket, host, port);
if(server_socket == -1){
goto update_ota_exit;
}
NewImg2Addr = update_ota_prepare_addr();
if(NewImg2Addr == -1){
goto update_ota_exit;
}
// reset
file_checksum->u = 0;
// Write New Image 2 sector
if(NewImg2Addr != ~0x0){
uint32_t idx = 0;
int data_len = 0;
printf("\n\r");
//send http request
request = (unsigned char *) update_malloc(strlen("GET /") + strlen(resource) + strlen(" HTTP/1.1\r\nHost: ")
+ strlen(host) + strlen("\r\n\r\n") + 1);
sprintf(request, "GET /%s HTTP/1.1\r\nHost: %s\r\n\r\n", resource, host);
ret = write(server_socket, request, strlen(request));
if(ret < 0){
printf("\n\r[%s] Send HTTP request failed", __FUNCTION__);
goto update_ota_exit;
}
while (3 >= rsp_result.parse_status){//still read header
if(0 == rsp_result.parse_status){//didn't get the http response
memset(buf, 0, BUF_SIZE);
read_bytes = read(server_socket, buf, BUF_SIZE);
if(read_bytes == 0)
continue;
if(read_bytes < 0){
printf("\n\r[%s] Read socket failed", __FUNCTION__);
goto update_ota_exit;
}
idx = read_bytes;
memset(&rsp_result, 0, sizeof(rsp_result));
if(parse_http_response(buf, idx, &rsp_result) == -1){
goto update_ota_exit;
}
}
else if((1 == rsp_result.parse_status) || (3 == rsp_result.parse_status)){//just get the status code
memset(buf, 0, BUF_SIZE);
memcpy(buf, rsp_result.header_bak, HEADER_BAK_LEN);
update_free(rsp_result.header_bak);
rsp_result.header_bak = NULL;
read_bytes = read(server_socket, buf+ HEADER_BAK_LEN, (BUF_SIZE - HEADER_BAK_LEN));
if(read_bytes == 0)
continue;
if(read_bytes < 0){
printf("\n\r[%s] Read socket failed", __FUNCTION__);
goto update_ota_exit;
}
idx = read_bytes + HEADER_BAK_LEN;
if(parse_http_response(buf, read_bytes + HEADER_BAK_LEN, &rsp_result) == -1){
goto update_ota_exit;
}
}
else if(3 == rsp_result.parse_status){
printf("\n\r[%s] Get the content_length failed", __FUNCTION__);
goto update_ota_exit;
}
}
if (0 == rsp_result.body_len){
printf("\n\r[%s] New firmware size = 0 !", __FUNCTION__);
goto update_ota_exit;
}
else
printf("\n\r[%s] Download new firmware begin, total size : %d\n\r", __FUNCTION__, rsp_result.body_len);
#if SWAP_UPDATE
NewImg2Addr = update_ota_swap_addr(rsp_result.body_len, NewImg2Addr);
if(NewImg2Addr == -1){
goto update_ota_exit;
}
#endif
address = NewImg2Addr;
NewImg2Len = update_ota_erase_upg_region(rsp_result.body_len, NewImg2Len, NewImg2Addr);
if(NewImg2Len == -1){
goto update_ota_exit;
}
//Write the body of http response into flash
data_len = idx - rsp_result.header_len;
if(data_len > 0){
file_checksum->c[0] = alloc[4+data_len-4]; // checksum attached at file end
file_checksum->c[1] = alloc[4+data_len-3];
file_checksum->c[2] = alloc[4+data_len-2];
file_checksum->c[3] = alloc[4+data_len-1];
device_mutex_lock(RT_DEV_LOCK_FLASH);
if(flash_stream_write(&flash_ota, address, data_len, (buf+rsp_result.header_len)) < 0){
printf("\n\r[%s] Write sector failed", __FUNCTION__);
device_mutex_unlock(RT_DEV_LOCK_FLASH);
goto update_ota_exit;
}
device_mutex_unlock(RT_DEV_LOCK_FLASH);
}
idx = 0;
idx += data_len;
while (idx < NewImg2Len){
printf(".");
data_len = NewImg2Len - idx;
if(data_len > BUF_SIZE)
data_len = BUF_SIZE;
memset(buf, 0, BUF_SIZE);
read_bytes = read(server_socket, buf, data_len);
if(read_bytes == 0)
continue;
if(read_bytes < 0){
printf("\n\r[%s] Read socket failed", __FUNCTION__);
goto update_ota_exit;
}
if(read_bytes<4)
printf("\n\r[%s] Recv small packet", __FUNCTION__);
device_mutex_lock(RT_DEV_LOCK_FLASH);
if(flash_stream_write(&flash_ota, address + idx, read_bytes, buf) < 0){
printf("\n\r[%s] Write sector failed", __FUNCTION__);
device_mutex_unlock(RT_DEV_LOCK_FLASH);
goto update_ota_exit;
}
device_mutex_unlock(RT_DEV_LOCK_FLASH);
file_checksum->c[0] = alloc[4+read_bytes-4]; // checksum attached at file end
file_checksum->c[1] = alloc[4+read_bytes-3];
file_checksum->c[2] = alloc[4+read_bytes-2];
file_checksum->c[3] = alloc[4+read_bytes-1];
idx += read_bytes;
}
printf("\n\r[%s] Download new firmware %d bytes completed\n\r", __FUNCTION__, idx);
// read flash data back and calculate checksum
for(i = 0; i < idx-4; i += BUF_SIZE){
int k;
int rlen = (idx-4-i)>BUF_SIZE?BUF_SIZE:(idx-4-i);
device_mutex_lock(RT_DEV_LOCK_FLASH);
flash_stream_read(&flash_ota, NewImg2Addr+i, rlen, buf);
device_mutex_unlock(RT_DEV_LOCK_FLASH);
for(k = 0; k < rlen; k++)
flash_checksum+=buf[k];
}
ret = update_ota_checksum(file_checksum, flash_checksum, NewImg2Addr);
if(ret == -1){
printf("\n\r[%s] The checksume is wrong!\n\r", __FUNCTION__);
goto update_ota_exit;
}
}
update_ota_exit:
if(alloc)
update_free(alloc);
if(request)
update_free(request);
if(server_socket >= 0)
close(server_socket);
return ret;
}
#endif

View file

@ -0,0 +1,97 @@
#ifndef OTA_8195A_H
#define OTA_8195A_H
#include <FreeRTOS.h>
#include <task.h>
#include <platform_stdlib.h>
#include <flash_api.h>
#include <lwip/sockets.h>
/************************Related setting****************************/
#define HTTP_OTA_UPDATE //if define, using http protocol, if not, will use socket
#define CONFIG_CUSTOM_SIGNATURE 0 //if verify the custom signature(define in ota_8195a.c cus_sig)
#define WRITE_OTA_ADDR 1
#define SWAP_UPDATE 0
#define BUF_SIZE 512
#define HEADER_BAK_LEN 32
#define OFFSET_DATA FLASH_SYSTEM_DATA_ADDR
#define IMAGE_2 0x0000B000
#if WRITE_OTA_ADDR
#define BACKUP_SECTOR (FLASH_SYSTEM_DATA_ADDR - 0x1000)
#endif
/*******************************************************************/
/****************Define the structures used*************************/
typedef struct{
uint32_t ip_addr;
uint16_t port;
}update_cfg_local_t;
typedef struct {
uint32_t status_code;
uint32_t header_len;
uint8_t *body;
uint32_t body_len;
uint8_t *header_bak;
uint32_t parse_status;
} http_response_result_t;
typedef union {
uint32_t u;
unsigned char c[4];
} _file_checksum;
/*******************************************************************/
/****************General functions used by ota update***************/
void *update_malloc(unsigned int size);
void update_free(void *buf);
void ota_platform_reset(void);
#if WRITE_OTA_ADDR
int write_ota_addr_to_system_data(flash_t *flash, uint32_t ota_addr);
#endif
int update_ota_connect_server(int server_socket, update_cfg_local_t *cfg);
uint32_t update_ota_prepare_addr(void);
#if SWAP_UPDATE
uint32_t update_ota_swap_addr(uint32_t img_len, uint32_t NewImg2Addr);
#endif
int update_ota_erase_upg_region(uint32_t img_len, uint32_t NewImg2Len, uint32_t NewImg2Addr);
int update_ota_checksum(_file_checksum *file_checksum, uint32_t flash_checksum, uint32_t NewImg2Addr);
/*******************************************************************/
/*******************Functions called by AT CMD**********************/
void cmd_update(int argc, char **argv);
void cmd_ota_image(bool cmd);
/*******************************************************************/
/*************************************************************************************************
** Function Name : update_ota_local
** Description : Starting a thread of OTA updating through socket
** Input : ip:The IP address of OTA server
** port:The Port of OTA server
** Return : 0: Task created OK
** -1: Task created failed
**************************************************************************************************/
int update_ota_local(char *ip, int port);
#ifdef HTTP_OTA_UPDATE
int parse_http_response(uint8_t *response, uint32_t response_len, http_response_result_t *result);
int update_ota_http_connect_server(int server_socket, char *host, int port);
/*************************************************************************************************
** Function Name : http_update_ota
** Description : The process of OTA updating through http protocol
** Input : cfg:struct update_cfg_local_t
** Return : NULL
**************************************************************************************************/
int http_update_ota(char *host, int port, char *resource);
#endif
#endif

View file

@ -0,0 +1,256 @@
/*
* rtl_lib.h
*
* Definitions for RTL library functions
*/
#ifndef _RTL_LIB_ROM_H_
#define _RTL_LIB_ROM_H_
#include <basic_types.h>
#include <diag.h>
#include <reent.h>
#include "../libc/rom/string/rom_libc_string.h"
#include "../libgloss/rtl8195a/rom/rom_libgloss_retarget.h"
#ifndef _PTR
#define _PTR void *
#endif
#ifndef _AND
#define _AND ,
#endif
#ifndef _NOARGS
#define _NOARGS void
#endif
#ifndef _CONST
#define _CONST const
#endif
#ifndef _VOLATILE
#define _VOLATILE volatile
#endif
#ifndef _SIGNED
#define _SIGNED signed
#endif
#ifndef _DOTS
#define _DOTS , ...
#endif
#ifndef _VOID
#define _VOID void
#endif
//
// RTL library functions in ROM
//
#define __rtl_memset __rtl_memset_v1_00
#define __rtl_memchr __rtl_memchr_v1_00
#define __rtl_memmove __rtl_memmove_v1_00
#define __rtl_strcmp __rtl_strcmp_v1_00
#define __rtl_memcpy __rtl_memcpy_v1_00
extern _LONG_CALL_ void * __rtl_memset_v1_00(void * m , int c , size_t n);
extern _LONG_CALL_ void * __rtl_memchr_v1_00(const void * src_void , int c , size_t length);
extern _LONG_CALL_ void * __rtl_memmove_v1_00( void * dst_void , const void * src_void , size_t length);
extern _LONG_CALL_ int __rtl_strcmp_v1_00(const char *s1 , const char *s2);
extern _LONG_CALL_ void * __rtl_memcpy_v1_00(void * __restrict dst0 , const void * __restrict src0 , size_t len0);
//
// rtl eabi functions
//
#define __rtl_itod __rtl_itod_v1_00
#define __rtl_dtoi __rtl_dtoi_v1_00
#define __rtl_uitof __rtl_uitof_v1_00
#define __rtl_uitod __rtl_uitod_v1_00
#define __rtl_dcmpeq __rtl_dcmpeq_v1_00
#define __rtl_dcmplt __rtl_dcmplt_v1_00
#define __rtl_dcmpgt __rtl_dcmpgt_v1_00
#define __rtl_dadd __rtl_dadd_v1_00
#define __rtl_dsub __rtl_dsub_v1_00
#define __rtl_dmul __rtl_dmul_v1_00
#define __rtl_ddiv __rtl_ddiv_v1_00
extern _LONG_CALL_ double __rtl_itod_v1_00(int lval);
extern _LONG_CALL_ int __rtl_dtoi_v1_00(double d);
extern _LONG_CALL_ float __rtl_uitof_v1_00(unsigned int lval);
extern _LONG_CALL_ double __rtl_uitod_v1_00(unsigned int lval);
extern _LONG_CALL_ int __rtl_dcmpeq_v1_00(double a, double b);
extern _LONG_CALL_ int __rtl_dcmplt_v1_00(double a, double b);
extern _LONG_CALL_ int __rtl_dcmpgt_v1_00(double a, double b);
extern _LONG_CALL_ double __rtl_dadd_v1_00(double a, double b);
extern _LONG_CALL_ double __rtl_dsub_v1_00(double a, double b);
extern _LONG_CALL_ double __rtl_dmul_v1_00(double a, double b);
extern _LONG_CALL_ double __rtl_ddiv_v1_00(double a, double b);
//
// mprec
//
#include <reent.h>
typedef struct _Bigint _Bigint;
#define __rtl_Balloc __rtl_Balloc_v1_00
#define __rtl_Bfree __rtl_Bfree_v1_00
#define __rtl_d2b __rtl_d2b_v1_00
#define __rtl_i2b __rtl_i2b_v1_00
#define __rtl_pow5mult __rtl_pow5mult_v1_00
#define __rtl_multadd __rtl_multadd_v1_00
#define __rtl_mult __rtl_mult_v1_00
#define __rtl_hi0bits __rtl_hi0bits_v1_00
#define __rtl_lshift __rtl_lshift_v1_00
#define __rtl_cmp __rtl_cmp_v1_00
#define __rtl_diff __rtl_diff_v1_00
extern _LONG_CALL_ _Bigint * __rtl_Balloc_v1_00(struct _reent *ptr, int k);
extern _LONG_CALL_ void __rtl_Bfree_v1_00(struct _reent *ptr, _Bigint * v);
extern _LONG_CALL_ _Bigint * __rtl_d2b_v1_00(struct _reent * ptr, double _d, int *e, int *bits);
extern _LONG_CALL_ _Bigint * __rtl_i2b_v1_00(struct _reent *ptr, int i );
extern _LONG_CALL_ _Bigint * __rtl_pow5mult_v1_00(struct _reent * ptr, _Bigint *b, int k);
extern _LONG_CALL_ _Bigint * __rtl_multadd_v1_00(struct _reent *ptr, _Bigint * b, int m, int a);
extern _LONG_CALL_ _Bigint * __rtl_mult_v1_00(struct _reent *ptr, _Bigint *a, _Bigint *b);
extern _LONG_CALL_ int __rtl_hi0bits_v1_00(register __ULong x);
extern _LONG_CALL_ _Bigint *__rtl_lshift_v1_00(struct _reent *ptr, _Bigint *b, int k);
extern _LONG_CALL_ int __rtl_cmp_v1_00(_Bigint *a, _Bigint *b);
extern _LONG_CALL_ _Bigint *__rtl_diff_v1_00(struct _reent* ptr, _Bigint *a, _Bigint *b);
//
// dtoa
//
#define __rtl_dtoa_r __rtl_dtoa_r_v1_00
extern char * __rtl_dtoa_r_v1_00(struct _reent *ptr, double _d, int mode, int ndigits, int *decpt, int *sign, char **rve);
//
// mallocr
//
#include <sys/config.h>
#include <reent.h>
#define __rom_mallocr_init __rom_mallocr_init_v1_00
#define __rtl_calloc_r __rtl_calloc_r_v1_00
#define __rtl_cfree_r __rtl_cfree_r_v1_00
#define __rtl_malloc_r __rtl_malloc_r_v1_00
#define __rtl_free_r __rtl_free_r_v1_00
#define __rtl_realloc_r __rtl_realloc_r_v1_00
#define __rtl_memalign_r __rtl_memalign_r_v1_00
#define __rtl_valloc_r __rtl_valloc_r_v1_00
#define __rtl_pvalloc_r __rtl_pvalloc_r_v1_00
extern _LONG_CALL_ void __rom_mallocr_init_v1_00(void);
#define RARG struct _reent *reent_ptr,
extern _LONG_CALL_ void* __rtl_calloc_r_v1_00(RARG size_t n, size_t elem_size);
extern _LONG_CALL_ void __rtl_cfree_r_v1_00(void *mem);
extern _LONG_CALL_ void* __rtl_malloc_r_v1_00(RARG size_t bytes);
extern _LONG_CALL_ void __rtl_free_r_v1_00(RARG void* mem);
extern _LONG_CALL_ void* __rtl_realloc_r_v1_00(RARG void* oldmem, size_t bytes);
extern _LONG_CALL_ void* __rtl_memalign_r_v1_00(RARG size_t alignment, size_t bytes);
extern _LONG_CALL_ void* __rtl_valloc_r_v1_00(RARG size_t bytes);
extern _LONG_CALL_ void* __rtl_pvalloc_r_v1_00(RARG size_t bytes);
//
// stdio
//
extern int __rtl_errno;
#ifndef _READ_WRITE_RETURN_TYPE
#define _READ_WRITE_RETURN_TYPE _ssize_t
#endif
#ifndef _READ_WRITE_BUFSIZE_TYPE
#define _READ_WRITE_BUFSIZE_TYPE int
#endif
#define __rtl_sread __rtl_sread_v1_00
#define __rtl_swrite __rtl_swrite_v1_00
#define __rtl_seofread __rtl_seofread_v1_00
#define __rtl_sseek __rtl_sseek_v1_00
#define __rtl_sclose __rtl_sclose_v1_00
#define __rtl_sbrk_r __rtl_sbrk_r_v1_00
extern _LONG_CALL_ _READ_WRITE_RETURN_TYPE __rtl_sread_v1_00(
struct _reent *ptr,
void *cookie,
char *buf,
_READ_WRITE_BUFSIZE_TYPE n);
extern _LONG_CALL_ _READ_WRITE_RETURN_TYPE __rtl_swrite_v1_00(
struct _reent *ptr,
void *cookie,
char const *buf,
_READ_WRITE_BUFSIZE_TYPE n);
extern _LONG_CALL_ _READ_WRITE_RETURN_TYPE __rtl_seofread_v1_00(
struct _reent *_ptr,
_PTR cookie,
char *buf,
_READ_WRITE_BUFSIZE_TYPE len);
extern _LONG_CALL_ _fpos_t __rtl_sseek_v1_00(
struct _reent *ptr _AND
void *cookie _AND
_fpos_t offset _AND
int whence);
extern _LONG_CALL_ int __rtl_sclose_v1_00(
struct _reent *ptr _AND
void *cookie);
extern _LONG_CALL_ void * __rtl_sbrk_r_v1_00(
struct _reent *ptr,
ptrdiff_t incr);
//
// vfprintf
//
#include <stdio.h>
#include <stdarg.h>
#define __rtl_vfprintf_r __rtl_vfprintf_r_v1_00
extern _LONG_CALL_ int __rtl_vfprintf_r_v1_00(struct _reent *, FILE *, const char *, va_list);
#ifndef CONFIG_RELEASE_BUILD_LIBRARIES
#define __rtl_fflush_r __rtl_fflush_r_v1_00
extern _LONG_CALL_ int __rtl_fflush_r_v1_00(struct _reent *ptr, register FILE * fp);
#endif
#endif /* _RTL_LIB_ROM_H_ */

View file

@ -0,0 +1,234 @@
/*
* rtl_bios_data.h
*
* Created on: 12/02/2017
* Author: pvvx
*
* This variables declared in ROM code!
* Variables use fixed addresses!
* (see *.ld script)
*/
#ifndef _RTL_BIOS_DATA_H_
#define _RTL_BIOS_DATA_H_
#include "platform_autoconf.h"
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include <sys/reent.h>
// component/soc/realtek/common/bsp/
#include "basic_types.h"
// component/soc/realtek/8195a/fwlib/
#include "rtl8195a/rtl8195a.h"
#include "hal_gpio.h"
#include "hal_irqn.h"
#include "hal_timer.h"
#include "hal_sdr_controller.h"
// component/soc/realtek/8195a/fwlib/
#include "ram_lib/wlan/realtek/wlan_ram_map/rom/rom_wlan_ram_map.h"
// component/soc/realtek/8195a/misc/driver/
#include "rtl_consol.h"
// component/soc/realtek/8195a/misc/rtl_std_lib/
#include "include/rtl_lib.h"
#include "include/rt_lib_rom.h"
#include "libc/rom/string/rom_libc_string.h"
#include "libgloss/rtl8195a/rom/rom_libgloss_retarget.h"
//#include "rom/rom_libgloss_retarget.h"
typedef void (*START_FUNC)(void);
/* ROM + startup.c */
extern IRQ_FUN NewVectorTable[64]; // 10000000
extern IRQ_FUN UserIrqFunTable[64]; // 10000100
extern u32 UserIrqDataTable[64]; // 10000200
/* ROM + diag.h */
extern u32 CfgSysDebugWarn; // 10000300
extern u32 CfgSysDebugInfo; // 10000304
extern u32 CfgSysDebugErr; // 10000308
extern u32 ConfigDebugWarn; // 1000030c
extern u32 ConfigDebugInfo; // 10000310
extern u32 ConfigDebugErr; // 10000314
/* ROM + hal_timer.h & .. */
extern HAL_TIMER_OP HalTimerOp; // 10000318
extern u16 GPIOState[11]; // 10000334
extern u32 gTimerRecord; // 1000034C
/* ROM + hal_ssi.h */
extern u32 SSI_DBG_CONFIG; // 10000350
extern PHAL_GPIO_ADAPTER _pHAL_Gpio_Adapter; // 10000354
/* ROM + rtl8195a_timer.c */
extern IRQ_FUN Timer2To7VectorTable[MAX_TIMER_VECTOR_TABLE_NUM]; // 10000358
/* ROM + Rand() */
extern u32 _rand_z4, _rand_z3, _rand_z2, _rand_z1, _rand_first; // 10000370..
/* ROM + rtl_consol.c */
extern volatile UART_LOG_CTL *pUartLogCtl; // 10000384
extern UART_LOG_BUF UartLogBuf; // 10000388
extern volatile UART_LOG_CTL UartLogCtl; // 10000408
extern u8 UartLogHistoryBuf[UART_LOG_HISTORY_LEN][UART_LOG_CMD_BUFLEN]; // 10000430 UartLogHistoryBuf[5][127] !
extern u8 *ArgvArray[MAX_ARGV]; // 100006AC *ArgvArray[10] !
/* ROM + ?? */
extern struct _rom_wlan_ram_map rom_wlan_ram_map; // 100006D4
typedef struct _FALSE_ALARM_STATISTICS {
u32 Cnt_Parity_Fail;
u32 Cnt_Rate_Illegal;
u32 Cnt_Crc8_fail;
u32 Cnt_Mcs_fail;
u32 Cnt_Ofdm_fail;
u32 Cnt_Ofdm_fail_pre;
u32 Cnt_Cck_fail;
u32 Cnt_all;
u32 Cnt_Fast_Fsync;
u32 Cnt_SB_Search_fail;
u32 Cnt_OFDM_CCA;
u32 Cnt_CCK_CCA;
u32 Cnt_CCA_all;
u32 Cnt_BW_USC;
u32 Cnt_BW_LSC;
} FALSE_ALARM_STATISTICS;
extern FALSE_ALARM_STATISTICS FalseAlmCnt; // 100006E0
typedef struct _rom_info {
u8 EEPROMVersion;
u8 CrystalCap;
u64 DebugComponents;
u32 DebugLevel;
} ROM_INFO;
extern ROM_INFO ROMInfo; // 10000720
typedef struct _CFO_TRACKING_ {
BOOL bATCStatus;
BOOL largeCFOHit;
BOOL bAdjust;
u8 CrystalCap;
u8 DefXCap;
u32 CFO_tail[2];
u32 CFO_ave_pre;
u32 packetCount;
u32 packetCount_pre;
BOOL bForceXtalCap;
BOOL bReset;
u8 CFO_TH_XTAL_HIGH;
u8 CFO_TH_XTAL_LOW;
u8 CFO_TH_ATC;
}CFO_TRACKING;
extern CFO_TRACKING DM_CfoTrack; // 10000738
/* in rom_libgloss_retarget.h
struct _rom_libgloss_ram_map {
int (*libgloss_close)(int fildes);
int (*libgloss_fstat)(int fildes , struct stat *st);
int (*libgloss_isatty)(int file);
int (*libgloss_lseek)(int file , int ptr , int dir);
int (*libgloss_open)(char *file , int flags , int mode);
int (*libgloss_read)(int file , char *ptr , int len);
int (*libgloss_write)(int file , const char *ptr , int len);
void* (*libgloss_sbrk)(int incr);
};
*/
extern struct _rom_libgloss_ram_map rom_libgloss_ram_map; // 10000760
struct malloc_chunk
{
size_t prev_size;
size_t size;
struct malloc_chunk *fd;
struct malloc_chunk *bk;
};
extern struct malloc_chunk * __rtl_malloc_av_[258]; // 10000780 __rom_mallocr_init_v1_00(), _rtl_free_r_v1_00()..
extern u32 __rtl_malloc_trim_threshold; // 10000b88 __rom_mallocr_init_v1_00()
extern u32 __rtl_malloc_top_pad; // 10000b8c __rom_mallocr_init_v1_00()
extern u8 * __rtl_malloc_sbrk_base; // 10000b90 __rom_mallocr_init_v1_00()
extern u32 __rtl_malloc_max_sbrked_mem; // 10000b94 __rom_mallocr_init_v1_00()
extern u32 __rtl_malloc_max_total_mem; // 10000b98 __rom_mallocr_init_v1_00()
struct mallinfo
{
int arena;
int ordblks;
int smblks;
int hblks;
int hblkhd;
int usmblks;
int fsmblks;
int uordblks;
int fordblks;
int keepcost;
};
extern struct mallinfo __rtl_malloc_current_mallinfo; // 10000b9c __rom_mallocr_init_v1_00()
/* IMAGE1 HEAD: ROM + startup.c (bootloader) */
extern RAM_START_FUNCTION gRamStartFun; // 10000bc8 = { PreProcessForVendor + 1 };
extern RAM_START_FUNCTION gRamPatchWAKE; // 10000bcc = { RtlBootToSram + 1 };
extern RAM_START_FUNCTION gRamPatchFun0; // 10000bd0 = { RtlBootToSram + 1 };
extern RAM_START_FUNCTION gRamPatchFun1; // 10000bd4 = { RtlBootToSram + 1 };
extern RAM_START_FUNCTION gRamPatchFun2; // 10000bd8 = { RtlBootToSram + 1 };
//extern uint8 RAM_IMG1_VALID_PATTEN[8]; // 10000bdc = { 0x23, 0x79, 0x16, 0x88, 0xff, 0xff, 0xff, 0xff };
/* ROM + hal_sdr_controller.c */
extern u32 rand_x; // 10000be4: ChangeRandSeed_rom(), Sdr_Rand2_rom()
#define REC_NUM 512
extern u32 AvaWds[2][REC_NUM]; // 10000be8
extern DRAM_DEVICE_INFO SdrDramInfo; // 10001be8
#define DRAM_DEVICE_INFO_INIT() { \
&SdrDramDev, \
&SdrDramModeReg, \
&SdrDramTiming, \
DRAM_TIMING_TCK, \
DFI_RATIO_1 }
extern DRAM_TIMING_INFO SdrDramTiming; // 10001bfc
#define DRAM_TIMING_INFO_INIT() { \
DRAM_TIMING_TRFC, /* TrfcPs; */ \
DRAM_TIMING_TREFI, /* TrefiPs; */ \
DRAM_TIMING_TWRMAXTCK, /* WrMaxTck; */\
DRAM_TIMING_TRCD, /* TrcdPs; */ \
DRAM_TIMING_TRP, /* TrpPs; */ \
DRAM_TIMING_TRAS, /* TrasPs; */ \
DRAM_TIMING_TRRD, /* TrrdTck; */ \
DRAM_TIMING_TWR, /* TwrPs; */ \
DRAM_TIMING_TWTR, /* TwtrTck; */ \
/* 13090, */ /* TrtpPs; */ \
DRAM_TIMING_TMRD, /* TmrdTck; */ \
DRAM_TIMING_TRTP, /* TrtpTck; */ \
DRAM_TIMING_TCCD, /* TccdTck; */ \
DRAM_TIMING_TRC } /* TrcPs; */
extern DRAM_MODE_REG_INFO SdrDramModeReg; // 10001c30
#define DRAM_MODE_REG_INFO_INIT() { \
BST_LEN_4, \
SENQUENTIAL, \
0x3, /* Mode0Cas: 3 */ \
0x0, /* Mode0Wr */ \
0, /* Mode1DllEnN */ \
0, /* Mode1AllLat */ \
0 } /* Mode2Cwl */
extern DRAM_INFO SdrDramDev; // 10001c4c
#define DRAM_INFO_INIT() { DRAM_INFO_TYPE, DRAM_INFO_COL_ADDR_WTH,DRAM_INFO_BANK_SZ, DRAM_INFO_DQ_WTH }
extern SPIC_INIT_PARA SpicInitParaAllClk[SpicMaxMode][CPU_CLK_TYPE_NO]; // 100021ec [144=0x90]
/* ROM + "C" standard library */
extern struct _reent * _rtl_impure_ptr; // 10001c60 = { &impure_reent };
extern struct _reent impure_reent; // 10001c68 = _REENT_INIT(impure_reent);
/* ROM ? UserData? */
extern u32 _rom_unc_data[9]; // 100020e8
/* ROM + hal_sdr_controller.c: Sdr_Rand2() */
extern u32 _sdr_rnd2_c, _sdr_rnd2_z, _sdr_rnd2_y; // 100020BC, 100020B8, 100020B4
/* *.ld */
extern u8 __rom_bss_start__, __rom_bss_end__;
extern u8 __image1_bss_start__, __image1_bss_end__;
extern START_FUNC __image2_entry_func__;
//extern RAM_START_FUNCTION __image2_entry_func__;
extern u8 __image2_validate_code__;
#ifndef STACK_TOP
#define STACK_TOP 0x1ffffffc
#endif
#endif /* _RTL_BIOS_DATA_H_ */

View file

@ -0,0 +1,141 @@
/*
* rtl_lib.h
*
* Definitions for RTL library functions
*/
#ifndef _RTL_LIB_H_
#define _RTL_LIB_H_
#include <basic_types.h>
#include <diag.h>
#include <stdarg.h>
extern int __rtl_errno;
void init_rom_libgloss_ram_map(void);
//
// RTL library functions for Libc::stdio
//
extern int rtl_printf(IN const char* fmt, ...);
extern int rtl_vprintf(const char *fmt, va_list param);
extern int rtl_sprintf(char* str, const char* fmt, ...);
extern int rtl_snprintf(char* str, size_t size, const char* fmt, ...);
extern int rtl_vsnprintf(char *str, size_t size, const char *fmt, va_list param);
//
// RTL library functions for string
//
extern void * rtl_memchr(const void * src_void , int c , size_t length);
extern int rtl_memcmp(const void * m1 , const void * m2 , size_t n);
extern void * rtl_memcpy(void * dst0 , const void * src0 , size_t len0);
extern void * rtl_memmove( void * dst_void , const void * src_void , size_t length);
extern void * rtl_memset(void * m , int c , size_t n);
extern char * rtl_strcat(char * s1 , const char * s2);
extern char * rtl_strchr(const char *s1 , int i);
extern int rtl_strcmp(const char *s1 , const char *s2);
extern char* rtl_strcpy(char *dst0 , const char *src0);
extern size_t rtl_strlen(const char *str);
extern char * rtl_strncat(char * s1 , const char * s2 , size_t n);
extern int rtl_strncmp(const char *s1 , const char *s2 , size_t n);
extern char * rtl_strncpy(char * dst0 , const char * src0 , size_t count);
extern char * rtl_strstr(const char *searchee , const char *lookfor);
extern char * rtl_strsep(char **source_ptr , const char *delim);
extern char * rtl_strtok(char * s , const char * delim);
//
// RTL library functions for math
//
extern double rtl_fabs(double);
extern float rtl_fabsf(float a);
extern float rtl_cos_f32(float a);
extern float rtl_sin_f32(float a);
extern float rtl_fadd(float a, float b);
extern float rtl_fsub(float a, float b);
extern float rtl_fmul(float a, float b);
extern float rtl_fdiv(float a, float b);
extern int rtl_fcmplt(float a, float b);
extern int rtl_fcmpgt(float a, float b);
//
// RTL eabi functions
extern double rtl_ftod(float f);
extern double rtl_ddiv(double a, double b);
//
// Macro Library Functions
//
typedef union
{
float value;
u32 word;
} ieee_float_shape_type;
/* Get a 32 bit int from a float. */
#define GET_FLOAT_WORD(i,d) \
do { \
ieee_float_shape_type gf_u; \
gf_u.value = (d); \
(i) = gf_u.word; \
} while (0)
/* Set a float from a 32 bit int. */
#define SET_FLOAT_WORD(d,i) \
do { \
ieee_float_shape_type sf_u; \
sf_u.word = (i); \
(d) = sf_u.value; \
} while (0)
static inline
float rtl_nanf(void)
{
float x;
SET_FLOAT_WORD(x,0x7fc00000);
return x;
}
//
// Library Test functions
//
extern int rtl_lib_test(IN u16 argc, IN u8 *argv[]);
extern int rtl_math_test(IN u16 argc, IN u8 *argv[]);
extern int rtl_string_test(IN u16 argc, IN u8 *argv[]);
//
// Macro functions
//
#undef dbg_printf
#define dbg_printf(fmt, args...) \
rtl_printf("%s():%d : " fmt "\n", __FUNCTION__, __LINE__, ##args);
#undef err_printf
#define err_printf(fmt, args...) \
rtl_printf("%s():%d : " fmt "\n", __FUNCTION__, __LINE__, ##args);
#endif /* _RTL_LIB_H_ */

View file

@ -0,0 +1,166 @@
/*
* RAM->ROM Calls
*/
#ifndef _INC_RTL_RR_LIBC_
#define _INC_RTL_RR_LIBC_
//#undef malloc
#define malloc(size) pvPortMalloc(size)
//#undef free
#define free(pbuf) vPortFree(pbuf)
//extern void* pvPortReAlloc( void *pv, size_t xWantedSize )
#define realloc(pv, xWantedSize) pvPortReAlloc(pv, xWantedSize)
#define calloc(nelements, elementSize) calloc_freertos(nelements, elementSize)
#define snprintf rtl_snprintf
#define sprintf rtl_sprintf
#define printf rtl_printf
#define vprintf rtl_vprintf
#define vsnprintf rtl_vsnprintf
#define vfprintf rtl_vfprintf
#define memchr rtl_memchr
#define memcmp rtl_memcmp
#define memcpy rtl_memcpy
#define memmove rtl_memmove
#define memset rtl_memset
#define strcat rtl_strcat
#define strchr rtl_strchr
#define strcmp rtl_strcmp
#define strcpy rtl_strcpy
#define strlen rtl_strlen
#define strncat rtl_strncat
#define strncmp rtl_strncmp
#define strncpy rtl_strncpy
#define strstr rtl_strstr
#define strsep rtl_strsep
#define strtok rtl_strtok
#if 0 // __aeabi_
#define dtoi rtl_dtoi
#define dtoui rtl_dtoui
#define i2f rtl_i2f
#define i2d rtl_i2d
#define ui2f rtl_ui2f
#define ui2d rtl_ui2d
#define itoa rtl_itoa
#define ltoa rtl_ltoa
#define utoa rtl_utoa
#define ultoa rtl_ultoa
#define ftol rtl_ftol
#define ftod rtl_ftod
#define dtof rtl_dtof
#define fadd rtl_fadd
#define fsub rtl_fsub
#define fmul rtl_fmul
#define fdiv rtl_fdiv
#define dadd rtl_dadd
#define dsub rtl_dsub
#define dmul rtl_dmul
#define ddiv rtl_ddiv
#define dcmpeq rtl_dcmpeq
#define dcmplt rtl_dcmplt
#define dcmple rtl_dcmple
#define dcmpgt rtl_dcmpgt
#define fcmplt rtl_fcmplt
#define fcmpgt rtl_fcmpgt
#define fabsf rtl_fabsf
#define fabs rtl_fabs
#define cos_f32 rtl_cos_f32
#define sin_f32 rtl_sin_f32
#endif
#if 0
extern void *calloc_freertos(size_t nelements, size_t elementSize);
// ram_libc.c
extern void rtl_libc_init(void);
extern int rtl_snprintf(char *str, size_t size, const char *fmt, ...);
extern int rtl_sprintf(char *str, const char *fmt, ...);
extern int rtl_printf(const char *fmt, ...);
extern int rtl_vprintf(const char *fmt, void *param);
extern int rtl_vsnprintf(char *str, size_t size, const char *fmt, void *param);
extern int rtl_vfprintf(FILE *fp, const char *fmt0, va_list ap);
extern void * rtl_memchr(const void * src_void , int c , size_t length);
extern int rtl_memcmp(const void *m1, const void *m2, size_t n);
extern void * rtl_memcpy(void *dst0, const void *src0, size_t len0);
extern void * rtl_memmove(void *dst_void, const void *src_void, size_t length);
extern void * rtl_memset(void *m, int c, size_t n);
extern char * rtl_strcat(char *s1, const char *s2);
extern char * rtl_strchr(const char *s1, int i);
extern int rtl_strcmp(const char *s1, const char *s2);
extern char * rtl_strcpy(char *dst0, const char *src0);
extern size_t rtl_strlen(const char *str);
extern char * rtl_strncat(char *s1, const char *s2, size_t n);
extern int rtl_strncmp(const char *s1, const char *s2, size_t n);
extern char * rtl_strncpy(char *dst0, const char *src0, size_t count);
extern char * rtl_strstr(const char *searchee, const char *lookfor);
extern char * rtl_strsep(char **source_ptr, const char *delim);
extern char * rtl_strtok(char *s, const char *delim);
//rtl_eabi_cast_ram.c
extern int rtl_dtoi(double d);
extern int rtl_dtoui(double d);
extern float rtl_i2f(int val);
extern int rtl_i2d(int val);
extern float rtl_ui2f(unsigned int val);
extern int rtl_ui2d(unsigned int val);
extern char *rtl_itoa(int value, char *string, int radix);
extern char *rtl_ltoa(int value, char *string, int radix);
extern char *rtl_utoa(unsigned int value, char *string, int radix);
extern char *rtl_ultoa(unsigned int value, char *string, int radix);
extern int rtl_ftol(float f);
extern int rtl_ftod(float f);
extern float rtl_dtof(double d);
extern float rtl_fadd(float a, float b);
extern float rtl_fsub(float a, float b);
extern float rtl_fmul(float a, float b);
extern float rtl_fdiv(float a, float b);
extern int rtl_dadd(double a, double b);
extern int rtl_dsub(double a, double b);
extern int rtl_dmul(double a, double b);
extern int rtl_ddiv(double a, double b);
extern int rtl_dcmpeq(double a, double b);
extern int rtl_dcmplt(double a, double b);
extern int rtl_dcmple(double a, double b);
extern int rtl_dcmpgt(double a, double b);
extern int rtl_fcmplt(float a, float b);
extern int rtl_fcmpgt(float a, float b);
// rtl_math_ram.c
extern float rtl_fabsf(float a);
extern int rtl_fabs(double a);
extern float rtl_cos_f32(float a);
extern float rtl_sin_f32(float a);
// ram_pvvx_libc.c
extern int snprintf(char *str, size_t size, const char *fmt, ...);
extern int sprintf(char *str, const char *fmt, ...);
extern int printf(const char *fmt, ...);
extern int vprintf(const char * fmt, __VALIST param);
extern int vsnprintf(char *str, size_t size, const char *fmt, __VALIST param);
extern int vfprintf(FILE *fp, const char *fmt0, va_list ap);
extern void * memchr(const void * src_void , int c , size_t length);
extern int memcmp(const void *m1, const void *m2, size_t n);
extern void * memcpy(void *dst0, const void *src0, size_t len0);
extern void * memmove(void *dst_void, const void *src_void, size_t length);
extern void * memset(void *m, int c, size_t n);
extern char * strcat(char *s1, const char *s2);
extern char * strchr(const char *s1, int i);
extern int strcmp(const char *s1, const char *s2);
extern char * strcpy(char *dst0, const char *src0);
extern size_t strlen(const char *str);
extern char * strncat(char *s1, const char *s2, size_t n);
extern int strncmp(const char *s1, const char *s2, size_t n);
extern char * strncpy(char *dst0, const char *src0, size_t count);
extern char * strstr(const char *searchee, const char *lookfor);
extern char * strsep(char **source_ptr, const char *delim);
extern char * strtok(char *s, const char *delim);
extern int sscanf(const char *buf, const char *fmt, ...);
extern char toupper(char ch);
extern int _stricmp (const char *s1, const char *s2);
extern unsigned long long __aeabi_llsr(unsigned long long val, unsigned int shift);
#endif
#endif // _INC_RTL_RR_LIBC_

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,292 @@
/*
* ram_libc.o
* pvvx 2016
*/
#include "rtl_bios_data.h"
#include "va_list.h"
#define CHECK_LIBC_INIT 0
//-------------------------------------------------------------------------
// Function declarations
#if 0
void rtl_libc_init(void);
int rtl_snprintf(char *str, size_t size, const char *fmt, ...);
int rtl_sprintf(char *str, const char *fmt, ...);
int rtl_printf(const char *fmt, ...);
int rtl_vprintf(const char *fmt, void *param);
int rtl_vsnprintf(char *str, size_t size, const char *fmt, void *param);
int rtl_vfprintf(FILE *fp, const char *fmt0, va_list ap);
void * rtl_memchr(const void * src_void , int c , size_t length);
int rtl_memcmp(const void *m1, const void *m2, size_t n);
void * rtl_memcpy(void *dst0, const void *src0, size_t len0);
void * rtl_memmove(void *dst_void, const void *src_void, size_t length);
void * rtl_memset(void *m, int c, size_t n);
char * rtl_strcat(char *s1, const char *s2);
char * rtl_strchr(const char *s1, int i);
int rtl_strcmp(const char *s1, const char *s2);
char * rtl_strcpy(char *dst0, const char *src0);
size_t rtl_strlen(const char *str);
char * rtl_strncat(char *s1, const char *s2, size_t n);
int rtl_strncmp(const char *s1, const char *s2, size_t n);
char * rtl_strncpy(char *dst0, const char *src0, size_t count);
char * rtl_strstr(const char *searchee, const char *lookfor);
char * rtl_strsep(char **source_ptr, const char *delim);
char * rtl_strtok(char *s, const char *delim);
#endif
// Extern Calls:
// extern int init_rom_libgloss_ram_map(_DWORD)
// extern int _rom_mallocr_init_v1_00(void)
// extern int __rtl_vfprintf_r_v1_00(_DWORD, _DWORD, _DWORD)
// extern int __rtl_fflush_r_v1_00(_DWORD, _DWORD)
// extern int __rtl_memchr_v1_00(_DWORD, _DWORD, _DWORD)
// extern int __rtl_memcmp_v1_00(_DWORD, _DWORD, _DWORD)
// extern int __rtl_memcpy_v1_00(_DWORD, _DWORD, _DWORD)
// extern int __rtl_memmove_v1_00(_DWORD, _DWORD, _DWORD)
// extern int __rtl_memset_v1_00(_DWORD, _DWORD, _DWORD)
// extern int __rtl_strcat_v1_00(_DWORD, _DWORD)
// extern int __rtl_strchr_v1_00(_DWORD, _DWORD)
// extern int __rtl_strcmp_v1_00(_DWORD, _DWORD)
// extern int __rtl_strcpy_v1_00(_DWORD, _DWORD)
// extern int __rtl_strlen_v1_00(_DWORD)
// extern int __rtl_strncat_v1_00(_DWORD, _DWORD, _DWORD)
// extern int __rtl_strncmp_v1_00(_DWORD, _DWORD, _DWORD)
// extern int __rtl_strncpy_v1_00(_DWORD, _DWORD, _DWORD)
// extern int __rtl_strstr_v1_00(_DWORD, _DWORD)
// extern int __rtl_strsep_v1_00(_DWORD, _DWORD)
// extern int __rtl_strtok_v1_00(_DWORD, _DWORD)
//-------------------------------------------------------------------------
// Data declarations
extern struct _reent * _rtl_impure_ptr;
char libc_has_init;
char print_off;
// extern rtl_impure_ptr
// extern impure_ptr
//-------------------------------------------------------------------------
// Function
//----- rtl_libc_init()
void rtl_libc_init(void) {
__rom_mallocr_init_v1_00();
init_rom_libgloss_ram_map();
libc_has_init = 1;
}
//----- rtl_snprintf()
int rtl_snprintf(char *str, size_t size, const char *fmt, ...) {
va_list args;
va_start (args, fmt);
int result;
int w;
FILE f;
#if CHECK_LIBC_INIT
if (!libc_has_init) {
rtl_libc_init();
}
#endif
if (size >= 0) {
f._flags = 520;
if (size)
w = size - 1;
else
w = 0;
f._w = w; /* write space left for putc() */
f._bf._size = w;
f._file = -1; /* fileno, if Unix descriptor, else -1 */
f._p = str; /* current position in (some) buffer */
f._bf._base = str;
result = __rtl_vfprintf_r_v1_00(_rtl_impure_ptr, &f, fmt, args);
if (result + 1 < 0)
_rtl_impure_ptr->_errno = 139;
if (size)
*f._p = 0;
} else {
_rtl_impure_ptr->_errno = 139;
result = -1;
}
return result;
}
//----- rtl_sprintf()
int rtl_sprintf(char *str, const char *fmt, ...) {
FILE f;
#if CHECK_LIBC_INIT
if (!libc_has_init) {
rtl_libc_init();
}
#endif
f._flags = 520;
f._w = 0x7FFFFFFF;
f._bf._size = 0x7FFFFFFF;
f._file = -1;
f._p = str;
f._bf._base = str;
va_list args;
va_start (args, fmt);
int result = __rtl_vfprintf_r_v1_00(_rtl_impure_ptr, &f, fmt, args);
*f._p = 0;
// va_end (args);
return result;
}
//----- rtl_printf()
int rtl_printf(const char *fmt, ...) {
#if CHECK_LIBC_INIT
if (!libc_has_init) {
rtl_libc_init();
}
#endif
if(!print_off) {
va_list args;
va_start (args, fmt);
int result = __rtl_vfprintf_r_v1_00(_rtl_impure_ptr,
_rtl_impure_ptr->_stdout, fmt, args);
__rtl_fflush_r_v1_00(_rtl_impure_ptr, _rtl_impure_ptr->_stdout);
// va_end (args);
return result;
}
else return 0;
}
//----- rtl_vprintf()
int rtl_vprintf(const char *fmt, va_list param) {
#if CHECK_LIBC_INIT
if (!libc_has_init) {
rtl_libc_init();
}
#endif
int result = __rtl_vfprintf_r_v1_00(_rtl_impure_ptr,
_rtl_impure_ptr->_stdout, fmt, param);
__rtl_fflush_r_v1_00(_rtl_impure_ptr, _rtl_impure_ptr->_stdout);
return result;
}
//----- rtl_vsnprintf()
int rtl_vsnprintf(char *str, size_t size, const char *fmt, va_list param) {
int result;
int w;
int v11;
FILE f;
#if CHECK_LIBC_INIT
if (!libc_has_init) {
rtl_libc_init();
}
#endif
if (size >= 0) {
if (size)
w = size - 1;
else
w = 0;
f._flags = 520;
f._p = str;
f._bf._base = str;
f._w = w;
f._bf._size = w;
f._file = -1;
result = __rtl_vfprintf_r_v1_00(_rtl_impure_ptr, &f, fmt, param);
if (result + 1 < 0)
_rtl_impure_ptr->_errno = 139;
if (size)
*f._p = 0;
} else {
_rtl_impure_ptr->_errno = 139;
result = -1;
}
return result;
}
//----- rtl_vfprintf()
int rtl_vfprintf(FILE *fp, const char *fmt0, va_list ap) {
#if CHECK_LIBC_INIT
if (!libc_has_init) {
rtl_libc_init();
}
#endif
return __rtl_vfprintf_r_v1_00(_rtl_impure_ptr, fp, fmt0, ap);
}
//----- rtl_memchr()
void * rtl_memchr(const void * src_void , int c , size_t length) {
return __rtl_memchr_v1_00(src_void, c, length);
}
//----- rtl_memcmp()
int rtl_memcmp(const void *m1, const void *m2, size_t n) {
return __rtl_memcmp_v1_00(m1, m2, n);
}
//----- rtl_memcpy()
void * rtl_memcpy(void *dst0, const void *src0, size_t len0) {
return __rtl_memcpy_v1_00(dst0, src0, len0);
}
//----- rtl_memmove()
void * rtl_memmove(void *dst_void, const void *src_void, size_t length) {
return __rtl_memmove_v1_00(dst_void, src_void, length);
}
//----- rtl_memset()
void * rtl_memset(void *m, int c, size_t n) {
return __rtl_memset_v1_00(m, c, n);
}
//----- rtl_strcat()
char * rtl_strcat(char *s1, const char *s2) {
return (char *) __rtl_strcat_v1_00(s1, s2);
}
//----- rtl_strchr()
char * rtl_strchr(const char *s1, int i) {
return (char *) __rtl_strchr_v1_00(s1, i);
}
//----- rtl_strcmp()
int rtl_strcmp(const char *s1, const char *s2) {
return __rtl_strcmp_v1_00(s1, s2);
}
//----- rtl_strcpy()
char * rtl_strcpy(char *dst0, const char *src0) {
return (char *) __rtl_strcpy_v1_00(dst0, src0);
}
//----- rtl_strlen()
size_t rtl_strlen(const char *str) {
return __rtl_strlen_v1_00(str);
}
//----- rtl_strncat()
char * rtl_strncat(char *s1, const char *s2, size_t n) {
return (char *) __rtl_strncat_v1_00(s1, s2, n);
}
//----- rtl_strncmp()
int rtl_strncmp(const char *s1, const char *s2, size_t n) {
return __rtl_strncmp_v1_00(s1, s2, n);
}
//----- rtl_strncpy()
char * rtl_strncpy(char *dst0, const char *src0, size_t count) {
return (char *) __rtl_strncpy_v1_00(dst0, src0, count);
}
//----- rtl_strstr()
char * rtl_strstr(const char *searchee, const char *lookfor) {
return (char *) __rtl_strstr_v1_00(searchee, lookfor);
}
//----- rtl_strsep()
char * rtl_strsep(char **source_ptr, const char *delim) {
return (char *) __rtl_strsep_v1_00(source_ptr, delim);
}
//----- rtl_strtok()
char * rtl_strtok(char *s, const char *delim) {
return (char *) __rtl_strtok_v1_00(s, delim);
}

View file

@ -0,0 +1,127 @@
/*
* ram_libgloss_retarget.o
* pvvx 2016
*/
#include "rtl_bios_data.h"
//-------------------------------------------------------------------------
// Function declarations
int ram_libgloss_close(int fildes);
int ram_libgloss_fstat(int fildes, struct stat *st);
int ram_libgloss_isatty(int file);
int ram_libgloss_lseek(int file, int ptr, int dir);
int ram_libgloss_read(int file, char *ptr, int len);
char *ram_libgloss_sbrk(int incr);
int ram_libgloss_write(int file, const char *ptr, int len);
int ram_libgloss_open(char *file, int flags, int mode);
void init_rom_libgloss_ram_map(void);
// Extern Calls:
//extern int HalSerialPutcRtl8195a();
//extern int rtl_strcmp();
extern char end;
//-------------------------------------------------------------------------
// Data declarations
static char *rheap_end;
// extern __rtl_errno;
// extern end;
// extern rom_libgloss_ram_map;
//----- ram_libgloss_close()
int ram_libgloss_close(int fildes) {
__rtl_errno = 88;
return -1;
}
//----- ram_libgloss_fstat()
int ram_libgloss_fstat(int fildes, struct stat *st) {
int result;
if ((unsigned int) fildes > 2) {
__rtl_errno = 9;
result = -1;
} else {
st->st_mode = 0x2000;
result = 0;
}
return result;
}
//----- ram_libgloss_isatty()
int ram_libgloss_isatty(int file) {
int result;
if (file <= 2)
result = 1;
else
result = -1;
return result;
}
//----- ram_libgloss_lseek()
int ram_libgloss_lseek(int file, int ptr, int dir) {
__rtl_errno = 88;
return -1;
}
//----- ram_libgloss_read()
int ram_libgloss_read(int file, char *ptr, int len) {
__rtl_errno = 88;
return -1;
}
//----- ram_libgloss_sbrk()
char *ram_libgloss_sbrk(int incr) {
char *prev_heap_end;
if (!rheap_end)
rheap_end = (char *) &end;
prev_heap_end = rheap_end;
rheap_end += incr;
#if CONFIG_DEBUG_LOG > 4
DBG_8195A("ROM_heap = %p[%d], end = %p\n", prev_heap_end, incr, rheap_end);
#endif
return prev_heap_end;
}
//----- ram_libgloss_write()
int ram_libgloss_write(int file, const char *ptr, int len) {
int i;
for (i = 0; i < len; ++i)
HalSerialPutcRtl8195a(ptr[i]);
return len;
}
//----- ram_libgloss_open()
int ram_libgloss_open(char *file, int flags, int mode) {
// file->_p
int result = rtl_strcmp(file, "/stdin");
if (result) {
if (rtl_strcmp(file, "/stdout")) {
if (rtl_strcmp(file, "/stderr"))
result = -1;
else
result = 2;
} else {
result = 1;
}
} else
result = 0;
return result;
}
//----- init_rom_libgloss_ram_map()
void init_rom_libgloss_ram_map(void) {
rom_libgloss_ram_map.libgloss_close = ram_libgloss_close;
rom_libgloss_ram_map.libgloss_fstat = ram_libgloss_fstat;
rom_libgloss_ram_map.libgloss_isatty = ram_libgloss_isatty;
rom_libgloss_ram_map.libgloss_lseek = ram_libgloss_lseek;
rom_libgloss_ram_map.libgloss_open = ram_libgloss_open;
rom_libgloss_ram_map.libgloss_read = ram_libgloss_read;
rom_libgloss_ram_map.libgloss_write = ram_libgloss_write;
rom_libgloss_ram_map.libgloss_sbrk = ram_libgloss_sbrk;
}

View file

@ -0,0 +1,565 @@
/*
* RTL871x1Ax: RAM libc
* Created on: 22/02/2017
* Author: pvvx
*/
#include "rtl_bios_data.h"
#include "va_list.h"
#define CHECK_LIBC_INIT 0
//-------------------------------------------------------------------------
// Function declarations
//void libc_init();
#if 0
int snprintf(char *str, size_t size, const char *fmt, ...);
int sprintf(char *str, const char *fmt, ...);
int printf(const char *fmt, ...);
int vprintf(const char * fmt, __VALIST param);
int vsnprintf(char *str, size_t size, const char *fmt, __VALIST param);
int vfprintf(FILE *fp, const char *fmt0, va_list ap);
void * memchr(const void * src_void , int c , size_t length);
int memcmp(const void *m1, const void *m2, size_t n);
void * memcpy(void *dst0, const void *src0, size_t len0);
void * memmove(void *dst_void, const void *src_void, size_t length);
void * memset(void *m, int c, size_t n);
char * strcat(char *s1, const char *s2);
char * strchr(const char *s1, int i);
int strcmp(const char *s1, const char *s2);
char * strcpy(char *dst0, const char *src0);
size_t strlen(const char *str);
char * strncat(char *s1, const char *s2, size_t n);
int strncmp(const char *s1, const char *s2, size_t n);
char * strncpy(char *dst0, const char *src0, size_t count);
char * strstr(const char *searchee, const char *lookfor);
char * strsep(char **source_ptr, const char *delim);
char * strtok(char *s, const char *delim);
int sscanf(const char *buf, const char *fmt, ...);
char toupper(char ch);
int _stricmp (const char *s1, const char *s2);
unsigned long long __aeabi_llsr(unsigned long long val, unsigned int shift);
#endif
// Extern Calls:
// extern int init_rom_libgloss_ram_map(_DWORD)
// extern int _rom_mallocr_init_v1_00(void)
// extern int __rtl_vfprintf_r_v1_00(_DWORD, _DWORD, _DWORD)
// extern int __rtl_fflush_r_v1_00(_DWORD, _DWORD)
// extern int __rtl_memchr_v1_00(_DWORD, _DWORD, _DWORD)
// extern int __rtl_memcmp_v1_00(_DWORD, _DWORD, _DWORD)
// extern int __rtl_memcpy_v1_00(_DWORD, _DWORD, _DWORD)
// extern int __rtl_memmove_v1_00(_DWORD, _DWORD, _DWORD)
// extern int __rtl_memset_v1_00(_DWORD, _DWORD, _DWORD)
// extern int __rtl_strcat_v1_00(_DWORD, _DWORD)
// extern int __rtl_strchr_v1_00(_DWORD, _DWORD)
// extern int __rtl_strcmp_v1_00(_DWORD, _DWORD)
// extern int __rtl_strcpy_v1_00(_DWORD, _DWORD)
// extern int __rtl_strlen_v1_00(_DWORD)
// extern int __rtl_strncat_v1_00(_DWORD, _DWORD, _DWORD)
// extern int __rtl_strncmp_v1_00(_DWORD, _DWORD, _DWORD)
// extern int __rtl_strncpy_v1_00(_DWORD, _DWORD, _DWORD)
// extern int __rtl_strstr_v1_00(_DWORD, _DWORD)
// extern int __rtl_strsep_v1_00(_DWORD, _DWORD)
// extern int __rtl_strtok_v1_00(_DWORD, _DWORD)
//-------------------------------------------------------------------------
// Data declarations
extern struct _reent * _rtl_impure_ptr;
#if CHECK_LIBC_INIT
extern char libc_has_init;
#endif
extern char print_off;
#undef snprintf
//-------------------------------------------------------------------------
// Function
//----- snprintf()
int snprintf(char *str, size_t size, const char *fmt, ...) {
va_list args;
va_start (args, fmt);
int result;
int w;
FILE f;
#if CHECK_LIBC_INIT
if (!libc_has_init) {
rtl_libc_init();
}
#endif
if (size >= 0) {
f._flags = 520;
if (size)
w = size - 1;
else
w = 0;
f._w = w; /* write space left for putc() */
f._bf._size = w;
f._file = -1; /* fileno, if Unix descriptor, else -1 */
f._p = str; /* current position in (some) buffer */
f._bf._base = str;
result = __rtl_vfprintf_r_v1_00(_rtl_impure_ptr, &f, fmt, args);
if (result + 1 < 0)
_rtl_impure_ptr->_errno = 139;
if (size)
*f._p = 0;
} else {
_rtl_impure_ptr->_errno = 139;
result = -1;
}
return result;
}
#ifndef ENAC_FLOAT
#undef sprintf
//----- sprintf()
int sprintf(char *str, const char *fmt, ...) {
FILE f;
#if CHECK_LIBC_INIT
if (!libc_has_init) {
rtl_libc_init();
}
#endif
f._flags = 520;
f._w = 0x7FFFFFFF;
f._bf._size = 0x7FFFFFFF;
f._file = -1;
f._p = str;
f._bf._base = str;
va_list args;
va_start (args, fmt);
int result = __rtl_vfprintf_r_v1_00(_rtl_impure_ptr, &f, fmt, args);
*f._p = 0;
// va_end (args);
return result;
}
#undef printf
//----- printf()
int printf(const char *fmt, ...) {
#if CHECK_LIBC_INIT
if (!libc_has_init) {
rtl_libc_init();
}
#endif
if(!print_off) {
va_list args;
va_start (args, fmt);
int result = __rtl_vfprintf_r_v1_00(_rtl_impure_ptr,
_rtl_impure_ptr->_stdout, fmt, args);
__rtl_fflush_r_v1_00(_rtl_impure_ptr, _rtl_impure_ptr->_stdout);
// va_end (args);
return result;
}
else return 0;
}
#undef vprintf
//----- vprintf()
int vprintf(const char * fmt, __VALIST param) {
#if CHECK_LIBC_INIT
if (!libc_has_init) {
rtl_libc_init();
}
#endif
int result = __rtl_vfprintf_r_v1_00(_rtl_impure_ptr,
_rtl_impure_ptr->_stdout, fmt, param);
__rtl_fflush_r_v1_00(_rtl_impure_ptr, _rtl_impure_ptr->_stdout);
return result;
}
#endif // ENAC_FLOAT
#undef vsnprintf
//----- vsnprintf()
int vsnprintf(char *str, size_t size, const char *fmt, __VALIST param) {
int result;
int w;
int v11;
FILE f;
#if CHECK_LIBC_INIT
if (!libc_has_init) {
rtl_libc_init();
}
#endif
if (size >= 0) {
if (size)
w = size - 1;
else
w = 0;
f._flags = 520;
f._p = str;
f._bf._base = str;
f._w = w;
f._bf._size = w;
f._file = -1;
result = __rtl_vfprintf_r_v1_00(_rtl_impure_ptr, &f, fmt, param);
if (result + 1 < 0)
_rtl_impure_ptr->_errno = 139;
if (size)
*f._p = 0;
} else {
_rtl_impure_ptr->_errno = 139;
result = -1;
}
return result;
}
#undef vfprintf
//----- vfprintf()
int vfprintf(FILE *fp, const char *fmt0, va_list ap) {
#if CHECK_LIBC_INIT
if (!libc_has_init) {
rtl_libc_init();
}
#endif
return __rtl_vfprintf_r_v1_00(_rtl_impure_ptr, fp, fmt0, ap);
}
#undef memchr
//----- memchr()
void * memchr(const void * src_void , int c , size_t length) {
return __rtl_memchr_v1_00(src_void, c, length);
}
#undef memcmp
//----- memcmp()
int memcmp(const void *m1, const void *m2, size_t n) {
return __rtl_memcmp_v1_00(m1, m2, n);
}
#undef memcpy
//----- memcpy()
void * memcpy(void *dst0, const void *src0, size_t len0) {
return __rtl_memcpy_v1_00(dst0, src0, len0);
}
#undef memmove
//----- memmove()
void * memmove(void *dst_void, const void *src_void, size_t length) {
return __rtl_memmove_v1_00(dst_void, src_void, length);
}
#undef memset
//----- memset()
void * memset(void *m, int c, size_t n) {
return __rtl_memset_v1_00(m, c, n);
}
#undef strcat
//----- strcat()
char * strcat(char *s1, const char *s2) {
return (char *) __rtl_strcat_v1_00(s1, s2);
}
#undef strchr
//----- strchr()
char * strchr(const char *s1, int i) {
return (char *) __rtl_strchr_v1_00(s1, i);
}
#undef strcmp
//----- strcmp()
int strcmp(const char *s1, const char *s2) {
return __rtl_strcmp_v1_00(s1, s2);
}
#undef strcpy
//----- strcpy()
char * strcpy(char *dst0, const char *src0) {
return (char *) __rtl_strcpy_v1_00(dst0, src0);
}
#undef strlen
//----- strlen()
size_t strlen(const char *str) {
return __rtl_strlen_v1_00(str);
}
#undef strncat
//----- strncat()
char * strncat(char *s1, const char *s2, size_t n) {
return (char *) __rtl_strncat_v1_00(s1, s2, n);
}
#undef strncmp
//----- strncmp()
int strncmp(const char *s1, const char *s2, size_t n) {
return __rtl_strncmp_v1_00(s1, s2, n);
}
#undef strncpy
//----- strncpy()
char * strncpy(char *dst0, const char *src0, size_t count) {
return (char *) __rtl_strncpy_v1_00(dst0, src0, count);
}
#undef strstr
//----- strstr()
char * strstr(const char *searchee, const char *lookfor) {
return (char *) __rtl_strstr_v1_00(searchee, lookfor);
}
#undef strsep
//----- strsep()
char * strsep(char **source_ptr, const char *delim) {
return (char *) __rtl_strsep_v1_00(source_ptr, delim);
}
#undef strtok
//----- strtok()
char * strtok(char *s, const char *delim) {
return (char *) __rtl_strtok_v1_00(s, delim);
}
#undef sscanf
int sscanf(const char *buf, const char *fmt, ...) {
va_list args;
int i;
va_start(args, fmt);
i = _vsscanf(buf, fmt, args);
va_end(args);
return i;
}
char toupper(char ch) {
return ((ch >= 'a' && ch <= 'z') ? ch - 'a' + 'A' : ch);
};
int _stricmp (const char *s1, const char *s2)
{
while (*s2 != 0 && toupper(*s1) == toupper(*s2))
s1++, s2++;
return (int) (toupper(*s1) - toupper(*s2));
}
unsigned long long __aeabi_llsr(unsigned long long val, unsigned int shift)
{
u32 lo = ((u32)val >> shift) | ((u32)(val >> 32) << (32 - shift));
u32 hi = (u32)val >> shift;
return ((unsigned long long)hi << 32) | lo;
}
/*
#undef __VFP_FP__
#if defined(__VFP_FP__)
typedef long __jmp_buf[10 + 8 + 1]; // d8-d15 fpu + fpscr
#else
typedef long __jmp_buf[10];
#endif
int setjmp(__jmp_buf buf) __attribute__ ((noinline));
int setjmp(__jmp_buf buf)
{
register void * r0 __asm__("r0") = buf;
__asm__(
"mov %%ip, %%sp\n"
"stmia %[store]!, {%%r4-%%r9, %%sl, %%fp, %%ip, %%lr}\n"
#if defined(__VFP_FP__)
"vstmia %[store]!, {%%d8-%%d15}\n"
"vmrs %%r1, fpscr\n"
"str %%r1, [%[store]], #4\n"
#endif
"mov.w %r0, #0\n"
: : [store] "r" (r0) :);
}
void longjmp(__jmp_buf buf, long value) __attribute__((noreturn));
void longjmp(__jmp_buf buf, long value)
{
__asm__(
"ldmia %[load]!, {%%r4-%%r9, %%sl, %%fp, %%ip, %%lr}\n"
#if defined(__VFP_FP__)
"vldmia %[load]!, {%%d8-%%d15}\n"
"ldr %%r0, [%[load]], #4\n"
"vmsr fpscr, %%r0\n"
#endif
"mov %%sp, %%ip\n"
"movs %%r0, %%r1\n"
"it eq\n"
"moveq %%r0, #1\n"
"bx lr\n"
: : [load] "r" (buf), [value] "r" (value):);
__builtin_unreachable();
}
*/
extern __attribute__ ((long_call)) unsigned int Rand(void);
int rand(void)
{
return Rand();
}
//----- rtl_dtoi()
int __aeabi_dtoi(double d)
{
return __rtl_dtoi_v1_00(d);
}
//----- __aeabi_dtoui()
int __aeabi_dtoui(double d)
{
return __rtl_dtoui_v1_00(d);
}
//----- __aeabi_i2f()
float __aeabi_i2f(int val)
{
return __rtl_itof_v1_00(val);
}
//----- __aeabi_i2d()
int __aeabi_i2d(int val)
{
return __rtl_itod_v1_00(val);
}
//----- __aeabi_ui2f()
float __aeabi_ui2f(unsigned int val)
{
return __rtl_uitof_v1_00(val);
}
//----- __aeabi_ui2d()
int __aeabi_ui2d(unsigned int val)
{
return __rtl_uitod_v1_00(val);
}
//----- __aeabi_itoa()
char * __aeabi_itoa(int value, char *string, int radix)
{
return (char *)__rtl_ltoa_v1_00(value, string, radix);
}
//----- __aeabi_ltoa()
char * __aeabi_ltoa(int value, char *string, int radix)
{
return (char *)__rtl_ltoa_v1_00(value, string, radix);
}
//----- __aeabi_utoa()
char * __aeabi_utoa(unsigned int value, char *string, int radix)
{
return (char *)__rtl_ultoa_v1_00(value, string, radix);
}
//----- __aeabi_ultoa()
char * __aeabi_ultoa(unsigned int value, char *string, int radix)
{
return (char *)__rtl_ultoa_v1_00(value, string, radix);
}
//----- __aeabi_ftol()
int __aeabi_ftol(float f)
{
return __rtl_ftol_v1_00(f);
}
//----- __aeabi_ftod()
int __aeabi_ftod(float f)
{
return __rtl_ftod_v1_00(f);
}
//----- __aeabi_dtof()
float __aeabi_dtof(double d)
{
return __rtl_dtof_v1_00(d);
}
//----- __aeabi_fadd()
float __aeabi_fadd(float a, float b)
{
return __rtl_fadd_v1_00(a, b);
}
//----- __aeabi_fsub()
float __aeabi_fsub(float a, float b)
{
return __rtl_fsub_v1_00(a, b);
}
//----- __aeabi_fmul()
float __aeabi_fmul(float a, float b)
{
return __rtl_fmul_v1_00(a, b);
}
//----- __aeabi_fdiv()
float __aeabi_fdiv(float a, float b)
{
return __rtl_fdiv_v1_00(a, b);
}
//----- __aeabi_dadd()
int __aeabi_dadd(double a, double b)
{
return __rtl_dadd_v1_00(a, b);
}
//----- __aeabi_dsub()
int __aeabi_dsub(double a, double b)
{
return __rtl_dsub_v1_00(a, b);
}
//----- __aeabi_dmul()
int __aeabi_dmul(double a, double b)
{
return __rtl_dmul_v1_00(a, b);
}
//----- __aeabi_ddiv()
int __aeabi_ddiv(double a, double b)
{
return __rtl_ddiv_v1_00(a, b);
}
//----- __aeabi_dcmpeq()
int __aeabi_dcmpeq(double a, double b)
{
return __rtl_dcmpeq_v1_00(a, b);
}
//----- __aeabi_dcmplt()
int __aeabi_dcmplt(double a, double b)
{
return __rtl_dcmplt_v1_00(a, b);
}
//----- __aeabi_dcmple()
int __aeabi_dcmple(double a, double b)
{
return __rtl_dcmple_v1_00(a, b);
}
//----- __aeabi_dcmpgt()
int __aeabi_dcmpgt(double a, double b)
{
return __rtl_dcmpgt_v1_00(a, b);
}
//----- __aeabi_fcmplt()
int __aeabi_fcmplt(float a, float b)
{
return __rtl_fcmplt_v1_00(a, b);
}
//----- __aeabi_fcmpgt()
int __aeabi_fcmpgt(float a, float b)
{
return __rtl_fcmpgt_v1_00(a, b);
}
extern _LONG_CALL_ void __aeabi_memset(void *dest, size_t n, int c); // { memset(dest, c, n); }
void __aeabi_memclr(void *dest, size_t n) { __aeabi_memset(dest, n, 0); }
void __aeabi_memclr4(void *dest, size_t n) { __aeabi_memset(dest, n, 0); }

View file

@ -0,0 +1,228 @@
/*
* rtl_eabi_cast_ram.o
* pvvx 2016
*/
#include "basic_types.h"
//-------------------------------------------------------------------------
// Function declarations
int rtl_dtoi(double d);
int rtl_dtoui(double d);
float rtl_i2f(int val);
int rtl_i2d(int val);
float rtl_ui2f(unsigned int val);
int rtl_ui2d(unsigned int val);
char *rtl_itoa(int value, char *string, int radix);
char *rtl_ltoa(int value, char *string, int radix);
char *rtl_utoa(unsigned int value, char *string, int radix);
char *rtl_ultoa(unsigned int value, char *string, int radix);
int rtl_ftol(float f);
int rtl_ftod(float f);
float rtl_dtof(double d);
float rtl_fadd(float a, float b);
float rtl_fsub(float a, float b);
float rtl_fmul(float a, float b);
float rtl_fdiv(float a, float b);
int rtl_dadd(double a, double b);
int rtl_dsub(double a, double b);
int rtl_dmul(double a, double b);
int rtl_ddiv(double a, double b);
int rtl_dcmpeq(double a, double b);
int rtl_dcmplt(double a, double b);
int rtl_dcmple(double a, double b);
int rtl_dcmpgt(double a, double b);
int rtl_fcmplt(float a, float b);
int rtl_fcmpgt(float a, float b);
// Extern Calls:
// int __rtl_dtoi_v1_00();
// int __rtl_dtoui_v1_00();
// int __rtl_itof_v1_00();
// int __rtl_itod_v1_00();
// int __rtl_uitof_v1_00();
// int __rtl_uitod_v1_00();
// int __rtl_ltoa_v1_00();
// int __rtl_ultoa_v1_00();
// int __rtl_ftol_v1_00();
// int __rtl_ftod_v1_00();
// int __rtl_dtof_v1_00();
// int __rtl_fadd_v1_00();
// int __rtl_fsub_v1_00();
// int __rtl_fmul_v1_00();
// int __rtl_fdiv_v1_00();
// int __rtl_dadd_v1_00();
// int __rtl_dsub_v1_00();
// int __rtl_dmul_v1_00();
// int __rtl_ddiv_v1_00();
// int __rtl_dcmpeq_v1_00();
// int __rtl_dcmplt_v1_00();
// int __rtl_dcmple_v1_00();
// int __rtl_dcmpgt_v1_00();
// int __rtl_fcmplt_v1_00();
// int __rtl_fcmpgt_v1_00();
//----- rtl_dtoi()
int rtl_dtoi(double d)
{
return __rtl_dtoi_v1_00(d);
}
//----- rtl_dtoui()
int rtl_dtoui(double d)
{
return __rtl_dtoui_v1_00(d);
}
//----- rtl_i2f()
float rtl_i2f(int val)
{
return __rtl_itof_v1_00(val);
}
//----- rtl_i2d()
int rtl_i2d(int val)
{
return __rtl_itod_v1_00(val);
}
//----- rtl_ui2f()
float rtl_ui2f(unsigned int val)
{
return __rtl_uitof_v1_00(val);
}
//----- rtl_ui2d()
int rtl_ui2d(unsigned int val)
{
return __rtl_uitod_v1_00(val);
}
//----- rtl_itoa()
char *rtl_itoa(int value, char *string, int radix)
{
return (char *)__rtl_ltoa_v1_00(value, string, radix);
}
//----- rtl_ltoa()
char *rtl_ltoa(int value, char *string, int radix)
{
return (char *)__rtl_ltoa_v1_00(value, string, radix);
}
//----- rtl_utoa()
char *rtl_utoa(unsigned int value, char *string, int radix)
{
return (char *)__rtl_ultoa_v1_00(value, string, radix);
}
//----- rtl_ultoa()
char *rtl_ultoa(unsigned int value, char *string, int radix)
{
return (char *)__rtl_ultoa_v1_00(value, string, radix);
}
//----- rtl_ftol()
int rtl_ftol(float f)
{
return __rtl_ftol_v1_00(f);
}
//----- rtl_ftod()
int rtl_ftod(float f)
{
return __rtl_ftod_v1_00(f);
}
//----- rtl_dtof()
float rtl_dtof(double d)
{
return __rtl_dtof_v1_00(d);
}
//----- rtl_fadd()
float rtl_fadd(float a, float b)
{
return __rtl_fadd_v1_00(a, b);
}
//----- rtl_fsub()
float rtl_fsub(float a, float b)
{
return __rtl_fsub_v1_00(a, b);
}
//----- rtl_fmul()
float rtl_fmul(float a, float b)
{
return __rtl_fmul_v1_00(a, b);
}
//----- rtl_fdiv()
float rtl_fdiv(float a, float b)
{
return __rtl_fdiv_v1_00(a, b);
}
//----- rtl_dadd()
int rtl_dadd(double a, double b)
{
return __rtl_dadd_v1_00(a, b);
}
//----- rtl_dsub()
int rtl_dsub(double a, double b)
{
return __rtl_dsub_v1_00(a, b);
}
//----- rtl_dmul()
int rtl_dmul(double a, double b)
{
return __rtl_dmul_v1_00(a, b);
}
//----- rtl_ddiv()
int rtl_ddiv(double a, double b)
{
return __rtl_ddiv_v1_00(a, b);
}
//----- rtl_dcmpeq()
int rtl_dcmpeq(double a, double b)
{
return __rtl_dcmpeq_v1_00(a, b);
}
//----- rtl_dcmplt()
int rtl_dcmplt(double a, double b)
{
return __rtl_dcmplt_v1_00(a, b);
}
//----- rtl_dcmple()
int rtl_dcmple(double a, double b)
{
return __rtl_dcmple_v1_00(a, b);
}
//----- rtl_dcmpgt()
int rtl_dcmpgt(double a, double b)
{
return __rtl_dcmpgt_v1_00(a, b);
}
//----- rtl_fcmplt()
int rtl_fcmplt(float a, float b)
{
return __rtl_fcmplt_v1_00(a, b);
}
//----- rtl_fcmpgt()
int rtl_fcmpgt(float a, float b)
{
return __rtl_fcmpgt_v1_00(a, b);
}

View file

@ -0,0 +1,46 @@
/*
* rtl_math_ram..o
* pvvx 2016
*/
#include "basic_types.h"
//-------------------------------------------------------------------------
// Function declarations
float rtl_fabsf(float a);
int rtl_fabs(double a);
float rtl_cos_f32(float a);
float rtl_sin_f32(float a);
// Extern Calls:
// int __rtl_fabsf_v1_00();
// int __rtl_fabs_v1_00();
// int __rtl_cos_f32_v1_00();
// int __rtl_sin_f32_v1_00();
//----- rtl_fabsf()
float rtl_fabsf(float a)
{
return __rtl_fabsf_v1_00(a);
}
//----- rtl_fabs()
int rtl_fabs(double a)
{
return __rtl_fabs_v1_00(a);
}
//----- rtl_cos_f32()
float rtl_cos_f32(float a)
{
return __rtl_cos_f32_v1_00(a);
}
//----- rtl_sin_f32()
float rtl_sin_f32(float a)
{
return __rtl_sin_f32_v1_00(a);
}

View file

@ -0,0 +1,49 @@
/*
* rom_libc_string.h
*
* Definitions for standard library - libc functions.
*/
#ifndef _ROM_LIBC_STRING_H_
#define _ROM_LIBC_STRING_H_
#include <basic_types.h>
#define __rtl_memchr __rtl_memchr_v1_00
#define __rtl_memcmp __rtl_memcmp_v1_00
#define __rtl_memcpy __rtl_memcpy_v1_00
#define __rtl_memmove __rtl_memmove_v1_00
#define __rtl_memset __rtl_memset_v1_00
#define __rtl_strcat __rtl_strcat_v1_00
#define __rtl_strchr __rtl_strchr_v1_00
#define __rtl_strcmp __rtl_strcmp_v1_00
#define __rtl_strcpy __rtl_strcpy_v1_00
#define __rtl_strlen __rtl_strlen_v1_00
#define __rtl_strncat __rtl_strncat_v1_00
#define __rtl_strncmp __rtl_strncmp_v1_00
#define __rtl_strncpy __rtl_strncpy_v1_00
#define __rtl_strstr __rtl_strstr_v1_00
#define __rtl_strsep __rtl_strsep_v1_00
#define __rtl_strtok __rtl_strtok_v1_00
#define __rtl_critical_factorization __rtl_critical_factorization_v1_00
#define __rtl_two_way_short_needle __rtl_two_way_short_needle_v1_00
#define __rtl_two_way_long_needle __rtl_two_way_long_needle_v1_00
extern _LONG_CALL_ void * __rtl_memchr_v1_00(const void * src_void , int c , size_t length);
extern _LONG_CALL_ int __rtl_memcmp_v1_00(const void * m1 , const void * m2 , size_t n);
extern _LONG_CALL_ void * __rtl_memcpy_v1_00(void * __restrict dst0 , const void * __restrict src0 , size_t len0);
extern _LONG_CALL_ void * __rtl_memmove_v1_00( void * dst_void , const void * src_void , size_t length);
extern _LONG_CALL_ void * __rtl_memset_v1_00(void * m , int c , size_t n);
extern _LONG_CALL_ char * __rtl_strcat_v1_00(char *__restrict s1 , const char *__restrict s2);
extern _LONG_CALL_ char * __rtl_strchr_v1_00(const char *s1 , int i);
extern _LONG_CALL_ int __rtl_strcmp_v1_00(const char *s1 , const char *s2);
extern _LONG_CALL_ char* __rtl_strcpy_v1_00(char *dst0 , const char *src0);
extern _LONG_CALL_ size_t __rtl_strlen_v1_00(const char *str);
extern _LONG_CALL_ char * __rtl_strncat_v1_00(char *__restrict s1 , const char *__restrict s2 , size_t n);
extern _LONG_CALL_ int __rtl_strncmp_v1_00(const char *s1 , const char *s2 , size_t n);
extern _LONG_CALL_ char * __rtl_strncpy_v1_00(char *__restrict dst0 , const char *__restrict src0 , size_t count);
extern _LONG_CALL_ char * __rtl_strstr_v1_00(const char *searchee , const char *lookfor);
extern _LONG_CALL_ char * __rtl_strsep_v1_00(register char **source_ptr , register const char *delim);
extern _LONG_CALL_ char * __rtl_strtok_v1_00(register char *__restrict s , register const char *__restrict delim);
#endif /* _ROM_LIBC_STRING_H_ */

View file

@ -0,0 +1,37 @@
#ifndef ROM_LIBGLOSS_RETARGET_H
#define ROM_LIBGLOSS_RETARGET_H
#include <sys/stat.h>
#include <basic_types.h>
#define __rtl_close __rtl_close_v1_00
#define __rtl_fstat __rtl_fstat_v1_00
#define __rtl_isatty __rtl_isatty_v1_00
#define __rtl_lseek __rtl_lseek_v1_00
#define __rtl_open __rtl_open_v1_00
#define __rtl_read __rtl_read_v1_00
#define __rtl_write __rtl_write_v1_00
#define __rtl_sbrk __rtl_sbrk_v1_00
extern _LONG_CALL_ int __rtl_close_v1_00(int fildes);
extern _LONG_CALL_ int __rtl_fstat_v1_00(int fildes , struct stat *st);
extern _LONG_CALL_ int __rtl_isatty_v1_00(int file);
extern _LONG_CALL_ int __rtl_lseek_v1_00(int file , int ptr , int dir);
extern _LONG_CALL_ int __rtl_open_v1_00(char *file , int flags , int mode);
extern _LONG_CALL_ int __rtl_read_v1_00(int file , char *ptr , int len);
extern _LONG_CALL_ int __rtl_write_v1_00(int file , const char *ptr , int len);
extern _LONG_CALL_ void* __rtl_sbrk_v1_00(int incr);
struct _rom_libgloss_ram_map {
int (*libgloss_close)(int fildes);
int (*libgloss_fstat)(int fildes , struct stat *st);
int (*libgloss_isatty)(int file);
int (*libgloss_lseek)(int file , int ptr , int dir);
int (*libgloss_open)(char *file , int flags , int mode);
int (*libgloss_read)(int file , char *ptr , int len);
int (*libgloss_write)(int file , const char *ptr , int len);
void* (*libgloss_sbrk)(int incr);
};
#endif /* ROM_LIBGLOSS_RETARGET_H */