void matrix_init(void) { #ifdef DEBUG debug_enable = true; debug_keyboard = true; #endif KEY_INIT(); // initialize matrix state: all keys off for (uint8_t i=0; i < MATRIX_ROWS; i++) _matrix0[i] = 0x00; for (uint8_t i=0; i < MATRIX_ROWS; i++) _matrix1[i] = 0x00; matrix = _matrix0; matrix_prev = _matrix1; }
void app_init(void) { LED_INIT(); KEY_INIT(); hif_init(HIF_DEFAULT_BAUDRATE); timer_init(); radio_init(RxFrame, sizeof(RxFrame)); radio_set_state(STATE_OFF); radio_set_param(RP_CHANNEL(CHANNEL)); radio_set_param(RP_IDLESTATE(STATE_RXAUTO)); radio_set_param(RP_SHORTADDR(RT_ADDR)); radio_set_param(RP_PANID(RT_PANID)); #if RADIO_TYPE == RADIO_AT86RF212 radio_set_param(RP_DATARATE(OQPSK100)); #endif }
void wibo_init(uint8_t channel, uint16_t pan_id, uint16_t short_addr, uint64_t ieee_addr) { #if defined(WIBO_FLAVOUR_KEYPRESS) || defined(WIBO_FLAVOUR_MAILBOX) uint8_t run_bootloader = 0; #endif /* only stay in bootloader if key is pressed */ #if defined(WIBO_FLAVOUR_KEYPRESS) #if defined(NO_KEYS) #error "No Keys defined for WIBO_FLAVOUR_KEYPRESS" #endif KEY_INIT(); if(KEY_GET() != 0) { run_bootloader = 1; } #endif /* defined(WIBO_FLAVOUR_KEYPRESS) */ #if defined(WIBO_FLAVOUR_MAILBOX) #if !defined(WIBO_FLAVOUR_MAILBOX_REGISTER) || !defined(WIBO_FLAVOUR_MAILBOX_CODE) #error "WIBO_FLAVOUR_MAILBOX not defined correctly" #endif if(WIBO_FLAVOUR_MAILBOX_REGISTER == WIBO_FLAVOUR_MAILBOX_CODE) { run_bootloader = 1; } //WIBO_MAILBOX_CLR(); #endif /* defined(WIBO_FLAVOUR_MAILBOX) */ #if defined(WIBO_FLAVOUR_KEYPRESS) || defined(WIBO_FLAVOUR_MAILBOX) if(run_bootloader == 0) { app(); } #endif #if !defined(NO_LEDS) LED_INIT(); LED_SET(PROGLED); #endif nodeconfig.channel=channel; nodeconfig.pan_id=pan_id; nodeconfig.short_addr=short_addr; nodeconfig.ieee_addr = ieee_addr; trx_io_init(DEFAULT_SPI_RATE); TRX_RESET_LOW(); TRX_SLPTR_LOW(); TRX_RESET_HIGH(); #if defined(DI_TRX_IRQ) DI_TRX_IRQ(); #endif trx_reg_write(RG_TRX_STATE, CMD_FORCE_TRX_OFF); #if (RADIO_TYPE == RADIO_AT86RF230A) || (RADIO_TYPE == RADIO_AT86RF230B) trx_reg_write(RG_PHY_TX_PWR, 0x80); /* set TX_AUTO_CRC bit, and TX_PWR = max */ #else trx_reg_write(RG_TRX_CTRL_1, 0x20); /* set TX_AUTO_CRC bit */ #endif /* setup network addresses for auto modes */ pingrep.hdr.pan = nodeconfig.pan_id; pingrep.hdr.src = nodeconfig.short_addr; trx_set_panid(nodeconfig.pan_id); trx_set_shortaddr(nodeconfig.short_addr); /* use register write to save code space, overwrites Bits CCA_REQUEST CCA_MODE[1] CCA_MODE[0] * which is accepted */ trx_reg_write(RG_PHY_CC_CCA, nodeconfig.channel); #if RADIO_TYPE == RADIO_AT86RF212 /* reset value, BPSK-40 */ /* trx_reg_write(RG_TRX_CTRL_2, 0x24); */ /* +5dBm acc. to datasheet AT86RF212 table 7-15 */ trx_reg_write(RG_PHY_TX_PWR, 0x84); #endif /* RADIO_TYPE == RADIO_AT86RF212 */ trx_reg_write(RG_CSMA_SEED_0, nodeconfig.short_addr); /* some seeding */ trx_reg_write(RG_TRX_STATE, CMD_RX_AACK_ON); trx_reg_write(RG_IRQ_STATUS, TRX_IRQ_RX_END); /* clear the flag */ #if defined(_DEBUG_SERIAL_) void sendchar(char c); static FILE usart_stdio = FDEV_SETUP_STREAM(sendchar, NULL, _FDEV_SETUP_WRITE); stdout = stderr = &usart_stdio; printf("WIBO Bootlapp Serial Debug"EOL); printf("PANID=%04X SHORTADDR=%04X CHANNEL=%d"EOL, nodeconfig.pan_id, nodeconfig.short_addr, nodeconfig.channel); #endif }
void key_init() { KEY_INIT(); KEY_ENABLE_IRQ(); last_state = KEY_STATE(); }
s32 CDECL rc5_72_unit_func_ansi_1 (RC5_72UnitWork *rc5_72unitwork, u32 *iterations, void * /*memblk*/) { u32 A, B; u32 S[26]; u32 L[3]; u32 kiter = *iterations; while (kiter--) { L[2] = rc5_72unitwork->L0.hi; L[1] = rc5_72unitwork->L0.mid; L[0] = rc5_72unitwork->L0.lo; #define KEY_INIT(i) S[i] = P + i*Q; KEY_INIT(0); KEY_INIT(1); KEY_INIT(2); KEY_INIT(3); KEY_INIT(4); KEY_INIT(5); KEY_INIT(6); KEY_INIT(7); KEY_INIT(8); KEY_INIT(9); KEY_INIT(10); KEY_INIT(11); KEY_INIT(12); KEY_INIT(13); KEY_INIT(14); KEY_INIT(15); KEY_INIT(16); KEY_INIT(17); KEY_INIT(18); KEY_INIT(19); KEY_INIT(20); KEY_INIT(21); KEY_INIT(22); KEY_INIT(23); KEY_INIT(24); KEY_INIT(25); #define ROTL_BLOCK(i,j) ROTL_BLOCK_j##j (i) #define ROTL_BLOCK_i0_j1 \ S[0] = ROTL3(S[0]+(S[25]+L[0])); \ L[1] = ROTL(L[1]+(S[0]+L[0]),(S[0]+L[0])); \ #define ROTL_BLOCK_i0_j2 \ S[0] = ROTL3(S[0]+(S[25]+L[1])); \ L[2] = ROTL(L[2]+(S[0]+L[1]),(S[0]+L[1])); \ #define ROTL_BLOCK_j0(i) \ S[i] = ROTL3(S[i]+(S[i-1]+L[2])); \ L[0] = ROTL(L[0]+(S[i]+L[2]),(S[i]+L[2])); \ #define ROTL_BLOCK_j1(i) \ S[i] = ROTL3(S[i]+(S[i-1]+L[0])); \ L[1] = ROTL(L[1]+(S[i]+L[0]),(S[i]+L[0])); \ #define ROTL_BLOCK_j2(i) \ S[i] = ROTL3(S[i]+(S[i-1]+L[1])); \ L[2] = ROTL(L[2]+(S[i]+L[1]),(S[i]+L[1])); \ S[0] = ROTL3(S[0]); L[0] = ROTL(L[0]+S[0],S[0]); ROTL_BLOCK(1,1); ROTL_BLOCK(2,2); ROTL_BLOCK(3,0); ROTL_BLOCK(4,1); ROTL_BLOCK(5,2); ROTL_BLOCK(6,0); ROTL_BLOCK(7,1); ROTL_BLOCK(8,2); ROTL_BLOCK(9,0); ROTL_BLOCK(10,1); ROTL_BLOCK(11,2); ROTL_BLOCK(12,0); ROTL_BLOCK(13,1); ROTL_BLOCK(14,2); ROTL_BLOCK(15,0); ROTL_BLOCK(16,1); ROTL_BLOCK(17,2); ROTL_BLOCK(18,0); ROTL_BLOCK(19,1); ROTL_BLOCK(20,2); ROTL_BLOCK(21,0); ROTL_BLOCK(22,1); ROTL_BLOCK(23,2); ROTL_BLOCK(24,0); ROTL_BLOCK(25,1); ROTL_BLOCK_i0_j2; ROTL_BLOCK(1,0); ROTL_BLOCK(2,1); ROTL_BLOCK(3,2); ROTL_BLOCK(4,0); ROTL_BLOCK(5,1); ROTL_BLOCK(6,2); ROTL_BLOCK(7,0); ROTL_BLOCK(8,1); ROTL_BLOCK(9,2); ROTL_BLOCK(10,0); ROTL_BLOCK(11,1); ROTL_BLOCK(12,2); ROTL_BLOCK(13,0); ROTL_BLOCK(14,1); ROTL_BLOCK(15,2); ROTL_BLOCK(16,0); ROTL_BLOCK(17,1); ROTL_BLOCK(18,2); ROTL_BLOCK(19,0); ROTL_BLOCK(20,1); ROTL_BLOCK(21,2); ROTL_BLOCK(22,0); ROTL_BLOCK(23,1); ROTL_BLOCK(24,2); ROTL_BLOCK(25,0); ROTL_BLOCK_i0_j1; ROTL_BLOCK(1,2); ROTL_BLOCK(2,0); ROTL_BLOCK(3,1); ROTL_BLOCK(4,2); ROTL_BLOCK(5,0); ROTL_BLOCK(6,1); ROTL_BLOCK(7,2); ROTL_BLOCK(8,0); ROTL_BLOCK(9,1); ROTL_BLOCK(10,2); ROTL_BLOCK(11,0); ROTL_BLOCK(12,1); ROTL_BLOCK(13,2); ROTL_BLOCK(14,0); ROTL_BLOCK(15,1); ROTL_BLOCK(16,2); ROTL_BLOCK(17,0); ROTL_BLOCK(18,1); ROTL_BLOCK(19,2); ROTL_BLOCK(20,0); ROTL_BLOCK(21,1); ROTL_BLOCK(22,2); ROTL_BLOCK(23,0); ROTL_BLOCK(24,1); ROTL_BLOCK(25,2); A = rc5_72unitwork->plain.lo + S[0]; B = rc5_72unitwork->plain.hi + S[1]; #define FINAL_BLOCK(i) \ A = ROTL(A^B,B)+S[2*i]; \ B = ROTL(B^A,A)+S[2*i+1]; FINAL_BLOCK(1); FINAL_BLOCK(2); FINAL_BLOCK(3); FINAL_BLOCK(4); FINAL_BLOCK(5); FINAL_BLOCK(6); FINAL_BLOCK(7); FINAL_BLOCK(8); FINAL_BLOCK(9); FINAL_BLOCK(10); FINAL_BLOCK(11); FINAL_BLOCK(12); if (A == rc5_72unitwork->cypher.lo) { ++rc5_72unitwork->check.count; rc5_72unitwork->check.hi = rc5_72unitwork->L0.hi; rc5_72unitwork->check.mid = rc5_72unitwork->L0.mid; rc5_72unitwork->check.lo = rc5_72unitwork->L0.lo; if (B == rc5_72unitwork->cypher.hi) { *iterations -= (kiter + 1); return RESULT_FOUND; } } #define key rc5_72unitwork->L0 key.hi = (key.hi + 0x01) & 0x000000FF; if (!key.hi) { key.mid = key.mid + 0x01000000; if (!(key.mid & 0xFF000000u)) { key.mid = (key.mid + 0x00010000) & 0x00FFFFFF; if (!(key.mid & 0x00FF0000)) { key.mid = (key.mid + 0x00000100) & 0x0000FFFF; if (!(key.mid & 0x0000FF00)) { key.mid = (key.mid + 0x00000001) & 0x000000FF; if (!key.mid) { key.lo = key.lo + 0x01000000; if (!(key.lo & 0xFF000000u)) { key.lo = (key.lo + 0x00010000) & 0x00FFFFFF; if (!(key.lo & 0x00FF0000)) { key.lo = (key.lo + 0x00000100) & 0x0000FFFF; if (!(key.lo & 0x0000FF00)) { key.lo = (key.lo + 0x00000001) & 0x000000FF; } } } } } } } } #undef key } return RESULT_NOTHING; }
s32 CDECL rc5_72_unit_func_ansi_2 (RC5_72UnitWork *rc5_72unitwork, u32 *iterations, void * /*memblk*/) { u32 A1, A2, B1, B2; u32 S1[26], S2[26]; u32 L1[3], L2[3]; u32 kiter = *iterations/2; while (kiter--) { L1[2] = rc5_72unitwork->L0.hi; L2[2] = L1[2] + 0x01; L1[1] = L2[1] = rc5_72unitwork->L0.mid; L1[0] = L2[0] = rc5_72unitwork->L0.lo; #define KEY_INIT(i) S1[i] = S2[i] = P + i*Q; KEY_INIT(0); KEY_INIT(1); KEY_INIT(2); KEY_INIT(3); KEY_INIT(4); KEY_INIT(5); KEY_INIT(6); KEY_INIT(7); KEY_INIT(8); KEY_INIT(9); KEY_INIT(10); KEY_INIT(11); KEY_INIT(12); KEY_INIT(13); KEY_INIT(14); KEY_INIT(15); KEY_INIT(16); KEY_INIT(17); KEY_INIT(18); KEY_INIT(19); KEY_INIT(20); KEY_INIT(21); KEY_INIT(22); KEY_INIT(23); KEY_INIT(24); KEY_INIT(25); #define ROTL_BLOCK(i,j) ROTL_BLOCK_j##j (i) #define ROTL_BLOCK_i0_j1 \ S1[0] = ROTL3(S1[0]+(S1[25]+L1[0])); \ S2[0] = ROTL3(S2[0]+(S2[25]+L2[0])); \ L1[1] = ROTL(L1[1]+(S1[0]+L1[0]),(S1[0]+L1[0])); \ L2[1] = ROTL(L2[1]+(S2[0]+L2[0]),(S2[0]+L2[0])); \ #define ROTL_BLOCK_i0_j2 \ S1[0] = ROTL3(S1[0]+(S1[25]+L1[1])); \ S2[0] = ROTL3(S2[0]+(S2[25]+L2[1])); \ L1[2] = ROTL(L1[2]+(S1[0]+L1[1]),(S1[0]+L1[1])); \ L2[2] = ROTL(L2[2]+(S2[0]+L2[1]),(S2[0]+L2[1])); \ #define ROTL_BLOCK_j0(i) \ S1[i] = ROTL3(S1[i]+(S1[i-1]+L1[2])); \ S2[i] = ROTL3(S2[i]+(S2[i-1]+L2[2])); \ L1[0] = ROTL(L1[0]+(S1[i]+L1[2]),(S1[i]+L1[2])); \ L2[0] = ROTL(L2[0]+(S2[i]+L2[2]),(S2[i]+L2[2])); \ #define ROTL_BLOCK_j1(i) \ S1[i] = ROTL3(S1[i]+(S1[i-1]+L1[0])); \ S2[i] = ROTL3(S2[i]+(S2[i-1]+L2[0])); \ L1[1] = ROTL(L1[1]+(S1[i]+L1[0]),(S1[i]+L1[0])); \ L2[1] = ROTL(L2[1]+(S2[i]+L2[0]),(S2[i]+L2[0])); \ #define ROTL_BLOCK_j2(i) \ S1[i] = ROTL3(S1[i]+(S1[i-1]+L1[1])); \ S2[i] = ROTL3(S2[i]+(S2[i-1]+L2[1])); \ L1[2] = ROTL(L1[2]+(S1[i]+L1[1]),(S1[i]+L1[1])); \ L2[2] = ROTL(L2[2]+(S2[i]+L2[1]),(S2[i]+L2[1])); \ S1[0] = ROTL3(S1[0]); S2[0] = ROTL3(S2[0]); L1[0] = ROTL(L1[0]+S1[0],S1[0]); L2[0] = ROTL(L2[0]+S2[0],S2[0]); ROTL_BLOCK(1,1); ROTL_BLOCK(2,2); ROTL_BLOCK(3,0); ROTL_BLOCK(4,1); ROTL_BLOCK(5,2); ROTL_BLOCK(6,0); ROTL_BLOCK(7,1); ROTL_BLOCK(8,2); ROTL_BLOCK(9,0); ROTL_BLOCK(10,1); ROTL_BLOCK(11,2); ROTL_BLOCK(12,0); ROTL_BLOCK(13,1); ROTL_BLOCK(14,2); ROTL_BLOCK(15,0); ROTL_BLOCK(16,1); ROTL_BLOCK(17,2); ROTL_BLOCK(18,0); ROTL_BLOCK(19,1); ROTL_BLOCK(20,2); ROTL_BLOCK(21,0); ROTL_BLOCK(22,1); ROTL_BLOCK(23,2); ROTL_BLOCK(24,0); ROTL_BLOCK(25,1); ROTL_BLOCK_i0_j2; ROTL_BLOCK(1,0); ROTL_BLOCK(2,1); ROTL_BLOCK(3,2); ROTL_BLOCK(4,0); ROTL_BLOCK(5,1); ROTL_BLOCK(6,2); ROTL_BLOCK(7,0); ROTL_BLOCK(8,1); ROTL_BLOCK(9,2); ROTL_BLOCK(10,0); ROTL_BLOCK(11,1); ROTL_BLOCK(12,2); ROTL_BLOCK(13,0); ROTL_BLOCK(14,1); ROTL_BLOCK(15,2); ROTL_BLOCK(16,0); ROTL_BLOCK(17,1); ROTL_BLOCK(18,2); ROTL_BLOCK(19,0); ROTL_BLOCK(20,1); ROTL_BLOCK(21,2); ROTL_BLOCK(22,0); ROTL_BLOCK(23,1); ROTL_BLOCK(24,2); ROTL_BLOCK(25,0); ROTL_BLOCK_i0_j1; ROTL_BLOCK(1,2); ROTL_BLOCK(2,0); ROTL_BLOCK(3,1); ROTL_BLOCK(4,2); ROTL_BLOCK(5,0); ROTL_BLOCK(6,1); ROTL_BLOCK(7,2); ROTL_BLOCK(8,0); ROTL_BLOCK(9,1); ROTL_BLOCK(10,2); ROTL_BLOCK(11,0); ROTL_BLOCK(12,1); ROTL_BLOCK(13,2); ROTL_BLOCK(14,0); ROTL_BLOCK(15,1); ROTL_BLOCK(16,2); ROTL_BLOCK(17,0); ROTL_BLOCK(18,1); ROTL_BLOCK(19,2); ROTL_BLOCK(20,0); ROTL_BLOCK(21,1); ROTL_BLOCK(22,2); ROTL_BLOCK(23,0); ROTL_BLOCK(24,1); ROTL_BLOCK(25,2); A1 = rc5_72unitwork->plain.lo + S1[0]; A2 = rc5_72unitwork->plain.lo + S2[0]; B1 = rc5_72unitwork->plain.hi + S1[1]; B2 = rc5_72unitwork->plain.hi + S2[1]; #define FINAL_BLOCK(i) \ A1 = ROTL(A1^B1,B1)+S1[2*i]; \ A2 = ROTL(A2^B2,B2)+S2[2*i]; \ B1 = ROTL(B1^A1,A1)+S1[2*i+1]; \ B2 = ROTL(B2^A2,A2)+S2[2*i+1]; FINAL_BLOCK(1); FINAL_BLOCK(2); FINAL_BLOCK(3); FINAL_BLOCK(4); FINAL_BLOCK(5); FINAL_BLOCK(6); FINAL_BLOCK(7); FINAL_BLOCK(8); FINAL_BLOCK(9); FINAL_BLOCK(10); FINAL_BLOCK(11); FINAL_BLOCK(12); if (A1 == rc5_72unitwork->cypher.lo) { ++rc5_72unitwork->check.count; rc5_72unitwork->check.hi = rc5_72unitwork->L0.hi; rc5_72unitwork->check.mid = rc5_72unitwork->L0.mid; rc5_72unitwork->check.lo = rc5_72unitwork->L0.lo; if (B1 == rc5_72unitwork->cypher.hi) { *iterations -= (kiter + 1)*2; return RESULT_FOUND; } } if (A2 == rc5_72unitwork->cypher.lo) { ++rc5_72unitwork->check.count; rc5_72unitwork->check.hi = rc5_72unitwork->L0.hi + 0x01; rc5_72unitwork->check.mid = rc5_72unitwork->L0.mid; rc5_72unitwork->check.lo = rc5_72unitwork->L0.lo; if (B2 == rc5_72unitwork->cypher.hi) { *iterations -= (kiter + 1)*2 - 1; return RESULT_FOUND; } } #define key rc5_72unitwork->L0 key.hi = (key.hi + 0x02) & 0x000000FF; if (!key.hi) { key.mid = key.mid + 0x01000000; if (!(key.mid & 0xFF000000u)) { key.mid = (key.mid + 0x00010000) & 0x00FFFFFF; if (!(key.mid & 0x00FF0000)) { key.mid = (key.mid + 0x00000100) & 0x0000FFFF; if (!(key.mid & 0x0000FF00)) { key.mid = (key.mid + 0x00000001) & 0x000000FF; if (!key.mid) { key.lo = key.lo + 0x01000000; if (!(key.lo & 0xFF000000u)) { key.lo = (key.lo + 0x00010000) & 0x00FFFFFF; if (!(key.lo & 0x00FF0000)) { key.lo = (key.lo + 0x00000100) & 0x0000FFFF; if (!(key.lo & 0x0000FF00)) { key.lo = (key.lo + 0x00000001) & 0x000000FF; } } } } } } } } #undef key } return RESULT_NOTHING; }