merlin16_field_access.c (5887B)
1 /************************************************************************************** 2 ************************************************************************************** 3 * File Name : merlin16_field_access.c * 4 * Created On : 29/04/2013 * 5 * Created By : Kiran Divakar * 6 * Description : APIs to access Serdes IP Registers and Reg fields * 7 * Revision : * 8 * * 9 * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file. 10 * 11 * Copyright 2007-2019 Broadcom Inc. All rights reserved. * 12 * No portions of this material may be reproduced in any form without * 13 * the written permission of: * 14 * Broadcom Corporation * 15 * 5300 California Avenue * 16 * Irvine, CA 92617 * 17 * * 18 * All information contained in this document is Broadcom Corporation * 19 * company private proprietary, and trade secret. * 20 */ 21 22 /** @file merlin16_field_access.c 23 * Registers and field access 24 */ 25 26 #include "merlin16_field_access.h" 27 #include "merlin16_functions.h" 28 #include "merlin16_internal.h" 29 #include "merlin16_internal_error.h" 30 31 /* If SERDES_EVAL is defined, then is_ate_log_enabled() is queried to *\ 32 \* know whether to log ATE. merlin16_access.h provides that function. */ 33 34 err_code_t _merlin16_pmd_rdt_field(srds_access_t *sa__, uint16_t addr, uint8_t shift_left, uint8_t shift_right, uint16_t *val_p) { 35 36 EFUN(merlin16_pmd_rdt_reg(sa__, addr,val_p)); 37 *val_p <<= shift_left; /* Move the MSB to the left most [shift_left = (15-msb)] */ 38 *val_p >>= shift_right; /* Right shift entire field to bit 0 [shift_right = (15-msb+lsb)] */ 39 40 return(ERR_CODE_NONE); 41 } 42 43 err_code_t _merlin16_pmd_rdt_field_signed(srds_access_t *sa__, uint16_t addr, uint8_t shift_left, uint8_t shift_right, int16_t *val_p) { 44 45 EFUN(merlin16_pmd_rdt_reg(sa__, addr,(uint16_t *)val_p)); 46 *val_p <<= shift_left; /* Move the sign bit to the left most [shift_left = (15-msb)] */ 47 *val_p >>= shift_right; /* Right shift entire field to bit 0 [shift_right = (15-msb+lsb)] */ 48 49 return(ERR_CODE_NONE); 50 } 51 52 /*-------------------------------*/ 53 /* Byte Write and Read Functions */ 54 /*-------------------------------*/ 55 56 err_code_t _merlin16_pmd_mwr_reg_byte(srds_access_t *sa__, uint16_t addr, uint16_t mask, uint8_t lsb, uint8_t val) { 57 58 59 EFUN(merlin16_pmd_mwr_reg(sa__, addr, mask, lsb, (uint16_t) val)); 60 61 return(ERR_CODE_NONE); 62 } 63 64 err_code_t _merlin16_pmd_rdt_field_byte(srds_access_t *sa__, uint16_t addr, uint8_t shift_left, uint8_t shift_right, uint8_t *val8_p) { 65 66 uint16_t val = 0; 67 68 EFUN(merlin16_pmd_rdt_reg(sa__, addr,&val)); 69 70 val <<= shift_left; /* Move the MSB to the left most [shift_left = (15-msb)] */ 71 val >>= shift_right; /* Right shift entire field to bit 0 [shift_right = (15-msb+lsb)] */ 72 73 *val8_p = (uint8_t) val; 74 75 return(ERR_CODE_NONE); 76 } 77 78 err_code_t _merlin16_pmd_rdt_field_signed_byte(srds_access_t *sa__, uint16_t addr, uint8_t shift_left, uint8_t shift_right, int8_t *val8_p) { 79 80 int16_t val = 0; 81 82 EFUN(merlin16_pmd_rdt_reg(sa__, addr,(uint16_t *) &val)); 83 84 val <<= shift_left; /* Move the sign bit to the left most [shift_left = (15-msb)] */ 85 val >>= shift_right; /* Right shift entire field to bit 0 [shift_right = (15-msb+lsb)] */ 86 87 *val8_p = (int8_t) val; 88 return(ERR_CODE_NONE); 89 } 90 91 92 /*-------------------------------*/ 93 /* EVAL specific functions */ 94 /*-------------------------------*/ 95 96 uint16_t _merlin16_pmd_rde_reg(srds_access_t *sa__, uint16_t addr, err_code_t *err_code_p) 97 { 98 uint16_t data = 0; 99 100 EPFUN(merlin16_pmd_rdt_reg(sa__, addr, &data)); 101 102 return data; 103 } 104 105 uint16_t _merlin16_pmd_rde_field(srds_access_t *sa__, uint16_t addr, uint8_t shift_left, uint8_t shift_right, err_code_t *err_code_p) 106 { 107 uint16_t data; 108 109 EPSTM(data = _merlin16_pmd_rde_reg(sa__, addr, err_code_p)); 110 111 data <<= shift_left; /* Move the sign bit to the left most [shift_left = (15-msb)] */ 112 data >>= shift_right; /* Right shift entire field to bit 0 [shift_right = (15-msb+lsb)] */ 113 114 return data; 115 } 116 117 int16_t _merlin16_pmd_rde_field_signed(srds_access_t *sa__, uint16_t addr, uint8_t shift_left, uint8_t shift_right, err_code_t *err_code_p) 118 { 119 int16_t data; 120 121 EPSTM(data = (int16_t) _merlin16_pmd_rde_reg(sa__, addr, err_code_p)); /* convert it to signed */ 122 123 data <<= shift_left; /* Move the sign bit to the left most [shift_left = (15-msb)] */ 124 data >>= shift_right; /* Move to the right with sign extension [shift_right = (15-msb+lsb)] */ 125 126 return data; 127 } 128 129 uint8_t _merlin16_pmd_rde_field_byte(srds_access_t *sa__, uint16_t addr, uint8_t shift_left, uint8_t shift_right, err_code_t *err_code_p) { 130 return ((uint8_t) _merlin16_pmd_rde_field(sa__, addr, shift_left, shift_right, err_code_p)); 131 } 132 133 int8_t _merlin16_pmd_rde_field_signed_byte(srds_access_t *sa__, uint16_t addr, uint8_t shift_left, uint8_t shift_right, err_code_t *err_code_p) { 134 return ((int8_t) _merlin16_pmd_rde_field_signed(sa__, addr, shift_left, shift_right, err_code_p)); 135 }