-#define VERS_BUILD 2
+#define VERS_BUILD 433
#define VERS_HOST "giskard.codewiz.org"
*/
#define CONFIG_KDEBUG_PORT 0
+#define CONFIG_KDEBUG_TRACE 0
+#define CONFIG_KDEBUG_VERBOSE_ASSERT 0
+#define CONFIG_KDEBUG_WALLS 0
+
/**
* Baudrate for the debug console.
* $WIZ$ type = "int"; min = 300
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_format"
*/
-#define FAT_LOG_FORMAT LOG_FMT_VERBOSE
+#define FAT_LOG_FORMAT LOG_FMT_TERSE
/**
* Minimization level to remove some functions.
* $WIZ$ type = "int"; min = 0; max = 3
*/
-#define CONFIG_FAT_FS_MINIMIZE 0
+#define CONFIG_FAT_FS_MINIMIZE 2
#define _FS_MINIMIZE CONFIG_FAT_FS_MINIMIZE
/**
* \sa PRINTF_NOFLOAT
* \sa PRINTF_FULL
*/
-#define CONFIG_PRINTF PRINTF_FULL
+#define CONFIG_PRINTF PRINTF_NOFLOAT
/**
* Size of buffer to format "%" sequences in printf.
+++ /dev/null
-/**
- * \file
- * <!--
- * This file is part of BeRTOS.
- *
- * Bertos is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * As a special exception, you may use this file as part of a free software
- * library without restriction. Specifically, if other files instantiate
- * templates or use macros or inline functions from this file, or you compile
- * this file and link it with other files to produce an executable, this
- * file does not by itself cause the resulting executable to be covered by
- * the GNU General Public License. This exception does not however
- * invalidate any other reasons why the executable file might be covered by
- * the GNU General Public License.
- *
- * Copyright 2008 Develer S.r.l. (http://www.develer.com/)
- * All Rights Reserved.
- * -->
- *
- * \brief Configuration file for heap module.
- *
- *
- * \author Daniele Basile <asterix@develer.com>
- */
-
-#ifndef CFG_HEAP_H
-#define CFG_HEAP_H
-
-/**
- * Enable malloc/free like API.
- * $WIZ$ type = "boolean"
- */
-#define CONFIG_HEAP_MALLOC 1
-
-#endif /* CFG_HEAP_H */
-
-
* Process monitor.
* $WIZ$ type = "autoenabled"
*/
-#define CONFIG_KERN_MONITOR 1
+#define CONFIG_KERN_MONITOR 0
#endif /* CFG_MONITOR_H */
*
* $WIZ$ type = "autoenabled"
*/
-#define CONFIG_KERN 1
+#define CONFIG_KERN 0
/**
* Kernel interrupt supervisor. WARNING: Experimental, still incomplete!
* Priority-based scheduling policy.
* $WIZ$ type = "boolean"
*/
-#define CONFIG_KERN_PRI 1
+#define CONFIG_KERN_PRI 0
/**
* Dynamic memory allocation for processes.
* $WIZ$ type = "boolean"
* $WIZ$ conditional_deps = "heap"
*/
-#define CONFIG_KERN_HEAP 1
+#define CONFIG_KERN_HEAP 0
/**
* Size of the dynamic memory pool used by processes.
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_format"
*/
-#define KERN_LOG_FORMAT LOG_FMT_VERBOSE
+#define KERN_LOG_FORMAT LOG_FMT_TERSE
#endif /* CFG_PROC_H */
+++ /dev/null
-/**
- * \file
- * <!--
- * This file is part of BeRTOS.
- *
- * Bertos is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * As a special exception, you may use this file as part of a free software
- * library without restriction. Specifically, if other files instantiate
- * templates or use macros or inline functions from this file, or you compile
- * this file and link it with other files to produce an executable, this
- * file does not by itself cause the resulting executable to be covered by
- * the GNU General Public License. This exception does not however
- * invalidate any other reasons why the executable file might be covered by
- * the GNU General Public License.
- *
- * Copyright 2008 Develer S.r.l. (http://www.develer.com/)
- * -->
- *
- * \brief Configuration file for PWM module.
- *
- * \author Daniele Basile <asterix@develer.com>
- */
-
-#ifndef CFG_PWM_H
-#define CFG_PWM_H
-
-/**
- * Module logging level.
- *
- * $WIZ$ type = "enum"
- * $WIZ$ value_list = "log_level"
- */
-#define PWM_LOG_LEVEL LOG_LVL_INFO
-
-/**
- * Module logging format.
- *
- * $WIZ$ type = "enum"
- * $WIZ$ value_list = "log_format"
- */
-#define PWM_LOG_FORMAT LOG_FMT_VERBOSE
-
-#endif /* CFG_PWM_H */
* $WIZ$ type = "enum"
* $WIZ$ value_list = "log_format"
*/
-#define SD_LOG_FORMAT LOG_FMT_VERBOSE
+#define SD_LOG_FORMAT LOG_FMT_TERSE
/**
*
* $WIZ$ type = "boolean"
*/
-#define CONFIG_SD_OLD_INIT 1
+#define CONFIG_SD_OLD_INIT 0
#endif /* CFG_SD_H */
* $WIZ$ type = "int"
* $WIZ$ min = 2
*/
-#define CONFIG_UART0_RXBUFSIZE 32
+#define CONFIG_UART0_RXBUFSIZE 512
/**
* Size of the outbound FIFO buffer for port 1 [bytes].
* $WIZ$ type = "int"
* $WIZ$ supports = "avr"
*/
-#define CONFIG_SPI_CLOCK_DIV 16
+#define CONFIG_SPI_CLOCK_DIV 128
/**
* SPI clock polarity: normal low or normal high.
* $WIZ$ type = "int"
* $WIZ$ min = -1
*/
-#define CONFIG_SER_RXTIMEOUT -1
+#define CONFIG_SER_RXTIMEOUT 200
/**
* Use RTS/CTS handshake.
* Inter-process signals.
* $WIZ$ type = "autoenabled"
*/
-#define CONFIG_KERN_SIGNALS 1
+#define CONFIG_KERN_SIGNALS 0
#endif /* CFG_SIGNAL_H */
#ifndef HW_SD_H
#define HW_SD_H
-#warning FIXME: This is an example implementation, you must implement it
-
-#define SD_CS_INIT() do { /* implement me */} while(0)
-#define SD_CS_ON() do { /* implement me */} while(0)
-#define SD_CS_OFF() do { /* implement me */} while(0)
-
-#define SD_PIN_INIT() do { /* implement me */} while(0)
-#define SD_CARD_PRESENT() true /* implement me */
-#define SD_WRITE_PROTECT() false /* implement me */
+#define SD_CS_INIT() do { SD_CS_OFF(); DDRB |= BV(0) | BV(2); } while(0)
+#define SD_CS_ON() do { PORTB &= ~BV(0); } while(0)
+#define SD_CS_OFF() do { PORTB |= BV(0); } while(0)
#endif /* HW_SD_H */
/**
* \file
- * <!--
- * This file is part of BeRTOS.
*
- * Bertos is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
+ * \author Bernie Innocenti <bernie@codewiz.org>
*
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
+ * \brief Serial data logger for RMS
*
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * As a special exception, you may use this file as part of a free software
- * library without restriction. Specifically, if other files instantiate
- * templates or use macros or inline functions from this file, or you compile
- * this file and link it with other files to produce an executable, this
- * file does not by itself cause the resulting executable to be covered by
- * the GNU General Public License. This exception does not however
- * invalidate any other reasons why the executable file might be covered by
- * the GNU General Public License.
- *
- * Copyright 2010 Develer S.r.l. (http://www.develer.com/)
- *
- * -->
- *
- * \author Andrea Righi <arighi@develer.com>
- *
- * \brief Kernel project.
- *
- * This is a minimalist kernel project: it just initializes the hardware and
- * creates an independent process to blink an LED, while the main loop
- * continues to monitor the stack utilization of all the processes.
+ * This application logs data
*/
#include "hw/hw_led.h"
+#define LOG_LEVEL 3
+#include <cfg/log.h>
#include <cfg/debug.h>
#include <cpu/irq.h>
#include <cpu/power.h>
-#include <drv/timer.h>
-#include <drv/ser.h>
+#ifdef BERTOS_FAT
+ #include <drv/sd.h>
+ #include <fs/fat.h>
+#else
+ #include <FAT16/fat.h>
+ #include <FAT16/partition.h>
+ #include <FAT16/sd_raw.h>
+#endif
+#include <drv/ser.h>
+#include <drv/timer.h>
#include <kern/proc.h>
-#include <kern/monitor.h>
-static Serial out;
+#include <string.h>
-static void init(void)
+
+static Serial ser;
+
+#ifdef BERTOS_FAT
+ static Serial spi;
+ static FATFS fs;
+ static FatFile file;
+ static Sd sd;
+#else
+ struct fat_fs_struct *fs;
+ struct partition_struct *partition;
+ struct fat_dir_struct *dd;
+ struct fat_dir_entry_struct dir_entry;
+ struct fat_file_struct *fd;
+#endif
+
+
+#ifndef BERTOS_FAT
+static void fat_init(void)
{
- /* Enable all the interrupts */
- IRQ_ENABLE;
+ partition = partition_open(
+ sd_raw_read,
+ sd_raw_read_interval,
+ sd_raw_write,
+ sd_raw_write_interval,
+ 0
+ );
+
+ if (!partition)
+ {
+ // If the partition did not open, assume the storage device
+ // is a "superfloppy", i.e. has no MBR.
+ partition = partition_open(
+ sd_raw_read,
+ sd_raw_read_interval,
+ sd_raw_write,
+ sd_raw_write_interval,
+ 0
+ );
+ }
+ if (!partition)
+ {
+ ASSERT(0); for(;;) {}
+ }
+
+ if (!(fs = fat_open(partition)))
+ {
+ ASSERT(0); for(;;) {}
+ }
+
+ //Open root directory
+ fat_get_dir_entry_of_path(fs, "/", &dir_entry);
+ if (!(dd = fat_open_dir(fs, &dir_entry)))
+ {
+ ASSERT(0); for(;;) {}
+ }
+}
+
+static uint8_t find_file_in_dir(UNUSED_ARG(struct fat_fs_struct *, fs), struct fat_dir_struct* dd, const char* name, struct fat_dir_entry_struct* dir_entry)
+{
+ fat_reset_dir(dd); //Make sure to start from the beginning of the directory!
+ while(fat_read_dir(dd, dir_entry))
+ {
+ if(strcmp(dir_entry->long_name, name) == 0)
+ {
+ //fat_reset_dir(dd);
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+static struct fat_file_struct *open_file_in_dir(struct fat_fs_struct* fs, struct fat_dir_struct* dd, const char* name)
+{
+ struct fat_dir_entry_struct file_entry;
+ if(!find_file_in_dir(fs, dd, name, &file_entry))
+ return 0;
+
+ return fat_open_file(fs, &file_entry);
+}
+
+#endif // !BERTOS_FAT
+static void init(void)
+{
/* Initialize debugging module (allow kprintf(), etc.) */
kdbg_init();
+
/* Initialize system timer */
timer_init();
- /*
- * XXX: Arduino has a single UART port that was previously
- * initialized for debugging purpose.
- * In order to activate the serial driver you should disable
- * the debugging module.
- */
-#if 0
+
+ /* Enable all the interrupts */
+ IRQ_ENABLE;
+
+ /* Kernel initialization: processes */
+ proc_init();
+
/* Initialize UART0 */
- ser_init(&out, SER_UART0);
- /* Configure UART0 to work at 115.200 bps */
- ser_setbaudrate(&out, 115200);
-#else
- (void)out;
-#endif
+ ser_init(&ser, SER_UART0);
+ //FIXME
+ //ser_setbaudrate(&ser, 115200);
+ //ser_setbaudrate(&ser, 57600);
+ //UCSR0A = BV(U2X0);
+ ser_setbaudrate(&ser, 19200);
+
/* Initialize LED driver */
LED_INIT();
- /*
- * Kernel initialization: processes (allow to create and dispatch
- * processes using proc_new()).
- */
- proc_init();
-}
-
-static void NORETURN led_process(void)
-{
- int i;
+ timer_delay(1000);
+ kfile_printf(&ser.fd, "Hello, world!\r\n");
- /* Periodically blink the led (toggle each 100 ms) */
- for (i = 0; ; i = !i)
+#ifdef BERTOS_FAT
+ ser_init(&spi, SER_SPI);
+#else
+ DDRB |= BV(PORTB0) | BV(PORTB2) | BV(PORTB3) | BV(PORTB5);
+ if (!sd_raw_init())
{
- if (i)
- LED_ON();
- else
- LED_OFF();
- timer_delay(100);
+ ASSERT(0); for(;;) {}
}
+#endif
+
+ fat_init();
}
+
int main(void)
{
- /* Hardware initialization */
init();
- /* Create a new child process */
- proc_new(led_process, NULL, KERN_MINSTACKSIZE * 2, NULL);
+#ifdef BERTOS_FAT
+
+ FRESULT fat_err;
+ if ((fat_err = f_mount(0, &fs)) != FR_OK)
+ {
+ LOG_ERR("Error mounting FAT volume: %d\n", fat_err);
+ }
+
+ fat_err = fatfile_open(&file, "foo.txt", FA_WRITE | FA_CREATE_ALWAYS);
+ ASSERT(fat_err == FR_OK);
+
+ size_t count = kfile_write(&file.fd, "Hello, world!", strlen("Hello, world!"));
+ ASSERT(count == strlen("Hello, world!"));
+
+#else
+
+ fat_create_file(dd, "log.txt", &dir_entry);
+ fd = open_file_in_dir(fs, dd, "log.txt");
+ int32_t offset = 0;
+ fat_seek_file(fd, &offset, FAT_SEEK_END);
+
+#endif
- /*
- * The main process is kept to periodically report the stack
- * utilization of all the processes (1 probe per second).
- */
while (1)
{
- monitor_report();
- timer_delay(1000);
+ size_t size;
+ char buf[128];
+ bool sync_pending = false;
+
+ if ((size = ser_read(&ser, buf, sizeof(buf))) != 0)
+ {
+ LED_ON();
+ fat_write_file(fd, (void *)buf, size);
+ sync_pending = true;
+ sprintf(buf, "%d\r\n", size);
+ ser_write(&ser, buf, strlen(buf));
+ LED_OFF();
+ }
+ else
+ {
+ serstatus_t err = ser_getstatus(&ser);
+ if (err & ~SERRF_RXTIMEOUT)
+ {
+ LED_ON();
+ kfile_printf(&ser.fd, "\r\n*** err=%d ***\r\n", err);
+ }
+ ser_setstatus(&ser, 0);
+
+ if (sync_pending)
+ {
+ LED_ON();
+ sd_raw_sync();
+ LED_OFF();
+ sync_pending = false;
+ }
+ }
}
+ fat_close_file(fd);
}
# Files automatically generated by the wizard. DO NOT EDIT, USE rmslog_USER_CSRC INSTEAD!
rmslog_WIZARD_CSRC = \
bertos/mware/event.c \
- bertos/kern/sem.c \
- bertos/kern/monitor.c \
- bertos/struct/heap.c \
bertos/io/kfile.c \
bertos/mware/formatwr.c \
bertos/cpu/avr/drv/timer_avr.c \
bertos/kern/signal.c \
bertos/kern/proc.c \
bertos/cpu/avr/drv/ser_avr.c \
+ bertos/drv/sd.c \
bertos/drv/ser.c \
bertos/mware/hex.c \
+ bertos/fs/fat.c \
+ bertos/fs/fatfs/ff.c \
+ bertos/fs/fatfs/diskio.c \
+ bertos/io/kblock.c \
+ FAT16/fat.c \
+ FAT16/sd_raw.c \
+ FAT16/partition.c \
#
+
# Files automatically generated by the wizard. DO NOT EDIT, USE rmslog_USER_PCSRC INSTEAD!
rmslog_WIZARD_PCSRC = \
bertos/mware/formatwr.c \
rmslog_PROGRAMMER_PORT = /dev/ttyACM0
flash: $(OUTDIR)/rmslog.hex
+ sudo killall minicom && sleep 3 || :
sudo avrdude -c arduino -p $(rmslog_MCU) -P $(rmslog_PROGRAMMER_PORT) -e -U flash:w:$(OUTDIR)/rmslog.hex
# Files included by the user.