swapforth

Форк
0
/
swapforth.c 
234 строки · 5.5 Кб
1
#include "ets_sys.h"
2
#include "osapi.h"
3
#include "gpio.h"
4
#include "os_type.h"
5
#include "mem.h"
6
#include "user_config.h"
7
#include "ip_addr.h"
8
#include "espconn.h"
9
#include "user_interface.h"
10

11
extern int swapforth(), swapforth2();
12

13
// #undef ICACHE_FLASH_ATTR
14
// #define ICACHE_FLASH_ATTR
15

16
#define user_procTaskPrio        0
17
#define user_procTaskQueueLen    128
18
os_event_t    user_procTaskQueue[user_procTaskQueueLen];
19
static void user_procTask(os_event_t *events);
20

21
volatile os_timer_t some_timer;
22

23
struct espconn *_ptrUDPServer;
24
uint8 udpServerIP[] = { 192, 168, 0, 64 };
25

26
void dump(uint32 a)
27
{
28
  uint32*ptr = (uint32_t*)a;
29
  int i;
30

31
  ets_printf("%08x:   ", a);
32
  for (i = 0; i < 8; i++)
33
    ets_printf("%08x ", *ptr++);
34
  ets_printf("\n");
35
}
36

37
void timer_action(void *arg)
38
{
39
  system_os_post(user_procTaskPrio, 0, 0 );
40
}
41

42
void some_timerfunc(void *arg)
43
{
44
  //Do blinky stuff
45
  if (GPIO_REG_READ(GPIO_OUT_ADDRESS) & BIT2)
46
  {
47
      //Set GPIO2 to LOW
48
      gpio_output_set(0, BIT2, BIT2, 0);
49
  }
50
  else
51
  {
52
      //Set GPIO2 to HIGH
53
      gpio_output_set(BIT2, 0, BIT2, 0);
54
  }
55
  static int cold = 1;
56
  if (cold) {
57
    cold = 0;
58
  }
59
  static int i; i++;
60
  ets_printf("Hello World %d!\r\n", i);
61

62
#if 0
63
  // See eagle_soc.h for timer layout
64
  {
65
    uint32*ptr = (uint32_t*)0x60000600;
66
    int i;
67

68
    for (i = 0; i < 24; i++) {
69
      ets_printf("%08x ", *ptr++);
70
      if ((i & 7) == 7)
71
        ets_printf("\n");
72
    }
73
  }
74
  dump(0x3fffdaac);
75
  dump(0x3fffc000);
76
  dump(0x40000390);
77
  dump(0x3fffc100);
78
  dump(0x401006a0);
79
#endif
80

81
  if (1) {
82
    _ptrUDPServer = (struct espconn *) os_zalloc(sizeof(struct espconn));
83
    _ptrUDPServer->type = ESPCONN_UDP;
84
    _ptrUDPServer->state = ESPCONN_NONE;
85
    _ptrUDPServer->proto.udp = (esp_udp *) os_zalloc(sizeof(esp_udp));
86
    _ptrUDPServer->proto.udp->local_port = espconn_port();
87
    _ptrUDPServer->proto.udp->remote_port = 2115;
88
    os_memcpy(_ptrUDPServer->proto.udp->remote_ip, udpServerIP, 4);
89
    espconn_create(_ptrUDPServer);
90
  }
91
  if (40 < i) {
92
    char USER_DATA[80];
93
    os_sprintf(USER_DATA, "%07d\n", i);
94
    espconn_sent(_ptrUDPServer, (uint8 *) USER_DATA, (uint16) strlen(USER_DATA));
95
  }
96
  system_os_post(user_procTaskPrio, 0, 0 );
97
}
98

99
//Do nothing function
100
static void ICACHE_FLASH_ATTR
101
user_procTask(os_event_t *e)
102
{
103
  // ets_printf("/idle %d %d/\n", e->sig, e->par);
104
  // os_delay_us(10);
105
  // ets_printf("\nreturn B: %08x\n", swapforth2(e->sig, e->par));
106
  swapforth2(e->sig, e->par);
107
}
108

109
#define UART0   0
110
#define UART1   1
111

112
#include "uart_register.h"
113

114
LOCAL void
115
uart0_rx_intr_handler(void *para)
116
{
117
  //Set GPIO2 to HIGH
118
  gpio_output_set(BIT2, 0, BIT2, 0);
119

120
  if (UART_RXFIFO_FULL_INT_ST != (READ_PERI_REG(UART_INT_ST(UART0)) & UART_RXFIFO_FULL_INT_ST)) {
121
    return;
122
  }
123

124
  WRITE_PERI_REG(UART_INT_CLR(UART0), UART_RXFIFO_FULL_INT_CLR);
125

126
  if (READ_PERI_REG(UART_STATUS(UART0)) & (UART_RXFIFO_CNT << UART_RXFIFO_CNT_S)) {
127
    uint8 RcvChar = READ_PERI_REG(UART_FIFO(UART0)) & 0xFF;
128
    // ets_printf("^^^%c", RcvChar);
129
    // os_delay_us(1000);
130
    system_os_post(user_procTaskPrio, 0x947, RcvChar );
131
  }
132
}
133

134
#define BAUDRATE  921600
135

136
void
137
uart_config(uint8 uart_no)
138
{
139
    if (uart_no == UART1) {
140
        PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_U1TXD_BK);
141
    } else {
142
        /* rcv_buff size if 0x100 */
143
        ETS_UART_INTR_ATTACH(uart0_rx_intr_handler,  NULL);
144
        PIN_PULLUP_DIS(PERIPHS_IO_MUX_U0TXD_U);
145
        PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0TXD_U, FUNC_U0TXD);
146
    }
147

148
    uart_div_modify(uart_no, UART_CLK_FREQ / BAUDRATE);
149

150

151
    //clear rx and tx fifo,not ready
152
    SET_PERI_REG_MASK(UART_CONF0(uart_no), UART_RXFIFO_RST | UART_TXFIFO_RST);
153
    CLEAR_PERI_REG_MASK(UART_CONF0(uart_no), UART_RXFIFO_RST | UART_TXFIFO_RST);
154

155
    //set rx fifo trigger
156
    WRITE_PERI_REG(UART_CONF1(uart_no), (1 & UART_RXFIFO_FULL_THRHD) << UART_RXFIFO_FULL_THRHD_S);
157

158
    //clear all interrupt
159
    WRITE_PERI_REG(UART_INT_CLR(uart_no), 0xffff);
160
    //enable rx_interrupt
161
    SET_PERI_REG_MASK(UART_INT_ENA(uart_no), UART_RXFIFO_FULL_INT_ENA);
162

163
    ETS_UART_INTR_ENABLE();
164
}
165

166
void wifi_config()
167
{
168
  const char ssid[32] = "bowmanvilleshed";
169
  const char password[64] = "qwertyui";
170
  wifi_station_get_connect_status();
171
  struct station_config stationConf;
172

173
  wifi_set_opmode(STATION_MODE);
174
  stationConf.bssid_set = 0;
175
  os_memcpy(&stationConf.ssid, ssid, 32);
176
  os_memcpy(&stationConf.password, password, 64);
177
  wifi_station_set_config(&stationConf);
178
  // wifi_station_connect();
179
};
180

181
//Init function 
182
void ICACHE_FLASH_ATTR
183
user_init()
184
{
185
  system_set_os_print(0);
186
  uart_div_modify(0, UART_CLK_FREQ / BAUDRATE);
187

188
  // wifi_config();
189

190
  // Initialize the GPIO subsystem.
191
  gpio_init();
192

193
  //Set GPIO2 to output mode
194
  PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_GPIO2);
195

196
  //Set GPIO2 low
197
  gpio_output_set(0, BIT2, BIT2, 0);
198

199
#if 0
200
  //Disarm timer
201
  os_timer_disarm(&some_timer);
202

203
  // Setup timer
204
  os_timer_setfn(&some_timer, (os_timer_func_t *)some_timerfunc, NULL);
205
  //Arm the timer
206
  //&some_timer is the pointer
207
  //1000 is the fire time in ms
208
  //0 for once and 1 for repeating
209
  // os_timer_arm(&some_timer, 2000, 1);
210
#endif
211

212
  os_timer_disarm(&some_timer);
213
  os_timer_setfn(&some_timer, (os_timer_func_t *)timer_action, NULL);
214
  // os_timer_arm(&some_timer, 2000, 1);
215

216
  //Start os task
217
  system_os_task(user_procTask, user_procTaskPrio,user_procTaskQueue, user_procTaskQueueLen);
218

219
  int j;
220
  for (j = 0; j < 2000; j++)
221
    ets_printf(".");
222

223
  uart_config(0);
224

225
  //ets_printf("\nreturn A: %08x\n", swapforth());
226
  swapforth();
227
}
228

229
int ICACHE_FLASH_ATTR
230
klok()
231
{
232
  os_timer_arm(&some_timer, 2000, 1);
233
  return 101;
234
}
235

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.