非main函数中获取 命令行参数
This commit is contained in:
38
cmdline_test.c
Normal file
38
cmdline_test.c
Normal file
@@ -0,0 +1,38 @@
|
||||
#include "stdio.h"
|
||||
#include "stdint.h"
|
||||
#include "soft/debug.h"
|
||||
#include "stddef.h"
|
||||
|
||||
|
||||
|
||||
|
||||
int get_argv(char** argv[]);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static void save_data(const char *filename,const uint8_t *buff,uint32_t size)
|
||||
{
|
||||
FILE* fp;
|
||||
fp = fopen(filename, "wb");
|
||||
fwrite(buff, size, 1, fp);
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int thread_fun(void* t) {
|
||||
int argc;
|
||||
char** argv;
|
||||
char buff[10240] = { 0 };
|
||||
int index = 0;
|
||||
argc = get_argv(&argv);
|
||||
DBG_LOG("argc=%d, ",argc);
|
||||
for (int i = 0;i < argc;i++) {
|
||||
DBG_LOG("%s", argv[i]);
|
||||
index += sprintf(&buff[index],"%s ", argv[i]);
|
||||
}
|
||||
save_data("argv.log", buff, index);
|
||||
return 0;
|
||||
}
|
26
main.c
26
main.c
@@ -25,20 +25,38 @@ const char g_str[] =
|
||||
|
||||
__attribute__((weak)) int thread_fun(void* t) {
|
||||
DBG_INFO("run in thread_fun.\n");
|
||||
lex_analysis(g_str , strlen(g_str));
|
||||
// lex_analysis(g_str , strlen(g_str));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int g_argc;
|
||||
// char* g_argv[100];
|
||||
char** g_argv;
|
||||
|
||||
void set_argv(int argc, char* argv[]) {
|
||||
g_argc = argc;
|
||||
// for (int i = 0;i < argc;i++) {
|
||||
// g_argv[i] = argv[i];
|
||||
// }
|
||||
g_argv = argv;
|
||||
}
|
||||
|
||||
int get_argv(char** argv[]) {
|
||||
// *argv = *(char ***)(g_argv);
|
||||
*argv = (g_argv);
|
||||
return g_argc;
|
||||
}
|
||||
|
||||
void SystemInit();
|
||||
extern char **environ;
|
||||
int main(int argc,char *argv[]){
|
||||
int main(int argc, char* argv[]) {
|
||||
set_argv(argc, argv);
|
||||
debug_init(NULL);
|
||||
DBG_INFO("hello world.%ld\n",(size_t)pthread_self());
|
||||
DBG_INFO("hello world.%ld\n", (size_t)pthread_self());
|
||||
|
||||
myth_create(thread_fun , NULL);
|
||||
|
||||
myth_create(thread_fun, NULL);
|
||||
|
||||
myth_join( );
|
||||
}
|
||||
|
16
soft/debug.c
16
soft/debug.c
@@ -67,7 +67,8 @@ int _sem_init(){
|
||||
|
||||
typedef struct{
|
||||
int inited;
|
||||
#ifdef RT_THREAD
|
||||
int print_context;
|
||||
#ifdef RT_THREAD
|
||||
struct rt_mutex mutex;
|
||||
#endif
|
||||
#ifdef LINUX
|
||||
@@ -113,12 +114,17 @@ int debug_init(dbg_dev *dev)
|
||||
self->dev=dev;
|
||||
self->dev->init();
|
||||
self->dev->write((const uint8_t *)"\r\n",2);
|
||||
self->inited=1;
|
||||
self->inited = 1;
|
||||
debug_print_context(1);
|
||||
DBG_LOG("debug inited.\r\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void debug_print_context(int enable) {
|
||||
g_data.print_context = enable;
|
||||
}
|
||||
|
||||
|
||||
void debug_log(const char *file,const char *fun,int line,int level,const char *fmt, ...)
|
||||
{
|
||||
@@ -137,8 +143,10 @@ void debug_log(const char *file,const char *fun,int line,int level,const char *f
|
||||
_sem_take(self->mutex);
|
||||
#endif
|
||||
memcpy(log_buf,level_str[level],level_str_len[level]);
|
||||
length=level_str_len[level];
|
||||
length+=sprintf(log_buf + length,"%s:%d|%s| ",file,line,fun);
|
||||
length = level_str_len[level];
|
||||
if (self->print_context) {
|
||||
length += sprintf(log_buf + length, "%s:%d|%s| ", file, line, fun);
|
||||
}
|
||||
|
||||
va_start(args, fmt);
|
||||
length += vsnprintf(log_buf + length, CONSOLEBUF_SIZE - length - 3, fmt, args);
|
||||
|
186
test_fun.c
186
test_fun.c
@@ -84,7 +84,7 @@ uint8_t iot_getcrc8(uint8_t *buffer, uint32_t len)
|
||||
|
||||
|
||||
|
||||
uint8_t data_table[] = { 0x5a,0x59,0x48,0x50,0x72,0x02,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfd,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
|
||||
uint8_t data_table[] = { 0xea,0x5a,0x59,0x48,0x50,0x72,0x02,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfd,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
|
||||
,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
|
||||
,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
|
||||
,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
|
||||
@@ -133,27 +133,171 @@ void fun_test(void) {
|
||||
}
|
||||
|
||||
|
||||
#define IOT_PHY_GAIN_STEP_NUM (85)
|
||||
#define IOT_CAL_DATA_DUMMY_LEN (10)
|
||||
|
||||
#pragma pack(push)
|
||||
#pragma pack(1)
|
||||
|
||||
/* adc module calibration data. actual_val = raw_val * k + b */
|
||||
typedef struct _iot_adc_m_cal_data {
|
||||
float k;
|
||||
float b;
|
||||
}iot_adc_m_cal_data_t;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int thread_fun(void* t) {
|
||||
DBG_INFO("run in test_fun.\n");
|
||||
uint8_t crc8 = 0;
|
||||
int len = 0;
|
||||
// while (crc8 != 0x83) {
|
||||
// crc8 = iot_getcrc8(data_table2+1, len);
|
||||
// len++;
|
||||
// }
|
||||
test_struct a;
|
||||
typeof(a.b) b;
|
||||
crc8 = offsetof(test_struct, c);
|
||||
DBG_LOG("a_addr=%p,a_d_d2_addr=%p", &a, headof(test_struct, d, &a.d));
|
||||
// crc8 = iot_getcrc8(data_table2 + 1, 264);
|
||||
DBG_LOG("crc8=%x,len=%d", crc8, len);
|
||||
|
||||
return 0;
|
||||
void print_adc_cal(iot_adc_m_cal_data_t* t) {
|
||||
DBG_LOG("k=%f, b=%f\n", t->k, t->b);
|
||||
}
|
||||
|
||||
/* rf version and phy tx calibration info */
|
||||
typedef struct _iot_cal_data_rf_ver_phy_txiqm {
|
||||
/* tx I MAG balance calibration value, range range: 0~15 */
|
||||
uint8_t tx_i_mag : 4,
|
||||
/* rf version, see RF_VER_XXX */
|
||||
rf_ver : 4;
|
||||
/* tx Q MAG balance calibration value, range range: 0~15 */
|
||||
uint8_t tx_q_mag;
|
||||
/* tx I phase calibration value, range range: 0~31 */
|
||||
uint8_t tx_i_phase;
|
||||
/* tx Q phase calibration value, range range: 0~31 */
|
||||
uint8_t tx_q_phase;
|
||||
/* tx I dc calibration value, range range: -127~127 */
|
||||
int8_t tx_i_dc;
|
||||
/* tx I dc calibration value, range range: -127~127 */
|
||||
int8_t tx_q_dc;
|
||||
} iot_cal_data_rf_ver_phy_txiqm_t;
|
||||
|
||||
void print_rf_ver(iot_cal_data_rf_ver_phy_txiqm_t* t) {
|
||||
DBG_LOG("tx_i_mag=%u, rf_ver=%u, tx_q_mag=%u, tx_i_phase=%u, tx_q_phase=%u, tx_i_dc=%i, tx_q_dc=%i",
|
||||
t->tx_i_mag, t->rf_ver, t->tx_q_mag, t->tx_i_phase, t->tx_q_phase, t->tx_i_dc, t->tx_q_dc);
|
||||
}
|
||||
|
||||
/* rf phy tx fiter calibration info */
|
||||
typedef struct _iot_cal_data_rf_phy_txf {
|
||||
/* flag mark if the value of the corresponding option is valid */
|
||||
uint8_t valid_mask;
|
||||
/* tx filter bw calibration value for each option */
|
||||
uint16_t bw_sel_value[3];
|
||||
} iot_cal_data_rf_phy_txf_t;
|
||||
|
||||
void print_rf_phy(iot_cal_data_rf_phy_txf_t* t) {
|
||||
DBG_LOG("valid_mask=%u, bw_sel_value[0]=%u, bw_sel_value[1]=%u, bw_sel_value[2]=%u, ",
|
||||
t->valid_mask, t->bw_sel_value[0], t->bw_sel_value[1], t->bw_sel_value[2]);
|
||||
}
|
||||
|
||||
typedef struct _iot_cal_data_pt_info {
|
||||
/* the golden mac which used for the pt test */
|
||||
uint8_t golden_mac[6];
|
||||
/* production test time in bcd format */
|
||||
uint8_t year;
|
||||
uint8_t month;
|
||||
uint8_t day;
|
||||
uint8_t hour;
|
||||
uint8_t min;
|
||||
uint32_t golden_fw_ver;
|
||||
uint32_t pt_tool_ver;
|
||||
uint32_t pt_board_ver;
|
||||
} iot_cal_data_pt_info;
|
||||
|
||||
void print_pt_info(iot_cal_data_pt_info* t) {
|
||||
DBG_LOG("year=%u, month=%u, day=%u, hour=%u, min=%u, golden_fw_ver=%u, pt_tool_ver=%u, pt_board_ver=%u",
|
||||
t->year, t->month, t->day, t->hour, t->min, t->golden_fw_ver, t->pt_tool_ver, t->pt_board_ver);
|
||||
DBG_LOG("golden_mac=%u.%u.%u.%u",
|
||||
t->golden_mac[0], t->golden_mac[1], t->golden_mac[2], t->golden_mac[3], t->golden_mac[4], t->golden_mac[5]);
|
||||
}
|
||||
|
||||
/* rf phy rx calibration info */
|
||||
typedef struct _iot_cal_data_rf_phy_rxiqm {
|
||||
/* rx I MAG balance calibration value, range range: 0~15 */
|
||||
uint8_t rx_i_mag : 4,
|
||||
/* rx Q MAG balance calibration value, range range: 0~15 */
|
||||
rx_q_mag : 4;
|
||||
/* rx I phase calibration value, range range: 0~31 */
|
||||
uint8_t rx_i_phase;
|
||||
/* rx Q phase calibration value, range range: 0~31 */
|
||||
uint8_t rx_q_phase;
|
||||
} iot_cal_data_rf_phy_rxiqm_t;
|
||||
|
||||
void print_rf_phy_rxiqm(iot_cal_data_rf_phy_rxiqm_t* t) {
|
||||
DBG_LOG("rx_i_mag=%u, rx_q_mag=%u, rx_i_phase=%u, rx_q_phase=%u",
|
||||
t->rx_i_mag, t->rx_q_mag, t->rx_i_phase, t->rx_q_phase);
|
||||
}
|
||||
|
||||
/* halphy config setting */
|
||||
typedef struct _iot_cal_data_halphy_real_cfg {
|
||||
/* magic num */
|
||||
uint32_t magic;
|
||||
/* mask */
|
||||
uint32_t mask;
|
||||
/* chip id for check valid */
|
||||
uint32_t chipid_hi;
|
||||
uint32_t chipid_lo;
|
||||
/* ppm cali */
|
||||
int8_t ppm;
|
||||
/* tx dc cali */
|
||||
uint16_t tx_dc[4];
|
||||
/* rx dc cali */
|
||||
uint16_t rx_dc[IOT_PHY_GAIN_STEP_NUM];
|
||||
/* pt fw version record */
|
||||
uint32_t pt_fw_ver;
|
||||
/* hardware version */
|
||||
uint16_t hw_ver_major;
|
||||
uint16_t hw_ver_minor;
|
||||
/* unit: degrees centigrade, actual_temp = raw_temp + cali_temp */
|
||||
float cali_temp;
|
||||
/* adc module calibration data */
|
||||
iot_adc_m_cal_data_t cali_adc_m;
|
||||
/* rf version and phy tx iqm calibration data */
|
||||
iot_cal_data_rf_ver_phy_txiqm_t rf_txiqm;
|
||||
/* rf phy tx filter calibration data */
|
||||
iot_cal_data_rf_phy_txf_t rf_txf;
|
||||
/* the production info */
|
||||
iot_cal_data_pt_info pt_info;
|
||||
/* rf phy rx iqm calibration data */
|
||||
iot_cal_data_rf_phy_rxiqm_t rf_rxiqm;
|
||||
uint8_t reserved[IOT_CAL_DATA_DUMMY_LEN];
|
||||
} iot_halphy_real_cfg_t;
|
||||
|
||||
|
||||
void print_halphy_real_cfg(iot_halphy_real_cfg_t* t) {
|
||||
DBG_LOG("magic=0x%08x, mask=0x%08x, chipid_hi=0x%08x, chipid_lo=0x%08x, ppm=%d, ",
|
||||
t->magic, t->mask, t->chipid_hi, t->chipid_lo, t->ppm);
|
||||
DBG_LOG("tx_dc=%u,%u,%u,%u", t->tx_dc[0], t->tx_dc[1], t->tx_dc[2], t->tx_dc[3]);
|
||||
for (int i = 0;i < IOT_PHY_GAIN_STEP_NUM;i++) {
|
||||
DBG_LOG("rx_dc[%d]=%u,", i, t->rx_dc[i]);
|
||||
}
|
||||
DBG_LOG("pt_fw_ver=%u, hw_ver_major=0x%04x, hw_ver_minor=0x%04x, cali_temp=%f,",
|
||||
t->pt_fw_ver, t->hw_ver_major, t->hw_ver_minor, t->cali_temp);
|
||||
|
||||
print_adc_cal(&t->cali_adc_m);
|
||||
print_rf_ver(&t->rf_txiqm);
|
||||
print_rf_phy(&t->rf_txf);
|
||||
print_pt_info(&t->pt_info);
|
||||
print_rf_phy_rxiqm(&t->rf_rxiqm);
|
||||
}
|
||||
|
||||
|
||||
typedef struct _iot_cal_data_cfg {
|
||||
uint8_t crc;
|
||||
iot_halphy_real_cfg_t halphy_cfg;
|
||||
} iot_cal_data_cfg_t;
|
||||
|
||||
void print_cal_data_cfg(iot_cal_data_cfg_t* t) {
|
||||
DBG_LOG("crc=0x%02x,", t->crc);
|
||||
print_halphy_real_cfg(&t->halphy_cfg);
|
||||
}
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
int thread_fun1(void* t) {
|
||||
DBG_LOG("run in test_fun.\n");
|
||||
uint8_t crc8 = 0;
|
||||
iot_cal_data_cfg_t data = { 0 };
|
||||
memcpy(&data, data_table2, sizeof(data));
|
||||
crc8 = iot_getcrc8(&data.halphy_cfg, sizeof(data.halphy_cfg));
|
||||
debug_print_context(0);
|
||||
DBG_LOG("calc_crc=0x%02x", crc8);
|
||||
print_cal_data_cfg(&data);
|
||||
debug_print_context(1);
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user