Parcourir la source

Delete unused modules.

Vladimir N. Shilov il y a 1 an
Parent
commit
3b7e515c63
4 fichiers modifiés avec 0 ajouts et 603 suppressions
  1. 0 206
      lib/ina219.c
  2. 0 146
      lib/ina219.h
  3. 0 193
      lib/rtos.c
  4. 0 58
      lib/rtos.h

+ 0 - 206
lib/ina219.c

@@ -1,206 +0,0 @@
-/*
-INA219.cpp - Class file for the INA219 Zero-Drift, Bi-directional Current/Power Monitor Arduino Library.
-
-Version: 1.0.0
-(c) 2014 Korneliusz Jarzebski
-www.jarzebski.pl
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the version 3 GNU General Public License as
-published by the Free Software Foundation.
-
-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, see <http://www.gnu.org/licenses/>.
-*/
-
-#include "INA219.h"
-#include "i2c.h"
-
-static uint16_t vShuntMax; // millivolt
-static uint16_t vBusMax; // millivolt
-static uint16_t rShunt; // milliohms
-
-static uint8_t flagCNVR; // Conversion Ready
-static uint8_t flagOVF; // Math Overflow Flag
-
-static t_i2c_status status = I2C_SUCCESS;
-
-/**
-  * Configure I2C, INA219
-  */
-void INA219_Config(void) {
-  uint16_t config;
-
-  vBusMax = 32000; // !!! Maximum input voltage only 26V !!!
-  vShuntMax = 80; // !! for shunt 10 mOhm and maximum 8A input current
-  rShunt = CURRENT_SHUNT_RESISTANCE; // in mOhm
-
-  /** INA219 configure */
-  config  = INA219_RESET_OFF; // INA219_RST
-  config |= INA219_RANGE_32V; // INA219_BVR
-  config |= INA219_GAIN_80MV; // INA219_PG
-  config |= INA219_BUS_RES_12BIT_128S; // INA219_BADC
-  config |= INA219_SHUNT_RES_12BIT_128S; //INA219_SADC
-  config |= INA219_MODE_SHUNT_BUS_CONT; //INA219_MODE
-
-  i2c_wr_reg(INA219_ADDRESS, INA219_REG_CONFIG, config);
-
-  i2c_wr_reg(INA219_ADDRESS, INA219_REG_CALIBRATION, CALIBRATION_VALUE);
-}
-
-/** */
-uint16_t getMaxPossibleCurrent(void) {
-  return (((1000 * vShuntMax) + (rShunt>>1)) / rShunt);
-}
-
-/** */
-uint16_t getMaxCurrent(void) {
-  uint16_t maxCurrent = ((CURRENT_LSB * 32767) + 500) / 1000;
-  uint16_t maxPossible = getMaxPossibleCurrent();
-
-  if (maxCurrent > maxPossible) {
-    return maxPossible;
-  } else {
-    return maxCurrent;
-  }
-}
-
-/** */
-uint16_t getMaxShuntVoltage(void) {
-  uint16_t maxVoltage = ((getMaxCurrent() * rShunt) + 500) / 1000;
-
-  if (maxVoltage >= vShuntMax) {
-    return vShuntMax;
-  } else {
-    return maxVoltage;
-  }
-}
-
-/** */
-uint32_t getMaxPower(void) {
-  return (((getMaxCurrent() * vBusMax) + 500000) / 1000000);
-}
-
-/** */
-uint16_t readBusCurrent(void) {
-  uint32_t current;;
-  int16_t tmp;
-
-  status = i2c_rd_reg(INA219_ADDRESS, INA219_REG_CURRENT, (uint16_t *)&tmp);
-  if (status != I2C_SUCCESS) {
-    return 9999;
-  }
-
-  if (tmp < 0) {
-    tmp = - tmp;
-  }
-  current = tmp;
-  current *= CURRENT_LSB;
-  current += 500;
-  current /= 1000;
-
-  return (uint16_t)current;
-}
-
-/** */
-uint32_t readBusPower(void) {
-  uint32_t power;
-  uint16_t tmp;
-
-  i2c_rd_reg(INA219_ADDRESS, INA219_REG_POWER, &tmp);
-  power = tmp;
-  power *= POWER_LSB;
-  power += 500;
-  power /= 1000;
-  return power;
-}
-
-/**
-  * Currently return raw value of shunt voltage in 10 uV
-  */
-int16_t readShuntVoltage(void) {
-  uint16_t shvolt;
-  status = i2c_rd_reg(INA219_ADDRESS, INA219_REG_SHUNTVOLTAGE, &shvolt);
-  if (status != I2C_SUCCESS) {
-    return 999;
-  }
-  return shvolt;
-}
-
-/**
-  * Return bus voltage in mV
-  */
-uint16_t readBusVoltage(void) {
-  uint16_t volt;
-
-  flagCNVR = 0;
-  flagOVF = 0;
-
-  status = i2c_rd_reg(INA219_ADDRESS, INA219_REG_BUSVOLTAGE, &volt);
-  if (status != I2C_SUCCESS) {
-    return 65535;
-  }
-
-  if ((volt & 0x0001) != 0) {
-    flagOVF = 1;
-  }
-  if ((volt & 0x0002) != 0) {
-    flagCNVR = 1;
-  }
-
-  return ((volt >> 3) * 4);
-}
-
-ina219_bvr_t getRange(void) {
-  uint16_t value;
-
-  i2c_rd_reg(INA219_ADDRESS, INA219_REG_CONFIG, &value);
-  value &= 0x2000;
-  value >>= 13;
-
-  return (ina219_bvr_t)value;
-}
-
-ina219_pg_t getGain(void) {
-  uint16_t value;
-
-  i2c_rd_reg(INA219_ADDRESS, INA219_REG_CONFIG, &value);
-  value &= 0x1800;
-  value >>= 11;
-
-  return (ina219_pg_t)value;
-}
-
-ina219_badc_t getBusRes(void) {
-  uint16_t value;
-
-  i2c_rd_reg(INA219_ADDRESS, INA219_REG_CONFIG, &value);
-  value &= 0x0780;
-  value >>= 7;
-
-  return (ina219_badc_t)value;
-}
-
-ina219_sadc_t getShuntRes(void) {
-  uint16_t value;
-
-  i2c_rd_reg(INA219_ADDRESS, INA219_REG_CONFIG, &value);
-  value &= 0x0078;
-  value >>= 3;
-
-  return (ina219_sadc_t)value;
-}
-
-ina219_mode_t getMode(void) {
-  uint16_t value;
-
-  i2c_rd_reg(INA219_ADDRESS, INA219_REG_CONFIG, &value);
-  value &= 0x0007;
-
-  return (ina219_mode_t)value;
-}

+ 0 - 146
lib/ina219.h

@@ -1,146 +0,0 @@
-/*
-INA219.h - Header file for the Zero-Drift, Bi-directional Current/Power Monitor Arduino Library.
-
-Version: 1.0.0
-(c) 2014 Korneliusz Jarzebski
-www.jarzebski.pl
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the version 3 GNU General Public License as
-published by the Free Software Foundation.
-
-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, see <http://www.gnu.org/licenses/>.
-*/
-
-#ifndef INA219_h
-#define INA219_h
-
-#include "stm8s.h"
-
-#define CURRENT_SHUNT_RESISTANCE    10
-#define INA219_ADDRESS              (uint8_t)(0x40 << 1)
-#define INA219_ADDR_RD              (INA219_ADDRESS | 0x01)
-
-/**
- * Calibration value -- ôîðìóëû èç ìàíóàëà:
- * Current_LSB = Maximum Expected Current / 2^15
- * Power_LSB = 20 * Current_LSB
- * Calibration_Value = trunc( 0.04096 / (Current_LSB * Rshunt) )
- */
-// 8000000 uA / 32768
-#define CURRENT_LSB                 244
-#define POWER_LSB                   4880
-// 0.04096 / ((8 A/32768) * 0.01 Ohm)
-#define CALIBRATION_VALUE           16777
-
-
-/* INA219 Registers */
-#define INA219_REG_CONFIG           0x00
-#define INA219_REG_SHUNTVOLTAGE     0x01
-#define INA219_REG_BUSVOLTAGE       0x02
-#define INA219_REG_POWER            0x03
-#define INA219_REG_CURRENT          0x04
-#define INA219_REG_CALIBRATION      0x05
-
-typedef enum
-{
-  INA219_RESET_OFF            = 0x0000,
-  INA219_RESET_ON             = 0x8000
-} ina219_reset_t;
-
-typedef enum
-{
-  INA219_RANGE_16V            = 0x0000,
-  INA219_RANGE_32V            = 0x2000
-} ina219_bvr_t;
-
-typedef enum
-{
-  INA219_GAIN_40MV            = 0x0000,
-  INA219_GAIN_80MV            = 0x0800,
-  INA219_GAIN_160MV           = 0x1000,
-  INA219_GAIN_320MV           = 0x1800
-} ina219_pg_t;
-
-typedef enum
-{
-  INA219_BUS_RES_9BIT         = 0x0000,
-  INA219_BUS_RES_10BIT        = 0x0080,
-  INA219_BUS_RES_11BIT        = 0x0100,
-  INA219_BUS_RES_12BIT        = 0x0180,
-  INA219_BUS_RES_12BIT_1S     = 0x0400,
-  INA219_BUS_RES_12BIT_2S     = 0x0480,
-  INA219_BUS_RES_12BIT_4S     = 0x0500,
-  INA219_BUS_RES_12BIT_8S     = 0x0580,
-  INA219_BUS_RES_12BIT_16S    = 0x0600,
-  INA219_BUS_RES_12BIT_32S    = 0x0680,
-  INA219_BUS_RES_12BIT_64S    = 0x0700,
-  INA219_BUS_RES_12BIT_128S   = 0x0780
-} ina219_badc_t;
-
-typedef enum
-{
-  INA219_SHUNT_RES_9BIT       = 0x0000,
-  INA219_SHUNT_RES_10BIT      = 0x0008,
-  INA219_SHUNT_RES_11BIT      = 0x0010,
-  INA219_SHUNT_RES_12BIT      = 0x0018,
-  INA219_SHUNT_RES_12BIT_1S   = 0x0040,
-  INA219_SHUNT_RES_12BIT_2S   = 0x0048,
-  INA219_SHUNT_RES_12BIT_4S   = 0x0050,
-  INA219_SHUNT_RES_12BIT_8S   = 0x0058,
-  INA219_SHUNT_RES_12BIT_16S  = 0x0060,
-  INA219_SHUNT_RES_12BIT_32S  = 0x0068,
-  INA219_SHUNT_RES_12BIT_64S  = 0x0070,
-  INA219_SHUNT_RES_12BIT_128S = 0x0078
-} ina219_sadc_t;
-
-typedef enum
-{
-  INA219_MODE_POWER_DOWN      = 0x0000,
-  INA219_MODE_SHUNT_TRIG      = 0x0001,
-  INA219_MODE_BUS_TRIG        = 0x0002,
-  INA219_MODE_SHUNT_BUS_TRIG  = 0x0003,
-  INA219_MODE_ADC_OFF         = 0x0004,
-  INA219_MODE_SHUNT_CONT      = 0x0005,
-  INA219_MODE_BUS_CONT        = 0x0006,
-  INA219_MODE_SHUNT_BUS_CONT  = 0x0007
-} ina219_mode_t;
-
-/**
-  * @brief  INA219 Configuration register definition
-  */
-typedef struct {
-  uint8_t         INA219_Addr; /* I2C address */
-  ina219_reset_t  INA219_RST;  /* Reset Bit */
-  ina219_bvr_t    INA219_BVR;  /* Bus Voltage Range */
-  ina219_pg_t     INA219_PG;   /* PGA (Shunt Voltage Only) */
-  ina219_badc_t   INA219_BADC; /* Bus ADC Resolution/Averaging */
-  ina219_sadc_t   INA219_SADC; /* Shunt ADC Resolution/Averaging */
-  ina219_mode_t   INA219_MODE; /* Operating Mode */
-} INA219_InitTypeDef;
-
-void INA219_Config(void);
-
-ina219_bvr_t getRange(void);
-ina219_pg_t getGain(void);
-ina219_badc_t getBusRes(void);
-ina219_sadc_t getShuntRes(void);
-ina219_mode_t getMode(void);
-
-int16_t readShuntVoltage(void);
-uint16_t readBusVoltage(void);
-uint16_t readBusCurrent(void);
-uint32_t readBusPower(void);
-
-uint16_t getMaxPossibleCurrent(void);
-uint16_t getMaxCurrent(void);
-uint16_t getMaxShuntVoltage(void);
-uint32_t getMaxPower(void);
-
-#endif

+ 0 - 193
lib/rtos.c

@@ -1,193 +0,0 @@
-#include "rtos.h"
-#include "stm8s_it.h"
-
-/* Private define ------------------------------------------------------------*/
-#define TIM4_PERIOD  (uint8_t)124
-
-/******************************************************************************************
- * Ïåðåìåííûå ìîäóëÿ
- */
-static __IO task TaskArray[MAX_TASKS];	// î÷åðåäü çàäà÷
-static __IO uint8_t arrayTail;         // "õâîñò" î÷åðåäè
-static __IO uint16_t TimingDelay;
-__IO uint8_t I2C_timeout;
-
-
-/******************************************************************************************
- * Èíèöèàëèçàöèÿ ÐÒÎÑ, âðåìÿ òèêà - 1 ìñ
- */
-inline void RTOS_Init()
-{
-  /*
-  TIM4 configuration:
-   - TIM4CLK is set to 16 MHz, the TIM4 Prescaler is equal to 128 so the TIM1 counter
-     clock used is 16 MHz / 128 = 125 000 Hz
-   - With 125 000 Hz we can generate time base:
-     max time base is 2.048 ms if TIM4_PERIOD = 255 --> (255 + 1) / 125000 = 2.048 ms
-     min time base is 0.016 ms if TIM4_PERIOD = 1   --> (  1 + 1) / 125000 = 0.016 ms
-   - In this example we need to generate a time base equal to 1 ms
-     so TIM4_PERIOD = (0.001 * 125000 - 1) = 124
-   */
-
-  /* Time base configuration. Set the Prescaler value */
-  TIM4->PSCR = (uint8_t)(TIM4_PRESCALER_128);
-  /* Set the Autoreload value */
-  TIM4->ARR = (uint8_t)(TIM4_PERIOD);
-  /* Clear TIM4 update flag */
-  TIM4->SR1 = (uint8_t)(~TIM4_FLAG_UPDATE);
-  /* Enable update interrupt */
-  TIM4->IER |= (uint8_t)TIM4_IT_UPDATE;
-
-  /* enable interrupts */
-  enableInterrupts();
-
-  /* Enable TIM4 */
-  TIM4->CR1 |= (uint8_t)TIM4_CR1_CEN;
-
-  /* "õâîñò" â 0 */
-  arrayTail = 0;
-}
-
-/******************************************************************************************
- * Äîáàâëåíèå çàäà÷è â ñïèñîê
- */
-void RTOS_SetTask (void (*taskFunc)(void), uint16_t taskDelay, uint16_t taskPeriod)
-{
-   uint8_t i;
-
-   if(!taskFunc) return;
-
-   for(i = 0; i < arrayTail; i++)                     // ïîèñê çàäà÷è â òåêóùåì ñïèñêå
-   {
-      if(TaskArray[i].pFunc == taskFunc)              // åñëè íàøëè, òî îáíîâëÿåì ïåðåìåííûå
-      {
-         DISABLE_INTERRUPT;
-
-         TaskArray[i].delay  = taskDelay;
-         TaskArray[i].period = taskPeriod;
-         TaskArray[i].run    = 0;
-
-//         RESTORE_INTERRUPT;
-         ENABLE_INTERRUPT;
-         return;                                      // îáíîâèâ, âûõîäèì
-      }
-   }
-
-   if (arrayTail < MAX_TASKS)                         // åñëè òàêîé çàäà÷è â ñïèñêå íåò
-   {                                                  // è åñòü ìåñòî,òî äîáàâëÿåì
-      DISABLE_INTERRUPT;
-
-      TaskArray[arrayTail].pFunc  = taskFunc;
-      TaskArray[arrayTail].delay  = taskDelay;
-      TaskArray[arrayTail].period = taskPeriod;
-      TaskArray[arrayTail].run    = 0;
-
-      arrayTail++;                                    // óâåëè÷èâàåì "õâîñò"
-
-      ENABLE_INTERRUPT;
-    /* ñèãíàëèçàöèÿ ïåðåïîëíåíèÿ áóôåðà çàäà÷ */
-    } else {
-      while(1);
-    }
-}
-
-/******************************************************************************************
- * Óäàëåíèå çàäà÷è èç ñïèñêà
- */
-void RTOS_DeleteTask (void (*taskFunc)(void))
-{
-   uint8_t i;
-
-   for (i=0; i<arrayTail; i++)                        // ïðîõîäèì ïî ñïèñêó çàäà÷
-   {
-      if(TaskArray[i].pFunc == taskFunc)              // åñëè çàäà÷à â ñïèñêå íàéäåíà
-      {
-
-         DISABLE_INTERRUPT;
-         if(i != (arrayTail - 1))                     // ïåðåíîñèì ïîñëåäíþþ çàäà÷ó
-         {                                            // íà ìåñòî óäàëÿåìîé
-            TaskArray[i] = TaskArray[arrayTail - 1];
-         }
-         arrayTail--;                                 // óìåíüøàåì óêàçàòåëü "õâîñòà"
-//         RESTORE_INTERRUPT;
-         ENABLE_INTERRUPT;
-         return;
-      }
-   }
-}
-
-/******************************************************************************************
- * Äèñïåò÷åð ÐÒÎÑ, âûçûâàåòñÿ â main
- */
-
-void RTOS_DispatchTask(void)
-{
-   uint8_t i;
-   void (*function) (void);
-
-   for (i=0; i<arrayTail; i++)                        // ïðîõîäèì ïî ñïèñêó çàäà÷
-   {
-      if (TaskArray[i].run == 1)                      // åñëè ôëàã íà âûïîëíåíèå âçâåäåí,
-      {                                               // çàïîìèíàåì çàäà÷ó, ò.ê. âî
-         function = TaskArray[i].pFunc;               // âðåìÿ âûïîëíåíèÿ ìîæåò
-                                                      // èçìåíèòüñÿ èíäåêñ
-         if(TaskArray[i].period == 0)
-         {                                            // åñëè ïåðèîä ðàâåí 0
-            RTOS_DeleteTask(TaskArray[i].pFunc);      // óäàëÿåì çàäà÷ó èç ñïèñêà,
-         } else {
-            TaskArray[i].run = 0;                     // èíà÷å ñíèìàåì ôëàã çàïóñêà
-            if(!TaskArray[i].delay)                   // åñëè çàäà÷à íå èçìåíèëà çàäåðæêó
-            {                                         // çàäàåì åå
-               TaskArray[i].delay = TaskArray[i].period-1;
-            }                                         // çàäà÷à äëÿ ñåáÿ ìîæåò ñäåëàòü ïàóçó
-         }
-         (*function)();                               // âûïîëíÿåì çàäà÷ó
-      }
-   }
-}
-
-/**
-  * @brief  Inserts a delay time.
-  * @param  nTime: specifies the delay time length, in milliseconds.
-  * @retval None
-  */
-void Delay(__IO uint16_t nTime)
-{
-  TimingDelay = nTime;
-  while (TimingDelay != 0) {
-      // çäåñü ìîæíî ñïàòü è æäàòü ïðåðûâàíèå
-      wfi();
-  }
-}
-
-/**
-  * @brief TIM4 Update/Overflow/Trigger Interrupt routine.
-  * @param  None
-  * @retval None
-  */
-INTERRUPT_HANDLER(TIM4_UPD_OVF_IRQHandler,23)
-{
-   /* Cleat Interrupt Pending bit */
-   TIM4->SR1 = (uint8_t)(~(uint8_t)TIM4_IT_UPDATE);
-
-   /* I2C timeout */
-   if (I2C_timeout > 0) {
-    I2C_timeout --;
-   }
-
-   /* Decrements the TimingDelay variable */
-   if (TimingDelay > 0) {
-      TimingDelay --;
-   }
-
-   /* Òàéìåðíàÿ ñëóæáà ÐÒÎÑ */
-   uint8_t i;
-   for (i=0; i<arrayTail; i++) {       // ïðîõîäèì ïî ñïèñêó çàäà÷
-      if  (TaskArray[i].delay == 0) {  // åñëè âðåìÿ äî âûïîëíåíèÿ èñòåêëî
-         TaskArray[i].run = 1;         // âçâîäèì ôëàã çàïóñêà,
-      } else {
-         TaskArray[i].delay--;         // èíà÷å óìåíüøàåì âðåìÿ
-      }
-   }
-
-}

+ 0 - 58
lib/rtos.h

@@ -1,58 +0,0 @@
-#pragma once
-#ifndef __RTOS_H
-#define __RTOS_H
-
-/******************************************************************************************
- * За основу взят планировщик задач с сайта ChipEnable.ru                                 *
- * http://chipenable.ru/index.php/programming-avr/item/110-planirovschik.html             *
- *                                                                                        *
- * Доработал Шибанов Владимир aka KontAr                                                  *
- * Дата: 26.03.2014                                                                       *
- *                                                                                        *
- * Изменения:                                                                             *
- * - добавлен однократный вызов задачи                                                    *
- * - добавлено удаление задачи по имени                                                   *
- * - при повторном добавлении задачи обновляются ее переменные                            *
- * - добавлен указатель на "хвост" списка                                                 *
- * - функции РТОС скорректированы с учетом "хвоста"                                       *
- *                                                                                        *
- * 18.05.2015, Shilov V.N. <shilow@ukr.net>                                               *
- * - скрестил с timing_delay от ST                                                        *
- * - перенёс сюда обработчик прерываний для уменьшения оверхеда                           *
- *                                                                                        *
- ******************************************************************************************/
-
-#include "stm8s.h"
-
-// Количество задач
-#define MAX_TASKS	9
-
-#define  ENABLE_INTERRUPT enableInterrupts()
-#define DISABLE_INTERRUPT disableInterrupts()
-
-/**
- * Структура задачи
- */
-typedef struct task
-{
-  void (*pFunc) (void); // указатель на функцию
-  uint16_t delay;       // задержка перед первым запуском задачи
-  uint16_t period;      // период запуска задачи
-  uint8_t run;          // флаг готовности задачи к запуску
-} task;
-
-/**
- * Переменные
- */
-
-/**
- * Прототипы фукнций
- */
-void RTOS_Init (void);
-void RTOS_SetTask (void (*taskFunc)(void), uint16_t taskDelay, uint16_t taskPeriod);
-void RTOS_DeleteTask (void (*taskFunc)(void));
-void RTOS_DispatchTask (void);
-
-void Delay(__IO uint16_t nTime);
-
-#endif /* __RTOS_H */