Chinaunix首页 | 论坛 | 博客
  • 博客访问: 9161278
  • 博文数量: 1727
  • 博客积分: 12961
  • 博客等级: 上将
  • 技术积分: 19860
  • 用 户 组: 普通用户
  • 注册时间: 2009-01-09 11:25
个人简介

偷得浮生半桶水(半日闲), 好记性不如抄下来(烂笔头). 信息爆炸的时代, 学习是一项持续的工作.

文章分类

全部博文(1727)

文章存档

2024年(3)

2023年(26)

2022年(112)

2021年(217)

2020年(157)

2019年(192)

2018年(81)

2017年(78)

2016年(70)

2015年(52)

2014年(40)

2013年(51)

2012年(85)

2011年(45)

2010年(231)

2009年(287)

分类: 其他平台

2015-06-25 18:59:14


点击(此处)折叠或打开

  1. //static int local_debug_level = 1;
  2. #include "gconf.h"
  3. #include <mdev_wdt.h>

  4. #if 0
  5. static uint16_t cmd[] = {
  6.     4822, 1494,
  7.         367, 721, 367, 721,     367, 722, 367, 721,    367, 721, 367, 720,    367, 722, 367, 736,
  8.         367, 722, 718, 372,     367, 721, 367, 721,     367, 721, 367, 722,     366, 721, 367, 734,
  9.         718, 372, 718, 372,     718, 372, 367, 721,    718, 372, 367, 721,    718, 372, 717, 387,
  10.         367, 721, 718, 372,     367, 720, 718, 372,    394, 721, 367, 721,    367, 721, 718, 382,        
  11.         367, 720, 367, 721, 367, 720, 717, 372, 366, 721, 367, 721, 367, 721, 718, 8842
  12. };
  13. #else
  14. static uint16_t cmd[] = { //同样OK, 说明433 允许有误差
  15.     4820, 1490,
  16.         360, 720, 360, 720,     360, 720, 360, 720,    360, 720, 360, 720,    360, 720, 360, 720,
  17.         360, 720, 720, 360,     360, 720, 360, 720,     360, 720, 360, 720,     360, 720, 360, 720,
  18.         720, 360, 720, 360,     720, 360, 360, 720,    720, 360, 360, 720,    720, 360, 720, 360,
  19.         360, 720, 720, 360,     360, 720, 720, 360,    360, 720, 360, 720,    360, 720, 720, 360,        
  20.         360, 720, 360, 720, 360, 720, 720, 360, 360, 720, 360, 720, 360, 720, 720, 8840
  21. };
  22. #endif


  23. #if 0 //锁住CPU 执行433 的方式 -- > 成功
  24. static const uint16_t open_433_1[] = {367, 720, 367, 721, 367, 720, 717, 372, 366, 721, 367, 721, 367, 721, 718, 8842 };
  25. static const uint16_t open_433_2[] = {366, 722, 366, 721, 366, 721, 717, 372, 717, 372, 717, 372, 718, 373, 367, 9159};
  26. static const uint16_t close_433_2[] = {367, 720, 367, 721, 717, 372, 717, 372, 717, 372, 717, 372, 367, 720, 367, 9159};
  27. static const uint16_t close_433_1[] = {    367, 720, 367, 721,     717, 372, 717, 372,     367, 720, 367, 721, 717, 372, 717, 8842    };
  28. static const uint16_t stop_433[] = {366, 722, 717, 372,    366, 721, 717, 372,    366, 721, 717, 372,    367, 721, 718, 8842};
  29. static const uint16_t header[] = {
  30.         4822, 1494,
  31.         367, 721, 367, 721,     367, 722, 367, 721,    367, 721, 367, 720,    367, 722, 367, 736,
  32.         367, 722, 718, 372,     367, 721, 367, 721,     367, 721, 367, 722,     366, 721, 367, 734,
  33.         718, 372, 718, 372,     718, 372, 367, 721,    718, 372, 367, 721,    718, 372, 717, 387,
  34.         367, 721, 718, 372,     367, 720, 718, 372,    394, 721, 367, 721,    367, 721, 718, 382,
  35.     };


  36. static inline void RF433_Level_Change(bool high_level, uint16_t timeout)
  37. {
  38.     if (high_level) {
  39.         GPIO_WritePinOutput(IO_433_SEND, GPIO_IO_HIGH);
  40.     }
  41.     else {
  42.         GPIO_WritePinOutput(IO_433_SEND, GPIO_IO_LOW);
  43.     }
  44.     nd_delay_us(timeout);
  45. }


  46. static void RF433_Send_Buffer(uint8_t repeat_cnt, uint16_t *head, uint16_t head_len, uint16_t *data, uint16_t data_len)
  47. {
  48.     uint16_t idx, cnt;
  49.     bool high_level = true;

  50.     for (cnt = 0; cnt < repeat_cnt; cnt++) {
  51.         WDT_RestartCounter();
  52.         high_level = true;
  53.         for (idx=0; idx<head_len; idx++) {
  54.             RF433_Level_Change(high_level, head[idx]);
  55.             high_level = !high_level;
  56.         }
  57.         high_level = true;
  58.         for (idx=0; idx<data_len; idx++) {
  59.             RF433_Level_Change(high_level, data[idx]);
  60.             high_level = !high_level;
  61.         }
  62.     }
  63. }

  64. static void RF433_Send_CMD(uint16_t *cmd, uint16_t cmd_len)
  65. {
  66.     uint16_t idx = 0, cnt=0;
  67.     bool high_level = true;

  68.     while (idx < cmd_len)
  69.     {
  70.         RF433_Level_Change(high_level, cmd[idx++]);        
  71.         high_level = !high_level;
  72.     }

  73.     dbg("%d commands OK", idx);
  74. }


  75. void start_rf433_send_proc(void) /* 占用所有的CPU时间, 最差的方案 */
  76. {
  77.     vTaskPrioritySet(NULL, OS_PRIO_0);
  78. //init
  79.     PMU_PowerOnVDDIO(PMU_VDDIO_D0);
  80.     GPIO_PinMuxFun(IO_433_SEND, GPIO8_GPIO8);
  81.     GPIO_SetPinDir(IO_433_SEND, GPIO_OUTPUT);    
  82. //send
  83. #if 1    //open
  84.     RF433_Send_CMD(cmd, ARRAYSIZE(cmd));
  85.     //RF433_Send_Buffer(3, header, ARRAYSIZE(header), open_433_1, ARRAYSIZE(open_433_1));
  86.     //nd_delay_us(50000-8842);
  87.     //RF433_Send_Buffer(6, header, ARRAYSIZE(header), open_433_2, ARRAYSIZE(open_433_2));
  88. #else
  89.     //close
  90.     RF433_Send_Buffer(3, header, ARRAYSIZE(header), close_433_1, ARRAYSIZE(close_433_1));
  91.     nd_delay_us(50000-8842);
  92.     RF433_Send_Buffer(6, header, ARRAYSIZE(header), close_433_2, ARRAYSIZE(close_433_2));

  93.     //stop
  94.     RF433_Send_Buffer(3, header, ARRAYSIZE(header), stop_433, ARRAYSIZE(stop_433));
  95. #endif        

  96. //final
  97.     GPIO_SetPinDir(IO_433_SEND, GPIO_INPUT);
  98.     vTaskPrioritySet(NULL, OS_PRIO_3);
  99. }
  100. #else

  101. static mdev_t *gpt3_dev = NULL;

  102. static bool high_level = true;
  103. static int cmd_index = 0, cmd_len;
  104. static int split_cnt = 10;

  105. #if 0
  106. static uint16_t idx = 0;
  107. static void gpt3_ch2_cb(void) // 10 us --> one-time
  108. {
  109.     idx++;
  110.     if ((idx * (split_cnt)) >= cmd[cmd_index]) {        
  111.         if (high_level) {
  112.             GPIO_WritePinOutput(IO_433_SEND, GPIO_IO_HIGH);
  113.         }
  114.         else {
  115.             GPIO_WritePinOutput(IO_433_SEND, GPIO_IO_LOW);
  116.         }        
  117.         high_level = !high_level;
  118.         
  119.         cmd_index ++;
  120.         idx = 0;
  121.         if (cmd_index >= cmd_len) {
  122.             gpt_drv_setcb(gpt3_dev, NULL);            
  123.             gpt_drv_stop(gpt3_dev);
  124.             gpt_drv_close(gpt3_dev);
  125.             dbg("[%d]->[%d]", cmd_index, nd_get_stopwatch());
  126.         }
  127.     }
  128. }
  129. /* 使用硬件定时器来触发的433 发送动作。--> 测试OK , 最好方案之 其次*/
  130. void start_rf433_send_proc(void)
  131. {    
  132.     int idx;
  133.     //init
  134.     PMU_PowerOnVDDIO(PMU_VDDIO_D0);
  135.     
  136.     gpt_drv_init(GPT3_ID);    
  137.     gpt3_dev = gpt_drv_open(GPT3_ID);
  138.     //default gptx CLK is CLK_SYSTEM @ 50Mhz    
  139.     //GPT_ChannelFuncSelect(GPT3_ID, GPT_CH_2, GPT_CH_FUNC_NO);
  140.     //GPT_ChannelReset(GPT3_ID, (1 << GPT_CH_2));
  141.     
  142.     GPIO_PinMuxFun(IO_433_SEND, GPIO8_GPIO8);
  143.     GPIO_SetPinDir(IO_433_SEND, GPIO_OUTPUT);

  144.     gpt_drv_setcb(gpt3_dev, gpt3_ch2_cb);
  145.     cmd_len = ARRAYSIZE(cmd);

  146.     cmd_index=0;
  147.     gpt_drv_set(gpt3_dev, split_cnt); //split_cnt usec --> one time callback

  148.     //start_tm = wmtime_time_get_posix();
  149.     nd_reset_stopwatch();
  150.     GPIO_WritePinOutput(IO_433_SEND, GPIO_IO_HIGH);
  151.     high_level = false;
  152.     gpt_drv_start(gpt3_dev); //1us interval.
  153.     
  154. }

  155. #else
  156. static void gpt3_ch2_cb(void) //随时改变当前的定时间隔。
  157. {    
  158.     cmd_index ++;
  159.     
  160.     if (cmd_index >= cmd_len) {
  161.         dbg("%d cmds --> [%d] usec", cmd_index, nd_get_stopwatch());
  162.         gpt_drv_setcb(gpt3_dev, NULL);
  163.         gpt_drv_stop(gpt3_dev);
  164.         gpt_drv_close(gpt3_dev);
  165.     }
  166.     else     
  167.     {
  168.         gpt_drv_set(gpt3_dev, cmd[cmd_index]);
  169.         if (high_level) {
  170.             GPIO_WritePinOutput(IO_433_SEND, GPIO_IO_HIGH);
  171.         }
  172.         else {
  173.             GPIO_WritePinOutput(IO_433_SEND, GPIO_IO_LOW);
  174.         }
  175.         high_level = !high_level;
  176.     }

  177.     //dbg("[%d]", cmd_index);
  178.     
  179. }
  180. /* 使用硬件定时器来触发的433 发送动作。--> 测试OK , 最好的方案*/
  181. void start_rf433_send_proc(void)
  182. {    
  183.     int idx;
  184.     //init
  185.     PMU_PowerOnVDDIO(PMU_VDDIO_D0);
  186.     
  187.     gpt_drv_init(GPT3_ID);    
  188.     gpt3_dev = gpt_drv_open(GPT3_ID);
  189.     //default gptx CLK is CLK_SYSTEM @ 50Mhz    
  190.     //GPT_ChannelFuncSelect(GPT3_ID, GPT_CH_2, GPT_CH_FUNC_NO);
  191.     //GPT_ChannelReset(GPT3_ID, (1 << GPT_CH_2));
  192.     
  193.     GPIO_PinMuxFun(IO_433_SEND, GPIO8_GPIO8);
  194.     GPIO_SetPinDir(IO_433_SEND, GPIO_OUTPUT);

  195.     gpt_drv_setcb(gpt3_dev, gpt3_ch2_cb);
  196.     cmd_len = ARRAYSIZE(cmd);

  197.     cmd_index=0;
  198.     gpt_drv_set(gpt3_dev, cmd[0]);

  199.     GPIO_WritePinOutput(IO_433_SEND, GPIO_IO_HIGH);
  200.     high_level = false;
  201.     
  202.     nd_reset_stopwatch();
  203.     gpt_drv_start(gpt3_dev);
  204.     
  205. }


  206. #endif





  207. #endif


点击(此处)折叠或打开

  1. #ifndef G_CONFIG_H_
  2. #define G_CONFIG_H_

  3. #include <wmlog.h>
  4. #include <stdbool.h>
  5. #include <ctype.h>
  6. #include <wm_os.h>
  7. #include <wm_net.h>
  8. #include <app_framework.h>
  9. #include <wmtime.h>
  10. #include <partition.h>
  11. #include <cli.h>
  12. #include <wmstdio.h>
  13. #include <wm_net.h>
  14. #include <httpd.h>
  15. #include <board.h>
  16. #include <dhcp-server.h>
  17. #include <wmtime.h>
  18. #include <psm.h>
  19. #include <ftfs.h>
  20. #include <rfget.h>
  21. #include <diagnostics.h>
  22. #include <mdev_gpio.h>
  23. #include <mdev_uart.h>
  24. #include <mdev_gpt.h>
  25. #include <healthmon.h>

  26. #include <mc200_gpio.h>
  27. #include <mc200_pinmux.h>
  28. #include <mc200_pmu.h>
  29. #include <mc200_uart.h>
  30. #include <mc200_i2c.h>
  31. #include <mc200_ssp.h>
  32. #include <mc200_gpt.h>
  33. #include <mdev_pinmux.h>
  34. #include <mdev_ssp.h>


  35. #ifndef ARRAYSIZE
  36. #define ARRAYSIZE(a) sizeof(a)/sizeof(a[0])
  37. #endif

  38. #ifndef INT_MAX
  39. #define INT_MAX        (0x7FFFFFFF) //MC200 is 32bit
  40. #endif
  41. #ifndef MAX
  42. #define MAX(x,y)                 (((x) > (y))? (x) : (y))
  43. #endif
  44. #ifndef MIN
  45. #define MIN(x,y)                 (((x) < (y))? (x) : (y))
  46. #endif
  47. #ifndef ABS
  48. #define ABS(x)                     ((x)>0 ? (x) : -(x))
  49. #endif
  50. #ifndef CHECKVAL
  51. #define CHECKVAL(val, min, max)     (((val) < (min) || (val) > (max)) ? false : true)
  52. #endif


  53. #define difftime(t1, t0) (double)(t1 - t0)

  54. #define    info(_fmt_, ...);            \
  55.     if (local_debug_level > 0)        \
  56.         { wmprintf(_fmt_"\n\r", ##__VA_ARGS__); }

  57. #define    dbg(_fmt_, ...) wmprintf("### "_fmt_"\n\r", ##__VA_ARGS__)
  58. #define prompt(a)            wmprintf(a)

  59. #define IO_433_RECV        GPIO_7        //GPT3_CH1
  60. #define IO_433_SEND        GPIO_8        //GPT3_CH2

  61. //=================================================================================
  62. //########### FreeRTOS 毫秒延时 ################################
  63. static inline void nd_delay_ms(uint32_t msec)
  64. {
  65.     if (msec > 0) {
  66.         portTickType xLastedExecTime = os_ticks_get();
  67.         vTaskDelayUntil(&xLastedExecTime, os_msec_to_ticks(msec));
  68.     }
  69. }

  70. //########### DWT 微秒延时 ################################
  71. extern void arch_start_cyccnt();
  72. extern uint32_t arch_get_cyccnt();
  73. extern void arch_stop_cyccnt();

  74. static inline void nd_delay_cycles(uint32_t cycles)
  75. {
  76.     arch_start_cyccnt();
  77.     
  78.     //等到计数到所需延时值的cpu时钟数
  79.     while (arch_get_cyccnt() < cycles);
  80.     arch_stop_cyccnt();
  81. }

  82. static inline void nd_delay_ns(uint32_t nsec)
  83. {
  84.     uint32_t ts = (nsec) / 5;
  85.     arch_start_cyccnt();
  86.     
  87.     //等到计数到所需延时值的cpu时钟数
  88.     while (arch_get_cyccnt() < ts);
  89.     arch_stop_cyccnt();
  90. }

  91. static inline void nd_delay_us(uint32_t usec)
  92. {
  93.     //计算达到所需延时值的cpu时钟数,^-^如果想要更精确此处可以减去运行前面代码所需的时钟数。
  94.     //u32 ts = (usec) * (configCPU_CLOCK_HZ/(1000*1000) );
  95.     uint32_t ts = (usec) * 200;
  96.     arch_start_cyccnt();
  97.     
  98.     //等到计数到所需延时值的cpu时钟数
  99.     while (arch_get_cyccnt() < ts);
  100.     arch_stop_cyccnt();
  101. }
  102. //########### 跑表计时 ################################
  103. static inline void nd_reset_stopwatch(void)
  104. {
  105.     arch_start_cyccnt();
  106. }

  107. static inline uint32_t nd_get_stopwatch(void)
  108. {
  109.     uint32_t cnt = arch_get_cyccnt();
  110.     //return (cnt/(configCPU_CLOCK_HZ/(1000*1000)));
  111.     return (cnt/200);
  112. }


  113. #endif //G_CONFIG_H_

阅读(3011) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~