This commit is contained in:
ADElectronics 2017-11-28 22:31:40 +03:00
parent 6a1f93f17b
commit 764b020238
1201 changed files with 527271 additions and 1 deletions

View file

@ -0,0 +1,291 @@
/*
* adc_tst.c
*
* Created on: 04/04/2017.
* Author: pvvx
*/
#include <platform_opts.h>
#include "rtl8195a.h"
#include "FreeRTOS.h"
#include "rtl8195a/rtl_libc.h"
//------------------------------------------------------------------------------
#include "objects.h"
#include "PinNames.h"
#include "hal_adc.h"
#include "analogin_api.h"
#include "strproc.h"
//------------------------------------------------------------------------------
analogin_t adc;
static void fATADI(int argc, char *argv[])
{
int count = 8;
int channel = 2;
union
{
unsigned int ui[2];
unsigned short us[4];
} x;
uint16_t adcdat;
memset(&adc, 0, sizeof(adc));
// ConfigDebugErr |= (_DBG_ADC_|_DBG_GDMA_);
// ConfigDebugInfo |= (_DBG_ADC_|_DBG_GDMA_);
if (argc > 1)
{
channel = atoi(argv[1]);
channel &= 0x03;
if(!channel) channel = 2;
}
if (argc > 2)
{
count = atoi(argv[2]);
}
analogin_init(&adc, (channel+1) | (PORT_V << 4));
PSAL_ADC_HND pSalADCHND = &((&(adc.SalADCMngtAdpt))->pSalHndPriv->SalADCHndPriv);
uint32_t sum = 0;
for (uint32_t i = 1; i <= count; i++)
{
RtkADCReceiveBuf(pSalADCHND, &x.ui);
adcdat = x.us[channel];
if((i % 8) == 0 || (i == count))
{
printf("0x%04x\n", adcdat);
}
else
{
printf("0x%04x, ", adcdat);
}
sum += adcdat;
}
analogin_deinit(&adc);
printf("ADC%d = 0x%04x\n", channel, sum / count);
// sys_adc_calibration(0, &channel, &count);
}
static void fATADD(int argc, char *argv[])
{
int count = 64;
int channel = 2;
uint16_t adcdat;
memset(&adc, 0, sizeof(adc));
// ConfigDebugErr |= (_DBG_ADC_|_DBG_GDMA_);
// ConfigDebugInfo |= (_DBG_ADC_|_DBG_GDMA_);
if (argc > 1)
{
channel = atoi(argv[1]);
channel &= 0x03;
if(!channel) channel = 1;
}
if (argc > 2)
{
count = atoi(argv[2]);
if (count <= 2)
{
count = 64;
}
};
analogin_init(&adc, (channel+1) | (PORT_V << 4));
SAL_ADC_TRANSFER_BUF trbuf;
trbuf.pDataBuf = zalloc(count*4);
if(trbuf.pDataBuf)
{
trbuf.DataLen = count/2; // x32 bit ?
trbuf.RSVD = 0;
adc.SalADCHndPriv.SalADCHndPriv.pRXBuf = &trbuf;
adc.SalADCHndPriv.SalADCHndPriv.OpType = ADC_DMA_TYPE;
adc.HalADCInitData.ADCEndian = ADC_DATA_ENDIAN_LITTLE; //ADC endian selection,
//but actually it's for 32-bit ADC data swap control
//1'b0: no swap,
//1'b1: swap the upper 16-bit and the lower 16-bit
// adc.HalADCInitData.ADCCompOnly = ADC_FEATURE_DISABLED; //ADC compare mode only enable (without FIFO enable)
// adc.HalADCInitData.ADCEnManul = ADC_FEATURE_ENABLED; // ADC_FEATURE_DISABLED; //ADC enable manually
// adc.HalADCInitData.ADCIdx = channel+1; //ADC index used (1..3 ?)
// adc.HalADCInitData.ADCBurstSz = 8; //ADC DMA operation threshold
// adc.HalADCInitData.ADCOneShotTD = 8; //ADC one shot mode threshold
// adc.HalADCInitData.ADCDataRate = 0; // 0xff; // ADC down sample data rate ??
adc.HalADCInitData.ADCAudioEn = ADC_FEATURE_ENABLED; //ADC audio mode enable // ADC_FEATURE_DISABLED
// adc.HalADCInitData.ADCOneShotEn = ADC_FEATURE_DISABLED; //ADC one shot mode threshold
adc.HalADCInitData.ADCInInput = ADC_FEATURE_ENABLED; //ADC Input is internal?
// adc.HalADCInitData.ADCEn = ADC_DISABLE; //ADC_ENABLE;
HalADCInit8195a(&adc.HalADCInitData);
/* Read Content */
HAL_ADC_READ32(REG_ADC_FIFO_READ);
HAL_ADC_READ32(REG_ADC_INTR_STS);
RtkADCReceive(&adc.SalADCHndPriv.SalADCHndPriv);
while(adc.SalADCHndPriv.SalADCHndPriv.DevSts != ADC_STS_IDLE);
uint16 * ptr = (uint16 *) trbuf.pDataBuf;
// RtkADCDMAInit(&adc.SalADCHndPriv.SalADCHndPriv);
for (uint32_t i = 1; i <= count; i++)
{
if((i % 16) == 0 || (i == count))
{
printf("%04x\n", *ptr);
}
else
{
printf("%04x ", *ptr);
}
ptr++;
}
uint32_t sum = 0;
ptr = (uint16 *) trbuf.pDataBuf;
for (uint32_t i = 1; i <= count; i++)
{
printf("%d\n", *ptr);
sum += *ptr;
ptr++;
if((i%512)==0) vTaskDelay(10);
}
/*
printf("OpType:\t\t%p\n", adc.SalADCHndPriv.SalADCHndPriv.OpType);
printf("pRXBuf:\t\t%p\n", adc.SalADCHndPriv.SalADCHndPriv.pRXBuf);
printf("pDataBuf:\t%p\n", adc.SalADCHndPriv.SalADCHndPriv.pRXBuf->pDataBuf);
printf("DataLen:\t%p\n", adc.SalADCHndPriv.SalADCHndPriv.pRXBuf->DataLen);
printf("ADCDataRate:\t%p\n", adc.HalADCInitData.ADCDataRate);
printf("ADCData:\t%p\n", adc.HalADCInitData.ADCData);
printf("ADCIdx:\t\t%p\n", adc.HalADCInitData.ADCIdx);
printf("ADCPWCtrl:\t%p\n", adc.HalADCInitData.ADCPWCtrl);
printf("ADCAnaParAd3:\t%p\n", adc.HalADCInitData.ADCAnaParAd3);
printf("ADC%d = 0x%04x\n", channel, analogin_read_u16(&adc));
printf("ADC%d = 0x%04x\n", channel, analogin_read_u16(&adc));
*/
analogin_deinit(&adc);
free(trbuf.pDataBuf);
printf("ADC%d = 0x%04x\n", channel, sum / count);
}
else
{
error_printf("%s: malloc failed!\n", __func__);
};
// sys_adc_calibration(0, &channel, &count);
}
static void fATADC(int argc, char *argv[]) {
int count = 8;
int channel = 2;
uint16_t adcdat;
memset(&adc, 0, sizeof(adc));
// ConfigDebugErr |= (_DBG_ADC_|_DBG_GDMA_);
// ConfigDebugInfo |= (_DBG_ADC_|_DBG_GDMA_);
if (argc > 1)
{
channel = atoi(argv[1]);
channel &= 0x03;
if(!channel) channel = 1;
}
if (argc > 2)
{
count = atoi(argv[2]);
}
analogin_init(&adc, (channel+1) | (PORT_V << 4));
uint32_t sum = 0;
for (uint32_t i = 1; i <= count; i++)
{
adcdat = analogin_read_u16(&adc);
if((i % 8) == 0 || (i == count))
{
printf("0x%04x\n", adcdat);
}
else
{
printf("0x%04x, ", adcdat);
}
sum += adcdat;
}
analogin_deinit(&adc);
printf("ADC%d = 0x%04x\n", channel, sum / count);
// sys_adc_calibration(0, &channel, &count);
}
static void fATSA(int argc, char *argv[])
{
// uint32_t tConfigDebugInfo = ConfigDebugInfo;
int channel;
char *ptmp;
uint16_t offset, gain, adcdat;
memset(&adc, 0, sizeof(adc));
if (argc < 2)
{
printf("Usage: ATSA=CHANNEL(0~2)\n");
printf("Usage: ATSA=k_get\n");
printf("Usage: ATSA=k_set[offet(hex),gain(hex)]\n");
return;
}
if (strcmp(argv[1], "k_get") == 0)
{
sys_adc_calibration(0, &offset, &gain);
// printf("[ATSA] offset = 0x%04X, gain = 0x%04X", offset, gain);
}
else if (strcmp(argv[1], "k_set") == 0)
{
if (argc != 4)
{
printf("Usage: ATSA=k_set[offet(hex),gain(hex)]\n");
return;
}
offset = strtoul(argv[2], &ptmp, 16);
gain = strtoul(argv[3], &ptmp, 16);
sys_adc_calibration(1, &offset, &gain);
// printf("[ATSA] offset = 0x%04X, gain = 0x%04X", offset, gain);
}
else
{
channel = atoi(argv[1]);
if (channel < 0 || channel > 2)
{
printf("Usage: ATSA=CHANNEL(0~2)\n");
return;
}
// Remove debug info massage
// ConfigDebugInfo = 0;
if (channel == 0)
analogin_init(&adc, AD_1);
else if (channel == 1)
analogin_init(&adc, AD_2);
else
analogin_init(&adc, AD_3);
// analogin_read_u16(&adc);
adcdat = analogin_read_u16(&adc) >> 4;
analogin_deinit(&adc);
// Recover debug info massage
// ConfigDebugInfo = tConfigDebugInfo;
printf("A%d = 0x%04X\n", channel, adcdat);
}
}
//------------------------------------------------------------------------------
MON_RAM_TAB_SECTION COMMAND_TABLE console_commands_adc[] =
{
{ "ATADC", 0, fATADC, ": ADC Test" },
{ "ATADD", 0, fATADD, ": ADC DMA Test" },
{ "ATADI", 0, fATADI, ": ADC Irq Test" },
{ "ATSA" , 0, fATSA , ": ADC at" }
};

View file

@ -0,0 +1,390 @@
#include <platform_opts.h>
#ifdef CONFIG_AT_USR
#include "FreeRTOS.h"
#include "task.h"
#include "semphr.h"
#include "freertos_pmu.h"
#include "at_cmd/log_service.h"
#include "at_cmd/atcmd_wifi.h"
#include <lwip_netconf.h>
#include "tcpip.h"
#include <dhcp/dhcps.h>
#include <wifi/wifi_conf.h>
#include <wifi/wifi_util.h>
#include "tcm_heap.h"
#include "rtl8195a/rtl_libc.h"
#include "flash_api.h"
#include "sleep_ex_api.h"
#include "lwip/tcp_impl.h"
extern char str_rom_57ch3Dch0A[]; // "=========================================================\n" 57
#define printf rtl_printf // DiagPrintf
/* RAM/TCM/Heaps info */
extern void ShowMemInfo(void);
/*
void ShowMemInfo(void)
{
printf("\nCLK CPU\t\t%d Hz\nRAM heap\t%d bytes\nTCM heap\t%d bytes\n",
HalGetCpuClk(), xPortGetFreeHeapSize(), tcm_heap_freeSpace());
}
*/
//------------------------------------------------------------------------------
// Mem, Tasks info
//------------------------------------------------------------------------------
void fATST(int argc, char *argv[]) {
(void) argc;
(void) argv;
ShowMemInfo();
#if CONFIG_DEBUG_LOG > 1
extern int min_free_heap_size;
printf("\nMin free heap size %d bytes\n", min_free_heap_size);
#endif
#if 0 //CONFIG_DEBUG_LOG > 1
dump_mem_block_list();
tcm_heap_dump();
#endif
printf("\n");
#if (configGENERATE_RUN_TIME_STATS == 1)
char *cBuffer = pvPortMalloc(512);
if(cBuffer != NULL) {
vTaskGetRunTimeStats((char *)cBuffer);
printf("%s", cBuffer);
}
vPortFree(cBuffer);
#endif
#if defined(configUSE_TRACE_FACILITY) && (configUSE_TRACE_FACILITY == 1) && (configUSE_STATS_FORMATTING_FUNCTIONS == 1)
{
char * pcWriteBuffer = malloc(1024);
if(pcWriteBuffer) {
vTaskList((char*)pcWriteBuffer);
printf("\nTask List:\n");
printf(&str_rom_57ch3Dch0A[7]); // "==========================================\n"
printf("Name\t Status Priority HighWaterMark TaskNumber\n%s\n", pcWriteBuffer);
free(pcWriteBuffer);
}
}
#endif
}
/*-------------------------------------------------------------------------------------
Копирует данные из области align(4) (flash, registers, ...) в область align(1) (ram)
--------------------------------------------------------------------------------------*/
extern void copy_align4_to_align1(unsigned char * pd, void * ps, unsigned int len);
/*
static void copy_align4_to_align1(unsigned char * pd, void * ps, unsigned int len)
{
union {
unsigned char uc[4];
unsigned int ud;
}tmp;
unsigned int *p = (unsigned int *)((unsigned int)ps & (~3));
unsigned int xlen = (unsigned int)ps & 3;
// unsigned int size = len;
if(xlen) {
tmp.ud = *p++;
while (len) {
len--;
*pd++ = tmp.uc[xlen++];
if(xlen & 4) break;
}
}
xlen = len >> 2;
while(xlen) {
tmp.ud = *p++;
*pd++ = tmp.uc[0];
*pd++ = tmp.uc[1];
*pd++ = tmp.uc[2];
*pd++ = tmp.uc[3];
xlen--;
}
if(len & 3) {
tmp.ud = *p;
pd[0] = tmp.uc[0];
if(len & 2) {
pd[1] = tmp.uc[1];
if(len & 1) {
pd[2] = tmp.uc[2];
}
}
}
// return size;
}
*/
/*
* int print_hex_dump(uint8_t *buf, int len, unsigned char k)
*/
int print_hex_dump(uint8_t *buf, int len, unsigned char k) {
uint32_t ss[2];
ss[0] = 0x78323025; // "%02x"
ss[1] = k; // ","...'\0'
uint8_t * ptr = buf;
int result = 0;
while (len--) {
if (len == 0)
ss[1] = 0;
result += printf((uint8_t *) &ss, *ptr++);
}
return result;
}
extern char str_rom_hex_addr[]; // in *.ld "[Addr] .0 .1 .2 .3 .4 .5 .6 .7 .8 .9 .A .B .C .D .E .F\n"
void dump_bytes(uint32 addr, int size)
{
uint8 buf[17];
int symbs_line = sizeof(buf)-1;
printf(str_rom_hex_addr);
while (size) {
if (symbs_line > size) symbs_line = size;
printf("%08X ", addr);
copy_align4_to_align1(buf, (void *) addr, symbs_line);
print_hex_dump(buf, symbs_line, ' ');
int i;
for(i = 0 ; i < symbs_line ; i++) {
if(buf[i] < 0x20 || buf[i] > 0x7E) {
buf[i] = '.';
}
}
buf[symbs_line] = 0;
i = (sizeof(buf)-1) - symbs_line;
while(i--) printf(" ");
printf(" %s\r\n", buf);
addr += symbs_line;
size -= symbs_line;
}
}
//------------------------------------------------------------------------------
// Dump byte register
//------------------------------------------------------------------------------
extern uint32_t Strtoul(
IN const uint8_t *nptr,
IN uint8_t **endptr,
IN uint32_t base
);
static void fATSB(int argc, char *argv[])
{
int size = 16;
uint32 addr = Strtoul(argv[1],0,16);
if (argc > 2) {
size = Strtoul(argv[2],0,10);
if (size <= 0 || size > 16384)
size = 16;
}
if(addr + size > SPI_FLASH_BASE) {
flash_turnon();
dump_bytes(addr, size);
SpicDisableRtl8195A();
}
else {
dump_bytes(addr, size);
}
}
extern uint32_t CmdDumpWord(IN uint16_t argc, IN uint8_t *argv[]);
extern uint32_t CmdWriteWord(IN uint16_t argc, IN uint8_t *argv[]);
//------------------------------------------------------------------------------
// Dump dword register
//------------------------------------------------------------------------------
static void fATSD(int argc, char *argv[])
{
/*
if (argc > 2) {
int size = Strtoul(argv[2],0,10);
if (size <= 0 || size > 16384)
argv[2] = "16";
}
*/
CmdDumpWord(argc-1, (unsigned char**)(argv+1));
}
//------------------------------------------------------------------------------
// Write dword register
//------------------------------------------------------------------------------
static void fATSW(int argc, char *argv[])
{
CmdWriteWord(argc-1, (unsigned char**)(argv+1));
}
/* Get one byte from the 4-byte address */
#define ip4_addr1(ipaddr) (((uint8_t*)(ipaddr))[0])
#define ip4_addr2(ipaddr) (((uint8_t*)(ipaddr))[1])
#define ip4_addr3(ipaddr) (((uint8_t*)(ipaddr))[2])
#define ip4_addr4(ipaddr) (((uint8_t*)(ipaddr))[3])
/* These are cast to uint16_t, with the intent that they are often arguments
* to printf using the U16_F format from cc.h. */
#define ip4_addr1_16(ipaddr) ((uint16_t)ip4_addr1(ipaddr))
#define ip4_addr2_16(ipaddr) ((uint16_t)ip4_addr2(ipaddr))
#define ip4_addr3_16(ipaddr) ((uint16_t)ip4_addr3(ipaddr))
#define ip4_addr4_16(ipaddr) ((uint16_t)ip4_addr4(ipaddr))
#define IP2STR(ipaddr) ip4_addr1_16(ipaddr), \
ip4_addr2_16(ipaddr), \
ip4_addr3_16(ipaddr), \
ip4_addr4_16(ipaddr)
#define IPSTR "%d.%d.%d.%d"
extern const char * const tcp_state_str[];
/*
static const char * const tcp_state_str[] = {
"CLOSED",
"LISTEN",
"SYN_SENT",
"SYN_RCVD",
"ESTABLISHED",
"FIN_WAIT_1",
"FIN_WAIT_2",
"CLOSE_WAIT",
"CLOSING",
"LAST_ACK",
"TIME_WAIT"
};
*/
/******************************************************************************
* FunctionName : debug
* Parameters :
* Returns :
*******************************************************************************/
void print_udp_pcb(void)
{
struct udp_pcb *pcb;
bool prt_none = true;
rtl_printf("UDP pcbs:\n");
for(pcb = udp_pcbs; pcb != NULL; pcb = pcb->next) {
rtl_printf("flg:%02x\t" IPSTR ":%d\t" IPSTR ":%d\trecv:%p\n", pcb->flags, IP2STR(&pcb->local_ip), pcb->local_port, IP2STR(&pcb->remote_ip), pcb->remote_port, pcb->recv );
prt_none = false;
};
if(prt_none) rtl_printf("none\n");
}
/******************************************************************************
* FunctionName : debug
* Parameters :
* Returns :
*******************************************************************************/
void print_tcp_pcb(void)
{
struct tcp_pcb *pcb;
rtl_printf("Active PCB states:\n");
bool prt_none = true;
for(pcb = tcp_active_pcbs; pcb != NULL; pcb = pcb->next) {
rtl_printf("Port %d|%d\tflg:%02x\ttmr:%p\t%s\n", pcb->local_port, pcb->remote_port, pcb->flags, pcb->tmr, tcp_state_str[pcb->state]);
prt_none = false;
};
if(prt_none) rtl_printf("none\n");
rtl_printf("Listen PCB states:\n");
prt_none = true;
for(pcb = (struct tcp_pcb *)tcp_listen_pcbs.pcbs; pcb != NULL; pcb = pcb->next) {
rtl_printf("Port %d|%d\tflg:%02x\ttmr:%p\t%s\n", pcb->local_port, pcb->remote_port, pcb->flags, pcb->tmr, tcp_state_str[pcb->state]);
prt_none = false;
};
if(prt_none) rtl_printf("none\n");
rtl_printf("TIME-WAIT PCB states:\n");
prt_none = true;
for(pcb = tcp_tw_pcbs; pcb != NULL; pcb = pcb->next) {
rtl_printf("Port %d|%d\tflg:%02x\ttmr:%p \t%s\n", pcb->local_port, pcb->remote_port, pcb->flags, pcb->tmr, tcp_state_str[pcb->state]);
prt_none = false;
};
if(prt_none) rtl_printf("none\n");
}
/******************************************************************************
* FunctionName : debug
* Parameters :
* Returns :
*******************************************************************************/
static void fATLW(int argc, char *argv[]) // Info Lwip
{
(void) argc; (void) argv;
print_udp_pcb();
print_tcp_pcb();
}
//------------------------------------------------------------------------------
// GPIO Info
//------------------------------------------------------------------------------
static void fATGI(int argc, char *argv[])
{
(void) argc; (void) argv;
int i;
for (i = 0; i < _PORT_MAX; i++)
printf("Port %c state: 0x%04x\n", i + 'A', GPIOState[i]);
}
//------------------------------------------------------------------------------
// Deep sleep
//------------------------------------------------------------------------------
static void fATDS(int argc, char *argv[])
{
uint32 sleep_ms = 10000;
if(argc > 1) sleep_ms = atoi(argv[1]);
#if 0 // WakeUp PB_1
if(argc > 2) {
printf("%u ms waiting low level on PB_1 before launching Deep-Sleep...\n", sleep_ms);
// turn off log uart
HalDeinitLogUart(); // sys_log_uart_off();
// initialize wakeup pin
gpio_t gpio_wake;
gpio_init(&gpio_wake, PB_1);
gpio_dir(&gpio_wake, PIN_INPUT);
gpio_mode(&gpio_wake, PullDown);
TickType_t sttime = xTaskGetTickCount();
do {
if(gpio_read(&gpio_wake) == 0) {
// Enter deep sleep... Wait give rising edge at PB_1 to wakeup system.
deepsleep_ex(DSLEEP_WAKEUP_BY_GPIO, 0);
};
vTaskDelay(1);
} while(xTaskGetTickCount() - sttime < sleep_ms);
HalInitLogUart(); // sys_log_uart_on();
printf("No set pin low in deep sleep!\n");
}
else {
printf("Deep-Sleep %u ms\n", sleep_ms);
HalLogUartWaitTxFifoEmpty();
// Enter deep sleep... Wait timer ms
deepsleep_ex(DSLEEP_WAKEUP_BY_TIMER, sleep_ms);
}
#else
HalLogUartWaitTxFifoEmpty();
deepsleep_ex(DSLEEP_WAKEUP_BY_TIMER, sleep_ms);
#endif
}
/*------------------------------------------------------------------------------
* power saving mode
*----------------------------------------------------------------------------*/
static void fATSP(int argc, char *argv[])
{
if(argc > 2) {
switch (argv[1][0]) {
case 'a': // acquire
{
acquire_wakelock(atoi(argv[2]));
break;
}
case 'r': // release
{
release_wakelock(atoi(argv[2]));
break;
}
};
};
printf("WakeLock Status %d\n", pmu_get_wakelock_status());
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
MON_RAM_TAB_SECTION COMMAND_TABLE console_commands_at[] = {
{"ATST", 0, fATST, ": Memory info"},
{"ATLW", 0, fATLW, ": LwIP Info"},
{"ATGI", 0, fATGI, ": GPIO Info"},
{"ATSB", 1, fATSB, "=<ADDRES(hex)>[,COUNT(dec)]: Dump byte register"},
{"ATSD", 1, fATSD, "=<ADDRES(hex)>[,COUNT(dec)]: Dump dword register"},
{"ATSW", 2, fATSW, "=<ADDRES(hex)>,<DATA(hex)>: Set register"},
{"ATDS", 0, fATDS, "=[TIME(ms)]: Deep sleep"},
{"ATSP", 0, fATSP, "=<a,r>,<wakelock_status:1|2|4|8>: Power"}
};
#endif //#ifdef CONFIG_AT_USR

View file

@ -0,0 +1,38 @@
/*
* flash_tst.c
*
* Created on: 10/04/2017
* Author: pvvx
*/
#include <platform_opts.h>
#include "rtl8195a.h"
#include "flash_api.h"
#include "rtl8195a/rtl_libc.h"
extern void dump_bytes(uint32 addr, int size);
static void FlashDump(int argc, char *argv[]) {
if (argc > 1) {
int addr;
sscanf(argv[1], "%x", &addr);
int size = 16;
if (argc > 2) {
size = atoi(argv[2]);
if (size <= 0 || size > 16384) {
size = 16;
};
};
flash_turnon();
dump_bytes(addr + SPI_FLASH_BASE, size);
SpicDisableRtl8195A();
}
}
MON_RAM_TAB_SECTION COMMAND_TABLE console_flash_tst[] = {
{"FLASHDB", 1, FlashDump, "=<faddr(HEX)>[,size]: Flash Dump"}
};

View file

@ -0,0 +1,99 @@
/*
* test.c
*
* Created on: 12 марта 2017 г.
* Author: PVV
*/
#include <platform_opts.h>
#include "device.h"
#include "gpio_api.h" // mbed
#include "gpio_irq_api.h" // mbed
#include "gpio_irq_ex_api.h" // mbed
#include "timer_api.h"
#include "diag.h"
#include "main.h"
#include "hal_diag.h"
#include "rtl8195a/rtl_libc.h"
#define GPIO_LED_PIN PA_4
#define GPIO_IRQ_PIN PC_4
gpio_irq_t gpio_btn;
gpio_t gpio_led;
gtimer_t my_timer;
uint32_t lo_time_us, hi_time_us;
uint32_t lo_time_cnt, hi_time_cnt;
uint32_t old_tsf;
uint32_t lo, hi, fr;
uint32_t io_irq_count;
static void gpio_demo_irq_handler(uint32_t id, gpio_irq_event event) {
// gpio_irq_disable(&gpio_btn);
io_irq_count++;
uint32_t new_tsf = get_tsf();
uint32_t delta_us = (uint32_t) new_tsf - (uint32_t) old_tsf;
if (event & 1) {
lo_time_us += delta_us;
lo_time_cnt++;
gpio_irq_set(&gpio_btn, IRQ_LOW, 1);
} else {
hi_time_us += delta_us;
hi_time_cnt++;
gpio_irq_set(&gpio_btn, IRQ_HIGH, 1);
}
old_tsf = new_tsf;
// gpio_irq_enable(&gpio_btn);
}
static void timer1_timeout_handler(uint32_t id) {
if (lo_time_cnt && hi_time_cnt) {
lo = lo_time_us / lo_time_cnt;
hi = hi_time_us / hi_time_cnt;
fr = hi + lo;
lo_time_cnt = 0;
lo_time_us = 0;
hi_time_cnt = 0;
hi_time_us = 0;
printf("Period: %lu us, Lo: %lu us, Hi: %lu us\n", fr, lo, hi);
}
}
/**
* @brief Main program.
* @param None
* @retval None
*/
static void fATTT(int argc, char *argv[]) {
lo_time_cnt = 0;
lo_time_us = 0;
hi_time_cnt = 0;
hi_time_us = 0;
// Init LED control pin
gpio_init(&gpio_led, GPIO_LED_PIN);
gpio_dir(&gpio_led, PIN_OUTPUT); // Direction: Output
gpio_mode(&gpio_led, PullNone); // No pull
gpio_write(&gpio_led, 0);
// Initial Push Button pin as interrupt source
gpio_irq_init(&gpio_btn, GPIO_IRQ_PIN, gpio_demo_irq_handler,
(uint32_t) (&gpio_led));
gpio_irq_set(&gpio_btn, IRQ_FALL, 1); // Falling Edge Trigger
gpio_irq_enable(&gpio_btn);
// Initial a periodical timer
gtimer_init(&my_timer, TIMER1);
gtimer_start_periodical(&my_timer, 1000000, (void*) timer1_timeout_handler,
(uint32_t) &gpio_led);
}
MON_RAM_TAB_SECTION COMMAND_TABLE console_commands_test[] = { { "ATTT", 0,
fATTT, ": Test" } };

View file

@ -0,0 +1,38 @@
/*
* power_tst.c
*
* Created on: 04 апр. 2017 г.
* Author: PVV
*/
#include "rtl8195a.h"
#include "freertos_pmu.h"
#include "rtl8195a/rtl_libc.h"
/*------------------------------------------------------------------------------
* power saving mode
*----------------------------------------------------------------------------*/
void fATSP(int argc, char *argv[])
{
if(argc > 2) {
switch (argv[1][0]) {
case 'a': // acquire
{
acquire_wakelock(atoi(argv[2]));
break;
}
case 'r': // release
{
release_wakelock(atoi(argv[2]));
break;
}
}
}
printf("WakeLock Status %d\n", pmu_get_wakelock_status());
}
MON_RAM_TAB_SECTION COMMAND_TABLE console_commands_pwrs[] = {
{"ATSP", 0, fATSP, "=<a,r>,<wakelock_status:1|2|4|8>: Power"}
};

View file

@ -0,0 +1,54 @@
/*
* pwm_tst.c
*
* Created on: 19/04/2017.
* Author: pvvx
*/
#include <platform_opts.h>
#include "rtl8195a.h"
#include "FreeRTOS.h"
#include "rtl8195a/rtl_libc.h"
//#include "device.h"
#include "pwmout_api.h" // mbed
//#include "main.h"
#include "web_utils.h"
#include "objects.h"
#include "pinmap.h"
extern const PinMap PinMap_PWM[];
extern uint32_t gTimerRecord;
HAL_PWM_ADAPTER pwm_hal_adp;
static void fATPWM(int argc, char *argv[]) {
uint8_t pin = ahextoul(argv[1]);
uint32_t period = ahextoul(argv[2]);
uint32_t pulse = ahextoul(argv[3]);
uint32_t peripheral = pinmap_peripheral(pin, PinMap_PWM);
if(pwm_hal_adp.enable) {
HAL_Pwm_Disable(&pwm_hal_adp);
gTimerRecord &= ~(1 << pwm_hal_adp.gtimer_id);
rtl_memset((void *)&pwm_hal_adp, 0, sizeof(HAL_PWM_ADAPTER));
};
if((period) && (unlikely(peripheral != NC))
&& (HAL_Pwm_Init(&pwm_hal_adp, RTL_GET_PERI_IDX(peripheral), RTL_GET_PERI_SEL(peripheral)) == HAL_OK)) {
HAL_Pwm_SetDuty(&pwm_hal_adp, period, pulse);
HAL_Pwm_Enable(&pwm_hal_adp);
} else {
printf("Error parameters!");
};
}
//------------------------------------------------------------------------------
// atpwm=34,1048575,524287
// atpwm=34,122,61 (8.187kHz)
// atsw 40000368 85001002 (8.187kHz)
// atsd 40000360 6
MON_RAM_TAB_SECTION COMMAND_TABLE console_commands_pwm[] = {
{ "ATPWM", 3, fATPWM, "=<pin>,<period>,<pulse>: PWM Test" }
};

View file

@ -0,0 +1,383 @@
/*
* sd_fat.c
*
* Created on: 17 дек. 2016 г.
* Author: PVV
*/
#include "rtl8195a.h"
#ifdef CONFIG_SDIO_HOST_EN
#include "rtl8195a_sdio_host.h"
#include "hal_sdio_host.h"
#include "sd.h"
#include "sdio_host.h"
#include "pinmap.h"
#include "sdcard.h"
//#include "ff.h"
//#include "fatfs_ext/inc/ff_driver.h"
#include "rtl8195a/os.h"
#include "at_cmd/log_service.h"
//extern ll_diskio_drv SD_disk_Driver;
char *logical_drv = "0:/";
#define START_CHAR_DISK '0'
typedef struct _msftm_td {
unsigned short day :5;
unsigned short month :4;
unsigned short year :7;
} msftm_d;
typedef struct _msftm_tt {
unsigned short sec :5;
unsigned short min :6;
unsigned short hour :5;
} msftm_t;
typedef union {
unsigned short w;
msftm_d d;
} msftm_td;
typedef union {
unsigned short w;
msftm_t t;
} msftm_tt;
uint8_t * month[12] = { "Jan" , "Feb" , "Mar" , "Apr" , "May" , "Jun" , "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
/*
* MS files times
*/
int ms_ftime(unsigned short td, unsigned short tt, struct os_tm *tm) {
msftm_td d;
msftm_tt t;
d.w = td;
t.w = tt;
tm->year = d.d.year + 1980;
tm->month = d.d.month;
tm->day = d.d.day;
tm->hour = t.t.hour;
tm->min = t.t.min;
tm->sec = t.t.sec << 1;
if (tm->month > 11 || tm->hour > 23 || tm->min > 59 || tm->sec > 59) {
return 0;
}
return 1;
}
/*
* MS files attr
*/
uint8_t * ms_fattr(uint8_t *s, uint8_t attr) {
memset(s, '-', 7);
if (attr & AM_ARC)
s[0] = 'a';
if (attr & AM_DIR)
s[1] = 'd';
if (attr & AM_LFN)
s[2] = 'l';
if (attr & AM_VOL)
s[3] = 'v';
if (attr & AM_SYS)
s[4] = 's';
if (attr & AM_HID)
s[5] = 'h';
if (attr & AM_RDO)
s[6] = 'r';
s[7] = 0;
return s;
}
/*
* Linux files attr
*/
uint8_t * ux_fattr(uint8_t *s, uint8_t attr) {
memset(s, '-', 10);
if (attr & AM_DIR) {
s[0] = 'd';
// s[3] = 'x';
// s[6] = 'x';
// s[9] = 'x';
}
if (!(attr & AM_VOL)) {
// {
s[1] = 'r';
s[4] = 'r';
s[7] = 'r';
if (!(attr & AM_RDO)) {
s[2] = 'w';
s[5] = 'w';
s[8] = 'w';
}
}
// if(attr & AM_VOL) s[3] = 'x';
if (!(attr & AM_SYS))
s[3] = 'x';
if (!(attr & AM_HID))
s[6] = 'x';
if (!(attr & AM_ARC))
s[9] = 'x';
s[10] = 0;
return s;
}
FATFS * sd_mount(void) {
FATFS * m_fs = NULL;
// Инициализация I/O SDIOH
if (HalGetChipId() != CHIP_ID_8195AM) {
GPIOState[0] &= ~((1 << 8) - 1);
HAL_GPIO_PullCtrl(PA_0, PullUp); // D2
HAL_GPIO_PullCtrl(PA_1, PullUp); // D3
HAL_GPIO_PullCtrl(PA_2, PullUp); // CMD
HAL_GPIO_PullCtrl(PA_3, PullNone); // CLK
HAL_GPIO_PullCtrl(PA_4, PullUp); // D0
HAL_GPIO_PullCtrl(PA_5, PullUp); // D1
HAL_GPIO_PullCtrl(PA_6, PullDown); // SD card removed
HAL_GPIO_PullCtrl(PA_7, PullDown); // WP enable
vTaskDelay(1);
};
int8_t ret = SD_Init();
if (ret < SD_NODISK) { // sdio_sd_init();
if (sdio_sd_status() >= 0 && sdio_status == SDIO_SD_OK) {
sdio_sd_getProtection();
#if CONFIG_DEBUG_LOG > 2
// чтение информации о SD карте
printf("\nSD CSD: ");
for (int i = 0; i < 16; i++)
printf("%02x", SdioHostAdapter.Csd[i]);
uint32_t i = sdio_sd_getCapacity();
printf("\nSD Capacity: %d sectors (%d GB | %d MB | %d KB)\n", i,
i >> 21, i >> 11, i >> 1);
#endif
m_fs = (FATFS *) malloc(sizeof(FATFS));
if (m_fs != NULL) {
memset(m_fs, 0, sizeof(FATFS));
int drv_num = FATFS_RegisterDiskDriver(&SD_disk_Driver);
if (drv_num >= 0) {
*logical_drv = (char) drv_num + START_CHAR_DISK;
if (f_mount(m_fs, logical_drv, 1) == FR_OK) {
m_fs->drv = (BYTE) drv_num;
#if CONFIG_DEBUG_LOG > 3
printf("SD disk:%c mounted\n", logical_drv[0], m_fs);
#endif
} else {
#if CONFIG_DEBUG_LOG > 2
printf("SD disk mount failed!\n");
#endif
FATFS_UnRegisterDiskDriver(drv_num);
free(m_fs);
m_fs = NULL;
}
} else {
#if CONFIG_DEBUG_LOG > 2
printf("SD Register Disk Driver failed!\n");
#endif
free(m_fs);
m_fs = NULL;
}
} else {
#if CONFIG_DEBUG_LOG > 2
printf("Malloc failed!\n");
#endif
}
} else {
#if CONFIG_DEBUG_LOG > 2
printf("SD Error (%d) get status!\n", sdio_status);
#endif
}
} else {
#if CONFIG_DEBUG_LOG > 2
printf("SD Init Error (%d)!\n", ret);
#endif
}
return m_fs;
}
void sd_unmount(FATFS *m_fs) {
if (m_fs != NULL) {
#if CONFIG_DEBUG_LOG > 2
printf("unmount (%d)\n", f_mount(NULL, logical_drv, 1));
#else
f_mount(NULL, logical_drv, 1);
#endif
FATFS_UnRegisterDiskDriver(m_fs->drv);
free(m_fs);
}
pin_mode(PA_6, PullUp); // SD card removed
pin_mode(PA_7, PullUp); // WP enable
vTaskDelay(1);
SD_DeInit(); // sdio_sd_deinit();
}
void read_file_test(char* file_name) {
FIL *f = malloc(sizeof(FIL));
if (f_open(f, file_name, FA_READ) == FR_OK) {
char * buf = malloc(2048);
unsigned int bytesread =0;
unsigned int totalread=0;
do {
if (f_read(f, buf, 2048, &bytesread) != FR_OK) {
totalread += bytesread;
printf("Read error!");
break;
}
totalread += bytesread;
}
while (bytesread !=0);
free(buf);
f_close(f);
} else {
printf("No open file!");
}
free(f);
}
static void fATHF(int argc, char *argv[]) {
uint8 buf[512];
FATFS * fs = sd_mount();
if (fs != NULL) {
uint8_t * pbuf = (uint8_t *) malloc(512); // char *lfn = malloc (_MAX_LFN + 1);
if (pbuf != NULL) {
DIR dir;
FILINFO fno;
fno.lfname = (TCHAR*) pbuf;
fno.lfsize = 512;
uint8_t * sdir;
if(argc > 1
&& argv[1] != NULL
&& (sdir = (uint8_t *) malloc(strlen(argv[1]) + 4)) != NULL )
strcpy(strcpy(sdir, logical_drv) + 3, argv[1]);
else sdir = logical_drv;
if (f_opendir(&dir, sdir) == FR_OK) {
while (f_readdir(&dir, &fno) == FR_OK && fno.fname[0] != 0) {
if ((fno.fattrib & AM_VOL)==0 && fno.fsize > 0) {
if (*fno.lfname) {
strcpy(strcpy(buf, logical_drv) + 3, fno.lfname);
} else {
strcpy(strcpy(buf, logical_drv) + 3, fno.fname);
}
TickType_t t1 = xTaskGetTickCount();
read_file_test(buf);
t1 = xTaskGetTickCount() - t1;
if(t1 == 0) t1 = 1;
printf("%u kbytes/sec\t%s\n", t1, buf);
}
}
} else
printf("FATFS: Open dir fail!\n");
free(pbuf);
if((void *)sdir != (void *)logical_drv) free(sdir);
}
}
sd_unmount(fs);
}
/* Test SD */
static void fATHS(int argc, char *argv[]) {
// HalPinCtrlRtl8195A(UART0,0,0);
// HalPinCtrlRtl8195A(UART1,0,0);
#if CONFIG_DEBUG_LOG > 4
ConfigDebugErr = -1;
ConfigDebugInfo = -1;
ConfigDebugWarn = -1;
CfgSysDebugErr = -1;
CfgSysDebugInfo = -1;
CfgSysDebugWarn = -1;
#endif
#if DEBUG_AT_USER_LEVEL > 3
printf("ATHS: dir\n");
#endif
FATFS * fs = sd_mount();
if (fs != NULL) {
uint8_t * pbuf = (uint8_t *) malloc(512); // char *lfn = malloc (_MAX_LFN + 1);
if (pbuf != NULL) {
DIR dir;
FILINFO fno;
struct os_tm tm;
fno.lfname = (TCHAR*) pbuf;
fno.lfsize = 512;
uint8_t * sdir;
if(argc > 1
&& argv[1] != NULL
&& (sdir = (uint8_t *) malloc(strlen(argv[1]) + 4)) != NULL )
strcpy(strcpy(sdir, logical_drv) + 3, argv[1]);
else sdir = logical_drv;
printf("\ndir %s\n", sdir);
if (f_opendir(&dir, sdir) == FR_OK) {
while (f_readdir(&dir, &fno) == FR_OK && fno.fname[0] != 0) {
int srtlen = 0;
{
uint8_t buf[12];
srtlen += printf(ux_fattr(buf, fno.fattrib));
}
srtlen += printf(" 0");
if (fno.fattrib & AM_VOL)
printf(" volume");
else if (fno.fattrib & AM_SYS)
printf(" system");
else
printf(" none ");
srtlen += 7;
if (fno.fattrib & AM_HID)
printf(" hidden");
else
printf(" none ");
srtlen += 7;
srtlen += printf(" %d", fno.fsize);
while (srtlen < 37)
srtlen += printf(" ");
ms_ftime(fno.fdate, fno.ftime, &tm);
srtlen += printf(" %04d-%02d-%02d %02d:%02d:%02d ", tm.year,
tm.month, tm.day, tm.hour, tm.min, tm.sec);
if (*fno.lfname) {
srtlen += printf(fno.lfname);
//fnlen = fno.lfsize;
} else {
srtlen += printf(fno.fname);
//fnlen = fno.fsize;
}
printf("\n");
};
printf("\n");
f_closedir(&dir);
} else
printf("FATFS: Open dir fail!\n");
free(pbuf);
if((void *)sdir != (void *)logical_drv) free(sdir);
}
}
sd_unmount(fs);
/*
} else
printf("FATFS: Malloc fail!\n");
f_mount(NULL, logical_drv, 1);
} else
printf("FATFS mount logical drive fail!\n");
FATFS_UnRegisterDiskDriver(drv_num);
} else
printf("Register disk driver to FATFS fail.\n");
free(m_fs);
} else
printf("FATFS: Malloc fail!\n");
} else
printf("SD Init fail!\n");
pin_mode(PA_6, PullUp); // SD card removed
pin_mode(PA_7, PullUp); // WP enable
vTaskDelay(5);
SD_DeInit(); // sdio_sd_deinit();
*/
}
MON_RAM_TAB_SECTION COMMAND_TABLE console_commands_dscard[] = {
{"ATHS", 0, fATHS, "=[dir]: SD test"},
{"ATHF", 0, fATHF, "=[dir]: SD file read"}
};
#endif // CONFIG_SDIO_HOST_EN

View file

@ -0,0 +1,83 @@
/*
* spi_test.c
*/
#include <platform_opts.h>
#include "rtl8195a.h"
#include "spi_api.h"
#include "spi_ex_api.h"
#include "rtl8195a/rtl_libc.h"
#define SPI0_MOSI PC_2
#define SPI0_MISO PC_3
#define SPI0_SCLK PC_1
#define SPI0_CS PC_0
spi_t spi_master;
static void show_reg_spi(int i) {
rtl_printf("Regs SPI:\n");
for(int x = 0; x < 64 ; x += 4) {
rtl_printf("0x%08x ", HAL_SSI_READ32(i, x));
if((x & 0x0F) == 0x0C) rtl_printf("\n");
}
}
static void fATSSI(int argc, char *argv[])
{
int len = 128;
int count = 32;
int clk = 1000000;
int ssn = 0;
if(argc > 1) {
len = atoi(argv[1]);
if(len > 32768 || len <= 0) {
len = 128;
error_printf("%s: len = %u!\n", __func__, len);
};
};
if(argc > 2) {
count = atoi(argv[2]);
if(count > 10000 || count <= 0) {
count = 32;
error_printf("%s: count = %u!\n", __func__, count);
};
};
if(argc > 3) {
clk = atoi(argv[3]);
if(clk <= 0) {
clk = 1000000;
error_printf("%s: clk = %u!\n", __func__, clk);
};
};
if(argc > 4) {
ssn = atoi(argv[4]);
if(ssn > 7 || ssn < 0) {
ssn = 0;
error_printf("%s: ssn = %u!\n", __func__, ssn);
};
};
char* buff = pvPortMalloc(len);
if(buff) {
spi_init(&spi_master, SPI0_MOSI, SPI0_MISO, SPI0_SCLK, SPI0_CS); // CS заданный тут нигде не используется
spi_format(&spi_master, 16, 3, 0);
spi_frequency(&spi_master, clk);
spi_slave_select(&spi_master, ssn); // выбор CS
for(int i = 0; i < len; i++) buff[i] = (char)i;
while(count--) {
spi_master_write_stream(&spi_master, buff, len);
while(spi_busy(&spi_master));
rtl_printf("Master write: %d\n", count);
};
// show_reg_spi(spi_master.spi_adp.Index);
spi_free(&spi_master);
free(buff);
}
else {
error_printf("%s: error malloc!\n", __func__);
};
}
MON_RAM_TAB_SECTION COMMAND_TABLE console_commands_spitst[] = {
{"ATSSI", 0, fATSSI, "=[len[,count[,clk[,ssn]]]]: Spi test"}
};

View file

@ -0,0 +1,353 @@
/*
* wifi_console.c
*
* Created on: 03/04/2017
* Author: pvvx
*/
#include <autoconf.h>
#include "FreeRTOS.h"
#include "diag.h"
#include "wifi_api.h"
#include "wifi_conf.h"
#include "rtl8195a/rtl_libc.h"
#include "hal_platform.h"
#include "freertos_pmu.h"
#include "section_config.h"
#include "hal_diag.h"
#include "lwip/netif.h"
extern struct netif xnetif[NET_IF_NUM];
//==========================================================
//--- CONSOLE --------------------------
// ATPN=<SSID>[,password[,encryption[,auto reconnect[,reconnect pause]]]: WIFI Connect to AP
static void fATPN(int argc, char *argv[]){
if(argc > 1) {
if(argv[1][0] == '?') {
show_wifi_st_cfg();
}
else {
strncpy(wifi_st_cfg.ssid, argv[1], NDIS_802_11_LENGTH_SSID);
int pswlen;
if(argc > 2) {
pswlen = strlen(wifi_st_cfg.password);
strncpy(wifi_st_cfg.password, argv[2], NDIS_802_11_LENGTH_SSID);
if(pswlen > 7) {
wifi_st_cfg.security = IDX_SECURITY_WPA2_AES_PSK;
}
else if(!pswlen) {
wifi_st_cfg.security = IDX_SECURITY_OPEN;
}
else {
printf("password len < 8!\n");
wifi_st_cfg.security = IDX_SECURITY_OPEN;
}
}
else {
// default
wifi_st_cfg.password[0] = 0;
wifi_st_cfg.security = IDX_SECURITY_OPEN;
}
if(argc > 3) {
if(pswlen > 7) {
wifi_st_cfg.security = atoi(argv[3]);
}
else {
printf("password len < 8!\n");
wifi_st_cfg.security = IDX_SECURITY_OPEN;
}
}
if(argc > 4) {
wifi_st_cfg.autoreconnect = atoi(argv[4]);
}
else wifi_st_cfg.autoreconnect = 0;
if(argc > 5) {
wifi_st_cfg.reconnect_pause = atoi(argv[5]);
}
else wifi_st_cfg.reconnect_pause = 5;
show_wifi_st_cfg();
#if CONFIG_WLAN_CONNECT_CB
connect_close();
#endif
wifi_run(wifi_run_mode | RTW_MODE_STA);
}
}
}
// ATPA=<SSID>[,password[,encryption[,channel[,hidden[,max connections]]]]]: Start WIFI AP
static void fATPA(int argc, char *argv[]){
if(argc > 1) {
if(argv[1][0] == '?') {
show_wifi_ap_cfg();
}
else {
strncpy(wifi_ap_cfg.ssid, argv[1], NDIS_802_11_LENGTH_SSID);
if(argc > 2) {
strncpy(wifi_ap_cfg.password, argv[2], NDIS_802_11_LENGTH_SSID);
int i = strlen(wifi_ap_cfg.password);
if(i > 7) {
wifi_ap_cfg.security = 1; // IDX_SECURITY_WPA2_AES_PSK;
}
else if(i == 0) {
wifi_ap_cfg.security = 0; // IDX_SECURITY_OPEN;
}
else {
printf("password len < 8!\n");
wifi_ap_cfg.security = 0; // IDX_SECURITY_OPEN;
}
}
else {
wifi_ap_cfg.password[0] = 0;
wifi_ap_cfg.security = 0; // IDX_SECURITY_OPEN;
}
if(argc > 3) {
wifi_ap_cfg.security = (argv[3][0] == '0')? 0 : 1; //RTW_SECURITY_OPEN : RTW_SECURITY_WPA2_AES_PSK;
}
if(argc > 4) {
wifi_ap_cfg.channel = atoi(argv[4]);
}
else wifi_ap_cfg.channel = 1;
if(argc > 5) {
wifi_ap_cfg.ssid_hidden = atoi(argv[5]);
}
else wifi_ap_cfg.ssid_hidden = 0;
if(argc > 6) {
wifi_ap_cfg.max_sta = atoi(argv[6]);
}
else wifi_ap_cfg.max_sta = 3;
show_wifi_ap_cfg();
#if CONFIG_WLAN_CONNECT_CB
connect_close();
#endif
wifi_run(wifi_run_mode | RTW_MODE_AP);
}
}
}
// WIFI Connect, Disconnect
static void fATWR(int argc, char *argv[]){
rtw_mode_t mode = RTW_MODE_NONE;
if(argc > 1) mode = atoi(argv[1]);
#if CONFIG_WLAN_CONNECT_CB
connect_close();
#endif
wifi_run(mode);
}
#if CONFIG_WLAN_CONNECT_CB
// Close connections
static void fATOF(int argc, char *argv[]){
connect_close();
}
// Open connections
static void fATON(int argc, char *argv[]){
connect_start();
}
#endif
static void fATWI(int argc, char *argv[]) {
#if 1
if(argc > 2) {
uint8_t c = argv[1][0] | 0x20;
if(c == 's') {
int i = atoi(argv[2]);
printf("Save configs(%d)..\n", i);
write_wifi_cfg(atoi(argv[2]));
}
else if(c == 'l') {
wifi_cfg.load_flg = atoi(argv[2]);
}
else if(c == 'm') {
wifi_cfg.mode = atoi(argv[2]);
}
}
#endif
rtw_wifi_setting_t Setting;
if((wifi_run_mode & RTW_MODE_AP)
&& wifi_get_setting(wlan_ap_name, &Setting) == 0) {
wifi_show_setting(wlan_ap_name, &Setting);
// show_wifi_ap_ip();
printf("\tIP: " IPSTR "\n\n", IP2STR(&xnetif[WLAN_AP_NETIF_NUM].ip_addr));
//#if CONFIG_DEBUG_LOG > 1
show_wlan_info(WLAN_AP_NETIF_NUM);
//#endif
}
if((wifi_run_mode & RTW_MODE_STA)
&& wifi_get_setting(wlan_st_name, &Setting) == 0) {
wifi_show_setting(wlan_st_name, &Setting);
// show_wifi_st_ip();
printf("\tIP: " IPSTR "\n\n", IP2STR(&xnetif[WLAN_ST_NETIF_NUM].ip_addr));
//#if CONFIG_DEBUG_LOG > 1
show_wlan_info(WLAN_ST_NETIF_NUM);
//#endif
}
printf("\nWIFI config:\n");
printf(&str_rom_57ch3Dch0A[25]); // "================================\n"
show_wifi_cfg();
printf("\nWIFI AP config:\n");
printf(&str_rom_57ch3Dch0A[25]); // "================================\n"
show_wifi_ap_cfg();
printf("\nWIFI ST config:\n");
printf(&str_rom_57ch3Dch0A[25]); // "================================\n"
show_wifi_st_cfg();
#if SDK_VER_NUM > 0x4000
if(wifi_mode & RTW_MODE_AP) {
printf("\nWIFI AP clients:\n");
printf(&str_rom_57ch3Dch0A[25]); // "================================\n"
show_wifi_ap_clients();
}
#endif
printf("\n");
}
extern uint8_t rtw_power_percentage_idx;
extern int rltk_set_tx_power_percentage(rtw_tx_pwr_percentage_t power_percentage_idx);
void fATWT(int argc, char *argv[]) {
(void) argc; (void) argv;
if(argc > 1) {
int txpwr = atoi(argv[1]);
debug_printf("set tx power (%d)...\n", txpwr);
if(rltk_set_tx_power_percentage(txpwr) != RTW_SUCCESS) {
error_printf("Error set tx power (%d)!", wifi_cfg.tx_pwr);
}
}
printf("TX power = %d\n", rtw_power_percentage_idx);
}
//-- Test tsf (64-bits counts, 1 us step) ---
//#include "hal_com_reg.h"
#define WIFI_REG_BASE 0x40080000
#define REG_TSFTR 0x0560
#define REG_TSFTR1 0x0568 // HW Port 1 TSF Register
#define ReadTSF_Lo32() (*((volatile unsigned int *)(WIFI_REG_BASE + REG_TSFTR)))
#define ReadTSF_Hi32() (*((volatile unsigned int *)(WIFI_REG_BASE + REG_TSFTR1)))
static uint64_t get_tsf(void)
{
return *((uint64_t *)(WIFI_REG_BASE + REG_TSFTR));
}
void fATSF(int argc, char *argv[])
{
(void) argc; (void) argv;
uint64_t tsf = get_tsf();
printf("\nTSF: %08x%08x\n", (uint32_t)(tsf>>32), (uint32_t)(tsf));
}
void fATWP(int argc, char *argv[]) {
(void) argc; (void) argv;
int x = 0;
if(argc > 1) {
x = atoi(argv[1]);
if(x == 0) {
acquire_wakelock(~WAKELOCK_WLAN);
release_wakelock(0xffff);
_wext_enable_powersave(0, 0, 0);
_wext_set_lps_dtim(0, 1);
} else {
release_wakelock(~WAKELOCK_WLAN);
_wext_enable_powersave(0, 1, 1);
_wext_set_lps_dtim(0, x);
}
}
else {
printf("DTIM: %d\n", _wext_get_lps_dtim(0));
}
}
/* -------- WiFi Scan ------------------------------- */
static rtw_result_t scan_result_handler(internal_scan_handler_t* ap_scan_result)
{
if (ap_scan_result) {
if(ap_scan_result->scan_cnt) {
printf("\nScan networks:\n\n");
printf("N\tType\tMAC\t\t\tSignal\tCh\tWPS\tSecyrity\tSSID\n\n");
for(int i = 0 ; i < ap_scan_result->scan_cnt; i++) {
rtw_scan_result_t* record = &ap_scan_result->ap_details[i];
printf("%d\t", i+1);
printf("%s\t", (record->bss_type == RTW_BSS_TYPE_ADHOC)? "Adhoc": "Infra");
printf(MAC_FMT, MAC_ARG(record->BSSID.octet));
printf("\t%d\t", record->signal_strength);
printf("%d\t", record->channel);
printf("%d\t", record->wps_type);
{
uint8 * s = rtw_security_to_str(record->security);
printf("%s\t", s);
if(strlen(s) < 8) printf("\t");
}
record->SSID.val[record->SSID.len] = '\0';
printf("%s\n", record->SSID.val);
}
}
} else {
printf("Scan networks: None!\n");
}
return RTW_SUCCESS;
}
/* -------- WiFi Scan ------------------------------- */
void fATSN(int argc, char *argv[])
{
(void) argc;
(void) argv;
api_wifi_scan(scan_result_handler);
}
#if defined(CONFIG_ENABLE_WPS_AP) && CONFIG_ENABLE_WPS_AP
extern void cmd_ap_wps(int argc, char **argv);
extern void cmd_wps(int argc, char **argv);
//extern void cmd_wifi_on(int argc, char **argv);
#endif
#if CONFIG_ENABLE_P2P
extern void cmd_wifi_p2p_start(int argc, char **argv);
extern void cmd_wifi_p2p_stop(int argc, char **argv);
extern void cmd_p2p_listen(int argc, char **argv);
extern void cmd_p2p_find(int argc, char **argv);
extern void cmd_p2p_peers(int argc, char **argv);
extern void cmd_p2p_info(int argc, char **argv);
extern void cmd_p2p_disconnect(int argc, char **argv);
extern void cmd_p2p_connect(int argc, char **argv);
extern void cmd_wifi_p2p_auto_go_start(int argc, char **argv);
extern void cmd_p2p_peers(int argc, char **argv);
#endif //CONFIG_ENABLE_P2P
MON_RAM_TAB_SECTION COMMAND_TABLE console_cmd_wifi_api[] = {
{"ATPN", 1, fATPN, "=<SSID>[,password[,encryption[,auto-reconnect[,reconnect pause]]]: WIFI Connect to AP"},
{"ATPA", 1, fATPA, "=<SSID>[,password[,encryption[,channel[,hidden[,max connections]]]]]: Start WIFI AP"},
#if defined(CONFIG_ENABLE_WPS_AP) && CONFIG_ENABLE_WPS_AP
{"WPS_AP", 1, cmd_ap_wps, "=<pbc/pin>[,pin]: WiFi AP WPS"},
{"WPS_ST", 1, cmd_wps, "=<pbc/pin>[,pin]: WiFi Station WPS"},
#endif
#if CONFIG_ENABLE_P2P
{"P2P_START", 0, cmd_wifi_p2p_start, ": p2p start" },
{"P2P_ASTART", 0, cmd_wifi_p2p_auto_go_start, ": p2p auto go start" },
{"P2P_STOP", 0, cmd_wifi_p2p_stop, ": p2p stop"},
{"P2P_PEERS", 0, cmd_p2p_peers, ": p2p peers" },
{"P2P_FIND", 0, cmd_p2p_find, ": p2p find"},
{"P2P_INFO", 0, cmd_p2p_info, ": p2p info"},
{"P2P_DISCCONNECT", 0, cmd_p2p_disconnect, ": p2p disconnect"},
{"P2P_CONNECT", 0, cmd_p2p_connect, ": p2p connect"},
#endif
{"ATWR", 0, fATWR, "=[mode]: WIFI Mode: 0 - off, 1 - ST, 2 - AP, 3 - ST+AP"},
#if CONFIG_WLAN_CONNECT_CB
{"ATON", 0, fATON, ": Open connections"},
{"ATOFF", 0, fATOF, ": Close connections"},
#endif
{"ATWI", 0, fATWI, ": WiFi Info"},
#if CONFIG_DEBUG_LOG > 3
{"ATWT", 1, fATWT, "=<tx_power>: WiFi tx power: 0 - 100%, 1 - 75%, 2 - 50%, 3 - 25%, 4 - 12.5%"},
{"ATSF", 0, fATSF, ": Get TSF value"},
#endif
// {"ATWP", 0, fATWP, "=[dtim]: 0 - WiFi ipc/lpc off, 1..10 - on + dtim"},
{"ATSN", 0, fATSN, ": Scan networks"}
};

View file

@ -0,0 +1,75 @@
/*
* wlan_tst.c
*
* Created on: 10 апр. 2017 г.
* Author: PVV
*/
#include <platform_opts.h>
#include "rtl8195a.h"
#include "FreeRTOS.h"
#include "task.h"
#if 1
#include "drv_types.h" // or #include "wlan_lib.h"
#else
#include "wifi_constants.h"
#include "wifi_structures.h"
#include "wlan_lib.h" // or #include "drv_types.h"
#endif
//#include "section_config.h"
//#include "hal_diag.h"
#include "rtl8195a/rtl_libc.h"
extern void dump_bytes(uint32 addr, int size);
extern Rltk_wlan_t rltk_wlan_info[2]; // in wrapper.h
static void tst_wlan_struct(int argc, char *argv[])
{
(void)argc; (void)argv;
printf("Test: sizeof(struct _ADAPTER) = %d\n", sizeof(struct _ADAPTER)); //6088
printf("mlmeextpriv\t+%d\n", offsetof(struct _ADAPTER, mlmeextpriv)); //+1256
printf("TSFValue\t+%d\n", offsetof(struct _ADAPTER, mlmeextpriv.TSFValue)); //+1992
printf("stapriv\t\t+%d\n", offsetof(struct _ADAPTER, stapriv)); //+3024 [164]
printf("pwrctrlpriv.bInternalAutoSuspend +%d\n", offsetof(struct _ADAPTER, pwrctrlpriv.bInternalAutoSuspend)); //+5061
printf("eeprompriv\t+%d\n", offsetof(struct _ADAPTER, eeprompriv)); // +5128
printf("HalData\t\t+%d\n", offsetof(struct _ADAPTER, HalData)); //+5656
printf("HalFunc\t\t+%d\n", offsetof(struct _ADAPTER, HalFunc)); //+5664
printf("bDriverStopped\t+%d\n", offsetof(struct _ADAPTER, bDriverStopped)); //+5880
printf("hw_init_completed +%d\n", offsetof(struct _ADAPTER, hw_init_completed)); //+5905
printf("stats\t\t+%d\n", offsetof(struct _ADAPTER, stats)); //+6024
printf("hw_init_mutex\t+%d\n", offsetof(struct _ADAPTER, hw_init_mutex)); //+6060
printf("fix_rate\t+%d\n", offsetof(struct _ADAPTER, fix_rate)); //+6084
printf("rltk_wlan_info = %p\n", &rltk_wlan_info);
dump_bytes((uint32_t)&rltk_wlan_info, sizeof(rltk_wlan_info));
_adapter * ad = *(_adapter **)((rltk_wlan_info[0].dev)->priv);
printf("adapter0 = %p, %p\n", ad, ad->pbuddy_adapter);
ad = *(_adapter **)((rltk_wlan_info[1].dev)->priv);
printf("adapter1 = %p, %p\n", ad, ad->pbuddy_adapter);
vTaskDelay(5);
dump_bytes((uint32_t)ad,sizeof(struct _ADAPTER));
vTaskDelay(5);
if (sizeof(struct _ADAPTER) != 6088) {
printf("Error: Check WiFi adapter struct!\n");
};
}
static void show_wlan_param(int argc, char *argv[]) {
(void)argc; (void)argv;
_adapter * ad = *(_adapter **)((rltk_wlan_info[0].dev)->priv);
#if 1
printf("reconnect_deauth_filtered\t%u\n", ad->mlmeextpriv.reconnect_deauth_filtered);
printf("reconnect_times\t%u\n", ad->mlmeextpriv.reconnect_times);
printf("reconnect_cnt\t%u\n", ad->mlmeextpriv.reconnect_cnt);
printf("reconnect_timeout\t%u\n", ad->mlmeextpriv.reconnect_timeout);
#endif
}
MON_RAM_TAB_SECTION COMMAND_TABLE console_wlan_tst[] = {
{"CHKWL", 0, tst_wlan_struct, ": Chk wlan struct"},
{"CHKAP", 0, show_wlan_param, ": Chow wlan parm"}
};