📄 wireless_cc1100rx.lst
字号:
973 {
974 1 unsigned short output;
975 1
976 1 // if a function tries to pull a value from an empty buffer, set the
977 1 // underflow flag and exit the function
978 1 if(DACTXFIFO_EMPTY)
979 1 {
980 2 DACTXFIFO_UF = 1;
C51 COMPILER V8.05a WIRELESS_CC1100RX 11/07/2007 15:16:42 PAGE 17
981 2 return 0;
982 2 }
983 1
984 1 // else the buffer is not empty, pull the value and return it
985 1 else
986 1 {
987 2 DACTXFIFO_FULL = 0;
988 2 // update the first pointer, wrap around if necessary
989 2 if (DACTXFIFO_FIRST==DACTXFIFO_FIFOSIZE-1) DACTXFIFO_FIRST = 0;
990 2 else (DACTXFIFO_FIRST)++;
991 2
992 2 // save output value
993 2 output = DACTXFIFO_FIFO[DACTXFIFO_FIRST];
994 2 // decrement buffer size
995 2 if (--(DACTXFIFO_COUNT) == 0) DACTXFIFO_EMPTY = 1;
996 2
997 2 if((DACTXFIFO_DECOMPRESS_HALT) &&
998 2 (DACTXFIFO_COUNT <= DACTXFIFO_FIFOSIZE - 2))
999 2 {
1000 3 DACTXFIFO_DECOMPRESS_HALT = 0;
1001 3 }
1002 2
1003 2 return output;
1004 2 }
1005 1 }
1006 //-----------------------------------------------------------------------------
1007 // CLEAR_FIFOS()
1008 //-----------------------------------------------------------------------------
1009 //
1010 // Routine resets all buffers; index values and flags to initial values.
1011 //
1012 void CLEAR_FIFOS(void)
1013 {
1014 1
1015 1 // reset the DACTX FIFO
1016 1 DACTXFIFO_EMPTY = 1;
1017 1 DACTXFIFO_FIRST = 0;
1018 1 DACTXFIFO_LAST = 0;
1019 1 DACTXFIFO_COUNT = 0;
1020 1 DACTXFIFO_OF = 0;
1021 1 DACTXFIFO_FULL = 0;
1022 1
1023 1 // reset the UART RX FIFO
1024 1 ReceiveFIFO_EMPTY = 1;
1025 1 ReceiveFIFO_FIRST = 0;
1026 1 ReceiveFIFO_LAST = 0;
1027 1 ReceiveFIFO_COUNT = 0;
1028 1 ReceiveFIFO_OF = 0;
1029 1 ReceiveFIFO_FULL = 0;
1030 1
1031 1 }
1032
1033 //-----------------------------------------------------------------------------
1034 // FIFO_ManagementRoutine()
1035 //-----------------------------------------------------------------------------
1036 //
1037 //
1038 //
1039 void FIFO_ManagementRoutine(void)
1040 {
1041 1 bit EAState;
1042 1 EAState = EA;
C51 COMPILER V8.05a WIRELESS_CC1100RX 11/07/2007 15:16:42 PAGE 18
1043 1 EA = 0;
1044 1 while ((!ReceiveFIFO_EMPTY) && (!DACTXFIFO_DECOMPRESS_HALT)) // (!ReceiveFIFO_EMPTY)
1045 1 {
1046 2 // Decompress received samples when
1047 2 DPCM_Decompress(); // available
1048 2 }
1049 1 EA = EAState;
1050 1
1051 1 EAState = EA;
1052 1 EA = 0;
1053 1 if(ReceiveFIFO_FULL)
1054 1 {
1055 2
1056 2 ReceiveFIFO_Pull();
1057 2 }
1058 1 EA = EAState;
1059 1
1060 1 EAState = EA;
1061 1 EA = 0;
1062 1 if(DACTXFIFO_OF)
1063 1 {
1064 2 DACTXFIFO_Pull();
1065 2 }
1066 1 EA = EAState;
1067 1
1068 1
1069 1 }
1070
1071 //-----------------------------------------------------------------------------
1072 // DPCM_Decode
1073 //-----------------------------------------------------------------------------
1074 //
1075 // decode the 8-bit (MSBs of 10-bit sample) sample using DPCM compression.
1076 // INPUTS:
1077 // old_prediction - the 8-bit unsigned predicted value from the current
1078 // cycle which will be used to calculate the new predicted
1079 // value
1080 // dpcm_code - the 4-bit code indicating the quantized difference between
1081 // the old_prediction and the current sample values
1082 // (see DPCM_Encode for the dpcm_code values)
1083 // OUTPUTS:
1084 // new_prediction - the 8-bit unsigned predicted value for the next cycle
1085 //
1086 void DPCM_Decompress (void)
1087 {
1088 1 unsigned char CompressedByte, CompressedSample;
1089 1 // static signed short UncompressedWord;
1090 1 bit EAstate;
1091 1
1092 1 EAstate = EA;
1093 1 EA = 0;
1094 1 CompressedByte = ReceiveFIFO_Pull();
1095 1 EA = EAstate;
1096 1 CompressedSample = CompressedByte>>4;
1097 1 UncompressedWord = UncompressedWord + Q_VALUES[CompressedSample];
1098 1
1099 1 if (UncompressedWord > 3)
1100 1 {
1101 2 UncompressedWord--;
1102 2 }
1103 1 else
1104 1 if (UncompressedWord < 3)
C51 COMPILER V8.05a WIRELESS_CC1100RX 11/07/2007 15:16:42 PAGE 19
1105 1 {
1106 2 UncompressedWord++;
1107 2 }
1108 1
1109 1 if (UncompressedWord > 511)
1110 1 {
1111 2 UncompressedWord = 511;
1112 2 }
1113 1 else
1114 1 if (UncompressedWord < -512)
1115 1 {
1116 2 UncompressedWord = -512;
1117 2 }
1118 1
1119 1 EAstate = EA;
1120 1 EA = 0;
1121 1 DACTXFIFO_Push(UncompressedWord + 512);
1122 1 EA = EAstate;
1123 1
1124 1 CompressedSample = CompressedByte & 0x0F;
1125 1
1126 1 UncompressedWord = UncompressedWord + Q_VALUES[CompressedSample];
1127 1
1128 1 if (UncompressedWord > 3)
1129 1 {
1130 2 UncompressedWord--;
1131 2 }
1132 1 else
1133 1 if (UncompressedWord < 3)
1134 1 {
1135 2 UncompressedWord++;
1136 2 }
1137 1
1138 1 if (UncompressedWord > 511)
1139 1 {
1140 2 UncompressedWord = 511;
1141 2 }
1142 1 else
1143 1 if (UncompressedWord < -512)
1144 1 {
1145 2 UncompressedWord = -512;
1146 2 }
1147 1
1148 1 EAstate = EA;
1149 1 EA = 0;
1150 1 DACTXFIFO_Push(UncompressedWord + 512);
1151 1 EA = EAstate;
1152 1
1153 1 }
1154 void WaitMS (unsigned int count)
1155 {
1156 1
1157 1 TCON &= ~0x30; // Stop Timer0; clear TF0
1158 1 TMOD &= ~0x0F; // Timer0 in 16-bit mode
1159 1 TMOD |= 0x01;
1160 1 CKCON |= 0x04; // Timer0 counts SYSCLKs
1161 1
1162 1 TH0 = (-SYSCLK / 1000) >> 8; // overflow in 1ms
1163 1 TL0 = (-SYSCLK / 1000);
1164 1
1165 1 TR0 = 1; // Start Timer0
1166 1 do {
C51 COMPILER V8.05a WIRELESS_CC1100RX 11/07/2007 15:16:42 PAGE 20
1167 2
1168 2 while (!TF0); // wait for overflow
1169 2 TR0 = 0; // Stop Timer0
1170 2 TF0 = 0; // clear overflow flag
1171 2
1172 2 TH0 = (-SYSCLK / 1000) >> 8; // overflow in 1ms
1173 2 TL0 = (-SYSCLK / 1000);
1174 2
1175 2 TR0 = 1; // Start Timer0
1176 2
1177 2 count--; // update counter
1178 2 } while (count != 0); // continue for <count> ms
1179 1
1180 1 TR0 = 0; // Stop Timer0
1181 1 }
1182 //-------------------------------------------------------------------------------------------------------
1183 // Macro to reset the CCxxx0 and wait for it to be ready
1184 void RESET_CCxxx0(void)
1185 {
1186 1 // SPI0CN = 0x08; // clear all flags
1187 1 NSSMD0 = 0;
1188 1 while (SO_data);
1189 1 // {SO_data = 0;}
1190 1 SPI0DAT = CCxxx0_SRES; //
1191 1 SPI_WAIT();
1192 1 // while (SO_data)
1193 1 // {SO_data = 0;}
1194 1 NSSMD0 = 1;
1195 1 SO_data = 0;
1196 1 }
1197 //-------------------------------------------------------------------------------------------------------
1198
1199
1200
1201
1202 //-------------------------------------------------------------------------------------------------------
1203 // Macro to reset the CCxxx0 after power_on and wait for it to be ready
1204 // IMPORTANT NOTICE:
1205 // The file Wait.c must be included if this macro shall be used
1206 // The file is located under: ..\Lib\Chipcon\Hal\CCxx00
1207 //
1208 // min 40 us
1209 // <------------------>
1210 // NSSMD0 |--| |--------------------| |-----
1211 // | | | | |
1212 // -- ------------
1213 //
1214 // MISO |----|
1215 // -----------------------------| | |
1216 // -- ---------
1217 // Unknown / don't care
1218 //
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -