[457] | 1 | #include <kernel.h>
|
---|
| 2 | #include <t_syslog.h>
|
---|
| 3 | #include <stdio.h>
|
---|
| 4 | #include <t_stdlib.h>
|
---|
| 5 | #include <stdlib.h>
|
---|
| 6 | #include "syssvc/serial.h"
|
---|
| 7 | #include "syssvc/syslog.h"
|
---|
| 8 | #include "kernel_cfg.h"
|
---|
| 9 | #include "monitor.h"
|
---|
| 10 | #include "device.h"
|
---|
| 11 |
|
---|
| 12 | /*
|
---|
| 13 | * デバイスコマンド番号
|
---|
| 14 | */
|
---|
| 15 | #define NUM_DEVICE_CMD 3
|
---|
| 16 |
|
---|
| 17 | static int_t led_func(int argc, char **argv);
|
---|
| 18 | static int_t dip_func(int argc, char **argv);
|
---|
| 19 | static int_t cup_func(int argc, char **argv);
|
---|
| 20 |
|
---|
| 21 | /*
|
---|
| 22 | * デバイスコマンドテーブル
|
---|
| 23 | */
|
---|
| 24 | static const COMMAND_INFO device_command_info[NUM_DEVICE_CMD] = {
|
---|
| 25 | {"LED", led_func},
|
---|
| 26 | {"DIP", dip_func},
|
---|
| 27 | {"CUP", cup_func}
|
---|
| 28 | };
|
---|
| 29 |
|
---|
| 30 | static const char device_name[] = "DEVICE";
|
---|
| 31 | static const char device_help[] =
|
---|
| 32 | " Device LED (no) (on-1,off-0) led control\n"
|
---|
| 33 | " DIP (no) (on-1,off-0) dipsw control\n"
|
---|
| 34 | " CUP command cup control\n";
|
---|
| 35 |
|
---|
| 36 | static const uint16_t led_pattern[4] = {
|
---|
| 37 | LED01, LED02, LED03, LED04
|
---|
| 38 | };
|
---|
| 39 |
|
---|
| 40 | static COMMAND_LINK device_command_link = {
|
---|
| 41 | NULL,
|
---|
| 42 | NUM_DEVICE_CMD,
|
---|
| 43 | device_name,
|
---|
| 44 | NULL,
|
---|
| 45 | device_help,
|
---|
| 46 | &device_command_info[0]
|
---|
| 47 | };
|
---|
| 48 |
|
---|
| 49 | static uint8_t cup_command;
|
---|
| 50 |
|
---|
| 51 | static int a2i(char *str)
|
---|
| 52 | {
|
---|
| 53 | int num = 0;
|
---|
| 54 |
|
---|
| 55 | while(*str >= '0' && *str <= '9'){
|
---|
| 56 | num = num * 10 + *str++ - '0';
|
---|
| 57 | }
|
---|
| 58 | return num;
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | /*
|
---|
| 62 | * DEVICEコマンド設定関数
|
---|
| 63 | */
|
---|
| 64 | void device_info_init(intptr_t exinf)
|
---|
| 65 | {
|
---|
| 66 | setup_command(&device_command_link);
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | /*
|
---|
| 70 | * LED設定コマンド関数
|
---|
| 71 | */
|
---|
| 72 | static int_t led_func(int argc, char **argv)
|
---|
| 73 | {
|
---|
| 74 | int_t arg1=0, arg2;
|
---|
| 75 | uint16_t reg;
|
---|
| 76 |
|
---|
| 77 | if(argc < 3)
|
---|
| 78 | return -1;
|
---|
| 79 | arg1 = a2i(argv[1]);
|
---|
| 80 | arg2 = a2i(argv[2]);
|
---|
| 81 | if(arg1 >= 1 && arg1 <= 4){
|
---|
| 82 | reg = led_in();
|
---|
| 83 | if(arg2 != 0)
|
---|
| 84 | reg |= led_pattern[arg1-1];
|
---|
| 85 | else
|
---|
| 86 | reg &= ~led_pattern[arg1-1];
|
---|
| 87 | led_out(reg);
|
---|
| 88 | }
|
---|
| 89 | return 0;
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | /*
|
---|
| 93 | * DIPSW設定コマンド関数
|
---|
| 94 | */
|
---|
| 95 | static int_t dip_func(int argc, char **argv)
|
---|
| 96 | {
|
---|
| 97 | int_t arg1=0, arg2=0, i;
|
---|
| 98 |
|
---|
| 99 | if(argc > 1)
|
---|
| 100 | arg1 = a2i(argv[1]);
|
---|
| 101 | if(argc > 2)
|
---|
| 102 | arg2 = a2i(argv[2]);
|
---|
| 103 | if(arg1 >= 1 && arg1 <= 8){
|
---|
| 104 | if(arg2 != 0)
|
---|
| 105 | dipsw_value |= (0x1<<(arg1-1));
|
---|
| 106 | else
|
---|
| 107 | dipsw_value &= ~(0x1<<(arg1-1));
|
---|
| 108 | }
|
---|
| 109 | printf("dipsw\n1 2 3 4 5 6 7 8\n");
|
---|
| 110 | for(i = 0 ; i < 8 ; i++){
|
---|
| 111 | if(dipsw_value & (1<<i))
|
---|
| 112 | printf("ON ");
|
---|
| 113 | else
|
---|
| 114 | printf("OFF ");
|
---|
| 115 | }
|
---|
| 116 | printf("\n");
|
---|
| 117 | return 0;
|
---|
| 118 | }
|
---|
| 119 |
|
---|
| 120 | /*
|
---|
| 121 | * カップラーメンタイマ補助コマンド関数
|
---|
| 122 | */
|
---|
| 123 | static int_t cup_func(int argc, char **argv)
|
---|
| 124 | {
|
---|
| 125 | if(argc > 1)
|
---|
| 126 | cup_command = *argv[1];
|
---|
| 127 | return 0;
|
---|
| 128 | }
|
---|
| 129 |
|
---|
| 130 | /*
|
---|
| 131 | * CUPラーメンコマンド
|
---|
| 132 | */
|
---|
| 133 | int8_t
|
---|
| 134 | get_cup_command(void)
|
---|
| 135 | {
|
---|
| 136 | uint8_t cmd = cup_command;
|
---|
| 137 | cup_command = 0;
|
---|
| 138 | return cmd;
|
---|
| 139 | }
|
---|
| 140 |
|
---|
| 141 |
|
---|