Skip to content

Commit

Permalink
demo: Adapt for GRiSP nano
Browse files Browse the repository at this point in the history
  • Loading branch information
c-mauderer committed Nov 27, 2024
1 parent 79e677f commit aefcfb3
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 35 deletions.
3 changes: 3 additions & 0 deletions demo/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ CFLAGS += -O0
ifeq ($(RTEMS_BSP),atsamv)
LDFLAGS += -qnolinkcmds -T linkcmds.sdram
endif
ifeq ($(RTEMS_BSP),stm32u5-grisp-nano)
LDFLAGS += -qnolinkcmds -T linkcmds.ospi
endif

APP = $(BUILDDIR)/demo
APP_PIECES = $(wildcard *.c)
Expand Down
79 changes: 50 additions & 29 deletions demo/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#undef EVENT_RECORDING
#define RTC_ENABLED

#include <grisp.h>

#include <assert.h>
#include <stdlib.h>

Expand All @@ -45,6 +47,7 @@
#include <rtems/shell.h>
#include <rtems/stringto.h>
#include <rtems/ftpd.h>
#include <rtems/tod.h>
#include <machine/rtems-bsd-commands.h>
#ifdef RTC_ENABLED
#include <libchip/rtc.h>
Expand All @@ -56,17 +59,12 @@
#endif /* EVENT_RECORDING */

#include <bsp.h>
#ifdef LIBBSP_ARM_ATSAM_BSP_H
#define IS_GRISP1 1
#else
#define IS_GRISP2 1
#endif

#include <grisp.h>
#ifdef IS_GRISP1
#ifdef GRISP_PLATFORM_GRISP_BASE
#include <bsp/i2c.h>
#include <grisp/pin-config.h>
#endif /* IS_GRISP1 */
#endif /* GRISP_PLATFORM_GRISP_BASE */
#include <grisp/led.h>
#include <grisp/init.h>
#include <grisp/eeprom.h>
Expand All @@ -91,12 +89,13 @@

const char *wpa_supplicant_conf = "/media/mmcsd-0-0/wpa_supplicant.conf";

#ifdef IS_GRISP1
#ifdef GRISP_PLATFORM_GRISP_BASE
const Pin atsam_pin_config[] = {GRISP_PIN_CONFIG};
const size_t atsam_pin_config_count = PIO_LISTSIZE(atsam_pin_config);
const uint32_t atsam_matrix_ccfg_sysio = GRISP_MATRIX_CCFG_SYSIO;
#endif /* IS_GRISP1 */
#endif /* GRISP_PLATFORM_GRISP_BASE */

#ifndef GRISP_PLATFORM_GRISP_NANO
struct rtems_ftpd_configuration rtems_ftpd_configuration = {
.priority = 100,
.max_hook_filesize = 0,
Expand All @@ -107,6 +106,7 @@ struct rtems_ftpd_configuration rtems_ftpd_configuration = {
.idle = 5 * 60,
.access = 0
};
#endif

static void
start_shell(void)
Expand All @@ -123,6 +123,7 @@ start_shell(void)
assert(sc == RTEMS_SUCCESSFUL);
}

#ifndef GRISP_PLATFORM_GRISP_NANO
static void
create_wlandev(void)
{
Expand Down Expand Up @@ -166,6 +167,7 @@ create_wlandev(void)
}
}
}
#endif

static void
led_task(rtems_task_argument arg)
Expand Down Expand Up @@ -211,6 +213,7 @@ init_led(void)
assert(sc == RTEMS_SUCCESSFUL);
}

#ifndef GRISP_PLATFORM_GRISP_NANO
static int
command_startftp(int argc, char *argv[])
{
Expand Down Expand Up @@ -238,6 +241,7 @@ rtems_shell_cmd_t rtems_shell_STARTFTP_Command = {
NULL, /* next */
0, 0, 0
};
#endif

static void
Init(rtems_task_argument arg)
Expand All @@ -250,11 +254,11 @@ Init(rtems_task_argument arg)

puts("\nGRiSP2 RTEMS Demo\n");

#ifdef IS_GRISP1
#ifdef GRISP_PLATFORM_GRISP_BASE
rv = atsam_register_i2c_0();
assert(rv == 0);
#endif
#ifdef IS_GRISP2
#ifdef GRISP_PLATFORM_GRISP2
if (grisp_is_industrialgrisp()) {
/* Industrial GRiSP */
rv = spi_bus_register_imx(GRISP_SPI_DEVICE,
Expand All @@ -279,26 +283,32 @@ Init(rtems_task_argument arg)
rv = i2c_bus_register_imx("/dev/i2c-2", "i2c1");
assert(rv == 0);
}
#endif /* IS_GRISP2 */
#endif /* GRISP_PLATFORM_GRISP2 */

#ifdef RTC_ENABLED
setRealTimeToRTEMS();
#endif

#ifndef GRISP_PLATFORM_GRISP_NANO
printf("Init EEPROM\n");
grisp_eeprom_init();
rv = grisp_eeprom_get(&eeprom);
#ifndef IS_GRISP1 /* On GRiSP1 the checksum hasn't been calculated correctly */
#ifndef GRISP_PLATFORM_GRISP_BASE /* On GRiSP1 the checksum hasn't been calculated correctly */
if (rv == 0) {
#endif
grisp_eeprom_dump(&eeprom);
#ifndef IS_GRISP1
#ifndef GRISP_PLATFORM_GRISP_BASE
} else {
printf("ERROR: Invalid EEPROM\n");
}
#endif
#else
/* FIXME: EEPROM would have to be re-implemented using STM HAL */
(void) rv;
(void) eeprom;
#endif

grisp_init_sd_card();
grisp_init_sd_card("/media/mmcsd-0-0");
grisp_init_lower_self_prio();
grisp_init_libbsd();

Expand All @@ -312,6 +322,7 @@ Init(rtems_task_argument arg)
}

sleep(1);
#ifndef GRISP_PLATFORM_GRISP_NANO
grisp_init_dhcpcd(PRIO_DHCP);

grisp_led_set2(false, false, true);
Expand All @@ -320,28 +331,30 @@ Init(rtems_task_argument arg)
grisp_init_wpa_supplicant(wpa_supplicant_conf, PRIO_WPA,
create_wlandev);
}
#endif

#ifdef EVENT_RECORDING
rtems_record_start_server(10, 1234, 10);
rtems_record_line();
#endif /* EVENT_RECORDING */

init_led();
#ifdef IS_GRISP2
#ifdef GRISP_PLATFORM_GRISP2
if (grisp_is_industrialgrisp()) {
pmod_rfid_init(GRISP_SPI_DEVICE, 0);
pmod_dio_init(GRISP_SPI_DEVICE);
} else {
// uncomment for testing RFID
//pmod_rfid_init(GRISP_SPI_DEVICE, 1);
}
#endif /* IS_GRISP2 */
#endif /* GRISP_PLATFORM_GRISP2 */
start_shell();

exit(0);
}

#ifdef RTC_ENABLED
#ifdef GRISP_PLATFORM_GRISP2
static struct mcp7940m_rtc rtc_ctx =
MCP7940M_RTC_INITIALIZER("/dev/i2c-1", 0x6f, false);

Expand All @@ -351,6 +364,7 @@ rtc_tbl RTC_Table[] = {

size_t RTC_Count = (sizeof(RTC_Table)/sizeof(rtc_tbl));
#endif
#endif

/*
* Configure LibBSD.
Expand Down Expand Up @@ -411,23 +425,30 @@ size_t RTC_Count = (sizeof(RTC_Table)/sizeof(rtc_tbl));
#include <bsp/irq-info.h>
#define CONFIGURE_SHELL_COMMANDS_INIT

#ifdef GRISP_PLATFORM_GRISP_NANO
#define GRISP_NET_CMDS
#else
#define GRISP_NET_CMDS \
&rtems_shell_ARP_Command, \
&rtems_shell_PFCTL_Command, \
&rtems_shell_PING_Command, \
&rtems_shell_IFCONFIG_Command, \
&rtems_shell_ROUTE_Command, \
&rtems_shell_NETSTAT_Command, \
&rtems_shell_DHCPCD_Command, \
&rtems_shell_HOSTNAME_Command, \
&rtems_shell_WLANSTATS_Command, \
&rtems_shell_STARTFTP_Command, \
&rtems_shell_WPA_SUPPLICANT_Command, \
&rtems_shell_WPA_SUPPLICANT_FORK_Command,
#endif

#define CONFIGURE_SHELL_USER_COMMANDS \
&bsp_interrupt_shell_command, \
&rtems_shell_ARP_Command, \
&rtems_shell_PFCTL_Command, \
&rtems_shell_PING_Command, \
&rtems_shell_IFCONFIG_Command, \
&rtems_shell_ROUTE_Command, \
&rtems_shell_NETSTAT_Command, \
&rtems_shell_DHCPCD_Command, \
&rtems_shell_HOSTNAME_Command, \
&rtems_shell_SYSCTL_Command, \
&rtems_shell_VMSTAT_Command, \
&rtems_shell_WLANSTATS_Command, \
&rtems_shell_STARTFTP_Command, \
&rtems_shell_BLKSTATS_Command, \
&rtems_shell_WPA_SUPPLICANT_Command, \
&rtems_shell_WPA_SUPPLICANT_FORK_Command, \
GRISP_NET_CMDS \
&shell_PATTERN_FILL_Command, \
&shell_PATTERN_CHECK_Command, \
&shell_1wiretemp_command, \
Expand Down
8 changes: 2 additions & 6 deletions demo/pmod_rfid.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,13 @@
* POSSIBILITY OF SUCH DAMAGE.
*/

#include <grisp.h>
#include <bsp.h>
#ifdef LIBBSP_ARM_ATSAM_BSP_H
#define IS_GRISP1 1
#else
#define IS_GRISP2 1
#endif

#include <rtems.h>
#include <rtems/shell.h>

#ifdef IS_GRISP2
#ifdef GRISP_PLATFORM_GRISP2
#include <bsp/fdt.h>
#include <bsp/imx-gpio.h>

Expand Down

0 comments on commit aefcfb3

Please sign in to comment.