I2c i2cMaster(I2c::Master);
I2c i2cSlave(I2c::Slave);
Rtc8563 rtc8563;
- Cc1101 cc1101;
+ Cc1101 cc1101Send(Cc1101::Send);
+ Cc1101 cc1101Receive(Cc1101::Receive);
}
#ifdef __AVR_ATmega644P__
TestUnit *unit[] = {
&led, &sw, &rgb, &seg7, &poti, &encoder, &r2r, &motor, &portExp, &lcd, &uart1, &modbus, &ieee485,
- &i2cMaster, &i2cSlave, &i2cSparkfun, &rtc8563, &cc1101
+ &i2cMaster, &i2cSlave, &i2cSparkfun, &rtc8563, &cc1101Send, &cc1101Receive
};
#endif
i2cMaster.tick1ms();
i2cSlave.tick1ms();
i2cSparkfun.tick1ms();
- cc1101.tick1ms();
+ cc1101Send.tick1ms();
+ cc1101Receive.tick1ms();
#ifdef __AVR_ATmega644P__
if (timerFlashRedLed > 0) {
if (--timerFlashRedLed < 128) {
PORTB &= ~(1 << PB0);
}
+ PGM_P Cc1101::getName () {
+ switch (mode) {
+ case Send: return PSTR("CC-1101-Send");
+ case Receive: return PSTR("CC-1101-Receive");
+ default: return PSTR("CC-1101-?");
+ }
+ }
+
void Cc1101::init () {
// trigger for debugging
PORTB &= ~(1 << PB0);
return 0;
- } else if (subtest == 2) {
+ } else if (subtest == 2 && mode == Send) {
+ uint16_t cnt = 0;
do {
- uint8_t data[16];
+ MainRadioControlState state = UNKNOWN;
+ uint8_t data[48];
+ printf_P(PSTR("\n [%04x]: state="), cnt++);
+ if (!readStatus(CC1101_MARCSTATE, (uint8_t *)&state)) {
+ printf_P(PSTR("E1"));
+ } else {
+ printf_P(PSTR("0x%02x"), state);
+ }
for (uint8_t i = 0; i < sizeof(data); i++) {
data[i] = i;
}
- printf_P(PSTR("\n => send 16 bytes ..."));
- triggerOn();
- if (sendData(data, sizeof(data))) {
- flashGreenLed(100);
- printf_P(PSTR("OK"));
- } else {
+ printf_P(PSTR(" --> send 48 bytes ... "));
+ if (!sendData(data, sizeof(data))) {
flashRedLed(100);
- printf_P(PSTR("E4"));
+ printf_P(PSTR("E1"));
+ continue;
+ }
+ flashGreenLed(100);
+ printf_P(PSTR("OK -> state="));
+ if (!readStatus(CC1101_MARCSTATE, (uint8_t *)&state)) {
+ printf_P(PSTR("E1"));
+ } else {
+ printf_P(PSTR("0x%02x"), state);
}
- triggerOff();
-
} while (wait(2000) == EOF);
return 0;
- } else if (subtest == 3) {
- setReceive();
+ // ------------------------------------------------------------------------
+
+ } else if (subtest == 2 && mode == Receive) {
int key = EOF;
- uint8_t state;
+ uint16_t cnt = 0;
+ MainRadioControlState state;
while (key == EOF) {
- printf_P(PSTR("\n => receive: "));
- if (!readStatus(CC1101_MARCSTATE, &state)) {
- flashRedLed(100);
- _delay_ms(500);
- continue;
- }
- if (state == 0x01) {
- uint8_t states[8] = { 0x01 };
- uint8_t statesIndex = 1;
- printf_P(PSTR("start "));
- setReceive();
- for (uint16_t i = 0; i < 1000; i++) {
- uint8_t s;
- if (!readStatus(CC1101_MARCSTATE, &s)) {
- continue;
- }
- if (statesIndex == 0 || (states[statesIndex - 1] != s && statesIndex < sizeof(states))) {
- states[statesIndex++] = s;
- }
- if (s == 0x13) {
- break;
- }
+ printf_P(PSTR("\n [%04x] => start ... "), cnt++);
+ setReceive();
+ do {
+ state = UNKNOWN;
+ if (!readStatus(CC1101_MARCSTATE, (uint8_t *)&state)) {
+ printf_P(PSTR("E1"));
+ _delay_ms(500);
+ break;
}
- printf_P(PSTR(" State:"));
- for (uint8_t i = 0; i < statesIndex; i++) {
- printf_P(PSTR(" 0x%02x"), states[i]);
+ if (wait(0) != EOF) {
+ printf_P(PSTR("cancelled"));
+ _delay_ms(500);
+ break;
}
+ if (state == IDLE) {
+ printf_P(PSTR("? (IDLE)"));
+ _delay_ms(500);
+ break;
+ }
+
+ } while (state != RX && state != RXFIFO_OVERFLOW);
+
+ if (state != RX && state != RXFIFO_OVERFLOW) {
+ continue;
}
- key = wait(0);
+ printf_P(PSTR("OK, receive ... "));
- while (key == EOF && state != 0x01) {
+ do {
uint8_t length;
uint8_t data[16];
- printf_P(PSTR(" -> receive ... "));
-
- while (key == EOF) {
- if (receiveData(data, &length, sizeof(data))) {
- flashGreenLed(100);
- printf_P(PSTR("OK, %d bytes received: "), length);
- for (uint8_t i = 0; i < length; i++) {
- printf_P(PSTR(" 0x%02x"), data[i]);
- }
- break;
- } else {
- state = 0;
- if (!readStatus(CC1101_MARCSTATE, &state) || state == 0x01 || state == 0x13) {
- printf_P(PSTR(" -> cancelled state=0x%02x"), state);
- break;
- }
- if (state != 0x0d) {
- printf_P(PSTR(" -> state=0x%02x "), state);
- }
+ if (!readStatus(CC1101_MARCSTATE, (uint8_t *)&state)) {
+ printf_P(PSTR("E2"));
+ _delay_ms(500);
+ continue;
+ }
+ if (wait(0) != EOF) {
+ printf_P(PSTR("cancelled"));
+ _delay_ms(500);
+ continue;
+ }
+ if (receiveData(data, &length, sizeof(data))) {
+ flashGreenLed(100);
+ printf_P(PSTR("OK, %d bytes received: "), length);
+ for (uint8_t i = 0; i < length; i++) {
+ printf_P(PSTR(" 0x%02x"), data[i]);
}
- key = wait(0);
+ printf_P(PSTR(" ... "));
}
- }
- }
- return 0;
- } else if (subtest == 4) {
+ } while (state == RX || state == RXFIFO_OVERFLOW);
+
+ printf_P(PSTR("done (state=0x%02x)"), state);
+ }
return 0;
- } else if (subtest == 5) {
- do {
- uint8_t status;
- printf_P(PSTR("\n => status: "));
- if (readStatus(CC1101_MARCSTATE, &status)) {
- printf_P(PSTR("0x%02x"), status);
- } else {
- printf_P(PSTR("E6"));
- }
- } while (wait(2000) == EOF);
+ // } else if (subtest == 4) {
+ // return 0;
+
+ // } else if (subtest == 5) {
+ // do {
+ // uint8_t status;
+ // printf_P(PSTR("\n => status: "));
+ // if (readStatus(CC1101_MARCSTATE, &status)) {
+ // printf_P(PSTR("0x%02x"), status);
+ // } else {
+ // printf_P(PSTR("E6"));
+ // }
+ // } while (wait(2000) == EOF);
}
return -1;