AG903ライブラリリファレンス
内容インデックスホーム
Body Source
本文ソース
1: 11: 12: 16: 17: 18: #include "AG903_common.h" 19: 20: #include "osp/ospprm.h" 21: #include "osp/ospmgr.h" 22: #include "osp.h" 23: 24: 25: 27: #define OSP_CMDID(ID) ((ID) << 28) 28: 29: 30: 32: #define OSP_CMD_BAS(LEN) (OSP_CMDID(OSP_CMDID_BAS) | (((LEN) & AG903_OSP_CMD_BAS_SIZE) << 0)) 33: 34: 37: #define OSP_CMD_BAB(LEN,F) (OSP_CMDID(OSP_CMDID_BAB) | (((F) & 0x1) << 27) | (((LEN) & AG903_OSP_CMD_BAB_SIZE) << 0)) 38: 39: 40: #define OSP_CMD_ADDR(ADR) ((ADR) & 0xFFFFFFFC) 41: 42: 43: #define OSP_CMD_DATA(DAT) (DAT) 44: 45: 46: #define OSP_CMD_BAW() (OSP_CMDID(OSP_CMDID_BAW)) 47: 48: 50: #define OSP_CMD_INTR(ID) (OSP_CMDID(OSP_CMDID_INTR) | (((ID) & 0x3F) << 0)) 51: 52: 54: #define OSP_CMD_EVENT(ID) (OSP_CMDID(OSP_CMDID_EVENT) | (((ID) & 0x3F) << 0)) 55: 56: 58: #define OSP_CMD_EVENTD(ID) (OSP_CMDID(OSP_CMDID_EVENTD) | (((ID) & 0x3F) << 0)) 59: 60: 62: #define OSP_CMD_EVENTC(ID) (OSP_CMDID(OSP_CMDID_EVENTC) | (((ID) & 0x3F) << 0)) 63: 64: 66: #define OSP_CMD_SETF(FLAG) (OSP_CMDID(OSP_CMDID_SETF) | (((FLAG) & 0x0FFFFFFF) << 0)) 67: 68: 70: #define OSP_CMD_CLRF(FLAG) (OSP_CMDID(OSP_CMDID_CLRF) | (((FLAG) & 0x0FFFFFFF) << 0)) 71: 72: 74: #define OSP_CMD_NOP() (OSP_CMDID(OSP_CMDID_NOP)) 75: 76: 77: 78: typedef struct _OSPCmdDesc { 79: uint32_t *Buf; 80: uint32_t BufLen; 81: uint32_t CurLen; 82: uint32_t *WrBuf; 83: uint32_t *RdBuf; 84: uint32_t BuffMode; 85: uint32_t Reserved[2]; 86: } OSPCmdDesc; 87: 88: 89: typedef struct _AG903_OSPMgrChStat{ 90: void* cmdbuf; 91: } AG903_OSPMgrChStat; 92: 93: 94: typedef struct _AG903_OSPMgrHandleStat{ 95: uint8_t lock; 96: uint8_t reserve[3]; 97: } AG903_OSPMgrHandleStat; 98: 99: static AG903_OSPMgrChStat OspChStat[AG903_OSP_CH_NUM]; 100: static AG903_OSPMgrHandleStat OspHandleStat[AG903_OSP_CH_NUM]; 101: 102: 103: static int32_t OSPMgrCheckHandle(AG903_OSPMgrHandle *handle,uint8_t *ch); 104: static int32_t OSPMgrCheckOverflow(uint8_t ch); 105: static int32_t OSPMgrSetCommand(uint8_t ch, uint32_t c); 106: #if AG903_OSP_CMD_PARSE 107: static int32_t OSPMgrParseCommand(OSPCmdDesc *desc); 108: static uint16_t OSPMgrParseCommandCRC(uint8_t mode, uint8_t* data, uint32_t s_adr, uint32_t e_adr); 109: #endif 110: 111: 112: 121: int32_t AG903_OSPMgrInit(void) 122: { 123: int32_t ch, evt; 124: 125: 126: for (ch = 0;ch < AG903_OSP_CH_NUM;ch++) { 127: AG903_OSPPrmFIFOCTRL(ch); 128: AG903_OSPPrmPRIOR(ch, 0); 129: } 130: 131: 132: for (evt=0; evt<AG903_OSP_EVENT_NUM; evt++) 133: AG903_OSPPrmEnableEvent(evt, 0, 0); 134: 135: 136: AG903_OSPPrmFLAGCLR(0x0FFFFFFF); 137: 138: for (ch = 0;ch < AG903_OSP_CH_NUM;ch++) { 139: OspChStat[ch].cmdbuf = NULL; 140: OspHandleStat[ch].lock = false; 141: } 142: 143: return AG903_ENONE; 144: } 145: 146: 156: int32_t AG903_OSPMgrGetHandle(AG903_OSPMgrHandle **handle) 157: { 158: int32_t rc = AG903_ENONE; 159: int32_t loop; 160: 161: if(NULL == handle) { 162: rc = -AG903_EINVAL; 163: } 164: 165: for(loop=0; loop<AG903_OSP_CH_NUM; loop++) { 166: if(false == OspHandleStat[loop].lock) { 167: OspHandleStat[loop].lock = true; 168: break; 169: } 170: } 171: if(AG903_OSP_CH_NUM <= loop) { 172: 173: return -AG903_EBUSY; 174: } 175: 176: (*handle) = (AG903_OSPMgrHandle*)&OspHandleStat[loop]; 177: 178: return rc; 179: } 180: 181: 191: int32_t AG903_OSPMgrReleaseHandle(AG903_OSPMgrHandle *handle) 192: { 193: int32_t rc = AG903_ENONE; 194: uint8_t ch; 195: uint8_t stat, cnt; 196: 197: if(NULL == handle) { 198: rc = -AG903_EINVAL; 199: } 200: 201: rc = OSPMgrCheckHandle(handle, &ch); 202: 203: if (rc == AG903_ENONE) { 204: rc = AG903_OSPMgrGetStat(handle, &stat, &cnt); 205: } 206: 207: if (rc == AG903_ENONE) { 208: if (stat != 0) { 209: 210: rc = -AG903_EBUSY; 211: } 212: } 213: 214: if (rc == AG903_ENONE) { 215: AG903_OSPMgrDisable(handle); 216: OspHandleStat[ch].lock = false; 217: } 218: 219: return rc; 220: } 221: 222: 237: int32_t AG903_OSPMgrSetCommandBuf(AG903_OSPMgrHandle *handle, AG903_OSPCmdBuf *param, bool init) 238: { 239: int32_t rc = AG903_ENONE; 240: uint8_t ch; 241: OSPCmdDesc *desc; 242: 243: if(NULL == handle || NULL == param) { 244: rc = -AG903_EINVAL; 245: } 246: 247: rc = OSPMgrCheckHandle(handle, &ch); 248: 249: if (rc == AG903_ENONE) { 250: if ((AG903_OSP_BUFMODE_NUM <= param->mode) || (NULL == param->addr) || (0 == param->size)) { 251: 252: rc = -AG903_EINVAL; 253: } 254: } 255: 256: if (rc == AG903_ENONE) { 257: 273: OspChStat[ch].cmdbuf = (void*)param->addr; 274: desc = (OSPCmdDesc*)param->addr; 275: desc->Buf = param->addr + sizeof(OSPCmdDesc) / sizeof(uint32_t); 276: desc->BufLen = (param->size - sizeof(OSPCmdDesc)) / sizeof(uint32_t); 277: desc->CurLen = 0; 278: desc->WrBuf = desc->Buf; 279: desc->RdBuf = desc->Buf; 280: desc->BuffMode = param->mode; 281: if(true == init) { 282: AG903_OSPMgrClearCommand(handle); 283: } 284: } 285: 286: return rc; 287: } 288: 289: 298: int32_t AG903_OSPMgrClearCommand(AG903_OSPMgrHandle *handle) 299: { 300: int32_t rc = AG903_ENONE; 301: uint8_t ch; 302: OSPCmdDesc *desc; 303: 304: if(NULL == handle) { 305: rc = -AG903_EINVAL; 306: } 307: 308: rc = OSPMgrCheckHandle(handle, &ch); 309: 310: if (rc == AG903_ENONE) { 311: desc = (OSPCmdDesc*)OspChStat[ch].cmdbuf; 312: 313: desc->CurLen = 0; 314: desc->RdBuf = desc->Buf; 315: desc->WrBuf = desc->Buf; 316: } 317: 318: return rc; 319: } 320: 321: 331: int32_t AG903_OSPMgrGetCommandCnt(AG903_OSPMgrHandle *handle, uint32_t *cnt) 332: { 333: int32_t rc = AG903_ENONE; 334: uint8_t ch; 335: OSPCmdDesc *desc; 336: 337: if(NULL == handle) { 338: rc = -AG903_EINVAL; 339: } 340: 341: rc = OSPMgrCheckHandle(handle, &ch); 342: 343: if (rc == AG903_ENONE) { 344: if (cnt == NULL) { 345: 346: rc = -AG903_EINVAL; 347: } 348: } 349: if (rc == AG903_ENONE) { 350: if(NULL == OspChStat[ch].cmdbuf) { 351: 352: rc = -AG903_ENODATA; 353: } 354: } 355: 356: if (rc == AG903_ENONE) { 357: desc = (OSPCmdDesc*)OspChStat[ch].cmdbuf; 358: (*cnt) = desc->CurLen; 359: } 360: 361: return rc; 362: } 363: 364: 376: int32_t AG903_OSPMgrSetPriority(AG903_OSPMgrHandle *handle, uint8_t priority) 377: { 378: int32_t rc = AG903_ENONE; 379: uint8_t ch; 380: 381: if(NULL == handle) { 382: rc = -AG903_EINVAL; 383: } 384: 385: rc = OSPMgrCheckHandle(handle, &ch); 386: 387: if (rc == AG903_ENONE) { 388: if (priority >= AG903_OSP_PRI_NUM) { 389: 390: rc = -AG903_EINVAL; 391: } 392: } 393: 394: if (rc == AG903_ENONE) { 395: AG903_OSPPrmPRIOR(ch, priority); 396: } 397: 398: return rc; 399: } 400: 401: 409: int32_t AG903_OSPMgrEnable(AG903_OSPMgrHandle *handle) 410: { 411: int32_t rc = AG903_ENONE; 412: uint8_t ch; 413: 414: if(NULL == handle) { 415: rc = -AG903_EINVAL; 416: } 417: 418: rc = OSPMgrCheckHandle(handle, &ch); 419: 420: if (rc == AG903_ENONE) { 421: AG903_OSPPrmCTRL(ch, true); 422: } 423: 424: return rc; 425: } 426: 427: 435: int32_t AG903_OSPMgrDisable(AG903_OSPMgrHandle *handle) 436: { 437: int32_t rc = AG903_ENONE; 438: uint8_t ch; 439: 440: if(NULL == handle) { 441: rc = -AG903_EINVAL; 442: } 443: 444: rc = OSPMgrCheckHandle(handle, &ch); 445: 446: if (rc == AG903_ENONE) { 447: AG903_OSPPrmCTRL(ch, false); 448: } 449: 450: return rc; 451: } 452: 453: 463: int32_t AG903_OSPMgrGetStat(AG903_OSPMgrHandle *handle, uint8_t *stat, uint8_t *cnt) 464: { 465: int32_t rc = AG903_ENONE; 466: uint8_t ch; 467: 468: if(NULL == handle) { 469: rc = -AG903_EINVAL; 470: } 471: 472: rc = OSPMgrCheckHandle(handle, &ch); 473: 474: if (rc == AG903_ENONE) { 475: if ((stat == NULL) 476: || (cnt == NULL)) { 477: 478: rc = -AG903_EINVAL; 479: } 480: } 481: 482: if (rc == AG903_ENONE) { 483: AG903_OSPPrmSTAT(ch, stat, cnt); 484: } 485: 486: return rc; 487: } 488: 489: 499: int32_t AG903_OSPMgrGetFIFOStat(AG903_OSPMgrHandle *handle, uint8_t *ovf, uint8_t *siz) 500: { 501: int32_t rc = AG903_ENONE; 502: uint8_t ch; 503: 504: if(NULL == handle) { 505: rc = -AG903_EINVAL; 506: } 507: 508: rc = OSPMgrCheckHandle(handle, &ch); 509: 510: if (rc == AG903_ENONE) { 511: if ((ovf == NULL) 512: || (siz == NULL)) { 513: 514: rc = -AG903_EINVAL; 515: } 516: } 517: 518: if (rc == AG903_ENONE) { 519: AG903_OSPPrmFIFOSTAT(ch, ovf, siz); 520: } 521: 522: return rc; 523: } 524: 525: 535: int32_t AG903_OSPMgrSetFlag(uint32_t flag) 536: { 537: int32_t rc = AG903_ENONE; 538: 539: if ((flag & 0xF0000000)) { 540: 541: rc = -AG903_EINVAL; 542: } 543: 544: if (rc == AG903_ENONE) { 545: AG903_OSPPrmFLAGSET(flag); 546: } 547: 548: return rc; 549: } 550: 551: 561: int32_t AG903_OSPMgrClearFlag(uint32_t flag) 562: { 563: int32_t rc = AG903_ENONE; 564: 565: if ((flag & 0xF0000000)) { 566: 567: rc = -AG903_EINVAL; 568: } 569: 570: if (rc == AG903_ENONE) { 571: AG903_OSPPrmFLAGCLR(flag); 572: } 573: 574: return rc; 575: } 576: 577: 586: int32_t AG903_OSPMgrGetFlagStat(uint32_t *flag) 587: { 588: int32_t rc = AG903_ENONE; 589: 590: if (flag == NULL) { 591: 592: rc = -AG903_EINVAL; 593: } 594: 595: if (rc == AG903_ENONE) { 596: AG903_OSPPrmFLAGSTAT(flag); 597: } 598: 599: return rc; 600: } 601: 602: 619: int32_t AG903_OSPMgrSetEventCntEnable(uint32_t evt, uint8_t enable, uint8_t cnt) 620: { 621: int32_t rc = AG903_ENONE; 622: 623: if (evt >= AG903_OSP_EVENT_NUM) { 624: 625: rc = -AG903_EINVAL; 626: } 627: 628: if (rc == AG903_ENONE) { 629: if ((enable & ~0x01) 630: || (cnt & ~0x0F)) { 631: 632: rc = -AG903_EINVAL; 633: } 634: } 635: 636: if (rc == AG903_ENONE) { 637: AG903_OSPPrmEnableEvent(evt, enable, cnt); 638: } 639: 640: return rc; 641: } 642: 643: 657: int32_t AG903_OSPMgrGetEventStat(uint32_t evt, uint8_t *ovf, uint8_t *cnt) 658: { 659: int32_t rc = AG903_ENONE; 660: 661: if (evt >= AG903_OSP_EVENT_NUM) { 662: 663: rc = -AG903_EINVAL; 664: } 665: 666: if (rc == AG903_ENONE) { 667: if ((ovf == NULL) 668: || (cnt == NULL)) { 669: 670: rc = -AG903_EINVAL; 671: } 672: } 673: 674: if (rc == AG903_ENONE) { 675: AG903_OSPPrmGetEventStat(evt, ovf, cnt); 676: } 677: 678: return rc; 679: } 680: 681: 699: int32_t AG903_OSPMgrSetFIFO(AG903_OSPMgrHandle *handle, uint32_t setcnt) 700: { 701: int32_t rc = AG903_ENONE; 702: uint8_t ch; 703: OSPCmdDesc *desc; 704: uint8_t ovf = 0; 705: uint8_t siz = 0; 706: uint32_t MaxLen; 707: 708: if(NULL == handle) { 709: rc = -AG903_EINVAL; 710: } 711: 712: rc = OSPMgrCheckHandle(handle, &ch); 713: if(AG903_ENONE != rc) { 714: 715: return -AG903_EINVAL; 716: } 717: if(NULL == OspChStat[ch].cmdbuf) { 718: 719: return -AG903_ENODATA; 720: } 721: 722: desc = (OSPCmdDesc*)OspChStat[ch].cmdbuf; 723: if(0 == desc->CurLen) { 724: 725: return -AG903_ENODATA; 726: } 727: 728: if (setcnt > desc->CurLen) { 729: 730: return -AG903_EINVAL; 731: } 732: 733: AG903_OSPPrmFIFOSTAT(ch, &ovf, &siz); 734: 735: if (ovf == true) { 736: 737: return -AG903_EOVERFLOW; 738: } 739: if ((siz == 0) || (siz < setcnt)) { 740: 741: return -AG903_EBUSY; 742: } 743: 744: #if AG903_OSP_CMD_PARSE 745: if (rc == AG903_ENONE) { 746: rc = OSPMgrParseCommand(desc); 747: } 748: #endif 749: 750: if (AG903_OSP_BUFMODE_RING == desc->BuffMode) { 751: MaxLen = desc->BufLen; 752: } 753: else { 754: MaxLen = desc->CurLen; 755: } 756: 757: if ((desc->RdBuf + setcnt) > (desc->Buf + MaxLen)) { 758: uint32_t Len; 759: 772: Len = (desc->Buf + MaxLen) - desc->RdBuf; 773: AG903_OSPPrmFIFODT(ch, desc->RdBuf, Len); 774: 775: desc->RdBuf = desc->Buf; 776: setcnt -= Len; 777: 778: if (AG903_OSP_BUFMODE_RING == desc->BuffMode) { 779: desc->CurLen -= Len; 780: } 781: } 782: 783: AG903_OSPPrmFIFODT(ch, desc->RdBuf, setcnt); 784: desc->RdBuf += setcnt; 785: 786: if (AG903_OSP_BUFMODE_RING == desc->BuffMode) { 787: desc->CurLen -= setcnt; 788: } 789: 790: if (desc->RdBuf >= (desc->Buf + MaxLen)) { 791: desc->RdBuf = desc->Buf; 792: } 793: 794: return rc; 795: } 796: 797: 807: int32_t AG903_OSPMgrClearFIFO(AG903_OSPMgrHandle *handle) 808: { 809: int32_t rc = AG903_ENONE; 810: uint8_t ch; 811: 812: if(NULL == handle) { 813: rc = -AG903_EINVAL; 814: } 815: 816: rc = OSPMgrCheckHandle(handle, &ch); 817: 818: if (rc == AG903_ENONE) { 819: AG903_OSPPrmFIFOCTRL(ch); 820: } 821: 822: return rc; 823: } 824: 825: 836: int32_t AG903_OSPMgrSetCommand(AG903_OSPMgrHandle *handle, AG903_OSPMgrCmd cmd, uint32_t param) 837: { 838: int32_t rc = AG903_ENONE; 839: uint32_t cmddt; 840: uint8_t ch = -1; 841: 842: if(NULL == handle) { 843: rc = -AG903_EINVAL; 844: } 845: 846: rc = OSPMgrCheckHandle(handle, &ch); 847: 848: if (rc == AG903_ENONE) { 849: rc = OSPMgrCheckOverflow(ch); 850: } 851: 852: switch(cmd) { 853: case AG903_OSP_CMD_BUS_SINGLE: 854: if( (0==param) || (AG903_OSP_CMD_BAS_SIZE<param) ) { 855: 856: rc = -AG903_EINVAL; 857: } 858: else { 859: cmddt = OSP_CMD_BAS(param); 860: } 861: break; 862: case AG903_OSP_CMD_BUS_BURST_FIX: 863: if( (0==param) || (AG903_OSP_CMD_BAB_SIZE<param) ) { 864: 865: rc = -AG903_EINVAL; 866: } 867: else { 868: cmddt = OSP_CMD_BAB(param, 1); 869: } 870: break; 871: case AG903_OSP_CMD_BUS_BURST_INC: 872: if( (0==param) || (AG903_OSP_CMD_BAB_SIZE<param) ) { 873: 874: rc = -AG903_EINVAL; 875: } 876: else { 877: cmddt = OSP_CMD_BAB(param, 0); 878: } 879: break; 880: case AG903_OSP_CMD_BUS_ADDR: 881: if( (0==param) || (param%4) ) { 882: 883: rc = -AG903_EINVAL; 884: } 885: else { 886: cmddt = OSP_CMD_ADDR(param); 887: } 888: break; 889: case AG903_OSP_CMD_BUS_DATA: 890: cmddt = OSP_CMD_DATA(param); 891: break; 892: case AG903_OSP_CMD_BUS_WAIT: 893: cmddt = OSP_CMD_BAW(); 894: break; 895: case AG903_OSP_CMD_INTR_WAIT: 896: cmddt = OSP_CMD_INTR(param); 897: break; 898: case AG903_OSP_CMD_EVNT_WAIT: 899: if(AG903_OSP_EVENT_NUM<=param) { 900: 901: rc = -AG903_EINVAL; 902: } 903: else { 904: cmddt = OSP_CMD_EVENT(param); 905: } 906: break; 907: case AG903_OSP_CMD_EVNT_DEC: 908: if(AG903_OSP_EVENT_NUM<=param) { 909: 910: rc = -AG903_EINVAL; 911: } 912: else { 913: cmddt = OSP_CMD_EVENTD(param); 914: } 915: break; 916: case AG903_OSP_CMD_EVNT_CLR: 917: if(AG903_OSP_EVENT_NUM<=param) { 918: 919: rc = -AG903_EINVAL; 920: } 921: else { 922: cmddt = OSP_CMD_EVENTC(param); 923: } 924: break; 925: case AG903_OSP_CMD_FLAG_SET: 926: cmddt = OSP_CMD_SETF(param); 927: break; 928: case AG903_OSP_CMD_FLAG_CLR: 929: cmddt = OSP_CMD_CLRF(param); 930: break; 931: case AG903_OSP_CMD_NOP: 932: cmddt = OSP_CMD_NOP(); 933: break; 934: default: 935: 936: rc = -AG903_EINVAL; 937: break; 938: } 939: 940: if (rc == AG903_ENONE) { 941: rc = OSPMgrSetCommand(ch, cmddt); 942: } 943: 944: return rc; 945: 946: } 947: 948: 956: static int32_t OSPMgrCheckHandle(AG903_OSPMgrHandle *handle, uint8_t *ch) 957: { 958: int32_t rc = AG903_ENONE; 959: uint32_t channel; 960: 961: 962: channel = ((uint32_t)handle - (uint32_t)OspHandleStat) / sizeof(AG903_OSPMgrHandleStat); 963: 964: if( (AG903_OSP_CH_NUM <= channel) || 965: (&OspHandleStat[channel] != (AG903_OSPMgrHandleStat*)handle) ) { 966: 967: rc = -AG903_EINVAL; 968: } 969: else { 970: (*ch) = (uint8_t)channel; 971: } 972: 973: return rc; 974: } 975: 976: 986: static int32_t OSPMgrCheckOverflow(uint8_t ch) 987: { 988: int32_t rc = AG903_ENONE; 989: OSPCmdDesc *desc; 990: 991: 992: desc = (OSPCmdDesc*)OspChStat[ch].cmdbuf; 993: 994: if ((desc->Buf == (uint32_t *)NULL ) 995: || (desc->BufLen == 0 ) 996: || (desc->CurLen > desc->BufLen ) 997: || (desc->RdBuf < desc->Buf ) 998: || (desc->Buf + desc->BufLen <= desc->RdBuf ) 999: || (desc->WrBuf < desc->Buf ) 1000: || (desc->Buf + desc->BufLen <= desc->WrBuf )) { 1001: 1002: rc = -AG903_EINVAL; 1003: } 1004: 1005: if (rc == AG903_ENONE) { 1006: if ((desc->CurLen + 1) > desc->BufLen) { 1007: 1008: rc = -AG903_EOVERFLOW; 1009: } 1010: } 1011: 1012: return rc; 1013: } 1014: 1015: 1023: static int32_t OSPMgrSetCommand(uint8_t ch, uint32_t c) 1024: { 1025: int32_t rc = AG903_ENONE; 1026: OSPCmdDesc *desc; 1027: 1028: 1029: desc = (OSPCmdDesc*)OspChStat[ch].cmdbuf; 1030: 1031: *(desc->WrBuf) = c; 1032: desc->WrBuf++; 1033: desc->CurLen++; 1034: 1035: if (desc->BuffMode) { 1036: if (desc->WrBuf >= (desc->Buf + desc->BufLen)) { 1037: desc->WrBuf = desc->Buf; 1038: } 1039: } 1040: 1041: return rc; 1042: } 1043: 1044: #if AG903_OSP_CMD_PARSE 1045: 1053: static int32_t OSPMgrParseCommand(OSPCmdDesc *desc) 1054: { 1055: int32_t rc = AG903_ENONE; 1056: uint32_t *buf, *endbuf; 1057: uint8_t cmdid; 1058: uint32_t len; 1059: uint32_t ii; 1060: 1061: 1062: buf = desc->RdBuf; 1063: endbuf = desc->Buf + desc->BufLen; 1064: 1065: for (ii = 0;ii < desc->CurLen;ii++) { 1066: cmdid = (*buf >> 28); 1067: 1068: switch (cmdid) { 1069: case OSP_CMDID_BAS: 1070: len = ((*buf & AG903_OSP_CMD_BAS_SIZE) << 1) + 1; 1071: buf += len; 1072: ii += len; 1073: break; 1074: 1075: case OSP_CMDID_BAB: 1076: len = (*buf & AG903_OSP_CMD_BAB_SIZE) + 1; 1077: buf += len; 1078: ii += len; 1079: break; 1080: 1081: case OSP_CMDID_BAW: 1082: case OSP_CMDID_INTR: 1083: case OSP_CMDID_EVENT: 1084: case OSP_CMDID_EVENTD: 1085: case OSP_CMDID_EVENTC: 1086: case OSP_CMDID_SETF: 1087: case OSP_CMDID_CLRF: 1088: case OSP_CMDID_NOP: 1089: break; 1090: 1091: default: 1092: 1093: rc = -AG903_EFAULT; 1094: goto err; 1095: } 1096: 1097: buf++; 1098: if (buf > endbuf) { buf = desc->Buf; } 1099: } 1100: 1101: err: 1102: return rc; 1103: } 1104: 1105: 1116: static uint16_t OSPMgrParseCommandCRC(uint8_t mode, uint8_t* data, uint32_t s_adr, uint32_t e_adr) 1117: { 1118: uint32_t crc; 1119: uint8_t *d_adr; 1120: uint32_t d_len; 1121: uint16_t ret; 1122: 1123: 1131: 1132: 1133: crc = 0; 1134: d_adr = (data + s_adr); 1135: d_len = e_adr - s_adr + 2; 1136: 1137: if (mode == 0) { 1138: 1139: *(data + e_adr + 0) = 0; 1140: *(data + e_adr + 1) = 0; 1141: } 1142: else { 1143: } 1144: 1145: for (uint32_t ii = 0;ii < d_len;ii++) { 1146: crc = crc | *(d_adr++); 1147: 1148: 1149: for (int8_t jj = 0;jj < 8;jj++) { 1150: crc = crc << 1; 1151: 1152: if ((crc & 0x01000000) != 0) { 1153: crc = crc ^ 0x00102100; 1154: } 1155: } 1156: } 1157: 1158: ret = (uint16_t)((crc & 0x00ffff00) >> 8); 1159: 1160: if (mode == 0) { 1161: *(d_adr - 2) = (uint8_t)((ret >> 8) & 0x00ff); 1162: *(d_adr - 1) = (uint8_t)((ret >> 0) & 0x00ff); 1163: } 1164: else { 1165: 1166: } 1167: 1168: return ret; 1169: } 1170: #endif
Copyright (c) 2017-2025 Axell Corporation. All rights reserved.