+/**
+ * \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 2010 Develer S.r.l. (http://www.develer.com/)
+ *
+ * -->
+ *
+ * \author Andrea Righi <arighi@develer.com>
+ *
+ * \brief DevelGPS demo application with gps.
+ */
+
+#include "hw/hw_led.h"
+
#include <cpu/irq.h>
#include <drv/lcd_rit128x96.h>
#include <drv/timer.h>
#include <drv/ser.h>
-#include <drv/flash_lm3s.h>
+#include <drv/flash.h>
#include <drv/kbd.h>
+#include <io/kblock.h>
+#include <io/kfile_block.h>
+
#include <kern/proc.h>
#include <kern/sem.h>
/* Storage stuff */
#define GPS_POS_MAGIC 0xdeadbeef
-static FlashLM3S flash;
+static Flash flash_blk;
+static KFileBlock flash;
-static void flash_load_target(void)
+struct SettingsData
{
uint32_t magic;
+ long target_lat, target_lon;
+};
- kfile_seek(&flash.fd, -FLASH_PAGE_SIZE_BYTES, KSM_SEEK_END);
- kfile_read(&flash.fd, &magic, sizeof(magic));
- if (magic == GPS_POS_MAGIC)
+static void flash_load_target(void)
+{
+ struct SettingsData data;
+
+ kfile_seek(&flash.fd, -sizeof(data), KSM_SEEK_END);
+ kfile_read(&flash.fd, &data, sizeof(data));
+
+ if (data.magic == GPS_POS_MAGIC)
{
- kfile_read(&flash.fd, &target_lat, sizeof(target_lat));
- kfile_read(&flash.fd, &target_lon, sizeof(target_lon));
+ target_lat = data.target_lat;
+ target_lon = data.target_lon;
}
}
static void flash_save_target(void)
{
- const uint32_t magic = GPS_POS_MAGIC;
+ struct SettingsData data;
- kfile_seek(&flash.fd, -FLASH_PAGE_SIZE_BYTES, KSM_SEEK_END);
- kfile_write(&flash.fd, &magic, sizeof(magic));
- kfile_write(&flash.fd, &target_lat, sizeof(target_lat));
- kfile_write(&flash.fd, &target_lon, sizeof(target_lon));
- kfile_flush(&flash.fd);
-}
-
-/* Status LED management */
-static void led_init(void)
-{
- SYSCTL_RCGC2_R = SYSCTL_RCGC2_GPIOG;
- (void)SYSCTL_RCGC2_R;
- GPIO_PORTG_DIR_R = 0x04;
- GPIO_PORTG_DEN_R = 0x04;
-}
+ data.magic = GPS_POS_MAGIC;
+ data.target_lat = target_lat;
+ data.target_lon = target_lon;
-INLINE void led_on(void)
-{
- GPIO_PORTG_DATA_R |= 0x04;
+ kfile_seek(&flash.fd, -sizeof(data), KSM_SEEK_END);
+ kfile_write(&flash.fd, &data, sizeof(data));
+ kfile_flush(&flash.fd);
}
-INLINE void led_off(void)
-{
- GPIO_PORTG_DATA_R &= ~0x04;
-}
/* Display management */
INLINE void video_off(void)
timer_delay(1000);
continue;
}
- led_on();
+ LED_ON();
timer_delay(100);
- led_off();
+ LED_OFF();
nmea_update = false;
}
}
ABS(lon) % 1000000L,
lon >= 0 ? 'E' : 'W');
text_xprintf(bm, 2, 0, TEXT_FILL,
- "Alt. %d", gga.altitude);
+ "Alt. %ld", gga.altitude);
text_xprintf(bm, 3, 0, TEXT_FILL,
"Speed: %d", vtg.km_speed);
if (gga.quality < countof(gps_fix))
static struct Menu main_menu =
{
- main_items, "DevelGPS v0.1", MF_STICKY | MF_SAVESEL, &lcd_bitmap, 0
+ main_items, "DevelGPS v0.1", MF_STICKY | MF_SAVESEL, &lcd_bitmap, 0, rit128x96_blitBitmap
};
static void init(void)
proc_init();
scrsvr_timestamp = ticks_to_ms(timer_clock_unlocked());
- led_init();
+ LED_INIT();
- flash_lm3sInit(&flash);
+ flash_init(&flash_blk, 0);
+ kfileblock_init(&flash, &flash_blk.blk);
flash_load_target();
ser_init(&ser_port, SER_UART1);