gpio toggle works

This commit is contained in:
tkl
2016-08-15 22:25:35 +02:00
parent 067dd1d3e5
commit 073f5093dd
16 changed files with 99 additions and 593 deletions

View File

@@ -16,7 +16,7 @@
#include "spi.h"
#include "uart.h"
int open(const struct driver *driver)
int drv_open(const struct driver *driver)
{
int ret = -1;
if(NULL == driver)
@@ -35,19 +35,19 @@ int open(const struct driver *driver)
ret = pwm_open((const struct pwm *)(driver->device_driver));
break;
case DRIVER_TYPE_RTC:
ret = rtc_open((const struct rtc *)(driver->device_driver));
// ret = rtc_open((const struct rtc *)(driver->device_driver));
break;
case DRIVER_TYPE_SPI:
ret = spi_open((const struct spi *)(driver->device_driver));
break;
case DRIVER_TYPE_UART:
ret = uart_open((const struct uart *)(driver->device_driver));
// ret = uart_open((const struct uart *)(driver->device_driver));
break;
}
return ret;
}
int close(const struct driver *driver)
int drv_close(const struct driver *driver)
{
int ret = -1;
if(NULL == driver)
@@ -78,7 +78,7 @@ int close(const struct driver *driver)
return ret;
}
int read(const struct driver *driver, char *buffer, int len)
int drv_read(const struct driver *driver, char *buffer, int len)
{
int ret = -1;
if(NULL == driver)
@@ -109,7 +109,7 @@ int read(const struct driver *driver, char *buffer, int len)
return ret;
}
int write(const struct driver *driver, const char *buffer, int len)
int drv_write(const struct driver *driver, const char *buffer, int len)
{
int ret = -1;
if(NULL == driver)
@@ -136,13 +136,13 @@ int write(const struct driver *driver, const char *buffer, int len)
case DRIVER_TYPE_SPI:
break;
case DRIVER_TYPE_UART:
ret = uart_write((const struct uart *)(driver->device_driver), buffer, len);
// ret = uart_write((const struct uart *)(driver->device_driver), buffer, len);
break;
}
return ret;
}
int ioctl(const struct driver *driver, unsigned int cmd, const void *data)
int drv_ioctl(const struct driver *driver, unsigned int cmd, const void *data)
{
int ret = -1;
if(NULL == driver)

View File

@@ -1,4 +1,2 @@
CHECK_FOLDER += source/firmware/kernel/driver
SUB_FOLDER += source/firmware/kernel/driver
SRC_DIR += source/firmware/kernel/driver
INCLUDES += source/firmware/kernel/driver/include
DOC_SRC += source/firmware/kernel/driver

View File

@@ -1,161 +0,0 @@
//! \file rtc.h
//! \author tkl
//! \date Jul 8, 2012
//! \brief Header file of the architecture independent rtc implementation.
#ifndef RTC_H_
#define RTC_H_
#include <stdint.h>
//-----------------------------------------------------------------------------
//! \brief Loki time container.
struct loki_time {
uint32_t sec; //!< Seconds. [0-60]
uint32_t min; //!< Minutes. [0-59]
uint32_t hour; //!< Hours. [0-23]
uint32_t day; //!< Day. [1-31]
uint32_t mon; //!< Month. [0-11]
uint32_t year; //!< Year.
};
//-----------------------------------------------------------------------------
//! \brief Rtc interrupt interval.
enum rtc_interval {
RTC_INTERVAL_MINUTE = 0, //!< rtc interrupt every minute.
RTC_INTERVAL_HOUR, //!< rtc interrupt every hour.
RTC_INTERVAL_MIDNIGHT, //!< rtc interrupt every day at 00:00.
RTC_INTERVAL_NOON //!< rtc interrupt every day at 12:00.
};
//-----------------------------------------------------------------------------
//! \brief Rtc alarm mask.
enum rtc_alarm_mask {
RTC_ALARM_DISABLED = 0x00, //!< Alarm mask disabled.
RTC_ALARM_MINUTE = 0x01, //!< Alarm mask minute.
RTC_ALARM_HOUR = 0x02, //!< Alarm mask hour.
RTC_ALARM_DAY_OF_WEEK = 0x04, //!< Alarm mask day of week.
RTC_ALARM_DAY_OF_MONTH = 0x08 //!< Alarm mask day of month.
};
//-----------------------------------------------------------------------------
//! Callback for the open function of the arch depended rtc driver.
typedef int (*rtc_fp_open_t)(const void*);
//! Callback for the close function of the arch depended rtc driver.
typedef int (*rtc_fp_close_t)(const void*);
//! Callback for the time set function of the arch depended rtc driver.
typedef void (*rtc_fp_set_time_t)(const void*, const struct loki_time*);
//! Callback for the time get function of the arch depended rtc driver.
typedef struct loki_time *(*rtc_fp_get_time_t)(const void*, struct loki_time*);
//! Callback for the start interval event function.
typedef int (*rtc_fp_start_interval_event)
(const void *, enum rtc_interval, const void *, const void *);
//! Callback for the stop interval event.
typedef int (*rtc_fp_stop_interval_event)(const void *);
//! Callback for the start alarm event.
typedef int (*rtc_fp_start_alarm_event)
(const void *, const struct loki_time*, enum rtc_alarm_mask, const void *, const void *);
//! Callback for the stop alarm event.
typedef int (*rtc_fp_stop_alarm_event)(const void *);
//-----------------------------------------------------------------------------
//! \brief Function pointer to access the rct driver.
struct rtc_fp {
const rtc_fp_open_t open; //!< Function pointer to the open function.
const rtc_fp_close_t close; //!< Function pointer to the close function.
const rtc_fp_set_time_t set_time; //!< Function pointer to the set_time function.
const rtc_fp_get_time_t get_time; //!< Function pointer to the get_time function.
const rtc_fp_start_interval_event start_interval; //!< Function pointer to the start_interval function.
const rtc_fp_stop_interval_event stop_interval; //!< Function pointer to the stop_interval function.
const rtc_fp_start_alarm_event start_alarm; //!< Function pointer to the start_alarm function.
const rtc_fp_stop_alarm_event stop_alarm; //!< Function pointer to the stop_alarm function.
};
//-----------------------------------------------------------------------------
//! \brief Contains the architecture depended device and the access functions to the rtc driver.
struct rtc {
const void *arch_dep_device; //!< Architecture depended rtc device (i.e. msp430_rtc_t).
const struct rtc_fp *fp; //!< Function pointer for the rtc driver access.
};
//-----------------------------------------------------------------------------
//! \brief Open a rtc device.
//! \param device The rtc device to open.
//! \retval -1 in error case.
int rtc_open(const struct rtc *device);
//-----------------------------------------------------------------------------
//! \brief Close a rtc device.
//! \param device The rtc device to close.
//! \retval -1 in error case.
int rtc_close(const struct rtc *device);
//-----------------------------------------------------------------------------
//! \brief Set rtc time.
//! \param device The rtc device.
//! \param time The time to set.
void rtc_set_time(const struct rtc *device, const struct loki_time *time);
//-----------------------------------------------------------------------------
//! \brief Get rtc time.
//! \param device The rtc device.
//! \param time The time to get.
//! \retval NULL in error case, otherwise points to time.
struct loki_time *rtc_get_time(const struct rtc *device,
struct loki_time *time);
//-----------------------------------------------------------------------------
//! \brief Converts a Unix timestamp to a loki_time.
//! \param tick The Unix timestamp.
//! \return the converted time.
struct loki_time tick_to_time(uint32_t tick);
//-----------------------------------------------------------------------------
//! \brief Converts a loki_time to aunix timestamp.
//! \param time The time to convert.
//! \return The converted unix timestamp.
uint32_t time_to_tick(const struct loki_time *time);
//-----------------------------------------------------------------------------
//! \brief Starts a rtc interval event.
//! On every occurance of interval the rtc event gets fired.
//! \param device The rtc device.
//! \param interval The interval of rtc event occurance.
//! \param callback The callback is executed in case of interval event.
//! \param argument The argument for the callback.
//! \retval -1 in error case.
int rtc_start_interval_event(const struct rtc *device, enum rtc_interval interval,
const void * callback, const void *argument);
//-----------------------------------------------------------------------------
//! \brief Stops a rtc interval event.
//! \param device The rtc device.
//! \retval -1 in error case.
int rtc_stop_interval_event(const struct rtc *device);
//-----------------------------------------------------------------------------
//! \brief Starts a rtc alarm event.
//! \param device The rtc device.
//! \param alarm_time The time to fire the alarm.
//! \param alarm_mask The mask to filter the alarm time.
//! \param callback The callback is executed in case of alarm.
//! \param argument The argument for the callback.
//! \retval -1 in error case.
int rtc_start_alarm_event(const struct rtc *device,
const struct loki_time *alarm_time, enum rtc_alarm_mask alarm_mask,
const void * callback, const void *argument);
//-----------------------------------------------------------------------------
//! \brief Stops a rtc alarm.
//! \param device The rtc device.
//! \retval -1 in error case.
int rtc_stop_alarm_event(const struct rtc *device);
#endif /* RTC_H_ */

View File

@@ -1,218 +0,0 @@
//! \file rtc.c
//! \author tkl
//! \date Jul 8, 2012
//! \brief Source file of the architecture independent rtc implementation.
#include <stddef.h>
#include <stdbool.h>
#include <string.h>
#include "rtc.h"
//-----------------------------------------------------------------------------
int rtc_open(const struct rtc *device) {
if(NULL == device) {
return (-1);
}
rtc_fp_open_t open = device->fp->open;
return (open(device->arch_dep_device));
}
//-----------------------------------------------------------------------------
int rtc_close(const struct rtc *device) {
if(NULL == device) {
return (-1);
}
rtc_fp_close_t close = device->fp->close;
return (close(device->arch_dep_device));
}
//-----------------------------------------------------------------------------
void rtc_set_time(const struct rtc *device, const struct loki_time *time) {
if(NULL == device) {
return;
}
rtc_fp_set_time_t set_time = device->fp->set_time;
set_time(device->arch_dep_device, time);
}
//-----------------------------------------------------------------------------
struct loki_time *rtc_get_time(const struct rtc *device, struct loki_time *time) {
if(NULL == device) {
return (NULL);
}
rtc_fp_get_time_t get_time = device->fp->get_time;
return (get_time(device->arch_dep_device, time));
}
#ifndef __isleap
//! Nonzero if YEAR is a leap year (every 4 years, except every 100th isn't, and every 400th is).
#define __isleap(year) \
((year) % 4 == 0 && ((year) % 100 != 0 || (year) % 400 == 0))
#endif
//! Seconds per hour.
#define SECS_PER_HOUR (long)(60 * 60)
//! Seconds per day.
#define SECS_PER_DAY (long)(SECS_PER_HOUR * 24)
//! Clocks per sec.
#define CLOCKS_PER_SEC 1000
static const uint8_t __mon_lengths[2][12] = {
{ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }, /* Normal years. */
{ 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } /* Leap years. */
};
//-----------------------------------------------------------------------------
uint32_t time_to_tick(const struct loki_time *time) {
if(NULL == time) {
return (0);
}
uint32_t ret = 0;
uint32_t year = time->year - 1970;
ret = time->sec + time->min * 60 + time->hour * 3600;
uint32_t days_in_year = 0;
switch(time->mon) {
case 1:
days_in_year = time->day;
break;
case 2:
days_in_year = time->day + 31;
break;
case 3:
days_in_year = time->day + 31 + 28;
break;
case 4:
days_in_year = time->day + 31 + 28 + 31;
break;
case 5:
days_in_year = time->day + 31 + 28 + 31 + 30;
break;
case 6:
days_in_year = time->day + 31 + 28 + 31 + 30 + 31;
break;
case 7:
days_in_year = time->day + 31 + 28 + 31 + 30 + 31 + 30;
break;
case 8:
days_in_year = time->day + 31 + 28 + 31 + 30 + 31 + 30 + 31;
break;
case 9:
days_in_year = time->day + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31;
break;
case 10:
days_in_year = time->day + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30;
break;
case 11:
days_in_year = time->day + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31;
break;
case 12:
days_in_year = time->day + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30;
break;
}
if(days_in_year > 0) {
days_in_year--;
}
uint32_t leap_days = 0;
uint32_t y = time->year;
while(y >= 1970) {
leap_days += __isleap(y) ? 1 : 0;
y--;
}
if(__isleap(time->year)) {
if(days_in_year < 59) {
if(leap_days > 0) {
leap_days--;
}
}
}
ret += (days_in_year + leap_days) * 60 * 60 * 24;
ret += (year * 60 * 60 * 24 * 365);
return (ret);
}
//-----------------------------------------------------------------------------
struct loki_time tick_to_time(uint32_t tick) {
struct loki_time ret;
uint32_t days, rem;
uint32_t y;
char *ip;
days = tick / SECS_PER_DAY;
rem = tick % SECS_PER_DAY;
while (rem < 0) {
rem += SECS_PER_DAY;
--days;
}
while (rem >= SECS_PER_DAY) {
rem -= SECS_PER_DAY;
++days;
}
ret.hour = rem / SECS_PER_HOUR;
rem %= SECS_PER_HOUR;
ret.min = rem / 60;
ret.sec = rem % 60;
y = 1970;
while (days >= (rem = __isleap(y) ? 366 : 365)) {
++y;
days -= rem;
}
while (days < 0) {
--y;
days += __isleap(y) ? 366 : 365;
}
ret.year = y;
ip = (char *)__mon_lengths[__isleap(y)];
for (y = 0; days >= ip[y]; ++y)
days -= ip[y];
ret.mon = y + 1;
ret.day = days + 1;
return (ret);
}
//-----------------------------------------------------------------------------
int rtc_start_interval_event(const struct rtc *device, enum rtc_interval interval,
const void *callback, const void *argument) {
if(NULL == device) {
return (-1);
}
rtc_fp_start_interval_event start_interval = device->fp->start_interval;
return (start_interval(device->arch_dep_device, interval, callback, argument));
}
//-----------------------------------------------------------------------------
int rtc_stop_interval_event(const struct rtc *device) {
if(NULL == device) {
return (-1);
}
rtc_fp_stop_interval_event stop_interval = device->fp->stop_interval;
return (stop_interval(device->arch_dep_device));
}
//-----------------------------------------------------------------------------
int rtc_start_alarm_event(const struct rtc *device,
const struct loki_time *alarm_time, enum rtc_alarm_mask alarm_mask,
const void *callback, const void *argument)
{
if(NULL == device) {
return (-1);
}
rtc_fp_start_alarm_event start_alarm = device->fp->start_alarm;
return (start_alarm(device->arch_dep_device, alarm_time, alarm_mask,
callback, argument));
}
//-----------------------------------------------------------------------------
int rtc_stop_alarm_event(const struct rtc *device) {
if(NULL == device) {
return (-1);
}
rtc_fp_stop_alarm_event stop_alarm = device->fp->stop_alarm;
return (stop_alarm(device->arch_dep_device));
}

View File

@@ -8,6 +8,6 @@
#ifndef SYS_TICK_H_
#define SYS_TICK_H_
void sys_tick_init(const struct loki_timer *hw_timer);
//void sys_tick_init(const struct loki_timer *hw_timer);
#endif /* SYS_TICK_H_ */

View File

@@ -20,15 +20,18 @@ enum driver_type {
DRIVER_TYPE_UART
};
#pragma pack(push)
#pragma pack(1)
struct driver {
enum driver_type driver_type;
const void *device_driver;
};
#pragma pack(pop)
int open(const struct driver *driver);
int close(const struct driver *driver);
int read(const struct driver *driver, char *buffer, int len);
int write(const struct driver *driver, const char *buffer, int len);
int ioctl(const struct driver *driver, unsigned int cmd, const void *data);
int drv_open(const struct driver *driver);
int drv_close(const struct driver *driver);
int drv_read(const struct driver *driver, char *buffer, int len);
int drv_write(const struct driver *driver, const char *buffer, int len);
int drv_ioctl(const struct driver *driver, unsigned int cmd, const void *data);
#endif /* SOURCE_FIRMWARE_KERNEL_DRIVER_INCLUDE_DRIVER_H_ */

View File

@@ -43,20 +43,20 @@ static void rx_func(void *arg)
char buffer[81];
unsigned int index = 0;
int ret = 0;
open(shell_object.shell_device);
drv_open(shell_object.shell_device);
while(1) {
ret = read(shell_object.shell_device, &buffer[index],
ret = drv_read(shell_object.shell_device, &buffer[index],
sizeof(buffer) / sizeof(buffer[0]) - index - 1);
if(ret) {
if(shell_object.echo_on) {
if((buffer[index + ret - 1] == '\n') && (buffer[index + ret -2] != '\r')) {
write(shell_object.shell_device, "\r\n", 2);
drv_write(shell_object.shell_device, "\r\n", 2);
}
else if((buffer[index + ret - 1] == '\r') && (buffer[index + ret -2] != '\n')) {
write(shell_object.shell_device, "\r\n", 2);
drv_write(shell_object.shell_device, "\r\n", 2);
}
else {
write(shell_object.shell_device, &buffer[index], ret); // echo
drv_write(shell_object.shell_device, &buffer[index], ret); // echo
}
}
if((buffer[index + ret - 1] == '\n') || (buffer[index + ret - 1] == '\r')) {

View File

@@ -49,14 +49,14 @@ static void *cmd_kosmos_version_cb(const char *cmd)
{
char *greeter = "Kosmos Version: ";
write(shell_object.shell_device, greeter, strlen(greeter));
write(shell_object.shell_device, KERNEL_VERSION, strlen(KERNEL_VERSION));
write(shell_object.shell_device, ".", 1);
write(shell_object.shell_device, MAJOR_VERSION, strlen(MAJOR_VERSION));
write(shell_object.shell_device, ".", 1);
write(shell_object.shell_device, MINOR_VERSION, strlen(MINOR_VERSION));
write(shell_object.shell_device, ".", 1);
write(shell_object.shell_device, BUILD_NUMBER, strlen(BUILD_NUMBER));
drv_write(shell_object.shell_device, greeter, strlen(greeter));
drv_write(shell_object.shell_device, KERNEL_VERSION, strlen(KERNEL_VERSION));
drv_write(shell_object.shell_device, ".", 1);
drv_write(shell_object.shell_device, MAJOR_VERSION, strlen(MAJOR_VERSION));
drv_write(shell_object.shell_device, ".", 1);
drv_write(shell_object.shell_device, MINOR_VERSION, strlen(MINOR_VERSION));
drv_write(shell_object.shell_device, ".", 1);
drv_write(shell_object.shell_device, BUILD_NUMBER, strlen(BUILD_NUMBER));
return NULL;
}
@@ -66,14 +66,14 @@ static void *cmd_list_all_commands_cb(const char *cmd)
struct list_node *it = shell_object.command_list.front;
int i, len = list_get_len(&shell_object.command_list);
write(shell_object.shell_device, greeter, strlen(greeter));
drv_write(shell_object.shell_device, greeter, strlen(greeter));
for(i = 0; i < (len - 1); i++) {
if(NULL != it) {
struct command *cmd = (struct command *)it->data;
write(shell_object.shell_device, cmd->command, strlen(cmd->command));
write(shell_object.shell_device, " - ", 3);
write(shell_object.shell_device, cmd->description, strlen(cmd->description));
write(shell_object.shell_device, "\r\n", 2);
drv_write(shell_object.shell_device, cmd->command, strlen(cmd->command));
drv_write(shell_object.shell_device, " - ", 3);
drv_write(shell_object.shell_device, cmd->description, strlen(cmd->description));
drv_write(shell_object.shell_device, "\r\n", 2);
it = it->next;
}
}

View File

@@ -4,6 +4,8 @@
* Created on: Sep 25, 2015
* Author: tkl
*/
#include "include/sys_tick.h"
#include <stddef.h>
#include <stdbool.h>
@@ -14,7 +16,6 @@
#include "thread.h"
#include "schedule.h"
#include "kernel.h"
#include "sys_tick.h"
struct sys_tick_obj
{