switched to libco

This commit is contained in:
Triss 2021-06-08 01:22:55 +02:00
parent 2683c5c0b5
commit b2e797d227
3 changed files with 72 additions and 9 deletions

View File

@ -36,6 +36,7 @@ if(FAMILY STREQUAL "rp2040")
target_sources(${PROJECT} PUBLIC target_sources(${PROJECT} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/main.c ${CMAKE_CURRENT_SOURCE_DIR}/main.c
${CMAKE_CURRENT_SOURCE_DIR}/usb_descriptors.c ${CMAKE_CURRENT_SOURCE_DIR}/usb_descriptors.c
${CMAKE_CURRENT_SOURCE_DIR}/libco/libco.S
${CMAKE_CURRENT_SOURCE_DIR}/CMSIS_5/CMSIS/DAP/Firmware/Source/DAP.c ${CMAKE_CURRENT_SOURCE_DIR}/CMSIS_5/CMSIS/DAP/Firmware/Source/DAP.c
${CMAKE_CURRENT_SOURCE_DIR}/CMSIS_5/CMSIS/DAP/Firmware/Source/JTAG_DP.c ${CMAKE_CURRENT_SOURCE_DIR}/CMSIS_5/CMSIS/DAP/Firmware/Source/JTAG_DP.c
${CMAKE_CURRENT_SOURCE_DIR}/CMSIS_5/CMSIS/DAP/Firmware/Source/DAP_vendor.c ${CMAKE_CURRENT_SOURCE_DIR}/CMSIS_5/CMSIS/DAP/Firmware/Source/DAP_vendor.c
@ -49,6 +50,7 @@ if(FAMILY STREQUAL "rp2040")
# Example include # Example include
target_include_directories(${PROJECT} PUBLIC target_include_directories(${PROJECT} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/ ${CMAKE_CURRENT_SOURCE_DIR}/
${CMAKE_CURRENT_SOURCE_DIR}/libco/
${CMAKE_CURRENT_SOURCE_DIR}/CMSIS_5/CMSIS/DAP/Firmware/Include/ ${CMAKE_CURRENT_SOURCE_DIR}/CMSIS_5/CMSIS/DAP/Firmware/Include/
${CMAKE_CURRENT_SOURCE_DIR}/CMSIS_5/CMSIS/Core/Include/ ${CMAKE_CURRENT_SOURCE_DIR}/CMSIS_5/CMSIS/Core/Include/
${CMAKE_CURRENT_SOURCE_DIR}/bsp/${FAMILY}/ ${CMAKE_CURRENT_SOURCE_DIR}/bsp/${FAMILY}/

View File

@ -197,14 +197,14 @@ void cdc_serprog_task(void) {
// bytes seem to be sent one by one, so its probably better to rework // bytes seem to be sent one by one, so its probably better to rework
// this, a lot // this, a lot
if (conn && avail) { if (conn && avail) {
printf("rbp=%d\n", bufpos); //printf("rbp=%d\n", bufpos);
uint32_t nread = tud_cdc_n_read(CDC_N_SERPROG, &rx_buf[bufpos], sizeof(rx_buf) - bufpos); uint32_t nread = tud_cdc_n_read(CDC_N_SERPROG, &rx_buf[bufpos], sizeof(rx_buf) - bufpos);
printf("got %d\n", nread); printf("got %d\n", nread);
cdc_uart_task(); cdc_uart_task();
bufpos = 0; bufpos = 0;
do { do {
printf("hbp=%d\n", /*rx_buf[bufpos],*/ bufpos); //printf("hbp=%d\n", /*rx_buf[bufpos],*/ bufpos);
cdc_uart_task(); cdc_uart_task();
uint32_t dec = serprog_handle_cmd(&rx_buf[bufpos], nread); uint32_t dec = serprog_handle_cmd(&rx_buf[bufpos], nread);
cdc_uart_task(); cdc_uart_task();
@ -218,9 +218,9 @@ void cdc_serprog_task(void) {
// so we move the leftover data to the start of the buffer, // so we move the leftover data to the start of the buffer,
// and make sure the next call will put the new data right // and make sure the next call will put the new data right
// after it // after it
printf("mv %d %d %d ", nread, bufpos, rx_buf[bufpos]); //printf("mv %d %d %d ", nread, bufpos, rx_buf[bufpos]);
memmove(rx_buf, &rx_buf[bufpos], nread); memmove(rx_buf, &rx_buf[bufpos], nread);
printf("%d\n", rx_buf[0]); //printf("%d\n", rx_buf[0]);
bufpos = nread; bufpos = nread;
break; break;
} }

71
main.c
View File

@ -36,12 +36,64 @@
#include "protocfg.h" #include "protocfg.h"
#include "protos.h" #include "protos.h"
#include "libco.h"
#include "thread.h"
#ifdef PICO_BOARD #ifdef PICO_BOARD
#include <pico/binary_info.h> #include <pico/binary_info.h>
#endif #endif
static cothread_t mainthread
#ifdef DBOARD_HAS_UART
, uartthread
#endif
#ifdef DBOARD_HAS_SERPROG
, serprogthread
#endif
;
void thread_yield(void) {
co_switch(mainthread);
}
#ifdef DBOARD_HAS_UART
static void uart_thread_fn(void) {
cdc_uart_init();
thread_yield();
while (1) {
cdc_uart_task();
thread_yield();
}
}
#endif
#ifdef DBOARD_HAS_SERPROG
static void serprog_thread_fn(void) {
cdc_serprog_init();
thread_yield();
while (1) {
cdc_serprog_task();
thread_yield();
}
}
#endif
#ifdef DBOARD_HAS_UART
static uint8_t uartstack[4096];
#endif
#ifdef DBOARD_HAS_UART
static uint8_t serprogstack[4096];
#endif
extern uint32_t co_active_buffer[64];
uint32_t co_active_buffer[64];
extern cothread_t co_active_handle;
cothread_t co_active_handle;
int main(void) int main(void)
{ {
mainthread = co_active();
// TODO: split this out in a bsp-specific file // TODO: split this out in a bsp-specific file
#ifdef PICO_BOARD #ifdef PICO_BOARD
// use hardcoded values from TinyUSB board.h // use hardcoded values from TinyUSB board.h
@ -50,10 +102,14 @@ int main(void)
board_init(); board_init();
#ifdef DBOARD_HAS_UART #ifdef DBOARD_HAS_UART
cdc_uart_init(); //cdc_uart_init();
uartthread = co_derive(uartstack, sizeof uartstack, uart_thread_fn);
co_switch(uartthread); // will call cdc_uart_init() on correct thread
#endif #endif
#ifdef DBOARD_HAS_SERPROG #ifdef DBOARD_HAS_SERPROG
cdc_serprog_init(); //cdc_serprog_init();
serprogthread = co_derive(serprogstack, sizeof serprogstack, serprog_thread_fn);
co_switch(serprogthread); // will call cdc_serprog_init() on correct thread
#endif #endif
#ifdef DBOARD_HAS_CMSISDAP #ifdef DBOARD_HAS_CMSISDAP
DAP_Setup(); DAP_Setup();
@ -65,12 +121,17 @@ int main(void)
{ {
tud_task(); // tinyusb device task tud_task(); // tinyusb device task
#ifdef DBOARD_HAS_UART #ifdef DBOARD_HAS_UART
cdc_uart_task(); //cdc_uart_task();
co_switch(uartthread);
#endif #endif
tud_task(); // tinyusb device task
#ifdef DBOARD_HAS_SERPROG #ifdef DBOARD_HAS_SERPROG
cdc_serprog_task(); //cdc_serprog_task();
co_switch(serprogthread);
#endif #endif
sleep_ms(100);
//printf("hi\n");
} }
return 0; return 0;