2016-02-14 19:13:43 +00:00
|
|
|
#include <SI_EFM8UB1_Register_Enums.h>
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
|
|
#include "efm8_usb.h"
|
|
|
|
|
#include "usb_0.h"
|
|
|
|
|
#include "atecc508a.h"
|
|
|
|
|
#include "InitDevice.h"
|
|
|
|
|
#include "descriptors.h"
|
2016-03-04 23:22:16 +00:00
|
|
|
#include "eeprom.h"
|
2016-02-14 19:13:43 +00:00
|
|
|
#include "idle.h"
|
|
|
|
|
#include "bsp.h"
|
|
|
|
|
#include "app.h"
|
|
|
|
|
#include "i2c.h"
|
|
|
|
|
#include "u2f_hid.h"
|
2016-03-04 05:33:17 +00:00
|
|
|
#include "u2f.h"
|
2016-02-15 07:12:48 +00:00
|
|
|
#include "tests.h"
|
2016-02-14 19:13:43 +00:00
|
|
|
|
|
|
|
|
data struct APP_DATA appdata;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef U2F_PRINT
|
|
|
|
|
|
2016-02-28 05:26:12 +00:00
|
|
|
FIFO_CREATE(debug,struct debug_msg, DBG_MSG_COUNT)
|
2016-02-14 19:13:43 +00:00
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
static void init(struct APP_DATA* ap)
|
|
|
|
|
{
|
|
|
|
|
memset(ap,0, sizeof(struct APP_DATA));
|
|
|
|
|
debug_fifo_init();
|
|
|
|
|
u2f_hid_init();
|
|
|
|
|
smb_init();
|
2016-02-25 02:16:21 +00:00
|
|
|
atecc_idle();
|
2016-02-14 19:13:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void listen_for_pkt(struct APP_DATA* ap)
|
|
|
|
|
{
|
|
|
|
|
USBD_Read(EP1OUT, ap->hidmsgbuf, sizeof(ap->hidmsgbuf), true);
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-22 05:22:21 +00:00
|
|
|
|
|
|
|
|
void set_app_error(APP_ERROR_CODE ec)
|
2016-02-14 19:13:43 +00:00
|
|
|
{
|
2016-02-22 05:22:21 +00:00
|
|
|
appdata.state = APP_ERROR;
|
|
|
|
|
appdata.error = ec;
|
|
|
|
|
}
|
2016-02-14 20:36:46 +00:00
|
|
|
|
2016-03-04 23:22:16 +00:00
|
|
|
//uint8_t readByte (uint16_t addr)
|
|
|
|
|
//{
|
|
|
|
|
//
|
|
|
|
|
// uint8_t code * pread; // FLASH read pointer
|
|
|
|
|
// uint8_t byte;
|
|
|
|
|
// DISABLE_INTERUPTS();
|
|
|
|
|
// pread = (uint8_t code *) addr;
|
|
|
|
|
//
|
|
|
|
|
// byte = *pread; // Read the byte
|
|
|
|
|
//
|
|
|
|
|
// ENABLE_INTERUPTS();
|
|
|
|
|
//
|
|
|
|
|
// return byte;
|
|
|
|
|
//}
|
2016-03-04 05:33:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int8_t test_eeprom()
|
|
|
|
|
{
|
2016-03-04 23:22:16 +00:00
|
|
|
|
2016-02-14 19:13:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define ms_since(ms,num) (((uint16_t)get_ms() - (ms)) >= num ? (1|(ms=(uint16_t)get_ms())):0)
|
|
|
|
|
|
|
|
|
|
int16_t main(void) {
|
|
|
|
|
|
|
|
|
|
data uint8_t i = 0;
|
|
|
|
|
data uint16_t last_ms = get_ms();
|
|
|
|
|
data uint16_t ms_heart;
|
|
|
|
|
data uint16_t ms_wink;
|
2016-02-15 07:32:07 +00:00
|
|
|
data uint8_t winks = 0;
|
2016-02-14 19:13:43 +00:00
|
|
|
|
2016-03-01 06:31:37 +00:00
|
|
|
|
|
|
|
|
uint8_t b = 0x66;
|
|
|
|
|
uint16_t d = 7777;
|
|
|
|
|
uint32_t l = 0x12345678;
|
|
|
|
|
|
|
|
|
|
|
2016-02-25 02:16:21 +00:00
|
|
|
enter_DefaultMode_from_RESET();
|
2016-02-14 19:13:43 +00:00
|
|
|
init(&appdata);
|
|
|
|
|
|
2016-02-25 02:16:21 +00:00
|
|
|
|
2016-02-14 19:13:43 +00:00
|
|
|
|
|
|
|
|
// STDIO library requires TI to print
|
|
|
|
|
SCON0_TI = 1;
|
|
|
|
|
|
|
|
|
|
// Enable interrupts
|
|
|
|
|
IE_EA = 1;
|
|
|
|
|
|
2016-03-01 06:31:37 +00:00
|
|
|
u2f_prints("U2F ZERO\r\n");
|
2016-02-22 05:22:21 +00:00
|
|
|
|
2016-03-01 06:31:37 +00:00
|
|
|
u2f_printb("b:",1,b);
|
|
|
|
|
u2f_printd("d:",1,d);
|
|
|
|
|
u2f_printlx("lx:",1,l);
|
2016-02-28 05:26:12 +00:00
|
|
|
run_tests();
|
2016-03-04 05:33:17 +00:00
|
|
|
test_eeprom();
|
2016-03-04 23:22:16 +00:00
|
|
|
|
2016-02-14 19:13:43 +00:00
|
|
|
while (1) {
|
|
|
|
|
|
|
|
|
|
if (ms_since(ms_heart,500))
|
|
|
|
|
{
|
2016-02-29 16:48:29 +00:00
|
|
|
u2f_printl("ms ", 1, get_ms());
|
2016-02-14 19:13:43 +00:00
|
|
|
LED_G = !LED_G;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( USBD_GetUsbState() == USBD_STATE_CONFIGURED)
|
|
|
|
|
{
|
2016-03-01 06:31:37 +00:00
|
|
|
if (!USBD_EpIsBusy(EP1OUT) && !USBD_EpIsBusy(EP1IN))
|
2016-02-14 19:13:43 +00:00
|
|
|
{
|
|
|
|
|
listen_for_pkt(&appdata);
|
2016-03-01 06:31:37 +00:00
|
|
|
u2f_prints("read added\r\n");
|
2016-02-14 19:13:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch(appdata.state)
|
|
|
|
|
{
|
|
|
|
|
case APP_NOTHING:
|
|
|
|
|
break;
|
|
|
|
|
case APP_WINK:
|
|
|
|
|
LED_B = 0;
|
|
|
|
|
ms_wink = get_ms();
|
|
|
|
|
appdata.state = _APP_WINK;
|
|
|
|
|
break;
|
|
|
|
|
case _APP_WINK:
|
|
|
|
|
if (ms_since(ms_wink,150))
|
|
|
|
|
{
|
|
|
|
|
LED_B = !LED_B;
|
|
|
|
|
winks++;
|
|
|
|
|
}
|
|
|
|
|
if (winks == 5)
|
|
|
|
|
{
|
|
|
|
|
winks = 0;
|
|
|
|
|
appdata.state = APP_NOTHING;
|
|
|
|
|
}
|
2016-02-23 05:48:20 +00:00
|
|
|
break;
|
2016-02-22 05:22:21 +00:00
|
|
|
case APP_ERROR:
|
2016-02-29 16:48:29 +00:00
|
|
|
u2f_printb("error: ", 1, appdata.error);
|
2016-02-22 05:22:21 +00:00
|
|
|
appdata.state = APP_NOTHING;
|
2016-02-14 19:13:43 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
flush_messages();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|