compile pass

This commit is contained in:
YiChin2018
2019-05-08 10:37:17 +08:00
parent e7ba561277
commit 44b4e249bb
4 changed files with 101 additions and 92 deletions
@@ -24,19 +24,19 @@ extern ICall_Semaphore semaphore;
#define EVT_PERIODIC_3 0x0800
// clang-format on
#define flag_mask(flag) ((event_flags & (flag)) != 0)
#define flag_mask(flag) ((event_mask & (flag)) != 0)
#define flag_enable(flag) \
do { \
uint8 __key = Hwi_disable(); \
event_flags |= (uint16_t)(flag); \
event_mask |= (uint16_t)(flag); \
Hwi_restore(__key); \
} while (0)
#define flag_disable(flag) \
do { \
uint8 __key = Hwi_disable(); \
event_flags &= ~((uint16_t)(flag)); \
event_mask &= ~((uint16_t)(flag)); \
Hwi_restore(__key); \
} while (0)
@@ -187,12 +187,13 @@ typedef struct {
//#include "headstage_cis_volt.h"
//#include "headstage_cis_led.h"
#include "headstage_tni.h"
/*======================
==== main function ====
======================*/
struct EventTableEntry EVENT_TABLE[] = { //
static EventTableEntry EVENT_TABLE[] = { //
#ifdef HEADSTAGE_TNI_H
{EVT_ALL, &headstage_tni_event},
#endif
@@ -204,8 +205,8 @@ struct EventTableEntry EVENT_TABLE[] = { //
static void headstage_event_handle() {
for (EventTableEntry *entry = EVENT_TABLE; entry->event_mask; entry++) {
if (event->event_callback && flag_mask(event->event_mask)) {
event->event_callback();
if (entry->event_callback && flag_mask(entry->event_mask)) {
entry->event_callback();
}
}
@@ -21,9 +21,9 @@
// clang-format off
// ART means amplifier reset
#define RIS_ART 0x60
#define RIS_ARM 0x80
#define RIS_DIR 0xA0
#define RIS_REC 0xC0
#define RIS_ARM 0xA0
#define RIS_STI 0xE0
// clang-format on
@@ -166,12 +166,12 @@ static void headstage_tni_periodic();
=======================*/
static void headstage_tni_event() {
if (flag_mask(EVT_EVT_PERIODIC_GPTIMER)) {
flag_disable(_EVT_PERIODIC_GPTIMER);
if (flag_mask(EVT_PERIODIC_GPTIMER)) {
flag_disable(EVT_PERIODIC_GPTIMER);
headstage_tni_periodic();
}
if (event_flags == 0) {
if (event_mask == 0) {
// fast return
return;
}
@@ -185,6 +185,79 @@ static void headstage_tni_event() {
}
}
/*======================
==== notify buffer ====
=====================*/
#define NOT_BUF_OFFSET_INIT 8
static uint32_t not_buf_offset = 0;
static uint32_t not_time_stamp = 0;
static void notify_set_timestamp() {
not_time_stamp = headstage_time_stamp_us();
not_buf[2] = not_time_stamp & 0xFF;
not_buf[3] = (not_time_stamp >> 8) & 0xFF;
not_buf[4] = (not_time_stamp >> 16) & 0xFF;
not_buf[5] = (not_time_stamp >> 24) & 0xFF;
}
static void notify_set_time_delta() {
uint32_t current = headstage_time_stamp_us();
uint32_t time_delta = (current - not_time_stamp) & 0xFFFF;
not_buf[6] = time_delta & 0xFF;
not_buf[7] = (time_delta >> 8) & 0xFF;
}
static void notify_flip_buffer() {
not_buf[0] = CHIP_ID; // chip id
not_buf[1] = not_buf_offset - 2; // data length
notify_set_time_delta();
not_buf_offset = NOT_BUF_OFFSET_INIT;
}
/**
* move data to not_buf. If not_buf is full, then send notify.
*/
static void notify_append_data(uint8_t *dat_buf) {
uint8 invalid_flag;
// checking data header
if ((dat_buf[0] & 0xF0) == 0xB0) {
// valid value
invalid_flag = 0x00;
} else {
// invalid value
invalid_flag = 0x03;
}
// change data buffer content
// add channel and invalid information
dat_buf[0] = (INSTRUCTION.data_channel << 4) | (dat_buf[0] & 0x0F);
dat_buf[1] = (dat_buf[1] & 0xFC) | invalid_flag;
if (not_buf_offset == NOT_BUF_OFFSET_INIT) {
notify_set_timestamp();
}
// data buffer -> not_buf
memcpy(not_buf + not_buf_offset, dat_buf, 2);
not_buf_offset += 2;
// check buffer full or not
// check whether has more place to append data into notify buffer
if (not_buf_offset >= BLE_NOT_BUFF_SIZE) {
notify_flip_buffer();
headstage_send_notify();
}
}
/*===========================
==== function implement ====
==========================*/
@@ -248,10 +321,10 @@ static void headstage_update_ris_instruction(uint8_t *instruction) {
uint8_t chc = (instruction[3] & 0b11110000) >> 4;
uint8_t chd = (instruction[3] & 0b00001111);
if (buf[1] & 0b1000) INSTRUCTION.channel_table[cha] = TRUE;
if (buf[1] & 0b0100) INSTRUCTION.channel_table[chb] = TRUE;
if (buf[1] & 0b0010) INSTRUCTION.channel_table[chc] = TRUE;
if (buf[1] & 0b0001) INSTRUCTION.channel_table[chd] = TRUE;
if (instruction[1] & 0b1000) INSTRUCTION.channel_table[cha] = TRUE;
if (instruction[1] & 0b0100) INSTRUCTION.channel_table[chb] = TRUE;
if (instruction[1] & 0b0010) INSTRUCTION.channel_table[chc] = TRUE;
if (instruction[1] & 0b0001) INSTRUCTION.channel_table[chd] = TRUE;
break;
}
@@ -271,10 +344,10 @@ static void headstage_update_ris_instruction(uint8_t *instruction) {
uint8_t chc = (instruction[3] & 0b11110000) >> 4;
uint8_t chd = (instruction[3] & 0b00001111);
if (buf[1] & 0b1000) INSTRUCTION.channel_table[cha] = TRUE;
if (buf[1] & 0b0100) INSTRUCTION.channel_table[chb] = TRUE;
if (buf[1] & 0b0010) INSTRUCTION.channel_table[chc] = TRUE;
if (buf[1] & 0b0001) INSTRUCTION.channel_table[chd] = TRUE;
if (instruction[1] & 0b1000) INSTRUCTION.channel_table[cha] = TRUE;
if (instruction[1] & 0b0100) INSTRUCTION.channel_table[chb] = TRUE;
if (instruction[1] & 0b0010) INSTRUCTION.channel_table[chc] = TRUE;
if (instruction[1] & 0b0001) INSTRUCTION.channel_table[chd] = TRUE;
switch (arm_mode) {
case 1:
@@ -326,7 +399,7 @@ static void headstage_update_ris_instruction(uint8_t *instruction) {
// continuous frequency
case 1: {
uint8_t prec = (instruction[0] & 0b00000111);
uint32_t freq = (buf[1] << 16) | (buf[2] << 8) | (buf[3]);
uint32_t freq = (instruction[1] << 16) | (instruction[2] << 8) | (instruction[3]);
// XXX consider precision
INSTRUCTION.frequency_mode = FREQ_MODE_VALUE;
@@ -408,77 +481,6 @@ static void headstage_update_vis_instruction(uint8_t vis_oper) {
}
}
/*======================
==== notify buffer ====
=====================*/
#define NOT_BUF_OFFSET_INIT 8
static uint32_t not_buf_offset = 0;
static uint32_t not_time_stamp = 0;
static void notify_set_timestamp() {
not_time_stamp = headstage_time_stamp_us();
not_buf[2] = not_time_stamp & 0xFF;
not_buf[3] = (not_time_stamp >> 8) & 0xFF;
not_buf[4] = (not_time_stamp >> 16) & 0xFF;
not_buf[5] = (not_time_stamp >> 24) & 0xFF;
}
static void notify_set_time_delta() {
uint32_t current = headstage_time_stamp_us();
uint32_t time_delta = (current - not_time_stamp) & 0xFFFF;
not_buf[6] = time_delta & 0xFF;
not_buf[7] = (time_delta >> 8) & 0xFF;
}
static void notify_flip_buffer() {
not_buf[0] = CHIP_ID; // chip id
not_buf[1] = not_buf_offset - 2; // data length
notify_set_time_delta();
not_buf_offset = NOT_BUF_OFFSET_INIT;
}
/**
* move data to not_buf. If not_buf is full, then send notify.
*/
static void notify_append_data(uint8_t *dat_buf) {
uint8 invalid_flag;
// checking data header
if ((dat_buf[0] & 0xF0) == 0xB0) {
// valid value
invalid_flag = 0x00;
} else {
// invalid value
invalid_flag = 0x03;
}
// change data buffer content
// add channel and invalid information
dat_buf[0] = (display_ch << 4) | (dat_buf[0] & 0x0F);
dat_buf[1] = (dat_buf[1] & 0xFC) | invalid_flag;
if (not_buf_offset == NOT_BUF_OFFSET_INIT) {
notify_set_timestamp();
}
// data buffer -> not_buf
memcpy(not_buf + not_buf_offset, dat_buf, 2);
not_buf_offset += 2;
// check buffer full or not
// check whether has more place to append data into notify buffer
if (not_buf_offset >= BLE_DAT_BUFF_SIZE) {
notify_flip_buffer();
headstage_send_notify();
}
}
/*===========================
==== instruction buffer ====
===========================*/
@@ -551,7 +553,7 @@ static int8_t next_active_channel(int8_t channel_pointer) {
if (channel_pointer >= REC_CHANNEL_COUNT) {
// channel to to the end of the channel_table, set to the beginning and re-search enable channel.
channel_pointer = 0;
while (channel_pointer < CHANNEL_COUNT && !channel_table[channel_pointer]) {
while (channel_pointer < REC_CHANNEL_COUNT && !INSTRUCTION.channel_table[channel_pointer]) {
channel_pointer++;
}
@@ -1,6 +1,7 @@
#ifndef HEADSTAGE_GPTIMER_H
#define HEADSTAGE_GPTIMER_H
#include <xdc/runtime/Types.h>
#include <ti/drivers/timer/GPTimerCC26XX.h>
#define EVT_PERIODIC_GPTIMER EVT_PERIODIC_0
@@ -34,7 +35,7 @@ static void headstage_gptimer_callback(GPTimerCC26XX_Handle handle, GPTimerCC26X
Types_FreqHz _cpu_freq; \
BIOS_getCpuFreq(&_cpu_freq); \
GPTimerCC26XX_Value _load = _cpu_freq.lo / _frequency - 1; \
_load = (_load < 0xFFFF) ? _load : ((0xFA0000 | (loadVal / 250)) - 1); \
_load = (_load < 0xFFFF) ? _load : ((0xFA0000 | (_load / 250)) - 1); \
GPTimerCC26XX_setLoadValue(gptimer_handle, _load); \
} while (0)
@@ -157,6 +157,11 @@
#define SBP_TASK_STACK_SIZE 644
#endif
// Internal Events for RTOS application
#define SBP_STATE_CHANGE_EVT 0x0001
#define SBP_CHAR_CHANGE_EVT 0x0002
#define SBP_CONN_EVT_END_EVT 0x0004
/*********************************************************************
* TYPEDEFS
*/